Select one of the symbols to view example projects that use it.
 
Outline
#include "usbh_hid_mouse.h"
#include "usbh_hid_parser.h"
mouse_info
mouse_report_data
mouse_rx_report_buf
prop_b1
prop_b2
prop_b3
prop_x
prop_y
USBH_HID_MouseInit(USBH_HandleTypeDef *)
USBH_HID_GetMouseInfo(USBH_HandleTypeDef *)
USBH_HID_MouseDecode(USBH_HandleTypeDef *)
Files
loading...
SourceVuSTM32 Libraries and SamplesSTM32_USB_Host_LibraryClass/HID/Src/usbh_hid_mouse.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file usbh_hid_mouse.c * @author MCD Application Team * @brief This file is the application layer for USB Host HID Mouse Handling. ****************************************************************************** * @attention * * Copyright (c) 2015 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* BSPDependencies - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - "stm32xxxxx_{eval}{discovery}_io.c" - "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" - "stm32xxxxx_{eval}{discovery}_sdram.c" EndBSPDependencies *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "usbh_hid_mouse.h" #include "usbh_hid_parser.h" /** @addtogroup USBH_LIB * @{ *//* ... */ /** @addtogroup USBH_CLASS * @{ *//* ... */ /** @addtogroup USBH_HID_CLASS * @{ *//* ... */ /** @defgroup USBH_HID_MOUSE * @brief This file includes HID Layer Handlers for USB Host HID class. * @{ *//* ... */ /** @defgroup USBH_HID_MOUSE_Private_TypesDefinitions * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup USBH_HID_MOUSE_Private_Defines * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup USBH_HID_MOUSE_Private_Macros * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup USBH_HID_MOUSE_Private_FunctionPrototypes * @{ *//* ... */ static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost); /** * @} *//* ... */ /** @defgroup USBH_HID_MOUSE_Private_Variables * @{ *//* ... */ HID_MOUSE_Info_TypeDef mouse_info; uint8_t mouse_report_data[USBH_HID_MOUSE_REPORT_SIZE]; uint8_t mouse_rx_report_buf[USBH_HID_MOUSE_REPORT_SIZE]; /* Structures defining how to access items in a HID mouse report */ /* Access button 1 state. */ static const HID_Report_ItemTypedef prop_b1 = { mouse_report_data, /*data*/ 1, /*size*/ 0, /*shift*/ 0, /*count (only for array items)*/ 0, /*signed?*/ 0, /*min value read can return*/ 1, /*max value read can return*/ 0, /*min value device can report*/ 1, /*max value device can report*/ 1 /*resolution*/ ...}; /* Access button 2 state. */ static const HID_Report_ItemTypedef prop_b2 = { mouse_report_data, /*data*/ 1, /*size*/ 1, /*shift*/ 0, /*count (only for array items)*/ 0, /*signed?*/ 0, /*min value read can return*/ 1, /*max value read can return*/ 0, /*min value device can report*/ 1, /*max value device can report*/ 1 /*resolution*/ ...}; /* Access button 3 state. */ static const HID_Report_ItemTypedef prop_b3 = { mouse_report_data, /*data*/ 1, /*size*/ 2, /*shift*/ 0, /*count (only for array items)*/ 0, /*signed?*/ 0, /*min value read can return*/ 1, /*max value read can return*/ 0, /*min vale device can report*/ 1, /*max value device can report*/ 1 /*resolution*/ ...}; /* Access x coordinate change. */ static const HID_Report_ItemTypedef prop_x = { mouse_report_data + 1U, /*data*/ 8, /*size*/ 0, /*shift*/ 0, /*count (only for array items)*/ 1, /*signed?*/ 0, /*min value read can return*/ 0xFFFF,/*max value read can return*/ 0, /*min vale device can report*/ 0xFFFF,/*max value device can report*/ 1 /*resolution*/ ...}; /* Access y coordinate change. */ static const HID_Report_ItemTypedef prop_y = { mouse_report_data + 2U, /*data*/ 8, /*size*/ 0, /*shift*/ 0, /*count (only for array items)*/ 1, /*signed?*/ 0, /*min value read can return*/ 0xFFFF,/*max value read can return*/ 0, /*min vale device can report*/ 0xFFFF,/*max value device can report*/ 1 /*resolution*/ ...}; /** * @} *//* ... */ /** @defgroup USBH_HID_MOUSE_Private_Functions * @{ *//* ... */ /** * @brief USBH_HID_MouseInit * The function init the HID mouse. * @param phost: Host handle * @retval USBH Status *//* ... */ USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost) { uint32_t i; HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; mouse_info.x = 0U; mouse_info.y = 0U; mouse_info.buttons[0] = 0U; mouse_info.buttons[1] = 0U; mouse_info.buttons[2] = 0U; for (i = 0U; i < sizeof(mouse_report_data); i++) { mouse_report_data[i] = 0U; mouse_rx_report_buf[i] = 0U; }for (i = 0U; i < sizeof(mouse_report_data); i++) { ... } if (HID_Handle->length > sizeof(mouse_report_data)) { HID_Handle->length = (uint16_t)sizeof(mouse_report_data); }if (HID_Handle->length > sizeof(mouse_report_data)) { ... } HID_Handle->pData = mouse_rx_report_buf; if ((HID_QUEUE_SIZE * sizeof(mouse_report_data)) > sizeof(phost->device.Data)) { return USBH_FAIL; }if ((HID_QUEUE_SIZE * sizeof(mouse_report_data)) > sizeof(phost->device.Data)) { ... } else { USBH_HID_FifoInit(&HID_Handle->fifo, phost->device.Data, (uint16_t)(HID_QUEUE_SIZE * sizeof(mouse_report_data))); }else { ... } return USBH_OK; }{ ... } /** * @brief USBH_HID_GetMouseInfo * The function return mouse information. * @param phost: Host handle * @retval mouse information *//* ... */ HID_MOUSE_Info_TypeDef *USBH_HID_GetMouseInfo(USBH_HandleTypeDef *phost) { if (USBH_HID_MouseDecode(phost) == USBH_OK) { return &mouse_info; }if (USBH_HID_MouseDecode(phost) == USBH_OK) { ... } else { return NULL; }else { ... } }{ ... } /** * @brief USBH_HID_MouseDecode * The function decode mouse data. * @param phost: Host handle * @retval USBH Status *//* ... */ static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost) { HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; if ((HID_Handle->length == 0U) || (HID_Handle->fifo.buf == NULL)) { return USBH_FAIL; }if ((HID_Handle->length == 0U) || (HID_Handle->fifo.buf == NULL)) { ... } /*Fill report */ if (USBH_HID_FifoRead(&HID_Handle->fifo, &mouse_report_data, HID_Handle->length) == HID_Handle->length) { /*Decode report */ mouse_info.x = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_x, 0U); mouse_info.y = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_y, 0U); mouse_info.buttons[0] = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b1, 0U); mouse_info.buttons[1] = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b2, 0U); mouse_info.buttons[2] = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b3, 0U); return USBH_OK; }if (USBH_HID_FifoRead(&HID_Handle->fifo, &mouse_report_data, HID_Handle->length) == HID_Handle->length) { ... } return USBH_FAIL; }{ ... } /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */
Details