Refactor application API parameters

This commit is contained in:
kkitayam
2021-09-26 17:15:00 +09:00
parent 0d6496886c
commit f7bbdea0b8
5 changed files with 116 additions and 103 deletions

View File

@@ -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;

View File

@@ -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

View File

@@ -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