37
37
#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
38
38
_PID_MAP(MIDI, 3) | _PID_MAP(VENDOR, 4) )
39
39
40
+ #define USB_VID 0xCafe
41
+ #define USB_BCD 0x0200
42
+
40
43
//--------------------------------------------------------------------+
41
44
// Device Descriptors
42
45
//--------------------------------------------------------------------+
@@ -51,9 +54,9 @@ tusb_desc_device_t const desc_device =
51
54
52
55
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE ,
53
56
54
- .idVendor = 0xCafe ,
57
+ .idVendor = USB_VID ,
55
58
.idProduct = USB_PID ,
56
- .bcdDevice = 0x0100 ,
59
+ .bcdDevice = USB_BCD ,
57
60
58
61
.iManufacturer = 0x01 ,
59
62
.iProduct = 0x02 ,
@@ -75,22 +78,22 @@ uint8_t const * tud_descriptor_device_cb(void)
75
78
76
79
#if defined(CFG_TUD_USBTMC )
77
80
78
- # define TUD_USBTMC_DESC_MAIN (_itfnum ,_bNumEndpoints ) \
81
+ # define TUD_USBTMC_DESC_MAIN (_itfnum ,_bNumEndpoints , _bulkMaxPacketLength ) \
79
82
TUD_USBTMC_IF_DESCRIPTOR(_itfnum, _bNumEndpoints, /*_stridx = */ 4u , TUD_USBTMC_PROTOCOL_USB488 ), \
80
- TUD_USBTMC_BULK_DESCRIPTORS (/* OUT = */ 0x01 , /* IN = */ 0x81 , /* packet size = */ USBTMCD_MAX_PACKET_SIZE )
83
+ TUD_USBTMC_BULK_DESCRIPTORS (/* OUT = */ 0x01 , /* IN = */ 0x81 , /* packet size = */ _bulkMaxPacketLength )
81
84
82
85
#if CFG_TUD_USBTMC_ENABLE_INT_EP
83
86
// USBTMC Interrupt xfer always has length of 2, but we use epMaxSize=8 for
84
87
// compatibility with mcus that only allow 8, 16, 32 or 64 for FS endpoints
85
- # define TUD_USBTMC_DESC (_itfnum ) \
86
- TUD_USBTMC_DESC_MAIN(_itfnum, /* _epCount = */ 3 ), \
88
+ # define TUD_USBTMC_DESC (_itfnum , _bulkMaxPacketLength ) \
89
+ TUD_USBTMC_DESC_MAIN(_itfnum, /* _epCount = */ 3 , _bulkMaxPacketLength ), \
87
90
TUD_USBTMC_INT_DESCRIPTOR (/* INT ep # */ 0x82 , /* epMaxSize = */ 8 , /* bInterval = */ 16u )
88
91
# define TUD_USBTMC_DESC_LEN (TUD_USBTMC_IF_DESCRIPTOR_LEN + TUD_USBTMC_BULK_DESCRIPTORS_LEN + TUD_USBTMC_INT_DESCRIPTOR_LEN )
89
92
90
93
#else
91
94
92
- # define TUD_USBTMC_DESC (_itfnum ) \
93
- TUD_USBTMC_DESC_MAIN(_itfnum, /* _epCount = */ 2u )
95
+ # define TUD_USBTMC_DESC (_itfnum , _bulkMaxPacketLength ) \
96
+ TUD_USBTMC_DESC_MAIN(_itfnum, /* _epCount = */ 2u , _bulkMaxPacketLength )
94
97
# define TUD_USBTMC_DESC_LEN (TUD_USBTMC_IF_DESCRIPTOR_LEN + TUD_USBTMC_BULK_DESCRIPTORS_LEN)
95
98
96
99
#endif /* CFG_TUD_USBTMC_ENABLE_INT_EP */
@@ -119,21 +122,66 @@ enum
119
122
#endif
120
123
121
124
122
- uint8_t const desc_configuration [] =
125
+ uint8_t const desc_fs_configuration [] =
123
126
{
124
127
// Config number, interface count, string index, total length, attribute, power in mA
125
128
TUD_CONFIG_DESCRIPTOR (1 , ITF_NUM_TOTAL , 0 , CONFIG_TOTAL_LEN , 0x00 , 100 ),
126
129
127
- TUD_USBTMC_DESC (ITF_NUM_USBTMC ),
130
+ TUD_USBTMC_DESC (ITF_NUM_USBTMC , /* _bulkMaxPacketLength = */ 64 ),
128
131
};
129
132
133
+ #if TUD_OPT_HIGH_SPEED
134
+
135
+ uint8_t const desc_hs_configuration [] =
136
+ {
137
+ // Config number, interface count, string index, total length, attribute, power in mA
138
+ TUD_CONFIG_DESCRIPTOR (1 , ITF_NUM_TOTAL , 0 , CONFIG_TOTAL_LEN , 0x00 , 100 ),
139
+
140
+ TUD_USBTMC_DESC (ITF_NUM_USBTMC , /* _bulkMaxPacketLength = */ 512 ),
141
+ };
142
+
143
+ // other speed configuration
144
+ uint8_t desc_other_speed_config [CONFIG_TOTAL_LEN ];
145
+
146
+ // device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
147
+ tusb_desc_device_qualifier_t const desc_device_qualifier =
148
+ {
149
+ .bLength = sizeof (tusb_desc_device_qualifier_t ),
150
+ .bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER ,
151
+ .bcdUSB = USB_BCD ,
152
+
153
+ .bDeviceClass = 0x00 ,
154
+ .bDeviceSubClass = 0x00 ,
155
+ .bDeviceProtocol = 0x00 ,
156
+
157
+ .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE ,
158
+ .bNumConfigurations = 0x01 ,
159
+ .bReserved = 0x00
160
+ };
161
+
162
+ // Invoked when received GET DEVICE QUALIFIER DESCRIPTOR request
163
+ // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete.
164
+ // device_qualifier descriptor describes information about a high-speed capable device that would
165
+ // change if the device were operating at the other speed. If not highspeed capable stall this request.
166
+ uint8_t const * tud_descriptor_device_qualifier_cb (void )
167
+ {
168
+ return (uint8_t const * ) & desc_device_qualifier ;
169
+ }
170
+
171
+ #endif
172
+
130
173
// Invoked when received GET CONFIGURATION DESCRIPTOR
131
174
// Application return pointer to descriptor
132
175
// Descriptor contents must exist long enough for transfer to complete
133
176
uint8_t const * tud_descriptor_configuration_cb (uint8_t index )
134
177
{
135
178
(void ) index ; // for multiple configurations
136
- return desc_configuration ;
179
+ #if TUD_OPT_HIGH_SPEED
180
+ // Although we are highspeed, host may be fullspeed.
181
+ return (tud_speed_get () == TUSB_SPEED_HIGH ) ? desc_hs_configuration : desc_fs_configuration ;
182
+ #else
183
+ return desc_fs_configuration ;
184
+ #endif
137
185
}
138
186
139
187
//--------------------------------------------------------------------+
0 commit comments