feat(isp_color): support ISP color on P4

This commit is contained in:
gaoxu 2024-09-02 15:42:10 +08:00
parent 6673376297
commit 7b71d7aaac
14 changed files with 371 additions and 1 deletions

View File

@ -30,6 +30,10 @@ if(CONFIG_SOC_ISP_SHARPEN_SUPPORTED)
list(APPEND srcs "src/isp_sharpen.c")
endif()
if(CONFIG_SOC_ISP_COLOR_SUPPORTED)
list(APPEND srcs "src/isp_color.c")
endif()
if(NOT ${target} STREQUAL "linux")
list(APPEND requires esp_mm)
endif()

View File

@ -21,3 +21,4 @@
#include "driver/isp_gamma.h"
#include "driver/isp_hist.h"
#include "driver/isp_sharpen.h"
#include "driver/isp_color.h"

View File

@ -0,0 +1,82 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include "esp_err.h"
#include "driver/isp_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief ISP color configurations
*/
typedef struct {
isp_color_contrast_t color_contrast; /*!< The color contrast value, defines the contrast level of the image,
* which controls the difference in luminance between the lightest and darkest parts of the image
* Range 0 ~ 1, decimal value should be 0~127, default 1
*/
isp_color_saturation_t color_saturation; /*!< The color saturation value, controls the intensity of colors in the image,
* affecting how vivid or muted the colors appear.
* Range 0 ~ 1, decimal value should be 0~127, default 1
*/
uint32_t color_hue; /*!< The color hue value, based on the color wheel.
* 0 degrees represents red, 120 degrees represents green, and 240 degrees represents blue. 360 degrees overlaps with 0 degrees
* Range 0 ~ 360, default 0.
*/
int color_brightness; /*!< The color brightness value.
* Range -128 ~ 127, default 0.
* Negative range (-128 to -1): Decreases brightness, the smaller the value, the darker the image.
* Zero (0): Maintains the original brightness, without adjusting the image's brightness.
* Positive range (1 to 127): Increases brightness, the larger the value, the brighter the image.
*/
} esp_isp_color_config_t;
/**
* @brief ISP Color configuration
*
* @note After calling this API, Color doesn't take into effect until `esp_isp_color_enable` is called
* @note API is ISR available
*
* @param[in] proc Processor handle
* @param[in] config Color configurations, set NULL to de-configure the ISP Color
*
* @return
* - ESP_OK On success
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid
*/
esp_err_t esp_isp_color_configure(isp_proc_handle_t proc, const esp_isp_color_config_t *config);
/**
* @brief Enable ISP color function
*
* @param[in] proc Processor handle
*
* @return
* - ESP_OK On success
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
* - ESP_ERR_INVALID_STATE Driver state is invalid.
*/
esp_err_t esp_isp_color_enable(isp_proc_handle_t proc);
/**
* @brief Disable ISP color function
*
* @param[in] proc Processor handle
*
* @return
* - ESP_OK On success
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
* - ESP_ERR_INVALID_STATE Driver state is invalid.
*/
esp_err_t esp_isp_color_disable(isp_proc_handle_t proc);
#ifdef __cplusplus
}
#endif

View File

