mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
Merge pull request #2426 from hathach/cleanup-uvc-example
house keeping uvc example
This commit is contained in:
commit
5aaa1aa63e
@ -1,4 +1,5 @@
|
||||
#if defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
|
||||
// uncopmressed frame
|
||||
static const unsigned char frame_buffer[128 * (96 + 1) * 2] = {
|
||||
/* 0 */
|
||||
0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80, 0xeb, 0x80,
|
||||
@ -1650,8 +1651,10 @@ static const unsigned char frame_buffer[128 * (96 + 1) * 2] = {
|
||||
0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80,
|
||||
0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80, 0x10, 0x80,
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
// mpeg compressed data (not CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
|
||||
#define color_bar_0_jpg_len 511
|
||||
#define color_bar_1_jpg_len 512
|
||||
#define color_bar_2_jpg_len 511
|
||||
|
@ -40,7 +40,7 @@
|
||||
* - 1000 ms : device mounted
|
||||
* - 2500 ms : device is suspended
|
||||
*/
|
||||
enum {
|
||||
enum {
|
||||
BLINK_NOT_MOUNTED = 250,
|
||||
BLINK_MOUNTED = 1000,
|
||||
BLINK_SUSPENDED = 2500,
|
||||
@ -52,8 +52,7 @@ void led_blinking_task(void);
|
||||
void video_task(void);
|
||||
|
||||
/*------------- MAIN -------------*/
|
||||
int main(void)
|
||||
{
|
||||
int main(void) {
|
||||
board_init();
|
||||
|
||||
// init device stack on configured roothub port
|
||||
@ -63,8 +62,7 @@ int main(void)
|
||||
board_init_after_tusb();
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
tud_task(); // tinyusb device task
|
||||
led_blinking_task();
|
||||
|
||||
@ -77,33 +75,28 @@ int main(void)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Invoked when device is mounted
|
||||
void tud_mount_cb(void)
|
||||
{
|
||||
void tud_mount_cb(void) {
|
||||
blink_interval_ms = BLINK_MOUNTED;
|
||||
}
|
||||
|
||||
// Invoked when device is unmounted
|
||||
void tud_umount_cb(void)
|
||||
{
|
||||
void tud_umount_cb(void) {
|
||||
blink_interval_ms = BLINK_NOT_MOUNTED;
|
||||
}
|
||||
|
||||
// Invoked when usb bus is suspended
|
||||
// remote_wakeup_en : if host allow us to perform remote wakeup
|
||||
// Within 7ms, device must draw an average of current less than 2.5 mA from bus
|
||||
void tud_suspend_cb(bool remote_wakeup_en)
|
||||
{
|
||||
void tud_suspend_cb(bool remote_wakeup_en) {
|
||||
(void) remote_wakeup_en;
|
||||
blink_interval_ms = BLINK_SUSPENDED;
|
||||
}
|
||||
|
||||
// Invoked when usb bus is resumed
|
||||
void tud_resume_cb(void)
|
||||
{
|
||||
void tud_resume_cb(void) {
|
||||
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USB Video
|
||||
//--------------------------------------------------------------------+
|
||||
@ -111,11 +104,12 @@ static unsigned frame_num = 0;
|
||||
static unsigned tx_busy = 0;
|
||||
static unsigned interval_ms = 1000 / FRAME_RATE;
|
||||
|
||||
/* YUY2 frame buffer */
|
||||
#ifdef CFG_EXAMPLE_VIDEO_READONLY
|
||||
// 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.
|
||||
#include "images.h"
|
||||
|
||||
# if !defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
|
||||
#if !defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
|
||||
static struct {
|
||||
uint32_t size;
|
||||
uint8_t const *buffer;
|
||||
@ -129,29 +123,30 @@ static struct {
|
||||
{color_bar_6_jpg_len, color_bar_6_jpg},
|
||||
{color_bar_7_jpg_len, color_bar_7_jpg},
|
||||
};
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
// YUY2 frame buffer
|
||||
static uint8_t frame_buffer[FRAME_WIDTH * FRAME_HEIGHT * 16 / 8];
|
||||
static void fill_color_bar(uint8_t *buffer, unsigned start_position)
|
||||
{
|
||||
/* EBU color bars
|
||||
* See also https://stackoverflow.com/questions/6939422 */
|
||||
|
||||
static void fill_color_bar(uint8_t* buffer, unsigned start_position) {
|
||||
/* EBU color bars: https://stackoverflow.com/questions/6939422 */
|
||||
static uint8_t const bar_color[8][4] = {
|
||||
/* Y, U, Y, V */
|
||||
{ 235, 128, 235, 128}, /* 100% White */
|
||||
{ 219, 16, 219, 138}, /* Yellow */
|
||||
{ 188, 154, 188, 16}, /* Cyan */
|
||||
{ 173, 42, 173, 26}, /* Green */
|
||||
{ 78, 214, 78, 230}, /* Magenta */
|
||||
{ 63, 102, 63, 240}, /* Red */
|
||||
{ 32, 240, 32, 118}, /* Blue */
|
||||
{ 16, 128, 16, 128}, /* Black */
|
||||
/* Y, U, Y, V */
|
||||
{ 235, 128, 235, 128}, /* 100% White */
|
||||
{ 219, 16, 219, 138}, /* Yellow */
|
||||
{ 188, 154, 188, 16}, /* Cyan */
|
||||
{ 173, 42, 173, 26}, /* Green */
|
||||
{ 78, 214, 78, 230}, /* Magenta */
|
||||
{ 63, 102, 63, 240}, /* Red */
|
||||
{ 32, 240, 32, 118}, /* Blue */
|
||||
{ 16, 128, 16, 128}, /* Black */
|
||||
};
|
||||
uint8_t *p;
|
||||
uint8_t* p;
|
||||
|
||||
/* Generate the 1st line */
|
||||
uint8_t *end = &buffer[FRAME_WIDTH * 2];
|
||||
uint8_t* end = &buffer[FRAME_WIDTH * 2];
|
||||
unsigned idx = (FRAME_WIDTH / 2 - 1) - (start_position % (FRAME_WIDTH / 2));
|
||||
p = &buffer[idx * 4];
|
||||
for (unsigned i = 0; i < 8; ++i) {
|
||||
@ -163,6 +158,7 @@ static void fill_color_bar(uint8_t *buffer, unsigned start_position)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Duplicate the 1st line to the others */
|
||||
p = &buffer[FRAME_WIDTH * 2];
|
||||
for (unsigned i = 1; i < FRAME_HEIGHT; ++i) {
|
||||
@ -170,16 +166,16 @@ static void fill_color_bar(uint8_t *buffer, unsigned start_position)
|
||||
p += FRAME_WIDTH * 2;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void video_task(void)
|
||||
{
|
||||
void video_task(void) {
|
||||
static unsigned start_ms = 0;
|
||||
static unsigned already_sent = 0;
|
||||
|
||||
if (!tud_video_n_streaming(0, 0)) {
|
||||
already_sent = 0;
|
||||
frame_num = 0;
|
||||
already_sent = 0;
|
||||
frame_num = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -187,15 +183,15 @@ void video_task(void)
|
||||
already_sent = 1;
|
||||
start_ms = board_millis();
|
||||
#ifdef CFG_EXAMPLE_VIDEO_READONLY
|
||||
# if defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
|
||||
#if defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
|
||||
tud_video_n_frame_xfer(0, 0, (void*)(uintptr_t)&frame_buffer[(frame_num % (FRAME_WIDTH / 2)) * 4],
|
||||
FRAME_WIDTH * FRAME_HEIGHT * 16/8);
|
||||
# else
|
||||
#else
|
||||
tud_video_n_frame_xfer(0, 0, (void*)(uintptr_t)frames[frame_num % 8].buffer, frames[frame_num % 8].size);
|
||||
# endif
|
||||
#endif
|
||||
#else
|
||||
fill_color_bar(frame_buffer, frame_num);
|
||||
tud_video_n_frame_xfer(0, 0, (void*)frame_buffer, FRAME_WIDTH * FRAME_HEIGHT * 16/8);
|
||||
tud_video_n_frame_xfer(0, 0, (void*) frame_buffer, FRAME_WIDTH * FRAME_HEIGHT * 16 / 8);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -205,30 +201,30 @@ void video_task(void)
|
||||
start_ms += interval_ms;
|
||||
|
||||
#ifdef CFG_EXAMPLE_VIDEO_READONLY
|
||||
# if defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
|
||||
#if defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
|
||||
tud_video_n_frame_xfer(0, 0, (void*)(uintptr_t)&frame_buffer[(frame_num % (FRAME_WIDTH / 2)) * 4],
|
||||
FRAME_WIDTH * FRAME_HEIGHT * 16/8);
|
||||
# else
|
||||
#else
|
||||
tud_video_n_frame_xfer(0, 0, (void*)(uintptr_t)frames[frame_num % 8].buffer, frames[frame_num % 8].size);
|
||||
# endif
|
||||
#endif
|
||||
#else
|
||||
fill_color_bar(frame_buffer, frame_num);
|
||||
tud_video_n_frame_xfer(0, 0, (void*)frame_buffer, FRAME_WIDTH * FRAME_HEIGHT * 16/8);
|
||||
tud_video_n_frame_xfer(0, 0, (void*) frame_buffer, FRAME_WIDTH * FRAME_HEIGHT * 16 / 8);
|
||||
#endif
|
||||
}
|
||||
|
||||
void tud_video_frame_xfer_complete_cb(uint_fast8_t ctl_idx, uint_fast8_t stm_idx)
|
||||
{
|
||||
(void)ctl_idx; (void)stm_idx;
|
||||
void tud_video_frame_xfer_complete_cb(uint_fast8_t ctl_idx, uint_fast8_t stm_idx) {
|
||||
(void) ctl_idx;
|
||||
(void) stm_idx;
|
||||
tx_busy = 0;
|
||||
/* flip buffer */
|
||||
++frame_num;
|
||||
}
|
||||
|
||||
int tud_video_commit_cb(uint_fast8_t ctl_idx, uint_fast8_t stm_idx,
|
||||
video_probe_and_commit_control_t const *parameters)
|
||||
{
|
||||
(void)ctl_idx; (void)stm_idx;
|
||||
video_probe_and_commit_control_t const* parameters) {
|
||||
(void) ctl_idx;
|
||||
(void) stm_idx;
|
||||
/* convert unit to ms from 100 ns */
|
||||
interval_ms = parameters->dwFrameInterval / 10000;
|
||||
return VIDEO_ERROR_NONE;
|
||||
@ -237,13 +233,12 @@ int tud_video_commit_cb(uint_fast8_t ctl_idx, uint_fast8_t stm_idx,
|
||||
//--------------------------------------------------------------------+
|
||||
// BLINKING TASK
|
||||
//--------------------------------------------------------------------+
|
||||
void led_blinking_task(void)
|
||||
{
|
||||
void led_blinking_task(void) {
|
||||
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
|
||||
if (board_millis() - start_ms < blink_interval_ms) return; // not enough time
|
||||
start_ms += blink_interval_ms;
|
||||
|
||||
board_led_write(led_state);
|
||||
|
@ -97,11 +97,11 @@
|
||||
// The number of video streaming interfaces
|
||||
#define CFG_TUD_VIDEO_STREAMING 1
|
||||
|
||||
// video streaming endpoint size
|
||||
// video streaming endpoint buffer size
|
||||
#define CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE 256
|
||||
|
||||
// use bulk endpoint for streaming interface
|
||||
#define CFG_TUD_VIDEO_STREAMING_BULK 0
|
||||
#define CFG_TUD_VIDEO_STREAMING_BULK 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -43,8 +43,7 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// Device Descriptors
|
||||
//--------------------------------------------------------------------+
|
||||
tusb_desc_device_t const desc_device =
|
||||
{
|
||||
tusb_desc_device_t const desc_device = {
|
||||
.bLength = sizeof(tusb_desc_device_t),
|
||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
||||
.bcdUSB = USB_BCD,
|
||||
@ -70,111 +69,70 @@ tusb_desc_device_t const desc_device =
|
||||
|
||||
// Invoked when received GET DEVICE DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
uint8_t const * tud_descriptor_device_cb(void)
|
||||
{
|
||||
return (uint8_t const *) &desc_device;
|
||||
uint8_t const* tud_descriptor_device_cb(void) {
|
||||
return (uint8_t const*) &desc_device;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Configuration Descriptor
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#if defined(CFG_EXAMPLE_VIDEO_READONLY) && !defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
|
||||
# if 1 == CFG_TUD_VIDEO_STREAMING_BULK
|
||||
# define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_VIDEO_CAPTURE_DESC_MJPEG_BULK_LEN)
|
||||
# else
|
||||
# define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_VIDEO_CAPTURE_DESC_MJPEG_LEN)
|
||||
# endif
|
||||
#else
|
||||
# if 1 == CFG_TUD_VIDEO_STREAMING_BULK
|
||||
# define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_VIDEO_CAPTURE_DESC_UNCOMPR_BULK_LEN)
|
||||
# else
|
||||
# define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_VIDEO_CAPTURE_DESC_UNCOMPR_LEN)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// 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
|
||||
// 0 control, 1 In, 2 Bulk, 3 Iso, 4 In, 5 Bulk etc ...
|
||||
#if 1 == CFG_TUD_VIDEO_STREAMING_BULK
|
||||
#define EPNUM_VIDEO_IN 0x82
|
||||
#else
|
||||
#define EPNUM_VIDEO_IN 0x83
|
||||
#endif
|
||||
|
||||
#define EPNUM_VIDEO_IN (CFG_TUD_VIDEO_STREAMING_BULK ? 0x82 : 0x83)
|
||||
#elif TU_CHECK_MCU(OPT_MCU_NRF5X)
|
||||
// nRF5x ISO can only be endpoint 8
|
||||
#define EPNUM_VIDEO_IN 0x88
|
||||
|
||||
#define EPNUM_VIDEO_IN (CFG_TUD_VIDEO_STREAMING_BULK ? 0x81 : 0x88)
|
||||
#else
|
||||
#define EPNUM_VIDEO_IN 0x81
|
||||
|
||||
#endif
|
||||
|
||||
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),
|
||||
|
||||
// IAD for Video Control
|
||||
// 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 1 == CFG_TUD_VIDEO_STREAMING_BULK
|
||||
TUD_VIDEO_CAPTURE_DESCRIPTOR_MJPEG_BULK(4, EPNUM_VIDEO_IN,
|
||||
FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE,
|
||||
64)
|
||||
# else
|
||||
TUD_VIDEO_CAPTURE_DESCRIPTOR_MJPEG(4, EPNUM_VIDEO_IN,
|
||||
FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE,
|
||||
CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE)
|
||||
# endif
|
||||
#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
|
||||
#else
|
||||
# if 1 == CFG_TUD_VIDEO_STREAMING_BULK
|
||||
TUD_VIDEO_CAPTURE_DESCRIPTOR_UNCOMPR_BULK(4, EPNUM_VIDEO_IN,
|
||||
FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE,
|
||||
64)
|
||||
# else
|
||||
TUD_VIDEO_CAPTURE_DESCRIPTOR_UNCOMPR(4, EPNUM_VIDEO_IN,
|
||||
FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE,
|
||||
CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE)
|
||||
# endif
|
||||
#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
|
||||
#endif
|
||||
|
||||
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + ITF_VIDEO_LEN)
|
||||
|
||||
// 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),
|
||||
|
||||
// IAD for Video Control
|
||||
ITF_VIDEO_DESC(CFG_TUD_VIDEO_STREAMING_BULK ? 64 : CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE)
|
||||
};
|
||||
|
||||
#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[] =
|
||||
{
|
||||
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),
|
||||
|
||||
// IAD for Video Control
|
||||
#if defined(CFG_EXAMPLE_VIDEO_READONLY) && !defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
|
||||
# if 1 == CFG_TUD_VIDEO_STREAMING_BULK
|
||||
TUD_VIDEO_CAPTURE_DESCRIPTOR_MJPEG_BULK(4, EPNUM_VIDEO_IN,
|
||||
FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE,
|
||||
512)
|
||||
# else
|
||||
TUD_VIDEO_CAPTURE_DESCRIPTOR_MJPEG(4, EPNUM_VIDEO_IN,
|
||||
FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE,
|
||||
CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE)
|
||||
# endif
|
||||
#else
|
||||
# if 1 == CFG_TUD_VIDEO_STREAMING_BULK
|
||||
TUD_VIDEO_CAPTURE_DESCRIPTOR_UNCOMPR_BULK(4, EPNUM_VIDEO_IN,
|
||||
FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE,
|
||||
512)
|
||||
# else
|
||||
TUD_VIDEO_CAPTURE_DESCRIPTOR_UNCOMPR(4, EPNUM_VIDEO_IN,
|
||||
FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE,
|
||||
CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE)
|
||||
# endif
|
||||
#endif
|
||||
ITF_VIDEO_DESC(CFG_TUD_VIDEO_STREAMING_BULK ? 512 : CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE)
|
||||
};
|
||||
|
||||
// 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 =
|
||||
{
|
||||
tusb_desc_device_qualifier_t const desc_device_qualifier = {
|
||||
.bLength = sizeof(tusb_desc_device_t),
|
||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
||||
.bcdUSB = USB_BCD,
|
||||
@ -192,29 +150,24 @@ tusb_desc_device_qualifier_t const desc_device_qualifier =
|
||||
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete.
|
||||
// device_qualifier descriptor describes information about a high-speed capable device that would
|
||||
// change if the device were operating at the other speed. If not highspeed capable stall this request.
|
||||
uint8_t const* tud_descriptor_device_qualifier_cb(void)
|
||||
{
|
||||
uint8_t const* tud_descriptor_device_qualifier_cb(void) {
|
||||
return (uint8_t const*) &desc_device_qualifier;
|
||||
}
|
||||
|
||||
// Invoked when received GET OTHER SEED CONFIGURATION DESCRIPTOR request
|
||||
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
|
||||
// Configuration descriptor in the other speed e.g if high speed then this is for full speed and vice versa
|
||||
uint8_t const* tud_descriptor_other_speed_configuration_cb(uint8_t index)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
#endif // highspeed
|
||||
|
||||
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
// Descriptor contents must exist long enough for transfer to complete
|
||||
uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
|
||||
{
|
||||
uint8_t const* tud_descriptor_configuration_cb(uint8_t index) {
|
||||
(void) index; // for multiple configurations
|
||||
|
||||
#if TUD_OPT_HIGH_SPEED
|
||||
@ -238,24 +191,23 @@ enum {
|
||||
};
|
||||
|
||||
// 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
|
||||
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
|
||||
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
|
||||
uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
||||
uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
||||
(void) langid;
|
||||
size_t chr_count;
|
||||
|
||||
switch ( index ) {
|
||||
switch (index) {
|
||||
case STRID_LANGID:
|
||||
memcpy(&_desc_str[1], string_desc_arr[0], 2);
|
||||
chr_count = 1;
|
||||
@ -269,17 +221,17 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
||||
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
|
||||
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
|
||||
|
||||
if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
|
||||
if (index >= sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) return NULL;
|
||||
|
||||
const char *str = string_desc_arr[index];
|
||||
const char* str = string_desc_arr[index];
|
||||
|
||||
// Cap at max char
|
||||
chr_count = strlen(str);
|
||||
size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
|
||||
if ( chr_count > max_count ) chr_count = max_count;
|
||||
if (chr_count > max_count) chr_count = max_count;
|
||||
|
||||
// Convert ASCII string into UTF-16
|
||||
for ( size_t i = 0; i < chr_count; i++ ) {
|
||||
for (size_t i = 0; i < chr_count; i++) {
|
||||
_desc_str[1 + i] = str[i];
|
||||
}
|
||||
break;
|
||||
|
@ -126,23 +126,17 @@ enum {
|
||||
#define TUD_VIDEO_CAPTURE_DESCRIPTOR_UNCOMPR(_stridx, _epin, _width, _height, _fps, _epsize) \
|
||||
TUD_VIDEO_DESC_IAD(ITF_NUM_VIDEO_CONTROL, /* 2 Interfaces */ 0x02, _stridx), \
|
||||
/* Video control 0 */ \
|
||||
TUD_VIDEO_DESC_STD_VC(ITF_NUM_VIDEO_CONTROL, 0, _stridx), \
|
||||
TUD_VIDEO_DESC_CS_VC( /* UVC 1.5*/ 0x0150, \
|
||||
/* wTotalLength - bLength */ \
|
||||
TUD_VIDEO_DESC_CAMERA_TERM_LEN + TUD_VIDEO_DESC_OUTPUT_TERM_LEN, \
|
||||
UVC_CLOCK_FREQUENCY, ITF_NUM_VIDEO_STREAMING), \
|
||||
TUD_VIDEO_DESC_CAMERA_TERM(UVC_ENTITY_CAP_INPUT_TERMINAL, 0, 0,\
|
||||
/*wObjectiveFocalLengthMin*/0, /*wObjectiveFocalLengthMax*/0,\
|
||||
/*wObjectiveFocalLength*/0, /*bmControls*/0), \
|
||||
TUD_VIDEO_DESC_STD_VC(ITF_NUM_VIDEO_CONTROL, 0, _stridx), \
|
||||
/* Header: UVC 1.5, length of followed descs, clock (deprecated), streaming interfaces */ \
|
||||
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), \
|
||||
/* Video stream alt. 0 */ \
|
||||
TUD_VIDEO_DESC_STD_VS(ITF_NUM_VIDEO_STREAMING, 0, 0, _stridx), \
|
||||
/* Video stream header for without still image capture */ \
|
||||
TUD_VIDEO_DESC_CS_VS_INPUT( /*bNumFormats*/1, \
|
||||
/*wTotalLength - bLength */\
|
||||
TUD_VIDEO_DESC_CS_VS_FMT_UNCOMPR_LEN\
|
||||
+ TUD_VIDEO_DESC_CS_VS_FRM_UNCOMPR_CONT_LEN\
|
||||
+ TUD_VIDEO_DESC_CS_VS_COLOR_MATCHING_LEN,\
|
||||
/*wTotalLength - bLength */ TUD_VIDEO_DESC_CS_VS_FMT_UNCOMPR_LEN + TUD_VIDEO_DESC_CS_VS_FRM_UNCOMPR_CONT_LEN + TUD_VIDEO_DESC_CS_VS_COLOR_MATCHING_LEN,\
|
||||
_epin, /*bmInfo*/0, /*bTerminalLink*/UVC_ENTITY_CAP_OUTPUT_TERMINAL, \
|
||||
/*bStillCaptureMethod*/0, /*bTriggerSupport*/0, /*bTriggerUsage*/0, \
|
||||
/*bmaControls(1)*/0), \
|
||||
@ -163,23 +157,17 @@ enum {
|
||||
#define TUD_VIDEO_CAPTURE_DESCRIPTOR_MJPEG(_stridx, _epin, _width, _height, _fps, _epsize) \
|
||||
TUD_VIDEO_DESC_IAD(ITF_NUM_VIDEO_CONTROL, /* 2 Interfaces */ 0x02, _stridx), \
|
||||
/* Video control 0 */ \
|
||||
TUD_VIDEO_DESC_STD_VC(ITF_NUM_VIDEO_CONTROL, 0, _stridx), \
|
||||
TUD_VIDEO_DESC_CS_VC( /* UVC 1.5*/ 0x0150, \
|
||||
/* wTotalLength - bLength */ \
|
||||
TUD_VIDEO_DESC_CAMERA_TERM_LEN + TUD_VIDEO_DESC_OUTPUT_TERM_LEN, \
|
||||
UVC_CLOCK_FREQUENCY, ITF_NUM_VIDEO_STREAMING), \
|
||||
TUD_VIDEO_DESC_CAMERA_TERM(UVC_ENTITY_CAP_INPUT_TERMINAL, 0, 0,\
|
||||
/*wObjectiveFocalLengthMin*/0, /*wObjectiveFocalLengthMax*/0,\
|
||||
/*wObjectiveFocalLength*/0, /*bmControls*/0), \
|
||||
TUD_VIDEO_DESC_STD_VC(ITF_NUM_VIDEO_CONTROL, 0, _stridx), \
|
||||
/* Header: UVC 1.5, length of followed descs, clock (deprecated), streaming interfaces */ \
|
||||
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), \
|
||||
/* Video stream alt. 0 */ \
|
||||
TUD_VIDEO_DESC_STD_VS(ITF_NUM_VIDEO_STREAMING, 0, 0, _stridx), \
|
||||
/* Video stream header for without still image capture */ \
|
||||
TUD_VIDEO_DESC_CS_VS_INPUT( /*bNumFormats*/1, \
|
||||
/*wTotalLength - bLength */\
|
||||
TUD_VIDEO_DESC_CS_VS_FMT_MJPEG_LEN\
|
||||
+ TUD_VIDEO_DESC_CS_VS_FRM_MJPEG_CONT_LEN\
|
||||
+ TUD_VIDEO_DESC_CS_VS_COLOR_MATCHING_LEN,\
|
||||
/*wTotalLength - bLength */ TUD_VIDEO_DESC_CS_VS_FMT_MJPEG_LEN + TUD_VIDEO_DESC_CS_VS_FRM_MJPEG_CONT_LEN + TUD_VIDEO_DESC_CS_VS_COLOR_MATCHING_LEN,\
|
||||
_epin, /*bmInfo*/0, /*bTerminalLink*/UVC_ENTITY_CAP_OUTPUT_TERMINAL, \
|
||||
/*bStillCaptureMethod*/0, /*bTriggerSupport*/0, /*bTriggerUsage*/0, \
|
||||
/*bmaControls(1)*/0), \
|
||||
@ -202,22 +190,17 @@ enum {
|
||||
TUD_VIDEO_DESC_IAD(ITF_NUM_VIDEO_CONTROL, /* 2 Interfaces */ 0x02, _stridx), \
|
||||
/* Video control 0 */ \
|
||||
TUD_VIDEO_DESC_STD_VC(ITF_NUM_VIDEO_CONTROL, 0, _stridx), \
|
||||
TUD_VIDEO_DESC_CS_VC( /* UVC 1.5*/ 0x0150, \
|
||||
/* wTotalLength - bLength */ \
|
||||
TUD_VIDEO_DESC_CAMERA_TERM_LEN + TUD_VIDEO_DESC_OUTPUT_TERM_LEN, \
|
||||
UVC_CLOCK_FREQUENCY, ITF_NUM_VIDEO_STREAMING), \
|
||||
TUD_VIDEO_DESC_CAMERA_TERM(UVC_ENTITY_CAP_INPUT_TERMINAL, 0, 0,\
|
||||
/*wObjectiveFocalLengthMin*/0, /*wObjectiveFocalLengthMax*/0,\
|
||||
/*wObjectiveFocalLength*/0, /*bmControls*/0), \
|
||||
/* Header: UVC 1.5, length of followed descs, clock (deprecated), streaming interfaces */ \
|
||||
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), \
|
||||
/* Video stream alt. 0 */ \
|
||||
TUD_VIDEO_DESC_STD_VS(ITF_NUM_VIDEO_STREAMING, 0, 1, _stridx), \
|
||||
/* Video stream header for without still image capture */ \
|
||||
TUD_VIDEO_DESC_CS_VS_INPUT( /*bNumFormats*/1, \
|
||||
/*wTotalLength - bLength */\
|
||||
TUD_VIDEO_DESC_CS_VS_FMT_UNCOMPR_LEN\
|
||||
+ TUD_VIDEO_DESC_CS_VS_FRM_UNCOMPR_CONT_LEN\
|
||||
+ TUD_VIDEO_DESC_CS_VS_COLOR_MATCHING_LEN,\
|
||||
TUD_VIDEO_DESC_CS_VS_FMT_UNCOMPR_LEN + TUD_VIDEO_DESC_CS_VS_FRM_UNCOMPR_CONT_LEN + TUD_VIDEO_DESC_CS_VS_COLOR_MATCHING_LEN,\
|
||||
_epin, /*bmInfo*/0, /*bTerminalLink*/UVC_ENTITY_CAP_OUTPUT_TERMINAL, \
|
||||
/*bStillCaptureMethod*/0, /*bTriggerSupport*/0, /*bTriggerUsage*/0, \
|
||||
/*bmaControls(1)*/0), \
|
||||
@ -235,23 +218,17 @@ enum {
|
||||
#define TUD_VIDEO_CAPTURE_DESCRIPTOR_MJPEG_BULK(_stridx, _epin, _width, _height, _fps, _epsize) \
|
||||
TUD_VIDEO_DESC_IAD(ITF_NUM_VIDEO_CONTROL, /* 2 Interfaces */ 0x02, _stridx), \
|
||||
/* Video control 0 */ \
|
||||
TUD_VIDEO_DESC_STD_VC(ITF_NUM_VIDEO_CONTROL, 0, _stridx), \
|
||||
TUD_VIDEO_DESC_CS_VC( /* UVC 1.5*/ 0x0150, \
|
||||
/* wTotalLength - bLength */ \
|
||||
TUD_VIDEO_DESC_CAMERA_TERM_LEN + TUD_VIDEO_DESC_OUTPUT_TERM_LEN, \
|
||||
UVC_CLOCK_FREQUENCY, ITF_NUM_VIDEO_STREAMING), \
|
||||
TUD_VIDEO_DESC_CAMERA_TERM(UVC_ENTITY_CAP_INPUT_TERMINAL, 0, 0,\
|
||||
/*wObjectiveFocalLengthMin*/0, /*wObjectiveFocalLengthMax*/0,\
|
||||
/*wObjectiveFocalLength*/0, /*bmControls*/0), \
|
||||
TUD_VIDEO_DESC_STD_VC(ITF_NUM_VIDEO_CONTROL, 0, _stridx), \
|
||||
/* Header: UVC 1.5, length of followed descs, clock (deprecated), streaming interfaces */ \
|
||||
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), \
|
||||
/* Video stream alt. 0 */ \
|
||||
TUD_VIDEO_DESC_STD_VS(ITF_NUM_VIDEO_STREAMING, 0, 1, _stridx), \
|
||||
/* Video stream header for without still image capture */ \
|
||||
TUD_VIDEO_DESC_CS_VS_INPUT( /*bNumFormats*/1, \
|
||||
/*wTotalLength - bLength */\
|
||||
TUD_VIDEO_DESC_CS_VS_FMT_MJPEG_LEN\
|
||||
+ TUD_VIDEO_DESC_CS_VS_FRM_MJPEG_CONT_LEN\
|
||||
+ TUD_VIDEO_DESC_CS_VS_COLOR_MATCHING_LEN,\
|
||||
/*wTotalLength - bLength */ TUD_VIDEO_DESC_CS_VS_FMT_MJPEG_LEN + TUD_VIDEO_DESC_CS_VS_FRM_MJPEG_CONT_LEN + TUD_VIDEO_DESC_CS_VS_COLOR_MATCHING_LEN,\
|
||||
_epin, /*bmInfo*/0, /*bTerminalLink*/UVC_ENTITY_CAP_OUTPUT_TERMINAL, \
|
||||
/*bStillCaptureMethod*/0, /*bTriggerSupport*/0, /*bTriggerUsage*/0, \
|
||||
/*bmaControls(1)*/0), \
|
||||
|
@ -211,7 +211,6 @@ function(family_configure_common TARGET RTOS)
|
||||
target_link_options(${TARGET} PUBLIC "LINKER:--map=$<TARGET_FILE:${TARGET}>.map")
|
||||
endif()
|
||||
|
||||
|
||||
# ETM Trace option
|
||||
if (TRACE_ETM STREQUAL "1")
|
||||
target_compile_definitions(${TARGET} PUBLIC TRACE_ETM)
|
||||
|
@ -434,8 +434,9 @@ static bool _update_streaming_parameters(videod_streaming_interface_t const *stm
|
||||
uint_fast32_t interval_ms = interval / 10000;
|
||||
TU_ASSERT(interval_ms);
|
||||
uint_fast32_t payload_size = (frame_size + interval_ms - 1) / interval_ms + 2;
|
||||
if (CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE < payload_size)
|
||||
if (CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE < payload_size) {
|
||||
payload_size = CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE;
|
||||
}
|
||||
param->dwMaxPayloadTransferSize = payload_size;
|
||||
return true;
|
||||
}
|
||||
@ -577,8 +578,9 @@ static bool _negotiate_streaming_parameters(videod_streaming_interface_t const *
|
||||
} else {
|
||||
payload_size = (frame_size + interval_ms - 1) / interval_ms + 2;
|
||||
}
|
||||
if (CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE < payload_size)
|
||||
if (CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE < payload_size) {
|
||||
payload_size = CFG_TUD_VIDEO_STREAMING_EP_BUFSIZE;
|
||||
}
|
||||
param->dwMaxPayloadTransferSize = payload_size;
|
||||
}
|
||||
return true;
|
||||
|
@ -44,43 +44,38 @@
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
/// defined base on EHCI specs value for Endpoint Speed
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
TUSB_SPEED_FULL = 0,
|
||||
TUSB_SPEED_LOW = 1,
|
||||
TUSB_SPEED_HIGH = 2,
|
||||
TUSB_SPEED_INVALID = 0xff,
|
||||
}tusb_speed_t;
|
||||
} tusb_speed_t;
|
||||
|
||||
/// defined base on USB Specs Endpoint's bmAttributes
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
TUSB_XFER_CONTROL = 0 ,
|
||||
TUSB_XFER_ISOCHRONOUS ,
|
||||
TUSB_XFER_BULK ,
|
||||
TUSB_XFER_INTERRUPT
|
||||
}tusb_xfer_type_t;
|
||||
} tusb_xfer_type_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
TUSB_DIR_OUT = 0,
|
||||
TUSB_DIR_IN = 1,
|
||||
|
||||
TUSB_DIR_IN_MASK = 0x80
|
||||
}tusb_dir_t;
|
||||
} tusb_dir_t;
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
TUSB_EPSIZE_BULK_FS = 64,
|
||||
TUSB_EPSIZE_BULK_HS= 512,
|
||||
TUSB_EPSIZE_BULK_HS = 512,
|
||||
|
||||
TUSB_EPSIZE_ISO_FS_MAX = 1023,
|
||||
TUSB_EPSIZE_ISO_HS_MAX = 1024,
|
||||
};
|
||||
|
||||
/// Isochronous End Point Attributes
|
||||
typedef enum
|
||||
{
|
||||
/// Isochronous Endpoint Attributes
|
||||
typedef enum {
|
||||
TUSB_ISO_EP_ATT_NO_SYNC = 0x00,
|
||||
TUSB_ISO_EP_ATT_ASYNCHRONOUS = 0x04,
|
||||
TUSB_ISO_EP_ATT_ADAPTIVE = 0x08,
|
||||
@ -88,11 +83,10 @@ typedef enum
|
||||
TUSB_ISO_EP_ATT_DATA = 0x00, ///< Data End Point
|
||||
TUSB_ISO_EP_ATT_EXPLICIT_FB = 0x10, ///< Feedback End Point
|
||||
TUSB_ISO_EP_ATT_IMPLICIT_FB = 0x20, ///< Data endpoint that also serves as an implicit feedback
|
||||
}tusb_iso_ep_attribute_t;
|
||||
} tusb_iso_ep_attribute_t;
|
||||
|
||||
/// USB Descriptor Types
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
TUSB_DESC_DEVICE = 0x01,
|
||||
TUSB_DESC_CONFIGURATION = 0x02,
|
||||
TUSB_DESC_STRING = 0x03,
|
||||
@ -119,10 +113,9 @@ typedef enum
|
||||
|
||||
TUSB_DESC_SUPERSPEED_ENDPOINT_COMPANION = 0x30,
|
||||
TUSB_DESC_SUPERSPEED_ISO_ENDPOINT_COMPANION = 0x31
|
||||
}tusb_desc_type_t;
|
||||
} tusb_desc_type_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
TUSB_REQ_GET_STATUS = 0 ,
|
||||
TUSB_REQ_CLEAR_FEATURE = 1 ,
|
||||
TUSB_REQ_RESERVED = 2 ,
|
||||
@ -136,25 +129,22 @@ typedef enum
|
||||
TUSB_REQ_GET_INTERFACE = 10 ,
|
||||
TUSB_REQ_SET_INTERFACE = 11 ,
|
||||
TUSB_REQ_SYNCH_FRAME = 12
|
||||
}tusb_request_code_t;
|
||||
} tusb_request_code_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
TUSB_REQ_FEATURE_EDPT_HALT = 0,
|
||||
TUSB_REQ_FEATURE_REMOTE_WAKEUP = 1,
|
||||
TUSB_REQ_FEATURE_TEST_MODE = 2
|
||||
}tusb_request_feature_selector_t;
|
||||
} tusb_request_feature_selector_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
TUSB_REQ_TYPE_STANDARD = 0,
|
||||
TUSB_REQ_TYPE_CLASS,
|
||||
TUSB_REQ_TYPE_VENDOR,
|
||||
TUSB_REQ_TYPE_INVALID
|
||||
} tusb_request_type_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
TUSB_REQ_RCPT_DEVICE =0,
|
||||
TUSB_REQ_RCPT_INTERFACE,
|
||||
TUSB_REQ_RCPT_ENDPOINT,
|
||||
@ -162,8 +152,7 @@ typedef enum
|
||||
} tusb_request_recipient_t;
|
||||
|
||||
// https://www.usb.org/defined-class-codes
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
TUSB_CLASS_UNSPECIFIED = 0 ,
|
||||
TUSB_CLASS_AUDIO = 1 ,
|
||||
TUSB_CLASS_CDC = 2 ,
|
||||
@ -187,26 +176,23 @@ typedef enum
|
||||
TUSB_CLASS_MISC = 0xEF ,
|
||||
TUSB_CLASS_APPLICATION_SPECIFIC = 0xFE ,
|
||||
TUSB_CLASS_VENDOR_SPECIFIC = 0xFF
|
||||
}tusb_class_code_t;
|
||||
} tusb_class_code_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MISC_SUBCLASS_COMMON = 2
|
||||
}misc_subclass_type_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
MISC_PROTOCOL_IAD = 1
|
||||
}misc_protocol_type_t;
|
||||
} misc_protocol_type_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
APP_SUBCLASS_USBTMC = 0x03,
|
||||
APP_SUBCLASS_DFU_RUNTIME = 0x01
|
||||
} app_subclass_type_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
DEVICE_CAPABILITY_WIRELESS_USB = 0x01,
|
||||
DEVICE_CAPABILITY_USB20_EXTENSION = 0x02,
|
||||
DEVICE_CAPABILITY_SUPERSPEED_USB = 0x03,
|
||||
@ -223,7 +209,7 @@ typedef enum
|
||||
DEVICE_CAPABILITY_AUTHENTICATION = 0x0E,
|
||||
DEVICE_CAPABILITY_BILLBOARD_EX = 0x0F,
|
||||
DEVICE_CAPABILITY_CONFIGURATION_SUMMARY = 0x10
|
||||
}device_capability_type_t;
|
||||
} device_capability_type_t;
|
||||
|
||||
enum {
|
||||
TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP = TU_BIT(5),
|
||||
@ -235,28 +221,25 @@ enum {
|
||||
//--------------------------------------------------------------------+
|
||||
//
|
||||
//--------------------------------------------------------------------+
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
XFER_RESULT_SUCCESS = 0,
|
||||
XFER_RESULT_FAILED,
|
||||
XFER_RESULT_STALLED,
|
||||
XFER_RESULT_TIMEOUT,
|
||||
XFER_RESULT_INVALID
|
||||
}xfer_result_t;
|
||||
} xfer_result_t;
|
||||
|
||||
enum // TODO remove
|
||||
{
|
||||
// TODO remove
|
||||
enum {
|
||||
DESC_OFFSET_LEN = 0,
|
||||
DESC_OFFSET_TYPE = 1
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
INTERFACE_INVALID_NUMBER = 0xff
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
MS_OS_20_SET_HEADER_DESCRIPTOR = 0x00,
|
||||
MS_OS_20_SUBSET_HEADER_CONFIGURATION = 0x01,
|
||||
MS_OS_20_SUBSET_HEADER_FUNCTION = 0x02,
|
||||
@ -268,16 +251,14 @@ typedef enum
|
||||
MS_OS_20_FEATURE_VENDOR_REVISION = 0x08
|
||||
} microsoft_os_20_type_t;
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
CONTROL_STAGE_IDLE,
|
||||
CONTROL_STAGE_SETUP,
|
||||
CONTROL_STAGE_DATA,
|
||||
CONTROL_STAGE_ACK
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
TUSB_INDEX_INVALID_8 = 0xFFu
|
||||
};
|
||||
|
||||
@ -290,8 +271,7 @@ TU_ATTR_PACKED_BEGIN
|
||||
TU_ATTR_BIT_FIELD_ORDER_BEGIN
|
||||
|
||||
/// USB Device Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType ; ///< DEVICE Descriptor Type.
|
||||
uint16_t bcdUSB ; ///< BUSB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H). This field identifies the release of the USB Specification with which the device and its descriptors are compliant.
|
||||
@ -314,8 +294,7 @@ typedef struct TU_ATTR_PACKED
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_device_t) == 18, "size is not correct");
|
||||
|
||||
// USB Binary Device Object Store (BOS) Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes
|
||||
uint8_t bDescriptorType ; ///< CONFIGURATION Descriptor Type
|
||||
uint16_t wTotalLength ; ///< Total length of data returned for this descriptor
|
||||
@ -325,8 +304,7 @@ typedef struct TU_ATTR_PACKED
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_bos_t) == 5, "size is not correct");
|
||||
|
||||
/// USB Configuration Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes
|
||||
uint8_t bDescriptorType ; ///< CONFIGURATION Descriptor Type
|
||||
uint16_t wTotalLength ; ///< Total length of data returned for this configuration. Includes the combined length of all descriptors (configuration, interface, endpoint, and class- or vendor-specific) returned for this configuration.
|
||||
@ -341,8 +319,7 @@ typedef struct TU_ATTR_PACKED
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_configuration_t) == 9, "size is not correct");
|
||||
|
||||
/// USB Interface Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes
|
||||
uint8_t bDescriptorType ; ///< INTERFACE Descriptor Type
|
||||
|
||||
@ -358,8 +335,7 @@ typedef struct TU_ATTR_PACKED
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_interface_t) == 9, "size is not correct");
|
||||
|
||||
/// USB Endpoint Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength ; // Size of this descriptor in bytes
|
||||
uint8_t bDescriptorType ; // ENDPOINT Descriptor Type
|
||||
|
||||
@ -379,8 +355,7 @@ typedef struct TU_ATTR_PACKED
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_endpoint_t) == 7, "size is not correct");
|
||||
|
||||
/// USB Other Speed Configuration Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength ; ///< Size of descriptor
|
||||
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
|
||||
uint16_t wTotalLength ; ///< Total length of data returned
|
||||
@ -393,8 +368,7 @@ typedef struct TU_ATTR_PACKED
|
||||
} tusb_desc_other_speed_t;
|
||||
|
||||
/// USB Device Qualifier Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength ; ///< Size of descriptor
|
||||
uint8_t bDescriptorType ; ///< Device Qualifier Type
|
||||
uint16_t bcdUSB ; ///< USB specification version number (e.g., 0200H for V2.00)
|
||||
@ -411,8 +385,7 @@ typedef struct TU_ATTR_PACKED
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_device_qualifier_t) == 10, "size is not correct");
|
||||
|
||||
/// USB Interface Association Descriptor (IAD ECN)
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength ; ///< Size of descriptor
|
||||
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
|
||||
|
||||
@ -427,16 +400,14 @@ typedef struct TU_ATTR_PACKED
|
||||
} tusb_desc_interface_assoc_t;
|
||||
|
||||
// USB String Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength ; ///< Size of this descriptor in bytes
|
||||
uint8_t bDescriptorType ; ///< Descriptor Type
|
||||
uint16_t unicode_string[];
|
||||
} tusb_desc_string_t;
|
||||
|
||||
// USB Binary Device Object Store (BOS)
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType ;
|
||||
uint8_t bDevCapabilityType;
|
||||
@ -445,9 +416,8 @@ typedef struct TU_ATTR_PACKED
|
||||
uint8_t CapabilityData[];
|
||||
} tusb_desc_bos_platform_t;
|
||||
|
||||
// USB WebuSB URL Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
// USB WebUSB URL Descriptor
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bScheme;
|
||||
@ -455,8 +425,7 @@ typedef struct TU_ATTR_PACKED
|
||||
} tusb_desc_webusb_url_t;
|
||||
|
||||
// DFU Functional Descriptor
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
|
||||
@ -481,7 +450,7 @@ typedef struct TU_ATTR_PACKED
|
||||
//
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
typedef struct TU_ATTR_PACKED{
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
union {
|
||||
struct TU_ATTR_PACKED {
|
||||
uint8_t recipient : 5; ///< Recipient type tusb_request_recipient_t.
|
||||
@ -509,36 +478,30 @@ TU_ATTR_BIT_FIELD_ORDER_END
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Get direction from Endpoint address
|
||||
TU_ATTR_ALWAYS_INLINE static inline tusb_dir_t tu_edpt_dir(uint8_t addr)
|
||||
{
|
||||
TU_ATTR_ALWAYS_INLINE static inline tusb_dir_t tu_edpt_dir(uint8_t addr) {
|
||||
return (addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
|
||||
}
|
||||
|
||||
// Get Endpoint number from address
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_edpt_number(uint8_t addr)
|
||||
{
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_edpt_number(uint8_t addr) {
|
||||
return (uint8_t)(addr & (~TUSB_DIR_IN_MASK));
|
||||
}
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_edpt_addr(uint8_t num, uint8_t dir)
|
||||
{
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_edpt_addr(uint8_t num, uint8_t dir) {
|
||||
return (uint8_t)(num | (dir ? TUSB_DIR_IN_MASK : 0));
|
||||
}
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_edpt_packet_size(tusb_desc_endpoint_t const* desc_ep)
|
||||
{
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_edpt_packet_size(tusb_desc_endpoint_t const* desc_ep) {
|
||||
return tu_le16toh(desc_ep->wMaxPacketSize) & TU_GENMASK(10, 0);
|
||||
}
|
||||
|
||||
#if CFG_TUSB_DEBUG
|
||||
TU_ATTR_ALWAYS_INLINE static inline const char *tu_edpt_dir_str(tusb_dir_t dir)
|
||||
{
|
||||
TU_ATTR_ALWAYS_INLINE static inline const char *tu_edpt_dir_str(tusb_dir_t dir) {
|
||||
tu_static const char *str[] = {"out", "in"};
|
||||
return str[dir];
|
||||
}
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline const char *tu_edpt_type_str(tusb_xfer_type_t t)
|
||||
{
|
||||
TU_ATTR_ALWAYS_INLINE static inline const char *tu_edpt_type_str(tusb_xfer_type_t t) {
|
||||
tu_static const char *str[] = {"control", "isochronous", "bulk", "interrupt"};
|
||||
return str[t];
|
||||
}
|
||||
@ -549,21 +512,18 @@ TU_ATTR_ALWAYS_INLINE static inline const char *tu_edpt_type_str(tusb_xfer_type_
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// return next descriptor
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint8_t const * tu_desc_next(void const* desc)
|
||||
{
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint8_t const * tu_desc_next(void const* desc) {
|
||||
uint8_t const* desc8 = (uint8_t const*) desc;
|
||||
return desc8 + desc8[DESC_OFFSET_LEN];
|
||||
}
|
||||
|
||||
// get descriptor type
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_desc_type(void const* desc)
|
||||
{
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_desc_type(void const* desc) {
|
||||
return ((uint8_t const*) desc)[DESC_OFFSET_TYPE];
|
||||
}
|
||||
|
||||
// get descriptor length
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_desc_len(void const* desc)
|
||||
{
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_desc_len(void const* desc) {
|
||||
return ((uint8_t const*) desc)[DESC_OFFSET_LEN];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user