From 72c4529e7e0e9c763597e00efb8847d9d41a257f Mon Sep 17 00:00:00 2001 From: gaoxu Date: Wed, 21 Jan 2026 15:17:02 +0800 Subject: [PATCH] feat(cam): add format conversion when new dvp cam --- .../esp_driver_cam/dvp/include/esp_cam_ctlr_dvp.h | 4 ++++ .../esp_driver_cam/dvp/src/esp_cam_ctlr_dvp_cam.c | 13 +++++++++++++ .../test_apps/dvp/main/test_dvp_driver.c | 4 ++++ .../test_apps/dvp/main/test_dvp_s3eye.c | 1 + .../en/api-reference/peripherals/camera_driver.rst | 1 + .../api-reference/peripherals/camera_driver.rst | 1 + .../peripherals/camera/dvp_dsi/main/dvp_dsi_main.c | 1 + .../camera/dvp_spi_lcd/main/dvp_spi_lcd_main.c | 14 ++++++++++---- 8 files changed, 35 insertions(+), 4 deletions(-) diff --git a/components/esp_driver_cam/dvp/include/esp_cam_ctlr_dvp.h b/components/esp_driver_cam/dvp/include/esp_cam_ctlr_dvp.h index 54cf67de2c9..1fddb238ee7 100644 --- a/components/esp_driver_cam/dvp/include/esp_cam_ctlr_dvp.h +++ b/components/esp_driver_cam/dvp/include/esp_cam_ctlr_dvp.h @@ -40,6 +40,10 @@ typedef struct esp_cam_ctlr_dvp_config { uint32_t h_res; /*!< Input horizontal resolution, i.e. the number of pixels in a line */ uint32_t v_res; /*!< Input vertical resolution, i.e. the number of lines in a frame */ cam_ctlr_color_t input_data_color_type; /*!< Input pixel format */ + cam_ctlr_color_t output_data_color_type; /*!< Output pixel format */ + color_conv_std_rgb_yuv_t conv_std; /*!< Conversion standard */ + color_range_t input_range; /*!< Input color range */ + color_range_t output_range; /*!< Output color range */ uint32_t cam_data_width; /*!< Byte width, 8, 16 or 24 bit, default to 8 */ struct { uint32_t bit_swap_en : 1; /*!< Enable bit swap */ diff --git a/components/esp_driver_cam/dvp/src/esp_cam_ctlr_dvp_cam.c b/components/esp_driver_cam/dvp/src/esp_cam_ctlr_dvp_cam.c index 209c7627d7e..5e2567a79ee 100644 --- a/components/esp_driver_cam/dvp/src/esp_cam_ctlr_dvp_cam.c +++ b/components/esp_driver_cam/dvp/src/esp_cam_ctlr_dvp_cam.c @@ -806,6 +806,9 @@ esp_err_t esp_cam_ctlr_dvp_format_conversion(esp_cam_ctlr_handle_t cam_handle, esp_cam_ctlr_dvp_cam_t *ctlr = (esp_cam_ctlr_dvp_cam_t *)cam_handle; ESP_LOGD(TAG, "Configure format conversion: %d -> %d", config->src_format, config->dst_format); + if (config->src_format == config->dst_format) { + return ESP_OK; + } #if !CONFIG_ESP32P4_SELECTS_REV_LESS_V3 if (config->src_format == CAM_CTLR_COLOR_YUV420) { @@ -903,6 +906,16 @@ esp_err_t esp_cam_new_dvp_ctlr(const esp_cam_ctlr_dvp_config_t *config, esp_cam_ cam_hal_init(&ctlr->hal, &cam_hal_config); + cam_ctlr_format_conv_config_t format_conv_config = { + .src_format = config->input_data_color_type, + .dst_format = config->output_data_color_type, + .conv_std = config->conv_std, + .data_width = config->cam_data_width == 0 ? 8 : config->cam_data_width, + .input_range = config->input_range, + .output_range = config->output_range, + }; + ESP_GOTO_ON_ERROR(esp_cam_ctlr_dvp_format_conversion(&(ctlr->base), &format_conv_config), fail5, TAG, "failed to configure format conversion"); + ctlr->ctlr_id = config->ctlr_id; ctlr->fb_size_in_bytes = fb_size_in_bytes; ctlr->dvp_fsm = ESP_CAM_CTLR_DVP_CAM_FSM_INIT; diff --git a/components/esp_driver_cam/test_apps/dvp/main/test_dvp_driver.c b/components/esp_driver_cam/test_apps/dvp/main/test_dvp_driver.c index 123297574c6..682e9ffd6c5 100644 --- a/components/esp_driver_cam/test_apps/dvp/main/test_dvp_driver.c +++ b/components/esp_driver_cam/test_apps/dvp/main/test_dvp_driver.c @@ -18,6 +18,7 @@ TEST_CASE("TEST DVP driver allocation", "[DVP]") .h_res = 800, .v_res = 640, .input_data_color_type = CAM_CTLR_COLOR_RGB565, + .output_data_color_type = CAM_CTLR_COLOR_RGB565, .dma_burst_size = 64, .byte_swap_en = false, .pin_dont_init = true, @@ -70,6 +71,7 @@ TEST_CASE("TEST DVP driver no backup buffer usage", "[DVP]") .h_res = 800, .v_res = 640, .input_data_color_type = CAM_CTLR_COLOR_RGB565, + .output_data_color_type = CAM_CTLR_COLOR_RGB565, .dma_burst_size = 64, .byte_swap_en = false, .bk_buffer_dis = true, @@ -97,6 +99,7 @@ TEST_CASE("TEST DVP driver intern/extern init", "[DVP]") .h_res = 800, .v_res = 640, .input_data_color_type = CAM_CTLR_COLOR_RGB565, + .output_data_color_type = CAM_CTLR_COLOR_RGB565, .dma_burst_size = 64, .byte_swap_en = false, .external_xtal = true, @@ -129,6 +132,7 @@ TEST_CASE("TEST DVP driver intern/extern generate xclk", "[DVP]") .h_res = 800, .v_res = 640, .input_data_color_type = CAM_CTLR_COLOR_RGB565, + .output_data_color_type = CAM_CTLR_COLOR_RGB565, .dma_burst_size = 64, .byte_swap_en = false, .external_xtal = true, diff --git a/components/esp_driver_cam/test_apps/dvp/main/test_dvp_s3eye.c b/components/esp_driver_cam/test_apps/dvp/main/test_dvp_s3eye.c index c5f3f69e010..d86a0325bae 100644 --- a/components/esp_driver_cam/test_apps/dvp/main/test_dvp_s3eye.c +++ b/components/esp_driver_cam/test_apps/dvp/main/test_dvp_s3eye.c @@ -88,6 +88,7 @@ TEST_CASE("TEST DVP camera on esp32s3_eye", "[dvp][camera][esp32s3_eye]") .h_res = TEST_DVP_CAM_H_RES, .v_res = TEST_DVP_CAM_V_RES, .input_data_color_type = CAM_CTLR_COLOR_RGB565, + .output_data_color_type = CAM_CTLR_COLOR_RGB565, .dma_burst_size = 64, .pin = &pin_cfg, .bk_buffer_dis = 1, diff --git a/docs/en/api-reference/peripherals/camera_driver.rst b/docs/en/api-reference/peripherals/camera_driver.rst index b99df7ec68f..0784ecad238 100644 --- a/docs/en/api-reference/peripherals/camera_driver.rst +++ b/docs/en/api-reference/peripherals/camera_driver.rst @@ -184,6 +184,7 @@ You can implement the camera controller driver using one of the following method .h_res = CONFIG_EXAMPLE_CAM_HRES, .v_res = CONFIG_EXAMPLE_CAM_VRES, .input_data_color_type = CAM_CTLR_COLOR_RGB565, + .output_data_color_type = CAM_CTLR_COLOR_RGB565, .dma_burst_size = 128, .pin = &pin_cfg, .bk_buffer_dis = 1, diff --git a/docs/zh_CN/api-reference/peripherals/camera_driver.rst b/docs/zh_CN/api-reference/peripherals/camera_driver.rst index f695b11538a..38a9212cead 100644 --- a/docs/zh_CN/api-reference/peripherals/camera_driver.rst +++ b/docs/zh_CN/api-reference/peripherals/camera_driver.rst @@ -184,6 +184,7 @@ .h_res = CONFIG_EXAMPLE_CAM_HRES, .v_res = CONFIG_EXAMPLE_CAM_VRES, .input_data_color_type = CAM_CTLR_COLOR_RGB565, + .output_data_color_type = CAM_CTLR_COLOR_RGB565, .dma_burst_size = 128, .pin = &pin_cfg, .bk_buffer_dis = 1, diff --git a/examples/peripherals/camera/dvp_dsi/main/dvp_dsi_main.c b/examples/peripherals/camera/dvp_dsi/main/dvp_dsi_main.c index 0bf5d203cce..f2bbce28956 100644 --- a/examples/peripherals/camera/dvp_dsi/main/dvp_dsi_main.c +++ b/examples/peripherals/camera/dvp_dsi/main/dvp_dsi_main.c @@ -92,6 +92,7 @@ void app_main(void) .h_res = CONFIG_EXAMPLE_CAM_HRES, .v_res = CONFIG_EXAMPLE_CAM_VRES, .input_data_color_type = CAM_CTLR_COLOR_RGB565, + .output_data_color_type = CAM_CTLR_COLOR_RGB565, .dma_burst_size = 128, .pin = &pin_cfg, .bk_buffer_dis = 1, diff --git a/examples/peripherals/camera/dvp_spi_lcd/main/dvp_spi_lcd_main.c b/examples/peripherals/camera/dvp_spi_lcd/main/dvp_spi_lcd_main.c index 655e46a16de..7270992ae84 100644 --- a/examples/peripherals/camera/dvp_spi_lcd/main/dvp_spi_lcd_main.c +++ b/examples/peripherals/camera/dvp_spi_lcd/main/dvp_spi_lcd_main.c @@ -1,11 +1,12 @@ /* - * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include #include #include +#include "hal/cam_ctlr_types.h" #include "sdkconfig.h" #include "esp_attr.h" #include "esp_log.h" @@ -147,10 +148,15 @@ void app_main(void) .h_res = CONFIG_EXAMPLE_CAM_HRES, .v_res = CONFIG_EXAMPLE_CAM_VRES, #if CONFIG_EXAMPLE_CAM_INPUT_FORMAT_YUV422 - .input_data_color_type = CAM_CTLR_COLOR_YUV422, + .input_data_color_type = CAM_CTLR_COLOR_YUV422_UYVY, + .output_data_color_type = CAM_CTLR_COLOR_RGB565, #else .input_data_color_type = CAM_CTLR_COLOR_RGB565, + .output_data_color_type = CAM_CTLR_COLOR_RGB565, #endif + .conv_std = COLOR_CONV_STD_RGB_YUV_BT601, + .input_range = COLOR_RANGE_LIMIT, + .output_range = COLOR_RANGE_LIMIT, .dma_burst_size = 64, .pin = &pin_cfg, .bk_buffer_dis = 1, @@ -208,8 +214,8 @@ void app_main(void) ESP_LOGI(TAG, "Configure format conversion: YUV422 -> RGB565"); // Configure format conversion const cam_ctlr_format_conv_config_t conv_cfg = { - .src_format = CAM_CTLR_COLOR_YUV422, // Source format: YUV422 - .dst_format = CAM_CTLR_COLOR_RGB565, // Destination format: RGB565 + .src_format = CAM_CTLR_COLOR_YUV422_UYVY, // Source format: YUV422 + .dst_format = CAM_CTLR_COLOR_RGB565, // Destination format: RGB565 .conv_std = COLOR_CONV_STD_RGB_YUV_BT601, .data_width = 8, .input_range = COLOR_RANGE_LIMIT,