@ -72,6 +72,7 @@ typedef struct isp_processor_t {
isp_fsm_t bf_fsm;
isp_fsm_t demosaic_fsm;
isp_fsm_t sharpen_fsm;
isp_fsm_t color_fsm;
esp_isp_evt_cbs_t cbs;
void *user_data;

View File

@ -0,0 +1,70 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <esp_types.h>
#include <sys/lock.h>
#include "sdkconfig.h"
#include "esp_log.h"
#include "esp_check.h"
#include "freertos/FreeRTOS.h"
#include "driver/isp_core.h"
#include "driver/isp_color.h"
#include "soc/isp_periph.h"
#include "esp_private/isp_private.h"
static const char *TAG = "ISP_COLOR";
/*---------------------------------------------------------------
Color
---------------------------------------------------------------*/
esp_err_t esp_isp_color_configure(isp_proc_handle_t proc, const esp_isp_color_config_t *config)
{
ESP_RETURN_ON_FALSE_ISR(proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
if (config) {
ESP_RETURN_ON_FALSE_ISR(((config->color_contrast.val <= ISP_LL_COLOR_CONTRAST_MAX) &&
(config->color_saturation.val <= ISP_LL_COLOR_SATURATION_MAX) &&
(config->color_hue <= ISP_LL_COLOR_HUE_MAX) &&
(config->color_brightness >= ISP_LL_COLOR_BRIGNTNESS_MIN) &&
(config->color_brightness <= ISP_LL_COLOR_BRIGNTNESS_MAX)), ESP_ERR_INVALID_ARG, TAG, "invalid color config");
isp_hal_color_cfg_t color_hal_cfg = {
.color_contrast = config->color_contrast,
.color_saturation = config->color_saturation,
.color_hue = config->color_hue,
.color_brightness = config->color_brightness,
};
isp_hal_color_config(&(proc->hal), &color_hal_cfg);
} else {
isp_hal_color_config(&(proc->hal), NULL);
}
return ESP_OK;
}
esp_err_t esp_isp_color_enable(isp_proc_handle_t proc)
{
ESP_RETURN_ON_FALSE(proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
ESP_RETURN_ON_FALSE(proc->color_fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "color is enabled already");
isp_ll_color_clk_enable(proc->hal.hw, true);
isp_ll_color_enable(proc->hal.hw, true);
proc->color_fsm = ISP_FSM_ENABLE;
return ESP_OK;
}
esp_err_t esp_isp_color_disable(isp_proc_handle_t proc)
{
ESP_RETURN_ON_FALSE(proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
ESP_RETURN_ON_FALSE(proc->color_fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "color isn't enabled yet");
isp_ll_color_enable(proc->hal.hw, false);
isp_ll_color_clk_enable(proc->hal.hw, false);
proc->color_fsm = ISP_FSM_INIT;
return ESP_OK;
}

View File

@ -69,6 +69,7 @@ extern "C" {
#define ISP_LL_EVENT_AWB_MASK (ISP_LL_EVENT_AWB_FDONE)
#define ISP_LL_EVENT_SHARP_MASK (ISP_LL_EVENT_SHARP_FRAME)
#define ISP_LL_EVENT_HIST_MASK (ISP_LL_EVENT_HIST_FDONE)
#define ISP_LL_EVENT_COLOR_MASK (ISP_LL_EVENT_COLOR_FRAME)
/*---------------------------------------------------------------
AF
@ -92,6 +93,15 @@ extern "C" {
#define ISP_LL_DVP_DATA_TYPE_RAW10 0x2B
#define ISP_LL_DVP_DATA_TYPE_RAW12 0x2C
/*---------------------------------------------------------------
Color
---------------------------------------------------------------*/
#define ISP_LL_COLOR_CONTRAST_MAX 0x80
#define ISP_LL_COLOR_SATURATION_MAX 0x80
#define ISP_LL_COLOR_HUE_MAX 360
#define ISP_LL_COLOR_BRIGNTNESS_MIN -128
#define ISP_LL_COLOR_BRIGNTNESS_MAX 127
/*---------------------------------------------------------------
AWB
---------------------------------------------------------------*/
@ -859,6 +869,50 @@ static inline void isp_ll_color_enable(isp_dev_t *hw, bool enable)
hw->cntl.color_en = enable;
}
/**
* @brief Set color contrast
*
* @param[in] hw Hardware instance address
* @param[in] color_contrast Color contrast value
*/
static inline void isp_ll_color_set_contrast(isp_dev_t *hw, isp_color_contrast_t color_contrast)
{
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->color_ctrl, color_contrast, color_contrast.val);
}
/**
* @brief Set color saturation
*
* @param[in] hw Hardware instance address
* @param[in] color_saturation Color saturation value
*/
static inline void isp_ll_color_set_saturation(isp_dev_t *hw, isp_color_saturation_t color_saturation)
{
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->color_ctrl, color_saturation, color_saturation.val);
}
/**
* @brief Set color hue
*
* @param[in] hw Hardware instance address
* @param[in] color_hue Color hue angle
*/
static inline void isp_ll_color_set_hue(isp_dev_t *hw, uint32_t color_hue)
{
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->color_ctrl, color_hue, color_hue);
}
/**
* @brief Set color brightness
*
* @param[in] hw Hardware instance address
* @param[in] color_brightness Color brightness value, signed 2's complement
*/
static inline void isp_ll_color_set_brigntness(isp_dev_t *hw, int8_t color_brightness)
{
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->color_ctrl, color_brightness, color_brightness);
}
/*---------------------------------------------------------------
DVP Camera
---------------------------------------------------------------*/

