mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-11 21:10:20 +00:00
refactor(isp): refactor the interrupt and callback solution
- Added async API - Replaced the polling API - Supported one more callback and event data
This commit is contained in:
@@ -4,84 +4,12 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief ISP peripheral contains many submodules, whose drivers are scattered in different header files.
|
||||
* This header file serves as a prelude, contains every thing that is needed to work with the ISP peripheral.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
#include "driver/isp_types.h"
|
||||
#include "driver/isp_core.h"
|
||||
#include "driver/isp_af.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief ISP configurations
|
||||
*/
|
||||
typedef struct {
|
||||
isp_clk_src_t clk_src; ///< Clock source
|
||||
uint32_t clk_hz; ///< Clock frequency in Hz, suggest twice higher than cam sensor speed
|
||||
isp_input_data_source_t input_data_source; ///< Input data source
|
||||
isp_color_t input_data_color_type; ///< Input color type
|
||||
isp_color_t output_data_color_type; ///< Output color type
|
||||
bool has_line_start_packet; ///< Enable line start packet
|
||||
bool has_line_end_packet; ///< Enable line end packet
|
||||
uint32_t h_res; ///< Input horizontal resolution, i.e. the number of pixels in a line
|
||||
uint32_t v_res; ///< Input vertical resolution, i.e. the number of lines in a frame
|
||||
} esp_isp_processor_cfg_t;
|
||||
|
||||
/**
|
||||
* @brief New an ISP processor
|
||||
*
|
||||
* @param[in] proc_config Pointer to ISP config. Refer to ``esp_isp_processor_cfg_t``.
|
||||
* @param[out] ret_proc Processor handle
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
|
||||
* - ESP_ERR_NOT_FOUND No free interrupt found with the specified flags
|
||||
* - ESP_ERR_NOT_SUPPORTED Not supported mode
|
||||
* - ESP_ERR_NO_MEM If out of memory
|
||||
*/
|
||||
esp_err_t esp_isp_new_processor(const esp_isp_processor_cfg_t *proc_config, isp_proc_handle_t *ret_proc);
|
||||
|
||||
/**
|
||||
* @brief Delete an ISP processor
|
||||
*
|
||||
* @param[in] proc Processor handle
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
|
||||
* - ESP_ERR_INVALID_STATE Driver state is invalid.
|
||||
*/
|
||||
esp_err_t esp_isp_del_processor(isp_proc_handle_t proc);
|
||||
|
||||
/**
|
||||
* @brief Enable an ISP processor
|
||||
*
|
||||
* @param[in] proc Processor handle
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
|
||||
* - ESP_ERR_INVALID_STATE Driver state is invalid.
|
||||
*/
|
||||
esp_err_t esp_isp_enable(isp_proc_handle_t proc);
|
||||
|
||||
/**
|
||||
* @brief Disable an ISP processor
|
||||
*
|
||||
* @param[in] proc Processor handle
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
|
||||
* - ESP_ERR_INVALID_STATE Driver state is invalid.
|
||||
*/
|
||||
esp_err_t esp_isp_disable(isp_proc_handle_t proc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -10,8 +10,6 @@
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
#include "driver/isp_types.h"
|
||||
#include "driver/isp.h"
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -21,10 +19,9 @@ extern "C" {
|
||||
* @brief AF controller config
|
||||
*/
|
||||
typedef struct {
|
||||
#if SOC_ISP_AF_WINDOW_NUMS
|
||||
isp_af_window_t window[SOC_ISP_AF_WINDOW_NUMS]; ///< AF window settings
|
||||
#endif
|
||||
isp_af_window_t window[ISP_AF_WINDOW_NUM]; ///< The sampling windows of AF
|
||||
int edge_thresh; ///< Edge threshold, definition higher than this value will be counted as a valid pixel for calculating AF result
|
||||
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
|
||||
} esp_isp_af_config_t;
|
||||
|
||||
/**
|
||||
@@ -80,17 +77,57 @@ esp_err_t esp_isp_af_controller_enable(isp_af_ctrlr_t af_ctrlr);
|
||||
esp_err_t esp_isp_af_controller_disable(isp_af_ctrlr_t af_ctrlr);
|
||||
|
||||
/**
|
||||
* @brief Get AF result
|
||||
* @brief Trigger AF luminance and definition statistics for one time and get the result
|
||||
* @note This function is a synchronous and block function,
|
||||
* it only returns when AF luminance and definition statistics is done or timeout.
|
||||
* It's a simple method to get the result directly for one time.
|
||||
*
|
||||
* @param[in] af_ctrlr AF controller handle
|
||||
* @param[out] out_res AF result
|
||||
* @param[in] af_ctrlr AF controller handle
|
||||
* @param[in] timeout_ms Timeout in millisecond
|
||||
* - timeout_ms < 0: Won't return until finished
|
||||
* - timeout_ms = 0: No timeout, trigger one time statistics and return immediately,
|
||||
* in this case, the result won't be assigned in this function,
|
||||
* but you can get the result in the callback `esp_isp_af_env_detector_evt_cbs_t::on_env_statistics_done`
|
||||
* - timeout_ms > 0: Wait for specified milliseconds, if not finished, then return timeout error
|
||||
* @param[out] out_res AF luminance and definition statistics result, can be NULL if `timeout_ms = 0`
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_TIMEOUT If the waiting time exceeds the specified timeout.
|
||||
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
|
||||
* - ESP_ERR_INVALID_STATE Driver state is invalid.
|
||||
*/
|
||||
esp_err_t esp_isp_af_controller_get_oneshot_result(isp_af_ctrlr_t af_ctrlr, isp_af_result_t *out_res);
|
||||
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);
|
||||
|
||||
/** @cond */
|
||||
#define esp_isp_af_controller_get_oneshot_result(af_ctrlr, out_res) \
|
||||
esp_isp_af_controller_get_oneshot_statistics(af_ctrlr, -1, out_res) // Alias
|
||||
/** @endcond */
|
||||
|
||||
/**
|
||||
* @brief Start AF continuous statistics of the luminance and definition in the windows
|
||||
* @note This function is an asynchronous and non-block function,
|
||||
* it will start the continuous statistics and return immediately.
|
||||
* You have to register the AF callback and get the result from the callback event data.
|
||||
*
|
||||
* @param[in] af_ctrlr AF controller handle
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG Null pointer
|
||||
* - ESP_ERR_INVALID_STATE Driver state is invalid.
|
||||
*/
|
||||
esp_err_t esp_isp_af_controller_start_continuous_statistics(isp_af_ctrlr_t af_ctrlr);
|
||||
|
||||
/**
|
||||
* @brief Stop AF continuous statistics of the luminance and definition in the windows
|
||||
*
|
||||
* @param[in] af_ctrlr AF controller handle
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG Null pointer
|
||||
* - ESP_ERR_INVALID_STATE Driver state is invalid.
|
||||
*/
|
||||
esp_err_t esp_isp_af_controller_stop_continuous_statistics(isp_af_ctrlr_t af_ctrlr);
|
||||
|
||||
/*---------------------------------------------
|
||||
AF Env Monitor
|
||||
@@ -99,7 +136,9 @@ esp_err_t esp_isp_af_controller_get_oneshot_result(isp_af_ctrlr_t af_ctrlr, isp_
|
||||
* @brief AF environment detector config
|
||||
*/
|
||||
typedef struct {
|
||||
int interval; ///< Interval between environment detection, in frames
|
||||
int interval; /*!< Interval between environment detection, in frames.
|
||||
* i.e., AF controller will trigger the statistic periodically to detect the environment change.
|
||||
*/
|
||||
} esp_isp_af_env_config_t;
|
||||
|
||||
/**
|
||||
@@ -133,7 +172,7 @@ esp_err_t esp_isp_af_controller_set_env_detector_threshold(isp_af_ctrlr_t af_ctr
|
||||
* @brief Event data structure
|
||||
*/
|
||||
typedef struct {
|
||||
//empty for future proof
|
||||
isp_af_result_t af_result; /*!< The AF statistics result */
|
||||
} esp_isp_af_env_detector_evt_data_t;
|
||||
|
||||
/**
|
||||
@@ -155,7 +194,8 @@ typedef bool (*esp_isp_af_env_detector_callback_t)(isp_af_ctrlr_t af_ctrlr, cons
|
||||
* Involved variables should be in internal RAM as well.
|
||||
*/
|
||||
typedef struct {
|
||||
esp_isp_af_env_detector_callback_t on_env_change; ///< Event callback, invoked when environment change happens.
|
||||
esp_isp_af_env_detector_callback_t on_env_statistics_done; ///< Event callback, invoked when environment sample done.
|
||||
esp_isp_af_env_detector_callback_t on_env_change; ///< Event callback, invoked when environment change happens.
|
||||
} esp_isp_af_env_detector_evt_cbs_t;
|
||||
|
||||
/**
|
||||
|
86
components/esp_driver_isp/include/driver/isp_core.h
Normal file
86
components/esp_driver_isp/include/driver/isp_core.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
#include "driver/isp_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief ISP configurations
|
||||
*/
|
||||
typedef struct {
|
||||
isp_clk_src_t clk_src; ///< Clock source
|
||||
uint32_t clk_hz; ///< Clock frequency in Hz, suggest twice higher than cam sensor speed
|
||||
isp_input_data_source_t input_data_source; ///< Input data source
|
||||
isp_color_t input_data_color_type; ///< Input color type
|
||||
isp_color_t output_data_color_type; ///< Output color type
|
||||
bool has_line_start_packet; ///< Enable line start packet
|
||||
bool has_line_end_packet; ///< Enable line end packet
|
||||
uint32_t h_res; ///< Input horizontal resolution, i.e. the number of pixels in a line
|
||||
uint32_t v_res; ///< Input vertical resolution, i.e. the number of lines in a frame
|
||||
} esp_isp_processor_cfg_t;
|
||||
|
||||
/**
|
||||
* @brief New an ISP processor
|
||||
*
|
||||
* @param[in] proc_config Pointer to ISP config. Refer to ``esp_isp_processor_cfg_t``.
|
||||
* @param[out] ret_proc Processor handle
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
|
||||
* - ESP_ERR_NOT_FOUND No free interrupt found with the specified flags
|
||||
* - ESP_ERR_NOT_SUPPORTED Not supported mode
|
||||
* - ESP_ERR_NO_MEM If out of memory
|
||||
*/
|
||||
esp_err_t esp_isp_new_processor(const esp_isp_processor_cfg_t *proc_config, isp_proc_handle_t *ret_proc);
|
||||
|
||||
/**
|
||||
* @brief Delete an ISP processor
|
||||
*
|
||||
* @param[in] proc Processor handle
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
|
||||
* - ESP_ERR_INVALID_STATE Driver state is invalid.
|
||||
*/
|
||||
esp_err_t esp_isp_del_processor(isp_proc_handle_t proc);
|
||||
|
||||
/**
|
||||
* @brief Enable an ISP processor
|
||||
*
|
||||
* @param[in] proc Processor handle
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
|
||||
* - ESP_ERR_INVALID_STATE Driver state is invalid.
|
||||
*/
|
||||
esp_err_t esp_isp_enable(isp_proc_handle_t proc);
|
||||
|
||||
/**
|
||||
* @brief Disable an ISP processor
|
||||
*
|
||||
* @param[in] proc Processor handle
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
|
||||
* - ESP_ERR_INVALID_STATE Driver state is invalid.
|
||||
*/
|
||||
esp_err_t esp_isp_disable(isp_proc_handle_t proc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user