Skip to content

Commit c91bdda

Browse files
committed
Merge branch 'refactor/isp_af_interrupt_and_callback_v5.3' into 'release/v5.3'
refactor(isp): refactor the interrupt and callback solution (v5.3) See merge request espressif/esp-idf!30565
2 parents f63e544 + dd20d1f commit c91bdda

File tree

12 files changed

+358
-320
lines changed

12 files changed

+358
-320
lines changed

components/esp_driver_isp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set(srcs)
33
set(public_include "include")
44

55
if(CONFIG_SOC_ISP_SUPPORTED)
6-
list(APPEND srcs "src/isp.c"
6+
list(APPEND srcs "src/isp_core.c"
77
"src/isp_af.c")
88
endif()
99

components/esp_driver_isp/include/driver/isp.h

Lines changed: 5 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,84 +4,12 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#pragma once
8-
9-
#include <stdint.h>
10-
#include <stdbool.h>
11-
#include "esp_err.h"
12-
#include "driver/isp_types.h"
13-
#include "driver/isp_af.h"
14-
15-
#ifdef __cplusplus
16-
extern "C" {
17-
#endif
18-
19-
/**
20-
* @brief ISP configurations
21-
*/
22-
typedef struct {
23-
isp_clk_src_t clk_src; ///< Clock source
24-
uint32_t clk_hz; ///< Clock frequency in Hz, suggest twice higher than cam sensor speed
25-
isp_input_data_source_t input_data_source; ///< Input data source
26-
isp_color_t input_data_color_type; ///< Input color type
27-
isp_color_t output_data_color_type; ///< Output color type
28-
bool has_line_start_packet; ///< Enable line start packet
29-
bool has_line_end_packet; ///< Enable line end packet
30-
uint32_t h_res; ///< Input horizontal resolution, i.e. the number of pixels in a line
31-
uint32_t v_res; ///< Input vertical resolution, i.e. the number of lines in a frame
32-
} esp_isp_processor_cfg_t;
33-
34-
/**
35-
* @brief New an ISP processor
36-
*
37-
* @param[in] proc_config Pointer to ISP config. Refer to ``esp_isp_processor_cfg_t``.
38-
* @param[out] ret_proc Processor handle
39-
*
40-
* @return
41-
* - ESP_OK On success
42-
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
43-
* - ESP_ERR_NOT_FOUND No free interrupt found with the specified flags
44-
* - ESP_ERR_NOT_SUPPORTED Not supported mode
45-
* - ESP_ERR_NO_MEM If out of memory
46-
*/
47-
esp_err_t esp_isp_new_processor(const esp_isp_processor_cfg_t *proc_config, isp_proc_handle_t *ret_proc);
48-
497
/**
50-
* @brief Delete an ISP processor
51-
*
52-
* @param[in] proc Processor handle
53-
*
54-
* @return
55-
* - ESP_OK On success
56-
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
57-
* - ESP_ERR_INVALID_STATE Driver state is invalid.
58-
*/
59-
esp_err_t esp_isp_del_processor(isp_proc_handle_t proc);
60-
61-
/**
62-
* @brief Enable an ISP processor
63-
*
64-
* @param[in] proc Processor handle
65-
*
66-
* @return
67-
* - ESP_OK On success
68-
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
69-
* - ESP_ERR_INVALID_STATE Driver state is invalid.
8+
* @brief ISP peripheral contains many submodules, whose drivers are scattered in different header files.
9+
* This header file serves as a prelude, contains every thing that is needed to work with the ISP peripheral.
7010
*/
71-
esp_err_t esp_isp_enable(isp_proc_handle_t proc);
7211

73-
/**
74-
* @brief Disable an ISP processor
75-
*
76-
* @param[in] proc Processor handle
77-
*
78-
* @return
79-
* - ESP_OK On success
80-
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
81-
* - ESP_ERR_INVALID_STATE Driver state is invalid.
82-
*/
83-
esp_err_t esp_isp_disable(isp_proc_handle_t proc);
12+
#pragma once
8413

85-
#ifdef __cplusplus
86-
}
87-
#endif
14+
#include "driver/isp_core.h"
15+
#include "driver/isp_af.h"

components/esp_driver_isp/include/driver/isp_af.h

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
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
1715
extern "C" {
@@ -21,10 +19,9 @@ extern "C" {
2119
* @brief AF controller config
2220
*/
2321
typedef 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);
8077
esp_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
*/
101138
typedef 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
*/
135174
typedef 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
*/
157196
typedef 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
/**
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include <stdint.h>
10+
#include <stdbool.h>
11+
#include "esp_err.h"
12+
#include "driver/isp_types.h"
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
/**
19+
* @brief ISP configurations
20+
*/
21+
typedef struct {
22+
isp_clk_src_t clk_src; ///< Clock source
23+
uint32_t clk_hz; ///< Clock frequency in Hz, suggest twice higher than cam sensor speed
24+
isp_input_data_source_t input_data_source; ///< Input data source
25+
isp_color_t input_data_color_type; ///< Input color type
26+
isp_color_t output_data_color_type; ///< Output color type
27+
bool has_line_start_packet; ///< Enable line start packet
28+
bool has_line_end_packet; ///< Enable line end packet
29+
uint32_t h_res; ///< Input horizontal resolution, i.e. the number of pixels in a line
30+
uint32_t v_res; ///< Input vertical resolution, i.e. the number of lines in a frame
31+
} esp_isp_processor_cfg_t;
32+
33+
/**
34+
* @brief New an ISP processor
35+
*
36+
* @param[in] proc_config Pointer to ISP config. Refer to ``esp_isp_processor_cfg_t``.
37+
* @param[out] ret_proc Processor handle
38+
*
39+
* @return
40+
* - ESP_OK On success
41+
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
42+
* - ESP_ERR_NOT_FOUND No free interrupt found with the specified flags
43+
* - ESP_ERR_NOT_SUPPORTED Not supported mode
44+
* - ESP_ERR_NO_MEM If out of memory
45+
*/
46+
esp_err_t esp_isp_new_processor(const esp_isp_processor_cfg_t *proc_config, isp_proc_handle_t *ret_proc);
47+
48+
/**
49+
* @brief Delete an ISP processor
50+
*
51+
* @param[in] proc Processor handle
52+
*
53+
* @return
54+
* - ESP_OK On success
55+
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
56+
* - ESP_ERR_INVALID_STATE Driver state is invalid.
57+
*/
58+
esp_err_t esp_isp_del_processor(isp_proc_handle_t proc);
59+
60+
/**
61+
* @brief Enable an ISP processor
62+
*
63+
* @param[in] proc Processor handle
64+
*
65+
* @return
66+
* - ESP_OK On success
67+
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
68+
* - ESP_ERR_INVALID_STATE Driver state is invalid.
69+
*/
70+
esp_err_t esp_isp_enable(isp_proc_handle_t proc);
71+
72+
/**
73+
* @brief Disable an ISP processor
74+
*
75+
* @param[in] proc Processor handle
76+
*
77+
* @return
78+
* - ESP_OK On success
79+
* - ESP_ERR_INVALID_ARG If the combination of arguments is invalid.
80+
* - ESP_ERR_INVALID_STATE Driver state is invalid.
81+
*/
82+
esp_err_t esp_isp_disable(isp_proc_handle_t proc);
83+
84+
#ifdef __cplusplus
85+
}
86+
#endif

0 commit comments

Comments
 (0)