Skip to content

Commit 2da8f76

Browse files
committed
update example to work with iso streaming
1 parent 0daf8ec commit 2da8f76

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

examples/device/video_capture/src/usb_descriptors.c

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,13 @@ uint8_t const* tud_descriptor_device_cb(void) {
110110
#endif
111111

112112
#if defined(CFG_EXAMPLE_VIDEO_READONLY) && !defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
113-
#define USE_MJPEG
113+
#define USE_MJPEG 1
114+
#else
115+
#define USE_MJPEG 0
114116
#endif
115117

118+
#define USE_ISO_STREAMING (!CFG_TUD_VIDEO_STREAMING_BULK)
119+
116120
// For mcus that does not have enough SRAM for frame buffer, we use fixed frame data.
117121
// To further reduce the size, we use MJPEG format instead of YUY2.
118122
// Select interface descriptor and length accordingly.
@@ -202,7 +206,7 @@ typedef struct TU_ATTR_PACKED {
202206
tusb_desc_interface_t itf;
203207
tusb_desc_video_streaming_input_header_1byte_t header;
204208

205-
#ifdef USE_MJPEG
209+
#if USE_MJPEG
206210
tusb_desc_video_format_mjpeg_t format;
207211
tusb_desc_video_frame_mjpeg_continuous_t frame;
208212
#else
@@ -211,6 +215,12 @@ typedef struct TU_ATTR_PACKED {
211215
#endif
212216

213217
tusb_desc_video_streaming_color_matching_t color;
218+
219+
#if USE_ISO_STREAMING
220+
// For ISO streaming, USB spec requires to alternate interface
221+
tusb_desc_interface_t itf_alt;
222+
#endif
223+
214224
tusb_desc_endpoint_t ep;
215225
} uvc_streaming_desc_t;
216226

@@ -230,7 +240,7 @@ const uvc_cfg_desc_t config_desc = {
230240
.bNumInterfaces = ITF_NUM_TOTAL,
231241
.bConfigurationValue = 1,
232242
.iConfiguration = 0,
233-
.bmAttributes = TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP,
243+
.bmAttributes = TU_BIT(7),
234244
.bMaxPower = 100 / 2
235245
},
236246
.iad = {
@@ -304,7 +314,7 @@ const uvc_cfg_desc_t config_desc = {
304314

305315
.bInterfaceNumber = ITF_NUM_VIDEO_STREAMING,
306316
.bAlternateSetting = 0,
307-
.bNumEndpoints = 1,
317+
.bNumEndpoints = CFG_TUD_VIDEO_STREAMING_BULK, // bulk 1, iso 0
308318
.bInterfaceClass = TUSB_CLASS_VIDEO,
309319
.bInterfaceSubClass = VIDEO_SUBCLASS_STREAMING,
310320
.bInterfaceProtocol = VIDEO_ITF_PROTOCOL_15,
@@ -316,7 +326,8 @@ const uvc_cfg_desc_t config_desc = {
316326
.bDescriptorSubType = VIDEO_CS_ITF_VS_INPUT_HEADER,
317327

318328
.bNumFormats = 1,
319-
.wTotalLength = sizeof(uvc_streaming_desc_t) - sizeof(tusb_desc_interface_t) - sizeof(tusb_desc_endpoint_t), // CS VS descriptors only
329+
.wTotalLength = sizeof(uvc_streaming_desc_t) - sizeof(tusb_desc_interface_t)
330+
- sizeof(tusb_desc_endpoint_t) - (USE_ISO_STREAMING ? sizeof(tusb_desc_interface_t) : 0) , // CS VS descriptors only
320331
.bEndpointAddress = EPNUM_VIDEO_IN,
321332
.bmInfo = 0,
322333
.bTerminalLink = UVC_ENTITY_CAP_OUTPUT_TERMINAL,
@@ -327,7 +338,7 @@ const uvc_cfg_desc_t config_desc = {
327338
.bmaControls = { 0 }
328339
},
329340
.format = {
330-
#ifdef USE_MJPEG
341+
#if USE_MJPEG
331342
.bLength = sizeof(tusb_desc_video_format_mjpeg_t),
332343
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
333344
.bDescriptorSubType = VIDEO_CS_ITF_VS_FORMAT_MJPEG,
@@ -350,7 +361,7 @@ const uvc_cfg_desc_t config_desc = {
350361
.bCopyProtect = 0
351362
},
352363
.frame = {
353-
#ifdef USE_MJPEG
364+
#if USE_MJPEG
354365
.bLength = sizeof(tusb_desc_video_frame_mjpeg_continuous_t),
355366
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
356367
.bDescriptorSubType = VIDEO_CS_ITF_VS_FRAME_MJPEG,
@@ -384,12 +395,31 @@ const uvc_cfg_desc_t config_desc = {
384395
.bTransferCharacteristics = VIDEO_COLOR_XFER_CH_BT709,
385396
.bMatrixCoefficients = VIDEO_COLOR_COEF_SMPTE170M
386397
},
398+
399+
#if USE_ISO_STREAMING
400+
.itf_alt = {
401+
.bLength = sizeof(tusb_desc_interface_t),
402+
.bDescriptorType = TUSB_DESC_INTERFACE,
403+
404+
.bInterfaceNumber = ITF_NUM_VIDEO_STREAMING,
405+
.bAlternateSetting = 1,
406+
.bNumEndpoints = 1,
407+
.bInterfaceClass = TUSB_CLASS_VIDEO,
408+
.bInterfaceSubClass = VIDEO_SUBCLASS_STREAMING,
409+
.bInterfaceProtocol = VIDEO_ITF_PROTOCOL_15,
410+
.iInterface = STRID_UVC_STREAMING
411+
},
412+
#endif
413+
387414
.ep = {
388415
.bLength = sizeof(tusb_desc_endpoint_t),
389416
.bDescriptorType = TUSB_DESC_ENDPOINT,
390417

391418
.bEndpointAddress = EPNUM_VIDEO_IN,
392-
.bmAttributes = { .xfer = TUSB_XFER_BULK },
419+
.bmAttributes = {
420+
.xfer = CFG_TUD_VIDEO_STREAMING_BULK ? TUSB_XFER_BULK : TUSB_XFER_ISOCHRONOUS,
421+
.sync = CFG_TUD_VIDEO_STREAMING_BULK ? 0 : 1 // asynchronous
422+
},
393423
.wMaxPacketSize = CFG_TUD_VIDEO_STREAMING_BULK ? 64 : CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE,
394424
.bInterval = 1
395425
}

examples/device/video_capture/src/usb_descriptors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ enum {
146146
/* Video stream frame format */ \
147147
TUD_VIDEO_DESC_CS_VS_FRM_UNCOMPR_CONT(/*bFrameIndex */1, 0, _width, _height, \
148148
_width * _height * 16, _width * _height * 16 * _fps, \
149-
_width * _height * 16, \
149+
_width * _height * 16 / 8, \
150150
(10000000/_fps), (10000000/_fps), (10000000/_fps)*_fps, (10000000/_fps)), \
151151
TUD_VIDEO_DESC_CS_VS_COLOR_MATCHING(VIDEO_COLOR_PRIMARIES_BT709, VIDEO_COLOR_XFER_CH_BT709, VIDEO_COLOR_COEF_SMPTE170M), \
152152
/* VS alt 1 */\

0 commit comments

Comments
 (0)