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 #include "esp_adc/adc_cali.h" 12 #include "adc_cali_schemes.h" 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 19 #if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED 20 /*--------------------------------------------------------------- 21 Curve Fitting Calibration Scheme 22 ---------------------------------------------------------------*/ 23 typedef struct { 24 adc_unit_t unit_id; ///< ADC unit 25 adc_channel_t chan; ///< ADC channel, for chips with SOC_ADC_CALIB_CHAN_COMPENS_SUPPORTED, calibration can be per channel 26 adc_atten_t atten; ///< ADC attenuation 27 adc_bitwidth_t bitwidth; ///< ADC raw output bitwidth 28 } adc_cali_curve_fitting_config_t; 29 30 /** 31 * @brief Create a Curve Fitting calibration scheme 32 * 33 * After creating, you'll get a handle to this scheme. Then you can use the driver APIS in `esp_adc/adc_cali.h` to do the 34 * ADC calibration via the handle you get. 35 * 36 * @param[in] config Initial configurations 37 * @param[out] handle ADC calibration handle 38 * 39 * @return 40 * - ESP_OK: On success 41 * - ESP_ERR_INVALID_ARG: Invalid argument 42 * - ESP_ERR_NO_MEM: No enough memory 43 * - ESP_ERR_NOT_SUPPORTED: Scheme required eFuse bits not burnt 44 */ 45 esp_err_t adc_cali_create_scheme_curve_fitting(const adc_cali_curve_fitting_config_t *config, adc_cali_handle_t *ret_handle); 46 47 /** 48 * @brief Delete the Curve Fitting calibration scheme handle 49 * 50 * @param[in] handle ADC calibration handle 51 * 52 * @return 53 * - ESP_OK: On success 54 * - ESP_ERR_INVALID_ARG: Invalid argument 55 */ 56 esp_err_t adc_cali_delete_scheme_curve_fitting(adc_cali_handle_t handle); 57 #endif // #if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED 58 59 60 #if ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED 61 /*--------------------------------------------------------------- 62 Line Fitting Calibration Scheme 63 ---------------------------------------------------------------*/ 64 /** 65 * @brief Type of calibration value used in line fitting scheme characterization 66 */ 67 typedef enum { 68 ADC_CALI_LINE_FITTING_EFUSE_VAL_EFUSE_VREF = 0, ///< Characterization based on reference voltage stored in eFuse 69 ADC_CALI_LINE_FITTING_EFUSE_VAL_EFUSE_TP = 1, ///< Characterization based on Two Point values stored in eFuse 70 ADC_CALI_LINE_FITTING_EFUSE_VAL_DEFAULT_VREF = 2, ///< Characterization based on default reference voltage 71 } adc_cali_line_fitting_efuse_val_t; 72 73 typedef struct { 74 adc_unit_t unit_id; ///< ADC unit 75 adc_atten_t atten; ///< ADC attenuation 76 adc_bitwidth_t bitwidth; ///< ADC raw output bitwidth 77 #if CONFIG_IDF_TARGET_ESP32 78 /** 79 * @brief Default ADC reference voltage in mV. 80 * 81 * Use this when the ADC calibration value is `ADC_CALI_LINE_FITTING_EFUSE_VAL_DEFAULT_VREF`. 82 * If others, driver will use the calibration code burnt in the eFuse for calibration. 83 */ 84 uint32_t default_vref; 85 #endif 86 } adc_cali_line_fitting_config_t; 87 88 /** 89 * @brief Create a Line Fitting calibration scheme 90 * 91 * After creating, you'll get a handle to this scheme. Then you can use the driver APIS in `esp_adc/adc_cali.h` to do the 92 * ADC calibration via the handle you get. 93 * 94 * @param[in] config Initial configurations 95 * @param[out] handle ADC calibration handle 96 * 97 * @return 98 * - ESP_OK: On success 99 * - ESP_ERR_INVALID_ARG: Invalid argument 100 * - ESP_ERR_NO_MEM: No enough memory 101 * - ESP_ERR_NOT_SUPPORTED: Scheme required eFuse bits not burnt 102 */ 103 esp_err_t adc_cali_create_scheme_line_fitting(const adc_cali_line_fitting_config_t *config, adc_cali_handle_t *ret_handle); 104 105 /** 106 * @brief Delete the Line Fitting calibration scheme handle 107 * 108 * @param[in] handle ADC calibration handle 109 * 110 * @return 111 * - ESP_OK: On success 112 * - ESP_ERR_INVALID_ARG: Invalid argument 113 */ 114 esp_err_t adc_cali_delete_scheme_line_fitting(adc_cali_handle_t handle); 115 116 #if CONFIG_IDF_TARGET_ESP32 117 /** 118 * @brief Helper function to quickly check the ADC calibration code burnt on your eFuse 119 * 120 * @note If `cali_val` equals to `ESP_ADC_CALI_VAL_DEFAULT_VREF`, please set the `default_vref` 121 * when creating this scheme (See `ESP_ADC_CALI_SCHEME_VER_LINE_FITTING_init_t`) 122 * 123 * @param[out] cali_val See `esp_adc_cali_value_t` 124 * 125 * @return 126 * - ESP_OK: On success 127 * - ESP_ERR_INVALID_ARG: Invalid argument 128 * - ESP_ERR_NOT_SUPPORTED: Scheme required eFuse bits not burnt 129 */ 130 esp_err_t adc_cali_scheme_line_fitting_check_efuse(adc_cali_line_fitting_efuse_val_t *cali_val); 131 #endif // CONFIG_IDF_TARGET_ESP32 132 #endif // #if ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED 133 134 #ifdef __cplusplus 135 } 136 #endif 137