adc_arch.h

Architecture specific ADC functions for ESP32.

enum adc_attenuation_t
ADC_ATTENUATION_0_DB = 0
full-range is about 1.1 V (Vref)
ADC_ATTENUATION_3_DB
full-range is about 1.5 V
ADC_ATTENUATION_6_DB
full-range is about 2.2 V
ADC_ATTENUATION_11_DB
full-range is about 3.3 V
int adc_set_attenuation(adc.h::adc_t line, adc_arch.h::adc_attenuation_t atten)

Set the attenuation for the ADC line.

Default attenuation is 11 dB.

For each ADC line, an attenuation of the input signal can be defined separately. This results in different full ranges of the measurable voltage at the input. The attenuation can be set to 0 dB, 3 dB, 6 dB and 11 dB, with 11 dB being the standard attenuation. Since an ADC input is measured against a reference voltage Vref of 1.1 V, approximately the following measurement ranges are given when using a corresponding attenuation:

Attenuation Voltage Range Symbol
0 dB 0 … 1.1V (Vref) ADC_ATTENUATION_0_DB
3 dB 0 … 1.5V ADC_ATTENUATION_3_DB
6 dB 0 … 2.2V ADC_ATTENUATION_6_DB
11 dB (default) 0 … 3.3V ADC_ATTENUATION_11_DB

Please note: The reference voltage Vref can vary from device to device in the range of 1.0V and 1.2V. The Vref of a device can be read with the function adc_vref_to_gpio25 at the pin GPIO 25. The results of the ADC input can then be adjusted accordingly.

Parameters

line:ADC line for which the attenuation is set
atten:Attenuation, see type definition of *adc_attenuation_t

Return values

  • 0 on success
  • -1 on invalid ADC line
int adc_vref_to_gpio25(void)

Output ADC reference voltage to GPIO25.

Return values

  • 0 on success
  • -1 on invalid ADC line
int rtcio_config_sleep_mode(gpio.h::gpio_t pin, bool mode, bool input)

Configure sleep mode for an GPIO pin if the pin is an RTCIO pin.

Parameters

pin:GPIO pin
mode:active in sleep mode if true
input:as input if true, as output otherwise

Return values

  • 0 success
  • -1 on invalid pin