summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2026-02-11 19:49:44 +0800
committersakumisu <[email protected]>2026-02-11 19:58:21 +0800
commit153dac1dbff9b7a9bcf8093b0cbcc7bb0bb8bc07 (patch)
tree133b7b3711b46450f8952bdeb7c46c8c015136e8
parent362fec943a386c8cf623108f5f9019904270156f (diff)
update(tests): move out video thread with new api
Signed-off-by: sakumisu <[email protected]>
-rw-r--r--tests/bouffalolab/src/main.c44
-rw-r--r--tests/hpmicro/src/uvc2lcd.c96
2 files changed, 92 insertions, 48 deletions
diff --git a/tests/bouffalolab/src/main.c b/tests/bouffalolab/src/main.c
index 7ff88b71..d846e18c 100644
--- a/tests/bouffalolab/src/main.c
+++ b/tests/bouffalolab/src/main.c
@@ -32,9 +32,38 @@ void usbh_video_stop(struct usbh_video *video_class)
usbh_video_stream_stop();
}
-void usbh_video_frame_callback(struct usbh_videoframe *frame)
+static void usbh_video_frame_thread(void *argument)
{
- USB_LOG_RAW("frame buf:%p,frame len:%d\r\n", frame->frame_buf, frame->frame_size);
+ int ret;
+ struct usbh_videoframe *frame;
+
+ while (1) {
+ ret = usbh_video_stream_dequeue(&frame, 0xfffffff);
+ if (ret < 0) {
+ continue;
+ }
+
+ USB_LOG_RAW("frame buf:%p,frame len:%d\r\n", frame->frame_buf, frame->frame_size);
+
+ usbh_video_stream_enqueue(frame);
+ }
+}
+
+static void usbh_audio_mic_frame_thread(void *argument)
+{
+ int ret;
+ struct usbh_audioframe *frame;
+
+ while (1) {
+ ret = usbh_audio_mic_stream_dequeue(&frame, 0xfffffff);
+ if (ret < 0) {
+ continue;
+ }
+
+ USB_LOG_RAW("frame buf:%p,frame len:%d\r\n", frame->frame_buf, frame->frame_size);
+
+ usbh_audio_mic_stream_enqueue(frame);
+ }
}
#endif
@@ -50,21 +79,24 @@ int main(void)
printf("Starting usb host task...\r\n");
#ifdef CONFIG_USB_EHCI_ISO
- extern void usbh_video_fps_init(void);
- usbh_video_fps_init();
frame_pool[0].frame_buf = frame_buffer1;
frame_pool[0].frame_bufsize = 640 * 480 * 2;
frame_pool[1].frame_buf = frame_buffer2;
frame_pool[1].frame_bufsize = 640 * 480 * 2;
- usbh_video_stream_init(5, frame_pool, 2);
+ usbh_video_stream_create(frame_pool, 2);
+
+ usb_osal_thread_create("uvc_frame", 3072, 5, usbh_video_frame_thread, NULL);
+ extern void usbh_video_fps_init(void);
+ usbh_video_fps_init();
for (uint8_t i = 0; i < 8; i++) {
frame_pool2[i].frame_buf = frame_buffer + i * AUDIO_MIC_EP_MPS;
frame_pool2[i].frame_bufsize = AUDIO_MIC_EP_MPS;
}
- usbh_audio_mic_stream_init(5, frame_pool2, 8);
+ usbh_audio_mic_stream_create(frame_pool2, 8);
+ usb_osal_thread_create("uac_mic", 3072, 5, usbh_audio_mic_frame_thread, NULL);
#endif
vTaskStartScheduler();
diff --git a/tests/hpmicro/src/uvc2lcd.c b/tests/hpmicro/src/uvc2lcd.c
index 71d36865..b93ec2aa 100644
--- a/tests/hpmicro/src/uvc2lcd.c
+++ b/tests/hpmicro/src/uvc2lcd.c
@@ -13,8 +13,40 @@ static ATTR_PLACE_AT_WITH_ALIGNMENT(".framebuffer", 64) uint8_t frame_buffer1[IM
static ATTR_PLACE_AT_WITH_ALIGNMENT(".framebuffer", 64) uint8_t frame_buffer2[IMAGE_WIDTH * IMAGE_HEIGHT * 2];
static struct usbh_videoframe frame_pool[2];
+void init_lcd(void)
+{
+ uint8_t layer_index = 0;
+ lcdc_config_t config = { 0 };
+ lcdc_layer_config_t layer = { 0 };
+
+ lcdc_get_default_config(LCD, &config);
+ board_panel_para_to_lcdc(&config);
+ lcdc_init(LCD, &config);
+
+ lcdc_get_default_layer_config(LCD, &layer, PIXEL_FORMAT, layer_index);
+
+ layer.position_x = (BOARD_LCD_WIDTH - IMAGE_WIDTH) / 2;
+ layer.position_y = (BOARD_LCD_HEIGHT - IMAGE_HEIGHT) / 2;
+ layer.width = IMAGE_WIDTH;
+ layer.height = IMAGE_HEIGHT;
+
+ layer.buffer = core_local_mem_to_sys_address(HPM_CORE0, (uint32_t)frame_buffer1);
+ layer.alphablend.src_alpha = 0xF4; /* src */
+ layer.alphablend.dst_alpha = 0xF0; /* dst */
+ layer.alphablend.src_alpha_op = display_alpha_op_override;
+ layer.alphablend.dst_alpha_op = display_alpha_op_override;
+ layer.background.u = 0xffff0000;
+ layer.alphablend.mode = display_alphablend_mode_xor;
+
+ if (status_success != lcdc_config_layer(LCD, layer_index, &layer, true)) {
+ printf("failed to configure layer\n");
+ while (1)
+ ;
+ }
+}
+
void writefont2screen(uint16_t or_x, uint16_t or_y, uint16_t x_end, uint16_t y_end, uint8_t assic_id, uint16_t colour,
- uint8_t clearflag, uint8_t *str_font, uint32_t screen_addr, uint16_t font_size)
+ uint8_t clearflag, uint8_t *str_font, uint32_t screen_addr, uint16_t font_size)
{
uint8_t *strdisp;
uint16_t x, y;
@@ -48,7 +80,7 @@ void writefont2screen(uint16_t or_x, uint16_t or_y, uint16_t x_end, uint16_t y_e
}
char string2font(uint16_t line, uint16_t column, uint8_t *string, uint8_t string_num, uint16_t colour,
- uint8_t *str_font, uint32_t screen_addr, uint8_t font_width, uint8_t font_height)
+ uint8_t *str_font, uint32_t screen_addr, uint8_t font_width, uint8_t font_height)
{
uint8_t i = 0, j = 0, numtemp = 0;
uint16_t or_x, or_y, x_end, y_end;
@@ -62,10 +94,10 @@ char string2font(uint16_t line, uint16_t column, uint8_t *string, uint8_t string
if ((*(string + numtemp) != 10) && (*(string + numtemp) != 0)) { /*enter or end*/
if (*(string + numtemp) != 8) { /*delete*/
writefont2screen(or_x + font_width * i, or_y + font_height * j, x_end + font_width * i, y_end + font_height * j,
- *(string + numtemp), colour, false, str_font, screen_addr, font_stroage_size);
+ *(string + numtemp), colour, false, str_font, screen_addr, font_stroage_size);
} else {
writefont2screen(or_x + font_width * i, or_y + font_height * j, x_end + font_width * i, y_end + font_height * j,
- *(string + numtemp), colour, true, str_font, screen_addr, font_stroage_size);
+ *(string + numtemp), colour, true, str_font, screen_addr, font_stroage_size);
}
} else if (*(string + numtemp) == 10) {
i = 19; /* jump next line */
@@ -96,47 +128,26 @@ void usbh_video_stop(struct usbh_video *video_class)
lcdc_turn_off_display(LCD);
}
-void usbh_video_frame_callback(struct usbh_videoframe *frame)
-{
- char font_display_buf[50];
-
- //USB_LOG_RAW("frame buf:%p,frame len:%d\r\n", frame->frame_buf, frame->frame_size);
- l1c_dc_invalidate((uint32_t)frame->frame_buf, IMAGE_WIDTH * IMAGE_HEIGHT * 2);
- sprintf(font_display_buf, "fps:%d", g_uvc_fps);
- string2font(1, 1, (uint8_t *)font_display_buf, sizeof(font_display_buf), 0x001f, (uint8_t *)nAsciiDot24x48, (uint32_t)frame->frame_buf, 24, 48);
- l1c_dc_writeback((uint32_t)frame->frame_buf, IMAGE_WIDTH * IMAGE_HEIGHT * 2);
- lcdc_layer_set_next_buffer(LCD, 0, (uint32_t)frame->frame_buf);
-}
-
-void init_lcd(void)
+static void usbh_video_frame_thread(void *argument)
{
- uint8_t layer_index = 0;
- lcdc_config_t config = { 0 };
- lcdc_layer_config_t layer = { 0 };
-
- lcdc_get_default_config(LCD, &config);
- board_panel_para_to_lcdc(&config);
- lcdc_init(LCD, &config);
-
- lcdc_get_default_layer_config(LCD, &layer, PIXEL_FORMAT, layer_index);
+ int ret;
+ struct usbh_videoframe *frame;
- layer.position_x = (BOARD_LCD_WIDTH - IMAGE_WIDTH) / 2;
- layer.position_y = (BOARD_LCD_HEIGHT - IMAGE_HEIGHT) / 2;
- layer.width = IMAGE_WIDTH;
- layer.height = IMAGE_HEIGHT;
+ while (1) {
+ ret = usbh_video_stream_dequeue(&frame, 0xfffffff);
+ if (ret < 0) {
+ continue;
+ }
+ char font_display_buf[50];
- layer.buffer = core_local_mem_to_sys_address(HPM_CORE0, (uint32_t)frame_buffer1);
- layer.alphablend.src_alpha = 0xF4; /* src */
- layer.alphablend.dst_alpha = 0xF0; /* dst */
- layer.alphablend.src_alpha_op = display_alpha_op_override;
- layer.alphablend.dst_alpha_op = display_alpha_op_override;
- layer.background.u = 0xffff0000;
- layer.alphablend.mode = display_alphablend_mode_xor;
+ //USB_LOG_RAW("frame buf:%p,frame len:%d\r\n", frame->frame_buf, frame->frame_size);
+ l1c_dc_invalidate((uint32_t)frame->frame_buf, IMAGE_WIDTH * IMAGE_HEIGHT * 2);
+ sprintf(font_display_buf, "fps:%d", g_uvc_fps);
+ string2font(1, 1, (uint8_t *)font_display_buf, sizeof(font_display_buf), 0x001f, (uint8_t *)nAsciiDot24x48, (uint32_t)frame->frame_buf, 24, 48);
+ l1c_dc_writeback((uint32_t)frame->frame_buf, IMAGE_WIDTH * IMAGE_HEIGHT * 2);
+ lcdc_layer_set_next_buffer(LCD, 0, (uint32_t)frame->frame_buf);
- if (status_success != lcdc_config_layer(LCD, layer_index, &layer, true)) {
- printf("failed to configure layer\n");
- while (1)
- ;
+ usbh_video_stream_enqueue(frame);
}
}
@@ -150,8 +161,9 @@ void uvc2lcd_init(void)
frame_pool[1].frame_buf = frame_buffer2;
frame_pool[1].frame_bufsize = IMAGE_WIDTH * IMAGE_HEIGHT * 2;
- usbh_video_stream_init(5, frame_pool, 2);
+ usbh_video_stream_create(frame_pool, 2);
+ usb_osal_thread_create("uvc_frame", 3072, 5, usbh_video_frame_thread, NULL);
extern void usbh_video_fps_init(void);
usbh_video_fps_init();
} \ No newline at end of file