mirror of
https://github.com/hathach/tinyusb.git
synced 2025-04-25 03:02:26 +00:00
update example to work with iso streaming
This commit is contained in:
parent
0daf8ec51b
commit
2da8f763d7
@ -110,9 +110,13 @@ uint8_t const* tud_descriptor_device_cb(void) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CFG_EXAMPLE_VIDEO_READONLY) && !defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
|
#if defined(CFG_EXAMPLE_VIDEO_READONLY) && !defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
|
||||||
#define USE_MJPEG
|
#define USE_MJPEG 1
|
||||||
|
#else
|
||||||
|
#define USE_MJPEG 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define USE_ISO_STREAMING (!CFG_TUD_VIDEO_STREAMING_BULK)
|
||||||
|
|
||||||
// For mcus that does not have enough SRAM for frame buffer, we use fixed frame data.
|
// For mcus that does not have enough SRAM for frame buffer, we use fixed frame data.
|
||||||
// To further reduce the size, we use MJPEG format instead of YUY2.
|
// To further reduce the size, we use MJPEG format instead of YUY2.
|
||||||
// Select interface descriptor and length accordingly.
|
// Select interface descriptor and length accordingly.
|
||||||
@ -202,7 +206,7 @@ typedef struct TU_ATTR_PACKED {
|
|||||||
tusb_desc_interface_t itf;
|
tusb_desc_interface_t itf;
|
||||||
tusb_desc_video_streaming_input_header_1byte_t header;
|
tusb_desc_video_streaming_input_header_1byte_t header;
|
||||||
|
|
||||||
#ifdef USE_MJPEG
|
#if USE_MJPEG
|
||||||
tusb_desc_video_format_mjpeg_t format;
|
tusb_desc_video_format_mjpeg_t format;
|
||||||
tusb_desc_video_frame_mjpeg_continuous_t frame;
|
tusb_desc_video_frame_mjpeg_continuous_t frame;
|
||||||
#else
|
#else
|
||||||
@ -211,6 +215,12 @@ typedef struct TU_ATTR_PACKED {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
tusb_desc_video_streaming_color_matching_t color;
|
tusb_desc_video_streaming_color_matching_t color;
|
||||||
|
|
||||||
|
#if USE_ISO_STREAMING
|
||||||
|
// For ISO streaming, USB spec requires to alternate interface
|
||||||
|
tusb_desc_interface_t itf_alt;
|
||||||
|
#endif
|
||||||
|
|
||||||
tusb_desc_endpoint_t ep;
|
tusb_desc_endpoint_t ep;
|
||||||
} uvc_streaming_desc_t;
|
} uvc_streaming_desc_t;
|
||||||
|
|
||||||
@ -230,7 +240,7 @@ const uvc_cfg_desc_t config_desc = {
|
|||||||
.bNumInterfaces = ITF_NUM_TOTAL,
|
.bNumInterfaces = ITF_NUM_TOTAL,
|
||||||
.bConfigurationValue = 1,
|
.bConfigurationValue = 1,
|
||||||
.iConfiguration = 0,
|
.iConfiguration = 0,
|
||||||
.bmAttributes = TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP,
|
.bmAttributes = TU_BIT(7),
|
||||||
.bMaxPower = 100 / 2
|
.bMaxPower = 100 / 2
|
||||||
},
|
},
|
||||||
.iad = {
|
.iad = {
|
||||||
@ -304,7 +314,7 @@ const uvc_cfg_desc_t config_desc = {
|
|||||||
|
|
||||||
.bInterfaceNumber = ITF_NUM_VIDEO_STREAMING,
|
.bInterfaceNumber = ITF_NUM_VIDEO_STREAMING,
|
||||||
.bAlternateSetting = 0,
|
.bAlternateSetting = 0,
|
||||||
.bNumEndpoints = 1,
|
.bNumEndpoints = CFG_TUD_VIDEO_STREAMING_BULK, // bulk 1, iso 0
|
||||||
.bInterfaceClass = TUSB_CLASS_VIDEO,
|
.bInterfaceClass = TUSB_CLASS_VIDEO,
|
||||||
.bInterfaceSubClass = VIDEO_SUBCLASS_STREAMING,
|
.bInterfaceSubClass = VIDEO_SUBCLASS_STREAMING,
|
||||||
.bInterfaceProtocol = VIDEO_ITF_PROTOCOL_15,
|
.bInterfaceProtocol = VIDEO_ITF_PROTOCOL_15,
|
||||||
@ -316,7 +326,8 @@ const uvc_cfg_desc_t config_desc = {
|
|||||||
.bDescriptorSubType = VIDEO_CS_ITF_VS_INPUT_HEADER,
|
.bDescriptorSubType = VIDEO_CS_ITF_VS_INPUT_HEADER,
|
||||||
|
|
||||||
.bNumFormats = 1,
|
.bNumFormats = 1,
|
||||||
.wTotalLength = sizeof(uvc_streaming_desc_t) - sizeof(tusb_desc_interface_t) - sizeof(tusb_desc_endpoint_t), // CS VS descriptors only
|
.wTotalLength = sizeof(uvc_streaming_desc_t) - sizeof(tusb_desc_interface_t)
|
||||||
|
- sizeof(tusb_desc_endpoint_t) - (USE_ISO_STREAMING ? sizeof(tusb_desc_interface_t) : 0) , // CS VS descriptors only
|
||||||
.bEndpointAddress = EPNUM_VIDEO_IN,
|
.bEndpointAddress = EPNUM_VIDEO_IN,
|
||||||
.bmInfo = 0,
|
.bmInfo = 0,
|
||||||
.bTerminalLink = UVC_ENTITY_CAP_OUTPUT_TERMINAL,
|
.bTerminalLink = UVC_ENTITY_CAP_OUTPUT_TERMINAL,
|
||||||
@ -327,7 +338,7 @@ const uvc_cfg_desc_t config_desc = {
|
|||||||
.bmaControls = { 0 }
|
.bmaControls = { 0 }
|
||||||
},
|
},
|
||||||
.format = {
|
.format = {
|
||||||
#ifdef USE_MJPEG
|
#if USE_MJPEG
|
||||||
.bLength = sizeof(tusb_desc_video_format_mjpeg_t),
|
.bLength = sizeof(tusb_desc_video_format_mjpeg_t),
|
||||||
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
|
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
|
||||||
.bDescriptorSubType = VIDEO_CS_ITF_VS_FORMAT_MJPEG,
|
.bDescriptorSubType = VIDEO_CS_ITF_VS_FORMAT_MJPEG,
|
||||||
@ -350,7 +361,7 @@ const uvc_cfg_desc_t config_desc = {
|
|||||||
.bCopyProtect = 0
|
.bCopyProtect = 0
|
||||||
},
|
},
|
||||||
.frame = {
|
.frame = {
|
||||||
#ifdef USE_MJPEG
|
#if USE_MJPEG
|
||||||
.bLength = sizeof(tusb_desc_video_frame_mjpeg_continuous_t),
|
.bLength = sizeof(tusb_desc_video_frame_mjpeg_continuous_t),
|
||||||
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
|
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
|
||||||
.bDescriptorSubType = VIDEO_CS_ITF_VS_FRAME_MJPEG,
|
.bDescriptorSubType = VIDEO_CS_ITF_VS_FRAME_MJPEG,
|
||||||
@ -384,12 +395,31 @@ const uvc_cfg_desc_t config_desc = {
|
|||||||
.bTransferCharacteristics = VIDEO_COLOR_XFER_CH_BT709,
|
.bTransferCharacteristics = VIDEO_COLOR_XFER_CH_BT709,
|
||||||
.bMatrixCoefficients = VIDEO_COLOR_COEF_SMPTE170M
|
.bMatrixCoefficients = VIDEO_COLOR_COEF_SMPTE170M
|
||||||
},
|
},
|
||||||
|
|
||||||
|
#if USE_ISO_STREAMING
|
||||||
|
.itf_alt = {
|
||||||
|
.bLength = sizeof(tusb_desc_interface_t),
|
||||||
|
.bDescriptorType = TUSB_DESC_INTERFACE,
|
||||||
|
|
||||||
|
.bInterfaceNumber = ITF_NUM_VIDEO_STREAMING,
|
||||||
|
.bAlternateSetting = 1,
|
||||||
|
.bNumEndpoints = 1,
|
||||||
|
.bInterfaceClass = TUSB_CLASS_VIDEO,
|
||||||
|
.bInterfaceSubClass = VIDEO_SUBCLASS_STREAMING,
|
||||||
|
.bInterfaceProtocol = VIDEO_ITF_PROTOCOL_15,
|
||||||
|
.iInterface = STRID_UVC_STREAMING
|
||||||
|
},
|
||||||
|
#endif
|
||||||
|
|
||||||
.ep = {
|
.ep = {
|
||||||
.bLength = sizeof(tusb_desc_endpoint_t),
|
.bLength = sizeof(tusb_desc_endpoint_t),
|
||||||
.bDescriptorType = TUSB_DESC_ENDPOINT,
|
.bDescriptorType = TUSB_DESC_ENDPOINT,
|
||||||
|
|
||||||
.bEndpointAddress = EPNUM_VIDEO_IN,
|
.bEndpointAddress = EPNUM_VIDEO_IN,
|
||||||
.bmAttributes = { .xfer = TUSB_XFER_BULK },
|
.bmAttributes = {
|
||||||
|
.xfer = CFG_TUD_VIDEO_STREAMING_BULK ? TUSB_XFER_BULK : TUSB_XFER_ISOCHRONOUS,
|
||||||
|
.sync = CFG_TUD_VIDEO_STREAMING_BULK ? 0 : 1 // asynchronous
|
||||||
|
},
|
||||||
.wMaxPacketSize = CFG_TUD_VIDEO_STREAMING_BULK ? 64 : CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE,
|
.wMaxPacketSize = CFG_TUD_VIDEO_STREAMING_BULK ? 64 : CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE,
|
||||||
.bInterval = 1
|
.bInterval = 1
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ enum {
|
|||||||
/* Video stream frame format */ \
|
/* Video stream frame format */ \
|
||||||
TUD_VIDEO_DESC_CS_VS_FRM_UNCOMPR_CONT(/*bFrameIndex */1, 0, _width, _height, \
|
TUD_VIDEO_DESC_CS_VS_FRM_UNCOMPR_CONT(/*bFrameIndex */1, 0, _width, _height, \
|
||||||
_width * _height * 16, _width * _height * 16 * _fps, \
|
_width * _height * 16, _width * _height * 16 * _fps, \
|
||||||
_width * _height * 16, \
|
_width * _height * 16 / 8, \
|
||||||
(10000000/_fps), (10000000/_fps), (10000000/_fps)*_fps, (10000000/_fps)), \
|
(10000000/_fps), (10000000/_fps), (10000000/_fps)*_fps, (10000000/_fps)), \
|
||||||
TUD_VIDEO_DESC_CS_VS_COLOR_MATCHING(VIDEO_COLOR_PRIMARIES_BT709, VIDEO_COLOR_XFER_CH_BT709, VIDEO_COLOR_COEF_SMPTE170M), \
|
TUD_VIDEO_DESC_CS_VS_COLOR_MATCHING(VIDEO_COLOR_PRIMARIES_BT709, VIDEO_COLOR_XFER_CH_BT709, VIDEO_COLOR_COEF_SMPTE170M), \
|
||||||
/* VS alt 1 */\
|
/* VS alt 1 */\
|
||||||
|
Loading…
x
Reference in New Issue
Block a user