Skip to content

Commit 153dac1

Browse files
committed
update(tests): move out video thread with new api
Signed-off-by: sakumisu <1203593632@qq.com>
1 parent 362fec9 commit 153dac1

2 files changed

Lines changed: 92 additions & 48 deletions

File tree

tests/bouffalolab/src/main.c

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,38 @@ void usbh_video_stop(struct usbh_video *video_class)
3232
usbh_video_stream_stop();
3333
}
3434

35-
void usbh_video_frame_callback(struct usbh_videoframe *frame)
35+
static void usbh_video_frame_thread(void *argument)
3636
{
37-
USB_LOG_RAW("frame buf:%p,frame len:%d\r\n", frame->frame_buf, frame->frame_size);
37+
int ret;
38+
struct usbh_videoframe *frame;
39+
40+
while (1) {
41+
ret = usbh_video_stream_dequeue(&frame, 0xfffffff);
42+
if (ret < 0) {
43+
continue;
44+
}
45+
46+
USB_LOG_RAW("frame buf:%p,frame len:%d\r\n", frame->frame_buf, frame->frame_size);
47+
48+
usbh_video_stream_enqueue(frame);
49+
}
50+
}
51+
52+
static void usbh_audio_mic_frame_thread(void *argument)
53+
{
54+
int ret;
55+
struct usbh_audioframe *frame;
56+
57+
while (1) {
58+
ret = usbh_audio_mic_stream_dequeue(&frame, 0xfffffff);
59+
if (ret < 0) {
60+
continue;
61+
}
62+
63+
USB_LOG_RAW("frame buf:%p,frame len:%d\r\n", frame->frame_buf, frame->frame_size);
64+
65+
usbh_audio_mic_stream_enqueue(frame);
66+
}
3867
}
3968
#endif
4069

@@ -50,21 +79,24 @@ int main(void)
5079

5180
printf("Starting usb host task...\r\n");
5281
#ifdef CONFIG_USB_EHCI_ISO
53-
extern void usbh_video_fps_init(void);
54-
usbh_video_fps_init();
5582
frame_pool[0].frame_buf = frame_buffer1;
5683
frame_pool[0].frame_bufsize = 640 * 480 * 2;
5784
frame_pool[1].frame_buf = frame_buffer2;
5885
frame_pool[1].frame_bufsize = 640 * 480 * 2;
5986

60-
usbh_video_stream_init(5, frame_pool, 2);
87+
usbh_video_stream_create(frame_pool, 2);
88+
89+
usb_osal_thread_create("uvc_frame", 3072, 5, usbh_video_frame_thread, NULL);
90+
extern void usbh_video_fps_init(void);
91+
usbh_video_fps_init();
6192

6293
for (uint8_t i = 0; i < 8; i++) {
6394
frame_pool2[i].frame_buf = frame_buffer + i * AUDIO_MIC_EP_MPS;
6495
frame_pool2[i].frame_bufsize = AUDIO_MIC_EP_MPS;
6596
}
6697

67-
usbh_audio_mic_stream_init(5, frame_pool2, 8);
98+
usbh_audio_mic_stream_create(frame_pool2, 8);
99+
usb_osal_thread_create("uac_mic", 3072, 5, usbh_audio_mic_frame_thread, NULL);
68100
#endif
69101
vTaskStartScheduler();
70102

