Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "usbd_core.h"
#include "usbd_composite_builder.h"
USBD_Init(USBD_HandleTypeDef *, USBD_DescriptorsTypeDef *, uint8_t)
USBD_DeInit(USBD_HandleTypeDef *)
USBD_RegisterClass(USBD_HandleTypeDef *, USBD_ClassTypeDef *)
USBD_Start(USBD_HandleTypeDef *)
USBD_Stop(USBD_HandleTypeDef *)
USBD_RunTestMode(USBD_HandleTypeDef *)
USBD_SetClassConfig(USBD_HandleTypeDef *, uint8_t)
USBD_ClrClassConfig(USBD_HandleTypeDef *, uint8_t)
USBD_LL_SetupStage(USBD_HandleTypeDef *, uint8_t *)
USBD_LL_DataOutStage(USBD_HandleTypeDef *, uint8_t, uint8_t *)
USBD_LL_DataInStage(USBD_HandleTypeDef *, uint8_t, uint8_t *)
USBD_LL_Reset(USBD_HandleTypeDef *)
USBD_LL_SetSpeed(USBD_HandleTypeDef *, USBD_SpeedTypeDef)
USBD_LL_Suspend(USBD_HandleTypeDef *)
USBD_LL_Resume(USBD_HandleTypeDef *)
USBD_LL_SOF(USBD_HandleTypeDef *)
USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *, uint8_t)
USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *, uint8_t)
USBD_LL_DevConnected(USBD_HandleTypeDef *)
USBD_LL_DevDisconnected(USBD_HandleTypeDef *)
USBD_CoreFindIF(USBD_HandleTypeDef *, uint8_t)
USBD_CoreFindEP(USBD_HandleTypeDef *, uint8_t)
USBD_GetEpDesc(uint8_t *, uint8_t)
USBD_GetNextDesc(uint8_t *, uint16_t *)
Files
loading...
SourceVuSTM32 Libraries and SamplesSTM32_USB_Device_LibraryCore/Src/usbd_core.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
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file usbd_core.c * @author MCD Application Team * @brief This file provides all the USBD 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. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "usbd_core.h" #ifdef USE_USBD_COMPOSITE #include "usbd_composite_builder.h" #endif /* USE_USBD_COMPOSITE */ /** @addtogroup STM32_USBD_DEVICE_LIBRARY * @{ *//* ... */ /** @defgroup USBD_CORE * @brief usbd core module * @{ *//* ... */ /** @defgroup USBD_CORE_Private_TypesDefinitions * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup USBD_CORE_Private_Defines * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup USBD_CORE_Private_Macros * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup USBD_CORE_Private_FunctionPrototypes * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup USBD_CORE_Private_Variables * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup USBD_CORE_Private_Functions * @{ *//* ... */ /** * @brief USBD_Init * Initializes the device stack and load the class driver * @param pdev: device instance * @param pdesc: Descriptor structure address * @param id: Low level core index * @retval None *//* ... */ USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id) { USBD_StatusTypeDef ret; /* Check whether the USB Host handle is valid */ if (pdev == NULL) { #if (USBD_DEBUG_LEVEL > 1U) USBD_ErrLog("Invalid Device handle"); #endif /* (USBD_DEBUG_LEVEL > 1U) */ return USBD_FAIL; }if (pdev == NULL) { ... } #ifdef USE_USBD_COMPOSITE /* Parse the table of classes in use */ for (uint32_t i = 0; i < USBD_MAX_SUPPORTED_CLASS; i++) { /* Unlink previous class*/ pdev->pClass[i] = NULL; pdev->pUserData[i] = NULL; /* Set class as inactive */ pdev->tclasslist[i].Active = 0; pdev->NumClasses = 0; pdev->classId = 0; }for (uint32_t i = 0; i < USBD_MAX_SUPPORTED_CLASS; i++) { ... } /* ... */#else /* Unlink previous class*/ pdev->pClass[0] = NULL; pdev->pUserData[0] = NULL;/* ... */ #endif /* USE_USBD_COMPOSITE */ pdev->pConfDesc = NULL; /* Assign USBD Descriptors */ if (pdesc != NULL) { pdev->pDesc = pdesc; }if (pdesc != NULL) { ... } /* Set Device initial State */ pdev->dev_state = USBD_STATE_DEFAULT; pdev->id = id; /* Initialize low level driver */ ret = USBD_LL_Init(pdev); return ret; }{ ... } /** * @brief USBD_DeInit * Re-Initialize the device library * @param pdev: device instance * @retval status: status *//* ... */ USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev) { USBD_StatusTypeDef ret; /* Disconnect the USB Device */ (void)USBD_LL_Stop(pdev); /* Set Default State */ pdev->dev_state = USBD_STATE_DEFAULT; #ifdef USE_USBD_COMPOSITE /* Parse the table of classes in use */ for (uint32_t i = 0; i < USBD_MAX_SUPPORTED_CLASS; i++) { /* Check if current class is in use */ if ((pdev->tclasslist[i].Active) == 1U) { if (pdev->pClass[i] != NULL) { pdev->classId = i; /* Free Class Resources */ pdev->pClass[i]->DeInit(pdev, (uint8_t)pdev->dev_config); }if (pdev->pClass[i] != NULL) { ... } }if ((pdev->tclasslist[i].Active) == 1U) { ... } }for (uint32_t i = 0; i < USBD_MAX_SUPPORTED_CLASS; i++) { ... } /* ... */#else /* Free Class Resources */ if (pdev->pClass[0] != NULL) { pdev->pClass[0]->DeInit(pdev, (uint8_t)pdev->dev_config); }if (pdev->pClass[0] != NULL) { ... } pdev->pUserData[0] = NULL; /* ... */ #endif /* USE_USBD_COMPOSITE */ /* Free Device descriptors resources */ pdev->pDesc = NULL; pdev->pConfDesc = NULL; /* DeInitialize low level driver */ ret = USBD_LL_DeInit(pdev); return ret; }{ ... } /** * @brief USBD_RegisterClass * Link class driver to Device Core. * @param pDevice : Device Handle * @param pclass: Class handle * @retval USBD Status *//* ... */ USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass) { uint16_t len = 0U; if (pclass == NULL) { #if (USBD_DEBUG_LEVEL > 1U) USBD_ErrLog("Invalid Class handle"); #endif /* (USBD_DEBUG_LEVEL > 1U) */ return USBD_FAIL; }if (pclass == NULL) { ... } /* link the class to the USB Device handle */ pdev->pClass[0] = pclass; /* Get Device Configuration Descriptor */ #ifdef USE_USB_HS if (pdev->pClass[pdev->classId]->GetHSConfigDescriptor != NULL) { pdev->pConfDesc = (void *)pdev->pClass[pdev->classId]->GetHSConfigDescriptor(&len); }if (pdev->pClass[pdev->classId]->GetHSConfigDescriptor != NULL) { ... } /* ... */#else /* Default USE_USB_FS */ if (pdev->pClass[pdev->classId]->GetFSConfigDescriptor != NULL) { pdev->pConfDesc = (void *)pdev->pClass[pdev->classId]->GetFSConfigDescriptor(&len); }if (pdev->pClass[pdev->classId]->GetFSConfigDescriptor != NULL) { ... } /* ... */#endif /* USE_USB_FS */ /* Increment the NumClasses */ pdev->NumClasses ++; return USBD_OK; }{ ... } #ifdef USE_USBD_COMPOSITE /** * @brief USBD_RegisterClassComposite * Link class driver to Device Core. * @param pdev : Device Handle * @param pclass: Class handle * @param classtype: Class type * @param EpAddr: Endpoint Address handle * @retval USBD Status *//* ... */ USBD_StatusTypeDef USBD_RegisterClassComposite(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass, USBD_CompositeClassTypeDef classtype, uint8_t *EpAddr) { USBD_StatusTypeDef ret = USBD_OK; uint16_t len = 0U; if ((pdev->classId < USBD_MAX_SUPPORTED_CLASS) && (pdev->NumClasses < USBD_MAX_SUPPORTED_CLASS)) { if ((uint32_t)pclass != 0U) { /* Link the class to the USB Device handle */ pdev->pClass[pdev->classId] = pclass; ret = USBD_OK; pdev->tclasslist[pdev->classId].EpAdd = EpAddr; /* Call the composite class builder */ (void)USBD_CMPSIT_AddClass(pdev, pclass, classtype, 0); /* Increment the ClassId for the next occurrence */ pdev->classId ++; pdev->NumClasses ++; }if ((uint32_t)pclass != 0U) { ... } else { #if (USBD_DEBUG_LEVEL > 1U) USBD_ErrLog("Invalid Class handle"); #endif /* (USBD_DEBUG_LEVEL > 1U) */ ret = USBD_FAIL; }else { ... } }if ((pdev->classId < USBD_MAX_SUPPORTED_CLASS) && (pdev->NumClasses < USBD_MAX_SUPPORTED_CLASS)) { ... } if (ret == USBD_OK) { /* Get Device Configuration Descriptor */ #ifdef USE_USB_HS pdev->pConfDesc = USBD_CMPSIT.GetHSConfigDescriptor(&len); #else /* Default USE_USB_FS */ pdev->pConfDesc = USBD_CMPSIT.GetFSConfigDescriptor(&len); #endif /* USE_USB_FS */ }if (ret == USBD_OK) { ... } return ret; }USBD_RegisterClassComposite (USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass, USBD_CompositeClassTypeDef classtype, uint8_t *EpAddr) { ... } /** * @brief USBD_UnRegisterClassComposite * UnLink all composite class drivers from Device Core. * @param pDevice : Device Handle * @retval USBD Status *//* ... */ USBD_StatusTypeDef USBD_UnRegisterClassComposite(USBD_HandleTypeDef *pdev) { USBD_StatusTypeDef ret = USBD_FAIL; uint8_t idx1; uint8_t idx2; /* Unroll all activated classes */ for (idx1 = 0; idx1 < pdev->NumClasses; idx1++) { /* Check if the class correspond to the requested type and if it is active */ if (pdev->tclasslist[idx1].Active == 1U) { /* Set the new class ID */ pdev->classId = idx1; /* Free resources used by the selected class */ if (pdev->pClass[pdev->classId] != NULL) { /* Free Class Resources */ if (pdev->pClass[pdev->classId]->DeInit(pdev, (uint8_t)pdev->dev_config) != 0U) { #if (USBD_DEBUG_LEVEL > 1U) USBD_ErrLog("Class DeInit didn't succeed!, can't unregister selected class"); #endif /* (USBD_DEBUG_LEVEL > 1U) */ ret = USBD_FAIL; }if (pdev->pClass[pdev->classId]->DeInit(pdev, (uint8_t)pdev->dev_config) != 0U) { ... } }if (pdev->pClass[pdev->classId] != NULL) { ... } /* Free the class pointer */ pdev->pClass[pdev->classId] = NULL; /* Free the class location in classes table and reset its parameters to zero */ pdev->tclasslist[pdev->classId].ClassType = CLASS_TYPE_NONE; pdev->tclasslist[pdev->classId].ClassId = 0U; pdev->tclasslist[pdev->classId].Active = 0U; pdev->tclasslist[pdev->classId].NumEps = 0U; pdev->tclasslist[pdev->classId].NumIf = 0U; pdev->tclasslist[pdev->classId].CurrPcktSze = 0U; for (idx2 = 0U; idx2 < USBD_MAX_CLASS_ENDPOINTS; idx2++) { pdev->tclasslist[pdev->classId].Eps[idx2].add = 0U; pdev->tclasslist[pdev->classId].Eps[idx2].type = 0U; pdev->tclasslist[pdev->classId].Eps[idx2].size = 0U; pdev->tclasslist[pdev->classId].Eps[idx2].is_used = 0U; }for (idx2 = 0U; idx2 < USBD_MAX_CLASS_ENDPOINTS; idx2++) { ... } for (idx2 = 0U; idx2 < USBD_MAX_CLASS_INTERFACES; idx2++) { pdev->tclasslist[pdev->classId].Ifs[idx2] = 0U; }for (idx2 = 0U; idx2 < USBD_MAX_CLASS_INTERFACES; idx2++) { ... } }if (pdev->tclasslist[idx1].Active == 1U) { ... } }for (idx1 = 0; idx1 < pdev->NumClasses; idx1++) { ... } /* Reset the configuration descriptor */ (void)USBD_CMPST_ClearConfDesc(pdev); /* Reset the class ID and number of classes */ pdev->classId = 0U; pdev->NumClasses = 0U; return ret; }USBD_UnRegisterClassComposite (USBD_HandleTypeDef *pdev) { ... } /* ... */#endif /* USE_USBD_COMPOSITE */ #if (USBD_USER_REGISTER_CALLBACK == 1U) /** * @brief USBD_RegisterDevStateCallback * @param pdev : Device Handle * @param pUserCallback: User Callback * @retval USBD Status *//* ... */ USBD_StatusTypeDef USBD_RegisterDevStateCallback(USBD_HandleTypeDef *pdev, USBD_DevStateCallbackTypeDef pUserCallback) { pdev->DevStateCallback = pUserCallback; return USBD_OK; }USBD_RegisterDevStateCallback (USBD_HandleTypeDef *pdev, USBD_DevStateCallbackTypeDef pUserCallback) { ... } /* ... */#endif /* USBD_USER_REGISTER_CALLBACK */ /** * @brief USBD_Start * Start the USB Device Core. * @param pdev: Device Handle * @retval USBD Status *//* ... */ USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev) { #ifdef USE_USBD_COMPOSITE pdev->classId = 0U; #endif /* USE_USBD_COMPOSITE */ /* Start the low level driver */ return USBD_LL_Start(pdev); }{ ... } /** * @brief USBD_Stop * Stop the USB Device Core. * @param pdev: Device Handle * @retval USBD Status *//* ... */ USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev) { /* Disconnect USB Device */ (void)USBD_LL_Stop(pdev); /* Free Class Resources */ #ifdef USE_USBD_COMPOSITE /* Parse the table of classes in use */ for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++) { /* Check if current class is in use */ if ((pdev->tclasslist[i].Active) == 1U) { if (pdev->pClass[i] != NULL) { pdev->classId = i; /* Free Class Resources */ (void)pdev->pClass[i]->DeInit(pdev, (uint8_t)pdev->dev_config); }if (pdev->pClass[i] != NULL) { ... } }if ((pdev->tclasslist[i].Active) == 1U) { ... } }for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++) { ... } /* Reset the class ID */ pdev->classId = 0U;/* ... */ #else if (pdev->pClass[0] != NULL) { (void)pdev->pClass[0]->DeInit(pdev, (uint8_t)pdev->dev_config); }if (pdev->pClass[0] != NULL) { ... } /* ... */#endif /* USE_USBD_COMPOSITE */ return USBD_OK; }{ ... } /** * @brief USBD_RunTestMode * Launch test mode process * @param pdev: device instance * @retval status *//* ... */ USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev) { #ifdef USBD_HS_TESTMODE_ENABLE USBD_StatusTypeDef ret; /* Run USB HS test mode */ ret = USBD_LL_SetTestMode(pdev, pdev->dev_test_mode); return ret;/* ... */ #else /* Prevent unused argument compilation warning */ UNUSED(pdev); return USBD_OK;/* ... */ #endif /* USBD_HS_TESTMODE_ENABLE */ }{ ... } /** * @brief USBD_SetClassConfig * Configure device and start the interface * @param pdev: device instance * @param cfgidx: configuration index * @retval status *//* ... */ USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx) { USBD_StatusTypeDef ret = USBD_OK; #ifdef USE_USBD_COMPOSITE /* Parse the table of classes in use */ for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++) { /* Check if current class is in use */ if ((pdev->tclasslist[i].Active) == 1U) { if (pdev->pClass[i] != NULL) { pdev->classId = i; /* Set configuration and Start the Class*/ if (pdev->pClass[i]->Init(pdev, cfgidx) != 0U) { ret = USBD_FAIL; }if (pdev->pClass[i]->Init(pdev, cfgidx) != 0U) { ... } }if (pdev->pClass[i] != NULL) { ... } }if ((pdev->tclasslist[i].Active) == 1U) { ... } }for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++) { ... } /* ... */#else if (pdev->pClass[0] != NULL) { /* Set configuration and Start the Class */ ret = (USBD_StatusTypeDef)pdev->pClass[0]->Init(pdev, cfgidx); }if (pdev->pClass[0] != NULL) { ... } /* ... */#endif /* USE_USBD_COMPOSITE */ return ret; }{ ... } /** * @brief USBD_ClrClassConfig * Clear current configuration * @param pdev: device instance * @param cfgidx: configuration index * @retval status: USBD_StatusTypeDef *//* ... */ USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx) { USBD_StatusTypeDef ret = USBD_OK; #ifdef USE_USBD_COMPOSITE /* Parse the table of classes in use */ for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++) { /* Check if current class is in use */ if ((pdev->tclasslist[i].Active) == 1U) { if (pdev->pClass[i] != NULL) { pdev->classId = i; /* Clear configuration and De-initialize the Class process */ if (pdev->pClass[i]->DeInit(pdev, cfgidx) != 0U) { ret = USBD_FAIL; }if (pdev->pClass[i]->DeInit(pdev, cfgidx) != 0U) { ... } }if (pdev->pClass[i] != NULL) { ... } }if ((pdev->tclasslist[i].Active) == 1U) { ... } }for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++) { ... } /* ... */#else /* Clear configuration and De-initialize the Class process */ if (pdev->pClass[0]->DeInit(pdev, cfgidx) != 0U) { ret = USBD_FAIL; }if (pdev->pClass[0]->DeInit(pdev, cfgidx) != 0U) { ... } /* ... */#endif /* USE_USBD_COMPOSITE */ return ret; }{ ... } /** * @brief USBD_LL_SetupStage * Handle the setup stage * @param pdev: device instance * @retval status *//* ... */ USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup) { USBD_StatusTypeDef ret; USBD_ParseSetupRequest(&pdev->request, psetup); pdev->ep0_state = USBD_EP0_SETUP; pdev->ep0_data_len = pdev->request.wLength; switch (pdev->request.bmRequest & 0x1FU) { case USB_REQ_RECIPIENT_DEVICE: ret = USBD_StdDevReq(pdev, &pdev->request); break; case USB_REQ_RECIPIENT_DEVICE: case USB_REQ_RECIPIENT_INTERFACE: ret = USBD_StdItfReq(pdev, &pdev->request); break; case USB_REQ_RECIPIENT_INTERFACE: case USB_REQ_RECIPIENT_ENDPOINT: ret = USBD_StdEPReq(pdev, &pdev->request); break; case USB_REQ_RECIPIENT_ENDPOINT: default: ret = USBD_LL_StallEP(pdev, (pdev->request.bmRequest & 0x80U)); break;default }switch (pdev->request.bmRequest & 0x1FU) { ... } return ret; }{ ... } /** * @brief USBD_LL_DataOutStage * Handle data OUT stage * @param pdev: device instance * @param epnum: endpoint index * @param pdata: data pointer * @retval status *//* ... */ USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata) { USBD_EndpointTypeDef *pep; USBD_StatusTypeDef ret = USBD_OK; uint8_t idx; if (epnum == 0U) { pep = &pdev->ep_out[0]; if (pdev->ep0_state == USBD_EP0_DATA_OUT) { if (pep->rem_length > pep->maxpacket) { pep->rem_length -= pep->maxpacket; (void)USBD_CtlContinueRx(pdev, pdata, MIN(pep->rem_length, pep->maxpacket)); }if (pep->rem_length > pep->maxpacket) { ... } else { /* Find the class ID relative to the current request */ switch (pdev->request.bmRequest & 0x1FU) { case USB_REQ_RECIPIENT_DEVICE: /* Device requests must be managed by the first instantiated class (or duplicated by all classes for simplicity) *//* ... */ idx = 0U; break; case USB_REQ_RECIPIENT_DEVICE: case USB_REQ_RECIPIENT_INTERFACE: idx = USBD_CoreFindIF(pdev, LOBYTE(pdev->request.wIndex)); break; case USB_REQ_RECIPIENT_INTERFACE: case USB_REQ_RECIPIENT_ENDPOINT: idx = USBD_CoreFindEP(pdev, LOBYTE(pdev->request.wIndex)); break; case USB_REQ_RECIPIENT_ENDPOINT: default: /* Back to the first class in case of doubt */ idx = 0U; break;default }switch (pdev->request.bmRequest & 0x1FU) { ... } if (idx < USBD_MAX_SUPPORTED_CLASS) { /* Setup the class ID and route the request to the relative class function */ if (pdev->dev_state == USBD_STATE_CONFIGURED) { if (pdev->pClass[idx]->EP0_RxReady != NULL) { pdev->classId = idx; pdev->pClass[idx]->EP0_RxReady(pdev); }if (pdev->pClass[idx]->EP0_RxReady != NULL) { ... } }if (pdev->dev_state == USBD_STATE_CONFIGURED) { ... } }if (idx < USBD_MAX_SUPPORTED_CLASS) { ... } (void)USBD_CtlSendStatus(pdev); }else { ... } }if (pdev->ep0_state == USBD_EP0_DATA_OUT) { ... } }if (epnum == 0U) { ... } else { /* Get the class index relative to this interface */ idx = USBD_CoreFindEP(pdev, (epnum & 0x7FU)); if (((uint16_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS)) { /* Call the class data out function to manage the request */ if (pdev->dev_state == USBD_STATE_CONFIGURED) { if (pdev->pClass[idx]->DataOut != NULL) { pdev->classId = idx; ret = (USBD_StatusTypeDef)pdev->pClass[idx]->DataOut(pdev, epnum); }if (pdev->pClass[idx]->DataOut != NULL) { ... } }if (pdev->dev_state == USBD_STATE_CONFIGURED) { ... } if (ret != USBD_OK) { return ret; }if (ret != USBD_OK) { ... } }if (((uint16_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS)) { ... } }else { ... } return USBD_OK; }{ ... } /** * @brief USBD_LL_DataInStage * Handle data in stage * @param pdev: device instance * @param epnum: endpoint index * @retval status *//* ... */ USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata) { USBD_EndpointTypeDef *pep; USBD_StatusTypeDef ret; uint8_t idx; if (epnum == 0U) { pep = &pdev->ep_in[0]; if (pdev->ep0_state == USBD_EP0_DATA_IN) { if (pep->rem_length > pep->maxpacket) { pep->rem_length -= pep->maxpacket; (void)USBD_CtlContinueSendData(pdev, pdata, pep->rem_length); /* Prepare endpoint for premature end of transfer */ (void)USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); }if (pep->rem_length > pep->maxpacket) { ... } else { /* last packet is MPS multiple, so send ZLP packet */ if ((pep->maxpacket == pep->rem_length) && (pep->total_length >= pep->maxpacket) && (pep->total_length < pdev->ep0_data_len)) { (void)USBD_CtlContinueSendData(pdev, NULL, 0U); pdev->ep0_data_len = 0U; /* Prepare endpoint for premature end of transfer */ (void)USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); }if ((pep->maxpacket == pep->rem_length) && (pep->total_length >= pep->maxpacket) && (pep->total_length < pdev->ep0_data_len)) { ... } else { if (pdev->dev_state == USBD_STATE_CONFIGURED) { if (pdev->pClass[0]->EP0_TxSent != NULL) { pdev->classId = 0U; pdev->pClass[0]->EP0_TxSent(pdev); }if (pdev->pClass[0]->EP0_TxSent != NULL) { ... } }if (pdev->dev_state == USBD_STATE_CONFIGURED) { ... } (void)USBD_LL_StallEP(pdev, 0x80U); (void)USBD_CtlReceiveStatus(pdev); }else { ... } }else { ... } }if (pdev->ep0_state == USBD_EP0_DATA_IN) { ... } if (pdev->dev_test_mode != 0U) { (void)USBD_RunTestMode(pdev); pdev->dev_test_mode = 0U; }if (pdev->dev_test_mode != 0U) { ... } }if (epnum == 0U) { ... } else { /* Get the class index relative to this interface */ idx = USBD_CoreFindEP(pdev, ((uint8_t)epnum | 0x80U)); if (((uint16_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS)) { /* Call the class data out function to manage the request */ if (pdev->dev_state == USBD_STATE_CONFIGURED) { if (pdev->pClass[idx]->DataIn != NULL) { pdev->classId = idx; ret = (USBD_StatusTypeDef)pdev->pClass[idx]->DataIn(pdev, epnum); if (ret != USBD_OK) { return ret; }if (ret != USBD_OK) { ... } }if (pdev->pClass[idx]->DataIn != NULL) { ... } }if (pdev->dev_state == USBD_STATE_CONFIGURED) { ... } }if (((uint16_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS)) { ... } }else { ... } return USBD_OK; }{ ... } /** * @brief USBD_LL_Reset * Handle Reset event * @param pdev: device instance * @retval status *//* ... */ USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev) { USBD_StatusTypeDef ret = USBD_OK; /* Upon Reset call user call back */ pdev->dev_state = USBD_STATE_DEFAULT; pdev->ep0_state = USBD_EP0_IDLE; pdev->dev_config = 0U; pdev->dev_remote_wakeup = 0U; pdev->dev_test_mode = 0U; #ifdef USE_USBD_COMPOSITE /* Parse the table of classes in use */ for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++) { /* Check if current class is in use */ if ((pdev->tclasslist[i].Active) == 1U) { if (pdev->pClass[i] != NULL) { pdev->classId = i; /* Clear configuration and De-initialize the Class process*/ if (pdev->pClass[i]->DeInit != NULL) { if (pdev->pClass[i]->DeInit(pdev, (uint8_t)pdev->dev_config) != USBD_OK) { ret = USBD_FAIL; }if (pdev->pClass[i]->DeInit(pdev, (uint8_t)pdev->dev_config) != USBD_OK) { ... } }if (pdev->pClass[i]->DeInit != NULL) { ... } }if (pdev->pClass[i] != NULL) { ... } }if ((pdev->tclasslist[i].Active) == 1U) { ... } }for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++) { ... } /* ... */#else if (pdev->pClass[0] != NULL) { if (pdev->pClass[0]->DeInit != NULL) { if (pdev->pClass[0]->DeInit(pdev, (uint8_t)pdev->dev_config) != USBD_OK) { ret = USBD_FAIL; }if (pdev->pClass[0]->DeInit(pdev, (uint8_t)pdev->dev_config) != USBD_OK) { ... } }if (pdev->pClass[0]->DeInit != NULL) { ... } }if (pdev->pClass[0] != NULL) { ... } /* ... */#endif /* USE_USBD_COMPOSITE */ /* Open EP0 OUT */ (void)USBD_LL_OpenEP(pdev, 0x00U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE); pdev->ep_out[0x00U & 0xFU].is_used = 1U; pdev->ep_out[0].maxpacket = USB_MAX_EP0_SIZE; /* Open EP0 IN */ (void)USBD_LL_OpenEP(pdev, 0x80U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE); pdev->ep_in[0x80U & 0xFU].is_used = 1U; pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE; return ret; }{ ... } /** * @brief USBD_LL_SetSpeed * Handle Reset event * @param pdev: device instance * @retval status *//* ... */ USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed) { pdev->dev_speed = speed; return USBD_OK; }{ ... } /** * @brief USBD_LL_Suspend * Handle Suspend event * @param pdev: device instance * @retval status *//* ... */ USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev) { if (pdev->dev_state != USBD_STATE_SUSPENDED) { pdev->dev_old_state = pdev->dev_state; }if (pdev->dev_state != USBD_STATE_SUSPENDED) { ... } pdev->dev_state = USBD_STATE_SUSPENDED; return USBD_OK; }{ ... } /** * @brief USBD_LL_Resume * Handle Resume event * @param pdev: device instance * @retval status *//* ... */ USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev) { if (pdev->dev_state == USBD_STATE_SUSPENDED) { pdev->dev_state = pdev->dev_old_state; }if (pdev->dev_state == USBD_STATE_SUSPENDED) { ... } return USBD_OK; }{ ... } /** * @brief USBD_LL_SOF * Handle SOF event * @param pdev: device instance * @retval status *//* ... */ USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev) { /* The SOF event can be distributed for all classes that support it */ if (pdev->dev_state == USBD_STATE_CONFIGURED) { #ifdef USE_USBD_COMPOSITE /* Parse the table of classes in use */ for (uint32_t i = 0; i < USBD_MAX_SUPPORTED_CLASS; i++) { /* Check if current class is in use */ if ((pdev->tclasslist[i].Active) == 1U) { if (pdev->pClass[i] != NULL) { if (pdev->pClass[i]->SOF != NULL) { pdev->classId = i; (void)pdev->pClass[i]->SOF(pdev); }if (pdev->pClass[i]->SOF != NULL) { ... } }if (pdev->pClass[i] != NULL) { ... } }if ((pdev->tclasslist[i].Active) == 1U) { ... } }for (uint32_t i = 0; i < USBD_MAX_SUPPORTED_CLASS; i++) { ... } /* ... */#else if (pdev->pClass[0] != NULL) { if (pdev->pClass[0]->SOF != NULL) { (void)pdev->pClass[0]->SOF(pdev); }if (pdev->pClass[0]->SOF != NULL) { ... } }if (pdev->pClass[0] != NULL) { ... } /* ... */#endif /* USE_USBD_COMPOSITE */ }if (pdev->dev_state == USBD_STATE_CONFIGURED) { ... } return USBD_OK; }{ ... } /** * @brief USBD_LL_IsoINIncomplete * Handle iso in incomplete event * @param pdev: device instance * @retval status *//* ... */ USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum) { if (pdev->pClass[pdev->classId] == NULL) { return USBD_FAIL; }if (pdev->pClass[pdev->classId] == NULL) { ... } if (pdev->dev_state == USBD_STATE_CONFIGURED) { if (pdev->pClass[pdev->classId]->IsoINIncomplete != NULL) { (void)pdev->pClass[pdev->classId]->IsoINIncomplete(pdev, epnum); }if (pdev->pClass[pdev->classId]->IsoINIncomplete != NULL) { ... } }if (pdev->dev_state == USBD_STATE_CONFIGURED) { ... } return USBD_OK; }{ ... } /** * @brief USBD_LL_IsoOUTIncomplete * Handle iso out incomplete event * @param pdev: device instance * @retval status *//* ... */ USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum) { if (pdev->pClass[pdev->classId] == NULL) { return USBD_FAIL; }if (pdev->pClass[pdev->classId] == NULL) { ... } if (pdev->dev_state == USBD_STATE_CONFIGURED) { if (pdev->pClass[pdev->classId]->IsoOUTIncomplete != NULL) { (void)pdev->pClass[pdev->classId]->IsoOUTIncomplete(pdev, epnum); }if (pdev->pClass[pdev->classId]->IsoOUTIncomplete != NULL) { ... } }if (pdev->dev_state == USBD_STATE_CONFIGURED) { ... } return USBD_OK; }{ ... } /** * @brief USBD_LL_DevConnected * Handle device connection event * @param pdev: device instance * @retval status *//* ... */ USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev) { /* Prevent unused argument compilation warning */ UNUSED(pdev); return USBD_OK; }{ ... } /** * @brief USBD_LL_DevDisconnected * Handle device disconnection event * @param pdev: device instance * @retval status *//* ... */ USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev) { USBD_StatusTypeDef ret = USBD_OK; /* Free Class Resources */ pdev->dev_state = USBD_STATE_DEFAULT; #ifdef USE_USBD_COMPOSITE /* Parse the table of classes in use */ for (uint32_t i = 0; i < USBD_MAX_SUPPORTED_CLASS; i++) { /* Check if current class is in use */ if ((pdev->tclasslist[i].Active) == 1U) { if (pdev->pClass[i] != NULL) { pdev->classId = i; /* Clear configuration and De-initialize the Class process*/ if (pdev->pClass[i]->DeInit(pdev, (uint8_t)pdev->dev_config) != 0U) { ret = USBD_FAIL; }if (pdev->pClass[i]->DeInit(pdev, (uint8_t)pdev->dev_config) != 0U) { ... } }if (pdev->pClass[i] != NULL) { ... } }if ((pdev->tclasslist[i].Active) == 1U) { ... } }for (uint32_t i = 0; i < USBD_MAX_SUPPORTED_CLASS; i++) { ... } /* ... */#else if (pdev->pClass[0] != NULL) { if (pdev->pClass[0]->DeInit(pdev, (uint8_t)pdev->dev_config) != 0U) { ret = USBD_FAIL; }if (pdev->pClass[0]->DeInit(pdev, (uint8_t)pdev->dev_config) != 0U) { ... } }if (pdev->pClass[0] != NULL) { ... } /* ... */#endif /* USE_USBD_COMPOSITE */ return ret; }{ ... } /** * @brief USBD_CoreFindIF * return the class index relative to the selected interface * @param pdev: device instance * @param index : selected interface number * @retval index of the class using the selected interface number. OxFF if no class found. *//* ... */ uint8_t USBD_CoreFindIF(USBD_HandleTypeDef *pdev, uint8_t index) { #ifdef USE_USBD_COMPOSITE /* Parse the table of classes in use */ for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++) { /* Check if current class is in use */ if ((pdev->tclasslist[i].Active) == 1U) { /* Parse all interfaces listed in the current class */ for (uint32_t j = 0U; j < pdev->tclasslist[i].NumIf; j++) { /* Check if requested Interface matches the current class interface */ if (pdev->tclasslist[i].Ifs[j] == index) { if (pdev->pClass[i]->Setup != NULL) { return (uint8_t)i; }if (pdev->pClass[i]->Setup != NULL) { ... } }if (pdev->tclasslist[i].Ifs[j] == index) { ... } }for (uint32_t j = 0U; j < pdev->tclasslist[i].NumIf; j++) { ... } }if ((pdev->tclasslist[i].Active) == 1U) { ... } }for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++) { ... } return 0xFFU;/* ... */ #else UNUSED(pdev); UNUSED(index); return 0x00U;/* ... */ #endif /* USE_USBD_COMPOSITE */ }{ ... } /** * @brief USBD_CoreFindEP * return the class index relative to the selected endpoint * @param pdev: device instance * @param index : selected endpoint number * @retval index of the class using the selected endpoint number. 0xFF if no class found. *//* ... */ uint8_t USBD_CoreFindEP(USBD_HandleTypeDef *pdev, uint8_t index) { #ifdef USE_USBD_COMPOSITE /* Parse the table of classes in use */ for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++) { /* Check if current class is in use */ if ((pdev->tclasslist[i].Active) == 1U) { /* Parse all endpoints listed in the current class */ for (uint32_t j = 0U; j < pdev->tclasslist[i].NumEps; j++) { /* Check if requested endpoint matches the current class endpoint */ if (pdev->tclasslist[i].Eps[j].add == index) { if (pdev->pClass[i]->Setup != NULL) { return (uint8_t)i; }if (pdev->pClass[i]->Setup != NULL) { ... } }if (pdev->tclasslist[i].Eps[j].add == index) { ... } }for (uint32_t j = 0U; j < pdev->tclasslist[i].NumEps; j++) { ... } }if ((pdev->tclasslist[i].Active) == 1U) { ... } }for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++) { ... } return 0xFFU;/* ... */ #else UNUSED(pdev); UNUSED(index); return 0x00U;/* ... */ #endif /* USE_USBD_COMPOSITE */ }{ ... } #ifdef USE_USBD_COMPOSITE /** * @brief USBD_CoreGetEPAdd * Get the endpoint address relative to a selected class * @param pdev: device instance * @param ep_dir: USBD_EP_IN or USBD_EP_OUT * @param ep_type: USBD_EP_TYPE_CTRL, USBD_EP_TYPE_ISOC, USBD_EP_TYPE_BULK or USBD_EP_TYPE_INTR * @param ClassId: The Class ID * @retval Address of the selected endpoint or 0xFFU if no endpoint found. *//* ... */ uint8_t USBD_CoreGetEPAdd(USBD_HandleTypeDef *pdev, uint8_t ep_dir, uint8_t ep_type, uint8_t ClassId) { uint8_t idx; /* Find the EP address in the selected class table */ for (idx = 0; idx < pdev->tclasslist[ClassId].NumEps; idx++) { if (((pdev->tclasslist[ClassId].Eps[idx].add & USBD_EP_IN) == ep_dir) && \ (pdev->tclasslist[ClassId].Eps[idx].type == ep_type) && \ (pdev->tclasslist[ClassId].Eps[idx].is_used != 0U)) { return (pdev->tclasslist[ClassId].Eps[idx].add); }if (((pdev->tclasslist[ClassId].Eps[idx].add & USBD_EP_IN) == ep_dir) && \ (pdev->tclasslist[ClassId].Eps[idx].type == ep_type) && \ (pdev->tclasslist[ClassId].Eps[idx].is_used != 0U)) { ... } }for (idx = 0; idx < pdev->tclasslist[ClassId].NumEps; idx++) { ... } /* If reaching this point, then no endpoint was found */ return 0xFFU; }USBD_CoreGetEPAdd (USBD_HandleTypeDef *pdev, uint8_t ep_dir, uint8_t ep_type, uint8_t ClassId) { ... } /* ... */#endif /* USE_USBD_COMPOSITE */ /** * @brief USBD_GetEpDesc * This function return the Endpoint descriptor * @param pdev: device instance * @param pConfDesc: pointer to Bos descriptor * @param EpAddr: endpoint address * @retval pointer to video endpoint descriptor *//* ... */ void *USBD_GetEpDesc(uint8_t *pConfDesc, uint8_t EpAddr) { USBD_DescHeaderTypeDef *pdesc = (USBD_DescHeaderTypeDef *)(void *)pConfDesc; USBD_ConfigDescTypeDef *desc = (USBD_ConfigDescTypeDef *)(void *)pConfDesc; USBD_EpDescTypeDef *pEpDesc = NULL; uint16_t ptr; if (desc->wTotalLength > desc->bLength) { ptr = desc->bLength; while (ptr < desc->wTotalLength) { pdesc = USBD_GetNextDesc((uint8_t *)pdesc, &ptr); if (pdesc->bDescriptorType == USB_DESC_TYPE_ENDPOINT) { pEpDesc = (USBD_EpDescTypeDef *)(void *)pdesc; if (pEpDesc->bEndpointAddress == EpAddr) { break; }if (pEpDesc->bEndpointAddress == EpAddr) { ... } else { pEpDesc = NULL; }else { ... } }if (pdesc->bDescriptorType == USB_DESC_TYPE_ENDPOINT) { ... } }while (ptr < desc->wTotalLength) { ... } }if (desc->wTotalLength > desc->bLength) { ... } return (void *)pEpDesc; }{ ... } /** * @brief USBD_GetNextDesc * This function return the next descriptor header * @param buf: Buffer where the descriptor is available * @param ptr: data pointer inside the descriptor * @retval next header *//* ... */ USBD_DescHeaderTypeDef *USBD_GetNextDesc(uint8_t *pbuf, uint16_t *ptr) { USBD_DescHeaderTypeDef *pnext = (USBD_DescHeaderTypeDef *)(void *)pbuf; *ptr += pnext->bLength; pnext = (USBD_DescHeaderTypeDef *)(void *)(pbuf + pnext->bLength); return (pnext); }{ ... } /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */ Includes
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.