Skip to content

Commit 4189c54

Browse files
committed
feat(isp_awb): support to change config after initialized
1 parent b0fcdcc commit 4189c54

File tree

4 files changed

+48
-29
lines changed

4 files changed

+48
-29
lines changed

components/esp_driver_isp/include/driver/isp_af.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ typedef struct {
178178
/**
179179
* @brief Prototype of ISP AF Env detector event callback
180180
*
181-
* @param[in] af_ctrlr ISP AF controller handle
181+
* @param[in] af_ctrlr ISP AF controller handle
182182
* @param[in] edata ISP AF Env detector event data
183183
* @param[in] user_data User registered context, registered when in `esp_isp_af_env_detector_register_event_callbacks()`
184184
*

components/esp_driver_isp/include/driver/isp_awb.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ typedef struct {
4949
* so that all the distorted pixels will be counted for the reference of white balance.
5050
*/
5151
} white_patch; /*!< white patch configuration */
52-
int intr_priority; /*!< The interrupt priority, range 0~7, if set to 0, the driver will try to allocate an interrupt with
53-
* a relative low priority (1,2,3) otherwise the larger the higher, 7 is NMI.
52+
int intr_priority; /*!< The interrupt priority, range 0~3, if set to 0, the driver will try to allocate an interrupt with
53+
* a relative low priority (1,2,3)
5454
*/
5555
} esp_isp_awb_config_t;
5656