tests/hpmicro/src/uvc2lcd.c

Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,40 @@ static ATTR_PLACE_AT_WITH_ALIGNMENT(".framebuffer", 64) uint8_t frame_buffer1[IM
1313
static ATTR_PLACE_AT_WITH_ALIGNMENT(".framebuffer", 64) uint8_t frame_buffer2[IMAGE_WIDTH * IMAGE_HEIGHT * 2];
1414
static struct usbh_videoframe frame_pool[2];
1515

16+
void init_lcd(void)
17+
{
18+
uint8_t layer_index = 0;
19+
lcdc_config_t config = { 0 };
20+
lcdc_layer_config_t layer = { 0 };
21+
22+
lcdc_get_default_config(LCD, &config);
23+
board_panel_para_to_lcdc(&config);
24+
lcdc_init(LCD, &config);
25+
26+
lcdc_get_default_layer_config(LCD, &layer, PIXEL_FORMAT, layer_index);
27+
28+
layer.position_x = (BOARD_LCD_WIDTH - IMAGE_WIDTH) / 2;
29+
layer.position_y = (BOARD_LCD_HEIGHT - IMAGE_HEIGHT) / 2;
30+
layer.width = IMAGE_WIDTH;
31+
layer.height = IMAGE_HEIGHT;
32+
33+
layer.buffer = core_local_mem_to_sys_address(HPM_CORE0, (uint32_t)frame_buffer1);
34+
layer.alphablend.src_alpha = 0xF4; /* src */
35+
layer.alphablend.dst_alpha = 0xF0; /* dst */
36+
layer.alphablend.src_alpha_op = display_alpha_op_override;
37+
layer.alphablend.dst_alpha_op = display_alpha_op_override;
38+
layer.background.u = 0xffff0000;
39+
layer.alphablend.mode = display_alphablend_mode_xor;
40+
41+
if (status_success != lcdc_config_layer(LCD, layer_index, &layer, true)) {
42+
printf("failed to configure layer\n");
43+
while (1)
44+
;
45+
}
46+
}
47+
1648
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,
17-
uint8_t clearflag, uint8_t *str_font, uint32_t screen_addr, uint16_t font_size)
49+
uint8_t clearflag, uint8_t *str_font, uint32_t screen_addr, uint16_t font_size)
1850
{
1951
uint8_t *strdisp;
2052
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
4880
}
4981

5082
char string2font(uint16_t line, uint16_t column, uint8_t *string, uint8_t string_num, uint16_t colour,
51-
uint8_t *str_font, uint32_t screen_addr, uint8_t font_width, uint8_t font_height)
83+
uint8_t *str_font, uint32_t screen_addr, uint8_t font_width, uint8_t font_height)
5284
{
5385
uint8_t i = 0, j = 0, numtemp = 0;
5486
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
6294
if ((*(string + numtemp) != 10) && (*(string + numtemp) != 0)) { /*enter or end*/
6395
if (*(string + numtemp) != 8) { /*delete*/
6496
writefont2screen(or_x + font_width * i, or_y + font_height * j, x_end + font_width * i, y_end + font_height * j,
65-
*(string + numtemp), colour, false, str_font, screen_addr, font_stroage_size);
97+
*(string + numtemp), colour, false, str_font, screen_addr, font_stroage_size);
6698
} else {
6799
writefont2screen(or_x + font_width * i, or_y + font_height * j, x_end + font_width * i, y_end + font_height * j,
68-
*(string + numtemp), colour, true, str_font, screen_addr, font_stroage_size);
100+
*(string + numtemp), colour, true, str_font, screen_addr, font_stroage_size);
69101
}
70102
} else if (*(string + numtemp) == 10) {
71103
i = 19; /* jump next line */
@@ -96,47 +128,26 @@ void usbh_video_stop(struct usbh_video *video_class)
96128
lcdc_turn_off_display(LCD);
97129
}
98130

