Select one of the symbols to view example projects that use it.
 
Outline
#include <stdint.h>
#include <string.h>
#include "inttypes.h"
#include "sdkconfig.h"
#include "esp_types.h"
#include "esp_err.h"
#include "esp_log.h"
#include "esp_check.h"
#include "hal/adc_types.h"
#define CONFIG_ADC_SUPPRESS_DEPRECATE_WARN
#include "esp_adc_cal.h"
#include "esp_adc_cal_internal_legacy.h"
#include "driver/adc.h"
TAG
esp_adc_cal_get_voltage(adc_channel_t, const esp_adc_cal_characteristics_t *, uint32_t *)
Files
ESP-IDF
components
app_trace
app_update
bootloader_support
bt
cmock
console
cxx
driver
efuse
esp_adc
deprecated
esp32
include
esp32
include
interface
esp_app_format
esp_bootloader_format
esp_coex
esp_common
esp_driver_ana_cmpr
esp_driver_cam
esp_driver_dac
esp_driver_gpio
esp_driver_gptimer
esp_driver_i2c
esp_driver_i2s
esp_driver_jpeg
esp_driver_ledc
esp_driver_mcpwm
esp_driver_parlio
esp_driver_pcnt
esp_driver_rmt
esp_driver_sdio
esp_driver_sdm
esp_driver_sdmmc
esp_driver_sdspi
esp_driver_spi
esp_driver_tsens
esp_driver_uart
esp_driver_usb_serial_jtag
esp_eth
esp_event
esp_gdbstub
esp_hid
esp_http_client
esp_http_server
esp_https_ota
esp_https_server
esp_hw_support
esp_lcd
esp_local_ctrl
esp_mm
esp_netif
esp_partition
esp_phy
esp_pm
esp_psram
esp_ringbuf
esp_rom
esp_security
esp_system
esp_timer
esp_vfs_console
esp_wifi
esp-tls
espcoredump
hal
heap
http_parser
ieee802154
log
mqtt
newlib
nvs_flash
nvs_sec_provider
openthread
perfmon
protobuf-c
protocomm
pthread
rt
sdmmc
soc
spi_flash
spiffs
tcp_transport
ulp
unity
vfs
wear_levelling
wifi_provisioning
wpa_supplicant
xtensa
examples
lwIP
FreeRTOS
cJSON
mbedTLS
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/esp_adc/deprecated/esp_adc_cal_common_legacy.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include <stdint.h> #include <string.h> #include "inttypes.h" #include "sdkconfig.h" #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 #include "esp_types.h" #include "esp_err.h" #include "esp_log.h" #include "esp_check.h" #include "hal/adc_types.h"5 includes #define CONFIG_ADC_SUPPRESS_DEPRECATE_WARN 1 #include "esp_adc_cal.h" #include "esp_adc_cal_internal_legacy.h" #include "driver/adc.h" const __attribute__((unused)) static char *TAG = "ADC_CALI"; esp_err_t esp_adc_cal_get_voltage(adc_channel_t channel, const esp_adc_cal_characteristics_t *chars, uint32_t *voltage) { // Check parameters ESP_RETURN_ON_FALSE(chars != NULL, ESP_ERR_INVALID_ARG, TAG, "No characteristic input"); ESP_RETURN_ON_FALSE(voltage != NULL, ESP_ERR_INVALID_ARG, TAG, "No output buffer"); esp_err_t ret = ESP_OK; int adc_reading; if (chars->adc_num == ADC_UNIT_1) { ESP_RETURN_ON_FALSE(channel < SOC_ADC_CHANNEL_NUM(0), ESP_ERR_INVALID_ARG, TAG, "Invalid channel"); adc_reading = adc1_get_raw(channel); }{...} else { ESP_RETURN_ON_FALSE(channel < SOC_ADC_CHANNEL_NUM(1), ESP_ERR_INVALID_ARG, TAG, "Invalid channel"); ret = adc2_get_raw(channel, chars->bit_width, &adc_reading); }{...} if (ret == ESP_OK) { *voltage = esp_adc_cal_raw_to_voltage((uint32_t)adc_reading, chars); }{...} return ret; }{ ... } #if ESP_ADC_CAL_CURVE_FITTING_SUPPORTED /*------------------------------------------------------------------------------ * Private API *----------------------------------------------------------------------------*//* ... */ int32_t esp_adc_cal_get_reading_error(const esp_adc_error_calc_param_t *param, uint8_t atten) { if (param->v_cali_input == 0) { return 0; }{...} uint64_t v_cali_1 = param->v_cali_input; uint8_t term_num = param->term_num; int32_t error = 0; uint64_t coeff = 0; uint64_t variable[term_num]; uint64_t term[term_num]; memset(variable, 0, term_num * sizeof(uint64_t)); memset(term, 0, term_num * sizeof(uint64_t)); /** * 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); *//* ... */ variable[0] = 1; coeff = (*param->coeff)[atten][0][0]; term[0] = variable[0] * coeff / (*param->coeff)[atten][0][1]; 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; 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); term[i] = term[i] / (*param->coeff)[atten][i][1]; error += (int32_t)term[i] * (*param->sign)[atten][i]; ESP_LOGV(TAG, "term%d is %llu, error is %"PRId32, i, term[i], error); }{...} return error; }{...} /* ... */#endif //#if ESP_ADC_CAL_CURVE_FITTING_SUPPORTED /* ... */ #endif //#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
Details