46
46
// Weak stubs: invoked if no strong implementation is available
47
47
//--------------------------------------------------------------------+
48
48
TU_ATTR_WEAK void tud_event_hook_cb (uint8_t rhport , uint32_t eventid , bool in_isr ) {
49
- (void )rhport ;
50
- (void )eventid ;
51
- (void )in_isr ;
49
+ (void ) rhport ;
50
+ (void ) eventid ;
51
+ (void ) in_isr ;
52
52
}
53
53
54
54
TU_ATTR_WEAK void tud_sof_cb (uint32_t frame_count ) {
55
- (void )frame_count ;
55
+ (void ) frame_count ;
56
+ }
57
+
58
+ TU_ATTR_WEAK uint8_t const * tud_descriptor_bos_cb (void ) {
59
+ return NULL ;
60
+ }
61
+
62
+ TU_ATTR_WEAK uint8_t const * tud_descriptor_device_qualifier_cb (void ) {
63
+ return NULL ;
64
+ }
65
+
66
+ TU_ATTR_WEAK uint8_t const * tud_descriptor_other_speed_configuration_cb (uint8_t index ) {
67
+ (void ) index ;
68
+ return NULL ;
69
+ }
70
+
71
+ TU_ATTR_WEAK void tud_mount_cb (void ) {
72
+ }
73
+
74
+ TU_ATTR_WEAK void tud_umount_cb (void ) {
75
+ }
76
+
77
+ TU_ATTR_WEAK void tud_suspend_cb (bool remote_wakeup_en ) {
78
+ (void ) remote_wakeup_en ;
79
+ }
80
+
81
+ TU_ATTR_WEAK void tud_resume_cb (void ) {
82
+ }
83
+
84
+ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb (uint8_t rhport , uint8_t stage , tusb_control_request_t const * request ) {
85
+ (void ) rhport ;
86
+ (void ) stage ;
87
+ (void ) request ;
88
+ return false;
56
89
}
57
90
58
91
TU_ATTR_WEAK bool dcd_deinit (uint8_t rhport ) {
@@ -557,7 +590,7 @@ void tud_task_ext(uint32_t timeout_ms, bool in_isr) {
557
590
case DCD_EVENT_UNPLUGGED :
558
591
TU_LOG_USBD ("\r\n" );
559
592
usbd_reset (event .rhport );
560
- if ( tud_umount_cb ) tud_umount_cb ();
593
+ tud_umount_cb ();
561
594
break ;
562
595
563
596
case DCD_EVENT_SETUP_RECEIVED :
@@ -617,7 +650,7 @@ void tud_task_ext(uint32_t timeout_ms, bool in_isr) {
617
650
// e.g suspend -> resume -> unplug/plug. Skip suspend/resume if not connected
618
651
if (_usbd_dev .connected ) {
619
652
TU_LOG_USBD (": Remote Wakeup = %u\r\n" , _usbd_dev .remote_wakeup_en );
620
- if ( tud_suspend_cb ) tud_suspend_cb (_usbd_dev .remote_wakeup_en );
653
+ tud_suspend_cb (_usbd_dev .remote_wakeup_en );
621
654
} else {
622
655
TU_LOG_USBD (" Skipped\r\n" );
623
656
}
@@ -626,7 +659,7 @@ void tud_task_ext(uint32_t timeout_ms, bool in_isr) {
626
659
case DCD_EVENT_RESUME :
627
660
if (_usbd_dev .connected ) {
628
661
TU_LOG_USBD ("\r\n" );
629
- if ( tud_resume_cb ) tud_resume_cb ();
662
+ tud_resume_cb ();
630
663
} else {
631
664
TU_LOG_USBD (" Skipped\r\n" );
632
665
}
@@ -675,8 +708,6 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
675
708
676
709
// Vendor request
677
710
if ( p_request -> bmRequestType_bit .type == TUSB_REQ_TYPE_VENDOR ) {
678
- TU_VERIFY (tud_vendor_control_xfer_cb );
679
-
680
711
usbd_control_set_complete_callback (tud_vendor_control_xfer_cb );
681
712
return tud_vendor_control_xfer_cb (rhport , CONTROL_STAGE_SETUP , p_request );
682
713
}
@@ -758,9 +789,9 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
758
789
_usbd_dev .cfg_num = 0 ;
759
790
return false;
760
791
}
761
- if ( tud_mount_cb ) tud_mount_cb ();
792
+ tud_mount_cb ();
762
793
} else {
763
- if ( tud_umount_cb ) tud_umount_cb ();
794
+ tud_umount_cb ();
764
795
}
765
796
}
766
797
@@ -1027,39 +1058,34 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
1027
1058
1028
1059
switch (desc_type )
1029
1060
{
1030
- case TUSB_DESC_DEVICE :
1031
- {
1061
+ case TUSB_DESC_DEVICE : {
1032
1062
TU_LOG_USBD (" Device\r\n" );
1033
1063
1034
1064
void * desc_device = (void * ) (uintptr_t ) tud_descriptor_device_cb ();
1065
+ TU_ASSERT (desc_device );
1035
1066
1036
1067
// Only response with exactly 1 Packet if: not addressed and host requested more data than device descriptor has.
1037
1068
// This only happens with the very first get device descriptor and EP0 size = 8 or 16.
1038
1069
if ((CFG_TUD_ENDPOINT0_SIZE < sizeof (tusb_desc_device_t )) && !_usbd_dev .addressed &&
1039
- ((tusb_control_request_t const * ) p_request )-> wLength > sizeof (tusb_desc_device_t ))
1040
- {
1070
+ ((tusb_control_request_t const * ) p_request )-> wLength > sizeof (tusb_desc_device_t )) {
1041
1071
// Hack here: we modify the request length to prevent usbd_control response with zlp
1042
1072
// since we are responding with 1 packet & less data than wLength.
1043
1073
tusb_control_request_t mod_request = * p_request ;
1044
1074
mod_request .wLength = CFG_TUD_ENDPOINT0_SIZE ;
1045
1075
1046
1076
return tud_control_xfer (rhport , & mod_request , desc_device , CFG_TUD_ENDPOINT0_SIZE );
1047
- }else
1048
- {
1077
+ }else {
1049
1078
return tud_control_xfer (rhport , p_request , desc_device , sizeof (tusb_desc_device_t ));
1050
1079
}
1051
1080
}
1052
1081
// break; // unreachable
1053
1082
1054
- case TUSB_DESC_BOS :
1055
- {
1083
+ case TUSB_DESC_BOS : {
1056
1084
TU_LOG_USBD (" BOS\r\n" );
1057
1085
1058
1086
// requested by host if USB > 2.0 ( i.e 2.1 or 3.x )
1059
- if (!tud_descriptor_bos_cb ) return false;
1060
-
1061
1087
uintptr_t desc_bos = (uintptr_t ) tud_descriptor_bos_cb ();
1062
- TU_ASSERT (desc_bos );
1088
+ TU_VERIFY (desc_bos );
1063
1089
1064
1090
// Use offsetof to avoid pointer to the odd/misaligned address
1065
1091
uint16_t const total_len = tu_le16toh ( tu_unaligned_read16 ((const void * ) (desc_bos + offsetof(tusb_desc_bos_t , wTotalLength ))) );
@@ -1069,24 +1095,20 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
1069
1095
// break; // unreachable
1070
1096
1071
1097
case TUSB_DESC_CONFIGURATION :
1072
- case TUSB_DESC_OTHER_SPEED_CONFIG :
1073
- {
1098
+ case TUSB_DESC_OTHER_SPEED_CONFIG : {
1074
1099
uintptr_t desc_config ;
1075
1100
1076
- if ( desc_type == TUSB_DESC_CONFIGURATION )
1077
- {
1101
+ if ( desc_type == TUSB_DESC_CONFIGURATION ) {
1078
1102
TU_LOG_USBD (" Configuration[%u]\r\n" , desc_index );
1079
1103
desc_config = (uintptr_t ) tud_descriptor_configuration_cb (desc_index );
1080
- } else
1081
- {
1104
+ TU_ASSERT ( desc_config );
1105
+ } else {
1082
1106
// Host only request this after getting Device Qualifier descriptor
1083
1107
TU_LOG_USBD (" Other Speed Configuration\r\n" );
1084
- TU_VERIFY ( tud_descriptor_other_speed_configuration_cb );
1085
1108
desc_config = (uintptr_t ) tud_descriptor_other_speed_configuration_cb (desc_index );
1109
+ TU_VERIFY (desc_config );
1086
1110
}
1087
1111
1088
- TU_ASSERT (desc_config );
1089
-
1090
1112
// Use offsetof to avoid pointer to the odd/misaligned address
1091
1113
uint16_t const total_len = tu_le16toh ( tu_unaligned_read16 ((const void * ) (desc_config + offsetof(tusb_desc_configuration_t , wTotalLength ))) );
1092
1114
@@ -1107,16 +1129,10 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
1107
1129
}
1108
1130
// break; // unreachable
1109
1131
1110
- case TUSB_DESC_DEVICE_QUALIFIER :
1111
- {
1132
+ case TUSB_DESC_DEVICE_QUALIFIER : {
1112
1133
TU_LOG_USBD (" Device Qualifier\r\n" );
1113
-
1114
- TU_VERIFY ( tud_descriptor_device_qualifier_cb );
1115
-
1116
1134
uint8_t const * desc_qualifier = tud_descriptor_device_qualifier_cb ();
1117
1135
TU_VERIFY (desc_qualifier );
1118
-
1119
- // first byte of descriptor is its size
1120
1136
return tud_control_xfer (rhport , p_request , (void * ) (uintptr_t ) desc_qualifier , tu_desc_len (desc_qualifier ));
1121
1137
}
1122
1138
// break; // unreachable
0 commit comments