Skip to content

Commit 703da8c

Browse files
committed
change(isp): make wbg standalone
1 parent 4cd8373 commit 703da8c

File tree

11 files changed

+200
-32
lines changed

11 files changed

+200
-32
lines changed

components/esp_driver_isp/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ if(CONFIG_SOC_ISP_LSC_SUPPORTED)
4242
list(APPEND srcs "src/isp_lsc.c")
4343
endif()
4444

45+
if(CONFIG_SOC_ISP_WBG_SUPPORTED)
46+
list(APPEND srcs "src/isp_wbg.c")
47+
endif()
48+
4549
if(NOT ${target} STREQUAL "linux")
4650
list(APPEND requires esp_mm)
4751
endif()

components/esp_driver_isp/include/driver/isp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@
2424
#include "driver/isp_hist.h"
2525
#include "driver/isp_lsc.h"
2626
#include "driver/isp_sharpen.h"
27+
#include "driver/isp_wbg.h"

components/esp_driver_isp/include/driver/isp_awb.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,6 @@ esp_err_t esp_isp_awb_controller_start_continuous_statistics(isp_awb_ctlr_t awb_
164164
*/
165165
esp_err_t esp_isp_awb_controller_stop_continuous_statistics(isp_awb_ctlr_t awb_ctlr);
166166

167-
/**
168-
* @brief Set AWB white balance gain
169-
*
170-
* @param[in] awb_ctlr AWB controller handle
171-
* @param[in] gain AWB white balance gain
172-
* @return
173-
* - ESP_OK On success
174-
* - ESP_ERR_INVALID_ARG Null pointer
175-
* - ESP_ERR_INVALID_STATE Driver state is invalid.
176-
*/
177-
esp_err_t esp_isp_awb_controller_set_wb_gain(isp_awb_ctlr_t awb_ctlr, isp_awb_gain_t gain);
178-
179167
/**
180168
* @brief Event data of callbacks
181169
*/
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include <stdint.h>
10+
#include "esp_err.h"
11+
#include "driver/isp_types.h"
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
/*---------------------------------------------------------------
18+
WBG (White Balance Gain)
19+
---------------------------------------------------------------*/
20+
/**
21+
* @brief ISP BLC configurations
22+
*/
23+
typedef struct {
24+
//for future proof
25+
} esp_isp_wbg_config_t;
26+
27+
/**
28+
* @brief ISP WBG configuration
29+
*
30+
* @note After calling this API, WBG doesn't take into effect until `esp_isp_wbg_enable` is called
31+
*
32+
* @param[in] isp_proc Processor handle
33+
* @param[in] config WBG configurations
34+
*
35+
* @return
36+
* - ESP_OK On success
37+
* - ESP_ERR_INVALID_STATE Not allowed to be called under current state
38+
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid
39+
* - ESP_ERR_NOT_SUPPORTED Not supported
40+
*/
41+
esp_err_t esp_isp_wbg_configure(isp_proc_handle_t isp_proc, const esp_isp_wbg_config_t *config);
42+
43+
/**
44+
* @brief Enable ISP WBG function
45+
*
46+
* @param[in] isp_proc Processor handle
47+
*
48+
* @return
49+
* - ESP_OK On success
50+
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
51+
* - ESP_ERR_INVALID_STATE Driver state is invalid.
52+
*/
53+
esp_err_t esp_isp_wbg_enable(isp_proc_handle_t isp_proc);
54+
55+
/**
56+
* @brief Set AWB white balance gain
57+
*
58+
* @param[in] isp_proc Processor handle
59+
* @param[in] gain WBG white balance gain
60+
* @return
61+
* - ESP_OK On success
62+
* - ESP_ERR_INVALID_ARG Null pointer
63+
* - ESP_ERR_INVALID_STATE Driver state is invalid.
64+
*/
65+
esp_err_t esp_isp_wbg_set_wb_gain(isp_proc_handle_t isp_proc, isp_wbg_gain_t gain);
66+
67+
/**
68+
* @brief Disable ISP WBG function
69+
*
70+
* @param[in] isp_proc Processor handle
71+
*
72+
* @return
73+
* - ESP_OK On success
74+
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
75+
* - ESP_ERR_INVALID_STATE Driver state is invalid.
76+
*/
77+
esp_err_t esp_isp_wbg_disable(isp_proc_handle_t isp_proc);
78+
79+
#ifdef __cplusplus
80+
}
81+
#endif

