3737#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
3838 _PID_MAP(MIDI, 3) | _PID_MAP(VENDOR, 4) )
3939
40+ #define USB_VID 0xCafe
41+ #define USB_BCD 0x0200
42+
4043//--------------------------------------------------------------------+
4144// Device Descriptors
4245//--------------------------------------------------------------------+
@@ -51,9 +54,9 @@ tusb_desc_device_t const desc_device =
5154
5255 .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE ,
5356
54- .idVendor = 0xCafe ,
57+ .idVendor = USB_VID ,
5558 .idProduct = USB_PID ,
56- .bcdDevice = 0x0100 ,
59+ .bcdDevice = USB_BCD ,
5760
5861 .iManufacturer = 0x01 ,
5962 .iProduct = 0x02 ,
@@ -75,22 +78,22 @@ uint8_t const * tud_descriptor_device_cb(void)
7578
7679#if defined(CFG_TUD_USBTMC )
7780
78- # define TUD_USBTMC_DESC_MAIN (_itfnum ,_bNumEndpoints ) \
81+ # define TUD_USBTMC_DESC_MAIN (_itfnum ,_bNumEndpoints , _bulkMaxPacketLength ) \
7982 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 )
8184
8285#if CFG_TUD_USBTMC_ENABLE_INT_EP
8386// USBTMC Interrupt xfer always has length of 2, but we use epMaxSize=8 for
8487// 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 ), \
8790 TUD_USBTMC_INT_DESCRIPTOR (/* INT ep # */ 0x82 , /* epMaxSize = */ 8 , /* bInterval = */ 16u )
8891# define TUD_USBTMC_DESC_LEN (TUD_USBTMC_IF_DESCRIPTOR_LEN + TUD_USBTMC_BULK_DESCRIPTORS_LEN + TUD_USBTMC_INT_DESCRIPTOR_LEN )
8992
9093#else
9194
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 )
9497# define TUD_USBTMC_DESC_LEN (TUD_USBTMC_IF_DESCRIPTOR_LEN + TUD_USBTMC_BULK_DESCRIPTORS_LEN)
9598
9699#endif /* CFG_TUD_USBTMC_ENABLE_INT_EP */
@@ -119,21 +122,66 @@ enum
119122#endif
120123
121124
122- uint8_t const desc_configuration [] =
125+ uint8_t const desc_fs_configuration [] =
123126{
124127 // Config number, interface count, string index, total length, attribute, power in mA
125128 TUD_CONFIG_DESCRIPTOR (1 , ITF_NUM_TOTAL , 0 , CONFIG_TOTAL_LEN , 0x00 , 100 ),
126129
127- TUD_USBTMC_DESC (ITF_NUM_USBTMC ),
130+ TUD_USBTMC_DESC (ITF_NUM_USBTMC , /* _bulkMaxPacketLength = */ 64 ),
128131};
129132
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+
130173// Invoked when received GET CONFIGURATION DESCRIPTOR
131174// Application return pointer to descriptor
132175// Descriptor contents must exist long enough for transfer to complete
133176uint8_t const * tud_descriptor_configuration_cb (uint8_t index )
134177{
135178 (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
137185}
138186
139187//--------------------------------------------------------------------+
0 commit comments