View File

@ -84,6 +84,17 @@ typedef struct {
void isp_hal_init(isp_hal_context_t *hal, int isp_id);
/**
* @brief Color configurations
*/
typedef struct {
isp_color_contrast_t color_contrast; ///< The color contrast value, range 0~1, decimal value should be 0~127
isp_color_saturation_t color_saturation; ///< The color saturation value, range 0~1, decimal value should be 0~127
uint32_t color_hue; ///< The color hue angle value, range 0-360
int color_brightness; ///< The color brightness value, range -128~127
} isp_hal_color_cfg_t;
/*---------------------------------------------------------------
AF
---------------------------------------------------------------*/
@ -225,6 +236,18 @@ void isp_hal_sharpen_config(isp_hal_context_t *hal, isp_hal_sharpen_cfg_t *confi
*/
void isp_hal_hist_window_config(isp_hal_context_t *hal, const isp_window_t *window);
/*---------------------------------------------------------------
Color
---------------------------------------------------------------*/
/**
* @brief Set the color config
*
* @param[in] hal Context of the HAL layer
* @param[in] config Color config, set NULL to de-config the ISP color
*/
void isp_hal_color_config(isp_hal_context_t *hal, const isp_hal_color_cfg_t *config);
#ifdef __cplusplus
}
#endif

View File

@ -359,6 +359,39 @@ typedef struct {
uint32_t hist_value[ISP_HIST_SEGMENT_NUMS]; ///< Histogram value, represents the number of pixels that the histogram window's brightness results fall into the segment X.
} isp_hist_result_t;
/*---------------------------------------------------------------
Color
---------------------------------------------------------------*/
#define ISP_COLOR_CONTRAST_INT_BITS 1
#define ISP_COLOR_CONTRAST_DEC_BITS 7
#define ISP_COLOR_CONTRAST_RES_BITS 24
#define ISP_COLOR_SATURATION_INT_BITS 1
#define ISP_COLOR_SATURATION_DEC_BITS 7
#define ISP_COLOR_SATURATION_RES_BITS 24
/**
* @brief Color contrast value
*/
typedef union {
struct {
uint32_t decimal:ISP_COLOR_CONTRAST_DEC_BITS; ///< Decimal part
uint32_t integer:ISP_COLOR_CONTRAST_INT_BITS; ///< Integer part
uint32_t reserved:ISP_COLOR_CONTRAST_RES_BITS; ///< Reserved
};
uint32_t val; ///< 32-bit color contrast value
} isp_color_contrast_t;
/**
* @brief Color saturation value
*/
typedef union {
struct {
uint32_t decimal:ISP_COLOR_SATURATION_DEC_BITS; ///< Decimal part
uint32_t integer:ISP_COLOR_SATURATION_INT_BITS; ///< Integer part
uint32_t reserved:ISP_COLOR_SATURATION_RES_BITS; ///< Reserved
};
uint32_t val; ///< 32-bit color saturation value
} isp_color_saturation_t;
#ifdef __cplusplus
}

View File

