mirror of
https://github.com/espressif/esp-idf.git
synced 2026-04-27 19:13:21 +00:00
Merge branch 'change/isp_wbg_api_change_v6.0' into 'release/v6.0'
isp: make wbg API standalone (v6.0) See merge request espressif/esp-idf!43164
This commit is contained in:
@@ -42,6 +42,10 @@ if(CONFIG_SOC_ISP_LSC_SUPPORTED)
|
||||
list(APPEND srcs "src/isp_lsc.c")
|
||||
endif()
|
||||
|
||||
if(CONFIG_SOC_ISP_WBG_SUPPORTED)
|
||||
list(APPEND srcs "src/isp_wbg.c")
|
||||
endif()
|
||||
|
||||
if(NOT ${target} STREQUAL "linux")
|
||||
list(APPEND requires esp_mm)
|
||||
endif()
|
||||
|
||||
@@ -24,3 +24,4 @@
|
||||
#include "driver/isp_hist.h"
|
||||
#include "driver/isp_lsc.h"
|
||||
#include "driver/isp_sharpen.h"
|
||||
#include "driver/isp_wbg.h"
|
||||
|
||||
@@ -164,18 +164,6 @@ esp_err_t esp_isp_awb_controller_start_continuous_statistics(isp_awb_ctlr_t awb_
|
||||
*/
|
||||
esp_err_t esp_isp_awb_controller_stop_continuous_statistics(isp_awb_ctlr_t awb_ctlr);
|
||||
|
||||
/**
|
||||
* @brief Set AWB white balance gain
|
||||
*
|
||||
* @param[in] awb_ctlr AWB controller handle
|
||||
* @param[in] gain AWB white balance gain
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG Null pointer
|
||||
* - ESP_ERR_INVALID_STATE Driver state is invalid.
|
||||
*/
|
||||
esp_err_t esp_isp_awb_controller_set_wb_gain(isp_awb_ctlr_t awb_ctlr, isp_awb_gain_t gain);
|
||||
|
||||
/**
|
||||
* @brief Event data of callbacks
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 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
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
WBG (White Balance Gain)
|
||||
---------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief ISP BLC configurations
|
||||
*/
|
||||
typedef struct {
|
||||
//for future proof
|
||||
} esp_isp_wbg_config_t;
|
||||
|
||||
/**
|
||||
* @brief ISP WBG configuration
|
||||
*
|
||||
* @note After calling this API, WBG doesn't take into effect until `esp_isp_wbg_enable` is called
|
||||
*
|
||||
* @param[in] isp_proc Processor handle
|
||||
* @param[in] config WBG configurations
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_STATE Not allowed to be called under current state
|
||||
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid
|
||||
* - ESP_ERR_NOT_SUPPORTED Not supported
|
||||
*/
|
||||
esp_err_t esp_isp_wbg_configure(isp_proc_handle_t isp_proc, const esp_isp_wbg_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Enable ISP WBG function
|
||||
*
|
||||
* @param[in] isp_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_wbg_enable(isp_proc_handle_t isp_proc);
|
||||
|
||||
/**
|
||||
* @brief Set AWB white balance gain
|
||||
*
|
||||
* @param[in] isp_proc Processor handle
|
||||
* @param[in] gain WBG white balance gain
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG Null pointer
|
||||
* - ESP_ERR_INVALID_STATE Driver state is invalid.
|
||||
*/
|
||||
esp_err_t esp_isp_wbg_set_wb_gain(isp_proc_handle_t isp_proc, isp_wbg_gain_t gain);
|
||||
|
||||
/**
|
||||
* @brief Disable ISP WBG function
|
||||
*
|
||||
* @param[in] isp_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_wbg_disable(isp_proc_handle_t isp_proc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -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
|
||||
*/
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <esp_types.h>
|
||||
#include <stdatomic.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_attr.h"
|
||||
#include "esp_log.h"
|
||||
@@ -27,8 +28,12 @@
|
||||
#include "soc/isp_periph.h"
|
||||
#endif
|
||||
|
||||
// Helper macros for atomic operations to ensure Clang compatibility
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#include <atomic>
|
||||
#define ISP_ATOMIC_TYPE(T) std::atomic<T>
|
||||
#else
|
||||
#define ISP_ATOMIC_TYPE(T) _Atomic T
|
||||
#endif
|
||||
|
||||
#if CONFIG_ISP_ISR_IRAM_SAFE || CONFIG_ISP_CTRL_FUNC_IN_IRAM
|
||||
@@ -39,6 +44,10 @@ extern "C" {
|
||||
#define ISP_MEM_ALLOC_CAPS MALLOC_CAP_DEFAULT
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
ISP_FSM_INIT, // Controller is initialized, but not enabled
|
||||
ISP_FSM_ENABLE, // Controller is enabled, but is not running
|
||||
@@ -59,7 +68,7 @@ typedef struct isp_processor_t {
|
||||
int csi_brg_id;
|
||||
void *csi_brg_hw;
|
||||
#endif
|
||||
isp_fsm_t isp_fsm;
|
||||
ISP_ATOMIC_TYPE(isp_fsm_t) isp_fsm;
|
||||
portMUX_TYPE spinlock;
|
||||
color_space_pixel_format_t in_color_format;
|
||||
color_space_pixel_format_t out_color_format;
|
||||
@@ -72,12 +81,15 @@ typedef struct isp_processor_t {
|
||||
isp_awb_ctlr_t awb_ctlr;
|
||||
isp_ae_ctlr_t ae_ctlr;
|
||||
isp_hist_ctlr_t hist_ctlr;
|
||||
isp_fsm_t bf_fsm;
|
||||
isp_fsm_t demosaic_fsm;
|
||||
isp_fsm_t sharpen_fsm;
|
||||
isp_fsm_t color_fsm;
|
||||
isp_fsm_t lsc_fsm;
|
||||
isp_fsm_t blc_fsm;
|
||||
ISP_ATOMIC_TYPE(isp_fsm_t) bf_fsm;
|
||||
ISP_ATOMIC_TYPE(isp_fsm_t) blc_fsm;
|
||||
ISP_ATOMIC_TYPE(isp_fsm_t) ccm_fsm;
|
||||
ISP_ATOMIC_TYPE(isp_fsm_t) color_fsm;
|
||||
ISP_ATOMIC_TYPE(isp_fsm_t) demosaic_fsm;
|
||||
ISP_ATOMIC_TYPE(isp_fsm_t) gamma_fsm;
|
||||
ISP_ATOMIC_TYPE(isp_fsm_t) lsc_fsm;
|
||||
ISP_ATOMIC_TYPE(isp_fsm_t) sharpen_fsm;
|
||||
ISP_ATOMIC_TYPE(isp_fsm_t) wbg_fsm;
|
||||
esp_isp_evt_cbs_t cbs;
|
||||
void *user_data;
|
||||
|
||||
|
||||
@@ -111,10 +111,6 @@ esp_err_t esp_isp_new_awb_controller(isp_proc_handle_t isp_proc, const esp_isp_a
|
||||
isp_ll_awb_enable(isp_proc->hal.hw, false);
|
||||
isp_ll_awb_set_clk_ctrl_mode(isp_proc->hal.hw, ISP_LL_PIPELINE_CLK_CTRL_AUTO);
|
||||
isp_ll_awb_enable_algorithm_mode(isp_proc->hal.hw, true);
|
||||
#if !CONFIG_ESP32P4_SELECTS_REV_LESS_V3
|
||||
isp_ll_awb_set_wb_gain_clk_ctrl_mode(isp_proc->hal.hw, ISP_LL_PIPELINE_CLK_CTRL_AUTO);
|
||||
isp_ll_awb_enable_wb_gain(isp_proc->hal.hw, true);
|
||||
#endif
|
||||
ESP_GOTO_ON_ERROR(s_esp_isp_awb_config_hardware(isp_proc, awb_cfg), err2, TAG, "configure awb hardware failed");
|
||||
|
||||
*ret_hdl = awb_ctlr;
|
||||
@@ -139,9 +135,6 @@ esp_err_t esp_isp_del_awb_controller(isp_awb_ctlr_t awb_ctlr)
|
||||
s_isp_declaim_awb_controller(awb_ctlr);
|
||||
|
||||
isp_ll_awb_enable_algorithm_mode(awb_ctlr->isp_proc->hal.hw, false);
|
||||
#if !CONFIG_ESP32P4_SELECTS_REV_LESS_V3
|
||||
isp_ll_awb_enable_wb_gain(awb_ctlr->isp_proc->hal.hw, false);
|
||||
#endif
|
||||
s_isp_awb_free_controller(awb_ctlr);
|
||||
|
||||
return ESP_OK;
|
||||
@@ -228,17 +221,6 @@ esp_err_t esp_isp_awb_controller_stop_continuous_statistics(isp_awb_ctlr_t awb_c
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
#if !CONFIG_ESP32P4_SELECTS_REV_LESS_V3
|
||||
esp_err_t esp_isp_awb_controller_set_wb_gain(isp_awb_ctlr_t awb_ctlr, isp_awb_gain_t gain)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(awb_ctlr, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||
ESP_RETURN_ON_FALSE(atomic_load(&awb_ctlr->fsm) != ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "controller not in init state");
|
||||
isp_ll_awb_set_wb_gain(awb_ctlr->isp_proc->hal.hw, gain);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
#endif //#if !CONFIG_ESP32P4_SELECTS_REV_LESS_V3
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
INTR
|
||||
---------------------------------------------------------------*/
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
@@ -49,10 +49,10 @@ esp_err_t esp_isp_bf_configure(isp_proc_handle_t proc, const esp_isp_bf_config_t
|
||||
esp_err_t esp_isp_bf_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->bf_fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "bf is enabled already");
|
||||
isp_fsm_t expected_fsm = ISP_FSM_INIT;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&proc->bf_fsm, &expected_fsm, ISP_FSM_ENABLE), ESP_ERR_INVALID_STATE, TAG, "bf is enabled already");
|
||||
|
||||
isp_ll_bf_enable(proc->hal.hw, true);
|
||||
proc->bf_fsm = ISP_FSM_ENABLE;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -60,10 +60,10 @@ esp_err_t esp_isp_bf_enable(isp_proc_handle_t proc)
|
||||
esp_err_t esp_isp_bf_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->bf_fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "bf isn't enabled yet");
|
||||
isp_fsm_t expected_fsm = ISP_FSM_ENABLE;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&proc->bf_fsm, &expected_fsm, ISP_FSM_INIT), ESP_ERR_INVALID_STATE, TAG, "bf isn't enabled yet");
|
||||
|
||||
isp_ll_bf_enable(proc->hal.hw, false);
|
||||
proc->bf_fsm = ISP_FSM_INIT;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -64,11 +64,11 @@ esp_err_t esp_isp_blc_configure(isp_proc_handle_t isp_proc, const esp_isp_blc_co
|
||||
esp_err_t esp_isp_blc_enable(isp_proc_handle_t isp_proc)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||
ESP_RETURN_ON_FALSE(isp_proc->blc_fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "blc is enabled already");
|
||||
isp_fsm_t expected_fsm = ISP_FSM_INIT;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&isp_proc->blc_fsm, &expected_fsm, ISP_FSM_ENABLE), ESP_ERR_INVALID_STATE, TAG, "blc is enabled already");
|
||||
|
||||
// Enable BLC module
|
||||
isp_ll_blc_enable(isp_proc->hal.hw, true);
|
||||
isp_proc->blc_fsm = ISP_FSM_ENABLE;
|
||||
|
||||
ESP_LOGD(TAG, "BLC enabled");
|
||||
return ESP_OK;
|
||||
@@ -77,7 +77,7 @@ esp_err_t esp_isp_blc_enable(isp_proc_handle_t isp_proc)
|
||||
esp_err_t esp_isp_blc_set_correction_offset(isp_proc_handle_t isp_proc, esp_isp_blc_offset_t *offset)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(isp_proc && offset, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||
ESP_RETURN_ON_FALSE(isp_proc->blc_fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "blc isn't enabled yet");
|
||||
ESP_RETURN_ON_FALSE(atomic_load(&isp_proc->blc_fsm) == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "blc isn't enabled yet");
|
||||
|
||||
// Set correction offset for each channel
|
||||
isp_ll_blc_set_correction_offset(isp_proc->hal.hw, offset->top_left_chan_offset, offset->top_right_chan_offset, offset->bottom_left_chan_offset, offset->bottom_right_chan_offset);
|
||||
@@ -92,11 +92,11 @@ esp_err_t esp_isp_blc_set_correction_offset(isp_proc_handle_t isp_proc, esp_isp_
|
||||
esp_err_t esp_isp_blc_disable(isp_proc_handle_t isp_proc)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||
ESP_RETURN_ON_FALSE(isp_proc->blc_fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "blc isn't enabled yet");
|
||||
isp_fsm_t expected_fsm = ISP_FSM_ENABLE;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&isp_proc->blc_fsm, &expected_fsm, ISP_FSM_INIT), ESP_ERR_INVALID_STATE, TAG, "blc isn't enabled yet");
|
||||
|
||||
// Disable BLC module
|
||||
isp_ll_blc_enable(isp_proc->hal.hw, false);
|
||||
isp_proc->blc_fsm = ISP_FSM_INIT;
|
||||
|
||||
ESP_LOGD(TAG, "BLC disabled");
|
||||
return ESP_OK;
|
||||
|
||||
@@ -45,6 +45,8 @@ esp_err_t esp_isp_ccm_configure(isp_proc_handle_t proc, const esp_isp_ccm_config
|
||||
esp_err_t esp_isp_ccm_enable(isp_proc_handle_t proc)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||
isp_fsm_t expected_fsm = ISP_FSM_INIT;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&proc->ccm_fsm, &expected_fsm, ISP_FSM_ENABLE), ESP_ERR_INVALID_STATE, TAG, "ccm is enabled already");
|
||||
|
||||
portENTER_CRITICAL(&proc->spinlock);
|
||||
isp_ll_ccm_enable(proc->hal.hw, true);
|
||||
@@ -56,6 +58,8 @@ esp_err_t esp_isp_ccm_enable(isp_proc_handle_t proc)
|
||||
esp_err_t esp_isp_ccm_disable(isp_proc_handle_t proc)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||
isp_fsm_t expected_fsm = ISP_FSM_ENABLE;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&proc->ccm_fsm, &expected_fsm, ISP_FSM_INIT), ESP_ERR_INVALID_STATE, TAG, "ccm isn't enabled yet");
|
||||
|
||||
portENTER_CRITICAL(&proc->spinlock);
|
||||
isp_ll_ccm_enable(proc->hal.hw, false);
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
@@ -49,10 +49,10 @@ esp_err_t esp_isp_color_configure(isp_proc_handle_t proc, const esp_isp_color_co
|
||||
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_fsm_t expected_fsm = ISP_FSM_INIT;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&proc->color_fsm, &expected_fsm, ISP_FSM_ENABLE), ESP_ERR_INVALID_STATE, TAG, "color is enabled already");
|
||||
|
||||
isp_ll_color_enable(proc->hal.hw, true);
|
||||
proc->color_fsm = ISP_FSM_ENABLE;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -60,10 +60,10 @@ esp_err_t esp_isp_color_enable(isp_proc_handle_t proc)
|
||||
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_fsm_t expected_fsm = ISP_FSM_ENABLE;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&proc->color_fsm, &expected_fsm, ISP_FSM_INIT), ESP_ERR_INVALID_STATE, TAG, "color isn't enabled yet");
|
||||
|
||||
isp_ll_color_enable(proc->hal.hw, false);
|
||||
proc->color_fsm = ISP_FSM_INIT;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -119,7 +119,16 @@ esp_err_t esp_isp_new_processor(const esp_isp_processor_cfg_t *proc_config, isp_
|
||||
isp_ll_set_clock_div(proc->hal.hw, &clk_div);
|
||||
}
|
||||
proc->clk_src = clk_src;
|
||||
proc->isp_fsm = ISP_FSM_INIT;
|
||||
atomic_init(&proc->isp_fsm, ISP_FSM_INIT);
|
||||
atomic_init(&proc->bf_fsm, ISP_FSM_INIT);
|
||||
atomic_init(&proc->blc_fsm, ISP_FSM_INIT);
|
||||
atomic_init(&proc->ccm_fsm, ISP_FSM_INIT);
|
||||
atomic_init(&proc->color_fsm, ISP_FSM_INIT);
|
||||
atomic_init(&proc->demosaic_fsm, ISP_FSM_INIT);
|
||||
atomic_init(&proc->gamma_fsm, ISP_FSM_INIT);
|
||||
atomic_init(&proc->lsc_fsm, ISP_FSM_INIT);
|
||||
atomic_init(&proc->sharpen_fsm, ISP_FSM_INIT);
|
||||
atomic_init(&proc->wbg_fsm, ISP_FSM_INIT);
|
||||
proc->spinlock = (portMUX_TYPE)portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
//Input & Output color format
|
||||
@@ -189,7 +198,7 @@ err:
|
||||
esp_err_t esp_isp_del_processor(isp_proc_handle_t proc)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||
ESP_RETURN_ON_FALSE(proc->isp_fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "processor isn't in init state");
|
||||
ESP_RETURN_ON_FALSE(atomic_load(&proc->isp_fsm) == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "processor isn't in init state");
|
||||
|
||||
//declaim first, then do free
|
||||
ESP_RETURN_ON_ERROR(s_isp_declaim_processor(proc), TAG, "declaim processor fail");
|
||||
@@ -205,7 +214,7 @@ esp_err_t esp_isp_del_processor(isp_proc_handle_t proc)
|
||||
esp_err_t esp_isp_register_event_callbacks(isp_proc_handle_t proc, const esp_isp_evt_cbs_t *cbs, void *user_data)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(proc && cbs, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||
ESP_RETURN_ON_FALSE(proc->isp_fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "processor isn't in the init state");
|
||||
ESP_RETURN_ON_FALSE(atomic_load(&proc->isp_fsm) == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "processor isn't in the init state");
|
||||
|
||||
#if CONFIG_ISP_ISR_IRAM_SAFE
|
||||
if (cbs->on_sharpen_frame_done) {
|
||||
@@ -230,11 +239,11 @@ esp_err_t esp_isp_register_event_callbacks(isp_proc_handle_t proc, const esp_isp
|
||||
esp_err_t esp_isp_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->isp_fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "processor isn't in init state");
|
||||
isp_fsm_t expected_fsm = ISP_FSM_INIT;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&proc->isp_fsm, &expected_fsm, ISP_FSM_ENABLE), ESP_ERR_INVALID_STATE, TAG, "processor isn't in init state");
|
||||
ESP_RETURN_ON_FALSE(proc->bypass_isp == false, ESP_ERR_INVALID_STATE, TAG, "processor is configured to be bypassed");
|
||||
|
||||
isp_ll_enable(proc->hal.hw, true);
|
||||
proc->isp_fsm = ISP_FSM_ENABLE;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -242,10 +251,10 @@ esp_err_t esp_isp_enable(isp_proc_handle_t proc)
|
||||
esp_err_t esp_isp_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->isp_fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "processor isn't in enable state");
|
||||
isp_fsm_t expected_fsm = ISP_FSM_ENABLE;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&proc->isp_fsm, &expected_fsm, ISP_FSM_INIT), ESP_ERR_INVALID_STATE, TAG, "processor isn't in enable state");
|
||||
|
||||
isp_ll_enable(proc->hal.hw, false);
|
||||
proc->isp_fsm = ISP_FSM_INIT;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
@@ -46,10 +46,10 @@ esp_err_t esp_isp_demosaic_configure(isp_proc_handle_t proc, const esp_isp_demos
|
||||
esp_err_t esp_isp_demosaic_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->demosaic_fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "demosaic is enabled already");
|
||||
isp_fsm_t expected_fsm = ISP_FSM_INIT;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&proc->demosaic_fsm, &expected_fsm, ISP_FSM_ENABLE), ESP_ERR_INVALID_STATE, TAG, "demosaic is enabled already");
|
||||
|
||||
isp_ll_demosaic_enable(proc->hal.hw, true);
|
||||
proc->demosaic_fsm = ISP_FSM_ENABLE;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -57,13 +57,13 @@ esp_err_t esp_isp_demosaic_enable(isp_proc_handle_t proc)
|
||||
esp_err_t esp_isp_demosaic_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->demosaic_fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "demosaic isn't enabled yet");
|
||||
isp_fsm_t expected_fsm = ISP_FSM_ENABLE;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&proc->demosaic_fsm, &expected_fsm, ISP_FSM_INIT), ESP_ERR_INVALID_STATE, TAG, "demosaic isn't enabled yet");
|
||||
|
||||
if (proc->out_color_format.color_space == (uint32_t)COLOR_SPACE_RAW) {
|
||||
// for other out_color_format, demosaic module is needed for rgb interpolation algorithm
|
||||
isp_ll_demosaic_enable(proc->hal.hw, false);
|
||||
}
|
||||
proc->demosaic_fsm = ISP_FSM_INIT;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -58,6 +58,8 @@ esp_err_t esp_isp_gamma_configure(isp_proc_handle_t proc, color_component_t comp
|
||||
esp_err_t esp_isp_gamma_enable(isp_proc_handle_t proc)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||
isp_fsm_t expected_fsm = ISP_FSM_INIT;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&proc->gamma_fsm, &expected_fsm, ISP_FSM_ENABLE), ESP_ERR_INVALID_STATE, TAG, "gamma is enabled already");
|
||||
|
||||
portENTER_CRITICAL(&proc->spinlock);
|
||||
isp_ll_gamma_enable(proc->hal.hw, true);
|
||||
@@ -69,6 +71,8 @@ esp_err_t esp_isp_gamma_enable(isp_proc_handle_t proc)
|
||||
esp_err_t esp_isp_gamma_disable(isp_proc_handle_t proc)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||
isp_fsm_t expected_fsm = ISP_FSM_ENABLE;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&proc->gamma_fsm, &expected_fsm, ISP_FSM_INIT), ESP_ERR_INVALID_STATE, TAG, "gamma is disabled already");
|
||||
|
||||
portENTER_CRITICAL(&proc->spinlock);
|
||||
isp_ll_gamma_enable(proc->hal.hw, false);
|
||||
|
||||
@@ -28,7 +28,7 @@ static const char *TAG = "ISP_LSC";
|
||||
esp_err_t esp_isp_lsc_allocate_gain_array(isp_proc_handle_t isp_proc, esp_isp_lsc_gain_array_t *gain_array, size_t *out_array_size_per_channel)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(isp_proc && gain_array && out_array_size_per_channel, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||
ESP_RETURN_ON_FALSE(isp_proc->lsc_fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "lsc is enabled already");
|
||||
ESP_RETURN_ON_FALSE(atomic_load(&isp_proc->lsc_fsm) == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "lsc is enabled already");
|
||||
|
||||
int num_grids_x_max = ISP_LSC_GET_GRIDS(ISP_LL_HSIZE_MAX);
|
||||
int num_grids_y_max = ISP_LSC_GET_GRIDS(ISP_LL_VSIZE_MAX);
|
||||
@@ -89,10 +89,10 @@ esp_err_t esp_isp_lsc_configure(isp_proc_handle_t isp_proc, const esp_isp_lsc_co
|
||||
esp_err_t esp_isp_lsc_enable(isp_proc_handle_t isp_proc)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||
ESP_RETURN_ON_FALSE(isp_proc->lsc_fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "lsc is enabled already");
|
||||
isp_fsm_t expected_fsm = ISP_FSM_INIT;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&isp_proc->lsc_fsm, &expected_fsm, ISP_FSM_ENABLE), ESP_ERR_INVALID_STATE, TAG, "lsc is enabled already");
|
||||
|
||||
isp_ll_lsc_enable(isp_proc->hal.hw, true);
|
||||
isp_proc->lsc_fsm = ISP_FSM_ENABLE;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -100,10 +100,10 @@ esp_err_t esp_isp_lsc_enable(isp_proc_handle_t isp_proc)
|
||||
esp_err_t esp_isp_lsc_disable(isp_proc_handle_t isp_proc)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||
ESP_RETURN_ON_FALSE(isp_proc->lsc_fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "lsc isn't enabled yet");
|
||||
isp_fsm_t expected_fsm = ISP_FSM_ENABLE;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&isp_proc->lsc_fsm, &expected_fsm, ISP_FSM_INIT), ESP_ERR_INVALID_STATE, TAG, "lsc isn't enabled yet");
|
||||
|
||||
isp_ll_lsc_enable(isp_proc->hal.hw, false);
|
||||
isp_proc->lsc_fsm = ISP_FSM_INIT;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
@@ -51,11 +51,11 @@ esp_err_t esp_isp_sharpen_configure(isp_proc_handle_t proc, const esp_isp_sharpe
|
||||
esp_err_t esp_isp_sharpen_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->sharpen_fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "sharpen is enabled already");
|
||||
isp_fsm_t expected_fsm = ISP_FSM_INIT;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&proc->sharpen_fsm, &expected_fsm, ISP_FSM_ENABLE), ESP_ERR_INVALID_STATE, TAG, "sharpen is enabled already");
|
||||
|
||||
isp_ll_enable_intr(proc->hal.hw, ISP_LL_EVENT_SHARP_FRAME, true);
|
||||
isp_ll_sharp_enable(proc->hal.hw, true);
|
||||
proc->sharpen_fsm = ISP_FSM_ENABLE;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -63,11 +63,11 @@ esp_err_t esp_isp_sharpen_enable(isp_proc_handle_t proc)
|
||||
esp_err_t esp_isp_sharpen_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->sharpen_fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "sharpen isn't enabled yet");
|
||||
isp_fsm_t expected_fsm = ISP_FSM_ENABLE;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&proc->sharpen_fsm, &expected_fsm, ISP_FSM_INIT), ESP_ERR_INVALID_STATE, TAG, "sharpen isn't enabled yet");
|
||||
|
||||
isp_ll_sharp_enable(proc->hal.hw, false);
|
||||
isp_ll_enable_intr(proc->hal.hw, ISP_LL_EVENT_SHARP_FRAME, false);
|
||||
proc->sharpen_fsm = ISP_FSM_INIT;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdatomic.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "driver/isp_core.h"
|
||||
#include "driver/isp_wbg.h"
|
||||
#include "esp_private/isp_private.h"
|
||||
#include "hal/efuse_hal.h"
|
||||
#include "soc/chip_revision.h"
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
WBG
|
||||
---------------------------------------------------------------*/
|
||||
|
||||
static const char *TAG = "ISP_WBG";
|
||||
|
||||
esp_err_t esp_isp_wbg_configure(isp_proc_handle_t isp_proc, const esp_isp_wbg_config_t *config)
|
||||
{
|
||||
#if CONFIG_IDF_TARGET_ESP32P4
|
||||
unsigned chip_version = efuse_hal_chip_revision();
|
||||
if (!ESP_CHIP_REV_ABOVE(chip_version, 300)) {
|
||||
ESP_RETURN_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, TAG, "WBG is not supported on ESP32P4 chips prior than v3.0");
|
||||
}
|
||||
#endif
|
||||
|
||||
ESP_RETURN_ON_FALSE(isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||
|
||||
// Configure clock control mode
|
||||
isp_ll_awb_set_wb_gain_clk_ctrl_mode(isp_proc->hal.hw, ISP_LL_PIPELINE_CLK_CTRL_AUTO);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_isp_wbg_enable(isp_proc_handle_t isp_proc)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||
isp_fsm_t expected_fsm = ISP_FSM_INIT;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&isp_proc->wbg_fsm, &expected_fsm, ISP_FSM_ENABLE), ESP_ERR_INVALID_STATE, TAG, "wbg is enabled already");
|
||||
|
||||
// Enable WBG module
|
||||
isp_ll_awb_enable_wb_gain(isp_proc->hal.hw, true);
|
||||
|
||||
ESP_LOGD(TAG, "WBG enabled");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_isp_wbg_set_wb_gain(isp_proc_handle_t isp_proc, isp_wbg_gain_t gain)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||
ESP_RETURN_ON_FALSE(atomic_load(&isp_proc->wbg_fsm) == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "wbg isn't enabled yet");
|
||||
|
||||
// Set WBG gain
|
||||
isp_ll_awb_set_wb_gain(isp_proc->hal.hw, gain);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_isp_wbg_disable(isp_proc_handle_t isp_proc)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||
isp_fsm_t expected_fsm = ISP_FSM_ENABLE;
|
||||
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&isp_proc->wbg_fsm, &expected_fsm, ISP_FSM_INIT), ESP_ERR_INVALID_STATE, TAG, "wbg isn't enabled yet");
|
||||
|
||||
// Disable WBG module
|
||||
isp_ll_awb_enable_wb_gain(isp_proc->hal.hw, false);
|
||||
|
||||
ESP_LOGD(TAG, "WBG disabled");
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -1742,14 +1742,29 @@ static inline void isp_ll_awb_set_wb_gain_clk_ctrl_mode(isp_dev_t *hw, isp_ll_pi
|
||||
* @brief Set AWB white balance gain
|
||||
*
|
||||
* @param[in] hw Hardware instance address
|
||||
* @param[in] gain AWB white balance gain
|
||||
* @param[in] gain WBG white balance gain
|
||||
*/
|
||||
static inline void isp_ll_awb_set_wb_gain(isp_dev_t *hw, isp_awb_gain_t gain)
|
||||
static inline void isp_ll_awb_set_wb_gain(isp_dev_t *hw, isp_wbg_gain_t gain)
|
||||
{
|
||||
hw->wbg_coef_r.wbg_r = gain.gain_r;
|
||||
hw->wbg_coef_g.wbg_g = gain.gain_g;
|
||||
hw->wbg_coef_b.wbg_b = gain.gain_b;
|
||||
}
|
||||
#else
|
||||
static inline void isp_ll_awb_enable_wb_gain(isp_dev_t *hw, bool enable)
|
||||
{
|
||||
//for compatibility
|
||||
}
|
||||
|
||||
static inline void isp_ll_awb_set_wb_gain_clk_ctrl_mode(isp_dev_t *hw, isp_ll_pipeline_clk_ctrl_t mode)
|
||||
{
|
||||
//for compatibility
|
||||
}
|
||||
|
||||
static inline void isp_ll_awb_set_wb_gain(isp_dev_t *hw, isp_wbg_gain_t gain)
|
||||
{
|
||||
//for compatibility
|
||||
}
|
||||
#endif //#if HAL_CONFIG(CHIP_SUPPORT_MIN_REV) >= 300
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
|
||||
@@ -435,6 +435,18 @@ typedef union {
|
||||
uint32_t val; ///< 32-bit gradient ratio value
|
||||
} isp_lsc_gain_t;
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
WBG (White Balance Gain)
|
||||
---------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief ISP White Balance Gain
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t gain_r; ///< White balance gain for R channel
|
||||
uint32_t gain_g; ///< White balance gain for G channel
|
||||
uint32_t gain_b; ///< White balance gain for B channel
|
||||
} isp_wbg_gain_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -919,6 +919,10 @@ config SOC_ISP_SHARPEN_SUPPORTED
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_ISP_WBG_SUPPORTED
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_ISP_SHARE_CSI_BRG
|
||||
bool
|
||||
default y
|
||||
|
||||
@@ -353,6 +353,7 @@
|
||||
#define SOC_ISP_DVP_SUPPORTED 1
|
||||
#define SOC_ISP_LSC_SUPPORTED 1
|
||||
#define SOC_ISP_SHARPEN_SUPPORTED 1
|
||||
#define SOC_ISP_WBG_SUPPORTED 1
|
||||
#define SOC_ISP_SHARE_CSI_BRG 1
|
||||
|
||||
#define SOC_ISP_NUMS 1U
|
||||
|
||||
Reference in New Issue
Block a user