@@ -97,6 +97,19 @@ uint8_t const* tud_descriptor_device_cb(void) {
9797// Configuration Descriptor
9898//--------------------------------------------------------------------+
9999
100+ /* Time stamp base clock. It is a deprecated parameter. */
101+ #define UVC_CLOCK_FREQUENCY 27000000
102+
103+ /* video capture path */
104+ #define UVC_ENTITY_CAP_INPUT_TERMINAL 0x01
105+ #define UVC_ENTITY_CAP_OUTPUT_TERMINAL 0x02
106+
107+ enum {
108+ ITF_NUM_VIDEO_CONTROL ,
109+ ITF_NUM_VIDEO_STREAMING ,
110+ ITF_NUM_TOTAL
111+ };
112+
100113// Select appropriate endpoint number
101114#if TU_CHECK_MCU (OPT_MCU_LPC175X_6X , OPT_MCU_LPC177X_8X , OPT_MCU_LPC40XX )
102115 // LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
@@ -117,81 +130,6 @@ uint8_t const* tud_descriptor_device_cb(void) {
117130
118131#define USE_ISO_STREAMING (!CFG_TUD_VIDEO_STREAMING_BULK)
119132
120- // For mcus that does not have enough SRAM for frame buffer, we use fixed frame data.
121- // To further reduce the size, we use MJPEG format instead of YUY2.
122- // Select interface descriptor and length accordingly.
123- #if defined(CFG_EXAMPLE_VIDEO_READONLY ) && !defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG )
124- #if CFG_TUD_VIDEO_STREAMING_BULK
125- #define ITF_VIDEO_DESC (epsize ) TUD_VIDEO_CAPTURE_DESCRIPTOR_MJPEG_BULK(4, EPNUM_VIDEO_IN, FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE, epsize)
126- #define ITF_VIDEO_LEN TUD_VIDEO_CAPTURE_DESC_MJPEG_BULK_LEN
127- #else
128- #define ITF_VIDEO_DESC (epsize ) TUD_VIDEO_CAPTURE_DESCRIPTOR_MJPEG(4, EPNUM_VIDEO_IN, FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE, epsize)
129- #define ITF_VIDEO_LEN TUD_VIDEO_CAPTURE_DESC_MJPEG_LEN
130- #endif
131- #else
132- #if CFG_TUD_VIDEO_STREAMING_BULK
133- #define ITF_VIDEO_DESC (epsize ) TUD_VIDEO_CAPTURE_DESCRIPTOR_UNCOMPR_BULK(4, EPNUM_VIDEO_IN, FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE, epsize)
134- #define ITF_VIDEO_LEN TUD_VIDEO_CAPTURE_DESC_UNCOMPR_BULK_LEN
135- #else
136- #define ITF_VIDEO_DESC (epsize ) TUD_VIDEO_CAPTURE_DESCRIPTOR_UNCOMPR(4, EPNUM_VIDEO_IN, FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE, epsize)
137- #define ITF_VIDEO_LEN TUD_VIDEO_CAPTURE_DESC_UNCOMPR_LEN
138- #endif
139- #endif
140-
141- #define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + ITF_VIDEO_LEN)
142-
143- // full speed descriptor
144- uint8_t const desc_fs_configuration [] = {
145- // Config number, interface count, string index, total length, attribute, power in mA
146- TUD_CONFIG_DESCRIPTOR (1 , ITF_NUM_TOTAL , 0 , CONFIG_TOTAL_LEN , 0 , 500 ),
147-
148- // IAD for Video Control
149- ITF_VIDEO_DESC (CFG_TUD_VIDEO_STREAMING_BULK ? 64 : CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE )
150- };
151-
152- #if TUD_OPT_HIGH_SPEED
153- // Per USB specs: high speed capable device must report device_qualifier and other_speed_configuration
154- uint8_t const desc_hs_configuration [] = {
155- // Config number, interface count, string index, total length, attribute, power in mA
156- TUD_CONFIG_DESCRIPTOR (1 , ITF_NUM_TOTAL , 0 , CONFIG_TOTAL_LEN , 0 , 500 ),
157-
158- // IAD for Video Control
159- ITF_VIDEO_DESC (CFG_TUD_VIDEO_STREAMING_BULK ? 512 : CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE )
160- };
161-
162- // device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
163- tusb_desc_device_qualifier_t const desc_device_qualifier = {
164- .bLength = sizeof (tusb_desc_device_t ),
165- .bDescriptorType = TUSB_DESC_DEVICE ,
166- .bcdUSB = USB_BCD ,
167-
168- .bDeviceClass = TUSB_CLASS_MISC ,
169- .bDeviceSubClass = MISC_SUBCLASS_COMMON ,
170- .bDeviceProtocol = MISC_PROTOCOL_IAD ,
171-
172- .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE ,
173- .bNumConfigurations = 0x01 ,
174- .bReserved = 0x00
175- };
176-
177- // Invoked when received GET DEVICE QUALIFIER DESCRIPTOR request
178- // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete.
179- // device_qualifier descriptor describes information about a high-speed capable device that would
180- // change if the device were operating at the other speed. If not highspeed capable stall this request.
181- uint8_t const * tud_descriptor_device_qualifier_cb (void ) {
182- return (uint8_t const * ) & desc_device_qualifier ;
183- }
184-
185- // Invoked when received GET OTHER SEED CONFIGURATION DESCRIPTOR request
186- // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
187- // Configuration descriptor in the other speed e.g if high speed then this is for full speed and vice versa
188- uint8_t const * tud_descriptor_other_speed_configuration_cb (uint8_t index ) {
189- (void ) index ; // for multiple configurations
190- // if link speed is high return fullspeed config, and vice versa
191- return (tud_speed_get () == TUSB_SPEED_HIGH ) ? desc_fs_configuration : desc_hs_configuration ;
192- }
193- #endif // highspeed
194-
195133typedef struct TU_ATTR_PACKED {
196134 tusb_desc_interface_t itf ;
197135 tusb_desc_video_control_header_1itf_t header ;
@@ -231,7 +169,7 @@ typedef struct TU_ATTR_PACKED {
231169 uvc_streaming_desc_t video_streaming ;
232170} uvc_cfg_desc_t ;
233171
234- const uvc_cfg_desc_t config_desc = {
172+ const uvc_cfg_desc_t desc_fs_configuration = {
235173 .config = {
236174 .bLength = sizeof (tusb_desc_configuration_t ),
237175 .bDescriptorType = TUSB_DESC_CONFIGURATION ,
@@ -370,7 +308,6 @@ const uvc_cfg_desc_t config_desc = {
370308 .bDescriptorType = TUSB_DESC_CS_INTERFACE ,
371309 .bDescriptorSubType = VIDEO_CS_ITF_VS_FRAME_UNCOMPRESSED ,
372310#endif
373-
374311 .bFrameIndex = 1 , // 1-based index
375312 .bmCapabilities = 0 ,
376313 .wWidth = FRAME_WIDTH ,
@@ -426,6 +363,42 @@ const uvc_cfg_desc_t config_desc = {
426363 }
427364};
428365
366+ #if TUD_OPT_HIGH_SPEED
367+ uvc_cfg_desc_t desc_hs_configuration = desc_fs_configuration ;
368+
369+ // device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
370+ tusb_desc_device_qualifier_t const desc_device_qualifier = {
371+ .bLength = sizeof (tusb_desc_device_t ),
372+ .bDescriptorType = TUSB_DESC_DEVICE ,
373+ .bcdUSB = USB_BCD ,
374+
375+ .bDeviceClass = TUSB_CLASS_MISC ,
376+ .bDeviceSubClass = MISC_SUBCLASS_COMMON ,
377+ .bDeviceProtocol = MISC_PROTOCOL_IAD ,
378+
379+ .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE ,
380+ .bNumConfigurations = 0x01 ,
381+ .bReserved = 0x00
382+ };
383+
384+ // Invoked when received GET DEVICE QUALIFIER DESCRIPTOR request
385+ // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete.
386+ // device_qualifier descriptor describes information about a high-speed capable device that would
387+ // change if the device were operating at the other speed. If not highspeed capable stall this request.
388+ uint8_t const * tud_descriptor_device_qualifier_cb (void ) {
389+ return (uint8_t const * ) & desc_device_qualifier ;
390+ }
391+
392+ // Invoked when received GET OTHER SEED CONFIGURATION DESCRIPTOR request
393+ // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
394+ // Configuration descriptor in the other speed e.g if high speed then this is for full speed and vice versa
395+ uint8_t const * tud_descriptor_other_speed_configuration_cb (uint8_t index ) {
396+ (void ) index ; // for multiple configurations
397+ // if link speed is high return fullspeed config, and vice versa
398+ return (uint8_t const * ) ((tud_speed_get () == TUSB_SPEED_HIGH ) ? & desc_fs_configuration : & desc_hs_configuration );
399+ }
400+ #endif // highspeed
401+
429402// Invoked when received GET CONFIGURATION DESCRIPTOR
430403// Application return pointer to descriptor
431404// Descriptor contents must exist long enough for transfer to complete
@@ -434,11 +407,17 @@ uint8_t const* tud_descriptor_configuration_cb(uint8_t index) {
434407
435408#if TUD_OPT_HIGH_SPEED
436409 // Although we are highspeed, host may be fullspeed.
437- return (tud_speed_get () == TUSB_SPEED_HIGH ) ? desc_hs_configuration : desc_fs_configuration ;
438- #else
439- // return desc_fs_configuration;
440- return (uint8_t const * ) & config_desc ;
410+ if (tud_speed_get () == TUSB_SPEED_HIGH ) {
411+ // change endpoint bulk size to 512 if bulk streaming
412+ if (CFG_TUD_VIDEO_STREAMING_BULK ) {
413+ desc_hs_configuration .video_streaming .ep .wMaxPacketSize = 512 ;
414+ }
415+ return (uint8_t const * ) & desc_hs_configuration ;
416+ } else
441417#endif
418+ {
419+ return (uint8_t const * ) & desc_fs_configuration ;
420+ }
442421}
443422
444423//--------------------------------------------------------------------+
0 commit comments