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
44
45
46
47
48
49
50
53
54
55
59
60
63
66
67
68
71
72
75
76
77
80
83
86
87
88
89
90
91
92
93
94
95
99
100
103
104
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
125
126
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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
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
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
236
237
240
241
248
249
250
251
252
253
254
255
260
261
262
263
264
265
268
269
270
275
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
301
302
303
304
305
306
313
314
315
316
317
318
321
322
323
324
325
326
327
328
329
330
331
332
333
334
341
342
343
344
345
352
353
354
355
356
357
358
359
360
361
362
363
364
368
369
370
371
372
373
374
378
382
386
390
391
392
399
400
403
404
405
406
407
414
415
422
423
424
425
426
427
429
430
431
432
437
438
440
441
442
443
444
445
449
450
451
452
453
454
455
467
485
497
509
512
516
517
518
519
523
524
525
526
527
528
529
530
531
532
533
534
535
536
540
541
542
543
544
545
546
547
551
552
553
555
556
557
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
589
590
595
596
597
598
599
600
607
608
609
610
611
612
617
618
623
624
625
626
627
628
635
636
637
638
639
640
645
646
651
652
653
654
655
656
657
664
665
666
667
668
670
671
672
673
674
675
682
683
684
685
686
687
691
692
693
694
696
697
698
699
700
701
702
703
709
710
711
712
713
717
718
719
721
722
723
724
725
726
727
728
729
730
731
732
733
739
740
741
742
743
747
748
754
755
756
757
758
759
760
761
762
763
764
765
771
772
778
779
780
781
785
786
787
788
789
790
793
794
795
798
799
800
803
/* ... */
/* ... */
#include "usbd_customhid.h"
#include "usbd_ctlreq.h"
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
static uint8_t USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
static uint8_t USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev);
#ifndef USE_USBD_COMPOSITE
static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc(uint16_t *length);
static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc(uint16_t *length);
static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc(uint16_t *length);
static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *length);/* ... */
#endif
/* ... */
/* ... */
USBD_ClassTypeDef USBD_CUSTOM_HID =
{
USBD_CUSTOM_HID_Init,
USBD_CUSTOM_HID_DeInit,
USBD_CUSTOM_HID_Setup,
NULL,
USBD_CUSTOM_HID_EP0_RxReady,
USBD_CUSTOM_HID_DataIn,
USBD_CUSTOM_HID_DataOut,
NULL,
NULL,
NULL,
#ifdef USE_USBD_COMPOSITE
NULL,
NULL,
NULL,
NULL,/* ... */
#else
USBD_CUSTOM_HID_GetHSCfgDesc,
USBD_CUSTOM_HID_GetFSCfgDesc,
USBD_CUSTOM_HID_GetOtherSpeedCfgDesc,
USBD_CUSTOM_HID_GetDeviceQualifierDesc,/* ... */
#endif
...};
#ifndef USE_USBD_COMPOSITE
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END =
{
0x09,
USB_DESC_TYPE_CONFIGURATION,
LOBYTE(USB_CUSTOM_HID_CONFIG_DESC_SIZ),
HIBYTE(USB_CUSTOM_HID_CONFIG_DESC_SIZ),
0x01,
0x01,
0x00,
/* ... */
#if (USBD_SELF_POWERED == 1U)
0xC0,
#else
0x80,
#endif
USBD_MAX_POWER,
0x09,
USB_DESC_TYPE_INTERFACE,
0x00,
0x00,
0x02,
0x03,
0x00,
0x00,
0x00, Descriptor of CUSTOM HID interface
0x09,
CUSTOM_HID_DESCRIPTOR_TYPE,
0x11,
0x01,
0x00,
0x01,
/* ... */
0x22,
LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE),
HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), Descriptor of CUSTOM_HID
0x07,
USB_DESC_TYPE_ENDPOINT,
CUSTOM_HID_EPIN_ADDR,
0x03,
LOBYTE(CUSTOM_HID_EPIN_SIZE),
HIBYTE(CUSTOM_HID_EPIN_SIZE),
CUSTOM_HID_FS_BINTERVAL,
0x07,
USB_DESC_TYPE_ENDPOINT,
CUSTOM_HID_EPOUT_ADDR,
0x03,
LOBYTE(CUSTOM_HID_EPOUT_SIZE),
HIBYTE(CUSTOM_HID_EPOUT_SIZE),
CUSTOM_HID_FS_BINTERVAL,
...};/* ... */
#endif
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_Desc[USB_CUSTOM_HID_DESC_SIZ] __ALIGN_END =
{
0x09,
CUSTOM_HID_DESCRIPTOR_TYPE,
0x11,
0x01,
0x00,
0x01,
/* ... */
0x22,
LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE),
HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE),
...};
#ifndef USE_USBD_COMPOSITE
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
{
USB_LEN_DEV_QUALIFIER_DESC,
USB_DESC_TYPE_DEVICE_QUALIFIER,
0x00,
0x02,
0x00,
0x00,
0x00,
0x40,
0x01,
0x00,
...};/* ... */
#endif
static uint8_t CUSTOMHIDInEpAdd = CUSTOM_HID_EPIN_ADDR;
static uint8_t CUSTOMHIDOutEpAdd = CUSTOM_HID_EPOUT_ADDR;
/* ... */
/* ... */
/* ... */
static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
{
UNUSED(cfgidx);
USBD_CUSTOM_HID_HandleTypeDef *hhid;
hhid = (USBD_CUSTOM_HID_HandleTypeDef *)USBD_malloc(sizeof(USBD_CUSTOM_HID_HandleTypeDef));
if (hhid == NULL)
{
pdev->pClassDataCmsit[pdev->classId] = NULL;
return (uint8_t)USBD_EMEM;
}if (hhid == NULL) { ... }
pdev->pClassDataCmsit[pdev->classId] = (void *)hhid;
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
#ifdef USE_USBD_COMPOSITE
CUSTOMHIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
CUSTOMHIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);/* ... */
#endif
if (pdev->dev_speed == USBD_SPEED_HIGH)
{
pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].bInterval = CUSTOM_HID_HS_BINTERVAL;
pdev->ep_out[CUSTOMHIDOutEpAdd & 0xFU].bInterval = CUSTOM_HID_HS_BINTERVAL;
}if (pdev->dev_speed == USBD_SPEED_HIGH) { ... }
else
{
pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].bInterval = CUSTOM_HID_FS_BINTERVAL;
pdev->ep_out[CUSTOMHIDOutEpAdd & 0xFU].bInterval = CUSTOM_HID_FS_BINTERVAL;
}else { ... }
(void)USBD_LL_OpenEP(pdev, CUSTOMHIDInEpAdd, USBD_EP_TYPE_INTR,
CUSTOM_HID_EPIN_SIZE);
pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].is_used = 1U;
(void)USBD_LL_OpenEP(pdev, CUSTOMHIDOutEpAdd, USBD_EP_TYPE_INTR,
CUSTOM_HID_EPOUT_SIZE);
pdev->ep_out[CUSTOMHIDOutEpAdd & 0xFU].is_used = 1U;
hhid->state = CUSTOM_HID_IDLE;
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->Init();
#ifndef USBD_CUSTOMHID_OUT_PREPARE_RECEIVE_DISABLED
(void)USBD_LL_PrepareReceive(pdev, CUSTOMHIDOutEpAdd, hhid->Report_buf,
USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);/* ... */
#endif
return (uint8_t)USBD_OK;
}{ ... }
/* ... */
static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
{
UNUSED(cfgidx);
#ifdef USE_USBD_COMPOSITE
CUSTOMHIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
CUSTOMHIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);/* ... */
#endif
(void)USBD_LL_CloseEP(pdev, CUSTOMHIDInEpAdd);
pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].is_used = 0U;
pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].bInterval = 0U;
(void)USBD_LL_CloseEP(pdev, CUSTOMHIDOutEpAdd);
pdev->ep_out[CUSTOMHIDOutEpAdd & 0xFU].is_used = 0U;
pdev->ep_out[CUSTOMHIDOutEpAdd & 0xFU].bInterval = 0U;
if (pdev->pClassDataCmsit[pdev->classId] != NULL)
{
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->DeInit();
USBD_free(pdev->pClassDataCmsit[pdev->classId]);
pdev->pClassDataCmsit[pdev->classId] = NULL;
pdev->pClassData = NULL;
}if (pdev->pClassDataCmsit[pdev->classId] != NULL) { ... }
return (uint8_t)USBD_OK;
}{ ... }
/* ... */
static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
USBD_SetupReqTypedef *req)
{
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
uint16_t len = 0U;
#ifdef USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED
uint16_t ReportLength = 0U;
#endif
uint8_t *pbuf = NULL;
uint16_t status_info = 0U;
USBD_StatusTypeDef ret = USBD_OK;
if (hhid == NULL)
{
return (uint8_t)USBD_FAIL;
}if (hhid == NULL) { ... }
switch (req->bmRequest & USB_REQ_TYPE_MASK)
{
case USB_REQ_TYPE_CLASS:
switch (req->bRequest)
{
case CUSTOM_HID_REQ_SET_PROTOCOL:
hhid->Protocol = (uint8_t)(req->wValue);
break;
case CUSTOM_HID_REQ_SET_PROTOCOL:
case CUSTOM_HID_REQ_GET_PROTOCOL:
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->Protocol, 1U);
break;
case CUSTOM_HID_REQ_GET_PROTOCOL:
case CUSTOM_HID_REQ_SET_IDLE:
hhid->IdleState = (uint8_t)(req->wValue >> 8);
break;
case CUSTOM_HID_REQ_SET_IDLE:
case CUSTOM_HID_REQ_GET_IDLE:
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->IdleState, 1U);
break;
case CUSTOM_HID_REQ_GET_IDLE:
case CUSTOM_HID_REQ_SET_REPORT:
#ifdef USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED
if (((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->CtrlReqComplete != NULL)
{
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->CtrlReqComplete(req->bRequest,
req->wLength);
}if (((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->CtrlReqComplete != NULL) { ... }
/* ... */#endif
#ifndef USBD_CUSTOMHID_EP0_OUT_PREPARE_RECEIVE_DISABLED
hhid->IsReportAvailable = 1U;
(void)USBD_CtlPrepareRx(pdev, hhid->Report_buf,
MIN(req->wLength, USBD_CUSTOMHID_OUTREPORT_BUF_SIZE));/* ... */
#endif
break;
#ifdef USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLEDcase CUSTOM_HID_REQ_SET_REPORT:
case CUSTOM_HID_REQ_GET_REPORT:
if (((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->GetReport != NULL)
{
ReportLength = req->wLength;
pbuf = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->GetReport(&ReportLength);
}if (((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->GetReport != NULL) { ... }
if ((pbuf != NULL) && (ReportLength != 0U))
{
len = MIN(ReportLength, req->wLength);
(void)USBD_CtlSendData(pdev, pbuf, len);
}if ((pbuf != NULL) && (ReportLength != 0U)) { ... }
else
{
#ifdef USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED
if (((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->CtrlReqComplete != NULL)
{
/* ... */
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->CtrlReqComplete(req->bRequest,
req->wLength);
}if (((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->CtrlReqComplete != NULL) { ... }
else
{
USBD_CtlError(pdev, req);
}else { ... }
/* ... */#else
USBD_CtlError(pdev, req);/* ... */
#endif
}else { ... }
break;/* ... */
#endif
case CUSTOM_HID_REQ_GET_REPORT:
default:
USBD_CtlError(pdev, req);
ret = USBD_FAIL;
break;default
}switch (req->bRequest) { ... }
break;
case USB_REQ_TYPE_CLASS:
case USB_REQ_TYPE_STANDARD:
switch (req->bRequest)
{
case USB_REQ_GET_STATUS:
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
(void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U);
}if (pdev->dev_state == USBD_STATE_CONFIGURED) { ... }
else
{
USBD_CtlError(pdev, req);
ret = USBD_FAIL;
}else { ... }
break;
case USB_REQ_GET_STATUS:
case USB_REQ_GET_DESCRIPTOR:
if ((req->wValue >> 8) == CUSTOM_HID_REPORT_DESC)
{
len = MIN(USBD_CUSTOM_HID_REPORT_DESC_SIZE, req->wLength);
pbuf = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->pReport;
}if ((req->wValue >> 8) == CUSTOM_HID_REPORT_DESC) { ... }
else
{
if ((req->wValue >> 8) == CUSTOM_HID_DESCRIPTOR_TYPE)
{
pbuf = USBD_CUSTOM_HID_Desc;
len = MIN(USB_CUSTOM_HID_DESC_SIZ, req->wLength);
}if ((req->wValue >> 8) == CUSTOM_HID_DESCRIPTOR_TYPE) { ... }
}else { ... }
(void)USBD_CtlSendData(pdev, pbuf, len);
break;
case USB_REQ_GET_DESCRIPTOR:
case USB_REQ_GET_INTERFACE:
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->AltSetting, 1U);
}if (pdev->dev_state == USBD_STATE_CONFIGURED) { ... }
else
{
USBD_CtlError(pdev, req);
ret = USBD_FAIL;
}else { ... }
break;
case USB_REQ_GET_INTERFACE:
case USB_REQ_SET_INTERFACE:
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
hhid->AltSetting = (uint8_t)(req->wValue);
}if (pdev->dev_state == USBD_STATE_CONFIGURED) { ... }
else
{
USBD_CtlError(pdev, req);
ret = USBD_FAIL;
}else { ... }
break;
case USB_REQ_SET_INTERFACE:
case USB_REQ_CLEAR_FEATURE:
break;
case USB_REQ_CLEAR_FEATURE:
default:
USBD_CtlError(pdev, req);
ret = USBD_FAIL;
break;default
}switch (req->bRequest) { ... }
break;
case USB_REQ_TYPE_STANDARD:
default:
USBD_CtlError(pdev, req);
ret = USBD_FAIL;
break;default
}switch (req->bmRequest & USB_REQ_TYPE_MASK) { ... }
return (uint8_t)ret;
}{ ... }
/* ... */
#ifdef USE_USBD_COMPOSITE
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
uint8_t *report, uint16_t len, uint8_t ClassId)
{
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[ClassId];/* ... */
#else
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
uint8_t *report, uint16_t len)
{
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
#endif
if (hhid == NULL)
{
return (uint8_t)USBD_FAIL;
}if (hhid == NULL) { ... }
#ifdef USE_USBD_COMPOSITE
CUSTOMHIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, ClassId);/* ... */
#endif
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
if (hhid->state == CUSTOM_HID_IDLE)
{
hhid->state = CUSTOM_HID_BUSY;
(void)USBD_LL_Transmit(pdev, CUSTOMHIDInEpAdd, report, len);
}if (hhid->state == CUSTOM_HID_IDLE) { ... }
else
{
return (uint8_t)USBD_BUSY;
}else { ... }
}if (pdev->dev_state == USBD_STATE_CONFIGURED) { ... }
return (uint8_t)USBD_OK;
}{ ... }
#ifndef USE_USBD_COMPOSITE
/* ... */
static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc(uint16_t *length)
{
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CUSTOM_HID_CfgDesc, CUSTOM_HID_EPIN_ADDR);
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CUSTOM_HID_CfgDesc, CUSTOM_HID_EPOUT_ADDR);
if (pEpInDesc != NULL)
{
pEpInDesc->wMaxPacketSize = CUSTOM_HID_EPIN_SIZE;
pEpInDesc->bInterval = CUSTOM_HID_FS_BINTERVAL;
}if (pEpInDesc != NULL) { ... }
if (pEpOutDesc != NULL)
{
pEpOutDesc->wMaxPacketSize = CUSTOM_HID_EPOUT_SIZE;
pEpOutDesc->bInterval = CUSTOM_HID_FS_BINTERVAL;
}if (pEpOutDesc != NULL) { ... }
*length = (uint16_t)sizeof(USBD_CUSTOM_HID_CfgDesc);
return USBD_CUSTOM_HID_CfgDesc;
}{ ... }
/* ... */
static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc(uint16_t *length)
{
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CUSTOM_HID_CfgDesc, CUSTOM_HID_EPIN_ADDR);
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CUSTOM_HID_CfgDesc, CUSTOM_HID_EPOUT_ADDR);
if (pEpInDesc != NULL)
{
pEpInDesc->wMaxPacketSize = CUSTOM_HID_EPIN_SIZE;
pEpInDesc->bInterval = CUSTOM_HID_HS_BINTERVAL;
}if (pEpInDesc != NULL) { ... }
if (pEpOutDesc != NULL)
{
pEpOutDesc->wMaxPacketSize = CUSTOM_HID_EPOUT_SIZE;
pEpOutDesc->bInterval = CUSTOM_HID_HS_BINTERVAL;
}if (pEpOutDesc != NULL) { ... }
*length = (uint16_t)sizeof(USBD_CUSTOM_HID_CfgDesc);
return USBD_CUSTOM_HID_CfgDesc;
}{ ... }
/* ... */
static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc(uint16_t *length)
{
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CUSTOM_HID_CfgDesc, CUSTOM_HID_EPIN_ADDR);
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CUSTOM_HID_CfgDesc, CUSTOM_HID_EPOUT_ADDR);
if (pEpInDesc != NULL)
{
pEpInDesc->wMaxPacketSize = CUSTOM_HID_EPIN_SIZE;
pEpInDesc->bInterval = CUSTOM_HID_FS_BINTERVAL;
}if (pEpInDesc != NULL) { ... }
if (pEpOutDesc != NULL)
{
pEpOutDesc->wMaxPacketSize = CUSTOM_HID_EPOUT_SIZE;
pEpOutDesc->bInterval = CUSTOM_HID_FS_BINTERVAL;
}if (pEpOutDesc != NULL) { ... }
*length = (uint16_t)sizeof(USBD_CUSTOM_HID_CfgDesc);
return USBD_CUSTOM_HID_CfgDesc;
}{ ... }
#endif/* ... */
/* ... */
static uint8_t USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
{
UNUSED(epnum);
/* ... */
((USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId])->state = CUSTOM_HID_IDLE;
return (uint8_t)USBD_OK;
}{ ... }
/* ... */
static uint8_t USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
{
UNUSED(epnum);
USBD_CUSTOM_HID_HandleTypeDef *hhid;
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
{
return (uint8_t)USBD_FAIL;
}if (pdev->pClassDataCmsit[pdev->classId] == NULL) { ... }
hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
/* ... */
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->OutEvent(hhid->Report_buf[0],
hhid->Report_buf[1]);
return (uint8_t)USBD_OK;
}{ ... }
/* ... */
uint8_t USBD_CUSTOM_HID_ReceivePacket(USBD_HandleTypeDef *pdev)
{
USBD_CUSTOM_HID_HandleTypeDef *hhid;
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
{
return (uint8_t)USBD_FAIL;
}if (pdev->pClassDataCmsit[pdev->classId] == NULL) { ... }
#ifdef USE_USBD_COMPOSITE
CUSTOMHIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);/* ... */
#endif
hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
(void)USBD_LL_PrepareReceive(pdev, CUSTOMHIDOutEpAdd, hhid->Report_buf,
USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);
return (uint8_t)USBD_OK;
}{ ... }
/* ... */
static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev)
{
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
if (hhid == NULL)
{
return (uint8_t)USBD_FAIL;
}if (hhid == NULL) { ... }
if (hhid->IsReportAvailable == 1U)
{
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->OutEvent(hhid->Report_buf[0],
hhid->Report_buf[1]);
hhid->IsReportAvailable = 0U;
}if (hhid->IsReportAvailable == 1U) { ... }
return (uint8_t)USBD_OK;
}{ ... }
#ifndef USE_USBD_COMPOSITE
/* ... */
static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *length)
{
*length = (uint16_t)sizeof(USBD_CUSTOM_HID_DeviceQualifierDesc);
return USBD_CUSTOM_HID_DeviceQualifierDesc;
}{ ... }
#endif/* ... */
/* ... */
uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev,
USBD_CUSTOM_HID_ItfTypeDef *fops)
{
if (fops == NULL)
{
return (uint8_t)USBD_FAIL;
}if (fops == NULL) { ... }
pdev->pUserData[pdev->classId] = fops;
return (uint8_t)USBD_OK;
}{ ... }
/* ... */
/* ... */
/* ... */
Includes