udc.c
Go to the documentation of this file.
1 
33 /*
34  * Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
35  */
36 
37 #include "conf_usb.h"
38 #include "usb_protocol.h"
39 #include "udd.h"
40 #include "udc_desc.h"
41 #include "udi.h"
42 #include "udc.h"
43 
52 
57 
58 COMPILER_WORD_ALIGNED
60 static uint8_t udc_iface_setting = 0;
61 
63 COMPILER_WORD_ALIGNED
64 static uint8_t udc_num_configuration = 0;
65 
68 
71 
73 
74 
77 
81 COMPILER_WORD_ALIGNED
83  .desc.bLength = sizeof(usb_str_lgid_desc_t),
84  .desc.bDescriptorType = USB_DT_STRING,
85  .string = {LE16(USB_LANGID_EN_US)}
86 };
87 
93 #ifdef USB_DEVICE_MANUFACTURE_NAME
94 static uint8_t udc_string_manufacturer_name[] = USB_DEVICE_MANUFACTURE_NAME;
95 # define USB_DEVICE_MANUFACTURE_NAME_SIZE \
96  (sizeof(udc_string_manufacturer_name)-1)
97 #else
98 # define USB_DEVICE_MANUFACTURE_NAME_SIZE 0
99 #endif
100 
106 #ifdef USB_DEVICE_PRODUCT_NAME
107 static uint8_t udc_string_product_name[] = USB_DEVICE_PRODUCT_NAME;
108 # define USB_DEVICE_PRODUCT_NAME_SIZE (sizeof(udc_string_product_name)-1)
109 #else
110 # define USB_DEVICE_PRODUCT_NAME_SIZE 0
111 #endif
112 
122 #if defined USB_DEVICE_GET_SERIAL_NAME_POINTER
123  static const uint8_t *udc_get_string_serial_name(void)
124  {
125  return (const uint8_t *)USB_DEVICE_GET_SERIAL_NAME_POINTER;
126  }
127 # define USB_DEVICE_SERIAL_NAME_SIZE \
128  USB_DEVICE_GET_SERIAL_NAME_LENGTH
129 #elif defined USB_DEVICE_SERIAL_NAME
130  static const uint8_t *udc_get_string_serial_name(void)
131  {
132  return (const uint8_t *)USB_DEVICE_SERIAL_NAME;
133  }
134 # define USB_DEVICE_SERIAL_NAME_SIZE \
135  (sizeof(USB_DEVICE_SERIAL_NAME)-1)
136 #else
137 # define USB_DEVICE_SERIAL_NAME_SIZE 0
138 #endif
139 
148 };
149 COMPILER_WORD_ALIGNED
152 };
154 
156 {
157  return udc_ptr_iface;
158 }
159 
166 {
167  return (UDC_DESC_STORAGE usb_conf_desc_t *) ((uint8_t *)
168  udc_ptr_conf->desc +
170 }
171 
172 #if (0!=USB_DEVICE_MAX_EP)
173 
183 static usb_conf_desc_t UDC_DESC_STORAGE *udc_next_desc_in_iface(usb_conf_desc_t
184  UDC_DESC_STORAGE * desc, uint8_t desc_id)
185 {
186  usb_conf_desc_t UDC_DESC_STORAGE *ptr_eof_desc;
187 
188  ptr_eof_desc = udc_get_eof_conf();
189  // Go to next descriptor
190  desc = (UDC_DESC_STORAGE usb_conf_desc_t *) ((uint8_t *) desc +
191  desc->bLength);
192  // Check the end of configuration descriptor
193  while (ptr_eof_desc > desc) {
194  // If new interface descriptor is found,
195  // then it is the end of the current global interface descriptor
196  if (USB_DT_INTERFACE == desc->bDescriptorType) {
197  break; // End of global interface descriptor
198  }
199  if (desc_id == desc->bDescriptorType) {
200  return desc; // Specific descriptor found
201  }
202  // Go to next descriptor
203  desc = (UDC_DESC_STORAGE usb_conf_desc_t *) ((uint8_t *) desc +
204  desc->bLength);
205  }
206  return NULL; // No specific descriptor found
207 }
208 #endif
209 
219 static bool udc_update_iface_desc(uint8_t iface_num, uint8_t setting_num)
220 {
221  usb_conf_desc_t UDC_DESC_STORAGE *ptr_end_desc;
222 
223  if (0 == udc_num_configuration) {
224  return false;
225  }
226 
227  if (iface_num >= udc_ptr_conf->desc->bNumInterfaces) {
228  return false;
229  }
230 
231  // Start at the beginning of configuration descriptor
234 
235  // Check the end of configuration descriptor
236  ptr_end_desc = udc_get_eof_conf();
237  while (ptr_end_desc >
240  // A interface descriptor is found
241  // Check interface and alternate setting number
242  if ((iface_num == udc_ptr_iface->bInterfaceNumber) &&
243  (setting_num ==
245  return true; // Interface found
246  }
247  }
248  // Go to next descriptor
250  (uint8_t *) udc_ptr_iface +
252  }
253  return false; // Interface not found
254 }
255 
264 static bool udc_iface_disable(uint8_t iface_num)
265 {
266  udi_api_t UDC_DESC_STORAGE *udi_api;
267 
268  // Select first alternate setting of the interface
269  // to update udc_ptr_iface before call iface->getsetting()
270  if (!udc_update_iface_desc(iface_num, 0)) {
271  return false;
272  }
273 
274  // Select the interface with the current alternate setting
275  udi_api = udc_ptr_conf->udi_apis[iface_num];
276 
277 #if (0!=USB_DEVICE_MAX_EP)
278  if (!udc_update_iface_desc(iface_num, udi_api->getsetting())) {
279  return false;
280  }
281 
282  // Start at the beginning of interface descriptor
283  {
286  while (1) {
287  // Search Endpoint descriptor included in global interface descriptor
288  ep_desc = (UDC_DESC_STORAGE usb_ep_desc_t *)
289  udc_next_desc_in_iface((UDC_DESC_STORAGE
290  usb_conf_desc_t *)
291  ep_desc, USB_DT_ENDPOINT);
292  if (NULL == ep_desc) {
293  break;
294  }
295  // Free the endpoint used by the interface
296  udd_ep_free(ep_desc->bEndpointAddress);
297  }
298  }
299 #endif
300 
301  // Disable interface
302  udi_api->disable();
303  return true;
304 }
305 
316 static bool udc_iface_enable(uint8_t iface_num, uint8_t setting_num)
317 {
318  // Select the interface descriptor
319  if (!udc_update_iface_desc(iface_num, setting_num)) {
320  return false;
321  }
322 
323 #if (0!=USB_DEVICE_MAX_EP)
325 
326  // Start at the beginning of the global interface descriptor
328  while (1) {
329  // Search Endpoint descriptor included in the global interface descriptor
330  ep_desc = (UDC_DESC_STORAGE usb_ep_desc_t *)
331  udc_next_desc_in_iface((UDC_DESC_STORAGE
332  usb_conf_desc_t *) ep_desc,
334  if (NULL == ep_desc)
335  break;
336  // Alloc the endpoint used by the interface
337  if (!udd_ep_alloc(ep_desc->bEndpointAddress,
338  ep_desc->bmAttributes,
340  (ep_desc->wMaxPacketSize))) {
341  return false;
342  }
343  }
344 #endif
345  // Enable the interface
346  return udc_ptr_conf->udi_apis[iface_num]->enable();
347 }
348 
351 void udc_start(void)
352 {
353  udd_enable();
354 }
355 
358 void udc_stop(void)
359 {
360  udd_disable();
361  udc_reset();
362 }
363 
368 void udc_reset(void)
369 {
370  uint8_t iface_num;
371 
372  if (udc_num_configuration) {
373  for (iface_num = 0;
374  iface_num < udc_ptr_conf->desc->bNumInterfaces;
375  iface_num++) {
376  udc_iface_disable(iface_num);
377  }
378  }
380 #if (USB_CONFIG_ATTR_REMOTE_WAKEUP \
381  == (USB_DEVICE_ATTR & USB_CONFIG_ATTR_REMOTE_WAKEUP))
383  // Remote wakeup is enabled then disable it
384  UDC_REMOTEWAKEUP_DISABLE();
385  }
386 #endif
387  udc_device_status =
388 #if (USB_DEVICE_ATTR & USB_CONFIG_ATTR_SELF_POWERED)
390 #else
392 #endif
393 }
394 
395 void udc_sof_notify(void)
396 {
397  uint8_t iface_num;
398 
399  if (udc_num_configuration) {
400  for (iface_num = 0;
401  iface_num < udc_ptr_conf->desc->bNumInterfaces;
402  iface_num++) {
403  if (udc_ptr_conf->udi_apis[iface_num]->sof_notify != NULL) {
404  udc_ptr_conf->udi_apis[iface_num]->sof_notify();
405  }
406  }
407  }
408 }
409 
415 static bool udc_req_std_dev_get_status(void)
416 {
417  if (udd_g_ctrlreq.req.wLength != sizeof(udc_device_status)) {
418  return false;
419  }
420 
422  sizeof(udc_device_status));
423  return true;
424 }
425 
426 #if (0!=USB_DEVICE_MAX_EP)
427 
432 static bool udc_req_std_ep_get_status(void)
433 {
434  static le16_t udc_ep_status;
435 
436  if (udd_g_ctrlreq.req.wLength != sizeof(udc_ep_status)) {
437  return false;
438  }
439 
440  udc_ep_status = udd_ep_is_halted(udd_g_ctrlreq.req.
441  wIndex & 0xFF) ? CPU_TO_LE16(USB_EP_STATUS_HALTED) : 0;
442 
443  udd_set_setup_payload( (uint8_t *) & udc_ep_status,
444  sizeof(udc_ep_status));
445  return true;
446 }
447 #endif
448 
455 {
456  if (udd_g_ctrlreq.req.wLength) {
457  return false;
458  }
459 
462 #if (USB_CONFIG_ATTR_REMOTE_WAKEUP \
463  == (USB_DEVICE_ATTR & USB_CONFIG_ATTR_REMOTE_WAKEUP))
464  UDC_REMOTEWAKEUP_DISABLE();
465 #endif
466  return true;
467  }
468  return false;
469 }
470 
471 #if (0!=USB_DEVICE_MAX_EP)
472 
477 static bool udc_req_std_ep_clear_feature(void)
478 {
479  if (udd_g_ctrlreq.req.wLength) {
480  return false;
481  }
482 
484  return udd_ep_clear_halt(udd_g_ctrlreq.req.wIndex & 0xFF);
485  }
486  return false;
487 }
488 #endif
489 
496 {
497  if (udd_g_ctrlreq.req.wLength) {
498  return false;
499  }
500 
501  switch (udd_g_ctrlreq.req.wValue) {
502 
504 #if (USB_CONFIG_ATTR_REMOTE_WAKEUP \
505  == (USB_DEVICE_ATTR & USB_CONFIG_ATTR_REMOTE_WAKEUP))
507  UDC_REMOTEWAKEUP_ENABLE();
508  return true;
509 #else
510  return false;
511 #endif
512 
513 #ifdef USB_DEVICE_HS_SUPPORT
515  if (!udd_is_high_speed()) {
516  break;
517  }
518  if (udd_g_ctrlreq.req.wIndex & 0xff) {
519  break;
520  }
521  // Unconfigure the device, terminating all ongoing requests
522  udc_reset();
523  switch ((udd_g_ctrlreq.req.wIndex >> 8) & 0xFF) {
524  case USB_DEV_TEST_MODE_J:
526  return true;
527 
528  case USB_DEV_TEST_MODE_K:
530  return true;
531 
534  return true;
535 
538  return true;
539 
540  case USB_DEV_TEST_MODE_FORCE_ENABLE: // Only for downstream facing hub ports
541  default:
542  break;
543  }
544  break;
545 #endif
546  default:
547  break;
548  }
549  return false;
550 }
551 
557 #if (0!=USB_DEVICE_MAX_EP)
558 static bool udc_req_std_ep_set_feature(void)
559 {
560  if (udd_g_ctrlreq.req.wLength) {
561  return false;
562  }
564  udd_ep_abort(udd_g_ctrlreq.req.wIndex & 0xFF);
565  return udd_ep_set_halt(udd_g_ctrlreq.req.wIndex & 0xFF);
566  }
567  return false;
568 }
569 #endif
570 
575 static void udc_valid_address(void)
576 {
578 }
579 
586 {
587  if (udd_g_ctrlreq.req.wLength) {
588  return false;
589  }
590 
591  // The address must be changed at the end of setup request after the handshake
592  // then we use a callback to change address
594  return true;
595 }
596 
603 {
604  uint8_t i;
605  const uint8_t *str=NULL;
606  uint8_t str_length = 0;
607 
608  // Link payload pointer to the string corresponding at request
609  switch (udd_g_ctrlreq.req.wValue & 0xff) {
610  case 0:
612  sizeof(udc_string_desc_languageid));
613  break;
614 
615 #ifdef USB_DEVICE_MANUFACTURE_NAME
616  case 1:
618  str = udc_string_manufacturer_name;
619  break;
620 #endif
621 #ifdef USB_DEVICE_PRODUCT_NAME
622  case 2:
623  str_length = USB_DEVICE_PRODUCT_NAME_SIZE;
624  str = udc_string_product_name;
625  break;
626 #endif
627 #if defined USB_DEVICE_SERIAL_NAME || defined USB_DEVICE_GET_SERIAL_NAME_POINTER
628  case 3:
629  str_length = USB_DEVICE_SERIAL_NAME_SIZE;
630  str = udc_get_string_serial_name();
631  break;
632 #endif
633  default:
634 #ifdef UDC_GET_EXTRA_STRING
635  if (UDC_GET_EXTRA_STRING()) {
636  break;
637  }
638 #endif
639  return false;
640  }
641 
642  if (str_length) {
643  for(i = 0; i < str_length; i++) {
644  udc_string_desc.string[i] = cpu_to_le16((le16_t)str[i]);
645  }
646 
647  udc_string_desc.header.bLength = 2 + (str_length) * 2;
649  (uint8_t *) &udc_string_desc,
650  udc_string_desc.header.bLength);
651  }
652 
653  return true;
654 }
655 
662 {
663  uint8_t conf_num;
664 
665  conf_num = udd_g_ctrlreq.req.wValue & 0xff;
666 
667  // Check descriptor ID
668  switch ((uint8_t) (udd_g_ctrlreq.req.wValue >> 8)) {
669  case USB_DT_DEVICE:
670  // Device descriptor requested
671 #ifdef USB_DEVICE_HS_SUPPORT
672  if (!udd_is_high_speed()) {
674  (uint8_t *) udc_config.confdev_hs,
675  udc_config.confdev_hs->bLength);
676  } else
677 #endif
678  {
680  (uint8_t *) udc_config.confdev_lsfs,
682  }
683  break;
684 
686  // Configuration descriptor requested
687 #ifdef USB_DEVICE_HS_SUPPORT
688  if (udd_is_high_speed()) {
689  // HS descriptor
690  if (conf_num >= udc_config.confdev_hs->
692  return false;
693  }
695  (uint8_t *)udc_config.conf_hs[conf_num].desc,
696  le16_to_cpu(udc_config.conf_hs[conf_num].desc->wTotalLength));
697  } else
698 #endif
699  {
700  // FS descriptor
701  if (conf_num >= udc_config.confdev_lsfs->
703  return false;
704  }
706  (uint8_t *)udc_config.conf_lsfs[conf_num].desc,
708  }
709  ((usb_conf_desc_t *) udd_g_ctrlreq.payload)->bDescriptorType =
711  break;
712 
713 #ifdef USB_DEVICE_HS_SUPPORT
715  // Device qualifier descriptor requested
716  udd_set_setup_payload( (uint8_t *) udc_config.qualifier,
717  udc_config.qualifier->bLength);
718  break;
719 
721  // Other configuration descriptor requested
722  if (!udd_is_high_speed()) {
723  // HS descriptor
724  if (conf_num >= udc_config.confdev_hs->
726  return false;
727  }
729  (uint8_t *)udc_config.conf_hs[conf_num].desc,
730  le16_to_cpu(udc_config.conf_hs[conf_num].desc->wTotalLength));
731  } else {
732  // FS descriptor
733  if (conf_num >= udc_config.confdev_lsfs->
735  return false;
736  }
738  (uint8_t *)udc_config.conf_lsfs[conf_num].desc,
740  }
741  ((usb_conf_desc_t *) udd_g_ctrlreq.payload)->bDescriptorType =
743  break;
744 #endif
745 
746  case USB_DT_BOS:
747  // Device BOS descriptor requested
748  if (udc_config.conf_bos == NULL) {
749  return false;
750  }
753  break;
754 
755  case USB_DT_STRING:
756  // String descriptor requested
758  return false;
759  }
760  break;
761 
762  default:
763  // Unknown descriptor requested
764  return false;
765  }
766  // if the descriptor is larger than length requested, then reduce it
769  }
770  return true;
771 }
772 
779 {
780  if (udd_g_ctrlreq.req.wLength != 1) {
781  return false;
782  }
783 
785  return true;
786 }
787 
794 {
795  uint8_t iface_num;
796 
797  // Check request length
798  if (udd_g_ctrlreq.req.wLength) {
799  return false;
800  }
801  // Authorize configuration only if the address is valid
802  if (!udd_getaddress()) {
803  return false;
804  }
805  // Check the configuration number requested
806 #ifdef USB_DEVICE_HS_SUPPORT
807  if (udd_is_high_speed()) {
808  // HS descriptor
809  if ((udd_g_ctrlreq.req.wValue & 0xFF) >
810  udc_config.confdev_hs->bNumConfigurations) {
811  return false;
812  }
813  } else
814 #endif
815  {
816  // FS descriptor
817  if ((udd_g_ctrlreq.req.wValue & 0xFF) >
819  return false;
820  }
821  }
822 
823  // Reset current configuration
824  udc_reset();
825 
826  // Enable new configuration
828  if (udc_num_configuration == 0) {
829  return true; // Default empty configuration requested
830  }
831  // Update pointer of the configuration descriptor
832 #ifdef USB_DEVICE_HS_SUPPORT
833  if (udd_is_high_speed()) {
834  // HS descriptor
836  } else
837 #endif
838  {
839  // FS descriptor
841  }
842  // Enable all interfaces of the selected configuration
843  for (iface_num = 0; iface_num < udc_ptr_conf->desc->bNumInterfaces;
844  iface_num++) {
845  if (!udc_iface_enable(iface_num, 0)) {
846  return false;
847  }
848  }
849  return true;
850 }
851 
859 {
860  uint8_t iface_num;
861  udi_api_t UDC_DESC_STORAGE *udi_api;
862 
863  if (udd_g_ctrlreq.req.wLength != 1) {
864  return false; // Error in request
865  }
866  if (!udc_num_configuration) {
867  return false; // The device is not is configured state yet
868  }
869 
870  // Check the interface number included in the request
871  iface_num = udd_g_ctrlreq.req.wIndex & 0xFF;
872  if (iface_num >= udc_ptr_conf->desc->bNumInterfaces) {
873  return false;
874  }
875 
876  // Select first alternate setting of the interface to update udc_ptr_iface
877  // before call iface->getsetting()
878  if (!udc_update_iface_desc(iface_num, 0)) {
879  return false;
880  }
881  // Get alternate setting from UDI
882  udi_api = udc_ptr_conf->udi_apis[iface_num];
883  udc_iface_setting = udi_api->getsetting();
884 
885  // Link value to payload pointer of request
887  return true;
888 }
889 
897 {
898  uint8_t iface_num, setting_num;
899 
900  if (udd_g_ctrlreq.req.wLength) {
901  return false; // Error in request
902  }
903  if (!udc_num_configuration) {
904  return false; // The device is not is configured state yet
905  }
906 
907  iface_num = udd_g_ctrlreq.req.wIndex & 0xFF;
908  setting_num = udd_g_ctrlreq.req.wValue & 0xFF;
909 
910  // Disable current setting
911  if (!udc_iface_disable(iface_num)) {
912  return false;
913  }
914 
915  // Enable new setting
916  return udc_iface_enable(iface_num, setting_num);
917 }
918 
924 static bool udc_reqstd(void)
925 {
926  if (Udd_setup_is_in()) {
927  // GET Standard Requests
928  if (udd_g_ctrlreq.req.wLength == 0) {
929  return false; // Error for USB host
930  }
931 
933  // Standard Get Device request
934  switch (udd_g_ctrlreq.req.bRequest) {
935  case USB_REQ_GET_STATUS:
941  default:
942  break;
943  }
944  }
945 
947  // Standard Get Interface request
948  switch (udd_g_ctrlreq.req.bRequest) {
951  default:
952  break;
953  }
954  }
955 #if (0!=USB_DEVICE_MAX_EP)
957  // Standard Get Endpoint request
958  switch (udd_g_ctrlreq.req.bRequest) {
959  case USB_REQ_GET_STATUS:
960  return udc_req_std_ep_get_status();
961  default:
962  break;
963  }
964  }
965 #endif
966  } else {
967  // SET Standard Requests
969  // Standard Set Device request
970  switch (udd_g_ctrlreq.req.bRequest) {
971  case USB_REQ_SET_ADDRESS:
975  case USB_REQ_SET_FEATURE:
980  /* Not supported (defined as optional by the USB 2.0 spec) */
981  break;
982  default:
983  break;
984  }
985  }
986 
988  // Standard Set Interface request
989  switch (udd_g_ctrlreq.req.bRequest) {
992  default:
993  break;
994  }
995  }
996 #if (0!=USB_DEVICE_MAX_EP)
998  // Standard Set Endpoint request
999  switch (udd_g_ctrlreq.req.bRequest) {
1000  case USB_REQ_CLEAR_FEATURE:
1001  return udc_req_std_ep_clear_feature();
1002  case USB_REQ_SET_FEATURE:
1003  return udc_req_std_ep_set_feature();
1004  default:
1005  break;
1006  }
1007  }
1008 #endif
1009  }
1010  return false;
1011 }
1012 
1018 static bool udc_req_iface(void)
1019 {
1020  uint8_t iface_num;
1021  udi_api_t UDC_DESC_STORAGE *udi_api;
1022 
1023  if (0 == udc_num_configuration) {
1024  return false; // The device is not is configured state yet
1025  }
1026  // Check interface number
1027  iface_num = udd_g_ctrlreq.req.wIndex & 0xFF;
1028  if (iface_num >= udc_ptr_conf->desc->bNumInterfaces) {
1029  return false;
1030  }
1031 
1032  //* To update udc_ptr_iface with the selected interface in request
1033  // Select first alternate setting of interface to update udc_ptr_iface
1034  // before calling udi_api->getsetting()
1035  if (!udc_update_iface_desc(iface_num, 0)) {
1036  return false;
1037  }
1038  // Select the interface with the current alternate setting
1039  udi_api = udc_ptr_conf->udi_apis[iface_num];
1040  if (!udc_update_iface_desc(iface_num, udi_api->getsetting())) {
1041  return false;
1042  }
1043 
1044  // Send the SETUP request to the UDI corresponding to the interface number
1045  return udi_api->setup();
1046 }
1047 
1053 static bool udc_req_ep(void)
1054 {
1055  uint8_t iface_num;
1056  udi_api_t UDC_DESC_STORAGE *udi_api;
1057 
1058  if (0 == udc_num_configuration) {
1059  return false; // The device is not is configured state yet
1060  }
1061  // Send this request on all enabled interfaces
1062  iface_num = udd_g_ctrlreq.req.wIndex & 0xFF;
1063  for (iface_num = 0; iface_num < udc_ptr_conf->desc->bNumInterfaces;
1064  iface_num++) {
1065  // Select the interface with the current alternate setting
1066  udi_api = udc_ptr_conf->udi_apis[iface_num];
1067  if (!udc_update_iface_desc(iface_num, udi_api->getsetting())) {
1068  return false;
1069  }
1070 
1071  // Send the SETUP request to the UDI
1072  if (udi_api->setup()) {
1073  return true;
1074  }
1075  }
1076  return false;
1077 }
1078 
1093 {
1094  // By default no data (receive/send) and no callbacks registered
1098 
1099  if (Udd_setup_is_in()) {
1100  if (udd_g_ctrlreq.req.wLength == 0) {
1101  return false; // Error from USB host
1102  }
1103  }
1104 
1105  // If standard request then try to decode it in UDC
1107  if (udc_reqstd()) {
1108  return true;
1109  }
1110  }
1111 
1112  // If interface request then try to decode it in UDI
1114  if (udc_req_iface()) {
1115  return true;
1116  }
1117  }
1118 
1119  // If endpoint request then try to decode it in UDI
1121  if (udc_req_ep()) {
1122  return true;
1123  }
1124  }
1125 
1126  // Here SETUP request unknown by UDC and UDIs
1127 #ifdef USB_DEVICE_SPECIFIC_REQUEST
1128  // Try to decode it in specific callback
1129  return USB_DEVICE_SPECIFIC_REQUEST(); // Ex: Vendor request,...
1130 #else
1131  return false;
1132 #endif
1133 }
1134 
#define USB_DEVICE_PRODUCT_NAME_SIZE
USB device product name storage String is allocated only if USB_DEVICE_PRODUCT_NAME is declared by us...
Definition: udc.c:110
static bool udc_req_std_dev_set_address(void)
Standard device request to set device address.
Definition: udc.c:585
static void udc_valid_address(void)
Standard endpoint request to halt an endpoint.
Definition: udc.c:575
#define USB_DEVICE_MANUFACTURE_NAME_SIZE
USB device manufacture name storage String is allocated only if USB_DEVICE_MANUFACTURE_NAME is declar...
Definition: udc.c:98
void udd_test_mode_packet(void)
Common API for USB Device Interface.
Common API for USB Device Drivers (UDD)
A standard USB string descriptor structure.
Definition: usb_protocol.h:474
USB configuration file for CDC application.
English (United States)
Definition: usb_protocol.h:260
void udd_disable(void)
Disables the USB Device mode.
Definition: usbhs_device.c:858
Interface of the USB Device Controller (UDC)
usb_str_desc_t desc
Definition: usb_protocol.h:480
le16_t string[Max(Max(USB_DEVICE_MANUFACTURE_NAME_SIZE, USB_DEVICE_PRODUCT_NAME_SIZE), USB_DEVICE_SERIAL_NAME_SIZE)]
Definition: udc.c:147
usb_iface_desc_t UDC_DESC_STORAGE * udc_get_interface_desc(void)
Returns a pointer on the current interface descriptor.
Definition: udc.c:155
USB protocol definitions.
Common API for USB Device Interface.
void udd_test_mode_se0_nak(void)
#define USB_REQ_TYPE_STANDARD
USB request types (bmRequestType)
Definition: usb_protocol.h:85
Standard USB configuration descriptor structure.
Definition: usb_protocol.h:410
#define cpu_to_le16(x)
Definition: compiler.h:893
UDC_DESC_STORAGE udc_config_t udc_config
Add all information about USB Device in global structure for UDC.
Definition: udi_cdc_desc.c:228
static bool udc_req_std_iface_set_setting(void)
Standard interface request to set an alternate setting of an interface.
Definition: udc.c:896
static bool udc_req_std_iface_get_setting(void)
Standard interface request to get the alternate setting number of an interface.
Definition: udc.c:858
void udd_test_mode_k(void)
#define NULL
Definition: nm_bsp.h:52
#define Udd_setup_recipient()
Return the recipient of the SETUP request udd_g_ctrlreq.
Definition: udd.h:108
void(* callback)(void)
Callback called after reception of ZLP from setup request.
Definition: udd.h:87
void udc_stop(void)
Stop the USB Device stack.
Definition: udc.c:358
#define Udd_setup_is_in()
Return true if the setup request udd_g_ctrlreq indicates IN data transfer.
Definition: udd.h:96
uint8_t bDescriptorType
Definition: usb_protocol.h:476
uint8_t bNumInterfaces
Definition: usb_protocol.h:414
Configuration descriptor and UDI link for one USB speed.
Definition: udc_desc.h:90
uint8_t bDescriptorType
Definition: usb_protocol.h:448
bool udd_is_high_speed(void)
Test whether the USB Device Controller is running at high speed or not.
Definition: usbhs_device.c:950
#define Max(a, b)
Takes the maximal value of a and b.
Definition: compiler.h:797
static bool udc_reqstd(void)
Main routine to manage the standard USB SETUP request.
Definition: udc.c:924
uint8_t * payload
Definition: udd.h:81
void udc_start(void)
Start the USB Device stack.
Definition: udc.c:351
#define USB_REQ_RECIP_ENDPOINT
Recipient endpoint.
Definition: usb_protocol.h:95
#define LE16(x)
Definition: compiler.h:890
bool(* enable)(void)
Enable the interface.
Definition: udi.h:75
static usb_conf_desc_t UDC_DESC_STORAGE * udc_get_eof_conf(void)
Returns a value to check the end of USB Configuration descriptor.
Definition: udc.c:165
void udd_enable(void)
Enables the USB Device mode.
Definition: usbhs_device.c:764
static bool udc_req_std_dev_get_str_desc(void)
Standard device request to get device string descriptor.
Definition: udc.c:602
UDI API.
Definition: udi.h:64
void(* sof_notify)(void)
To signal that a SOF is occurred.
Definition: udi.h:115
Standard USB interface descriptor structure.
Definition: usb_protocol.h:446
void udd_set_address(uint8_t address)
Changes the USB address of device.
Definition: usbhs_device.c:960
#define CPU_TO_LE16(x)
Definition: compiler.h:895
static COMPILER_WORD_ALIGNED uint8_t udc_num_configuration
Device Configuration number selected by the USB host.
Definition: udc.c:64
static bool udc_req_std_dev_get_descriptor(void)
Standard device request to get descriptors about USB device.
Definition: udc.c:661
static COMPILER_WORD_ALIGNED UDC_DESC_STORAGE struct udc_string_desc_t udc_string_desc
Definition: udc.c:150
static bool udc_update_iface_desc(uint8_t iface_num, uint8_t setting_num)
Search an interface descriptor This routine updates the internal pointer udc_ptr_iface.
Definition: udc.c:219
#define USB_DEVICE_SERIAL_NAME_SIZE
Get USB device serial number.
Definition: udc.c:137
static bool udc_req_std_dev_get_status(void)
Standard device request to get device status.
Definition: udc.c:415
USB device string descriptor Structure used to transfer ASCII strings to USB String descriptor struct...
Definition: udc.c:144
static udc_config_speed_t UDC_DESC_STORAGE * udc_ptr_conf
Pointer on the selected speed device configuration.
Definition: udc.c:67
udc_config_speed_t UDC_DESC_STORAGE * conf_lsfs
USB configuration descriptor and UDI API pointers for low or full speed.
Definition: udc_desc.h:105
bool(* setup)(void)
Handle a control request directed at an interface.
Definition: udi.h:101
uint16_t le16_t
Definition: compiler.h:250
static COMPILER_WORD_ALIGNED UDC_DESC_STORAGE usb_str_lgid_desc_t udc_string_desc_languageid
Language ID of USB device (US ID by default)
Definition: udc.c:82
static le16_t udc_device_status
Device status state (see enum usb_device_status in usb_protocol.h)
Definition: udc.c:56
static bool udc_iface_enable(uint8_t iface_num, uint8_t setting_num)
Enables an usb device interface (UDI) This routine calls the UDI corresponding to the interface and s...
Definition: udc.c:316
uint8_t bAlternateSetting
Definition: usb_protocol.h:450
static bool udc_req_std_dev_set_configuration(void)
Standard device request to enable a configuration.
Definition: udc.c:793
static bool udc_iface_disable(uint8_t iface_num)
Disables an usb device interface (UDI) This routine call the UDI corresponding to interface number...
Definition: udc.c:264
static bool udc_req_std_dev_set_feature(void)
Standard device request to set a feature.
Definition: udc.c:495
udi_api_t UDC_DESC_STORAGE *UDC_DESC_STORAGE * udi_apis
Array of UDI API pointer.
Definition: udc_desc.h:94
bool udc_process_setup(void)
Main routine to manage the USB SETUP request.
Definition: udc.c:1092
#define Udd_setup_type()
Return the type of the SETUP request udd_g_ctrlreq.
Definition: udd.h:104
static bool udc_req_ep(void)
Send the SETUP interface request to UDI.
Definition: udc.c:1053
usb_str_desc_t header
Definition: udc.c:145
Remote wakeup enabled.
Definition: usb_protocol.h:148
Standard USB endpoint descriptor structure.
Definition: usb_protocol.h:461
static bool udc_req_std_dev_get_configuration(void)
Standard device request to get configuration number.
Definition: udc.c:778
usb_setup_req_t req
Definition: udd.h:77
uint8_t bNumConfigurations
Definition: usb_protocol.h:327
#define le16_to_cpu(x)
Definition: compiler.h:892
uint8_t udd_getaddress(void)
Returns the USB address of device.
Definition: usbhs_device.c:968
udd_ctrl_request_t udd_g_ctrlreq
Global variable to give and record information about setup request management.
Definition: usbhs_device.c:459
usb_dev_desc_t UDC_DESC_STORAGE * confdev_lsfs
USB device descriptor for low or full speed.
Definition: udc_desc.h:103
static bool udc_req_iface(void)
Send the SETUP interface request to UDI.
Definition: udc.c:1018
#define UDC_DESC_STORAGE
Defines the memory&#39;s location of USB descriptors.
Definition: udc_desc.h:70
usb_conf_desc_t UDC_DESC_STORAGE * desc
USB configuration descriptor.
Definition: udc_desc.h:92
static bool udc_req_std_dev_clear_feature(void)
Standard device request to change device status.
Definition: udc.c:454
#define USB_REQ_RECIP_DEVICE
USB recipient codes (bmRequestType)
Definition: usb_protocol.h:93
static usb_iface_desc_t UDC_DESC_STORAGE * udc_ptr_iface
Pointer on interface descriptor used by SETUP request.
Definition: udc.c:70
static COMPILER_WORD_ALIGNED uint8_t udc_iface_setting
Device interface setting value.
Definition: udc.c:60
void udd_set_setup_payload(uint8_t *payload, uint16_t payload_size)
Load setup payload.
Definition: usbhs_device.c:997
bool(* over_under_run)(void)
Definition: udd.h:91
usb_dev_bos_desc_t UDC_DESC_STORAGE * conf_bos
Definition: udc_desc.h:114
void udc_sof_notify(void)
To signal that a SOF is occurred.
Definition: udc.c:395
uint16_t payload_size
Size of buffer to send or fill, and content the number of byte transfered.
Definition: udd.h:84
uint8_t bNumConfigurations
void udd_test_mode_j(void)
void udc_reset(void)
Reset the current configuration of the USB device, This routines can be called by UDD when a RESET on...
Definition: udc.c:368
uint8_t bInterfaceNumber
Definition: usb_protocol.h:449
#define USB_REQ_RECIP_INTERFACE
Recipient interface.
Definition: usb_protocol.h:94


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:58