99-
void usbh_video_frame_callback(struct usbh_videoframe *frame)
100-
{
101-
char font_display_buf[50];
102-
103-
//USB_LOG_RAW("frame buf:%p,frame len:%d\r\n", frame->frame_buf, frame->frame_size);
104-
l1c_dc_invalidate((uint32_t)frame->frame_buf, IMAGE_WIDTH * IMAGE_HEIGHT * 2);
105-
sprintf(font_display_buf, "fps:%d", g_uvc_fps);
106-
string2font(1, 1, (uint8_t *)font_display_buf, sizeof(font_display_buf), 0x001f, (uint8_t *)nAsciiDot24x48, (uint32_t)frame->frame_buf, 24, 48);
107-
l1c_dc_writeback((uint32_t)frame->frame_buf, IMAGE_WIDTH * IMAGE_HEIGHT * 2);
108-
lcdc_layer_set_next_buffer(LCD, 0, (uint32_t)frame->frame_buf);
109-
}
110-
111-
void init_lcd(void)
131+
static void usbh_video_frame_thread(void *argument)
112132
{
113-
uint8_t layer_index = 0;
114-
lcdc_config_t config = { 0 };
115-
lcdc_layer_config_t layer = { 0 };
133+
int ret;
134+
struct usbh_videoframe *frame;
116135

117-
lcdc_get_default_config(LCD, &config);
118-
board_panel_para_to_lcdc(&config);
119-
lcdc_init(LCD, &config);
120-
121-
lcdc_get_default_layer_config(LCD, &layer, PIXEL_FORMAT, layer_index);
122-
123-
layer.position_x = (BOARD_LCD_WIDTH - IMAGE_WIDTH) / 2;
124-
layer.position_y = (BOARD_LCD_HEIGHT - IMAGE_HEIGHT) / 2;
125-
layer.width = IMAGE_WIDTH;
126-
layer.height = IMAGE_HEIGHT;
136+
while (1) {
137+
ret = usbh_video_stream_dequeue(&frame, 0xfffffff);
138+
if (ret < 0) {
139+
continue;
140+
}
141+
char font_display_buf[50];
127142

128-
layer.buffer = core_local_mem_to_sys_address(HPM_CORE0, (uint32_t)frame_buffer1);
129-
layer.alphablend.src_alpha = 0xF4; /* src */
130-
layer.alphablend.dst_alpha = 0xF0; /* dst */
131-
layer.alphablend.src_alpha_op = display_alpha_op_override;
132-
layer.alphablend.dst_alpha_op = display_alpha_op_override;
133-
layer.background.u = 0xffff0000;
134-
layer.alphablend.mode = display_alphablend_mode_xor;
143+
//USB_LOG_RAW("frame buf:%p,frame len:%d\r\n", frame->frame_buf, frame->frame_size);
144+
l1c_dc_invalidate((uint32_t)frame->frame_buf, IMAGE_WIDTH * IMAGE_HEIGHT * 2);
145+
sprintf(font_display_buf, "fps:%d", g_uvc_fps);
146+
string2font(1, 1, (uint8_t *)font_display_buf, sizeof(font_display_buf), 0x001f, (uint8_t *)nAsciiDot24x48, (uint32_t)frame->frame_buf, 24, 48);
147+
l1c_dc_writeback((uint32_t)frame->frame_buf, IMAGE_WIDTH * IMAGE_HEIGHT * 2);
148+
lcdc_layer_set_next_buffer(LCD, 0, (uint32_t)frame->frame_buf);
135149

136-
if (status_success != lcdc_config_layer(LCD, layer_index, &layer, true)) {
137-
printf("failed to configure layer\n");
138-
while (1)
139-
;
150+
usbh_video_stream_enqueue(frame);
140151
}
141152
}
142153

@@ -150,8 +161,9 @@ void uvc2lcd_init(void)
150161
frame_pool[1].frame_buf = frame_buffer2;
151162
frame_pool[1].frame_bufsize = IMAGE_WIDTH * IMAGE_HEIGHT * 2;
152163

153-
usbh_video_stream_init(5, frame_pool, 2);
164+
usbh_video_stream_create(frame_pool, 2);
154165

166+
usb_osal_thread_create("uvc_frame", 3072, 5, usbh_video_frame_thread, NULL);
155167
extern void usbh_video_fps_init(void);
156168
usbh_video_fps_init();
157169
}

0 commit comments

Comments
 (0)