diff options
| author | kkitayam <[email protected]> | 2021-09-26 17:15:00 +0900 |
|---|---|---|
| committer | kkitayam <[email protected]> | 2021-09-29 21:23:17 +0900 |
| commit | f7bbdea0b8f360d1fcf2f835211ed5c26e0240ea (patch) | |
| tree | 7037b5dda055e8629f4bc187ed1222aa3ad93898 /examples | |
| parent | 0d6496886cae22f33408bd126925b5d6c4908d65 (diff) | |
Refactor application API parameters
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/device/video_capture/src/main.c | 22 | ||||
| -rw-r--r-- | examples/device/video_capture/src/tusb_config.h | 12 | ||||
| -rw-r--r-- | examples/device/video_capture/src/usb_descriptors.c | 2 |
3 files changed, 19 insertions, 17 deletions
diff --git a/examples/device/video_capture/src/main.c b/examples/device/video_capture/src/main.c index 4a124c537..abc97a377 100644 --- a/examples/device/video_capture/src/main.c +++ b/examples/device/video_capture/src/main.c @@ -35,9 +35,6 @@ // MACRO CONSTANT TYPEDEF PROTYPES //--------------------------------------------------------------------+ -#define FRAME_WIDTH 128 -#define FRAME_HEIGHT 96 - /* Blink pattern * - 250 ms : device not mounted * - 1000 ms : device mounted @@ -115,11 +112,10 @@ static unsigned tx_busy = 0; void video_task(void) { static unsigned start_ms = 0; - static unsigned interval_ms = 100; - static unsigned frame_num = 0; + static unsigned interval_ms = 1000 / FRAME_RATE; static unsigned already_sent = 0; - if (!tud_video_n_streaming(0)) { + if (!tud_video_n_streaming(0, 0)) { already_sent = 0; current_frame = 0; return; @@ -128,7 +124,7 @@ void video_task(void) if (!already_sent) { already_sent = 1; start_ms = board_millis(); - tud_video_n_frame_xfer(0, 0, (void*)frames[current_frame], 128 * 96 * 12/8); + tud_video_n_frame_xfer(0, 0, (void*)frames[current_frame], FRAME_WIDTH * FRAME_HEIGHT * 12/8); } unsigned cur = board_millis(); @@ -136,18 +132,12 @@ void video_task(void) if (tx_busy) return; start_ms += interval_ms; - tud_video_n_frame_xfer(0, 0, (void*)frames[current_frame], 128 * 96 * 12/8); - - ++frame_num; - if (frame_num % 3) { - interval_ms = 66; - } else { - interval_ms = 67; - } + tud_video_n_frame_xfer(0, 0, (void*)frames[current_frame], FRAME_WIDTH * FRAME_HEIGHT * 12/8); } -int tud_video_frame_xfer_complete_cb(unsigned itf) +int 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 */ ++current_frame; diff --git a/examples/device/video_capture/src/tusb_config.h b/examples/device/video_capture/src/tusb_config.h index 3958b85b6..fb194c55a 100644 --- a/examples/device/video_capture/src/tusb_config.h +++ b/examples/device/video_capture/src/tusb_config.h @@ -90,8 +90,10 @@ #define CFG_TUD_ENDPOINT0_SIZE 64 #endif +// video streaming endpoint size #define CFG_TUD_VIDEO_EP_BUFSIZE 256 +// The number of video streaming interfaces #define CFG_TUD_VIDEO_STREAMING 1 //------------- CLASS -------------// @@ -100,9 +102,19 @@ #define CFG_TUD_HID 0 #define CFG_TUD_MIDI 0 #define CFG_TUD_AUDIO 0 +// The number of video control interfaces #define CFG_TUD_VIDEO 1 #define CFG_TUD_VENDOR 0 + +//-------------------------------------------------------------------- +// APPLICATION CONFIGURATION +//-------------------------------------------------------------------- +#define FRAME_WIDTH 128 +#define FRAME_HEIGHT 96 +#define FRAME_RATE 10 + + #ifdef __cplusplus } #endif diff --git a/examples/device/video_capture/src/usb_descriptors.c b/examples/device/video_capture/src/usb_descriptors.c index 096ac4373..a9fa2c043 100644 --- a/examples/device/video_capture/src/usb_descriptors.c +++ b/examples/device/video_capture/src/usb_descriptors.c @@ -104,7 +104,7 @@ 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 - TUD_VIDEO_CAPTURE_DESCRIPTOR(4, EPNUM_VIDEO_IN, 128, 96, 10, 256) + TUD_VIDEO_CAPTURE_DESCRIPTOR(4, EPNUM_VIDEO_IN, FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE, CFG_TUD_VIDEO_EP_BUFSIZE) }; // Invoked when received GET CONFIGURATION DESCRIPTOR |