@ -189,6 +189,32 @@ void isp_hal_demosaic_config(isp_hal_context_t *hal, isp_hal_demosaic_cfg_t *con
}
}
/*---------------------------------------------------------------
Color
---------------------------------------------------------------*/
void isp_hal_color_config(isp_hal_context_t *hal, const isp_hal_color_cfg_t *config)
{
if (config) {
isp_ll_color_set_contrast(hal->hw, config->color_contrast);
isp_ll_color_set_saturation(hal->hw, config->color_saturation);
isp_ll_color_set_hue(hal->hw, (config->color_hue * 256) / 360);
isp_ll_color_set_brigntness(hal->hw, (int8_t)config->color_brightness);
} else {
isp_color_contrast_t color_contrast_default = {
.integer = 1,
.decimal = 0,
};
isp_color_saturation_t color_saturation_default = {
.integer = 1,
.decimal = 0,
};
isp_ll_color_set_contrast(hal->hw, color_contrast_default);
isp_ll_color_set_saturation(hal->hw, color_saturation_default);
isp_ll_color_set_hue(hal->hw, 0);
isp_ll_color_set_brigntness(hal->hw, 0);
}
}
/*---------------------------------------------------------------
Histogram
---------------------------------------------------------------*/

View File

@ -855,6 +855,10 @@ config SOC_ISP_SHARPEN_SUPPORTED
bool
default y
config SOC_ISP_COLOR_SUPPORTED
bool
default y
config SOC_ISP_SHARE_CSI_BRG
bool
default y

View File

@ -337,6 +337,7 @@
#define SOC_ISP_DEMOSAIC_SUPPORTED 1
#define SOC_ISP_DVP_SUPPORTED 1
#define SOC_ISP_SHARPEN_SUPPORTED 1
#define SOC_ISP_COLOR_SUPPORTED 1
#define SOC_ISP_SHARE_CSI_BRG 1
#define SOC_ISP_NUMS 1U

View File

@ -28,6 +28,7 @@ INPUT += \
$(PROJECT_PATH)/components/esp_driver_touch_sens/hw_ver3/include/driver/touch_version_types.h \
$(PROJECT_PATH)/components/esp_driver_jpeg/include/driver/jpeg_types.h \
$(PROJECT_PATH)/components/esp_driver_isp/include/driver/isp.h \
$(PROJECT_PATH)/components/esp_driver_isp/include/driver/isp_types.h \
$(PROJECT_PATH)/components/esp_driver_isp/include/driver/isp_af.h \
$(PROJECT_PATH)/components/esp_driver_isp/include/driver/isp_ae.h \
$(PROJECT_PATH)/components/esp_driver_isp/include/driver/isp_awb.h \
@ -38,6 +39,7 @@ INPUT += \
$(PROJECT_PATH)/components/esp_driver_isp/include/driver/isp_core.h \
$(PROJECT_PATH)/components/esp_driver_isp/include/driver/isp_gamma.h \
$(PROJECT_PATH)/components/esp_driver_isp/include/driver/isp_hist.h \
$(PROJECT_PATH)/components/esp_driver_isp/include/driver/isp_color.h \
$(PROJECT_PATH)/components/esp_driver_jpeg/include/driver/jpeg_decode.h \
$(PROJECT_PATH)/components/esp_driver_jpeg/include/driver/jpeg_encode.h \
$(PROJECT_PATH)/components/esp_driver_ppa/include/driver/ppa.h \

View File

