summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorkkitayam <[email protected]>2021-09-20 14:55:56 +0900
committerkkitayam <[email protected]>2021-09-29 21:23:16 +0900
commit3cb4bb391d814d88662581f47b4dc13097d7c69e (patch)
treef62f1ccfe995c49496998962b5c0867d99402442 /examples
parent2b4e02f192446f4fdf92c7e83ab260ae743503e9 (diff)
Separate a handling resource into controller and streaming
Diffstat (limited to 'examples')
-rw-r--r--examples/device/video_capture/src/main.c41
-rw-r--r--examples/device/video_capture/src/tusb_config.h4
-rw-r--r--examples/device/video_capture/src/usb_descriptors.c2
3 files changed, 46 insertions, 1 deletions
diff --git a/examples/device/video_capture/src/main.c b/examples/device/video_capture/src/main.c
index 098cd2f8d..1921da4bf 100644
--- a/examples/device/video_capture/src/main.c
+++ b/examples/device/video_capture/src/main.c
@@ -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;
}
//--------------------------------------------------------------------+
diff --git a/examples/device/video_capture/src/tusb_config.h b/examples/device/video_capture/src/tusb_config.h
index ae2387357..3958b85b6 100644
--- a/examples/device/video_capture/src/tusb_config.h
+++ b/examples/device/video_capture/src/tusb_config.h
@@ -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
diff --git a/examples/device/video_capture/src/usb_descriptors.c b/examples/device/video_capture/src/usb_descriptors.c
index d3544cc63..096ac4373 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, 15, 256)
+ TUD_VIDEO_CAPTURE_DESCRIPTOR(4, EPNUM_VIDEO_IN, 128, 96, 10, 256)
};
// Invoked when received GET CONFIGURATION DESCRIPTOR