Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "usbd_customhid.h"
#include "usbd_ctlreq.h"
USBD_CUSTOM_HID
USBD_CUSTOM_HID_CfgDesc
USBD_CUSTOM_HID_Desc
USBD_CUSTOM_HID_DeviceQualifierDesc
CUSTOMHIDInEpAdd
CUSTOMHIDOutEpAdd
USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *, uint8_t)
USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *, uint8_t)
USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *, USBD_SetupReqTypedef *)
USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *, uint8_t *, uint16_t)
USBD_CUSTOM_HID_GetFSCfgDesc(uint16_t *)
USBD_CUSTOM_HID_GetHSCfgDesc(uint16_t *)
USBD_CUSTOM_HID_GetOtherSpeedCfgDesc(uint16_t *)
USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *, uint8_t)
USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *, uint8_t)
USBD_CUSTOM_HID_ReceivePacket(USBD_HandleTypeDef *)
USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *)
USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *)
USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *, USBD_CUSTOM_HID_ItfTypeDef *)
Files
loading...
SourceVuSTM32 Libraries and SamplesSTM32_USB_Device_LibraryClass/CustomHID/Src/usbd_customhid.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file usbd_customhid.c * @author MCD Application Team * @brief This file provides the CUSTOM_HID core functions. * ****************************************************************************** * @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. * ****************************************************************************** * @verbatim * * =================================================================== * CUSTOM_HID Class Description * =================================================================== * This module manages the CUSTOM_HID class V1.11 following the "Device Class Definition * for Human Interface Devices (CUSTOM_HID) Version 1.11 Jun 27, 2001". * This driver implements the following aspects of the specification: * - The Boot Interface Subclass * - Usage Page : Generic Desktop * - Usage : Vendor * - Collection : Application * * @note In HS mode and when the DMA is used, all variables and data structures * dealing with the DMA during the transaction process should be 32-bit aligned. * * * @endverbatim * ****************************************************************************** *//* ... */ /* BSPDependencies - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - "stm32xxxxx_{eval}{discovery}_io.c" EndBSPDependencies *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "usbd_customhid.h" #include "usbd_ctlreq.h" /** @addtogroup STM32_USB_DEVICE_LIBRARY * @{ *//* ... */ /** @defgroup USBD_CUSTOM_HID * @brief usbd core module * @{ *//* ... */ /** @defgroup USBD_CUSTOM_HID_Private_TypesDefinitions * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup USBD_CUSTOM_HID_Private_Defines * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup USBD_CUSTOM_HID_Private_Macros * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup USBD_CUSTOM_HID_Private_FunctionPrototypes * @{ *//* ... */ 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 /* USE_USBD_COMPOSITE */ /** * @} *//* ... */ /** @defgroup USBD_CUSTOM_HID_Private_Variables * @{ *//* ... */ USBD_ClassTypeDef USBD_CUSTOM_HID = { USBD_CUSTOM_HID_Init, USBD_CUSTOM_HID_DeInit, USBD_CUSTOM_HID_Setup, NULL, /*EP0_TxSent*/ USBD_CUSTOM_HID_EP0_RxReady, /*EP0_RxReady*/ /* STATUS STAGE IN */ USBD_CUSTOM_HID_DataIn, /*DataIn*/ USBD_CUSTOM_HID_DataOut, NULL, /*SOF */ 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 /* USE_USBD_COMPOSITE */ ...}; #ifndef USE_USBD_COMPOSITE /* USB CUSTOM_HID device FS Configuration Descriptor */ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END = { 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ LOBYTE(USB_CUSTOM_HID_CONFIG_DESC_SIZ), /* wTotalLength: Bytes returned */ HIBYTE(USB_CUSTOM_HID_CONFIG_DESC_SIZ), 0x01, /* bNumInterfaces: 1 interface */ 0x01, /* bConfigurationValue: Configuration value */ 0x00, /* iConfiguration: Index of string descriptor describing the configuration *//* ... */ #if (USBD_SELF_POWERED == 1U) 0xC0, /* bmAttributes: Bus Powered according to user configuration */ #else 0x80, /* bmAttributes: Bus Powered according to user configuration */ #endif /* USBD_SELF_POWERED */ USBD_MAX_POWER, /* MaxPower (mA) */ /************** Descriptor of CUSTOM HID interface ****************/ /* 09 */ 0x09, /* bLength: Interface Descriptor size*/ USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */ 0x00, /* bInterfaceNumber: Number of Interface */ 0x00, /* bAlternateSetting: Alternate setting */ 0x02, /* bNumEndpoints*/ 0x03, /* bInterfaceClass: CUSTOM_HID */ 0x00, /* bInterfaceSubClass : 1=BOOT, 0=no boot */ 0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */ 0x00, /* iInterface: Index of string descriptor */ Descriptor of CUSTOM HID interface /******************** Descriptor of CUSTOM_HID *************************/ /* 18 */ 0x09, /* bLength: CUSTOM_HID Descriptor size */ CUSTOM_HID_DESCRIPTOR_TYPE, /* bDescriptorType: CUSTOM_HID */ 0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */ 0x01, 0x00, /* bCountryCode: Hardware target country */ 0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors to follow *//* ... */ 0x22, /* bDescriptorType */ LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /* wItemLength: Total length of Report descriptor */ HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), Descriptor of CUSTOM_HID /******************** Descriptor of Custom HID endpoints ********************/ /* 27 */ 0x07, /* bLength: Endpoint Descriptor size */ USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */ CUSTOM_HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */ 0x03, /* bmAttributes: Interrupt endpoint */ LOBYTE(CUSTOM_HID_EPIN_SIZE), /* wMaxPacketSize: 2 Bytes max */ HIBYTE(CUSTOM_HID_EPIN_SIZE), CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */ /* 34 */ 0x07, /* bLength: Endpoint Descriptor size */ USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */ CUSTOM_HID_EPOUT_ADDR, /* bEndpointAddress: Endpoint Address (OUT) */ 0x03, /* bmAttributes: Interrupt endpoint */ LOBYTE(CUSTOM_HID_EPOUT_SIZE), /* wMaxPacketSize: 2 Bytes max */ HIBYTE(CUSTOM_HID_EPOUT_SIZE), CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */ /* 41 */ ...};/* ... */ #endif /* USE_USBD_COMPOSITE */ /* USB CUSTOM_HID device Configuration Descriptor */ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_Desc[USB_CUSTOM_HID_DESC_SIZ] __ALIGN_END = { /* 18 */ 0x09, /* bLength: CUSTOM_HID Descriptor size */ CUSTOM_HID_DESCRIPTOR_TYPE, /* bDescriptorType: CUSTOM_HID */ 0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */ 0x01, 0x00, /* bCountryCode: Hardware target country */ 0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors to follow *//* ... */ 0x22, /* bDescriptorType */ LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /* wItemLength: Total length of Report descriptor */ HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), ...}; #ifndef USE_USBD_COMPOSITE /* USB Standard Device Descriptor */ __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 /* USE_USBD_COMPOSITE */ static uint8_t CUSTOMHIDInEpAdd = CUSTOM_HID_EPIN_ADDR; static uint8_t CUSTOMHIDOutEpAdd = CUSTOM_HID_EPOUT_ADDR; /** * @} *//* ... */ /** @defgroup USBD_CUSTOM_HID_Private_Functions * @{ *//* ... */ /** * @brief USBD_CUSTOM_HID_Init * Initialize the CUSTOM_HID interface * @param pdev: device instance * @param cfgidx: Configuration index * @retval status *//* ... */ 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 /* Get the Endpoints addresses allocated for this class instance */ 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 /* USE_USBD_COMPOSITE */ 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 /* LOW and FULL-speed endpoints */ { pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].bInterval = CUSTOM_HID_FS_BINTERVAL; pdev->ep_out[CUSTOMHIDOutEpAdd & 0xFU].bInterval = CUSTOM_HID_FS_BINTERVAL; }else { ... } /* Open EP IN */ (void)USBD_LL_OpenEP(pdev, CUSTOMHIDInEpAdd, USBD_EP_TYPE_INTR, CUSTOM_HID_EPIN_SIZE); pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].is_used = 1U; /* Open EP OUT */ (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 /* Prepare Out endpoint to receive 1st packet */ (void)USBD_LL_PrepareReceive(pdev, CUSTOMHIDOutEpAdd, hhid->Report_buf, USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);/* ... */ #endif /* USBD_CUSTOMHID_OUT_PREPARE_RECEIVE_DISABLED */ return (uint8_t)USBD_OK; }{ ... } /** * @brief USBD_CUSTOM_HID_Init * DeInitialize the CUSTOM_HID layer * @param pdev: device instance * @param cfgidx: Configuration index * @retval status *//* ... */ static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx) { UNUSED(cfgidx); #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ 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 /* USE_USBD_COMPOSITE */ /* Close CUSTOM_HID EP IN */ (void)USBD_LL_CloseEP(pdev, CUSTOMHIDInEpAdd); pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].is_used = 0U; pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].bInterval = 0U; /* Close CUSTOM_HID EP OUT */ (void)USBD_LL_CloseEP(pdev, CUSTOMHIDOutEpAdd); pdev->ep_out[CUSTOMHIDOutEpAdd & 0xFU].is_used = 0U; pdev->ep_out[CUSTOMHIDOutEpAdd & 0xFU].bInterval = 0U; /* Free allocated memory */ 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; }{ ... } /** * @brief USBD_CUSTOM_HID_Setup * Handle the CUSTOM_HID specific requests * @param pdev: instance * @param req: usb requests * @retval status *//* ... */ 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 /* USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */ 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) { /* Let the application decide when to enable EP0 to receive the next report */ ((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 /* USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */ #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 /* USBD_CUSTOMHID_EP0_OUT_PREPARE_RECEIVE_DISABLED */ 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; /* Get report data buffer */ 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); /* Send the report data over EP0 */ (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) { /* Let the application decide what to do, keep EP0 data phase in NAK state and use USBD_CtlSendData() when data become available or stall the EP0 data phase *//* ... */ ((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 { /* Stall EP0 if no data available */ USBD_CtlError(pdev, req); }else { ... } /* ... */#else /* Stall EP0 if no data available */ USBD_CtlError(pdev, req);/* ... */ #endif /* USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */ }else { ... } break;/* ... */ #endif /* USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */ 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; }{ ... } /** * @brief USBD_CUSTOM_HID_SendReport * Send CUSTOM_HID Report * @param pdev: device instance * @param buff: pointer to report * @param ClassId: The Class ID * @retval status *//* ... */ #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 /* USE_USBD_COMPOSITE */ if (hhid == NULL) { return (uint8_t)USBD_FAIL; }if (hhid == NULL) { ... } #ifdef USE_USBD_COMPOSITE /* Get Endpoint IN address allocated for this class instance */ CUSTOMHIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, ClassId);/* ... */ #endif /* USE_USBD_COMPOSITE */ 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 /** * @brief USBD_CUSTOM_HID_GetFSCfgDesc * return FS configuration descriptor * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer *//* ... */ 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; }{ ... } /** * @brief USBD_CUSTOM_HID_GetHSCfgDesc * return HS configuration descriptor * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer *//* ... */ 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; }{ ... } /** * @brief USBD_CUSTOM_HID_GetOtherSpeedCfgDesc * return other speed configuration descriptor * @param speed : current device speed * @param length : pointer data length * @retval pointer to descriptor buffer *//* ... */ 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/* ... */ /* USE_USBD_COMPOSITE */ /** * @brief USBD_CUSTOM_HID_DataIn * handle data IN Stage * @param pdev: device instance * @param epnum: endpoint index * @retval status *//* ... */ static uint8_t USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) { UNUSED(epnum); /* Ensure that the FIFO is empty before a new transfer, this condition could be caused by a new transfer before the end of the previous transfer *//* ... */ ((USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId])->state = CUSTOM_HID_IDLE; return (uint8_t)USBD_OK; }{ ... } /** * @brief USBD_CUSTOM_HID_DataOut * handle data OUT Stage * @param pdev: device instance * @param epnum: endpoint index * @retval status *//* ... */ 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]; /* USB data will be immediately processed, this allow next USB traffic being NAKed till the end of the application processing *//* ... */ ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->OutEvent(hhid->Report_buf[0], hhid->Report_buf[1]); return (uint8_t)USBD_OK; }{ ... } /** * @brief USBD_CUSTOM_HID_ReceivePacket * prepare OUT Endpoint for reception * @param pdev: device instance * @retval status *//* ... */ 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 /* Get OUT Endpoint address allocated for this class instance */ CUSTOMHIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);/* ... */ #endif /* USE_USBD_COMPOSITE */ hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; /* Resume USB Out process */ (void)USBD_LL_PrepareReceive(pdev, CUSTOMHIDOutEpAdd, hhid->Report_buf, USBD_CUSTOMHID_OUTREPORT_BUF_SIZE); return (uint8_t)USBD_OK; }{ ... } /** * @brief USBD_CUSTOM_HID_EP0_RxReady * Handles control request data. * @param pdev: device instance * @retval status *//* ... */ 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 /** * @brief DeviceQualifierDescriptor * return Device Qualifier descriptor * @param length : pointer data length * @retval pointer to descriptor buffer *//* ... */ static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *length) { *length = (uint16_t)sizeof(USBD_CUSTOM_HID_DeviceQualifierDesc); return USBD_CUSTOM_HID_DeviceQualifierDesc; }{ ... } #endif/* ... */ /* USE_USBD_COMPOSITE */ /** * @brief USBD_CUSTOM_HID_RegisterInterface * @param pdev: device instance * @param fops: CUSTOMHID Interface callback * @retval status *//* ... */ 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
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.