[refactor][cam] refactor camera driver,add standard interfaces for camera

This commit is contained in:
jzlv 2021-10-25 15:14:04 +08:00
parent 9792e36ab4
commit e27aedace2
20 changed files with 404 additions and 259 deletions

View file

@ -63,9 +63,6 @@ int main(void)
cam_clk_out();
cam_hsync_crop(0, 2 * CAMERA_RESOLUTION_X);
cam_vsync_crop(0, CAMERA_RESOLUTION_Y);
if (SUCCESS != image_sensor_init(DISABLE, &camera_cfg, &mjpeg_cfg)) {
MSG("Init error!\n");
BL_CASE_FAIL;
@ -73,7 +70,15 @@ int main(void)
}
}
cam_start();
cam_frame_area_t cfg;
cfg.x0 = 0;
cfg.x1 = CAMERA_RESOLUTION_X;
cfg.y0 = 0;
cfg.y1 = CAMERA_RESOLUTION_Y;
struct device *cam0 = device_find("camera0");
device_control(cam0, DEVICE_CTRL_CAM_FRAME_CUT, &cfg);
device_control(cam0, DEVICE_CTRL_RESUME, NULL);
for (i = 0; i < 3; i++) {
while (SUCCESS != cam_get_one_frame_interleave(&picture, &length)) {
@ -82,11 +87,10 @@ int main(void)
MSG("picturestartuyvy");
UART_SendData(0, picture, length);
MSG("pictureend");
cam_drop_one_frame_interleave();
device_control(cam0, DEVICE_CTRL_CAM_FRAME_DROP, NULL);
}
cam_stop();
device_control(cam0, DEVICE_CTRL_SUSPEND, NULL);
BL_CASE_SUCCESS;
while (1) {

View file

@ -1,4 +1,3 @@
**board/bl706_avb/pinmux_config.h** 中 **PINMUX_SELECT** 选择 **PINMUX_CAMERA_LCD**
**bsp_common/image_sensor/bsp_image_sensor.c** 中**FORMAT_SEL** 选择 **RGB565**
```bash

View file

@ -99,7 +99,7 @@ void my_memcpy(void *dst, void const *src, uint32_t size)
}
}
void ATTR_TCM_SECTION CAM_Interrupt_Normal(void)
void ATTR_TCM_SECTION cam_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state)
{
if (flag_normal == 0) {
// memcpy((void *)(uint32_t)(0x42023000 + (8640 * buff_using_num)), (void *)CAMERA_WRITE_ADDR, CAMERA_FRAME_SIZE);
@ -162,7 +162,6 @@ void ATTR_TCM_SECTION CAM_Interrupt_Normal(void)
return;
}
// MSG("CAM NORMAL\r\n");
return;
}
@ -182,32 +181,34 @@ int ATTR_TCM_SECTION main(void)
}
// MSG("dma open \r\n");
cam_hw_mode_wrap(DISABLE);
//CAM_HW_Mode_Wrap(DISABLE);
cam_clk_out();
cam_hsync_crop(0, 2 * CAMERA_RESOLUTION_X);
cam_vsync_crop(0, CAMERA_RESOLUTION_Y);
CAM_IntMask(CAM_INT_ALL, MASK);
CAM_Int_Callback_set(CAM_INT_NORMAL_0, &CAM_Interrupt_Normal);
CAM_IntMask(CAM_INT_NORMAL_0, UNMASK);
CPU_Interrupt_Enable(CAM_IRQn);
if (SUCCESS != image_sensor_init(DISABLE, &camera_cfg, &mjpeg_cfg)) {
MSG("Init error!\n");
BL_CASE_FAIL;
while (1) {
}
}
// MSG("cam init!\n");
cam_start();
cam_frame_area_t cfg;
cfg.x0 = 0;
cfg.x1 = CAMERA_RESOLUTION_X;
cfg.y0 = 0;
cfg.y1 = CAMERA_RESOLUTION_Y;
struct device *cam0 = device_find("camera0");
device_control(cam0, DEVICE_CTRL_CAM_FRAME_CUT, &cfg);
device_set_callback(cam0, cam_irq_callback);
device_control(cam0, DEVICE_CTRL_SET_INT, (void *)CAM_FRAME_IT);
device_control(cam0, DEVICE_CTRL_RESUME, NULL);
while (1) {
if (buff_using_num == 18 * 3) { // close cam when 3 pic saved,480x360 = 480x20x18
cam_stop();
device_control(cam0, DEVICE_CTRL_SUSPEND, NULL);
device_write(uart0, 0, (void *)(uint32_t *)PSRAM_START_ADDR, YUV400_FRAME_SIZE * 3); // uart log send 3 pic raw data
//device_write(uart0, 0, (void *)(uint32_t *)PSRAM_START_ADDR, YUV400_FRAME_SIZE * 3); // uart log send 3 pic raw data
// MSG("\r\ntim1:%d, tim2:%d, tim3:%d, tim4:%d", tim1, tim2, tim3, tim4);
return 0;

View file

@ -1,4 +1,3 @@
**board/bl706_avb/pinmux_config.h** 中 **PINMUX_SELECT** 选择 **PINMUX_CAMERA_LCD**
**bsp_common/image_sensor/bsp_image_sensor.c** 中**IMAGE_SENSOR_USE** 选择**IMAGE_SENSOR_GC0308** (目前暂时没有 BF2013 sensor 验证)
**bsp_common/image_sensor/bsp_image_sensor.c** 中**FORMAT_SEL** 选择 **YUYV**
**bsp_common/image_sensor/bsp_image_sensor.c** 中**CAM_MODE** 选择 **CAM_USING_INT_MODE**模式

View file

@ -70,9 +70,6 @@ int main(void)
cam_clk_out();
cam_hsync_crop(0, 2 * CAMERA_RESOLUTION_X);
cam_vsync_crop(0, CAMERA_RESOLUTION_Y);
if (SUCCESS != image_sensor_init(DISABLE, &camera_cfg, &mjpeg_cfg)) {
MSG("Init error!\n");
BL_CASE_FAIL;
@ -80,7 +77,15 @@ int main(void)
}
}
cam_start();
cam_frame_area_t cfg;
cfg.x0 = 0;
cfg.x1 = CAMERA_RESOLUTION_X;
cfg.y0 = 0;
cfg.y1 = CAMERA_RESOLUTION_Y;
struct device *cam0 = device_find("camera0");
device_control(cam0, DEVICE_CTRL_CAM_FRAME_CUT, &cfg);
device_control(cam0, DEVICE_CTRL_RESUME, NULL);
for (i = 0; i < 5; i++) {
while (SUCCESS != cam_get_one_frame_interleave(&picture, &length)) {
@ -93,7 +98,7 @@ int main(void)
cam_drop_one_frame_interleave();
}
cam_stop();
device_control(cam0, DEVICE_CTRL_SUSPEND, NULL);
BL_CASE_SUCCESS;
while (1) {

View file

@ -1,4 +1,3 @@
**board/bl706_avb/pinmux_config.h** 中 **PINMUX_SELECT** 选择 **PINMUX_CAMERA_LCD**
**bsp_common/image_sensor/bsp_image_sensor.c** 中**FORMAT_SEL** 选择 **RGB565**
```bash

View file

@ -246,17 +246,21 @@ int main(void)
cam_clk_out();
cam_hsync_crop(400, (2 * CAMERA_RESOLUTION_X) + 400);
cam_vsync_crop(80, CAMERA_RESOLUTION_Y + 80);
if (SUCCESS != image_sensor_init(DISABLE, &camera_cfg, &mjpeg_cfg)) {
MSG("Init error!\n");
BL_CASE_FAIL;
while (1) {
}
}
cam_frame_area_t cfg;
cfg.x0 = 200;
cfg.x1 = CAMERA_RESOLUTION_X + 200;
cfg.y0 = 80;
cfg.y1 = CAMERA_RESOLUTION_Y + 80;
cam_start();
struct device *cam0 = device_find("camera0");
device_control(cam0, DEVICE_CTRL_CAM_FRAME_CUT, &cfg);
device_control(cam0, DEVICE_CTRL_RESUME, NULL);
LCD_Set_Addr(0, 0, CAMERA_RESOLUTION_X, CAMERA_RESOLUTION_Y);
@ -268,16 +272,16 @@ int main(void)
while (SUCCESS != cam_get_one_frame_interleave(&picture, &length)) {
}
cam_stop();
device_control(cam0, DEVICE_CTRL_SUSPEND, NULL);
#ifdef USE_YUV422
yuv422sp_to_rgb24(picture, rgb_pic, CAMERA_RESOLUTION_X, CAMERA_RESOLUTION_Y);
rgb24_to_rgb565(rgb_pic, rgb16_pic);
LCD_DrawPicture_cam(0, 0, CAMERA_RESOLUTION_X, CAMERA_RESOLUTION_Y, picture);
#else
LCD_WR_SPI_DMA(picture, (CAMERA_FRAME_SIZE));
LCD_WR_SPI_DMA((uint16_t *)picture, (CAMERA_FRAME_SIZE));
#endif
cam_drop_one_frame_interleave();
cam_start();
device_control(cam0, DEVICE_CTRL_CAM_FRAME_DROP, NULL);
device_control(cam0, DEVICE_CTRL_RESUME, NULL);
#ifdef TEST_TIM
timer_end = bflb_platform_get_time_ms();

View file

@ -1,4 +1,3 @@
**board/bl706_avb/pinmux_config.h** 中 **PINMUX_SELECT** 选择 **PINMUX_CAMERA_LCD**
**bsp_common/image_sensor/bsp_image_sensor.c** 中**FORMAT_SEL** 选择 **RGB565**
```bash

View file

@ -353,16 +353,18 @@ uint32_t jpeg_count = 0;
void usbd_video_set_interface_callback(uint8_t value)
{
struct device* cam0 = device_find("camera0");
if (value) {
play_status = 1;
MSG("OPEN\r\n");
mjpeg_start();
cam_start();
device_control(cam0, DEVICE_CTRL_RESUME, NULL);
} else {
play_status = 0;
MSG("CLOSE\r\n");
cam_stop();
device_control(cam0, DEVICE_CTRL_SUSPEND, NULL);
mjpeg_stop();
}
}