mirror of
https://github.com/espressif/esp-idf.git
synced 2026-04-27 19:13:21 +00:00
change(isp): make wbg standalone
This commit is contained in:
committed by
Armando (Dou Yiwen)
parent
cc72cf9953
commit
235d607671
@@ -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
|
||||
@@ -78,6 +78,7 @@ typedef struct isp_processor_t {
|
||||
isp_fsm_t color_fsm;
|
||||
isp_fsm_t lsc_fsm;
|
||||
isp_fsm_t blc_fsm;
|
||||
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
|
||||
---------------------------------------------------------------*/
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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");
|
||||
ESP_RETURN_ON_FALSE(isp_proc->wbg_fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "wbg is enabled already");
|
||||
|
||||
// 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");
|
||||
ESP_RETURN_ON_FALSE(isp_proc->wbg_fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "wbg is enabled already");
|
||||
|
||||
// Enable WBG module
|
||||
isp_ll_awb_enable_wb_gain(isp_proc->hal.hw, true);
|
||||
isp_proc->wbg_fsm = ISP_FSM_ENABLE;
|
||||
|
||||
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(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");
|
||||
ESP_RETURN_ON_FALSE(isp_proc->wbg_fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "wbg isn't enabled yet");
|
||||
|
||||
// Disable WBG module
|
||||
isp_ll_awb_enable_wb_gain(isp_proc->hal.hw, false);
|
||||
isp_proc->wbg_fsm = ISP_FSM_INIT;
|
||||
|
||||
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