Merge pull request #2435 from hathach/enhance-uvc
Enhance UVC decriptors and example
This commit is contained in:
4
examples/device/video_capture/src/CMakeLists.txt
Normal file
4
examples/device/video_capture/src/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
# This file is for ESP-IDF only
|
||||
idf_component_register(SRCS "main.c" "usb_descriptors.c"
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES boards tinyusb_src)
|
@@ -48,13 +48,25 @@ enum {
|
||||
|
||||
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
|
||||
|
||||
void led_blinking_task(void);
|
||||
void video_task(void);
|
||||
void led_blinking_task(void* param);
|
||||
void usb_device_task(void *param);
|
||||
void video_task(void* param);
|
||||
|
||||
/*------------- MAIN -------------*/
|
||||
#if CFG_TUSB_OS == OPT_OS_FREERTOS
|
||||
void freertos_init_task(void);
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Main
|
||||
//--------------------------------------------------------------------+
|
||||
int main(void) {
|
||||
board_init();
|
||||
|
||||
// If using FreeRTOS: create blinky, tinyusb device, video task
|
||||
#if CFG_TUSB_OS == OPT_OS_FREERTOS
|
||||
freertos_init_task();
|
||||
#else
|
||||
// init device stack on configured roothub port
|
||||
tud_init(BOARD_TUD_RHPORT);
|
||||
|
||||
@@ -64,10 +76,10 @@ int main(void) {
|
||||
|
||||
while (1) {
|
||||
tud_task(); // tinyusb device task
|
||||
led_blinking_task();
|
||||
|
||||
video_task();
|
||||
led_blinking_task(NULL);
|
||||
video_task(NULL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@@ -169,7 +181,7 @@ static void fill_color_bar(uint8_t* buffer, unsigned start_position) {
|
||||
|
||||
#endif
|
||||
|
||||
void video_task(void) {
|
||||
void video_send_frame(void) {
|
||||
static unsigned start_ms = 0;
|
||||
static unsigned already_sent = 0;
|
||||
|
||||
@@ -213,6 +225,21 @@ void video_task(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void video_task(void* param) {
|
||||
(void) param;
|
||||
|
||||
while(1) {
|
||||
video_send_frame();
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_FREERTOS
|
||||
vTaskDelay(interval_ms / portTICK_PERIOD_MS);
|
||||
#else
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void tud_video_frame_xfer_complete_cb(uint_fast8_t ctl_idx, uint_fast8_t stm_idx) {
|
||||
(void) ctl_idx;
|
||||
(void) stm_idx;
|
||||
@@ -231,16 +258,92 @@ int tud_video_commit_cb(uint_fast8_t ctl_idx, uint_fast8_t stm_idx,
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// BLINKING TASK
|
||||
// Blinking Task
|
||||
//--------------------------------------------------------------------+
|
||||
void led_blinking_task(void) {
|
||||
void led_blinking_task(void* param) {
|
||||
(void) param;
|
||||
static uint32_t start_ms = 0;
|
||||
static bool led_state = false;
|
||||
|
||||
// Blink every interval ms
|
||||
if (board_millis() - start_ms < blink_interval_ms) return; // not enough time
|
||||
start_ms += blink_interval_ms;
|
||||
while (1) {
|
||||
#if CFG_TUSB_OS == OPT_OS_FREERTOS
|
||||
vTaskDelay(blink_interval_ms / portTICK_PERIOD_MS);
|
||||
#else
|
||||
if (board_millis() - start_ms < blink_interval_ms) return; // not enough time
|
||||
#endif
|
||||
|
||||
board_led_write(led_state);
|
||||
led_state = 1 - led_state; // toggle
|
||||
start_ms += blink_interval_ms;
|
||||
board_led_write(led_state);
|
||||
led_state = 1 - led_state; // toggle
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// FreeRTOS
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUSB_OS == OPT_OS_FREERTOS
|
||||
|
||||
#define BLINKY_STACK_SIZE configMINIMAL_STACK_SIZE
|
||||
#define VIDEO_STACK_SIZE (configMINIMAL_STACK_SIZE*4)
|
||||
|
||||
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
|
||||
#define USBD_STACK_SIZE 4096
|
||||
int main(void);
|
||||
void app_main(void) {
|
||||
main();
|
||||
}
|
||||
#else
|
||||
// Increase stack size when debug log is enabled
|
||||
#define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) * (CFG_TUSB_DEBUG ? 2 : 1)
|
||||
#endif
|
||||
|
||||
// static task
|
||||
#if configSUPPORT_STATIC_ALLOCATION
|
||||
StackType_t blinky_stack[BLINKY_STACK_SIZE];
|
||||
StaticTask_t blinky_taskdef;
|
||||
|
||||
StackType_t usb_device_stack[USBD_STACK_SIZE];
|
||||
StaticTask_t usb_device_taskdef;
|
||||
|
||||
StackType_t video_stack[VIDEO_STACK_SIZE];
|
||||
StaticTask_t video_taskdef;
|
||||
#endif
|
||||
|
||||
// USB Device Driver task
|
||||
// This top level thread process all usb events and invoke callbacks
|
||||
void usb_device_task(void *param) {
|
||||
(void) param;
|
||||
|
||||
// init device stack on configured roothub port
|
||||
// This should be called after scheduler/kernel is started.
|
||||
// Otherwise, it could cause kernel issue since USB IRQ handler does use RTOS queue API.
|
||||
tud_init(BOARD_TUD_RHPORT);
|
||||
|
||||
if (board_init_after_tusb) {
|
||||
board_init_after_tusb();
|
||||
}
|
||||
|
||||
// RTOS forever loop
|
||||
while (1) {
|
||||
// put this thread to waiting state until there is new events
|
||||
tud_task();
|
||||
}
|
||||
}
|
||||
|
||||
void freertos_init_task(void) {
|
||||
#if configSUPPORT_STATIC_ALLOCATION
|
||||
xTaskCreateStatic(led_blinking_task, "blinky", BLINKY_STACK_SIZE, NULL, 1, blinky_stack, &blinky_taskdef);
|
||||
xTaskCreateStatic(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef);
|
||||
xTaskCreateStatic(video_task, "cdc", VIDEO_STACK_SIZE, NULL, configMAX_PRIORITIES - 2, video_stack, &video_taskdef);
|
||||
#else
|
||||
xTaskCreate(led_blinking_task, "blinky", BLINKY_STACK_SIZE, NULL, 1, NULL);
|
||||
xTaskCreate(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);
|
||||
xTaskCreate(video_task, "video", VIDEO_STACK_SZIE, NULL, configMAX_PRIORITIES - 2, NULL);
|
||||
#endif
|
||||
|
||||
// skip starting scheduler (and return) for ESP32-S2 or ESP32-S3
|
||||
#if !TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
|
||||
vTaskStartScheduler();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
@@ -57,6 +57,11 @@
|
||||
#define CFG_TUSB_OS OPT_OS_NONE
|
||||
#endif
|
||||
|
||||
// Espressif IDF requires "freertos/" prefix in include path
|
||||
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
|
||||
#define CFG_TUSB_OS_INC_PATH freertos/
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUSB_DEBUG
|
||||
#define CFG_TUSB_DEBUG 0
|
||||
#endif
|
||||
@@ -103,6 +108,9 @@
|
||||
// use bulk endpoint for streaming interface
|
||||
#define CFG_TUD_VIDEO_STREAMING_BULK 1
|
||||
|
||||
//#define CFG_EXAMPLE_VIDEO_READONLY
|
||||
//#define CFG_EXAMPLE_VIDEO_DISABLE_MJPEG
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -40,6 +40,26 @@
|
||||
#define USB_VID 0xCafe
|
||||
#define USB_BCD 0x0200
|
||||
|
||||
// String Descriptor Index
|
||||
enum {
|
||||
STRID_LANGID = 0,
|
||||
STRID_MANUFACTURER,
|
||||
STRID_PRODUCT,
|
||||
STRID_SERIAL,
|
||||
STRID_UVC_CONTROL,
|
||||
STRID_UVC_STREAMING,
|
||||
};
|
||||
|
||||
// array of pointer to string descriptors
|
||||
char const* string_desc_arr[] = {
|
||||
(const char[]) {0x09, 0x04}, // 0: is supported language is English (0x0409)
|
||||
"TinyUSB", // 1: Manufacturer
|
||||
"TinyUSB Device", // 2: Product
|
||||
NULL, // 3: Serials will use unique ID if possible
|
||||
"TinyUSB UVC Control", // 4: UVC Interface
|
||||
"TinyUSB UVC Streaming", // 5: UVC Interface
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Device Descriptors
|
||||
//--------------------------------------------------------------------+
|
||||
@@ -60,9 +80,9 @@ tusb_desc_device_t const desc_device = {
|
||||
.idProduct = USB_PID,
|
||||
.bcdDevice = 0x0100,
|
||||
|
||||
.iManufacturer = 0x01,
|
||||
.iProduct = 0x02,
|
||||
.iSerialNumber = 0x03,
|
||||
.iManufacturer = STRID_MANUFACTURER,
|
||||
.iProduct = STRID_PRODUCT,
|
||||
.iSerialNumber = STRID_SERIAL,
|
||||
|
||||
.bNumConfigurations = 0x01
|
||||
};
|
||||
@@ -77,6 +97,19 @@ uint8_t const* tud_descriptor_device_cb(void) {
|
||||
// Configuration Descriptor
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/* Time stamp base clock. It is a deprecated parameter. */
|
||||
#define UVC_CLOCK_FREQUENCY 27000000
|
||||
|
||||
/* video capture path */
|
||||
#define UVC_ENTITY_CAP_INPUT_TERMINAL 0x01
|
||||
#define UVC_ENTITY_CAP_OUTPUT_TERMINAL 0x02
|
||||
|
||||
enum {
|
||||
ITF_NUM_VIDEO_CONTROL,
|
||||
ITF_NUM_VIDEO_STREAMING,
|
||||
ITF_NUM_TOTAL
|
||||
};
|
||||
|
||||
// Select appropriate endpoint number
|
||||
#if TU_CHECK_MCU(OPT_MCU_LPC175X_6X, OPT_MCU_LPC177X_8X, OPT_MCU_LPC40XX)
|
||||
// LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
|
||||
@@ -89,61 +122,278 @@ uint8_t const* tud_descriptor_device_cb(void) {
|
||||
#define EPNUM_VIDEO_IN 0x81
|
||||
#endif
|
||||
|
||||
// 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.
|
||||
// Select interface descriptor and length accordingly.
|
||||
#if defined(CFG_EXAMPLE_VIDEO_READONLY) && !defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
|
||||
#if CFG_TUD_VIDEO_STREAMING_BULK
|
||||
#define ITF_VIDEO_DESC(epsize) TUD_VIDEO_CAPTURE_DESCRIPTOR_MJPEG_BULK(4, EPNUM_VIDEO_IN, FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE, epsize)
|
||||
#define ITF_VIDEO_LEN TUD_VIDEO_CAPTURE_DESC_MJPEG_BULK_LEN
|
||||
#else
|
||||
#define ITF_VIDEO_DESC(epsize) TUD_VIDEO_CAPTURE_DESCRIPTOR_MJPEG(4, EPNUM_VIDEO_IN, FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE, epsize)
|
||||
#define ITF_VIDEO_LEN TUD_VIDEO_CAPTURE_DESC_MJPEG_LEN
|
||||
#endif
|
||||
#define USE_MJPEG 1
|
||||
#else
|
||||
#if CFG_TUD_VIDEO_STREAMING_BULK
|
||||
#define ITF_VIDEO_DESC(epsize) TUD_VIDEO_CAPTURE_DESCRIPTOR_UNCOMPR_BULK(4, EPNUM_VIDEO_IN, FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE, epsize)
|
||||
#define ITF_VIDEO_LEN TUD_VIDEO_CAPTURE_DESC_UNCOMPR_BULK_LEN
|
||||
#else
|
||||
#define ITF_VIDEO_DESC(epsize) TUD_VIDEO_CAPTURE_DESCRIPTOR_UNCOMPR(4, EPNUM_VIDEO_IN, FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE, epsize)
|
||||
#define ITF_VIDEO_LEN TUD_VIDEO_CAPTURE_DESC_UNCOMPR_LEN
|
||||
#endif
|
||||
#define USE_MJPEG 0
|
||||
#endif
|
||||
|
||||
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + ITF_VIDEO_LEN)
|
||||
#define USE_ISO_STREAMING (!CFG_TUD_VIDEO_STREAMING_BULK)
|
||||
|
||||
// full speed descriptor
|
||||
uint8_t const desc_fs_configuration[] = {
|
||||
// Config number, interface count, string index, total length, attribute, power in mA
|
||||
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0, 500),
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
tusb_desc_interface_t itf;
|
||||
tusb_desc_video_control_header_1itf_t header;
|
||||
tusb_desc_video_control_camera_terminal_t camera_terminal;
|
||||
tusb_desc_video_control_output_terminal_t output_terminal;
|
||||
} uvc_control_desc_t;
|
||||
|
||||
// IAD for Video Control
|
||||
ITF_VIDEO_DESC(CFG_TUD_VIDEO_STREAMING_BULK ? 64 : CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE)
|
||||
/* Windows support YUY2 and NV12
|
||||
* https://docs.microsoft.com/en-us/windows-hardware/drivers/stream/usb-video-class-driver-overview */
|
||||
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
tusb_desc_interface_t itf;
|
||||
tusb_desc_video_streaming_input_header_1byte_t header;
|
||||
|
||||
#if USE_MJPEG
|
||||
tusb_desc_video_format_mjpeg_t format;
|
||||
tusb_desc_video_frame_mjpeg_continuous_t frame;
|
||||
#else
|
||||
tusb_desc_video_format_uncompressed_t format;
|
||||
tusb_desc_video_frame_uncompressed_continuous_t frame;
|
||||
#endif
|
||||
|
||||
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;
|
||||
} uvc_streaming_desc_t;
|
||||
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
tusb_desc_configuration_t config;
|
||||
tusb_desc_interface_assoc_t iad;
|
||||
uvc_control_desc_t video_control;
|
||||
uvc_streaming_desc_t video_streaming;
|
||||
} uvc_cfg_desc_t;
|
||||
|
||||
const uvc_cfg_desc_t desc_fs_configuration = {
|
||||
.config = {
|
||||
.bLength = sizeof(tusb_desc_configuration_t),
|
||||
.bDescriptorType = TUSB_DESC_CONFIGURATION,
|
||||
|
||||
.wTotalLength = sizeof(uvc_cfg_desc_t),
|
||||
.bNumInterfaces = ITF_NUM_TOTAL,
|
||||
.bConfigurationValue = 1,
|
||||
.iConfiguration = 0,
|
||||
.bmAttributes = TU_BIT(7),
|
||||
.bMaxPower = 100 / 2
|
||||
},
|
||||
.iad = {
|
||||
.bLength = sizeof(tusb_desc_interface_assoc_t),
|
||||
.bDescriptorType = TUSB_DESC_INTERFACE_ASSOCIATION,
|
||||
|
||||
.bFirstInterface = ITF_NUM_VIDEO_CONTROL,
|
||||
.bInterfaceCount = 2,
|
||||
.bFunctionClass = TUSB_CLASS_VIDEO,
|
||||
.bFunctionSubClass = VIDEO_SUBCLASS_INTERFACE_COLLECTION,
|
||||
.bFunctionProtocol = VIDEO_ITF_PROTOCOL_UNDEFINED,
|
||||
.iFunction = 0
|
||||
},
|
||||
|
||||
.video_control = {
|
||||
.itf = {
|
||||
.bLength = sizeof(tusb_desc_interface_t),
|
||||
.bDescriptorType = TUSB_DESC_INTERFACE,
|
||||
|
||||
.bInterfaceNumber = ITF_NUM_VIDEO_CONTROL,
|
||||
.bAlternateSetting = 0,
|
||||
.bNumEndpoints = 0,
|
||||
.bInterfaceClass = TUSB_CLASS_VIDEO,
|
||||
.bInterfaceSubClass = VIDEO_SUBCLASS_CONTROL,
|
||||
.bInterfaceProtocol = VIDEO_ITF_PROTOCOL_15,
|
||||
.iInterface = STRID_UVC_CONTROL
|
||||
},
|
||||
.header = {
|
||||
.bLength = sizeof(tusb_desc_video_control_header_1itf_t),
|
||||
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
|
||||
.bDescriptorSubType = VIDEO_CS_ITF_VC_HEADER,
|
||||
|
||||
.bcdUVC = VIDEO_BCD_1_50,
|
||||
.wTotalLength = sizeof(uvc_control_desc_t) - sizeof(tusb_desc_interface_t), // CS VC descriptors only
|
||||
.dwClockFrequency = UVC_CLOCK_FREQUENCY,
|
||||
.bInCollection = 1,
|
||||
.baInterfaceNr = { ITF_NUM_VIDEO_STREAMING }
|
||||
},
|
||||
.camera_terminal = {
|
||||
.bLength = sizeof(tusb_desc_video_control_camera_terminal_t),
|
||||
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
|
||||
.bDescriptorSubType = VIDEO_CS_ITF_VC_INPUT_TERMINAL,
|
||||
|
||||
.bTerminalID = UVC_ENTITY_CAP_INPUT_TERMINAL,
|
||||
.wTerminalType = VIDEO_ITT_CAMERA,
|
||||
.bAssocTerminal = 0,
|
||||
.iTerminal = 0,
|
||||
.wObjectiveFocalLengthMin = 0,
|
||||
.wObjectiveFocalLengthMax = 0,
|
||||
.wOcularFocalLength = 0,
|
||||
.bControlSize = 3,
|
||||
.bmControls = { 0, 0, 0 }
|
||||
},
|
||||
.output_terminal = {
|
||||
.bLength = sizeof(tusb_desc_video_control_output_terminal_t),
|
||||
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
|
||||
.bDescriptorSubType = VIDEO_CS_ITF_VC_OUTPUT_TERMINAL,
|
||||
|
||||
.bTerminalID = UVC_ENTITY_CAP_OUTPUT_TERMINAL,
|
||||
.wTerminalType = VIDEO_TT_STREAMING,
|
||||
.bAssocTerminal = 0,
|
||||
.bSourceID = UVC_ENTITY_CAP_INPUT_TERMINAL,
|
||||
.iTerminal = 0
|
||||
}
|
||||
},
|
||||
|
||||
.video_streaming = {
|
||||
.itf = {
|
||||
.bLength = sizeof(tusb_desc_interface_t),
|
||||
.bDescriptorType = TUSB_DESC_INTERFACE,
|
||||
|
||||
.bInterfaceNumber = ITF_NUM_VIDEO_STREAMING,
|
||||
.bAlternateSetting = 0,
|
||||
.bNumEndpoints = CFG_TUD_VIDEO_STREAMING_BULK, // bulk 1, iso 0
|
||||
.bInterfaceClass = TUSB_CLASS_VIDEO,
|
||||
.bInterfaceSubClass = VIDEO_SUBCLASS_STREAMING,
|
||||
.bInterfaceProtocol = VIDEO_ITF_PROTOCOL_15,
|
||||
.iInterface = STRID_UVC_STREAMING
|
||||
},
|
||||
.header = {
|
||||
.bLength = sizeof(tusb_desc_video_streaming_input_header_1byte_t),
|
||||
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
|
||||
.bDescriptorSubType = VIDEO_CS_ITF_VS_INPUT_HEADER,
|
||||
|
||||
.bNumFormats = 1,
|
||||
.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,
|
||||
.bmInfo = 0,
|
||||
.bTerminalLink = UVC_ENTITY_CAP_OUTPUT_TERMINAL,
|
||||
.bStillCaptureMethod = 0,
|
||||
.bTriggerSupport = 0,
|
||||
.bTriggerUsage = 0,
|
||||
.bControlSize = 1,
|
||||
.bmaControls = { 0 }
|
||||
},
|
||||
.format = {
|
||||
#if USE_MJPEG
|
||||
.bLength = sizeof(tusb_desc_video_format_mjpeg_t),
|
||||
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
|
||||
.bDescriptorSubType = VIDEO_CS_ITF_VS_FORMAT_MJPEG,
|
||||
.bFormatIndex = 1, // 1-based index
|
||||
.bNumFrameDescriptors = 1,
|
||||
.bmFlags = 0,
|
||||
#else
|
||||
.bLength = sizeof(tusb_desc_video_format_uncompressed_t),
|
||||
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
|
||||
.bDescriptorSubType = VIDEO_CS_ITF_VS_FORMAT_UNCOMPRESSED,
|
||||
.bFormatIndex = 1, // 1-based index
|
||||
.bNumFrameDescriptors = 1,
|
||||
.guidFormat = { TUD_VIDEO_GUID_YUY2 },
|
||||
.bBitsPerPixel = 16,
|
||||
#endif
|
||||
.bDefaultFrameIndex = 1,
|
||||
.bAspectRatioX = 0,
|
||||
.bAspectRatioY = 0,
|
||||
.bmInterlaceFlags = 0,
|
||||
.bCopyProtect = 0
|
||||
},
|
||||
.frame = {
|
||||
#if USE_MJPEG
|
||||
.bLength = sizeof(tusb_desc_video_frame_mjpeg_continuous_t),
|
||||
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
|
||||
.bDescriptorSubType = VIDEO_CS_ITF_VS_FRAME_MJPEG,
|
||||
#else
|
||||
.bLength = sizeof(tusb_desc_video_frame_uncompressed_continuous_t),
|
||||
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
|
||||
.bDescriptorSubType = VIDEO_CS_ITF_VS_FRAME_UNCOMPRESSED,
|
||||
#endif
|
||||
.bFrameIndex = 1, // 1-based index
|
||||
.bmCapabilities = 0,
|
||||
.wWidth = FRAME_WIDTH,
|
||||
.wHeight = FRAME_HEIGHT,
|
||||
.dwMinBitRate = FRAME_WIDTH * FRAME_HEIGHT * 16 * 1,
|
||||
.dwMaxBitRate = FRAME_WIDTH * FRAME_HEIGHT * 16 * FRAME_RATE,
|
||||
.dwMaxVideoFrameBufferSize = FRAME_WIDTH * FRAME_HEIGHT * 16 / 8,
|
||||
.dwDefaultFrameInterval = 10000000 / FRAME_RATE,
|
||||
.bFrameIntervalType = 0, // continuous
|
||||
.dwFrameInterval = {
|
||||
10000000 / FRAME_RATE, // min
|
||||
10000000, // max
|
||||
10000000 / FRAME_RATE // step
|
||||
}
|
||||
},
|
||||
.color = {
|
||||
.bLength = sizeof(tusb_desc_video_streaming_color_matching_t),
|
||||
.bDescriptorType = TUSB_DESC_CS_INTERFACE,
|
||||
.bDescriptorSubType = VIDEO_CS_ITF_VS_COLORFORMAT,
|
||||
|
||||
.bColorPrimaries = VIDEO_COLOR_PRIMARIES_BT709,
|
||||
.bTransferCharacteristics = VIDEO_COLOR_XFER_CH_BT709,
|
||||
.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 = {
|
||||
.bLength = sizeof(tusb_desc_endpoint_t),
|
||||
.bDescriptorType = TUSB_DESC_ENDPOINT,
|
||||
|
||||
.bEndpointAddress = EPNUM_VIDEO_IN,
|
||||
.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,
|
||||
.bInterval = 1
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#if TUD_OPT_HIGH_SPEED
|
||||
// Per USB specs: high speed capable device must report device_qualifier and other_speed_configuration
|
||||
uint8_t const desc_hs_configuration[] = {
|
||||
// Config number, interface count, string index, total length, attribute, power in mA
|
||||
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0, 500),
|
||||
uvc_cfg_desc_t desc_hs_configuration;
|
||||
|
||||
// IAD for Video Control
|
||||
ITF_VIDEO_DESC(CFG_TUD_VIDEO_STREAMING_BULK ? 512 : CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE)
|
||||
};
|
||||
static uint8_t * get_hs_configuration_desc(void) {
|
||||
static bool init = false;
|
||||
|
||||
if (!init) {
|
||||
desc_hs_configuration = desc_fs_configuration;
|
||||
// change endpoint bulk size to 512 if bulk streaming
|
||||
if (CFG_TUD_VIDEO_STREAMING_BULK) {
|
||||
desc_hs_configuration.video_streaming.ep.wMaxPacketSize = 512;
|
||||
}
|
||||
}
|
||||
init = true;
|
||||
|
||||
return (uint8_t *) &desc_hs_configuration;
|
||||
}
|
||||
|
||||
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
|
||||
tusb_desc_device_qualifier_t const desc_device_qualifier = {
|
||||
.bLength = sizeof(tusb_desc_device_t),
|
||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
||||
.bcdUSB = USB_BCD,
|
||||
.bLength = sizeof(tusb_desc_device_t),
|
||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
||||
.bcdUSB = USB_BCD,
|
||||
|
||||
.bDeviceClass = TUSB_CLASS_MISC,
|
||||
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
|
||||
.bDeviceProtocol = MISC_PROTOCOL_IAD,
|
||||
.bDeviceClass = TUSB_CLASS_MISC,
|
||||
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
|
||||
.bDeviceProtocol = MISC_PROTOCOL_IAD,
|
||||
|
||||
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
|
||||
.bNumConfigurations = 0x01,
|
||||
.bReserved = 0x00
|
||||
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
|
||||
.bNumConfigurations = 0x01,
|
||||
.bReserved = 0x00
|
||||
};
|
||||
|
||||
// Invoked when received GET DEVICE QUALIFIER DESCRIPTOR request
|
||||
@@ -160,7 +410,11 @@ uint8_t const* tud_descriptor_device_qualifier_cb(void) {
|
||||
uint8_t const* tud_descriptor_other_speed_configuration_cb(uint8_t index) {
|
||||
(void) index; // for multiple configurations
|
||||
// if link speed is high return fullspeed config, and vice versa
|
||||
return (tud_speed_get() == TUSB_SPEED_HIGH) ? desc_fs_configuration : desc_hs_configuration;
|
||||
if (tud_speed_get() == TUSB_SPEED_HIGH) {
|
||||
return (uint8_t const*) &desc_fs_configuration;
|
||||
} else {
|
||||
return get_hs_configuration_desc();
|
||||
}
|
||||
}
|
||||
#endif // highspeed
|
||||
|
||||
@@ -172,33 +426,19 @@ uint8_t const* tud_descriptor_configuration_cb(uint8_t index) {
|
||||
|
||||
#if TUD_OPT_HIGH_SPEED
|
||||
// Although we are highspeed, host may be fullspeed.
|
||||
return (tud_speed_get() == TUSB_SPEED_HIGH) ? desc_hs_configuration : desc_fs_configuration;
|
||||
#else
|
||||
return desc_fs_configuration;
|
||||
if (tud_speed_get() == TUSB_SPEED_HIGH) {
|
||||
return get_hs_configuration_desc();
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
return (uint8_t const*) &desc_fs_configuration;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// String Descriptors
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// String Descriptor Index
|
||||
enum {
|
||||
STRID_LANGID = 0,
|
||||
STRID_MANUFACTURER,
|
||||
STRID_PRODUCT,
|
||||
STRID_SERIAL,
|
||||
};
|
||||
|
||||
// array of pointer to string descriptors
|
||||
char const* string_desc_arr[] = {
|
||||
(const char[]) {0x09, 0x04}, // 0: is supported language is English (0x0409)
|
||||
"TinyUSB", // 1: Manufacturer
|
||||
"TinyUSB Device", // 2: Product
|
||||
NULL, // 3: Serials will use unique ID if possible
|
||||
"TinyUSB UVC", // 4: UVC Interface
|
||||
};
|
||||
|
||||
static uint16_t _desc_str[32 + 1];
|
||||
|
||||
// Invoked when received GET STRING DESCRIPTOR request
|
||||
|
@@ -27,21 +27,11 @@
|
||||
#ifndef _USB_DESCRIPTORS_H_
|
||||
#define _USB_DESCRIPTORS_H_
|
||||
|
||||
/* Time stamp base clock. It is a deprecated parameter. */
|
||||
#define UVC_CLOCK_FREQUENCY 27000000
|
||||
/* video capture path */
|
||||
#define UVC_ENTITY_CAP_INPUT_TERMINAL 0x01
|
||||
#define UVC_ENTITY_CAP_OUTPUT_TERMINAL 0x02
|
||||
|
||||
#define FRAME_WIDTH 128
|
||||
#define FRAME_HEIGHT 96
|
||||
#define FRAME_RATE 10
|
||||
|
||||
enum {
|
||||
ITF_NUM_VIDEO_CONTROL,
|
||||
ITF_NUM_VIDEO_STREAMING,
|
||||
ITF_NUM_TOTAL
|
||||
};
|
||||
// NOTE: descriptor template is not used but leave here as reference
|
||||
|
||||
#define TUD_VIDEO_CAPTURE_DESC_UNCOMPR_LEN (\
|
||||
TUD_VIDEO_DESC_IAD_LEN\
|
||||
@@ -146,7 +136,7 @@ enum {
|
||||
/* Video stream frame format */ \
|
||||
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 / 8, \
|
||||
(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), \
|
||||
/* VS alt 1 */\
|
||||
@@ -210,7 +200,7 @@ enum {
|
||||
/* Video stream frame format */ \
|
||||
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 / 8, \
|
||||
(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_EP_BULK(_epin, _epsize, 1)
|
||||
@@ -223,7 +213,7 @@ enum {
|
||||
TUD_VIDEO_DESC_CS_VC(0x0150, TUD_VIDEO_DESC_CAMERA_TERM_LEN + TUD_VIDEO_DESC_OUTPUT_TERM_LEN, UVC_CLOCK_FREQUENCY, ITF_NUM_VIDEO_STREAMING), \
|
||||
/* Camera Terminal: ID, bAssocTerminal, iTerminal, focal min, max, length, bmControl */ \
|
||||
TUD_VIDEO_DESC_CAMERA_TERM(UVC_ENTITY_CAP_INPUT_TERMINAL, 0, 0, 0, 0, 0, 0), \
|
||||
TUD_VIDEO_DESC_OUTPUT_TERM(UVC_ENTITY_CAP_OUTPUT_TERMINAL, VIDEO_TT_STREAMING, 0, 1, 0), \
|
||||
TUD_VIDEO_DESC_OUTPUT_TERM(UVC_ENTITY_CAP_OUTPUT_TERMINAL, VIDEO_TT_STREAMING, 0, UVC_ENTITY_CAP_INPUT_TERMINAL, 0), \
|
||||
/* Video stream alt. 0 */ \
|
||||
TUD_VIDEO_DESC_STD_VS(ITF_NUM_VIDEO_STREAMING, 0, 1, _stridx), \
|
||||
/* Video stream header for without still image capture */ \
|
||||
|
@@ -33,9 +33,26 @@ extern "C" {
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_FREERTOS
|
||||
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
|
||||
// ESP-IDF need "freertos/" prefix in include path.
|
||||
// CFG_TUSB_OS_INC_PATH should be defined accordingly.
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/timers.h"
|
||||
#else
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
#include "queue.h"
|
||||
#include "task.h"
|
||||
#include "timers.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Define the default baudrate
|
||||
#ifndef CFG_BOARD_UART_BAUDRATE
|
||||
#define CFG_BOARD_UART_BAUDRATE 115200 ///< Default baud rate
|
||||
|
@@ -29,6 +29,10 @@
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
|
||||
enum {
|
||||
VIDEO_BCD_1_50 = 0x0150,
|
||||
};
|
||||
|
||||
// Table 3-19 Color Matching Descriptor
|
||||
typedef enum {
|
||||
VIDEO_COLOR_PRIMARIES_UNDEFINED = 0x00,
|
||||
@@ -198,55 +202,98 @@ typedef enum {
|
||||
} video_terminal_type_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Descriptors
|
||||
// Video Control (VC) Descriptors
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/* 2.3.4.2 */
|
||||
#define tusb_desc_video_control_header_nitf_t(_nitf) \
|
||||
struct TU_ATTR_PACKED { \
|
||||
uint8_t bLength; \
|
||||
uint8_t bDescriptorType; \
|
||||
uint8_t bDescriptorSubType; \
|
||||
uint16_t bcdUVC; \
|
||||
uint16_t wTotalLength; \
|
||||
uint32_t dwClockFrequency; /* deprecated */ \
|
||||
uint8_t bInCollection; \
|
||||
uint8_t baInterfaceNr[_nitf]; \
|
||||
}
|
||||
|
||||
typedef tusb_desc_video_control_header_nitf_t() tusb_desc_video_control_header_t;
|
||||
typedef tusb_desc_video_control_header_nitf_t(1) tusb_desc_video_control_header_1itf_t;
|
||||
typedef tusb_desc_video_control_header_nitf_t(2) tusb_desc_video_control_header_2itf_t;
|
||||
typedef tusb_desc_video_control_header_nitf_t(3) tusb_desc_video_control_header_3itf_t;
|
||||
typedef tusb_desc_video_control_header_nitf_t(4) tusb_desc_video_control_header_4itf_t;
|
||||
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDescriptorSubType;
|
||||
uint16_t bcdUVC;
|
||||
uint16_t wTotalLength;
|
||||
uint32_t dwClockFrequency;
|
||||
uint8_t bInCollection;
|
||||
uint8_t baInterfaceNr[];
|
||||
} tusb_desc_cs_video_ctl_itf_hdr_t;
|
||||
uint8_t bTerminalID;
|
||||
uint16_t wTerminalType;
|
||||
uint8_t bAssocTerminal;
|
||||
uint8_t iTerminal;
|
||||
} tusb_desc_video_control_input_terminal_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(tusb_desc_video_control_input_terminal_t) == 8, "size is not correct");
|
||||
|
||||
/* 2.4.3.3 */
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bHeaderLength;
|
||||
union {
|
||||
uint8_t bmHeaderInfo;
|
||||
struct {
|
||||
uint8_t FrameID: 1;
|
||||
uint8_t EndOfFrame: 1;
|
||||
uint8_t PresentationTime: 1;
|
||||
uint8_t SourceClockReference: 1;
|
||||
uint8_t PayloadSpecific: 1;
|
||||
uint8_t StillImage: 1;
|
||||
uint8_t Error: 1;
|
||||
uint8_t EndOfHeader: 1;
|
||||
};
|
||||
};
|
||||
} tusb_video_payload_header_t;
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDescriptorSubType;
|
||||
uint8_t bTerminalID;
|
||||
uint16_t wTerminalType;
|
||||
uint8_t bAssocTerminal;
|
||||
uint8_t bSourceID;
|
||||
uint8_t iTerminal;
|
||||
} tusb_desc_video_control_output_terminal_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(tusb_desc_video_control_output_terminal_t) == 9, "size is not correct");
|
||||
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDescriptorSubType;
|
||||
uint8_t bTerminalID;
|
||||
uint16_t wTerminalType;
|
||||
uint8_t bAssocTerminal;
|
||||
uint8_t iTerminal;
|
||||
|
||||
uint16_t wObjectiveFocalLengthMin;
|
||||
uint16_t wObjectiveFocalLengthMax;
|
||||
uint16_t wOcularFocalLength;
|
||||
uint8_t bControlSize;
|
||||
uint8_t bmControls[3];
|
||||
} tusb_desc_video_control_camera_terminal_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(tusb_desc_video_control_camera_terminal_t) == 18, "size is not correct");
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Video Streaming (VS) Descriptors
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/* 3.9.2.1 */
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDescriptorSubType;
|
||||
uint8_t bNumFormats;
|
||||
uint16_t wTotalLength;
|
||||
uint8_t bEndpointAddress;
|
||||
uint8_t bmInfo;
|
||||
uint8_t bTerminalLink;
|
||||
uint8_t bStillCaptureMethod;
|
||||
uint8_t bTriggerSupport;
|
||||
uint8_t bTriggerUsage;
|
||||
uint8_t bControlSize;
|
||||
uint8_t bmaControls[];
|
||||
} tusb_desc_cs_video_stm_itf_in_hdr_t;
|
||||
#define tusb_desc_video_streaming_input_header_nbyte_t(_nb) \
|
||||
struct TU_ATTR_PACKED { \
|
||||
uint8_t bLength; \
|
||||
uint8_t bDescriptorType; \
|
||||
uint8_t bDescriptorSubType; \
|
||||
uint8_t bNumFormats; /* Number of video payload Format descriptors for this interface */ \
|
||||
uint16_t wTotalLength; \
|
||||
uint8_t bEndpointAddress; \
|
||||
uint8_t bmInfo; /* Bit 0: dynamic format change supported */ \
|
||||
uint8_t bTerminalLink; \
|
||||
uint8_t bStillCaptureMethod; \
|
||||
uint8_t bTriggerSupport; /* Hardware trigger supported */ \
|
||||
uint8_t bTriggerUsage; \
|
||||
uint8_t bControlSize; /* sizeof of each control item */ \
|
||||
uint8_t bmaControls[_nb]; \
|
||||
}
|
||||
|
||||
typedef tusb_desc_video_streaming_input_header_nbyte_t() tusb_desc_video_streaming_input_header_t;
|
||||
typedef tusb_desc_video_streaming_input_header_nbyte_t(1) tusb_desc_video_streaming_input_header_1byte_t;
|
||||
typedef tusb_desc_video_streaming_input_header_nbyte_t(2) tusb_desc_video_streaming_input_header_2byte_t;
|
||||
typedef tusb_desc_video_streaming_input_header_nbyte_t(3) tusb_desc_video_streaming_input_header_3byte_t;
|
||||
typedef tusb_desc_video_streaming_input_header_nbyte_t(4) tusb_desc_video_streaming_input_header_4byte_t;
|
||||
|
||||
/* 3.9.2.2 */
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
@@ -259,7 +306,7 @@ typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bTerminalLink;
|
||||
uint8_t bControlSize;
|
||||
uint8_t bmaControls[];
|
||||
} tusb_desc_cs_video_stm_itf_out_hdr_t;
|
||||
} tusb_desc_video_streaming_output_header_t;
|
||||
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength;
|
||||
@@ -285,14 +332,33 @@ typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bmaControls[];
|
||||
} output;
|
||||
};
|
||||
} tusb_desc_cs_video_stm_itf_hdr_t;
|
||||
} tusb_desc_video_streaming_inout_header_t;
|
||||
|
||||
// 3.9.2.6 Color Matching Descriptor
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDescriptorSubType;
|
||||
uint8_t bColorPrimaries;
|
||||
uint8_t bTransferCharacteristics;
|
||||
uint8_t bMatrixCoefficients;
|
||||
} tusb_desc_video_streaming_color_matching_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(tusb_desc_video_streaming_color_matching_t) == 6, "size is not correct");
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Format and Frame Descriptor
|
||||
// Note: bFormatIndex & bFrameIndex are 1-based index
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
//------------- Uncompressed -------------//
|
||||
// Uncompressed payload specs: 3.1.1 format descriptor
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDescriptorSubType;
|
||||
uint8_t bFormatIndex;
|
||||
uint8_t bNumFrameDescriptors;
|
||||
uint8_t bNumFrameDescriptors; // Number of frame descriptors for this format
|
||||
uint8_t guidFormat[16];
|
||||
uint8_t bBitsPerPixel;
|
||||
uint8_t bDefaultFrameIndex;
|
||||
@@ -300,22 +366,65 @@ typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bAspectRatioY;
|
||||
uint8_t bmInterlaceFlags;
|
||||
uint8_t bCopyProtect;
|
||||
} tusb_desc_cs_video_fmt_uncompressed_t;
|
||||
} tusb_desc_video_format_uncompressed_t;
|
||||
|
||||
// Uncompressed payload specs: 3.1.2 frame descriptor
|
||||
#define tusb_desc_video_frame_uncompressed_nint_t(_nint) \
|
||||
struct TU_ATTR_PACKED { \
|
||||
uint8_t bLength; \
|
||||
uint8_t bDescriptorType; \
|
||||
uint8_t bDescriptorSubType; \
|
||||
uint8_t bFrameIndex; \
|
||||
uint8_t bmCapabilities; \
|
||||
uint16_t wWidth; \
|
||||
uint16_t wHeight; \
|
||||
uint32_t dwMinBitRate; \
|
||||
uint32_t dwMaxBitRate; \
|
||||
uint32_t dwMaxVideoFrameBufferSize; /* deprecated in 1.5 */ \
|
||||
uint32_t dwDefaultFrameInterval; \
|
||||
uint8_t bFrameIntervalType; \
|
||||
uint32_t dwFrameInterval[_nint]; \
|
||||
}
|
||||
|
||||
typedef tusb_desc_video_frame_uncompressed_nint_t() tusb_desc_video_frame_uncompressed_t;
|
||||
typedef tusb_desc_video_frame_uncompressed_nint_t(1) tusb_desc_video_frame_uncompressed_1int_t;
|
||||
typedef tusb_desc_video_frame_uncompressed_nint_t(2) tusb_desc_video_frame_uncompressed_2int_t;
|
||||
typedef tusb_desc_video_frame_uncompressed_nint_t(3) tusb_desc_video_frame_uncompressed_3int_t;
|
||||
typedef tusb_desc_video_frame_uncompressed_nint_t(4) tusb_desc_video_frame_uncompressed_4int_t;
|
||||
|
||||
// continuous = 3 intervals: min, max, step
|
||||
typedef tusb_desc_video_frame_uncompressed_3int_t tusb_desc_video_frame_uncompressed_continuous_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(tusb_desc_video_frame_uncompressed_continuous_t) == 38, "size is not correct");
|
||||
|
||||
//------------- MJPEG -------------//
|
||||
// MJPEG payload specs: 3.1.1 format descriptor
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDescriptorSubType;
|
||||
uint8_t bFormatIndex;
|
||||
uint8_t bNumFrameDescriptors;
|
||||
uint8_t bmFlags;
|
||||
uint8_t bmFlags; // Bit 0: fixed size samples (1 = yes)
|
||||
uint8_t bDefaultFrameIndex;
|
||||
uint8_t bAspectRatioX;
|
||||
uint8_t bAspectRatioY;
|
||||
uint8_t bmInterlaceFlags;
|
||||
uint8_t bCopyProtect;
|
||||
} tusb_desc_cs_video_fmt_mjpeg_t;
|
||||
} tusb_desc_video_format_mjpeg_t;
|
||||
|
||||
// MJPEG payload specs: 3.1.2 frame descriptor (same as uncompressed)
|
||||
typedef tusb_desc_video_frame_uncompressed_t tusb_desc_video_frame_mjpeg_t;
|
||||
typedef tusb_desc_video_frame_uncompressed_1int_t tusb_desc_video_frame_mjpeg_1int_t;
|
||||
typedef tusb_desc_video_frame_uncompressed_2int_t tusb_desc_video_frame_mjpeg_2int_t;
|
||||
typedef tusb_desc_video_frame_uncompressed_3int_t tusb_desc_video_frame_mjpeg_3int_t;
|
||||
typedef tusb_desc_video_frame_uncompressed_4int_t tusb_desc_video_frame_mjpeg_4int_t;
|
||||
|
||||
// continuous = 3 intervals: min, max, step
|
||||
typedef tusb_desc_video_frame_mjpeg_3int_t tusb_desc_video_frame_mjpeg_continuous_t;
|
||||
|
||||
//------------- DV -------------//
|
||||
// DV payload specs: 3.1.1
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
@@ -323,8 +432,9 @@ typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bFormatIndex;
|
||||
uint32_t dwMaxVideoFrameBufferSize; /* deprecated */
|
||||
uint8_t bFormatType;
|
||||
} tusb_desc_cs_video_fmt_dv_t;
|
||||
} tusb_desc_video_format_dv_t;
|
||||
|
||||
// Frame Based payload specs: 3.1.1
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
@@ -339,25 +449,7 @@ typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bmInterlaceFlags;
|
||||
uint8_t bCopyProtect;
|
||||
uint8_t bVaribaleSize;
|
||||
} tusb_desc_cs_video_fmt_frame_based_t;
|
||||
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDescriptorSubType;
|
||||
uint8_t bFrameIndex;
|
||||
uint8_t bmCapabilities;
|
||||
uint16_t wWidth;
|
||||
uint16_t wHeight;
|
||||
uint32_t dwMinBitRate;
|
||||
uint32_t dwMaxBitRate;
|
||||
uint32_t dwMaxVideoFrameBufferSize; /* deprecated */
|
||||
uint32_t dwDefaultFrameInterval;
|
||||
uint8_t bFrameIntervalType;
|
||||
uint32_t dwFrameInterval[];
|
||||
} tusb_desc_cs_video_frm_uncompressed_t;
|
||||
|
||||
typedef tusb_desc_cs_video_frm_uncompressed_t tusb_desc_cs_video_frm_mjpeg_t;
|
||||
} tusb_desc_video_format_framebased_t;
|
||||
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength;
|
||||
@@ -373,12 +465,30 @@ typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bFrameIntervalType;
|
||||
uint32_t dwBytesPerLine;
|
||||
uint32_t dwFrameInterval[];
|
||||
} tusb_desc_cs_video_frm_frame_based_t;
|
||||
} tusb_desc_video_frame_framebased_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Requests
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/* 2.4.3.3 */
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bHeaderLength;
|
||||
union {
|
||||
uint8_t bmHeaderInfo;
|
||||
struct {
|
||||
uint8_t FrameID: 1;
|
||||
uint8_t EndOfFrame: 1;
|
||||
uint8_t PresentationTime: 1;
|
||||
uint8_t SourceClockReference: 1;
|
||||
uint8_t PayloadSpecific: 1;
|
||||
uint8_t StillImage: 1;
|
||||
uint8_t Error: 1;
|
||||
uint8_t EndOfHeader: 1;
|
||||
};
|
||||
};
|
||||
} tusb_video_payload_header_t;
|
||||
|
||||
/* 4.3.1.1 */
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
union {
|
||||
|
@@ -50,17 +50,17 @@
|
||||
|
||||
typedef struct {
|
||||
tusb_desc_interface_t std;
|
||||
tusb_desc_cs_video_ctl_itf_hdr_t ctl;
|
||||
tusb_desc_video_control_header_t ctl;
|
||||
} tusb_desc_vc_itf_t;
|
||||
|
||||
typedef struct {
|
||||
tusb_desc_interface_t std;
|
||||
tusb_desc_cs_video_stm_itf_hdr_t stm;
|
||||
tusb_desc_video_streaming_inout_header_t stm;
|
||||
} tusb_desc_vs_itf_t;
|
||||
|
||||
typedef union {
|
||||
tusb_desc_cs_video_ctl_itf_hdr_t ctl;
|
||||
tusb_desc_cs_video_stm_itf_hdr_t stm;
|
||||
tusb_desc_video_control_header_t ctl;
|
||||
tusb_desc_video_streaming_inout_header_t stm;
|
||||
} tusb_desc_video_itf_hdr_t;
|
||||
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
@@ -78,9 +78,9 @@ typedef union {
|
||||
uint8_t bFormatIndex;
|
||||
uint8_t bNumFrameDescriptors;
|
||||
};
|
||||
tusb_desc_cs_video_fmt_uncompressed_t uncompressed;
|
||||
tusb_desc_cs_video_fmt_mjpeg_t mjpeg;
|
||||
tusb_desc_cs_video_fmt_frame_based_t frame_based;
|
||||
tusb_desc_video_format_uncompressed_t uncompressed;
|
||||
tusb_desc_video_format_mjpeg_t mjpeg;
|
||||
tusb_desc_video_format_framebased_t frame_based;
|
||||
} tusb_desc_cs_video_fmt_t;
|
||||
|
||||
typedef union {
|
||||
@@ -93,9 +93,9 @@ typedef union {
|
||||
uint16_t wWidth;
|
||||
uint16_t wHeight;
|
||||
};
|
||||
tusb_desc_cs_video_frm_uncompressed_t uncompressed;
|
||||
tusb_desc_cs_video_frm_mjpeg_t mjpeg;
|
||||
tusb_desc_cs_video_frm_frame_based_t frame_based;
|
||||
tusb_desc_video_frame_uncompressed_t uncompressed;
|
||||
tusb_desc_video_frame_mjpeg_t mjpeg;
|
||||
tusb_desc_video_frame_framebased_t frame_based;
|
||||
} tusb_desc_cs_video_frm_t;
|
||||
|
||||
/* video streaming interface */
|
||||
|
@@ -399,6 +399,8 @@ typedef struct TU_ATTR_PACKED {
|
||||
uint8_t iFunction ; ///< Index of the string descriptor describing the interface association.
|
||||
} tusb_desc_interface_assoc_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_interface_assoc_t) == 8, "size is not correct");
|
||||
|
||||
// USB String Descriptor
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes
|
||||
@@ -469,7 +471,6 @@ typedef struct TU_ATTR_PACKED {
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(tusb_control_request_t) == 8, "size is not correct");
|
||||
|
||||
|
||||
TU_ATTR_PACKED_END // End of all packed definitions
|
||||
TU_ATTR_BIT_FIELD_ORDER_END
|
||||
|
||||
|
Reference in New Issue
Block a user