3737#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
3838 _PID_MAP(MIDI, 3) | _PID_MAP(AUDIO, 4) | _PID_MAP(VIDEO, 5) | _PID_MAP(VENDOR, 6) )
3939
40+ #define USB_VID 0xCafe
41+ #define USB_BCD 0x0200
42+
4043//--------------------------------------------------------------------+
4144// Device Descriptors
4245//--------------------------------------------------------------------+
4346tusb_desc_device_t const desc_device =
4447{
4548 .bLength = sizeof (tusb_desc_device_t ),
4649 .bDescriptorType = TUSB_DESC_DEVICE ,
47- .bcdUSB = 0x0200 ,
50+ .bcdUSB = USB_BCD ,
4851
4952 // Use Interface Association Descriptor (IAD) for Video
5053 // As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
@@ -54,7 +57,7 @@ tusb_desc_device_t const desc_device =
5457
5558 .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE ,
5659
57- .idVendor = 0xCafe ,
60+ .idVendor = USB_VID ,
5861 .idProduct = USB_PID ,
5962 .bcdDevice = 0x0100 ,
6063
@@ -137,14 +140,89 @@ uint8_t const desc_fs_configuration[] =
137140#endif
138141};
139142
143+ #if TUD_OPT_HIGH_SPEED
144+ // Per USB specs: high speed capable device must report device_qualifier and other_speed_configuration
145+
146+ uint8_t const desc_hs_configuration [] =
147+ {
148+ // Config number, interface count, string index, total length, attribute, power in mA
149+ TUD_CONFIG_DESCRIPTOR (1 , ITF_NUM_TOTAL , 0 , CONFIG_TOTAL_LEN , 0 , 500 ),
150+
151+ // IAD for Video Control
152+ #if defined(CFG_EXAMPLE_VIDEO_READONLY ) && !defined (CFG_EXAMPLE_VIDEO_DISABLE_MJPEG )
153+ # if 1 == CFG_TUD_VIDEO_STREAMING_BULK
154+ TUD_VIDEO_CAPTURE_DESCRIPTOR_MJPEG_BULK (4 , EPNUM_VIDEO_IN ,
155+ FRAME_WIDTH , FRAME_HEIGHT , FRAME_RATE ,
156+ 512 )
157+ # else
158+ TUD_VIDEO_CAPTURE_DESCRIPTOR_MJPEG (4 , EPNUM_VIDEO_IN ,
159+ FRAME_WIDTH , FRAME_HEIGHT , FRAME_RATE ,
160+ CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE )
161+ # endif
162+ #else
163+ # if 1 == CFG_TUD_VIDEO_STREAMING_BULK
164+ TUD_VIDEO_CAPTURE_DESCRIPTOR_UNCOMPR_BULK (4 , EPNUM_VIDEO_IN ,
165+ FRAME_WIDTH , FRAME_HEIGHT , FRAME_RATE ,
166+ 512 )
167+ # else
168+ TUD_VIDEO_CAPTURE_DESCRIPTOR_UNCOMPR (4 , EPNUM_VIDEO_IN ,
169+ FRAME_WIDTH , FRAME_HEIGHT , FRAME_RATE ,
170+ CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE )
171+ # endif
172+ #endif
173+ };
174+
175+ // device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
176+ tusb_desc_device_qualifier_t const desc_device_qualifier =
177+ {
178+ .bLength = sizeof (tusb_desc_device_t ),
179+ .bDescriptorType = TUSB_DESC_DEVICE ,
180+ .bcdUSB = USB_BCD ,
181+
182+ .bDeviceClass = TUSB_CLASS_MISC ,
183+ .bDeviceSubClass = MISC_SUBCLASS_COMMON ,
184+ .bDeviceProtocol = MISC_PROTOCOL_IAD ,
185+
186+ .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE ,
187+ .bNumConfigurations = 0x01 ,
188+ .bReserved = 0x00
189+ };
190+
191+ // Invoked when received GET DEVICE QUALIFIER DESCRIPTOR request
192+ // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete.
193+ // device_qualifier descriptor describes information about a high-speed capable device that would
194+ // change if the device were operating at the other speed. If not highspeed capable stall this request.
195+ uint8_t const * tud_descriptor_device_qualifier_cb (void )
196+ {
197+ return (uint8_t const * ) & desc_device_qualifier ;
198+ }
199+
200+ // Invoked when received GET OTHER SEED CONFIGURATION DESCRIPTOR request
201+ // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
202+ // Configuration descriptor in the other speed e.g if high speed then this is for full speed and vice versa
203+ uint8_t const * tud_descriptor_other_speed_configuration_cb (uint8_t index )
204+ {
205+ (void ) index ; // for multiple configurations
206+
207+ // if link speed is high return fullspeed config, and vice versa
208+ return (tud_speed_get () == TUSB_SPEED_HIGH ) ? desc_fs_configuration : desc_hs_configuration ;
209+ }
210+
211+ #endif // highspeed
212+
140213// Invoked when received GET CONFIGURATION DESCRIPTOR
141214// Application return pointer to descriptor
142215// Descriptor contents must exist long enough for transfer to complete
143216uint8_t const * tud_descriptor_configuration_cb (uint8_t index )
144217{
145218 (void ) index ; // for multiple configurations
146219
220+ #if TUD_OPT_HIGH_SPEED
221+ // Although we are highspeed, host may be fullspeed.
222+ return (tud_speed_get () == TUSB_SPEED_HIGH ) ? desc_hs_configuration : desc_fs_configuration ;
223+ #else
147224 return desc_fs_configuration ;
225+ #endif
148226}
149227
150228//--------------------------------------------------------------------+
0 commit comments