components/esp_driver_isp/include/esp_private/isp_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ typedef struct isp_processor_t {
7878
isp_fsm_t color_fsm;
7979
isp_fsm_t lsc_fsm;
8080
isp_fsm_t blc_fsm;
81+
isp_fsm_t wbg_fsm;
8182
esp_isp_evt_cbs_t cbs;
8283
void *user_data;
8384

components/esp_driver_isp/src/isp_awb.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ esp_err_t esp_isp_new_awb_controller(isp_proc_handle_t isp_proc, const esp_isp_a
111111
isp_ll_awb_enable(isp_proc->hal.hw, false);
112112
isp_ll_awb_set_clk_ctrl_mode(isp_proc->hal.hw, ISP_LL_PIPELINE_CLK_CTRL_AUTO);
113113
isp_ll_awb_enable_algorithm_mode(isp_proc->hal.hw, true);
114-
#if !CONFIG_ESP32P4_SELECTS_REV_LESS_V3
115-
isp_ll_awb_set_wb_gain_clk_ctrl_mode(isp_proc->hal.hw, ISP_LL_PIPELINE_CLK_CTRL_AUTO);
116-
isp_ll_awb_enable_wb_gain(isp_proc->hal.hw, true);
117-
#endif
118114
ESP_GOTO_ON_ERROR(s_esp_isp_awb_config_hardware(isp_proc, awb_cfg), err2, TAG, "configure awb hardware failed");
119115

120116
*ret_hdl = awb_ctlr;
@@ -139,9 +135,6 @@ esp_err_t esp_isp_del_awb_controller(isp_awb_ctlr_t awb_ctlr)
139135
s_isp_declaim_awb_controller(awb_ctlr);
140136

141137
isp_ll_awb_enable_algorithm_mode(awb_ctlr->isp_proc->hal.hw, false);
142-
#if !CONFIG_ESP32P4_SELECTS_REV_LESS_V3
143-
isp_ll_awb_enable_wb_gain(awb_ctlr->isp_proc->hal.hw, false);
144-
#endif
145138
s_isp_awb_free_controller(awb_ctlr);
146139

147140
return ESP_OK;
@@ -228,17 +221,6 @@ esp_err_t esp_isp_awb_controller_stop_continuous_statistics(isp_awb_ctlr_t awb_c
228221
return ESP_OK;
229222
}
230223

231-
#if !CONFIG_ESP32P4_SELECTS_REV_LESS_V3
232-
esp_err_t esp_isp_awb_controller_set_wb_gain(isp_awb_ctlr_t awb_ctlr, isp_awb_gain_t gain)
233-
{
234-
ESP_RETURN_ON_FALSE(awb_ctlr, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
235-
ESP_RETURN_ON_FALSE(atomic_load(&awb_ctlr->fsm) != ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "controller not in init state");
236-
isp_ll_awb_set_wb_gain(awb_ctlr->isp_proc->hal.hw, gain);
237-
238-
return ESP_OK;
239-
}
240-
#endif //#if !CONFIG_ESP32P4_SELECTS_REV_LESS_V3
241-
242224
/*---------------------------------------------------------------
243225
INTR
244226
---------------------------------------------------------------*/
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <stdio.h>
7+
#include <stdlib.h>
8+
#include <string.h>
9+
#include <stdatomic.h>
10+
#include "sdkconfig.h"
11+
#include "esp_log.h"
12+
#include "esp_check.h"
13+
#include "freertos/FreeRTOS.h"
14+
#include "driver/isp_core.h"
15+
#include "driver/isp_wbg.h"
16+
#include "esp_private/isp_private.h"
17+
#include "hal/efuse_hal.h"
18+
#include "soc/chip_revision.h"
19+
20+
/*---------------------------------------------------------------
21+
WBG
22+
---------------------------------------------------------------*/
23+
24+
static const char *TAG = "ISP_WBG";
25+
26+
esp_err_t esp_isp_wbg_configure(isp_proc_handle_t isp_proc, const esp_isp_wbg_config_t *config)
27+
{
28+
#if CONFIG_IDF_TARGET_ESP32P4
29+
unsigned chip_version = efuse_hal_chip_revision();
30+
if (!ESP_CHIP_REV_ABOVE(chip_version, 300)) {
31+
ESP_RETURN_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, TAG, "WBG is not supported on ESP32P4 chips prior than v3.0");
32+
}
33+
#endif
34+
35+
ESP_RETURN_ON_FALSE(isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
36+
ESP_RETURN_ON_FALSE(isp_proc->wbg_fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "wbg is enabled already");
37+
38+
// Configure clock control mode
39+
isp_ll_awb_set_wb_gain_clk_ctrl_mode(isp_proc->hal.hw, ISP_LL_PIPELINE_CLK_CTRL_AUTO);
40+
41+
return ESP_OK;
42+
}
43+
44+
esp_err_t esp_isp_wbg_enable(isp_proc_handle_t isp_proc)
45+
{
46+
ESP_RETURN_ON_FALSE(isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
47+
ESP_RETURN_ON_FALSE(isp_proc->wbg_fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "wbg is enabled already");
48+
49+
// Enable WBG module
50+
isp_ll_awb_enable_wb_gain(isp_proc->hal.hw, true);
51+
isp_proc->wbg_fsm = ISP_FSM_ENABLE;
52+
53+
ESP_LOGD(TAG, "WBG enabled");
54+
return ESP_OK;
55+
}
56+
57+
esp_err_t esp_isp_wbg_set_wb_gain(isp_proc_handle_t isp_proc, isp_wbg_gain_t gain)
58+
{
59+
ESP_RETURN_ON_FALSE(isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
60+
ESP_RETURN_ON_FALSE(isp_proc->wbg_fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "wbg isn't enabled yet");
61+
62+
// Set WBG gain
63+
isp_ll_awb_set_wb_gain(isp_proc->hal.hw, gain);
64+
65+
return ESP_OK;
66+
}
67+
68+
esp_err_t esp_isp_wbg_disable(isp_proc_handle_t isp_proc)
69+
{
70+
ESP_RETURN_ON_FALSE(isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
71+
ESP_RETURN_ON_FALSE(isp_proc->wbg_fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "wbg isn't enabled yet");
72+
73+
// Disable WBG module
74+
isp_ll_awb_enable_wb_gain(isp_proc->hal.hw, false);
75+
isp_proc->wbg_fsm = ISP_FSM_INIT;
76+
77+
ESP_LOGD(TAG, "WBG disabled");
78+
return ESP_OK;
79+
}

components/hal/esp32p4/include/hal/isp_ll.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,14 +1720,29 @@ static inline void isp_ll_awb_set_wb_gain_clk_ctrl_mode(isp_dev_t *hw, isp_ll_pi
17201720
* @brief Set AWB white balance gain
17211721
*
17221722
* @param[in] hw Hardware instance address
1723-
* @param[in] gain AWB white balance gain
1723+
* @param[in] gain WBG white balance gain
17241724
*/
1725-
static inline void isp_ll_awb_set_wb_gain(isp_dev_t *hw, isp_awb_gain_t gain)
1725+
static inline void isp_ll_awb_set_wb_gain(isp_dev_t *hw, isp_wbg_gain_t gain)
17261726
{
17271727
hw->wbg_coef_r.wbg_r = gain.gain_r;
17281728
hw->wbg_coef_g.wbg_g = gain.gain_g;
17291729
hw->wbg_coef_b.wbg_b = gain.gain_b;
17301730
}
1731+
#else
1732+
static inline void isp_ll_awb_enable_wb_gain(isp_dev_t *hw, bool enable)
1733+
{
1734+
//for compatibility
1735+
}
1736+
1737+
static inline void isp_ll_awb_set_wb_gain_clk_ctrl_mode(isp_dev_t *hw, isp_ll_pipeline_clk_ctrl_t mode)
1738+
{
1739+
//for compatibility
1740+
}
1741+
1742+
static inline void isp_ll_awb_set_wb_gain(isp_dev_t *hw, isp_wbg_gain_t gain)
1743+
{
1744+
//for compatibility
1745+
}
17311746
#endif //#if HAL_CONFIG(CHIP_SUPPORT_MIN_REV) >= 300
17321747

17331748
/*---------------------------------------------------------------

components/hal/include/hal/isp_types.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,18 @@ typedef union {
435435
uint32_t val; ///< 32-bit gradient ratio value
436436
} isp_lsc_gain_t;
437437

438+
/*---------------------------------------------------------------
439+
WBG (White Balance Gain)
440+
---------------------------------------------------------------*/
441+
/**
442+
* @brief ISP White Balance Gain
443+
*/
444+
typedef struct {
445+
uint32_t gain_r; ///< White balance gain for R channel
446+
uint32_t gain_g; ///< White balance gain for G channel
447+
uint32_t gain_b; ///< White balance gain for B channel
448+
} isp_wbg_gain_t;
449+
438450
#ifdef __cplusplus
439451
}
440452
#endif

components/soc/esp32p4/include/soc/Kconfig.soc_caps.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,10 @@ config SOC_ISP_SHARPEN_SUPPORTED
959959
bool
960960
default y
961961

962+
config SOC_ISP_WBG_SUPPORTED
963+
bool
964+
default y
965+
962966
config SOC_ISP_SHARE_CSI_BRG
963967
bool
964968
default y

0 commit comments

Comments
 (0)