From ff9b88d8275fdd3731587cd9e6ef4dccd5a1ed31 Mon Sep 17 00:00:00 2001 From: Armando Date: Mon, 18 Dec 2023 12:06:00 +0800 Subject: [PATCH] feat(isp_af): added af scheme driver and stepping approx scheme driver --- examples/peripherals/.build-test-rules.yml | 8 ++++ .../components/isp_af_schemes/CMakeLists.txt | 10 +++++ .../isp_af_schemes/include/isp_af_scheme.h | 37 +++++++++++++++++ .../interface/isp_af_scheme_interface.h | 41 +++++++++++++++++++ .../isp_af_schemes/src/isp_af_scheme.c | 26 ++++++++++++ .../isp_af_schemes/src/isp_af_scheme_sa.c | 2 +- 6 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 examples/peripherals/isp/auto_focus/components/isp_af_schemes/CMakeLists.txt create mode 100644 examples/peripherals/isp/auto_focus/components/isp_af_schemes/include/isp_af_scheme.h create mode 100644 examples/peripherals/isp/auto_focus/components/isp_af_schemes/interface/isp_af_scheme_interface.h create mode 100644 examples/peripherals/isp/auto_focus/components/isp_af_schemes/src/isp_af_scheme.c diff --git a/examples/peripherals/.build-test-rules.yml b/examples/peripherals/.build-test-rules.yml index 845eaf50c8..9a9fbea719 100644 --- a/examples/peripherals/.build-test-rules.yml +++ b/examples/peripherals/.build-test-rules.yml @@ -117,6 +117,14 @@ examples/peripherals/jpeg/jpeg_decode: - if: SOC_JPEG_CODEC_SUPPORTED != 1 depends_components: - esp_driver_jpeg + +examples/peripherals/isp/auto_focus: + disable: + - if: INCLUDE_DEFAULT == 1 + temporary: true + reason: disable build temporarily # TODO: IDF-8895 + depends_components: + - esp_driver_isp examples/peripherals/lcd/i2c_oled: disable: diff --git a/examples/peripherals/isp/auto_focus/components/isp_af_schemes/CMakeLists.txt b/examples/peripherals/isp/auto_focus/components/isp_af_schemes/CMakeLists.txt new file mode 100644 index 0000000000..cd4946b13c --- /dev/null +++ b/examples/peripherals/isp/auto_focus/components/isp_af_schemes/CMakeLists.txt @@ -0,0 +1,10 @@ +set(srcs) + +list(APPEND srcs "src/isp_af_scheme.c" + "src/isp_af_scheme_sa.c") + +set(priv_requires "esp_driver_isp") + +idf_component_register(SRCS ${srcs} + INCLUDE_DIRS "include" "interface" + PRIV_REQUIRES ${priv_requires}) diff --git a/examples/peripherals/isp/auto_focus/components/isp_af_schemes/include/isp_af_scheme.h b/examples/peripherals/isp/auto_focus/components/isp_af_schemes/include/isp_af_scheme.h new file mode 100644 index 0000000000..1926c484fd --- /dev/null +++ b/examples/peripherals/isp/auto_focus/components/isp_af_schemes/include/isp_af_scheme.h @@ -0,0 +1,37 @@ +/* + * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include "sdkconfig.h" +#include "esp_err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Type of ISP AF scheme handle + */ +typedef struct isp_af_scheme_t *isp_af_scheme_handle_t; + +/** + * @brief ISP AF process, which is used to calculate definition threshold and luminance threshold for AF environment detector to detect environment change + * + * @param[in] scheme AF scheme handle + * @param[out] out_definition_thresh Calculated definition threshold + * @param[out] out_luminance_thresh Calculated luminance threshold + * + * @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 isp_af_process(isp_af_scheme_handle_t scheme, int *out_definition_thresh, int *out_luminance_thresh); + +#ifdef __cplusplus +} +#endif diff --git a/examples/peripherals/isp/auto_focus/components/isp_af_schemes/interface/isp_af_scheme_interface.h b/examples/peripherals/isp/auto_focus/components/isp_af_schemes/interface/isp_af_scheme_interface.h new file mode 100644 index 0000000000..78b157ce33 --- /dev/null +++ b/examples/peripherals/isp/auto_focus/components/isp_af_schemes/interface/isp_af_scheme_interface.h @@ -0,0 +1,41 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#pragma once + +#include +#include "esp_err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct isp_af_scheme_t isp_af_scheme_t; + +/** + * @brief ISP AF Scheme Interface + */ +struct isp_af_scheme_t { + /** + * @brief Do AF + * + * @param[in] arg ISP AF scheme specific context + * @param[out] definition_thresh Definition thresh that is updated according to the current definition, this can be used to set to the ISP AF Env detector + * @param[out] luminance_thresh Luminance thresh that is updated according to the current luminance, this can be used to set to the ISP AF Env detector + * + * @return + */ + esp_err_t (*af_process)(void *arg, int *out_definition_thresh, int *out_luminance_thresh); + + /** + * @brief ISP AF scheme specific contexts + * Can be customized to difference AF schemes + */ + void *ctx; +}; + +#ifdef __cplusplus +} +#endif diff --git a/examples/peripherals/isp/auto_focus/components/isp_af_schemes/src/isp_af_scheme.c b/examples/peripherals/isp/auto_focus/components/isp_af_schemes/src/isp_af_scheme.c new file mode 100644 index 0000000000..8f038cbf3e --- /dev/null +++ b/examples/peripherals/isp/auto_focus/components/isp_af_schemes/src/isp_af_scheme.c @@ -0,0 +1,26 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "esp_types.h" +#include "sdkconfig.h" +#include "esp_err.h" +#include "esp_log.h" +#include "esp_check.h" +#include "esp_heap_caps.h" +#include "isp_af_scheme.h" +#include "isp_af_scheme_interface.h" + +const static char *TAG = "AF_SCHEME"; + +esp_err_t isp_af_process(isp_af_scheme_handle_t scheme, int *out_definition_thresh, int *out_luminance_thresh) +{ + ESP_RETURN_ON_FALSE(scheme, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer"); + ESP_RETURN_ON_FALSE(scheme->ctx, ESP_ERR_INVALID_STATE, TAG, "no scheme registered, create a scheme first"); + + return scheme->af_process(scheme->ctx, out_definition_thresh, out_luminance_thresh); +} diff --git a/examples/peripherals/isp/auto_focus/components/isp_af_schemes/src/isp_af_scheme_sa.c b/examples/peripherals/isp/auto_focus/components/isp_af_schemes/src/isp_af_scheme_sa.c index 094ae4df46..516782695d 100644 --- a/examples/peripherals/isp/auto_focus/components/isp_af_schemes/src/isp_af_scheme_sa.c +++ b/examples/peripherals/isp/auto_focus/components/isp_af_schemes/src/isp_af_scheme_sa.c @@ -136,7 +136,7 @@ static esp_err_t s_af_process(void *arg, int *out_definition_thresh, int *out_lu af_current_best = af_current; } - ESP_LOGV(TAG, "af_sum: %d, af_current: %d.%d", af_sum, (int)af_current, (int)((int)(af_current * 1000) % 1000)); + ESP_LOGV(TAG, "af_sum: %"PRId32", af_current: %"PRId32".%"PRId32, af_sum, (int)af_current, (int)((int)(af_current * 1000) % 1000)); } // second search