1 /*
2  * SPDX-FileCopyrightText: 2020-2022 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 "sdkconfig.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 #if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
17 #define ESP_ADC_CAL_CURVE_FITTING_SUPPORTED    1
18 
19 #define COEFF_GROUP_NUM    4
20 #define TERM_MAX           5
21 #endif
22 
23 #if ESP_ADC_CAL_CURVE_FITTING_SUPPORTED
24 /**
25  * Calculation parameters used for curve fitting calibration algorithm error
26  *
27  * @note For atten0 ~ 2, error = (K0 * X^0) + (K1 * X^1) + (K2 * X^2); For atten3, error = (K0 * X^0) + (K1 * X^1)  + (K2 * X^2) + (K3 * X^3) + (K4 * X^4);
28  *       Where X is the `v_cali_input`.
29  */
30 typedef struct {
31     uint64_t v_cali_input;                                      //Input to calculate the error
32     uint8_t  term_num;                                          //Term number of the algorithm formula
33     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)
34     const int32_t  (*sign)[COEFF_GROUP_NUM][TERM_MAX];          //Sign of each term
35 } esp_adc_error_calc_param_t;
36 
37 /**
38  * Calculate the curve fitting error
39  *
40  * @param param   see `esp_adc_error_calc_param_t`
41  * @param atten   ADC attenuation
42  */
43 int32_t esp_adc_cal_get_reading_error(const esp_adc_error_calc_param_t *param, uint8_t atten);
44 
45 #endif  //#if ESP_ADC_CAL_CURVE_FITTING_SUPPORTED
46 
47 
48 #ifdef __cplusplus
49 }
50 #endif
51