@ -502,6 +502,58 @@ After calling :cpp:func:`esp_isp_bf_configure`, you need to enable the ISP BF pr
Calling :cpp:func:`esp_isp_bf_disable` does the opposite, that is, put the driver back to the **init** state.
.. _isp-color:
ISP Color Processor
~~~~~~~~~~~~~~~~~~~
This pipeline is used to adjust the image contrast, saturation, hue and brightness.
Calling :cpp:func:`esp_isp_color_configure` to configure color function, you can take following code as reference.
{IDF_TARGET_SOC_ISP_COLOR_CONTRAST_MAX:default="1.0", esp32p4="1.0"}
{IDF_TARGET_SOC_ISP_COLOR_CONTRAST_DEFAULT:default="1.0", esp32p4="1.0"}
{IDF_TARGET_SOC_ISP_COLOR_SATURATION_MAX:default="1.0", esp32p4="1.0"}
{IDF_TARGET_SOC_ISP_COLOR_SATURATION_DEFAULT:default="1.0", esp32p4="1.0"}
{IDF_TARGET_SOC_ISP_COLOR_HUE_MAX:default="360", esp32p4="360"}
{IDF_TARGET_SOC_ISP_COLOR_HUE_DEFAULT:default="0", esp32p4="0"}
{IDF_TARGET_SOC_ISP_COLOR_BRIGHTNESS_MIN:default="-127", esp32p4="-127"}
{IDF_TARGET_SOC_ISP_COLOR_BRIGHTNESS_MAX:default="128", esp32p4="128"}
{IDF_TARGET_SOC_ISP_COLOR_BRIGHTNESS_DEFAULT:default="0", esp32p4="0"}
.. list::
- Contrast value should be 0 ~ {IDF_TARGET_SOC_ISP_COLOR_CONTRAST_MAX}, default {IDF_TARGET_SOC_ISP_COLOR_CONTRAST_DEFAULT}
- Saturation value should be 0 ~ {IDF_TARGET_SOC_ISP_COLOR_SATURATION_MAX}, default {IDF_TARGET_SOC_ISP_COLOR_SATURATION_DEFAULT}
- Hue value should be 0 ~ {IDF_TARGET_SOC_ISP_COLOR_HUE_MAX}, default {IDF_TARGET_SOC_ISP_COLOR_HUE_DEFAULT}
- Brightness value should be -{IDF_TARGET_SOC_ISP_COLOR_BRIGHTNESS_MIN} ~ {IDF_TARGET_SOC_ISP_COLOR_BRIGHTNESS_MAX}, default {IDF_TARGET_SOC_ISP_COLOR_BRIGHTNESS_DEFAULT}
.. code:: c
esp_isp_color_config_t color_config = {
.color_contrast = {
.integer = 1,
.decimal = 0,
},
.color_saturation = {
.integer = 1,
.decimal = 0,
},
.color_hue = 0,
.color_brightness = 0,
};
ESP_ERROR_CHECK(esp_isp_color_configure(isp_proc, &color_config));
ESP_ERROR_CHECK(esp_isp_color_enable(isp_proc));
After calling :cpp:func:`esp_isp_color_configure`, you need to enable the ISP color processor, by calling :cpp:func:`esp_isp_color_enable`. This function:
* Switches the driver state from **init** to **enable**.
Calling :cpp:func:`esp_isp_color_disable` does the opposite, that is, put the driver back to the **init** state.
.. _isp-ccm-config:
Configure CCM
@ -752,7 +804,8 @@ API Reference
-------------
.. include-build-file:: inc/isp.inc
.. include-build-file:: inc/isp_types.inc
.. include-build-file:: inc/components/hal/include/hal/isp_types.inc
.. include-build-file:: inc/components/esp_driver_isp/include/driver/isp_types.inc
.. include-build-file:: inc/isp_af.inc
.. include-build-file:: inc/isp_ae.inc
.. include-build-file:: inc/isp_awb.inc
@ -762,3 +815,4 @@ API Reference
.. include-build-file:: inc/isp_sharpen.inc
.. include-build-file:: inc/isp_gamma.inc
.. include-build-file:: inc/isp_hist.inc
.. include-build-file:: inc/isp_color.inc

View File

@ -344,6 +344,21 @@ void app_main(void)
ESP_ERROR_CHECK(esp_isp_sharpen_configure(isp_proc, &sharpen_config));
ESP_ERROR_CHECK(esp_isp_sharpen_enable(isp_proc));
esp_isp_color_config_t color_config = {
.color_contrast = {
.integer = 1,
.decimal = 0,
},
.color_saturation = {
.integer = 1,
.decimal = 0,
},
.color_hue = 0,
.color_brightness = 0,
};
ESP_ERROR_CHECK(esp_isp_color_configure(isp_proc, &color_config));
ESP_ERROR_CHECK(esp_isp_color_enable(isp_proc));
typedef struct af_task_param_t {
isp_proc_handle_t isp_proc;
esp_sccb_io_handle_t dw9714_io_handle;