1010#include <stdbool.h>
1111#include "esp_err.h"
1212#include "driver/isp_types.h"
13- #include "driver/isp.h"
14- #include "soc/soc_caps.h"
1513
1614#ifdef __cplusplus
1715extern "C" {
@@ -21,10 +19,9 @@ extern "C" {
2119 * @brief AF controller config
2220 */
2321typedef struct {
24- #if SOC_ISP_AF_WINDOW_NUMS
25- isp_af_window_t window [SOC_ISP_AF_WINDOW_NUMS ]; ///< AF window settings
26- #endif
22+ isp_af_window_t window [ISP_AF_WINDOW_NUM ]; ///< The sampling windows of AF
2723 int edge_thresh ; ///< Edge threshold, definition higher than this value will be counted as a valid pixel for calculating AF result
24+ int intr_priority ; ///< The interrupt priority, range 0~7, if set to 0, the driver will try to allocate an interrupt with a relative low priority (1,2,3) otherwise the larger the higher, 7 is NMI
2825} esp_isp_af_config_t ;
2926
3027/**
@@ -80,17 +77,57 @@ esp_err_t esp_isp_af_controller_enable(isp_af_ctrlr_t af_ctrlr);
8077esp_err_t esp_isp_af_controller_disable (isp_af_ctrlr_t af_ctrlr );
8178
8279/**
83- * @brief Get AF result
80+ * @brief Trigger AF luminance and definition statistics for one time and get the result
81+ * @note This function is a synchronous and block function,
82+ * it only returns when AF luminance and definition statistics is done or timeout.
83+ * It's a simple method to get the result directly for one time.
84+ *
85+ * @param[in] af_ctrlr AF controller handle
86+ * @param[in] timeout_ms Timeout in millisecond
87+ * - timeout_ms < 0: Won't return until finished
88+ * - timeout_ms = 0: No timeout, trigger one time statistics and return immediately,
89+ * in this case, the result won't be assigned in this function,
90+ * but you can get the result in the callback `esp_isp_af_env_detector_evt_cbs_t::on_env_statistics_done`
91+ * - timeout_ms > 0: Wait for specified milliseconds, if not finished, then return timeout error
92+ * @param[out] out_res AF luminance and definition statistics result, can be NULL if `timeout_ms = 0`
93+ *
94+ * @return
95+ * - ESP_OK On success
96+ * - ESP_ERR_TIMEOUT If the waiting time exceeds the specified timeout.
97+ * - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
98+ * - ESP_ERR_INVALID_STATE Driver state is invalid.
99+ */
100+ esp_err_t esp_isp_af_controller_get_oneshot_statistics (isp_af_ctrlr_t af_ctrlr , int timeout_ms , isp_af_result_t * out_res );
101+
102+ /** @cond */
103+ #define esp_isp_af_controller_get_oneshot_result (af_ctrlr , out_res ) \
104+ esp_isp_af_controller_get_oneshot_statistics(af_ctrlr, -1, out_res) // Alias
105+ /** @endcond */
106+
107+ /**
108+ * @brief Start AF continuous statistics of the luminance and definition in the windows
109+ * @note This function is an asynchronous and non-block function,
110+ * it will start the continuous statistics and return immediately.
111+ * You have to register the AF callback and get the result from the callback event data.
84112 *
85113 * @param[in] af_ctrlr AF controller handle
86- * @param[out] out_res AF result
114+ * @return
115+ * - ESP_OK On success
116+ * - ESP_ERR_INVALID_ARG Null pointer
117+ * - ESP_ERR_INVALID_STATE Driver state is invalid.
118+ */
119+ esp_err_t esp_isp_af_controller_start_continuous_statistics (isp_af_ctrlr_t af_ctrlr );
120+
121+ /**
122+ * @brief Stop AF continuous statistics of the luminance and definition in the windows
87123 *
124+ * @param[in] af_ctrlr AF controller handle
88125 * @return
89126 * - ESP_OK On success
90- * - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
127+ * - ESP_ERR_INVALID_ARG Null pointer
91128 * - ESP_ERR_INVALID_STATE Driver state is invalid.
92129 */
93- esp_err_t esp_isp_af_controller_get_oneshot_result (isp_af_ctrlr_t af_ctrlr , isp_af_result_t * out_res );
130+ esp_err_t esp_isp_af_controller_stop_continuous_statistics (isp_af_ctrlr_t af_ctrlr );
94131
95132/*---------------------------------------------
96133 AF Env Monitor
@@ -99,7 +136,9 @@ esp_err_t esp_isp_af_controller_get_oneshot_result(isp_af_ctrlr_t af_ctrlr, isp_
99136 * @brief AF environment detector config
100137 */
101138typedef struct {
102- int interval ; ///< Interval between environment detection, in frames
139+ int interval ; /*!< Interval between environment detection, in frames.
140+ * i.e., AF controller will trigger the statistic periodically to detect the environment change.
141+ */
103142} esp_isp_af_env_config_t ;
104143
105144/**
@@ -133,7 +172,7 @@ esp_err_t esp_isp_af_controller_set_env_detector_threshold(isp_af_ctrlr_t af_ctr
133172 * @brief Event data structure
134173 */
135174typedef struct {
136- //empty for future proof
175+ isp_af_result_t af_result ; /*!< The AF statistics result */
137176} esp_isp_af_env_detector_evt_data_t ;
138177
139178/**
@@ -155,7 +194,8 @@ typedef bool (*esp_isp_af_env_detector_callback_t)(isp_af_ctrlr_t af_ctrlr, cons
155194 * Involved variables should be in internal RAM as well.
156195 */
157196typedef struct {
158- esp_isp_af_env_detector_callback_t on_env_change ; ///< Event callback, invoked when environment change happens.
197+ esp_isp_af_env_detector_callback_t on_env_statistics_done ; ///< Event callback, invoked when environment sample done.
198+ esp_isp_af_env_detector_callback_t on_env_change ; ///< Event callback, invoked when environment change happens.
159199} esp_isp_af_env_detector_evt_cbs_t ;
160200
161201/**
0 commit comments