Separate a handling resource into controller and streaming
This commit is contained in:
@@ -30,10 +30,14 @@
|
||||
#include "bsp/board.h"
|
||||
#include "tusb.h"
|
||||
|
||||
#include "images.h"
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF PROTYPES
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#define FRAME_WIDTH 128
|
||||
#define FRAME_HEIGHT 96
|
||||
|
||||
/* Blink pattern
|
||||
* - 250 ms : device not mounted
|
||||
* - 1000 ms : device mounted
|
||||
@@ -102,8 +106,45 @@ void tud_resume_cb(void)
|
||||
//--------------------------------------------------------------------+
|
||||
// USB Video
|
||||
//--------------------------------------------------------------------+
|
||||
static unsigned char const *frames[] = {
|
||||
black_128x96_yuv, white_128x96_yuv
|
||||
};
|
||||
uint8_t current_frame = 0;
|
||||
|
||||
void video_task(void)
|
||||
{
|
||||
static unsigned start_ms = 0;
|
||||
static unsigned interval_ms = 66;
|
||||
static unsigned frame_num = 0;
|
||||
static unsigned already_sent = 0;
|
||||
|
||||
if (!tud_video_n_streaming(0)) return;
|
||||
|
||||
if (!already_sent) {
|
||||
tud_video_n_frame_xfer(0, 0, (void*)frames[current_frame], 128 * 96 * 12/8);
|
||||
current_frame ^= 1;
|
||||
already_sent = 1;
|
||||
}
|
||||
|
||||
unsigned cur = board_millis();
|
||||
if (cur - start_ms < interval_ms) return; // not enough time
|
||||
start_ms += interval_ms;
|
||||
|
||||
/* flip buffer */
|
||||
++frame_num;
|
||||
if (frame_num % 3) {
|
||||
interval_ms = 66;
|
||||
} else {
|
||||
interval_ms = 67;
|
||||
}
|
||||
}
|
||||
|
||||
int tud_video_frame_xfer_complete_cb(void)
|
||||
{
|
||||
/* prepare tx */
|
||||
tud_video_n_frame_xfer(0, 0, (void*)frames[current_frame], 128 * 96 * 12/8);
|
||||
current_frame ^= 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
|
@@ -90,6 +90,10 @@
|
||||
#define CFG_TUD_ENDPOINT0_SIZE 64
|
||||
#endif
|
||||
|
||||
#define CFG_TUD_VIDEO_EP_BUFSIZE 256
|
||||
|
||||
#define CFG_TUD_VIDEO_STREAMING 1
|
||||
|
||||
//------------- CLASS -------------//
|
||||
#define CFG_TUD_CDC 0
|
||||
#define CFG_TUD_MSC 0
|
||||
|
@@ -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, 15, 256)
|
||||
TUD_VIDEO_CAPTURE_DESCRIPTOR(4, EPNUM_VIDEO_IN, 128, 96, 10, 256)
|
||||
};
|
||||
|
||||
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
||||
|
Reference in New Issue
Block a user