@@ -82,6 +82,19 @@ esp_err_t esp_isp_new_awb_controller(isp_proc_handle_t isp_proc, const esp_isp_a
8282
*/
8383
esp_err_t esp_isp_del_awb_controller(isp_awb_ctlr_t awb_ctlr);
8484

85+
/**
86+
* @brief Reconfigure the ISP AWB controller
87+
* @note This function is allowed to be called no matter the awb controller is enabled or not.
88+
*
89+
* @param[in] awb_ctlr AWB controller handle
90+
* @param[in] awb_cfg Pointer to AWB config. Refer to ``esp_isp_awb_config_t``
91+
*
92+
* @return
93+
* - ESP_OK On success
94+
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid
95+
*/
96+
esp_err_t esp_isp_awb_controller_reconfig(isp_awb_ctlr_t awb_ctlr, const esp_isp_awb_config_t *awb_cfg);
97+
8598
/**
8699
* @brief Enable an ISP AWB controller
87100
*

components/esp_driver_isp/src/isp_awb.c

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ typedef struct isp_awb_controller_t {
1818
isp_fsm_t fsm;
1919
portMUX_TYPE spinlock;
2020
intr_handle_t intr_handle;
21+
int intr_priority;
2122
isp_proc_handle_t isp_proc;
2223
QueueHandle_t evt_que;
2324
SemaphoreHandle_t stat_lock;
@@ -72,6 +73,25 @@ static void s_isp_awb_free_controller(isp_awb_ctlr_t awb_ctlr)
7273
}
7374
}
7475

76+
static esp_err_t s_esp_isp_awb_config_hardware(isp_proc_handle_t isp_proc, const esp_isp_awb_config_t *awb_cfg)
77+
{
78+
isp_ll_awb_set_sample_point(isp_proc->hal.hw, awb_cfg->sample_point);
79+
ESP_RETURN_ON_FALSE(isp_hal_awb_set_window_range(&isp_proc->hal, &awb_cfg->window),
80+
ESP_ERR_INVALID_ARG, TAG, "invalid window");
81+
isp_u32_range_t lum_range = awb_cfg->white_patch.luminance;
82+
ESP_RETURN_ON_FALSE(isp_hal_awb_set_luminance_range(&isp_proc->hal, lum_range.min, lum_range.max),
83+
ESP_ERR_INVALID_ARG, TAG, "invalid luminance range");
84+
isp_float_range_t rg_range = awb_cfg->white_patch.red_green_ratio;
85+
ESP_RETURN_ON_FALSE(rg_range.min < rg_range.max && rg_range.min >= 0 &&
86+
isp_hal_awb_set_rg_ratio_range(&isp_proc->hal, rg_range.min, rg_range.max),
87+
ESP_ERR_INVALID_ARG, TAG, "invalid range of Red Green ratio");
88+
isp_float_range_t bg_range = awb_cfg->white_patch.blue_green_ratio;
89+
ESP_RETURN_ON_FALSE(bg_range.min < bg_range.max && bg_range.min >= 0 &&
90+
isp_hal_awb_set_bg_ratio_range(&isp_proc->hal, bg_range.min, bg_range.max),
91+
ESP_ERR_INVALID_ARG, TAG, "invalid range of Blue to Green ratio");
92+
return ESP_OK;
93+
}
94+
7595
esp_err_t esp_isp_new_awb_controller(isp_proc_handle_t isp_proc, const esp_isp_awb_config_t *awb_cfg, isp_awb_ctlr_t *ret_hdl)
7696
{
7797
esp_err_t ret = ESP_FAIL;
@@ -91,27 +111,14 @@ esp_err_t esp_isp_new_awb_controller(isp_proc_handle_t isp_proc, const esp_isp_a
91111
ESP_GOTO_ON_ERROR(s_isp_claim_awb_controller(isp_proc, awb_ctlr), err1, TAG, "no available controller");
92112
// Register the AWB ISR
93113
uint32_t intr_st_reg_addr = isp_ll_get_intr_status_reg_addr(isp_proc->hal.hw);
94-
int intr_priority = awb_cfg->intr_priority > 0 && awb_cfg->intr_priority <= 7 ? BIT(awb_cfg->intr_priority) : ESP_INTR_FLAG_LOWMED;
95-
ESP_GOTO_ON_ERROR(esp_intr_alloc_intrstatus(isp_hw_info.instances[isp_proc->proc_id].irq, ISP_INTR_ALLOC_FLAGS | intr_priority, intr_st_reg_addr, ISP_LL_EVENT_AWB_MASK,
114+
awb_ctlr->intr_priority = awb_cfg->intr_priority > 0 && awb_cfg->intr_priority <= 3 ? BIT(awb_cfg->intr_priority) : ESP_INTR_FLAG_LOWMED;
115+
ESP_GOTO_ON_ERROR(esp_intr_alloc_intrstatus(isp_hw_info.instances[isp_proc->proc_id].irq, ISP_INTR_ALLOC_FLAGS | awb_ctlr->intr_priority, intr_st_reg_addr, ISP_LL_EVENT_AWB_MASK,
96116
s_isp_awb_default_isr, awb_ctlr, &awb_ctlr->intr_handle), err2, TAG, "allocate interrupt failed");
97117

98118
// Configure the hardware
99119
isp_ll_awb_enable(isp_proc->hal.hw, false);
100-
isp_ll_awb_set_sample_point(isp_proc->hal.hw, awb_cfg->sample_point);
101120
isp_ll_awb_enable_algorithm_mode(isp_proc->hal.hw, true);
102-
ESP_GOTO_ON_FALSE(isp_hal_awb_set_window_range(&isp_proc->hal, &awb_cfg->window),
103-
ESP_ERR_INVALID_ARG, err2, TAG, "invalid window");
104-
isp_u32_range_t lum_range = awb_cfg->white_patch.luminance;
105-
ESP_GOTO_ON_FALSE(isp_hal_awb_set_luminance_range(&isp_proc->hal, lum_range.min, lum_range.max),
106-
ESP_ERR_INVALID_ARG, err2, TAG, "invalid luminance range");
107-
isp_float_range_t rg_range = awb_cfg->white_patch.red_green_ratio;
108-
ESP_GOTO_ON_FALSE(rg_range.min < rg_range.max && rg_range.min >= 0 &&
109-
isp_hal_awb_set_rg_ratio_range(&isp_proc->hal, rg_range.min, rg_range.max),
110-
ESP_ERR_INVALID_ARG, err2, TAG, "invalid range of Red Green ratio");
111-
isp_float_range_t bg_range = awb_cfg->white_patch.blue_green_ratio;
112-
ESP_GOTO_ON_FALSE(bg_range.min < bg_range.max && bg_range.min >= 0 &&
113-
isp_hal_awb_set_bg_ratio_range(&isp_proc->hal, bg_range.min, bg_range.max),
114-
ESP_ERR_INVALID_ARG, err2, TAG, "invalid range of Blue to Green ratio");
121+
ESP_GOTO_ON_ERROR(s_esp_isp_awb_config_hardware(isp_proc, awb_cfg), err2, TAG, "configure awb hardware failed");
115122

116123
*ret_hdl = awb_ctlr;
117124

@@ -138,6 +145,15 @@ esp_err_t esp_isp_del_awb_controller(isp_awb_ctlr_t awb_ctlr)
138145
return ESP_OK;
139146
}
140147

148+
esp_err_t esp_isp_awb_controller_reconfig(isp_awb_ctlr_t awb_ctlr, const esp_isp_awb_config_t *awb_cfg)
149+
{
150+
ESP_RETURN_ON_FALSE(awb_ctlr && awb_cfg, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
151+
int intr_priority = awb_cfg->intr_priority > 0 && awb_cfg->intr_priority <= 3 ? BIT(awb_cfg->intr_priority) : ESP_INTR_FLAG_LOWMED;
152+
ESP_RETURN_ON_FALSE(intr_priority == awb_ctlr->intr_priority, ESP_ERR_INVALID_ARG, TAG, "can't change interrupt priority after initialized");
153+
154+
return s_esp_isp_awb_config_hardware(awb_ctlr->isp_proc, awb_cfg);
155+
}
156+
141157
esp_err_t esp_isp_awb_controller_enable(isp_awb_ctlr_t awb_ctlr)
142158
{
143159
ESP_RETURN_ON_FALSE(awb_ctlr && awb_ctlr->isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");

components/hal/include/hal/isp_types.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,6 @@ typedef enum {
8181
#define ISP_AF_WINDOW_NUM 0
8282
#endif
8383

84-
/**
85-
* @brief ISP AF window
86-
*/
87-
typedef struct {
88-
uint32_t top_left_x; ///< Top left x axis value
89-
uint32_t top_left_y; ///< Top left y axis value
90-
uint32_t bottom_right_x; ///< Bottom right x axis value
91-
uint32_t bottom_right_y; ///< Bottom right y axis value
92-
} isp_af_window_t;
93-
9484
/*---------------------------------------------------------------
9585
BF
9686
---------------------------------------------------------------*/

0 commit comments

Comments
 (0)