feat(cam): support esp32p4 eco5 dvp cam

This commit is contained in:
gaoxu
2025-11-05 10:10:52 +08:00
parent 4483e2628d
commit 2621a23201
6 changed files with 74 additions and 7 deletions
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -38,8 +38,33 @@ 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 */
uint32_t cam_data_width; /*!< Byte width, 8, 16 or 24 bit, default to 8 */
struct {
uint32_t byte_swap_en : 1; /*!< Enable byte swap */
uint32_t bit_swap_en : 1; /*!< Enable bit swap */
uint32_t byte_swap_en : 1; /*!< Enable byte swap
*
* GDMA Data Byte Order Table (input: B0,B1,B2,B3,B4,B5, addresses from low to high)
*
* | cam_data_width | bit_swap_en | byte_swap_en | Stage 1 Output Data Sequence |
* |----------------|-------------|--------------|------------------------------ |
* | 8-bit | 0 | 0 | {B0}{B1}{B2}{B3}{B4}{B5} |
* | 8-bit | 0 | 1 | {B1,B0}{B3,B2}{B5,B4} |
* | 8-bit | 1 | 0 | {B0'}{B1'}{B2'}{B3'}{B4'}{B5'} |
* | 8-bit | 1 | 1 | {B1',B0'}{B3',B2'}{B5',B4'} |
*
* | 16-bit | 0 | 0 | {B1,B0}{B3,B2}{B5,B4} |
* | 16-bit | 0 | 1 | {B0,B1}{B2,B3}{B4,B5} |
* | 16-bit | 1 | 0 | {B1',B0'}{B3',B2'}{B5',B4'} |
* | 16-bit | 1 | 1 | {B0',B1'}{B2',B3'}{B4',B5'} |
*
* | 24-bit | 0 | 0 | {B2,B1,B0}{B5,B4,B3} |
* | 24-bit | 0 | 1 | {B0,B1,B2}{B3,B4,B5} |
* | 24-bit | 1 | 0 | {B2',B1',B0'}{B5',B4',B3'} |
* | 24-bit | 1 | 1 | {B0',B1',B2'}{B3',B4',B5'} |
*
* Where B0' = bit-reversed B0,Bn'[7:0] = Bn[0:7]
* Each {} contains big-endian parallel data, {} are in serial relationship, output order is left to right
*/
uint32_t bk_buffer_dis : 1; /*!< Disable backup buffer */
uint32_t pin_dont_init : 1; /*!< Don't initialize DVP pins if users have called "esp_cam_ctlr_dvp_init" before */
uint32_t pic_format_jpeg : 1; /*!< Input picture format is JPEG, if set this flag and "input_data_color_type" will be ignored */
@@ -771,7 +771,9 @@ static void *esp_cam_ctlr_dvp_cam_alloc_buffer(esp_cam_ctlr_t *handle, size_t si
* @param cam_handle Camera controller handle
* @param src_format Source format
* @param dst_format Destination format
* @return ESP_OK on success, ESP_FAIL on failure
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG: Invalid argument
*/
esp_err_t esp_cam_ctlr_dvp_format_conversion(esp_cam_ctlr_handle_t cam_handle,
const cam_ctlr_format_conv_config_t *config)
@@ -784,6 +786,12 @@ esp_err_t esp_cam_ctlr_dvp_format_conversion(esp_cam_ctlr_handle_t cam_handle,
ESP_LOGD(TAG, "Configure format conversion: %d -> %d", config->src_format, config->dst_format);
#if !CONFIG_ESP32P4_SELECTS_REV_LESS_V3
if (config->src_format == CAM_CTLR_COLOR_YUV420) {
ESP_LOGE(TAG, "YUV420 is not allowed for source format");
return ESP_ERR_INVALID_ARG;
}
#endif
// Configure color format conversion
cam_hal_color_format_convert(&ctlr->hal, config);
@@ -845,9 +853,17 @@ esp_err_t esp_cam_new_dvp_ctlr(const esp_cam_ctlr_dvp_config_t *config, esp_cam_
cam_hal_config_t cam_hal_config = {
.port = config->ctlr_id,
.cam_data_width = config->cam_data_width == 0 ? 8 : config->cam_data_width,
.bit_swap_en = config->bit_swap_en,
.byte_swap_en = config->byte_swap_en,
};
ESP_RETURN_ON_FALSE(cam_hal_config.cam_data_width == 8 || cam_hal_config.cam_data_width == 16 || cam_hal_config.cam_data_width == 24, ESP_ERR_INVALID_ARG, TAG, "invalid argument: cam_data_width is not 8 or 16 or 24");
#if !CONFIG_ESP32P4_SELECTS_REV_LESS_V3
ESP_RETURN_ON_FALSE(cam_hal_config.cam_data_width != 8 || cam_hal_config.byte_swap_en == 0, ESP_ERR_INVALID_ARG, TAG, "invalid argument: byte swap is not supported when cam_data_width is 8");
#endif
if (!config->pin_dont_init) {
// Initialzie DVP clock and GPIO internally
ESP_GOTO_ON_ERROR(esp_cam_ctlr_dvp_init(config->ctlr_id, config->clk_src, config->pin),