Skip to content

Commit 4b3e014

Browse files
committed
docs(isp_awb): add isp awb programming guide
1 parent 8c225c0 commit 4b3e014

File tree

9 files changed

+229
-88
lines changed

9 files changed

+229
-88
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_types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ typedef struct {
3030
float max; ///< Maximum float value
3131
} isp_float_range_t;
3232

33+
/**
34+
* @brief ISP AF result
35+
*/
36+
typedef struct {
37+
int definition[ISP_AF_WINDOW_NUM]; ///< Definition, it refers how clear and sharp an image is
38+
int luminance[ISP_AF_WINDOW_NUM]; ///< Luminance, it refers how luminant an image is
39+
} isp_af_result_t;
40+
3341
/**
3442
* @brief ISP AWB result
3543
*/

components/esp_driver_isp/src/isp_awb.c

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "esp_check.h"
1313
#include "esp_heap_caps.h"
1414
#include "driver/isp_awb.h"
15-
#include "isp_internal.h"
15+
#include "esp_private/isp_private.h"
1616

1717
typedef struct isp_awb_controller_t {
1818
isp_fsm_t fsm;
@@ -142,40 +142,43 @@ esp_err_t esp_isp_awb_controller_enable(isp_awb_ctlr_t awb_ctlr)
142142
{
143143
ESP_RETURN_ON_FALSE(awb_ctlr && awb_ctlr->isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
144144
ESP_RETURN_ON_FALSE(awb_ctlr->fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "controller isn't in init state");
145+
awb_ctlr->fsm = ISP_FSM_ENABLE;
145146

146-
esp_intr_enable(awb_ctlr->intr_handle);
147+
esp_err_t ret = ESP_OK;
148+
ESP_GOTO_ON_ERROR(esp_intr_enable(awb_ctlr->intr_handle), err, TAG, "failed to enable the AWB interrupt");
147149
isp_ll_awb_clk_enable(awb_ctlr->isp_proc->hal.hw, true);
148150
isp_ll_enable_intr(awb_ctlr->isp_proc->hal.hw, ISP_LL_EVENT_AWB_MASK, true);
149151
xSemaphoreGive(awb_ctlr->stat_lock);
150-
awb_ctlr->fsm = ISP_FSM_ENABLE;
151152

152-
return ESP_OK;
153+
return ret;
154+
err:
155+
awb_ctlr->fsm = ISP_FSM_INIT;
156+
return ret;
153157
}
154158

155159
esp_err_t esp_isp_awb_controller_disable(isp_awb_ctlr_t awb_ctlr)
156160
{
157161
ESP_RETURN_ON_FALSE(awb_ctlr && awb_ctlr->isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
158162
ESP_RETURN_ON_FALSE(awb_ctlr->fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "controller isn't in enable state");
163+
xSemaphoreTake(awb_ctlr->stat_lock, 0);
164+
awb_ctlr->fsm = ISP_FSM_INIT;
159165

160166
isp_ll_enable_intr(awb_ctlr->isp_proc->hal.hw, ISP_LL_EVENT_AWB_MASK, false);
161167
isp_ll_awb_clk_enable(awb_ctlr->isp_proc->hal.hw, false);
162168
esp_intr_disable(awb_ctlr->intr_handle);
163-
awb_ctlr->fsm = ISP_FSM_INIT;
164-
xSemaphoreTake(awb_ctlr->stat_lock, 0);
165169

166170
return ESP_OK;
167171
}
168172

169173
esp_err_t esp_isp_awb_controller_get_oneshot_statistics(isp_awb_ctlr_t awb_ctlr, int timeout_ms, isp_awb_stat_result_t *out_res)
170174
{
171-
ESP_RETURN_ON_FALSE_ISR(awb_ctlr && (out_res || timeout_ms == 0), ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
172-
ESP_RETURN_ON_FALSE_ISR(awb_ctlr->fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "controller isn't in enable state");
175+
ESP_RETURN_ON_FALSE(awb_ctlr && (out_res || timeout_ms == 0), ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
176+
esp_err_t ret = ESP_OK;
173177
TickType_t ticks = timeout_ms < 0 ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms);
174-
175178
xSemaphoreTake(awb_ctlr->stat_lock, ticks);
179+
ESP_GOTO_ON_FALSE(awb_ctlr->fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, err, TAG, "controller isn't in enable state");
176180
// Update state to avoid race condition
177181
awb_ctlr->fsm = ISP_FSM_START;
178-
esp_err_t ret = ESP_OK;
179182
// Reset the queue in case receiving the legacy data in the queue
180183
xQueueReset(awb_ctlr->evt_que);
181184
// Start the AWB white patch statistics and waiting it done
@@ -187,30 +190,34 @@ esp_err_t esp_isp_awb_controller_get_oneshot_statistics(isp_awb_ctlr_t awb_ctlr,
187190
// Stop the AWB white patch statistics
188191
isp_ll_awb_enable(awb_ctlr->isp_proc->hal.hw, false);
189192
awb_ctlr->fsm = ISP_FSM_ENABLE;
193+
err:
190194
xSemaphoreGive(awb_ctlr->stat_lock);
191-
192195
return ret;
193196
}
194197

195198
esp_err_t esp_isp_awb_controller_start_continuous_statistics(isp_awb_ctlr_t awb_ctlr)
196199
{
197-
ESP_RETURN_ON_FALSE_ISR(awb_ctlr, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
198-
ESP_RETURN_ON_FALSE_ISR(awb_ctlr->fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "controller isn't in enable state");
199-
200+
ESP_RETURN_ON_FALSE(awb_ctlr, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
201+
ESP_RETURN_ON_FALSE(awb_ctlr->cbs.on_statistics_done, ESP_ERR_INVALID_STATE, TAG, "invalid state: on_statistics_done callback not registered");
202+
esp_err_t ret = ESP_OK;
200203
if (xSemaphoreTake(awb_ctlr->stat_lock, 0) == pdFALSE) {
201204
ESP_LOGW(TAG, "statistics lock is not acquired, controller is busy");
202205
return ESP_ERR_INVALID_STATE;
203206
}
207+
ESP_GOTO_ON_FALSE(awb_ctlr->fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, err, TAG, "controller isn't in enable state");
204208
awb_ctlr->fsm = ISP_FSM_START;
205209
isp_ll_awb_enable(awb_ctlr->isp_proc->hal.hw, true);
206210

207-
return ESP_OK;
211+
return ret;
212+
err:
213+
xSemaphoreGive(awb_ctlr->stat_lock);
214+
return ret;
208215
}
209216

210217
esp_err_t esp_isp_awb_controller_stop_continuous_statistics(isp_awb_ctlr_t awb_ctlr)
211218
{
212-
ESP_RETURN_ON_FALSE_ISR(awb_ctlr, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
213-
ESP_RETURN_ON_FALSE_ISR(awb_ctlr->fsm == ISP_FSM_START, ESP_ERR_INVALID_STATE, TAG, "controller isn't in continuous state");
219+
ESP_RETURN_ON_FALSE(awb_ctlr, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
220+
ESP_RETURN_ON_FALSE(awb_ctlr->fsm == ISP_FSM_START, ESP_ERR_INVALID_STATE, TAG, "controller isn't in continuous state");
214221

215222
isp_ll_awb_enable(awb_ctlr->isp_proc->hal.hw, false);
216223
awb_ctlr->fsm = ISP_FSM_ENABLE;
@@ -236,7 +243,7 @@ static void IRAM_ATTR s_isp_awb_default_isr(void *arg)
236243
// Get the statistics result
237244
esp_isp_awb_evt_data_t edata = {
238245
.awb_result = {
239-
.white_patch_num = isp_ll_awb_get_white_patcherence_cnt(proc->hal.hw),
246+
.white_patch_num = isp_ll_awb_get_white_patch_cnt(proc->hal.hw),
240247
.sum_r = isp_ll_awb_get_accumulated_r_value(proc->hal.hw),
241248
.sum_g = isp_ll_awb_get_accumulated_g_value(proc->hal.hw),
242249
.sum_b = isp_ll_awb_get_accumulated_b_value(proc->hal.hw),

components/esp_driver_isp/test_apps/isp/main/test_isp_driver.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ TEST_CASE("ISP AF controller exhausted allocation", "[isp]")
5757
TEST_ESP_OK(esp_isp_del_processor(isp_proc));
5858
}
5959

60+
static bool test_isp_awb_default_on_statistics_done_cb(isp_awb_ctlr_t awb_ctlr, const esp_isp_awb_evt_data_t *edata, void *user_data)
61+
{
62+
(void) awb_ctlr;
63+
(void) edata;
64+
(void) user_data;
65+
// Do nothing
66+
return false;
67+
}
68+
6069
TEST_CASE("ISP AWB driver basic function", "[isp]")
6170
{
6271
esp_isp_processor_cfg_t isp_config = {
@@ -88,6 +97,11 @@ TEST_CASE("ISP AWB driver basic function", "[isp]")
8897
isp_awb_stat_result_t stat_res = {};
8998
/* Create the awb controller */
9099
TEST_ESP_OK(esp_isp_new_awb_controller(isp_proc, &awb_config, &awb_ctlr));
100+
/* Register AWB callback */
101+
esp_isp_awb_cbs_t awb_cb = {
102+
.on_statistics_done = test_isp_awb_default_on_statistics_done_cb,
103+
};
104+
TEST_ESP_OK(esp_isp_awb_register_event_callbacks(awb_ctlr, &awb_cb, NULL));
91105
/* Enabled the awb controller */
92106
TEST_ESP_OK(esp_isp_awb_controller_enable(awb_ctlr));
93107
/* Start continuous AWB statistics */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ static inline void isp_ll_awb_set_bg_ratio_range(isp_dev_t *hw, isp_ll_awb_rgb_r
11231123
* - white patch count
11241124
*/
11251125
__attribute__((always_inline))
1126-
static inline uint32_t isp_ll_awb_get_white_patcherence_cnt(isp_dev_t *hw)
1126+
static inline uint32_t isp_ll_awb_get_white_patch_cnt(isp_dev_t *hw)
11271127
{
11281128
return hw->awb0_white_cnt.awb0_white_cnt;
11291129
}

components/hal/include/hal/isp_hal.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,6 @@ uint32_t isp_hal_check_clear_intr_event(const isp_hal_context_t *hal, uint32_t m
8888
*/
8989
void isp_hal_bf_config(isp_hal_context_t *hal, isp_hal_bf_cfg_t *config);
9090

91-
/*---------------------------------------------------------------
92-
Color Correction Matrix
93-
---------------------------------------------------------------*/
94-
/**
95-
* @brief Set Color Correction Matrix
96-
*
97-
* @param[in] hal Context of the HAL layer
98-
* @param[in] saturation Whether to enable saturation when float data overflow
99-
* @param[in] flt_matrix 3x3 RGB correction matrix
100-
* @return
101-
* - true Set success
102-
* - false Invalid are
103-
*/
104-
bool isp_hal_ccm_set_matrix(const isp_hal_context_t *hal, bool saturation, const float flt_matrix[3][3]);
105-
10691
/*---------------------------------------------------------------
10792
AWB
10893
---------------------------------------------------------------*/

components/hal/include/hal/isp_types.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,14 @@ typedef enum {
8282
#endif
8383

8484
/**
85-
* @brief ISP AF result
85+
* @brief ISP AF window
8686
*/
8787
typedef struct {
88-
int definition[ISP_AF_WINDOW_NUM]; ///< Definition, it refers how clear and sharp an image is
89-
int luminance[ISP_AF_WINDOW_NUM]; ///< Luminance, it refers how luminant an image is
90-
} isp_af_result_t;
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;
9193

9294
/*---------------------------------------------------------------
9395
BF

components/hal/isp_hal.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#include "hal/isp_types.h"
1717
#include "hal/hal_utils.h"
1818

19-
#include "esp_rom_sys.h"
20-
2119
/**
2220
* ISP HAL layer
2321
*/

0 commit comments

Comments
 (0)