Select one of the symbols to view example projects that use it.
 
Outline
#include <esp_types.h>
#include "sdkconfig.h"
#include "esp_log.h"
#include "esp_check.h"
#include "freertos/FreeRTOS.h"
#include "esp_private/periph_ctrl.h"
#include "esp_private/adc_private.h"
#include "esp_private/adc_share_hw_ctrl.h"
#include "driver/gpio.h"
#include "hal/adc_hal.h"
#include "hal/adc_hal_common.h"
#include "soc/adc_periph.h"
TAG
adc_io_to_channel(int, adc_unit_t *const, adc_channel_t *const)
adc_channel_to_io(adc_unit_t, adc_channel_t, int *const)
Files
ESP-IDF
components
app_trace
app_update
bootloader_support
bt
cmock
console
cxx
driver
efuse
esp_adc
deprecated
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/adc_common.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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include <esp_types.h> #include "sdkconfig.h" #include "esp_log.h" #include "esp_check.h" #include "freertos/FreeRTOS.h" #include "esp_private/periph_ctrl.h" #include "esp_private/adc_private.h" #include "esp_private/adc_share_hw_ctrl.h" #include "driver/gpio.h" #include "hal/adc_hal.h" #include "hal/adc_hal_common.h" #include "soc/adc_periph.h"12 includes static const char *TAG = "adc_common"; /*--------------------------------------------------------------- ADC IOs ---------------------------------------------------------------*//* ... */ esp_err_t adc_io_to_channel(int io_num, adc_unit_t * const unit_id, adc_channel_t * const channel) { ESP_RETURN_ON_FALSE(GPIO_IS_VALID_GPIO(io_num), ESP_ERR_INVALID_ARG, TAG, "invalid gpio number"); ESP_RETURN_ON_FALSE(unit_id && channel, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer"); bool found = false; for (int i = 0; i < SOC_ADC_PERIPH_NUM; i++) { for (int j = 0; j < SOC_ADC_MAX_CHANNEL_NUM; j++) { if (adc_channel_io_map[i][j] == io_num) { *channel = j; *unit_id = i; found = true; }{...} }{...} }{...} return (found) ? ESP_OK : ESP_ERR_NOT_FOUND; }{ ... } esp_err_t adc_channel_to_io(adc_unit_t unit_id, adc_channel_t channel, int * const io_num) { ESP_RETURN_ON_FALSE(unit_id < SOC_ADC_PERIPH_NUM, ESP_ERR_INVALID_ARG, TAG, "invalid unit"); ESP_RETURN_ON_FALSE(channel < SOC_ADC_CHANNEL_NUM(unit_id), ESP_ERR_INVALID_ARG, TAG, "invalid channel"); ESP_RETURN_ON_FALSE(io_num, ESP_ERR_INVALID_ARG, TAG, "invalid argument: null pointer"); *io_num = adc_channel_io_map[unit_id][channel]; return ESP_OK; }{ ... } #if SOC_ADC_CALIBRATION_V1_SUPPORTED /*--------------------------------------------------------------- ADC Hardware Calibration ---------------------------------------------------------------*//* ... */ static __attribute__((constructor)) void adc_hw_calibration(void) { adc_apb_periph_claim(); //Calculate all ICode for (int i = 0; i < SOC_ADC_PERIPH_NUM; i++) { adc_hal_calibration_init(i); for (int j = 0; j < SOC_ADC_ATTEN_NUM; j++) { /** * This may get wrong when attenuations are NOT consecutive on some chips, * update this when bringing up the calibration on that chip *//* ... */ adc_calc_hw_calibration_code(i, j); #if SOC_ADC_CALIB_CHAN_COMPENS_SUPPORTED /* Load the channel compensation from efuse */ for (int k = 0; k < SOC_ADC_CHANNEL_NUM(i); k++) { adc_load_hw_calibration_chan_compens(i, k, j); }{...} /* ... */#endif }{...} }{...} }{...} /* ... */#endif //#if SOC_ADC_CALIBRATION_V1_SUPPORTED
Details