forked from espressif/esp-idf
feat(isp_ae): add thread safe lock for ISP AE
This commit is contained in:
@@ -101,8 +101,8 @@ esp_err_t esp_isp_ae_controller_get_oneshot_statistics(isp_ae_ctlr_t ae_ctlr, in
|
|||||||
* @note This function is an asynchronous and non-block function,
|
* @note This function is an asynchronous and non-block function,
|
||||||
* it will start the continuous statistics and return immediately.
|
* it will start the continuous statistics and return immediately.
|
||||||
* You have to register the AE callback and get the result from the callback event data.
|
* You have to register the AE callback and get the result from the callback event data.
|
||||||
* When you call `esp_isp_ae_controller_get_oneshot_statistics` during continuous mode,
|
* @note When using oneshot statistics, the AE Environment Detector will be temporarily disabled
|
||||||
* continuous will be invalid, you need to restart continuous mode again.
|
* and will automatically recover once the oneshot is complete.
|
||||||
* @param[in] ae_ctlr AE controller handle
|
* @param[in] ae_ctlr AE controller handle
|
||||||
* @return
|
* @return
|
||||||
* - ESP_OK On success
|
* - ESP_OK On success
|
||||||
|
@@ -40,9 +40,12 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ISP_FSM_INIT,
|
ISP_FSM_INIT, // Controller is initialized, but not enabled
|
||||||
ISP_FSM_ENABLE,
|
ISP_FSM_ENABLE, // Controller is enabled, but is not running
|
||||||
ISP_FSM_START,
|
ISP_FSM_START, // Controller is in running
|
||||||
|
|
||||||
|
ISP_FSM_ONESHOT, // Controller is in oneshot sampling
|
||||||
|
ISP_FSM_CONTINUOUS, // Controller is in continuous sampling
|
||||||
} isp_fsm_t;
|
} isp_fsm_t;
|
||||||
|
|
||||||
#if SOC_ISP_SUPPORTED
|
#if SOC_ISP_SUPPORTED
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <esp_types.h>
|
#include <esp_types.h>
|
||||||
#include <sys/lock.h>
|
#include <sys/lock.h>
|
||||||
|
#include <stdatomic.h>
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_check.h"
|
#include "esp_check.h"
|
||||||
@@ -18,13 +19,12 @@ static const char *TAG = "ISP_AE";
|
|||||||
|
|
||||||
typedef struct isp_ae_controller_t {
|
typedef struct isp_ae_controller_t {
|
||||||
int id;
|
int id;
|
||||||
isp_fsm_t fsm;
|
_Atomic isp_fsm_t fsm;
|
||||||
portMUX_TYPE spinlock;
|
portMUX_TYPE spinlock;
|
||||||
intr_handle_t intr_handle;
|
intr_handle_t intr_handle;
|
||||||
int intr_priority;
|
int intr_priority;
|
||||||
isp_proc_handle_t isp_proc;
|
isp_proc_handle_t isp_proc;
|
||||||
QueueHandle_t evt_que;
|
QueueHandle_t evt_que;
|
||||||
SemaphoreHandle_t stat_lock;
|
|
||||||
int low_thresh;
|
int low_thresh;
|
||||||
int high_thresh;
|
int high_thresh;
|
||||||
esp_isp_ae_env_detector_evt_cbs_t cbs;
|
esp_isp_ae_env_detector_evt_cbs_t cbs;
|
||||||
@@ -67,9 +67,6 @@ static void s_isp_ae_free_controller(isp_ae_ctlr_t ae_ctlr)
|
|||||||
if (ae_ctlr->evt_que) {
|
if (ae_ctlr->evt_que) {
|
||||||
vQueueDeleteWithCaps(ae_ctlr->evt_que);
|
vQueueDeleteWithCaps(ae_ctlr->evt_que);
|
||||||
}
|
}
|
||||||
if (ae_ctlr->stat_lock) {
|
|
||||||
vSemaphoreDeleteWithCaps(ae_ctlr->stat_lock);
|
|
||||||
}
|
|
||||||
free(ae_ctlr);
|
free(ae_ctlr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,10 +87,9 @@ esp_err_t esp_isp_new_ae_controller(isp_proc_handle_t isp_proc, const esp_isp_ae
|
|||||||
ESP_RETURN_ON_FALSE(ae_ctlr, ESP_ERR_NO_MEM, TAG, "no mem");
|
ESP_RETURN_ON_FALSE(ae_ctlr, ESP_ERR_NO_MEM, TAG, "no mem");
|
||||||
ae_ctlr->evt_que = xQueueCreateWithCaps(1, sizeof(isp_ae_result_t), ISP_MEM_ALLOC_CAPS);
|
ae_ctlr->evt_que = xQueueCreateWithCaps(1, sizeof(isp_ae_result_t), ISP_MEM_ALLOC_CAPS);
|
||||||
ESP_GOTO_ON_FALSE(ae_ctlr->evt_que, ESP_ERR_NO_MEM, err1, TAG, "no mem for ae event queue");
|
ESP_GOTO_ON_FALSE(ae_ctlr->evt_que, ESP_ERR_NO_MEM, err1, TAG, "no mem for ae event queue");
|
||||||
ae_ctlr->stat_lock = xSemaphoreCreateBinaryWithCaps(ISP_MEM_ALLOC_CAPS);
|
|
||||||
ESP_GOTO_ON_FALSE(ae_ctlr->stat_lock, ESP_ERR_NO_MEM, err1, TAG, "no mem for ae semaphore");
|
|
||||||
|
|
||||||
ae_ctlr->fsm = ISP_FSM_INIT;
|
atomic_init(&ae_ctlr->fsm, ISP_FSM_INIT);
|
||||||
|
|
||||||
ae_ctlr->spinlock = (portMUX_TYPE)portMUX_INITIALIZER_UNLOCKED;
|
ae_ctlr->spinlock = (portMUX_TYPE)portMUX_INITIALIZER_UNLOCKED;
|
||||||
ae_ctlr->isp_proc = isp_proc;
|
ae_ctlr->isp_proc = isp_proc;
|
||||||
|
|
||||||
@@ -126,7 +122,7 @@ esp_err_t esp_isp_del_ae_controller(isp_ae_ctlr_t ae_ctlr)
|
|||||||
{
|
{
|
||||||
ESP_RETURN_ON_FALSE(ae_ctlr && ae_ctlr->isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
ESP_RETURN_ON_FALSE(ae_ctlr && ae_ctlr->isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||||
ESP_RETURN_ON_FALSE(ae_ctlr->isp_proc->ae_ctlr == ae_ctlr, ESP_ERR_INVALID_ARG, TAG, "controller isn't in use");
|
ESP_RETURN_ON_FALSE(ae_ctlr->isp_proc->ae_ctlr == ae_ctlr, ESP_ERR_INVALID_ARG, TAG, "controller isn't in use");
|
||||||
ESP_RETURN_ON_FALSE(ae_ctlr->fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "controller isn't in init state");
|
ESP_RETURN_ON_FALSE(atomic_load(&ae_ctlr->fsm) == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "controller not in init state");
|
||||||
|
|
||||||
// Deregister the AE ISR
|
// Deregister the AE ISR
|
||||||
ESP_RETURN_ON_FALSE(esp_isp_deregister_isr(ae_ctlr->isp_proc, ISP_SUBMODULE_AE) == ESP_OK, ESP_FAIL, TAG, "fail to deregister ISR");
|
ESP_RETURN_ON_FALSE(esp_isp_deregister_isr(ae_ctlr->isp_proc, ISP_SUBMODULE_AE) == ESP_OK, ESP_FAIL, TAG, "fail to deregister ISR");
|
||||||
@@ -140,23 +136,24 @@ esp_err_t esp_isp_del_ae_controller(isp_ae_ctlr_t ae_ctlr)
|
|||||||
esp_err_t esp_isp_ae_controller_enable(isp_ae_ctlr_t ae_ctlr)
|
esp_err_t esp_isp_ae_controller_enable(isp_ae_ctlr_t ae_ctlr)
|
||||||
{
|
{
|
||||||
ESP_RETURN_ON_FALSE(ae_ctlr && ae_ctlr->isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
ESP_RETURN_ON_FALSE(ae_ctlr && ae_ctlr->isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||||
ESP_RETURN_ON_FALSE(ae_ctlr->fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "controller isn't in init state");
|
|
||||||
|
isp_fsm_t expected_fsm = ISP_FSM_INIT;
|
||||||
|
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&ae_ctlr->fsm, &expected_fsm, ISP_FSM_ENABLE),
|
||||||
|
ESP_ERR_INVALID_STATE, TAG, "controller not in init state");
|
||||||
|
|
||||||
isp_ll_ae_clk_enable(ae_ctlr->isp_proc->hal.hw, true);
|
isp_ll_ae_clk_enable(ae_ctlr->isp_proc->hal.hw, true);
|
||||||
isp_ll_enable_intr(ae_ctlr->isp_proc->hal.hw, ISP_LL_EVENT_AE_MASK, true);
|
isp_ll_enable_intr(ae_ctlr->isp_proc->hal.hw, ISP_LL_EVENT_AE_MASK, true);
|
||||||
isp_ll_ae_enable(ae_ctlr->isp_proc->hal.hw, true);
|
isp_ll_ae_enable(ae_ctlr->isp_proc->hal.hw, true);
|
||||||
xSemaphoreGive(ae_ctlr->stat_lock);
|
|
||||||
|
|
||||||
ae_ctlr->fsm = ISP_FSM_ENABLE;
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t esp_isp_ae_controller_disable(isp_ae_ctlr_t ae_ctlr)
|
esp_err_t esp_isp_ae_controller_disable(isp_ae_ctlr_t ae_ctlr)
|
||||||
{
|
{
|
||||||
ESP_RETURN_ON_FALSE(ae_ctlr && ae_ctlr->isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
ESP_RETURN_ON_FALSE(ae_ctlr && ae_ctlr->isp_proc, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||||
ESP_RETURN_ON_FALSE(ae_ctlr->fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "controller isn't in enable state");
|
isp_fsm_t expected_fsm = ISP_FSM_ENABLE;
|
||||||
xSemaphoreTake(ae_ctlr->stat_lock, 0);
|
ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&ae_ctlr->fsm, &expected_fsm, ISP_FSM_INIT),
|
||||||
ae_ctlr->fsm = ISP_FSM_INIT;
|
ESP_ERR_INVALID_STATE, TAG, "controller not in enable state");
|
||||||
|
|
||||||
isp_ll_ae_clk_enable(ae_ctlr->isp_proc->hal.hw, false);
|
isp_ll_ae_clk_enable(ae_ctlr->isp_proc->hal.hw, false);
|
||||||
isp_ll_enable_intr(ae_ctlr->isp_proc->hal.hw, ISP_LL_EVENT_AE_MASK, false);
|
isp_ll_enable_intr(ae_ctlr->isp_proc->hal.hw, ISP_LL_EVENT_AE_MASK, false);
|
||||||
@@ -172,59 +169,52 @@ esp_err_t esp_isp_ae_controller_get_oneshot_statistics(isp_ae_ctlr_t ae_ctlr, in
|
|||||||
|
|
||||||
esp_err_t ret = ESP_OK;
|
esp_err_t ret = ESP_OK;
|
||||||
TickType_t ticks = timeout_ms < 0 ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms);
|
TickType_t ticks = timeout_ms < 0 ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms);
|
||||||
xSemaphoreTake(ae_ctlr->stat_lock, ticks);
|
|
||||||
ESP_GOTO_ON_FALSE(ae_ctlr->fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, err, TAG, "controller isn't in enable state");
|
|
||||||
|
|
||||||
// Reset the queue in case receiving the legacy data in the queue
|
isp_fsm_t expected_fsm = ISP_FSM_ENABLE;
|
||||||
xQueueReset(ae_ctlr->evt_que);
|
if (atomic_compare_exchange_strong(&ae_ctlr->fsm, &expected_fsm, ISP_FSM_ONESHOT)) {
|
||||||
|
// Reset the queue in case receiving the legacy data in the queue
|
||||||
|
xQueueReset(ae_ctlr->evt_que);
|
||||||
|
|
||||||
// Disable the env detector when manual statistics.
|
// Disable the env detector when manual statistics.
|
||||||
// Otherwise, the env detector results may overwrite the manual statistics results when the statistics results are not read out in time
|
// Otherwise, the env detector results may overwrite the manual statistics results when the statistics results are not read out in time
|
||||||
isp_ll_ae_env_detector_set_thresh(ae_ctlr->isp_proc->hal.hw, 0, 0);
|
isp_ll_ae_env_detector_set_thresh(ae_ctlr->isp_proc->hal.hw, 0, 0);
|
||||||
// Trigger the AE statistics manually
|
// Trigger the AE statistics manually
|
||||||
isp_ll_ae_manual_update(ae_ctlr->isp_proc->hal.hw);
|
isp_ll_ae_manual_update(ae_ctlr->isp_proc->hal.hw);
|
||||||
// Wait the statistics to finish and receive the result from the queue
|
// Wait the statistics to finish and receive the result from the queue
|
||||||
if ((ticks > 0) && xQueueReceive(ae_ctlr->evt_que, out_res, ticks) != pdTRUE) {
|
if ((ticks > 0) && xQueueReceive(ae_ctlr->evt_que, out_res, ticks) != pdTRUE) {
|
||||||
ret = ESP_ERR_TIMEOUT;
|
ret = ESP_ERR_TIMEOUT;
|
||||||
|
}
|
||||||
|
// Re-enable the env detector after manual statistics.
|
||||||
|
isp_ll_ae_env_detector_set_thresh(ae_ctlr->isp_proc->hal.hw, ae_ctlr->low_thresh, ae_ctlr->high_thresh);
|
||||||
|
} else {
|
||||||
|
ESP_RETURN_ON_FALSE_ISR(false, ESP_ERR_INVALID_STATE, TAG, "controller is not enabled yet");
|
||||||
}
|
}
|
||||||
// Re-enable the env detector after manual statistics.
|
|
||||||
isp_ll_ae_env_detector_set_thresh(ae_ctlr->isp_proc->hal.hw, ae_ctlr->low_thresh, ae_ctlr->high_thresh);
|
|
||||||
|
|
||||||
ae_ctlr->fsm = ISP_FSM_ENABLE;
|
|
||||||
|
|
||||||
err:
|
|
||||||
xSemaphoreGive(ae_ctlr->stat_lock);
|
|
||||||
|
|
||||||
|
atomic_store(&ae_ctlr->fsm, ISP_FSM_ENABLE);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t esp_isp_ae_controller_start_continuous_statistics(isp_ae_ctlr_t ae_ctlr)
|
esp_err_t esp_isp_ae_controller_start_continuous_statistics(isp_ae_ctlr_t ae_ctlr)
|
||||||
{
|
{
|
||||||
ESP_RETURN_ON_FALSE_ISR(ae_ctlr, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
ESP_RETURN_ON_FALSE_ISR(ae_ctlr, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||||
esp_err_t ret = ESP_OK;
|
|
||||||
if (xSemaphoreTake(ae_ctlr->stat_lock, 0) == pdFALSE) {
|
isp_fsm_t expected_fsm = ISP_FSM_ENABLE;
|
||||||
ESP_LOGW(TAG, "statistics lock is not acquired, controller is busy");
|
if (atomic_compare_exchange_strong(&ae_ctlr->fsm, &expected_fsm, ISP_FSM_CONTINUOUS)) {
|
||||||
return ESP_ERR_INVALID_STATE;
|
isp_ll_ae_manual_update(ae_ctlr->isp_proc->hal.hw);
|
||||||
|
} else {
|
||||||
|
ESP_RETURN_ON_FALSE_ISR(false, ESP_ERR_INVALID_STATE, TAG, "controller is not enabled yet");
|
||||||
}
|
}
|
||||||
ESP_GOTO_ON_FALSE(ae_ctlr->fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, err, TAG, "controller isn't in enable state");
|
|
||||||
|
|
||||||
ae_ctlr->fsm = ISP_FSM_START;
|
return ESP_OK;
|
||||||
|
|
||||||
isp_ll_ae_manual_update(ae_ctlr->isp_proc->hal.hw);
|
|
||||||
|
|
||||||
err:
|
|
||||||
xSemaphoreGive(ae_ctlr->stat_lock);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t esp_isp_ae_controller_stop_continuous_statistics(isp_ae_ctlr_t ae_ctlr)
|
esp_err_t esp_isp_ae_controller_stop_continuous_statistics(isp_ae_ctlr_t ae_ctlr)
|
||||||
{
|
{
|
||||||
ESP_RETURN_ON_FALSE_ISR(ae_ctlr, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
ESP_RETURN_ON_FALSE_ISR(ae_ctlr, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||||
ESP_RETURN_ON_FALSE_ISR(ae_ctlr->fsm == ISP_FSM_START, ESP_ERR_INVALID_STATE, TAG, "controller isn't in continuous state");
|
|
||||||
|
|
||||||
ae_ctlr->fsm = ISP_FSM_ENABLE;
|
|
||||||
xSemaphoreGive(ae_ctlr->stat_lock);
|
|
||||||
|
|
||||||
|
isp_fsm_t expected_fsm = ISP_FSM_CONTINUOUS;
|
||||||
|
ESP_RETURN_ON_FALSE_ISR(atomic_compare_exchange_strong(&ae_ctlr->fsm, &expected_fsm, ISP_FSM_ENABLE),
|
||||||
|
ESP_ERR_INVALID_STATE, TAG, "controller is not running");
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,8 +224,8 @@ esp_err_t esp_isp_ae_controller_stop_continuous_statistics(isp_ae_ctlr_t ae_ctlr
|
|||||||
esp_err_t esp_isp_ae_controller_set_env_detector(isp_ae_ctlr_t ae_ctlr, const esp_isp_ae_env_config_t *env_config)
|
esp_err_t esp_isp_ae_controller_set_env_detector(isp_ae_ctlr_t ae_ctlr, const esp_isp_ae_env_config_t *env_config)
|
||||||
{
|
{
|
||||||
ESP_RETURN_ON_FALSE(ae_ctlr && env_config, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
ESP_RETURN_ON_FALSE(ae_ctlr && env_config, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer");
|
||||||
ESP_RETURN_ON_FALSE(ae_ctlr->fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "invalid fsm, should be called when in init state");
|
|
||||||
ESP_RETURN_ON_FALSE(env_config->interval > 0, ESP_ERR_INVALID_STATE, TAG, "invalid interval, should be greater than 0");
|
ESP_RETURN_ON_FALSE(env_config->interval > 0, ESP_ERR_INVALID_STATE, TAG, "invalid interval, should be greater than 0");
|
||||||
|
ESP_RETURN_ON_FALSE(atomic_load(&ae_ctlr->fsm) == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "controller not in init state");
|
||||||
|
|
||||||
isp_ll_clear_intr(ae_ctlr->isp_proc->hal.hw, ISP_LL_EVENT_AE_ENV);
|
isp_ll_clear_intr(ae_ctlr->isp_proc->hal.hw, ISP_LL_EVENT_AE_ENV);
|
||||||
isp_ll_ae_env_detector_set_period(ae_ctlr->isp_proc->hal.hw, env_config->interval);
|
isp_ll_ae_env_detector_set_period(ae_ctlr->isp_proc->hal.hw, env_config->interval);
|
||||||
@@ -247,7 +237,7 @@ esp_err_t esp_isp_ae_controller_set_env_detector(isp_ae_ctlr_t ae_ctlr, const es
|
|||||||
esp_err_t esp_isp_ae_env_detector_register_event_callbacks(isp_ae_ctlr_t ae_ctlr, const esp_isp_ae_env_detector_evt_cbs_t *cbs, void *user_data)
|
esp_err_t esp_isp_ae_env_detector_register_event_callbacks(isp_ae_ctlr_t ae_ctlr, const esp_isp_ae_env_detector_evt_cbs_t *cbs, void *user_data)
|
||||||
{
|
{
|
||||||
ESP_RETURN_ON_FALSE(ae_ctlr && cbs, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
ESP_RETURN_ON_FALSE(ae_ctlr && cbs, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||||
ESP_RETURN_ON_FALSE(ae_ctlr->fsm == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "detector isn't in the init state");
|
ESP_RETURN_ON_FALSE(atomic_load(&ae_ctlr->fsm) == ISP_FSM_INIT, ESP_ERR_INVALID_STATE, TAG, "controller not in init state");
|
||||||
|
|
||||||
#if CONFIG_ISP_ISR_IRAM_SAEE
|
#if CONFIG_ISP_ISR_IRAM_SAEE
|
||||||
if (cbs->on_env_statistics_done) {
|
if (cbs->on_env_statistics_done) {
|
||||||
@@ -270,8 +260,8 @@ esp_err_t esp_isp_ae_env_detector_register_event_callbacks(isp_ae_ctlr_t ae_ctlr
|
|||||||
esp_err_t esp_isp_ae_controller_set_env_detector_threshold(isp_ae_ctlr_t ae_ctlr, const esp_isp_ae_env_thresh_t *env_thresh)
|
esp_err_t esp_isp_ae_controller_set_env_detector_threshold(isp_ae_ctlr_t ae_ctlr, const esp_isp_ae_env_thresh_t *env_thresh)
|
||||||
{
|
{
|
||||||
ESP_RETURN_ON_FALSE_ISR(ae_ctlr, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
ESP_RETURN_ON_FALSE_ISR(ae_ctlr, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||||
ESP_RETURN_ON_FALSE_ISR(ae_ctlr->fsm == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "AE env detector isn't in enable state");
|
|
||||||
ESP_RETURN_ON_FALSE_ISR((env_thresh->low_thresh != 0 && env_thresh->high_thresh != 0) && (env_thresh->low_thresh <= env_thresh->high_thresh), ESP_ERR_INVALID_STATE, TAG, "invalid AE env detector thresh");
|
ESP_RETURN_ON_FALSE_ISR((env_thresh->low_thresh != 0 && env_thresh->high_thresh != 0) && (env_thresh->low_thresh <= env_thresh->high_thresh), ESP_ERR_INVALID_STATE, TAG, "invalid AE env detector thresh");
|
||||||
|
ESP_RETURN_ON_FALSE(atomic_load(&ae_ctlr->fsm) == ISP_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "controller not in enable state");
|
||||||
|
|
||||||
ae_ctlr->low_thresh = env_thresh->low_thresh;
|
ae_ctlr->low_thresh = env_thresh->low_thresh;
|
||||||
ae_ctlr->high_thresh = env_thresh->high_thresh;
|
ae_ctlr->high_thresh = env_thresh->high_thresh;
|
||||||
@@ -307,7 +297,7 @@ bool IRAM_ATTR esp_isp_ae_isr(isp_proc_handle_t proc, uint32_t ae_events)
|
|||||||
need_yield |= high_task_awake == pdTRUE;
|
need_yield |= high_task_awake == pdTRUE;
|
||||||
|
|
||||||
/* If started continuous sampling, then trigger the next AE sample */
|
/* If started continuous sampling, then trigger the next AE sample */
|
||||||
if (ae_ctlr->fsm == ISP_FSM_START) {
|
if (atomic_load(&ae_ctlr->fsm) == ISP_FSM_START) {
|
||||||
isp_ll_ae_manual_update(ae_ctlr->isp_proc->hal.hw);
|
isp_ll_ae_manual_update(ae_ctlr->isp_proc->hal.hw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -64,7 +64,7 @@ void isp_hal_init(isp_hal_context_t *hal, int isp_id);
|
|||||||
* @param[in] window_id Window ID
|
* @param[in] window_id Window ID
|
||||||
* @param[in] window Window info, see `isp_window_t`
|
* @param[in] window Window info, see `isp_window_t`
|
||||||
*/
|
*/
|
||||||
void isp_hal_af_window_config(const isp_hal_context_t *hal, int window_id, const isp_window_t *window);
|
void isp_hal_af_window_config(isp_hal_context_t *hal, int window_id, const isp_window_t *window);
|
||||||
|
|
||||||
/*---------------------------------------------------------------
|
/*---------------------------------------------------------------
|
||||||
AE
|
AE
|
||||||
@@ -75,7 +75,7 @@ void isp_hal_af_window_config(const isp_hal_context_t *hal, int window_id, const
|
|||||||
* @param[in] hal Context of the HAL layer
|
* @param[in] hal Context of the HAL layer
|
||||||
* @param[in] window Window info, see `isp_window_t`
|
* @param[in] window Window info, see `isp_window_t`
|
||||||
*/
|
*/
|
||||||
void isp_hal_ae_window_config(const isp_hal_context_t *hal, const isp_window_t *window);
|
void isp_hal_ae_window_config(isp_hal_context_t *hal, const isp_window_t *window);
|
||||||
|
|
||||||
/*---------------------------------------------------------------
|
/*---------------------------------------------------------------
|
||||||
INTR
|
INTR
|
||||||
@@ -86,7 +86,7 @@ void isp_hal_ae_window_config(const isp_hal_context_t *hal, const isp_window_t *
|
|||||||
* @param[in] hal Context of the HAL layer
|
* @param[in] hal Context of the HAL layer
|
||||||
* @param[in] mask HW event mask
|
* @param[in] mask HW event mask
|
||||||
*/
|
*/
|
||||||
uint32_t isp_hal_check_clear_intr_event(const isp_hal_context_t *hal, uint32_t mask);
|
uint32_t isp_hal_check_clear_intr_event(isp_hal_context_t *hal, uint32_t mask);
|
||||||
|
|
||||||
/*---------------------------------------------------------------
|
/*---------------------------------------------------------------
|
||||||
BF
|
BF
|
||||||
@@ -112,7 +112,7 @@ void isp_hal_bf_config(isp_hal_context_t *hal, isp_hal_bf_cfg_t *config);
|
|||||||
* - true Set success
|
* - true Set success
|
||||||
* - false Invalid argument
|
* - false Invalid argument
|
||||||
*/
|
*/
|
||||||
bool isp_hal_ccm_set_matrix(const isp_hal_context_t *hal, bool saturation, const float flt_matrix[ISP_CCM_DIMENSION][ISP_CCM_DIMENSION]);
|
bool isp_hal_ccm_set_matrix(isp_hal_context_t *hal, bool saturation, const float flt_matrix[ISP_CCM_DIMENSION][ISP_CCM_DIMENSION]);
|
||||||
|
|
||||||
/*---------------------------------------------------------------
|
/*---------------------------------------------------------------
|
||||||
AWB
|
AWB
|
||||||
@@ -126,7 +126,7 @@ bool isp_hal_ccm_set_matrix(const isp_hal_context_t *hal, bool saturation, const
|
|||||||
* - true Set success
|
* - true Set success
|
||||||
* - false Invalid arg
|
* - false Invalid arg
|
||||||
*/
|
*/
|
||||||
bool isp_hal_awb_set_window_range(const isp_hal_context_t *hal, const isp_window_t *win);
|
bool isp_hal_awb_set_window_range(isp_hal_context_t *hal, const isp_window_t *win);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the luminance range of the white patch
|
* @brief Set the luminance range of the white patch
|
||||||
@@ -138,7 +138,7 @@ bool isp_hal_awb_set_window_range(const isp_hal_context_t *hal, const isp_window
|
|||||||
* - true Set success
|
* - true Set success
|
||||||
* - false Invalid arg
|
* - false Invalid arg
|
||||||
*/
|
*/
|
||||||
bool isp_hal_awb_set_luminance_range(const isp_hal_context_t *hal, uint32_t lum_min, uint32_t lum_max);
|
bool isp_hal_awb_set_luminance_range(isp_hal_context_t *hal, uint32_t lum_min, uint32_t lum_max);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the R/G ratio of the white patch
|
* @brief Set the R/G ratio of the white patch
|
||||||
@@ -149,7 +149,7 @@ bool isp_hal_awb_set_luminance_range(const isp_hal_context_t *hal, uint32_t lum_
|
|||||||
* - true Set success
|
* - true Set success
|
||||||
* - false Invalid arg
|
* - false Invalid arg
|
||||||
*/
|
*/
|
||||||
bool isp_hal_awb_set_rg_ratio_range(const isp_hal_context_t *hal, float rg_min, float rg_max);
|
bool isp_hal_awb_set_rg_ratio_range(isp_hal_context_t *hal, float rg_min, float rg_max);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the B/R ratio of the white patch
|
* @brief Set the B/R ratio of the white patch
|
||||||
@@ -160,7 +160,7 @@ bool isp_hal_awb_set_rg_ratio_range(const isp_hal_context_t *hal, float rg_min,
|
|||||||
* - true Set success
|
* - true Set success
|
||||||
* - false Invalid arg
|
* - false Invalid arg
|
||||||
*/
|
*/
|
||||||
bool isp_hal_awb_set_bg_ratio_range(const isp_hal_context_t *hal, float bg_min, float bg_max);
|
bool isp_hal_awb_set_bg_ratio_range(isp_hal_context_t *hal, float bg_min, float bg_max);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,7 @@ void isp_hal_init(isp_hal_context_t *hal, int isp_id)
|
|||||||
/*---------------------------------------------------------------
|
/*---------------------------------------------------------------
|
||||||
AF
|
AF
|
||||||
---------------------------------------------------------------*/
|
---------------------------------------------------------------*/
|
||||||
void isp_hal_af_window_config(const isp_hal_context_t *hal, int window_id, const isp_window_t *window)
|
void isp_hal_af_window_config(isp_hal_context_t *hal, int window_id, const isp_window_t *window)
|
||||||
{
|
{
|
||||||
isp_ll_af_set_window_range(hal->hw, window_id, window->top_left.x, window->top_left.y, window->btm_right.x, window->btm_right.y);
|
isp_ll_af_set_window_range(hal->hw, window_id, window->top_left.x, window->top_left.y, window->btm_right.x, window->btm_right.y);
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ void isp_hal_bf_config(isp_hal_context_t *hal, isp_hal_bf_cfg_t *config)
|
|||||||
/*---------------------------------------------------------------
|
/*---------------------------------------------------------------
|
||||||
AE
|
AE
|
||||||
---------------------------------------------------------------*/
|
---------------------------------------------------------------*/
|
||||||
void isp_hal_ae_window_config(const isp_hal_context_t *hal, const isp_window_t *window)
|
void isp_hal_ae_window_config(isp_hal_context_t *hal, const isp_window_t *window)
|
||||||
{
|
{
|
||||||
uint32_t ae_x_start = window->top_left.x;
|
uint32_t ae_x_start = window->top_left.x;
|
||||||
uint32_t ae_x_bsize = (window->btm_right.x - window-> top_left.x) / SOC_ISP_AE_BLOCK_X_NUMS;
|
uint32_t ae_x_bsize = (window->btm_right.x - window-> top_left.x) / SOC_ISP_AE_BLOCK_X_NUMS;
|
||||||
@@ -78,7 +78,7 @@ void isp_hal_ae_window_config(const isp_hal_context_t *hal, const isp_window_t *
|
|||||||
/*---------------------------------------------------------------
|
/*---------------------------------------------------------------
|
||||||
INTR, put in iram
|
INTR, put in iram
|
||||||
---------------------------------------------------------------*/
|
---------------------------------------------------------------*/
|
||||||
uint32_t isp_hal_check_clear_intr_event(const isp_hal_context_t *hal, uint32_t mask)
|
uint32_t isp_hal_check_clear_intr_event(isp_hal_context_t *hal, uint32_t mask)
|
||||||
{
|
{
|
||||||
uint32_t triggered_events = isp_ll_get_intr_status(hal->hw) & mask;
|
uint32_t triggered_events = isp_ll_get_intr_status(hal->hw) & mask;
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ uint32_t isp_hal_check_clear_intr_event(const isp_hal_context_t *hal, uint32_t m
|
|||||||
/*---------------------------------------------------------------
|
/*---------------------------------------------------------------
|
||||||
Color Correction Matrix
|
Color Correction Matrix
|
||||||
---------------------------------------------------------------*/
|
---------------------------------------------------------------*/
|
||||||
bool isp_hal_ccm_set_matrix(const isp_hal_context_t *hal, bool saturation, const float flt_matrix[ISP_CCM_DIMENSION][ISP_CCM_DIMENSION])
|
bool isp_hal_ccm_set_matrix(isp_hal_context_t *hal, bool saturation, const float flt_matrix[ISP_CCM_DIMENSION][ISP_CCM_DIMENSION])
|
||||||
{
|
{
|
||||||
isp_ll_ccm_gain_t fp_matrix[ISP_CCM_DIMENSION][ISP_CCM_DIMENSION] = {};
|
isp_ll_ccm_gain_t fp_matrix[ISP_CCM_DIMENSION][ISP_CCM_DIMENSION] = {};
|
||||||
hal_utils_fixed_point_t fp_cfg = {
|
hal_utils_fixed_point_t fp_cfg = {
|
||||||
@@ -116,7 +116,7 @@ bool isp_hal_ccm_set_matrix(const isp_hal_context_t *hal, bool saturation, const
|
|||||||
/*---------------------------------------------------------------
|
/*---------------------------------------------------------------
|
||||||
AWB
|
AWB
|
||||||
---------------------------------------------------------------*/
|
---------------------------------------------------------------*/
|
||||||
bool isp_hal_awb_set_window_range(const isp_hal_context_t *hal, const isp_window_t *win)
|
bool isp_hal_awb_set_window_range(isp_hal_context_t *hal, const isp_window_t *win)
|
||||||
{
|
{
|
||||||
if (win->top_left.x > win->btm_right.x ||
|
if (win->top_left.x > win->btm_right.x ||
|
||||||
win->top_left.y > win->btm_right.y ||
|
win->top_left.y > win->btm_right.y ||
|
||||||
@@ -129,7 +129,7 @@ bool isp_hal_awb_set_window_range(const isp_hal_context_t *hal, const isp_window
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isp_hal_awb_set_luminance_range(const isp_hal_context_t *hal, uint32_t lum_min, uint32_t lum_max)
|
bool isp_hal_awb_set_luminance_range(isp_hal_context_t *hal, uint32_t lum_min, uint32_t lum_max)
|
||||||
{
|
{
|
||||||
if (lum_min > lum_max || lum_max > ISP_LL_AWB_LUM_MAX_RANGE) {
|
if (lum_min > lum_max || lum_max > ISP_LL_AWB_LUM_MAX_RANGE) {
|
||||||
return false;
|
return false;
|
||||||
@@ -138,7 +138,7 @@ bool isp_hal_awb_set_luminance_range(const isp_hal_context_t *hal, uint32_t lum_
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isp_hal_awb_set_rg_ratio_range(const isp_hal_context_t *hal, float rg_min, float rg_max)
|
bool isp_hal_awb_set_rg_ratio_range(isp_hal_context_t *hal, float rg_min, float rg_max)
|
||||||
{
|
{
|
||||||
// Convert to fixed point
|
// Convert to fixed point
|
||||||
isp_ll_awb_rgb_ratio_t fp_rg_min = {};
|
isp_ll_awb_rgb_ratio_t fp_rg_min = {};
|
||||||
@@ -160,7 +160,7 @@ bool isp_hal_awb_set_rg_ratio_range(const isp_hal_context_t *hal, float rg_min,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isp_hal_awb_set_bg_ratio_range(const isp_hal_context_t *hal, float bg_min, float bg_max)
|
bool isp_hal_awb_set_bg_ratio_range(isp_hal_context_t *hal, float bg_min, float bg_max)
|
||||||
{
|
{
|
||||||
// Convert to fixed point
|
// Convert to fixed point
|
||||||
isp_ll_awb_rgb_ratio_t fp_bg_min = {};
|
isp_ll_awb_rgb_ratio_t fp_bg_min = {};
|
||||||
|
@@ -279,6 +279,9 @@ Aside from the above oneshot API, the ISP AE driver also provides a way to start
|
|||||||
|
|
||||||
Note that if you want to use the continuous statistics, you need to register the :cpp:member:`esp_isp_ae_env_detector_evt_cbs_t::on_statistics_done` or :cpp:member:`esp_isp_ae_env_detector_evt_cbs_t::on_change` callback to get the statistics result. See how to register in `Register Event Callbacks <#isp-callback>`__
|
Note that if you want to use the continuous statistics, you need to register the :cpp:member:`esp_isp_ae_env_detector_evt_cbs_t::on_statistics_done` or :cpp:member:`esp_isp_ae_env_detector_evt_cbs_t::on_change` callback to get the statistics result. See how to register in `Register Event Callbacks <#isp-callback>`__
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
When using oneshot statistics, the AE Environment Detector will be temporarily disabled and will automatically recover once the oneshot is complete.
|
||||||
|
|
||||||
.. code:: c
|
.. code:: c
|
||||||
|
|
||||||
esp_isp_ae_config_t ae_config = {
|
esp_isp_ae_config_t ae_config = {
|
||||||
|
Reference in New Issue
Block a user