From b774bd1457bb15544c4c3e9f018ffd76767928d5 Mon Sep 17 00:00:00 2001 From: Armando Date: Sun, 8 Oct 2023 10:35:52 +0800 Subject: [PATCH] refactor(esp_adc): reformat code with astyle_py --- components/esp_adc/adc_cali.c | 1 - components/esp_adc/adc_cali_curve_fitting.c | 1 - components/esp_adc/adc_common.c | 1 - components/esp_adc/adc_continuous.c | 4 +- components/esp_adc/adc_continuous_internal.h | 1 - components/esp_adc/adc_filter.c | 8 +-- components/esp_adc/adc_monitor.c | 1 - components/esp_adc/adc_oneshot.c | 12 +--- .../esp_adc/curve_fitting_coefficients.h | 2 +- .../deprecated/esp32/esp_adc_cal_legacy.c | 14 +++-- .../deprecated/esp32c3/esp_adc_cal_legacy.c | 31 +++++------ .../deprecated/esp32s2/esp_adc_cal_legacy.c | 20 +++---- .../deprecated/esp32s3/esp_adc_cal_legacy.c | 55 +++++++++---------- .../deprecated/esp_adc_cal_common_legacy.c | 3 +- .../deprecated/esp_adc_cal_internal_legacy.h | 3 +- .../include/esp_adc_cal_types_legacy.h | 1 - .../esp_adc/esp32/adc_cali_line_fitting.c | 22 +++----- .../esp_adc/esp32c2/adc_cali_line_fitting.c | 4 -- .../esp32c3/curve_fitting_coefficients.c | 20 +++---- .../esp32c6/curve_fitting_coefficients.c | 3 +- .../esp_adc/esp32s2/adc_cali_line_fitting.c | 31 ++++------- .../esp32s3/curve_fitting_coefficients.c | 40 +++++++------- components/esp_adc/include/esp_adc/adc_cali.h | 1 - .../esp_adc/include/esp_adc/adc_cali_scheme.h | 2 - .../esp_adc/include/esp_adc/adc_continuous.h | 2 - .../esp_adc/include/esp_adc/adc_filter.h | 1 - .../esp_adc/include/esp_adc/adc_monitor.h | 2 - .../esp_adc/include/esp_private/adc_private.h | 4 -- .../esp_adc/interface/adc_cali_interface.h | 1 - .../esp_adc/test_apps/adc/main/test_adc.c | 25 ++++----- .../test_apps/adc/main/test_adc_driver.c | 15 ++--- .../test_apps/adc/main/test_adc_driver_iram.c | 5 +- .../test_apps/adc/main/test_adc_performance.c | 23 ++++---- .../test_apps/adc/main/test_common_adc.c | 7 +-- .../test_apps/adc/main/test_common_adc.h | 2 - tools/ci/astyle-rules.yml | 1 - 36 files changed, 152 insertions(+), 217 deletions(-) diff --git a/components/esp_adc/adc_cali.c b/components/esp_adc/adc_cali.c index 4b5b4e26aa..89558f28d7 100644 --- a/components/esp_adc/adc_cali.c +++ b/components/esp_adc/adc_cali.c @@ -18,7 +18,6 @@ const __attribute__((unused)) static char *TAG = "adc_cali"; - esp_err_t adc_cali_check_scheme(adc_cali_scheme_ver_t *scheme_mask) { ESP_RETURN_ON_FALSE(scheme_mask, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer"); diff --git a/components/esp_adc/adc_cali_curve_fitting.c b/components/esp_adc/adc_cali_curve_fitting.c index dbdfab4783..919614a5fc 100644 --- a/components/esp_adc/adc_cali_curve_fitting.c +++ b/components/esp_adc/adc_cali_curve_fitting.c @@ -178,7 +178,6 @@ static void calc_first_step_coefficients(const adc_calib_info_t *parsed_data, ca ESP_LOGV(TAG, "Calib V1, Cal Voltage = %" PRId32 ", Digi out = %" PRId32 ", Coef_a = %" PRId32, parsed_data->ref_data.ver1.voltage, parsed_data->ref_data.ver1.digi, ctx->chars_first_step.coeff_a); } - static int32_t get_reading_error(uint64_t v_cali_1, const cali_chars_second_step_t *param) { if (v_cali_1 == 0 || param->term_num == 0) { diff --git a/components/esp_adc/adc_common.c b/components/esp_adc/adc_common.c index c7f4e10029..4a2da9625b 100644 --- a/components/esp_adc/adc_common.c +++ b/components/esp_adc/adc_common.c @@ -17,7 +17,6 @@ #include "hal/adc_hal_common.h" #include "soc/adc_periph.h" - static const char *TAG = "adc_common"; static portMUX_TYPE s_spinlock = portMUX_INITIALIZER_UNLOCKED; extern portMUX_TYPE rtc_spinlock; diff --git a/components/esp_adc/adc_continuous.c b/components/esp_adc/adc_continuous.c index ebaf348003..a52799210d 100644 --- a/components/esp_adc/adc_continuous.c +++ b/components/esp_adc/adc_continuous.c @@ -197,7 +197,7 @@ esp_err_t adc_continuous_new_handle(const adc_continuous_handle_cfg_t *hdl_confi } ret = esp_intr_alloc(spicommon_irqdma_source_for_host(adc_ctx->spi_host), ESP_INTR_FLAG_IRAM, adc_dma_intr_handler, - (void *)adc_ctx, &adc_ctx->dma_intr_hdl); + (void *)adc_ctx, &adc_ctx->dma_intr_hdl); if (ret != ESP_OK) { goto cleanup; } @@ -213,7 +213,7 @@ esp_err_t adc_continuous_new_handle(const adc_continuous_handle_cfg_t *hdl_confi adc_ctx->i2s_host = I2S_NUM_0; ret = esp_intr_alloc(i2s_periph_signal[adc_ctx->i2s_host].irq, ESP_INTR_FLAG_IRAM, adc_dma_intr_handler, - (void *)adc_ctx, &adc_ctx->dma_intr_hdl); + (void *)adc_ctx, &adc_ctx->dma_intr_hdl); if (ret != ESP_OK) { goto cleanup; } diff --git a/components/esp_adc/adc_continuous_internal.h b/components/esp_adc/adc_continuous_internal.h index 3673cf6833..e78787ba97 100644 --- a/components/esp_adc/adc_continuous_internal.h +++ b/components/esp_adc/adc_continuous_internal.h @@ -106,7 +106,6 @@ struct adc_continuous_ctx_t { #endif }; - #ifdef __cplusplus } #endif diff --git a/components/esp_adc/adc_filter.c b/components/esp_adc/adc_filter.c index 672b5acd5a..da8ead99ea 100644 --- a/components/esp_adc/adc_filter.c +++ b/components/esp_adc/adc_filter.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2016-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -20,13 +20,12 @@ static const char *TAG = "adc_filter"; static portMUX_TYPE s_filter_spinlock = portMUX_INITIALIZER_UNLOCKED; - #if SOC_ADC_DIG_IIR_FILTER_UNIT_BINDED static atomic_bool s_adc_filter_claimed[SOC_ADC_DIGI_IIR_FILTER_NUM] = {ATOMIC_VAR_INIT(false), #if (SOC_ADC_DIGI_IIR_FILTER_NUM >= 2) -ATOMIC_VAR_INIT(false) + ATOMIC_VAR_INIT(false) #endif -}; + }; static esp_err_t s_adc_filter_claim(adc_continuous_handle_t handle, adc_iir_filter_t *filter_ctx, adc_unit_t unit) { @@ -87,7 +86,6 @@ static esp_err_t s_adc_filter_free(adc_iir_filter_t *filter_ctx) } #endif - esp_err_t adc_new_continuous_iir_filter(adc_continuous_handle_t handle, const adc_continuous_iir_filter_config_t *config, adc_iir_filter_handle_t *ret_hdl) { esp_err_t ret = ESP_FAIL; diff --git a/components/esp_adc/adc_monitor.c b/components/esp_adc/adc_monitor.c index 75ceaf4674..8bdeeddd85 100644 --- a/components/esp_adc/adc_monitor.c +++ b/components/esp_adc/adc_monitor.c @@ -28,7 +28,6 @@ typedef struct adc_monitor_platform_t { // Global context of adc monitor, other member will be lazy loaded static adc_monitor_platform_t s_adc_monitor_platform = {.monitor_spinlock = portMUX_INITIALIZER_UNLOCKED}; - #if CONFIG_IDF_TARGET_ESP32S2 // Monitor unit index need equal to ADC unit index on ESP32S2 static atomic_bool s_adc_monitor_claimed[SOC_ADC_DIGI_MONITOR_NUM] = {}; diff --git a/components/esp_adc/adc_oneshot.c b/components/esp_adc/adc_oneshot.c index 84b3cd3323..dba3fd6b1c 100644 --- a/components/esp_adc/adc_oneshot.c +++ b/components/esp_adc/adc_oneshot.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -25,18 +25,15 @@ #include "hal/adc_ll.h" #include "soc/adc_periph.h" - #if CONFIG_ADC_ONESHOT_CTRL_FUNC_IN_IRAM #define ADC_MEM_ALLOC_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT) #else #define ADC_MEM_ALLOC_CAPS MALLOC_CAP_DEFAULT #endif - extern portMUX_TYPE rtc_spinlock; static const char *TAG = "adc_oneshot"; - typedef struct adc_oneshot_unit_ctx_t { adc_oneshot_hal_ctx_t hal; uint32_t unit_id; @@ -49,20 +46,17 @@ typedef struct adc_oneshot_ctx_t { int apb_periph_ref_cnts; //For the chips that ADC oneshot mode using APB_SARADC periph } adc_oneshot_ctx_t; - static adc_oneshot_ctx_t s_ctx; //ADC oneshot mode context static atomic_bool s_adc_unit_claimed[SOC_ADC_PERIPH_NUM] = {ATOMIC_VAR_INIT(false), #if (SOC_ADC_PERIPH_NUM >= 2) -ATOMIC_VAR_INIT(false) + ATOMIC_VAR_INIT(false) #endif -}; - + }; static bool s_adc_unit_claim(adc_unit_t unit); static bool s_adc_unit_free(adc_unit_t unit); static esp_err_t s_adc_io_init(adc_unit_t unit, adc_channel_t channel); - esp_err_t adc_oneshot_io_to_channel(int io_num, adc_unit_t * const unit_id, adc_channel_t * const channel) { return adc_io_to_channel(io_num, unit_id, channel); diff --git a/components/esp_adc/curve_fitting_coefficients.h b/components/esp_adc/curve_fitting_coefficients.h index 9c35d724b5..a4620237ad 100644 --- a/components/esp_adc/curve_fitting_coefficients.h +++ b/components/esp_adc/curve_fitting_coefficients.h @@ -15,7 +15,7 @@ extern "C" { typedef struct { uint8_t term_num; ///< Term number of the algorithm formula const uint64_t (*coeff)[2]; ///< Coeff of each term. See `adc_error_coef_atten` for details (and the magic number 2) - const int32_t (*sign); ///< Sign of each term + const int32_t (*sign); ///< Sign of each term } cali_chars_second_step_t; /** diff --git a/components/esp_adc/deprecated/esp32/esp_adc_cal_legacy.c b/components/esp_adc/deprecated/esp32/esp_adc_cal_legacy.c index 58cd8476cb..08603733d1 100644 --- a/components/esp_adc/deprecated/esp32/esp_adc_cal_legacy.c +++ b/components/esp_adc/deprecated/esp32/esp_adc_cal_legacy.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -85,13 +85,17 @@ static const uint32_t adc2_vref_atten_offset[4] = {63, 66, 89, 128}; //20 Point lookup tables, covering ADC readings from 2880 to 4096, step size of 64 static const uint32_t lut_adc1_low[LUT_POINTS] = {2240, 2297, 2352, 2405, 2457, 2512, 2564, 2616, 2664, 2709, - 2754, 2795, 2832, 2868, 2903, 2937, 2969, 3000, 3030, 3060}; + 2754, 2795, 2832, 2868, 2903, 2937, 2969, 3000, 3030, 3060 + }; static const uint32_t lut_adc1_high[LUT_POINTS] = {2667, 2706, 2745, 2780, 2813, 2844, 2873, 2901, 2928, 2956, - 2982, 3006, 3032, 3059, 3084, 3110, 3135, 3160, 3184, 3209}; + 2982, 3006, 3032, 3059, 3084, 3110, 3135, 3160, 3184, 3209 + }; static const uint32_t lut_adc2_low[LUT_POINTS] = {2238, 2293, 2347, 2399, 2451, 2507, 2561, 2613, 2662, 2710, - 2754, 2792, 2831, 2869, 2904, 2937, 2968, 2999, 3029, 3059}; + 2754, 2792, 2831, 2869, 2904, 2937, 2968, 2999, 3029, 3059 + }; static const uint32_t lut_adc2_high[LUT_POINTS] = {2657, 2698, 2738, 2774, 2807, 2838, 2867, 2894, 2921, 2946, - 2971, 2996, 3020, 3043, 3067, 3092, 3116, 3139, 3162, 3185}; + 2971, 2996, 3020, 3043, 3067, 3092, 3116, 3139, 3162, 3185 + }; /* ----------------------- EFuse Access Functions --------------------------- */ static bool check_efuse_vref(void) diff --git a/components/esp_adc/deprecated/esp32c3/esp_adc_cal_legacy.c b/components/esp_adc/deprecated/esp32c3/esp_adc_cal_legacy.c index 1755344799..74213defc9 100644 --- a/components/esp_adc/deprecated/esp32c3/esp_adc_cal_legacy.c +++ b/components/esp_adc/deprecated/esp32c3/esp_adc_cal_legacy.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -20,7 +20,6 @@ const static char LOG_TAG[] = "ADC_CALI"; - /* ------------------------ Characterization Constants ---------------------- */ // coeff_a is actually a float number @@ -41,21 +40,21 @@ static const int coeff_a_scaling = 65536; * @note ADC1 and ADC2 use same coeffients */ const static uint64_t adc_error_coef_atten[4][5][2] = { - {{225966470500043, 1e15}, {7265418501948, 1e16}, {109410402681, 1e16}, {0, 0}, {0, 0}}, //atten0 - {{4229623392600516, 1e16}, {731527490903, 1e16}, {88166562521, 1e16}, {0, 0}, {0, 0}}, //atten1 - {{1017859239236435, 1e15}, {97159265299153, 1e16}, {149794028038, 1e16}, {0, 0}, {0, 0}}, //atten2 - {{14912262772850453, 1e16}, {228549975564099, 1e16}, {356391935717, 1e16}, {179964582, 1e16}, {42046, 1e16}} //atten3 - }; + {{225966470500043, 1e15}, {7265418501948, 1e16}, {109410402681, 1e16}, {0, 0}, {0, 0}}, //atten0 + {{4229623392600516, 1e16}, {731527490903, 1e16}, {88166562521, 1e16}, {0, 0}, {0, 0}}, //atten1 + {{1017859239236435, 1e15}, {97159265299153, 1e16}, {149794028038, 1e16}, {0, 0}, {0, 0}}, //atten2 + {{14912262772850453, 1e16}, {228549975564099, 1e16}, {356391935717, 1e16}, {179964582, 1e16}, {42046, 1e16}} //atten3 +}; /** * Term sign * @note ADC1 and ADC2 use same coeffients */ const static int32_t adc_error_sign[4][5] = { - {-1, -1, 1, 0, 0}, //atten0 - { 1, -1, 1, 0, 0}, //atten1 - {-1, -1, 1, 0, 0}, //atten2 - {-1, -1, 1, -1, 1} //atten3 - }; + {-1, -1, 1, 0, 0}, //atten0 + { 1, -1, 1, 0, 0}, //atten1 + {-1, -1, 1, 0, 0}, //atten2 + {-1, -1, 1, -1, 1} //atten3 +}; /* -------------------- Characterization Helper Data Types ------------------ */ typedef struct { @@ -122,10 +121,10 @@ esp_err_t esp_adc_cal_check_efuse(esp_adc_cal_value_t source) } esp_adc_cal_value_t esp_adc_cal_characterize(adc_unit_t adc_num, - adc_atten_t atten, - adc_bits_width_t bit_width, - uint32_t default_vref, - esp_adc_cal_characteristics_t *chars) + adc_atten_t atten, + adc_bits_width_t bit_width, + uint32_t default_vref, + esp_adc_cal_characteristics_t *chars) { esp_err_t ret; adc_calib_parsed_info_t efuse_parsed_data = {0}; diff --git a/components/esp_adc/deprecated/esp32s2/esp_adc_cal_legacy.c b/components/esp_adc/deprecated/esp32s2/esp_adc_cal_legacy.c index e995541c96..6e92f8f37e 100644 --- a/components/esp_adc/deprecated/esp32s2/esp_adc_cal_legacy.c +++ b/components/esp_adc/deprecated/esp32s2/esp_adc_cal_legacy.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -105,11 +105,11 @@ static bool prepare_calib_data_for(adc_unit_t adc_num, adc_atten_t atten, adc_ca * */ static void characterize_using_two_point(adc_unit_t adc_num, - adc_atten_t atten, - uint32_t high, - uint32_t low, - uint32_t *coeff_a, - uint32_t *coeff_b) + adc_atten_t atten, + uint32_t high, + uint32_t low, + uint32_t *coeff_a, + uint32_t *coeff_b) { // once we have recovered the reference high(Dhigh) and low(Dlow) readings, we can calculate a and b from // the measured high and low readings @@ -161,10 +161,10 @@ esp_err_t esp_adc_cal_check_efuse(esp_adc_cal_value_t source) } esp_adc_cal_value_t esp_adc_cal_characterize(adc_unit_t adc_num, - adc_atten_t atten, - adc_bits_width_t bit_width, - uint32_t default_vref, - esp_adc_cal_characteristics_t *chars) + adc_atten_t atten, + adc_bits_width_t bit_width, + uint32_t default_vref, + esp_adc_cal_characteristics_t *chars) { bool res __attribute__((unused)); adc_calib_parsed_info efuse_parsed_data = {0}; diff --git a/components/esp_adc/deprecated/esp32s3/esp_adc_cal_legacy.c b/components/esp_adc/deprecated/esp32s3/esp_adc_cal_legacy.c index 0c6945d813..a37cf01655 100644 --- a/components/esp_adc/deprecated/esp32s3/esp_adc_cal_legacy.c +++ b/components/esp_adc/deprecated/esp32s3/esp_adc_cal_legacy.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -39,32 +39,32 @@ static const int coeff_a_scaling = 1000000; * @note Above formula is rewritten from the original documentation, please note that the coefficients are re-ordered. */ const static uint64_t adc1_error_coef_atten[4][5][2] = { - {{27856531419538344, 1e16}, {50871540569528, 1e16}, {9798249589, 1e15}, {0, 0}, {0, 0}}, //ADC1 atten0 - {{29831022915028695, 1e16}, {49393185868806, 1e16}, {101379430548, 1e16}, {0, 0}, {0, 0}}, //ADC1 atten1 - {{23285545746296417, 1e16}, {147640181047414, 1e16}, {208385525314, 1e16}, {0, 0}, {0, 0}}, //ADC1 atten2 - {{644403418269478, 1e15}, {644334888647536, 1e16}, {1297891447611, 1e16}, {70769718, 1e15}, {13515, 1e15}} //ADC1 atten3 - }; + {{27856531419538344, 1e16}, {50871540569528, 1e16}, {9798249589, 1e15}, {0, 0}, {0, 0}}, //ADC1 atten0 + {{29831022915028695, 1e16}, {49393185868806, 1e16}, {101379430548, 1e16}, {0, 0}, {0, 0}}, //ADC1 atten1 + {{23285545746296417, 1e16}, {147640181047414, 1e16}, {208385525314, 1e16}, {0, 0}, {0, 0}}, //ADC1 atten2 + {{644403418269478, 1e15}, {644334888647536, 1e16}, {1297891447611, 1e16}, {70769718, 1e15}, {13515, 1e15}} //ADC1 atten3 +}; const static uint64_t adc2_error_coef_atten[4][5][2] = { - {{25668651654328927, 1e16}, {1353548869615, 1e16}, {36615265189, 1e16}, {0, 0}, {0, 0}}, //ADC2 atten0 - {{23690184690298404, 1e16}, {66319894226185, 1e16}, {118964995959, 1e16}, {0, 0}, {0, 0}}, //ADC2 atten1 - {{9452499397020617, 1e16}, {200996773954387, 1e16}, {259011467956, 1e16}, {0, 0}, {0, 0}}, //ADC2 atten2 - {{12247719764336924,1e16}, {755717904943462, 1e16}, {1478791187119, 1e16}, {79672528, 1e15}, {15038, 1e15}} //ADC2 atten3 - }; + {{25668651654328927, 1e16}, {1353548869615, 1e16}, {36615265189, 1e16}, {0, 0}, {0, 0}}, //ADC2 atten0 + {{23690184690298404, 1e16}, {66319894226185, 1e16}, {118964995959, 1e16}, {0, 0}, {0, 0}}, //ADC2 atten1 + {{9452499397020617, 1e16}, {200996773954387, 1e16}, {259011467956, 1e16}, {0, 0}, {0, 0}}, //ADC2 atten2 + {{12247719764336924, 1e16}, {755717904943462, 1e16}, {1478791187119, 1e16}, {79672528, 1e15}, {15038, 1e15}} //ADC2 atten3 +}; /** * Term sign */ const static int32_t adc1_error_sign[4][5] = { - {-1, -1, 1, 0, 0}, //ADC1 atten0 - {-1, -1, 1, 0, 0}, //ADC1 atten1 - {-1, -1, 1, 0, 0}, //ADC1 atten2 - {-1, -1, 1, -1, 1} //ADC1 atten3 - }; + {-1, -1, 1, 0, 0}, //ADC1 atten0 + {-1, -1, 1, 0, 0}, //ADC1 atten1 + {-1, -1, 1, 0, 0}, //ADC1 atten2 + {-1, -1, 1, -1, 1} //ADC1 atten3 +}; const static int32_t adc2_error_sign[4][5] = { - {-1, 1, 1, 0, 0}, //ADC2 atten0 - {-1, -1, 1, 0, 0}, //ADC2 atten1 - {-1, -1, 1, 0, 0}, //ADC2 atten2 - { 1, -1, 1, -1, 1} //ADC2 atten3 - }; + {-1, 1, 1, 0, 0}, //ADC2 atten0 + {-1, -1, 1, 0, 0}, //ADC2 atten1 + {-1, -1, 1, 0, 0}, //ADC2 atten2 + { 1, -1, 1, -1, 1} //ADC2 atten3 +}; /* -------------------- Characterization Helper Data Types ------------------ */ typedef struct { @@ -81,7 +81,6 @@ typedef struct { } ref_data; } adc_calib_info_t; - //To get the reference point (Dout, Vin) static esp_err_t get_reference_point(int version_num, adc_unit_t adc_num, adc_atten_t atten, adc_calib_info_t *calib_info) { @@ -125,10 +124,10 @@ static void calculate_characterization_coefficients(const adc_calib_info_t *pars } esp_adc_cal_value_t esp_adc_cal_characterize(adc_unit_t adc_num, - adc_atten_t atten, - adc_bits_width_t bit_width, - uint32_t default_vref, - esp_adc_cal_characteristics_t *chars) + adc_atten_t atten, + adc_bits_width_t bit_width, + uint32_t default_vref, + esp_adc_cal_characteristics_t *chars) { (void) default_vref; @@ -176,8 +175,8 @@ uint32_t esp_adc_cal_raw_to_voltage(uint32_t adc_reading, const esp_adc_cal_char esp_adc_error_calc_param_t param = { .v_cali_input = v_cali_1, .term_num = (chars->atten == 3) ? 5 : 3, - .coeff = (chars->adc_num == ADC_UNIT_1) ? &adc1_error_coef_atten : &adc2_error_coef_atten, - .sign = (chars->adc_num == ADC_UNIT_1) ? &adc1_error_sign : &adc2_error_sign, + .coeff = (chars->adc_num == ADC_UNIT_1) ? &adc1_error_coef_atten :&adc2_error_coef_atten, + .sign = (chars->adc_num == ADC_UNIT_1) ? &adc1_error_sign :&adc2_error_sign, }; error = esp_adc_cal_get_reading_error(¶m, chars->atten); diff --git a/components/esp_adc/deprecated/esp_adc_cal_common_legacy.c b/components/esp_adc/deprecated/esp_adc_cal_common_legacy.c index a990466394..982f7c9f7c 100644 --- a/components/esp_adc/deprecated/esp_adc_cal_common_legacy.c +++ b/components/esp_adc/deprecated/esp_adc_cal_common_legacy.c @@ -46,7 +46,6 @@ esp_err_t esp_adc_cal_get_voltage(adc_channel_t channel, return ret; } - #if ESP_ADC_CAL_CURVE_FITTING_SUPPORTED /*------------------------------------------------------------------------------ * Private API @@ -79,7 +78,7 @@ int32_t esp_adc_cal_get_reading_error(const esp_adc_error_calc_param_t *param, u error = (int32_t)term[0] * (*param->sign)[atten][0]; for (int i = 1; i < term_num; i++) { - variable[i] = variable[i-1] * v_cali_1; + variable[i] = variable[i - 1] * v_cali_1; coeff = (*param->coeff)[atten][i][0]; term[i] = variable[i] * coeff; ESP_LOGV(TAG, "big coef is %llu, big term%d is %llu, coef_id is %d", coeff, i, term[i], i); diff --git a/components/esp_adc/deprecated/esp_adc_cal_internal_legacy.h b/components/esp_adc/deprecated/esp_adc_cal_internal_legacy.h index 518c397f5b..3f2218e8ba 100644 --- a/components/esp_adc/deprecated/esp_adc_cal_internal_legacy.h +++ b/components/esp_adc/deprecated/esp_adc_cal_internal_legacy.h @@ -31,7 +31,7 @@ typedef struct { uint64_t v_cali_input; //Input to calculate the error uint8_t term_num; //Term number of the algorithm formula const uint64_t (*coeff)[COEFF_GROUP_NUM][TERM_MAX][2]; //Coeff of each term. See `adc_error_coef_atten` for details (and the magic number 2) - const int32_t (*sign)[COEFF_GROUP_NUM][TERM_MAX]; //Sign of each term + const int32_t (*sign)[COEFF_GROUP_NUM][TERM_MAX]; //Sign of each term } esp_adc_error_calc_param_t; /** @@ -44,7 +44,6 @@ int32_t esp_adc_cal_get_reading_error(const esp_adc_error_calc_param_t *param, u #endif //#if ESP_ADC_CAL_CURVE_FITTING_SUPPORTED - #ifdef __cplusplus } #endif diff --git a/components/esp_adc/deprecated/include/esp_adc_cal_types_legacy.h b/components/esp_adc/deprecated/include/esp_adc_cal_types_legacy.h index 7c366afabe..613f09a4c6 100644 --- a/components/esp_adc/deprecated/include/esp_adc_cal_types_legacy.h +++ b/components/esp_adc/deprecated/include/esp_adc_cal_types_legacy.h @@ -44,7 +44,6 @@ typedef struct { } esp_adc_cal_characteristics_t; #endif //#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 - #ifdef __cplusplus } #endif diff --git a/components/esp_adc/esp32/adc_cali_line_fitting.c b/components/esp_adc/esp32/adc_cali_line_fitting.c index 0421b27fd4..adf79c4c3f 100644 --- a/components/esp_adc/esp32/adc_cali_line_fitting.c +++ b/components/esp_adc/esp32/adc_cali_line_fitting.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -88,17 +88,20 @@ static const uint32_t adc2_vref_atten_offset[4] = {63, 66, 89, 128}; //20 Point lookup tables, covering ADC readings from 2880 to 4096, step size of 64 static const uint32_t lut_adc1_low[LUT_POINTS] = {2240, 2297, 2352, 2405, 2457, 2512, 2564, 2616, 2664, 2709, - 2754, 2795, 2832, 2868, 2903, 2937, 2969, 3000, 3030, 3060}; + 2754, 2795, 2832, 2868, 2903, 2937, 2969, 3000, 3030, 3060 + }; static const uint32_t lut_adc1_high[LUT_POINTS] = {2667, 2706, 2745, 2780, 2813, 2844, 2873, 2901, 2928, 2956, - 2982, 3006, 3032, 3059, 3084, 3110, 3135, 3160, 3184, 3209}; + 2982, 3006, 3032, 3059, 3084, 3110, 3135, 3160, 3184, 3209 + }; static const uint32_t lut_adc2_low[LUT_POINTS] = {2238, 2293, 2347, 2399, 2451, 2507, 2561, 2613, 2662, 2710, - 2754, 2792, 2831, 2869, 2904, 2937, 2968, 2999, 3029, 3059}; + 2754, 2792, 2831, 2869, 2904, 2937, 2968, 2999, 3029, 3059 + }; static const uint32_t lut_adc2_high[LUT_POINTS] = {2657, 2698, 2738, 2774, 2807, 2838, 2867, 2894, 2921, 2946, - 2971, 2996, 3020, 3043, 3067, 3092, 3116, 3139, 3162, 3185}; + 2971, 2996, 3020, 3043, 3067, 3092, 3116, 3139, 3162, 3185 + }; const __attribute__((unused)) static char *TAG = "adc_cali"; - /* ----------------------- EFuse Access Functions --------------------------- */ static bool check_efuse_vref(void); static bool check_efuse_tp(void); @@ -107,7 +110,6 @@ static uint32_t read_efuse_vref(void); static uint32_t read_efuse_tp_low(adc_unit_t unit_id); static uint32_t read_efuse_tp_high(adc_unit_t unit_id); - /* ----------------------- Characterization Functions ----------------------- */ static void characterize_using_two_point(adc_unit_t unit_id, adc_atten_t atten, @@ -121,7 +123,6 @@ static void characterize_using_vref(adc_unit_t unit_id, uint32_t *coeff_a, uint32_t *coeff_b); - /* ------------------------ Conversion Functions --------------------------- */ static uint32_t calculate_voltage_linear(uint32_t adc_reading, uint32_t coeff_a, uint32_t coeff_b); //Only call when ADC reading is above threshold @@ -133,11 +134,9 @@ static inline uint32_t interpolate_two_points(uint32_t y1, uint32_t y2, uint32_t return ((y1 * x_step) + (y2 * x) - (y1 * x) + (x_step / 2)) / x_step; } - /* ------------------------ Interface Functions --------------------------- */ static esp_err_t cali_raw_to_voltage(void *arg, int raw, int *voltage); - /* ------------------------ Context Structure--------------------------- */ typedef struct { adc_unit_t unit_id; ///< ADC unit @@ -151,7 +150,6 @@ typedef struct { adc_cali_line_fitting_efuse_val_t efuse_val; ///< Type of calibration value used in characterization } cali_chars_line_fitting_t; - /* ------------------------- Public API ------------------------------------- */ esp_err_t adc_cali_create_scheme_line_fitting(const adc_cali_line_fitting_config_t *config, adc_cali_handle_t *ret_handle) { @@ -350,7 +348,6 @@ static uint32_t read_efuse_tp_high(adc_unit_t unit_id) return ret; //Reading of ADC at 850mV } - /* ----------------------- Characterization Functions ----------------------- */ static void characterize_using_two_point(adc_unit_t unit_id, adc_atten_t atten, @@ -400,7 +397,6 @@ static void characterize_using_vref(adc_unit_t unit_id, *coeff_b = atten_offsets[atten]; } - /* ------------------------ Conversion Functions --------------------------- */ static uint32_t calculate_voltage_linear(uint32_t adc_reading, uint32_t coeff_a, uint32_t coeff_b) { diff --git a/components/esp_adc/esp32c2/adc_cali_line_fitting.c b/components/esp_adc/esp32c2/adc_cali_line_fitting.c index 295616c05f..3ccf36eba4 100644 --- a/components/esp_adc/esp32c2/adc_cali_line_fitting.c +++ b/components/esp_adc/esp32c2/adc_cali_line_fitting.c @@ -17,7 +17,6 @@ #include "esp_adc/adc_cali_scheme.h" #include "adc_cali_interface.h" - /** * This file contains Line Fitting Calibration Scheme for ESP32C2. * @@ -30,7 +29,6 @@ * 5. Only build this file, when `ADC_CALI_SCHEME_LINE_FITTING_V2_SUPPORTED == true` */ - // coeff_a is actually a float number // it is scaled to put them into uint32_t so that the headers do not have to be changed static const int coeff_a_scaling = 65536; @@ -43,7 +41,6 @@ typedef struct { uint32_t coeff_b; ///< Offset of ADC-Voltage characteristics } cali_chars_line_fitting_t; - /* ------------------------ Interface Functions --------------------------- */ static esp_err_t cali_raw_to_voltage(void *arg, int raw, int *voltage); static esp_err_t check_valid(const adc_cali_line_fitting_config_t *config); @@ -107,7 +104,6 @@ esp_err_t adc_cali_delete_scheme_line_fitting(adc_cali_handle_t handle) return ESP_OK; } - /* ------------------------ Interface Functions --------------------------- */ static esp_err_t cali_raw_to_voltage(void *arg, int raw, int *voltage) { diff --git a/components/esp_adc/esp32c3/curve_fitting_coefficients.c b/components/esp_adc/esp32c3/curve_fitting_coefficients.c index 9d8bda65ed..4ef3a058d1 100644 --- a/components/esp_adc/esp32c3/curve_fitting_coefficients.c +++ b/components/esp_adc/esp32c3/curve_fitting_coefficients.c @@ -24,20 +24,20 @@ * @note ADC1 and ADC2 use same coefficients */ const static uint64_t adc1_error_coef_atten[COEFF_GROUP_NUM][TERM_MAX][2] = { - {{225966470500043, 1e15}, {7265418501948, 1e16}, {109410402681, 1e16}, {0, 0}, {0, 0}}, //atten0 - {{4229623392600516, 1e16}, {731527490903, 1e16}, {88166562521, 1e16}, {0, 0}, {0, 0}}, //atten1 - {{1017859239236435, 1e15}, {97159265299153, 1e16}, {149794028038, 1e16}, {0, 0}, {0, 0}}, //atten2 - {{14912262772850453, 1e16}, {228549975564099, 1e16}, {356391935717, 1e16}, {179964582, 1e16}, {42046, 1e16}} //atten3 - }; + {{225966470500043, 1e15}, {7265418501948, 1e16}, {109410402681, 1e16}, {0, 0}, {0, 0}}, //atten0 + {{4229623392600516, 1e16}, {731527490903, 1e16}, {88166562521, 1e16}, {0, 0}, {0, 0}}, //atten1 + {{1017859239236435, 1e15}, {97159265299153, 1e16}, {149794028038, 1e16}, {0, 0}, {0, 0}}, //atten2 + {{14912262772850453, 1e16}, {228549975564099, 1e16}, {356391935717, 1e16}, {179964582, 1e16}, {42046, 1e16}} //atten3 +}; /** * Term sign */ const static int32_t adc1_error_sign[COEFF_GROUP_NUM][TERM_MAX] = { - {-1, -1, 1, 0, 0}, //atten0 - { 1, -1, 1, 0, 0}, //atten1 - {-1, -1, 1, 0, 0}, //atten2 - {-1, -1, 1, -1, 1} //atten3 - }; + {-1, -1, 1, 0, 0}, //atten0 + { 1, -1, 1, 0, 0}, //atten1 + {-1, -1, 1, 0, 0}, //atten2 + {-1, -1, 1, -1, 1} //atten3 +}; void curve_fitting_get_second_step_coeff(const adc_cali_curve_fitting_config_t *config, cali_chars_second_step_t *ctx) { diff --git a/components/esp_adc/esp32c6/curve_fitting_coefficients.c b/components/esp_adc/esp32c6/curve_fitting_coefficients.c index 588c318b96..b0be52b643 100644 --- a/components/esp_adc/esp32c6/curve_fitting_coefficients.c +++ b/components/esp_adc/esp32c6/curve_fitting_coefficients.c @@ -38,7 +38,7 @@ const static uint64_t adc1_error_coef_atten[COEFF_VERSION_NUM][COEFF_GROUP_NUM][ {{0, 0}, {0, 0}, {0, 0}}, //atten0 {{0, 0}, {0, 0}, {0, 0}}, //atten1 {{12217864764388775, 1e16}, {1954123107752, 1e16}, {6409679727, 1e16}}, //atten2 - {{3915910437042445 , 1e16}, {31536470857564, 1e16}, {12493873014, 1e16}}, //atten3 + {{3915910437042445, 1e16}, {31536470857564, 1e16}, {12493873014, 1e16}}, //atten3 }, }; @@ -62,7 +62,6 @@ const static int32_t adc1_error_sign[COEFF_VERSION_NUM][COEFF_GROUP_NUM][TERM_MA }, }; - void curve_fitting_get_second_step_coeff(const adc_cali_curve_fitting_config_t *config, cali_chars_second_step_t *ctx) { uint32_t adc_calib_ver = esp_efuse_rtc_calib_get_ver(); diff --git a/components/esp_adc/esp32s2/adc_cali_line_fitting.c b/components/esp_adc/esp32s2/adc_cali_line_fitting.c index a14e912353..87ec4e7e3e 100644 --- a/components/esp_adc/esp32s2/adc_cali_line_fitting.c +++ b/components/esp_adc/esp32s2/adc_cali_line_fitting.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -27,7 +27,6 @@ const __attribute__((unused)) static char *TAG = "adc_cali"; static const int coeff_a_scaling = 65536; static const int coeff_b_scaling = 1024; - /* -------------------- Characterization Helper Data Types ------------------ */ typedef struct { int adc_calib_high; @@ -49,7 +48,6 @@ typedef struct { } efuse_data; } adc_calib_parsed_info_t; - /* ------------------------ Context Structure--------------------------- */ typedef struct { adc_unit_t unit_id; ///< ADC unit @@ -58,7 +56,6 @@ typedef struct { uint32_t coeff_b; ///< Offset of ADC-Voltage curve } cali_chars_line_fitting_t; - /* ----------------------- Characterization Functions ----------------------- */ static bool prepare_calib_data_for(adc_unit_t unit_id, adc_atten_t atten, adc_calib_parsed_info_t *parsed_data_storage); /** @@ -71,22 +68,20 @@ static bool prepare_calib_data_for(adc_unit_t unit_id, adc_atten_t atten, adc_ca * */ static void characterize_using_two_point(adc_unit_t unit_id, - adc_atten_t atten, - uint32_t high, - uint32_t low, - uint32_t *coeff_a, - uint32_t *coeff_b); + adc_atten_t atten, + uint32_t high, + uint32_t low, + uint32_t *coeff_a, + uint32_t *coeff_b); /* * Estimate the (assumed) linear relationship btwn the measured raw value and the voltage * with the previously done measurement when the chip was manufactured. * */ static bool calculate_characterization_coefficients(const adc_calib_parsed_info_t *parsed_data, cali_chars_line_fitting_t *ctx); - /* ------------------------ Interface Functions --------------------------- */ static esp_err_t cali_raw_to_voltage(void *arg, int raw, int *voltage); - /* ------------------------- Public API ------------------------------------- */ esp_err_t adc_cali_create_scheme_line_fitting(const adc_cali_line_fitting_config_t *config, adc_cali_handle_t *ret_handle) { @@ -142,7 +137,6 @@ esp_err_t adc_cali_delete_scheme_line_fitting(adc_cali_handle_t handle) return ESP_OK; } - /* ------------------------ Interface Functions --------------------------- */ static esp_err_t cali_raw_to_voltage(void *arg, int raw, int *voltage) { @@ -154,7 +148,6 @@ static esp_err_t cali_raw_to_voltage(void *arg, int raw, int *voltage) return ESP_OK; } - /* ----------------------- Characterization Functions ----------------------- */ static bool prepare_calib_data_for(adc_unit_t unit_id, adc_atten_t atten, adc_calib_parsed_info_t *parsed_data_storage) { @@ -213,11 +206,11 @@ static bool prepare_calib_data_for(adc_unit_t unit_id, adc_atten_t atten, adc_ca * */ static void characterize_using_two_point(adc_unit_t unit_id, - adc_atten_t atten, - uint32_t high, - uint32_t low, - uint32_t *coeff_a, - uint32_t *coeff_b) + adc_atten_t atten, + uint32_t high, + uint32_t low, + uint32_t *coeff_a, + uint32_t *coeff_b) { // once we have recovered the reference high(Dhigh) and low(Dlow) readings, we can calculate a and b from // the measured high and low readings @@ -244,7 +237,7 @@ static bool calculate_characterization_coefficients(const adc_calib_parsed_info_ case 2: ESP_LOGD(TAG, "Calib V2, volt%dmV", parsed_data->efuse_data.ver2.adc_calib_high); ctx->coeff_a = coeff_a_scaling * parsed_data->efuse_data.ver2.adc_calib_high_voltage / - parsed_data->efuse_data.ver2.adc_calib_high; + parsed_data->efuse_data.ver2.adc_calib_high; ctx->coeff_b = 0; break; default: diff --git a/components/esp_adc/esp32s3/curve_fitting_coefficients.c b/components/esp_adc/esp32s3/curve_fitting_coefficients.c index 74a500da31..ea10cfeb66 100644 --- a/components/esp_adc/esp32s3/curve_fitting_coefficients.c +++ b/components/esp_adc/esp32s3/curve_fitting_coefficients.c @@ -24,32 +24,32 @@ * @note Above formula is rewritten from the original documentation, please note that the coefficients are re-ordered. */ const static uint64_t adc1_error_coef_atten[COEFF_GROUP_NUM][TERM_MAX][2] = { - {{27856531419538344, 1e16}, {50871540569528, 1e16}, {9798249589, 1e15}, {0, 0}, {0, 0}}, //ADC1 atten0 - {{29831022915028695, 1e16}, {49393185868806, 1e16}, {101379430548, 1e16}, {0, 0}, {0, 0}}, //ADC1 atten1 - {{23285545746296417, 1e16}, {147640181047414, 1e16}, {208385525314, 1e16}, {0, 0}, {0, 0}}, //ADC1 atten2 - {{644403418269478, 1e15}, {644334888647536, 1e16}, {1297891447611, 1e16}, {70769718, 1e15}, {13515, 1e15}} //ADC1 atten3 - }; + {{27856531419538344, 1e16}, {50871540569528, 1e16}, {9798249589, 1e15}, {0, 0}, {0, 0}}, //ADC1 atten0 + {{29831022915028695, 1e16}, {49393185868806, 1e16}, {101379430548, 1e16}, {0, 0}, {0, 0}}, //ADC1 atten1 + {{23285545746296417, 1e16}, {147640181047414, 1e16}, {208385525314, 1e16}, {0, 0}, {0, 0}}, //ADC1 atten2 + {{644403418269478, 1e15}, {644334888647536, 1e16}, {1297891447611, 1e16}, {70769718, 1e15}, {13515, 1e15}} //ADC1 atten3 +}; const static uint64_t adc2_error_coef_atten[COEFF_GROUP_NUM][TERM_MAX][2] = { - {{25668651654328927, 1e16}, {1353548869615, 1e16}, {36615265189, 1e16}, {0, 0}, {0, 0}}, //ADC2 atten0 - {{23690184690298404, 1e16}, {66319894226185, 1e16}, {118964995959, 1e16}, {0, 0}, {0, 0}}, //ADC2 atten1 - {{9452499397020617, 1e16}, {200996773954387, 1e16}, {259011467956, 1e16}, {0, 0}, {0, 0}}, //ADC2 atten2 - {{12247719764336924,1e16}, {755717904943462, 1e16}, {1478791187119, 1e16}, {79672528, 1e15}, {15038, 1e15}} //ADC2 atten3 - }; + {{25668651654328927, 1e16}, {1353548869615, 1e16}, {36615265189, 1e16}, {0, 0}, {0, 0}}, //ADC2 atten0 + {{23690184690298404, 1e16}, {66319894226185, 1e16}, {118964995959, 1e16}, {0, 0}, {0, 0}}, //ADC2 atten1 + {{9452499397020617, 1e16}, {200996773954387, 1e16}, {259011467956, 1e16}, {0, 0}, {0, 0}}, //ADC2 atten2 + {{12247719764336924, 1e16}, {755717904943462, 1e16}, {1478791187119, 1e16}, {79672528, 1e15}, {15038, 1e15}} //ADC2 atten3 +}; /** * Term sign */ const static int32_t adc1_error_sign[COEFF_GROUP_NUM][TERM_MAX] = { - {-1, -1, 1, 0, 0}, //ADC1 atten0 - {-1, -1, 1, 0, 0}, //ADC1 atten1 - {-1, -1, 1, 0, 0}, //ADC1 atten2 - {-1, -1, 1, -1, 1} //ADC1 atten3 - }; + {-1, -1, 1, 0, 0}, //ADC1 atten0 + {-1, -1, 1, 0, 0}, //ADC1 atten1 + {-1, -1, 1, 0, 0}, //ADC1 atten2 + {-1, -1, 1, -1, 1} //ADC1 atten3 +}; const static int32_t adc2_error_sign[COEFF_GROUP_NUM][TERM_MAX] = { - {-1, 1, 1, 0, 0}, //ADC2 atten0 - {-1, -1, 1, 0, 0}, //ADC2 atten1 - {-1, -1, 1, 0, 0}, //ADC2 atten2 - { 1, -1, 1, -1, 1} //ADC2 atten3 - }; + {-1, 1, 1, 0, 0}, //ADC2 atten0 + {-1, -1, 1, 0, 0}, //ADC2 atten1 + {-1, -1, 1, 0, 0}, //ADC2 atten2 + { 1, -1, 1, -1, 1} //ADC2 atten3 +}; void curve_fitting_get_second_step_coeff(const adc_cali_curve_fitting_config_t *config, cali_chars_second_step_t *ctx) { diff --git a/components/esp_adc/include/esp_adc/adc_cali.h b/components/esp_adc/include/esp_adc/adc_cali.h index b9b949b19f..2057601510 100644 --- a/components/esp_adc/include/esp_adc/adc_cali.h +++ b/components/esp_adc/include/esp_adc/adc_cali.h @@ -53,7 +53,6 @@ esp_err_t adc_cali_check_scheme(adc_cali_scheme_ver_t *scheme_mask); */ esp_err_t adc_cali_raw_to_voltage(adc_cali_handle_t handle, int raw, int *voltage); - #ifdef __cplusplus } #endif diff --git a/components/esp_adc/include/esp_adc/adc_cali_scheme.h b/components/esp_adc/include/esp_adc/adc_cali_scheme.h index 8894c66c1f..80889096ac 100644 --- a/components/esp_adc/include/esp_adc/adc_cali_scheme.h +++ b/components/esp_adc/include/esp_adc/adc_cali_scheme.h @@ -15,7 +15,6 @@ extern "C" { #endif - #if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED /*--------------------------------------------------------------- Curve Fitting Calibration Scheme @@ -56,7 +55,6 @@ esp_err_t adc_cali_create_scheme_curve_fitting(const adc_cali_curve_fitting_conf esp_err_t adc_cali_delete_scheme_curve_fitting(adc_cali_handle_t handle); #endif // #if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED - #if ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED /*--------------------------------------------------------------- Line Fitting Calibration Scheme diff --git a/components/esp_adc/include/esp_adc/adc_continuous.h b/components/esp_adc/include/esp_adc/adc_continuous.h index 7f8aec4a89..99b2b269d5 100644 --- a/components/esp_adc/include/esp_adc/adc_continuous.h +++ b/components/esp_adc/include/esp_adc/adc_continuous.h @@ -16,7 +16,6 @@ extern "C" { #endif - /* * Driver Backgrounds * @@ -239,7 +238,6 @@ esp_err_t adc_continuous_io_to_channel(int io_num, adc_unit_t * const unit_id, a */ esp_err_t adc_continuous_channel_to_io(adc_unit_t unit_id, adc_channel_t channel, int * const io_num); - #ifdef __cplusplus } #endif diff --git a/components/esp_adc/include/esp_adc/adc_filter.h b/components/esp_adc/include/esp_adc/adc_filter.h index 973ccf0d26..bc34dcfc8d 100644 --- a/components/esp_adc/include/esp_adc/adc_filter.h +++ b/components/esp_adc/include/esp_adc/adc_filter.h @@ -31,7 +31,6 @@ typedef struct { adc_digi_iir_filter_coeff_t coeff; ///< ADC filter coefficient } adc_continuous_iir_filter_config_t; - /** * @brief New an ADC continuous mode IIR filter * diff --git a/components/esp_adc/include/esp_adc/adc_monitor.h b/components/esp_adc/include/esp_adc/adc_monitor.h index c6a37695c7..8066771a2e 100644 --- a/components/esp_adc/include/esp_adc/adc_monitor.h +++ b/components/esp_adc/include/esp_adc/adc_monitor.h @@ -6,7 +6,6 @@ #pragma once - #include "adc_continuous.h" #ifdef __cplusplus @@ -48,7 +47,6 @@ typedef struct { adc_monitor_evt_cb_t on_below_low_thresh; /*!< adc_monitor low value interrupt callback */ } adc_monitor_evt_cbs_t; - /** * @brief Allocate an ADC continuous mode monitor (and configure it into an initial state) * diff --git a/components/esp_adc/include/esp_private/adc_private.h b/components/esp_adc/include/esp_private/adc_private.h index ae599e97c6..805614a976 100644 --- a/components/esp_adc/include/esp_private/adc_private.h +++ b/components/esp_adc/include/esp_private/adc_private.h @@ -11,7 +11,6 @@ #include "hal/adc_types.h" #include "soc/soc_caps.h" - #ifdef __cplusplus extern "C" { #endif @@ -33,7 +32,6 @@ void adc_apb_periph_claim(void); */ void adc_apb_periph_free(void); - /*--------------------------------------------------------------- ADC IOs ---------------------------------------------------------------*/ @@ -64,7 +62,6 @@ esp_err_t adc_io_to_channel(int io_num, adc_unit_t * const unit_id, adc_channel_ */ esp_err_t adc_channel_to_io(adc_unit_t unit_id, adc_channel_t channel, int * const io_num); - /*--------------------------------------------------------------- ADC Oneshot Read API ISR Version ---------------------------------------------------------------*/ @@ -89,7 +86,6 @@ typedef struct adc_oneshot_unit_ctx_t *adc_oneshot_unit_handle_t; */ esp_err_t adc_oneshot_read_isr(adc_oneshot_unit_handle_t handle, adc_channel_t chan, int *out_raw); - #ifdef __cplusplus } #endif diff --git a/components/esp_adc/interface/adc_cali_interface.h b/components/esp_adc/interface/adc_cali_interface.h index 751fef5276..34edc85eb6 100644 --- a/components/esp_adc/interface/adc_cali_interface.h +++ b/components/esp_adc/interface/adc_cali_interface.h @@ -11,7 +11,6 @@ extern "C" { #endif - typedef struct adc_cali_scheme_t adc_cali_scheme_t; /** diff --git a/components/esp_adc/test_apps/adc/main/test_adc.c b/components/esp_adc/test_apps/adc/main/test_adc.c index 2fedff2b08..30230fa4c2 100644 --- a/components/esp_adc/test_apps/adc/main/test_adc.c +++ b/components/esp_adc/test_apps/adc/main/test_adc.c @@ -34,7 +34,6 @@ static const char *TAG_CH[2][10] = {{"ADC1_CH4", "ADC1_CH5"}, {"ADC2_CH0"}}; static const char *TAG_CH[2][10] = {{"ADC1_CH2", "ADC1_CH3"}, {"ADC2_CH0"}}; #endif - /*--------------------------------------------------------------- ADC Oneshot High / Low test ---------------------------------------------------------------*/ @@ -95,7 +94,6 @@ TEST_CASE("ADC oneshot high/low test", "[adc_oneshot]") TEST_ASSERT_INT_WITHIN(ADC_TEST_LOW_THRESH, ADC_TEST_LOW_VAL, adc_raw[1][0]); #endif //#if ADC_TEST_ONESHOT_HIGH_LOW_TEST_ADC2 - test_adc_set_io_level(ADC_UNIT_1, ADC1_TEST_CHAN0, 1); TEST_ESP_OK(adc_oneshot_read(adc1_handle, ADC1_TEST_CHAN0, &adc_raw[0][0])); ESP_LOGI(TAG_CH[0][0], "raw data: %d", adc_raw[0][0]); @@ -113,15 +111,12 @@ TEST_CASE("ADC oneshot high/low test", "[adc_oneshot]") TEST_ASSERT_INT_WITHIN(ADC_TEST_HIGH_THRESH, ADC_TEST_HIGH_VAL, adc_raw[1][0]); #endif //#if ADC_TEST_ONESHOT_HIGH_LOW_TEST_ADC2 - TEST_ESP_OK(adc_oneshot_del_unit(adc1_handle)); #if ADC_TEST_ONESHOT_HIGH_LOW_TEST_ADC2 TEST_ESP_OK(adc_oneshot_del_unit(adc2_handle)); #endif //#if ADC_TEST_ONESHOT_HIGH_LOW_TEST_ADC2 } - - #if SOC_ADC_CALIBRATION_V1_SUPPORTED /*--------------------------------------------------------------- ADC Oneshot with Light Sleep @@ -224,8 +219,8 @@ static void s_adc_oneshot_with_sleep(adc_unit_t unit_id, adc_channel_t channel) ESP_LOGI(TAG, "ADC%d Chan%d: raw difference: %"PRId32, unit_id + 1, channel, raw_diff); if (do_calibration) { - int32_t cali_diff = cali_expected - cali_after_sleep; - ESP_LOGI(TAG, "ADC%d Chan%d: cali difference: %"PRId32, unit_id + 1, channel, cali_diff); + int32_t cali_diff = cali_expected - cali_after_sleep; + ESP_LOGI(TAG, "ADC%d Chan%d: cali difference: %"PRId32, unit_id + 1, channel, cali_diff); } //Test Calibration registers @@ -267,14 +262,14 @@ TEST_CASE("test ADC2 Single Read with Light Sleep", "[adc][manul][ignore]") #endif //#if SOC_ADC_CALIBRATION_V1_SUPPORTED - #if SOC_ADC_MONITOR_SUPPORTED && CONFIG_SOC_ADC_DMA_SUPPORTED #if CONFIG_IDF_TARGET_ESP32S2 #define TEST_ADC_FORMATE_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE1 #else #define TEST_ADC_FORMATE_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2 #endif -bool IRAM_ATTR test_high_cb(adc_monitor_handle_t monitor_handle, const adc_monitor_evt_data_t *event_data, void *user_data){ +bool IRAM_ATTR test_high_cb(adc_monitor_handle_t monitor_handle, const adc_monitor_evt_data_t *event_data, void *user_data) +{ return false; } TEST_CASE("ADC continuous monitor init_deinit", "[adc]") @@ -366,7 +361,6 @@ TEST_CASE("ADC continuous monitor init_deinit", "[adc]") TEST_ESP_OK(adc_continuous_deinit(handle)); } - /** * NOTE: To run this special feature test case, you need wire ADC channel pin you want to monit * to a wave output pin defined below. @@ -386,11 +380,13 @@ TEST_CASE("ADC continuous monitor init_deinit", "[adc]") #define TEST_WAVE_OUT_PIN GPIO_NUM_2 //GPIO_2 static uint32_t m1h_cnt, m1l_cnt; -bool IRAM_ATTR m1h_cb(adc_monitor_handle_t monitor_handle, const adc_monitor_evt_data_t *event_data, void *user_data){ +bool IRAM_ATTR m1h_cb(adc_monitor_handle_t monitor_handle, const adc_monitor_evt_data_t *event_data, void *user_data) +{ m1h_cnt ++; return false; } -bool IRAM_ATTR m1l_cb(adc_monitor_handle_t monitor_handle, const adc_monitor_evt_data_t *event_data, void *user_data){ +bool IRAM_ATTR m1l_cb(adc_monitor_handle_t monitor_handle, const adc_monitor_evt_data_t *event_data, void *user_data) +{ m1l_cnt ++; return false; } @@ -451,8 +447,7 @@ TEST_CASE("ADC continuous monitor functionary", "[adc][manual][ignore]") TEST_ESP_OK(adc_continuous_monitor_enable(monitor_handle)); TEST_ESP_OK(adc_continuous_start(handle)); - for (uint8_t i=0; i<8; i++) - { + for (uint8_t i = 0; i < 8; i++) { vTaskDelay(1000); // check monitor cb @@ -465,7 +460,7 @@ TEST_CASE("ADC continuous monitor functionary", "[adc][manual][ignore]") m1h_cnt = 0; gpio_set_level(TEST_WAVE_OUT_PIN, 0); } else { - TEST_ASSERT_UINT32_WITHIN(SOC_ADC_SAMPLE_FREQ_THRES_LOW*0.1, SOC_ADC_SAMPLE_FREQ_THRES_LOW, m1l_cnt); + TEST_ASSERT_UINT32_WITHIN(SOC_ADC_SAMPLE_FREQ_THRES_LOW * 0.1, SOC_ADC_SAMPLE_FREQ_THRES_LOW, m1l_cnt); TEST_ASSERT_LESS_THAN_UINT32(5, m1h_cnt); //Actually, it will still encountered 1~2 times because hardware run very quickly m1l_cnt = 0; gpio_set_level(TEST_WAVE_OUT_PIN, 1); diff --git a/components/esp_adc/test_apps/adc/main/test_adc_driver.c b/components/esp_adc/test_apps/adc/main/test_adc_driver.c index 04d5fb397b..a38f4270fe 100644 --- a/components/esp_adc/test_apps/adc/main/test_adc_driver.c +++ b/components/esp_adc/test_apps/adc/main/test_adc_driver.c @@ -59,13 +59,11 @@ static bool IRAM_ATTR s_alarm_callback(gptimer_handle_t timer, const gptimer_ala TEST_ASSERT_INT_WITHIN(ADC_TEST_LOW_THRESH, ADC_TEST_LOW_VAL, adc_raw); } - // check the count value at alarm event vTaskNotifyGiveFromISR(test_ctx->task_handle, &high_task_wakeup); return high_task_wakeup == pdTRUE; } - TEST_CASE("ADC oneshot fast work with ISR", "[adc_oneshot]") { static test_adc_isr_ctx_t isr_test_ctx = {}; @@ -114,7 +112,6 @@ TEST_CASE("ADC oneshot fast work with ISR", "[adc_oneshot]") TEST_ASSERT_NOT_EQUAL(0, ulTaskNotifyTake(pdFALSE, pdMS_TO_TICKS(1000))); TEST_ESP_OK(gptimer_stop(timer)); - //ADC IO tile high test_adc_set_io_level(ADC_UNIT_1, ADC1_TEST_CHAN0, 1); isr_test_ctx.level = 1; @@ -144,7 +141,6 @@ TEST_CASE("ADC oneshot fast work with ISR", "[adc_oneshot]") #define ADC_FRAME_TEST_SIZE 8192 - static bool IRAM_ATTR NOINLINE_ATTR s_conv_done_cb_frame_size_test(adc_continuous_handle_t handle, const adc_continuous_evt_data_t *edata, void *user_data) { test_adc_isr_ctx_t *test_ctx = (test_adc_isr_ctx_t *)user_data; @@ -206,8 +202,8 @@ TEST_CASE("ADC continuous big conv_frame_size test", "[adc_continuous]") sum += ADC_DRIVER_TEST_GET_DATA(p); cnt++; } - esp_rom_printf("avg: %d\n", sum/cnt); - TEST_ASSERT_INT_WITHIN(ADC_TEST_LOW_THRESH, ADC_TEST_LOW_VAL, sum/cnt); + esp_rom_printf("avg: %d\n", sum / cnt); + TEST_ASSERT_INT_WITHIN(ADC_TEST_LOW_THRESH, ADC_TEST_LOW_VAL, sum / cnt); } TEST_ESP_OK(adc_continuous_stop(handle)); @@ -215,7 +211,6 @@ TEST_CASE("ADC continuous big conv_frame_size test", "[adc_continuous]") free(result); } - #define ADC_FLUSH_TEST_SIZE 64 TEST_CASE("ADC continuous flush internal pool", "[adc_continuous][mannual][ignore]") @@ -253,11 +248,11 @@ TEST_CASE("ADC continuous flush internal pool", "[adc_continuous][mannual][ignor for (int i = 0; i < ret_num; i += SOC_ADC_DIGI_RESULT_BYTES) { adc_digi_output_data_t *p = (void*)&result[i]; - #if (SOC_ADC_DIGI_RESULT_BYTES == 2) +#if (SOC_ADC_DIGI_RESULT_BYTES == 2) printf("ADC1, Channel: %d, Value: %d\n", p->type1.channel, p->type1.data); - #else +#else printf("ADC1, Channel: %d, Value: %d\n", p->type2.channel, p->type2.data); - #endif +#endif } /** * With this delay, check the read out data to be the newest data diff --git a/components/esp_adc/test_apps/adc/main/test_adc_driver_iram.c b/components/esp_adc/test_apps/adc/main/test_adc_driver_iram.c index cfe4f32131..a69d4fcf76 100644 --- a/components/esp_adc/test_apps/adc/main/test_adc_driver_iram.c +++ b/components/esp_adc/test_apps/adc/main/test_adc_driver_iram.c @@ -43,7 +43,6 @@ extern void spi_flash_enable_interrupts_caches_and_other_cpu(void); __attribute__((unused)) static void s_test_cache_disable_period_us(test_adc_iram_ctx_t *ctx, uint32_t period_us); - #if CONFIG_ADC_ONESHOT_CTRL_FUNC_IN_IRAM && CONFIG_GPTIMER_ISR_IRAM_SAFE /*--------------------------------------------------------------- ADC oneshot work with cache safe ISR @@ -143,7 +142,6 @@ TEST_CASE("ADC oneshot fast work with ISR and Flash", "[adc_oneshot]") } #endif //#if CONFIG_ADC_ONESHOT_CTRL_FUNC_IN_IRAM && CONFIG_GPTIMER_ISR_IRAM_SAFE - #if CONFIG_ADC_CONTINUOUS_ISR_IRAM_SAFE || CONFIG_GDMA_ISR_IRAM_SAFE #include "esp_adc/adc_continuous.h" /*--------------------------------------------------------------- @@ -165,7 +163,7 @@ static bool IRAM_ATTR NOINLINE_ATTR s_conv_done_cb(adc_continuous_handle_t handl int raw = 0; for (int i = 0; i < edata->size; i += SOC_ADC_DIGI_RESULT_BYTES) { - adc_digi_output_data_t *p = (void*)&(edata->conv_frame_buffer[i]); + adc_digi_output_data_t *p = (void*) & (edata->conv_frame_buffer[i]); #if (SOC_ADC_DIGI_RESULT_BYTES == 2) raw += p->type1.data; #else @@ -181,7 +179,6 @@ static bool IRAM_ATTR NOINLINE_ATTR s_conv_done_cb(adc_continuous_handle_t handl } } - return false; } diff --git a/components/esp_adc/test_apps/adc/main/test_adc_performance.c b/components/esp_adc/test_apps/adc/main/test_adc_performance.c index d255bb7061..e0da5d9aef 100644 --- a/components/esp_adc/test_apps/adc/main/test_adc_performance.c +++ b/components/esp_adc/test_apps/adc/main/test_adc_performance.c @@ -41,7 +41,7 @@ static int s_insert_point(uint32_t value) TEST_ASSERT_GREATER_OR_EQUAL(4096, s_adc_count_size); s_adc_offset = 0; //Fixed to 0 because the array can hold all the data in 12 bits } else { - s_adc_offset = MAX((int)value - s_adc_count_size/2, 0); + s_adc_offset = MAX((int)value - s_adc_count_size / 2, 0); } } @@ -75,15 +75,15 @@ static uint32_t s_get_average(void) uint32_t sum = 0; int count = 0; for (int i = 0; i < s_adc_count_size; i++) { - sum += s_p_adc_count[i] * (s_adc_offset+i); + sum += s_p_adc_count[i] * (s_adc_offset + i); count += s_p_adc_count[i]; } - return sum/count; + return sum / count; } static float s_print_summary(bool figure) { - const int MAX_WIDTH=20; + const int MAX_WIDTH = 20; int max_count = 0; int start = -1; int end = -1; @@ -100,12 +100,12 @@ static float s_print_summary(bool figure) end = i; } count += s_p_adc_count[i]; - sum += s_p_adc_count[i] * (s_adc_offset+i); + sum += s_p_adc_count[i] * (s_adc_offset + i); } if (figure) { for (int i = start; i <= end; i++) { - printf("%4d ", i+s_adc_offset); + printf("%4d ", i + s_adc_offset); int count = s_p_adc_count[i] * MAX_WIDTH / max_count; for (int j = 0; j < count; j++) { putchar('|'); @@ -113,7 +113,7 @@ static float s_print_summary(bool figure) printf(" %d\n", s_p_adc_count[i]); } } - float average = (float)sum/count; + float average = (float)sum / count; float variation_square = 0; for (int i = start; i <= end; i ++) { @@ -125,10 +125,10 @@ static float s_print_summary(bool figure) } printf("%d points.\n", count); - printf("average: %.1f\n", (float)sum/count); - printf("std: %.2f\n", sqrt(variation_square/count)); + printf("average: %.1f\n", (float)sum / count); + printf("std: %.2f\n", sqrt(variation_square / count)); - return sqrt(variation_square/count); + return sqrt(variation_square / count); } #if SOC_ADC_DMA_SUPPORTED @@ -148,7 +148,6 @@ static float s_print_summary(bool figure) #define ADC_TEST_PKG_SIZE 512 #define ADC_TEST_CNT 4096 - static bool IRAM_ATTR s_conv_done_cb(adc_continuous_handle_t handle, const adc_continuous_evt_data_t *edata, void *user_data) { BaseType_t mustYield = pdFALSE; @@ -389,7 +388,6 @@ TEST_CASE("ADC1 oneshot std_deviation performance", "[adc_oneshot][performance]" #define RECORD_TIME_END(p_time) do{__t2 = esp_cpu_get_cycle_count(); *p_time = (__t2-__t1);}while(0) #define GET_US_BY_CCOUNT(t) ((double)t/CPU_FREQ_MHZ) - //ADC Channels #if CONFIG_IDF_TARGET_ESP32 #define ADC1_CALI_SPEED_TEST_CHAN0 ADC_CHANNEL_6 @@ -401,7 +399,6 @@ TEST_CASE("ADC1 oneshot std_deviation performance", "[adc_oneshot][performance]" #define TIMES_PER_ATTEN 10 - static IRAM_ATTR NOINLINE_ATTR uint32_t get_cali_time_in_ccount(adc_cali_handle_t cali_handle, int adc_raw) { uint32_t time; diff --git a/components/esp_adc/test_apps/adc/main/test_common_adc.c b/components/esp_adc/test_apps/adc/main/test_common_adc.c index 9bb4a3b79f..7212d849c9 100644 --- a/components/esp_adc/test_apps/adc/main/test_common_adc.c +++ b/components/esp_adc/test_apps/adc/main/test_common_adc.c @@ -35,7 +35,6 @@ adc_digi_iir_filter_coeff_t g_test_filter_coeff[TEST_FILTER_COEFF_NUMS] = { }; #endif - /*--------------------------------------------------------------- ADC Calibration ---------------------------------------------------------------*/ @@ -90,7 +89,6 @@ void test_adc_calibration_deinit(adc_cali_handle_t handle) #endif } - /*--------------------------------------------------------------- ADC GPIO ---------------------------------------------------------------*/ @@ -102,7 +100,7 @@ void test_adc_set_io_level(adc_unit_t unit, adc_channel_t channel, bool level) #if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED uint32_t io_num = ADC_GET_IO_NUM(unit, channel); - TEST_ESP_OK(gpio_set_pull_mode(io_num, (level ? GPIO_PULLUP_ONLY: GPIO_PULLDOWN_ONLY))); + TEST_ESP_OK(gpio_set_pull_mode(io_num, (level ? GPIO_PULLUP_ONLY : GPIO_PULLDOWN_ONLY))); #else gpio_num_t io_num = ADC_GET_IO_NUM(unit, channel); if (level) { @@ -112,11 +110,10 @@ void test_adc_set_io_level(adc_unit_t unit, adc_channel_t channel, bool level) TEST_ESP_OK(rtc_gpio_pullup_dis(io_num)); TEST_ESP_OK(rtc_gpio_pulldown_en(io_num)); } - TEST_ESP_OK(gpio_set_pull_mode(io_num, (level ? GPIO_PULLUP_ONLY: GPIO_PULLDOWN_ONLY))); + TEST_ESP_OK(gpio_set_pull_mode(io_num, (level ? GPIO_PULLUP_ONLY : GPIO_PULLDOWN_ONLY))); #endif } - void test_adc_set_io_middle(adc_unit_t unit, adc_channel_t channel) { TEST_ASSERT(channel < SOC_ADC_CHANNEL_NUM(unit) && "invalid channel"); diff --git a/components/esp_adc/test_apps/adc/main/test_common_adc.h b/components/esp_adc/test_apps/adc/main/test_common_adc.h index f77200add2..742b536aa9 100644 --- a/components/esp_adc/test_apps/adc/main/test_common_adc.h +++ b/components/esp_adc/test_apps/adc/main/test_common_adc.h @@ -88,7 +88,6 @@ extern "C" { #define ADC_TEST_HIGH_THRESH 200 #endif - /*--------------------------------------------------------------- ADC Attenuation ---------------------------------------------------------------*/ @@ -133,7 +132,6 @@ bool test_adc_calibration_init(adc_unit_t unit, adc_channel_t channel, adc_atten */ void test_adc_calibration_deinit(adc_cali_handle_t handle); - /*--------------------------------------------------------------- ADC GPIO ---------------------------------------------------------------*/ diff --git a/tools/ci/astyle-rules.yml b/tools/ci/astyle-rules.yml index b09def62d5..92e8c8a73a 100644 --- a/tools/ci/astyle-rules.yml +++ b/tools/ci/astyle-rules.yml @@ -52,7 +52,6 @@ components_not_formatted_temporary: - "/components/cxx/" - "/components/driver/" - "/components/efuse/" - - "/components/esp_adc/" - "/components/esp_app_format/" - "/components/esp_bootloader_format/" - "/components/esp_coex/"