1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
25
26
27
28
29
30
31
34
35
38
39
42
43
47
48
51
54
55
56
59
62
63
64
67
70
71
74
75
76
79
80
81
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
168
169
170
173
174
180
181
182
183
184
185
186
187
188
189
190
191
196
197
201
202
203
207
211
212
213
214
215
221
232
233
239
240
241
242
243
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
266
267
270
271
274
275
278
279
280
/* ... */
/* ... */
#include "usbh_hid_mouse.h"
#include "usbh_hid_parser.h"
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost);
/* ... */
/* ... */
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];
static const HID_Report_ItemTypedef prop_b1 =
{
mouse_report_data,
1,
0,
0,
0,
0,
1,
0,
1,
1
...};
static const HID_Report_ItemTypedef prop_b2 =
{
mouse_report_data,
1,
1,
0,
0,
0,
1,
0,
1,
1
...};
static const HID_Report_ItemTypedef prop_b3 =
{
mouse_report_data,
1,
2,
0,
0,
0,
1,
0,
1,
1
...};
static const HID_Report_ItemTypedef prop_x =
{
mouse_report_data + 1U,
8,
0,
0,
1,
0,
0xFFFF,
0,
0xFFFF,
1
...};
static const HID_Report_ItemTypedef prop_y =
{
mouse_report_data + 2U,
8,
0,
0,
1,
0,
0xFFFF,
0,
0xFFFF,
1
...};
/* ... */
/* ... */
/* ... */
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;
}{ ... }
/* ... */
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 { ... }
}{ ... }
/* ... */
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)) { ... }
if (USBH_HID_FifoRead(&HID_Handle->fifo, &mouse_report_data, HID_Handle->length) == HID_Handle->length)
{
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;
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */