STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
usbd_ctlreq.c
Go to the documentation of this file.
1/**
2 ******************************************************************************
3 * @file usbd_req.c
4 * @author MCD Application Team
5 * @brief This file provides the standard USB requests following chapter 9.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2015 STMicroelectronics.
10 * All rights reserved.
11 *
12 * This software is licensed under terms that can be found in the LICENSE file
13 * in the root directory of this software component.
14 * If no LICENSE file comes with this software, it is provided AS-IS.
15 *
16 ******************************************************************************
17 */
18
19/* Includes ------------------------------------------------------------------*/
20#include "usbd_ctlreq.h"
21#include "usbd_ioreq.h"
22
23#ifdef USE_USBD_COMPOSITE
24#include "usbd_composite_builder.h"
25#endif /* USE_USBD_COMPOSITE */
26
27/** @addtogroup STM32_USBD_STATE_DEVICE_LIBRARY
28 * @{
29 */
30
31
32/** @defgroup USBD_REQ
33 * @brief USB standard requests module
34 * @{
35 */
36
37/** @defgroup USBD_REQ_Private_TypesDefinitions
38 * @{
39 */
40
41/**
42 * @}
43 */
44
45
46/** @defgroup USBD_REQ_Private_Defines
47 * @{
48 */
49#ifndef USBD_MAX_STR_DESC_SIZ
50#define USBD_MAX_STR_DESC_SIZ 64U
51#endif /* USBD_MAX_STR_DESC_SIZ */
52/**
53 * @}
54 */
55
56
57/** @defgroup USBD_REQ_Private_Macros
58 * @{
59 */
60
61/**
62 * @}
63 */
64
65
66/** @defgroup USBD_REQ_Private_Variables
67 * @{
68 */
69
70/**
71 * @}
72 */
73
74
75/** @defgroup USBD_REQ_Private_FunctionPrototypes
76 * @{
77 */
85static uint8_t USBD_GetLen(uint8_t *buf);
86
87/**
88 * @}
89 */
90
91
92/** @defgroup USBD_REQ_Private_Functions
93 * @{
94 */
95
96
97/**
98 * @brief USBD_StdDevReq
99 * Handle standard usb device requests
100 * @param pdev: device instance
101 * @param req: usb request
102 * @retval status
103 */
105{
107
108 switch (req->bmRequest & USB_REQ_TYPE_MASK)
109 {
112 ret = (USBD_StatusTypeDef)pdev->pClass[pdev->classId]->Setup(pdev, req);
113 break;
114
116 switch (req->bRequest)
117 {
119 USBD_GetDescriptor(pdev, req);
120 break;
121
123 USBD_SetAddress(pdev, req);
124 break;
125
127 ret = USBD_SetConfig(pdev, req);
128 break;
129
131 USBD_GetConfig(pdev, req);
132 break;
133
135 USBD_GetStatus(pdev, req);
136 break;
137
139 USBD_SetFeature(pdev, req);
140 break;
141
143 USBD_ClrFeature(pdev, req);
144 break;
145
146 default:
147 USBD_CtlError(pdev, req);
148 break;
149 }
150 break;
151
152 default:
153 USBD_CtlError(pdev, req);
154 break;
155 }
156
157 return ret;
158}
159
160/**
161 * @brief USBD_StdItfReq
162 * Handle standard usb interface requests
163 * @param pdev: device instance
164 * @param req: usb request
165 * @retval status
166 */
168{
170 uint8_t idx;
171
172 switch (req->bmRequest & USB_REQ_TYPE_MASK)
173 {
177 switch (pdev->dev_state)
178 {
182
183 if (LOBYTE(req->wIndex) <= USBD_MAX_NUM_INTERFACES)
184 {
185 /* Get the class index relative to this interface */
186 idx = USBD_CoreFindIF(pdev, LOBYTE(req->wIndex));
187 if (((uint8_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS))
188 {
189 /* Call the class data out function to manage the request */
190 if (pdev->pClass[idx]->Setup != NULL)
191 {
192 pdev->classId = idx;
193 ret = (USBD_StatusTypeDef)(pdev->pClass[idx]->Setup(pdev, req));
194 }
195 else
196 {
197 /* should never reach this condition */
198 ret = USBD_FAIL;
199 }
200 }
201 else
202 {
203 /* No relative interface found */
204 ret = USBD_FAIL;
205 }
206
207 if ((req->wLength == 0U) && (ret == USBD_OK))
208 {
209 (void)USBD_CtlSendStatus(pdev);
210 }
211 }
212 else
213 {
214 USBD_CtlError(pdev, req);
215 }
216 break;
217
218 default:
219 USBD_CtlError(pdev, req);
220 break;
221 }
222 break;
223
224 default:
225 USBD_CtlError(pdev, req);
226 break;
227 }
228
229 return ret;
230}
231
232/**
233 * @brief USBD_StdEPReq
234 * Handle standard usb endpoint requests
235 * @param pdev: device instance
236 * @param req: usb request
237 * @retval status
238 */
240{
242 uint8_t ep_addr;
243 uint8_t idx;
245
246 ep_addr = LOBYTE(req->wIndex);
247
248 switch (req->bmRequest & USB_REQ_TYPE_MASK)
249 {
252 /* Get the class index relative to this endpoint */
253 idx = USBD_CoreFindEP(pdev, ep_addr);
254 if (((uint8_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS))
255 {
256 pdev->classId = idx;
257 /* Call the class data out function to manage the request */
258 if (pdev->pClass[idx]->Setup != NULL)
259 {
260 ret = (USBD_StatusTypeDef)pdev->pClass[idx]->Setup(pdev, req);
261 }
262 }
263 break;
264
266 switch (req->bRequest)
267 {
269 switch (pdev->dev_state)
270 {
272 if ((ep_addr != 0x00U) && (ep_addr != 0x80U))
273 {
274 (void)USBD_LL_StallEP(pdev, ep_addr);
275 (void)USBD_LL_StallEP(pdev, 0x80U);
276 }
277 else
278 {
279 USBD_CtlError(pdev, req);
280 }
281 break;
282
284 if (req->wValue == USB_FEATURE_EP_HALT)
285 {
286 if ((ep_addr != 0x00U) && (ep_addr != 0x80U) && (req->wLength == 0x00U))
287 {
288 (void)USBD_LL_StallEP(pdev, ep_addr);
289 }
290 }
291 (void)USBD_CtlSendStatus(pdev);
292
293 break;
294
295 default:
296 USBD_CtlError(pdev, req);
297 break;
298 }
299 break;
300
302
303 switch (pdev->dev_state)
304 {
306 if ((ep_addr != 0x00U) && (ep_addr != 0x80U))
307 {
308 (void)USBD_LL_StallEP(pdev, ep_addr);
309 (void)USBD_LL_StallEP(pdev, 0x80U);
310 }
311 else
312 {
313 USBD_CtlError(pdev, req);
314 }
315 break;
316
318 if (req->wValue == USB_FEATURE_EP_HALT)
319 {
320 if ((ep_addr & 0x7FU) != 0x00U)
321 {
322 (void)USBD_LL_ClearStallEP(pdev, ep_addr);
323 }
324 (void)USBD_CtlSendStatus(pdev);
325
326 /* Get the class index relative to this interface */
327 idx = USBD_CoreFindEP(pdev, ep_addr);
328 if (((uint8_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS))
329 {
330 pdev->classId = idx;
331 /* Call the class data out function to manage the request */
332 if (pdev->pClass[idx]->Setup != NULL)
333 {
334 ret = (USBD_StatusTypeDef)(pdev->pClass[idx]->Setup(pdev, req));
335 }
336 }
337 }
338 break;
339
340 default:
341 USBD_CtlError(pdev, req);
342 break;
343 }
344 break;
345
347 switch (pdev->dev_state)
348 {
350 if ((ep_addr != 0x00U) && (ep_addr != 0x80U))
351 {
352 USBD_CtlError(pdev, req);
353 break;
354 }
355 pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU] : \
356 &pdev->ep_out[ep_addr & 0x7FU];
357
358 pep->status = 0x0000U;
359
360 (void)USBD_CtlSendData(pdev, (uint8_t *)&pep->status, 2U);
361 break;
362
364 if ((ep_addr & 0x80U) == 0x80U)
365 {
366 if (pdev->ep_in[ep_addr & 0xFU].is_used == 0U)
367 {
368 USBD_CtlError(pdev, req);
369 break;
370 }
371 }
372 else
373 {
374 if (pdev->ep_out[ep_addr & 0xFU].is_used == 0U)
375 {
376 USBD_CtlError(pdev, req);
377 break;
378 }
379 }
380
381 pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU] : \
382 &pdev->ep_out[ep_addr & 0x7FU];
383
384 if ((ep_addr == 0x00U) || (ep_addr == 0x80U))
385 {
386 pep->status = 0x0000U;
387 }
388 else if (USBD_LL_IsStallEP(pdev, ep_addr) != 0U)
389 {
390 pep->status = 0x0001U;
391 }
392 else
393 {
394 pep->status = 0x0000U;
395 }
396
397 (void)USBD_CtlSendData(pdev, (uint8_t *)&pep->status, 2U);
398 break;
399
400 default:
401 USBD_CtlError(pdev, req);
402 break;
403 }
404 break;
405
406 default:
407 USBD_CtlError(pdev, req);
408 break;
409 }
410 break;
411
412 default:
413 USBD_CtlError(pdev, req);
414 break;
415 }
416
417 return ret;
418}
419
420
421/**
422 * @brief USBD_GetDescriptor
423 * Handle Get Descriptor requests
424 * @param pdev: device instance
425 * @param req: usb request
426 * @retval None
427 */
429{
430 uint16_t len = 0U;
431 uint8_t *pbuf = NULL;
432 uint8_t err = 0U;
433
434 switch (req->wValue >> 8)
435 {
436#if ((USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1U))
438 if (pdev->pDesc->GetBOSDescriptor != NULL)
439 {
440 pbuf = pdev->pDesc->GetBOSDescriptor(pdev->dev_speed, &len);
441 }
442 else
443 {
444 USBD_CtlError(pdev, req);
445 err++;
446 }
447 break;
448#endif /* (USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1U) */
450 pbuf = pdev->pDesc->GetDeviceDescriptor(pdev->dev_speed, &len);
451 break;
452
454 if (pdev->dev_speed == USBD_SPEED_HIGH)
455 {
456#ifdef USE_USBD_COMPOSITE
457 if ((uint8_t)(pdev->NumClasses) > 0U)
458 {
459 pbuf = (uint8_t *)USBD_CMPSIT.GetHSConfigDescriptor(&len);
460 }
461 else
462#endif /* USE_USBD_COMPOSITE */
463 {
464 pbuf = (uint8_t *)pdev->pClass[0]->GetHSConfigDescriptor(&len);
465 }
467 }
468 else
469 {
470#ifdef USE_USBD_COMPOSITE
471 if ((uint8_t)(pdev->NumClasses) > 0U)
472 {
473 pbuf = (uint8_t *)USBD_CMPSIT.GetFSConfigDescriptor(&len);
474 }
475 else
476#endif /* USE_USBD_COMPOSITE */
477 {
478 pbuf = (uint8_t *)pdev->pClass[0]->GetFSConfigDescriptor(&len);
479 }
481 }
482 break;
483
485 switch ((uint8_t)(req->wValue))
486 {
488 if (pdev->pDesc->GetLangIDStrDescriptor != NULL)
489 {
490 pbuf = pdev->pDesc->GetLangIDStrDescriptor(pdev->dev_speed, &len);
491 }
492 else
493 {
494 USBD_CtlError(pdev, req);
495 err++;
496 }
497 break;
498
499 case USBD_IDX_MFC_STR:
501 {
502 pbuf = pdev->pDesc->GetManufacturerStrDescriptor(pdev->dev_speed, &len);
503 }
504 else
505 {
506 USBD_CtlError(pdev, req);
507 err++;
508 }
509 break;
510
512 if (pdev->pDesc->GetProductStrDescriptor != NULL)
513 {
514 pbuf = pdev->pDesc->GetProductStrDescriptor(pdev->dev_speed, &len);
515 }
516 else
517 {
518 USBD_CtlError(pdev, req);
519 err++;
520 }
521 break;
522
524 if (pdev->pDesc->GetSerialStrDescriptor != NULL)
525 {
526 pbuf = pdev->pDesc->GetSerialStrDescriptor(pdev->dev_speed, &len);
527 }
528 else
529 {
530 USBD_CtlError(pdev, req);
531 err++;
532 }
533 break;
534
537 {
538 pbuf = pdev->pDesc->GetConfigurationStrDescriptor(pdev->dev_speed, &len);
539 }
540 else
541 {
542 USBD_CtlError(pdev, req);
543 err++;
544 }
545 break;
546
549 {
550 pbuf = pdev->pDesc->GetInterfaceStrDescriptor(pdev->dev_speed, &len);
551 }
552 else
553 {
554 USBD_CtlError(pdev, req);
555 err++;
556 }
557 break;
558
559 default:
560#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
561 pbuf = NULL;
562
563 for (uint32_t idx = 0U; (idx < pdev->NumClasses); idx++)
564 {
565 if (pdev->pClass[idx]->GetUsrStrDescriptor != NULL)
566 {
567 pdev->classId = idx;
568 pbuf = pdev->pClass[idx]->GetUsrStrDescriptor(pdev, LOBYTE(req->wValue), &len);
569
570 if (pbuf == NULL) /* This means that no class recognized the string index */
571 {
572 continue;
573 }
574 else
575 {
576 break;
577 }
578 }
579 }
580#endif /* USBD_SUPPORT_USER_STRING_DESC */
581
582#if (USBD_CLASS_USER_STRING_DESC == 1U)
583 if (pdev->pDesc->GetUserStrDescriptor != NULL)
584 {
585 pbuf = pdev->pDesc->GetUserStrDescriptor(pdev->dev_speed, LOBYTE(req->wValue), &len);
586 }
587 else
588 {
589 USBD_CtlError(pdev, req);
590 err++;
591 }
592#endif /* USBD_SUPPORT_USER_STRING_DESC */
593
594#if ((USBD_CLASS_USER_STRING_DESC == 0U) && (USBD_SUPPORT_USER_STRING_DESC == 0U))
595 USBD_CtlError(pdev, req);
596 err++;
597#endif /* (USBD_CLASS_USER_STRING_DESC == 0U) && (USBD_SUPPORT_USER_STRING_DESC == 0U) */
598 break;
599 }
600 break;
601
603 if (pdev->dev_speed == USBD_SPEED_HIGH)
604 {
605#ifdef USE_USBD_COMPOSITE
606 if ((uint8_t)(pdev->NumClasses) > 0U)
607 {
608 pbuf = (uint8_t *)USBD_CMPSIT.GetDeviceQualifierDescriptor(&len);
609 }
610 else
611#endif /* USE_USBD_COMPOSITE */
612 {
613 pbuf = (uint8_t *)pdev->pClass[0]->GetDeviceQualifierDescriptor(&len);
614 }
615 }
616 else
617 {
618 USBD_CtlError(pdev, req);
619 err++;
620 }
621 break;
622
624 if (pdev->dev_speed == USBD_SPEED_HIGH)
625 {
626#ifdef USE_USBD_COMPOSITE
627 if ((uint8_t)(pdev->NumClasses) > 0U)
628 {
629 pbuf = (uint8_t *)USBD_CMPSIT.GetOtherSpeedConfigDescriptor(&len);
630 }
631 else
632#endif /* USE_USBD_COMPOSITE */
633 {
634 pbuf = (uint8_t *)pdev->pClass[0]->GetOtherSpeedConfigDescriptor(&len);
635 }
637 }
638 else
639 {
640 USBD_CtlError(pdev, req);
641 err++;
642 }
643 break;
644
645 default:
646 USBD_CtlError(pdev, req);
647 err++;
648 break;
649 }
650
651 if (err != 0U)
652 {
653 return;
654 }
655
656 if (req->wLength != 0U)
657 {
658 if (len != 0U)
659 {
660 len = MIN(len, req->wLength);
661 (void)USBD_CtlSendData(pdev, pbuf, len);
662 }
663 else
664 {
665 USBD_CtlError(pdev, req);
666 }
667 }
668 else
669 {
670 (void)USBD_CtlSendStatus(pdev);
671 }
672}
673
674
675/**
676 * @brief USBD_SetAddress
677 * Set device address
678 * @param pdev: device instance
679 * @param req: usb request
680 * @retval None
681 */
683{
684 uint8_t dev_addr;
685
686 if ((req->wIndex == 0U) && (req->wLength == 0U) && (req->wValue < 128U))
687 {
688 dev_addr = (uint8_t)(req->wValue) & 0x7FU;
689
690 if (pdev->dev_state == USBD_STATE_CONFIGURED)
691 {
692 USBD_CtlError(pdev, req);
693 }
694 else
695 {
696 pdev->dev_address = dev_addr;
697 (void)USBD_LL_SetUSBAddress(pdev, dev_addr);
698 (void)USBD_CtlSendStatus(pdev);
699
700 if (dev_addr != 0U)
701 {
703 }
704 else
705 {
707 }
708 }
709 }
710 else
711 {
712 USBD_CtlError(pdev, req);
713 }
714}
715
716/**
717 * @brief USBD_SetConfig
718 * Handle Set device configuration request
719 * @param pdev: device instance
720 * @param req: usb request
721 * @retval status
722 */
724{
726 static uint8_t cfgidx;
727
728 cfgidx = (uint8_t)(req->wValue);
729
730 if (cfgidx > USBD_MAX_NUM_CONFIGURATION)
731 {
732 USBD_CtlError(pdev, req);
733 return USBD_FAIL;
734 }
735
736 switch (pdev->dev_state)
737 {
739 if (cfgidx != 0U)
740 {
741 pdev->dev_config = cfgidx;
742
743 ret = USBD_SetClassConfig(pdev, cfgidx);
744
745 if (ret != USBD_OK)
746 {
747 USBD_CtlError(pdev, req);
749 }
750 else
751 {
752 (void)USBD_CtlSendStatus(pdev);
754
755#if (USBD_USER_REGISTER_CALLBACK == 1U)
756 if (pdev->DevStateCallback != NULL)
757 {
758 pdev->DevStateCallback(USBD_STATE_CONFIGURED, cfgidx);
759 }
760#endif /* USBD_USER_REGISTER_CALLBACK */
761 }
762 }
763 else
764 {
765 (void)USBD_CtlSendStatus(pdev);
766 }
767 break;
768
770 if (cfgidx == 0U)
771 {
773 pdev->dev_config = cfgidx;
774 (void)USBD_ClrClassConfig(pdev, cfgidx);
775 (void)USBD_CtlSendStatus(pdev);
776 }
777 else if (cfgidx != pdev->dev_config)
778 {
779 /* Clear old configuration */
780 (void)USBD_ClrClassConfig(pdev, (uint8_t)pdev->dev_config);
781
782 /* set new configuration */
783 pdev->dev_config = cfgidx;
784
785 ret = USBD_SetClassConfig(pdev, cfgidx);
786
787 if (ret != USBD_OK)
788 {
789 USBD_CtlError(pdev, req);
790 (void)USBD_ClrClassConfig(pdev, (uint8_t)pdev->dev_config);
792 }
793 else
794 {
795 (void)USBD_CtlSendStatus(pdev);
796 }
797 }
798 else
799 {
800 (void)USBD_CtlSendStatus(pdev);
801 }
802 break;
803
804 default:
805 USBD_CtlError(pdev, req);
806 (void)USBD_ClrClassConfig(pdev, cfgidx);
807 ret = USBD_FAIL;
808 break;
809 }
810
811 return ret;
812}
813
814/**
815 * @brief USBD_GetConfig
816 * Handle Get device configuration request
817 * @param pdev: device instance
818 * @param req: usb request
819 * @retval None
820 */
822{
823 if (req->wLength != 1U)
824 {
825 USBD_CtlError(pdev, req);
826 }
827 else
828 {
829 switch (pdev->dev_state)
830 {
833 pdev->dev_default_config = 0U;
834 (void)USBD_CtlSendData(pdev, (uint8_t *)&pdev->dev_default_config, 1U);
835 break;
836
838 (void)USBD_CtlSendData(pdev, (uint8_t *)&pdev->dev_config, 1U);
839 break;
840
841 default:
842 USBD_CtlError(pdev, req);
843 break;
844 }
845 }
846}
847
848/**
849 * @brief USBD_GetStatus
850 * Handle Get Status request
851 * @param pdev: device instance
852 * @param req: usb request
853 * @retval None
854 */
856{
857 switch (pdev->dev_state)
858 {
862 if (req->wLength != 0x2U)
863 {
864 USBD_CtlError(pdev, req);
865 break;
866 }
867
868#if (USBD_SELF_POWERED == 1U)
870#else
871 pdev->dev_config_status = 0U;
872#endif /* USBD_SELF_POWERED */
873
874 if (pdev->dev_remote_wakeup != 0U)
875 {
877 }
878
879 (void)USBD_CtlSendData(pdev, (uint8_t *)&pdev->dev_config_status, 2U);
880 break;
881
882 default:
883 USBD_CtlError(pdev, req);
884 break;
885 }
886}
887
888
889/**
890 * @brief USBD_SetFeature
891 * Handle Set device feature request
892 * @param pdev: device instance
893 * @param req: usb request
894 * @retval None
895 */
897{
898 if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
899 {
900 pdev->dev_remote_wakeup = 1U;
901 (void)USBD_CtlSendStatus(pdev);
902 }
903 else if (req->wValue == USB_FEATURE_TEST_MODE)
904 {
905 pdev->dev_test_mode = (uint8_t)(req->wIndex >> 8);
906 (void)USBD_CtlSendStatus(pdev);
907 }
908 else
909 {
910 USBD_CtlError(pdev, req);
911 }
912}
913
914
915/**
916 * @brief USBD_ClrFeature
917 * Handle clear device feature request
918 * @param pdev: device instance
919 * @param req: usb request
920 * @retval None
921 */
923{
924 switch (pdev->dev_state)
925 {
929 if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
930 {
931 pdev->dev_remote_wakeup = 0U;
932 (void)USBD_CtlSendStatus(pdev);
933 }
934 break;
935
936 default:
937 USBD_CtlError(pdev, req);
938 break;
939 }
940}
941
942
943/**
944 * @brief USBD_ParseSetupRequest
945 * Copy buffer into setup structure
946 * @param req: usb request
947 * @param pdata: setup data pointer
948 * @retval None
949 */
951{
952 uint8_t *pbuff = pdata;
953
954 req->bmRequest = *(uint8_t *)(pbuff);
955
956 pbuff++;
957 req->bRequest = *(uint8_t *)(pbuff);
958
959 pbuff++;
960 req->wValue = SWAPBYTE(pbuff);
961
962 pbuff++;
963 pbuff++;
964 req->wIndex = SWAPBYTE(pbuff);
965
966 pbuff++;
967 pbuff++;
968 req->wLength = SWAPBYTE(pbuff);
969}
970
971
972/**
973 * @brief USBD_CtlError
974 * Handle USB low level Error
975 * @param pdev: device instance
976 * @param req: usb request
977 * @retval None
978 */
980{
981 UNUSED(req);
982
983 (void)USBD_LL_StallEP(pdev, 0x80U);
984 (void)USBD_LL_StallEP(pdev, 0U);
985}
986
987
988/**
989 * @brief USBD_GetString
990 * Convert Ascii string into unicode one
991 * @param desc : descriptor buffer
992 * @param unicode : Formatted string buffer (unicode)
993 * @param len : descriptor length
994 * @retval None
995 */
996void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len)
997{
998 uint8_t idx = 0U;
999 uint8_t *pdesc;
1000
1001 if (desc == NULL)
1002 {
1003 return;
1004 }
1005
1006 pdesc = desc;
1007 *len = MIN(USBD_MAX_STR_DESC_SIZ, ((uint16_t)USBD_GetLen(pdesc) * 2U) + 2U);
1008
1009 unicode[idx] = *(uint8_t *)len;
1010 idx++;
1011 unicode[idx] = USB_DESC_TYPE_STRING;
1012 idx++;
1013
1014 while (*pdesc != (uint8_t)'\0')
1015 {
1016 unicode[idx] = *pdesc;
1017 pdesc++;
1018 idx++;
1019
1020 unicode[idx] = 0U;
1021 idx++;
1022 }
1023}
1024
1025
1026/**
1027 * @brief USBD_GetLen
1028 * return the string length
1029 * @param buf : pointer to the ascii string buffer
1030 * @retval string length
1031 */
1032static uint8_t USBD_GetLen(uint8_t *buf)
1033{
1034 uint8_t len = 0U;
1035 uint8_t *pbuff = buf;
1036
1037 while (*pbuff != (uint8_t)'\0')
1038 {
1039 len++;
1040 pbuff++;
1041 }
1042
1043 return len;
1044}
1045/**
1046 * @}
1047 */
1048
1049
1050/**
1051 * @}
1052 */
1053
1054
1055/**
1056 * @}
1057 */
1058
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
USBD_ClrClassConfig Clear current configuration.
Definition usbd_core.c:505
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
USBD_SetClassConfig Configure device and start the interface.
Definition usbd_core.c:465
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
Returns Stall condition.
Definition usbd_conf.c:520
uint8_t USBD_CoreFindEP(USBD_HandleTypeDef *pdev, uint8_t index)
USBD_CoreFindEP return the class index relative to the selected endpoint.
Definition usbd_core.c:1086
uint8_t USBD_CoreFindIF(USBD_HandleTypeDef *pdev, uint8_t index)
USBD_CoreFindIF return the class index relative to the selected interface.
Definition usbd_core.c:1046
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
Sets a Stall condition on an endpoint of the Low Level Driver.
Definition usbd_conf.c:484
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr)
Assigns a USB address to the device.
Definition usbd_conf.c:540
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
Clears a Stall condition on an endpoint of the Low Level Driver.
Definition usbd_conf.c:502
#define LOBYTE(x)
Definition usbd_def.h:442
#define MIN(a, b)
Definition usbd_def.h:450
__STATIC_INLINE uint16_t SWAPBYTE(uint8_t *addr)
Definition usbd_def.h:425
struct _USBD_HandleTypeDef USBD_HandleTypeDef
struct usb_setup_req USBD_SetupReqTypedef
USBD_StatusTypeDef
Definition usbd_def.h:280
@ USBD_SPEED_HIGH
Definition usbd_def.h:273
@ USBD_FAIL
Definition usbd_def.h:284
@ USBD_OK
Definition usbd_def.h:281
USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev)
USBD_CtlSendStatus send zero lzngth packet on the ctl pipe.
Definition usbd_ioreq.c:173
USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len)
USBD_CtlSendData send data on the ctl pipe.
Definition usbd_ioreq.c:86
#define USBD_MAX_STR_DESC_SIZ
Definition usbd_ctlreq.c:50
static void USBD_SetAddress(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
USBD_SetAddress Set device address.
static void USBD_GetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
USBD_GetConfig Handle Get device configuration request.
static uint8_t USBD_GetLen(uint8_t *buf)
USBD_GetLen return the string length.
static USBD_StatusTypeDef USBD_SetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
USBD_SetConfig Handle Set device configuration request.
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
USBD_GetDescriptor Handle Get Descriptor requests.
static void USBD_SetFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
USBD_SetFeature Handle Set device feature request.
static void USBD_GetStatus(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
USBD_GetStatus Handle Get Status request.
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
USBD_ClrFeature Handle clear device feature request.
USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
USBD_StdEPReq Handle standard usb endpoint requests.
void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
USBD_CtlError Handle USB low level Error.
void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata)
USBD_ParseSetupRequest Copy buffer into setup structure.
void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len)
USBD_GetString Convert Ascii string into unicode one.
USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
USBD_StdItfReq Handle standard usb interface requests.
USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
USBD_StdDevReq Handle standard usb device requests.
#define NULL
Definition usbd_def.h:44
#define USBD_IDX_INTERFACE_STR
Definition usbd_def.h:107
#define USBD_MAX_NUM_INTERFACES
Definition usbd_def.h:48
#define USB_DESC_TYPE_DEVICE
Definition usbd_def.h:131
#define USB_FEATURE_REMOTE_WAKEUP
Definition usbd_def.h:145
#define USB_REQ_SET_FEATURE
Definition usbd_def.h:121
#define USB_DESC_TYPE_CONFIGURATION
Definition usbd_def.h:132
#define USB_REQ_TYPE_STANDARD
Definition usbd_def.h:109
#define USBD_IDX_CONFIG_STR
Definition usbd_def.h:106
#define USBD_STATE_DEFAULT
Definition usbd_def.h:160
#define USB_REQ_CLEAR_FEATURE
Definition usbd_def.h:120
#define USBD_STATE_CONFIGURED
Definition usbd_def.h:162
#define USB_REQ_TYPE_VENDOR
Definition usbd_def.h:111
#define USBD_IDX_LANGID_STR
Definition usbd_def.h:102
#define USB_REQ_SET_CONFIGURATION
Definition usbd_def.h:126
#define USB_CONFIG_REMOTE_WAKEUP
Definition usbd_def.h:141
#define USBD_IDX_PRODUCT_STR
Definition usbd_def.h:104
#define USBD_IDX_SERIAL_STR
Definition usbd_def.h:105
#define USB_REQ_TYPE_MASK
Definition usbd_def.h:112
#define USB_CONFIG_SELF_POWERED
Definition usbd_def.h:142
#define USB_FEATURE_TEST_MODE
Definition usbd_def.h:146
#define USB_FEATURE_EP_HALT
Definition usbd_def.h:144
#define USB_DESC_TYPE_BOS
Definition usbd_def.h:139
#define USB_REQ_GET_STATUS
Definition usbd_def.h:119
#define USB_REQ_SET_ADDRESS
Definition usbd_def.h:122
#define USBD_IDX_MFC_STR
Definition usbd_def.h:103
#define USB_DESC_TYPE_STRING
Definition usbd_def.h:133
#define USBD_MAX_SUPPORTED_CLASS
Definition usbd_def.h:61
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION
Definition usbd_def.h:137
#define USB_REQ_GET_DESCRIPTOR
Definition usbd_def.h:123
#define USB_REQ_GET_CONFIGURATION
Definition usbd_def.h:125
#define USBD_STATE_ADDRESSED
Definition usbd_def.h:161
#define USBD_MAX_NUM_CONFIGURATION
Definition usbd_def.h:52
#define USB_DESC_TYPE_DEVICE_QUALIFIER
Definition usbd_def.h:136
#define USB_REQ_TYPE_CLASS
Definition usbd_def.h:110
#define UNUSED(x)
uint8_t *(* GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length)
Definition usbd_def.h:296
uint8_t *(* GetSerialStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length)
Definition usbd_def.h:294
uint8_t *(* GetLangIDStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length)
Definition usbd_def.h:291
uint8_t *(* GetManufacturerStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length)
Definition usbd_def.h:292
uint8_t *(* GetProductStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length)
Definition usbd_def.h:293
uint8_t *(* GetConfigurationStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length)
Definition usbd_def.h:295
uint8_t *(* GetDeviceDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length)
Definition usbd_def.h:290
uint8_t *(* GetFSConfigDescriptor)(uint16_t *length)
Definition usbd_def.h:261
uint8_t *(* GetHSConfigDescriptor)(uint16_t *length)
Definition usbd_def.h:260
uint8_t *(* GetDeviceQualifierDescriptor)(uint16_t *length)
Definition usbd_def.h:263
uint8_t(* Setup)(struct _USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
Definition usbd_def.h:250
uint8_t *(* GetOtherSpeedConfigDescriptor)(uint16_t *length)
Definition usbd_def.h:262
uint32_t dev_default_config
Definition usbd_def.h:365
uint32_t dev_config_status
Definition usbd_def.h:366
USBD_EndpointTypeDef ep_in[16]
Definition usbd_def.h:368
USBD_EndpointTypeDef ep_out[16]
Definition usbd_def.h:369
uint32_t dev_remote_wakeup
Definition usbd_def.h:377
uint32_t dev_config
Definition usbd_def.h:364
USBD_DescriptorsTypeDef * pDesc
Definition usbd_def.h:381
uint32_t NumClasses
Definition usbd_def.h:390
uint8_t dev_test_mode
Definition usbd_def.h:376
USBD_SpeedTypeDef dev_speed
Definition usbd_def.h:367
USBD_ClassTypeDef * pClass[USBD_MAX_SUPPORTED_CLASS]
Definition usbd_def.h:382
__IO uint8_t dev_state
Definition usbd_def.h:372
Header file for the usbd_ioreq.c file.