11#include <soc/gpio_num.h>
12#include <esp_adc/adc_oneshot.h>
13#include <esp_adc/adc_cali.h>
14#include <freertos/FreeRTOS.h>
33 static constexpr const char* TAG =
"HAL::ADC";
36 mutable SemaphoreHandle_t mutex;
41 adc_oneshot_unit_handle_t adc_handle =
nullptr;
42 adc_cali_handle_t cali_handle =
nullptr;
44 std::vector<adc_channel_t> registered_channels;
47 explicit Controller();
57 static gpio_num_t adc_channel_to_gpio(
const adc_channel_t adc_channel) {
58 switch (adc_channel) {
59 case ADC_CHANNEL_0:
return GPIO_NUM_36;
60 case ADC_CHANNEL_3:
return GPIO_NUM_39;
61 case ADC_CHANNEL_4:
return GPIO_NUM_32;
62 case ADC_CHANNEL_5:
return GPIO_NUM_33;
63 case ADC_CHANNEL_6:
return GPIO_NUM_34;
64 case ADC_CHANNEL_7:
return GPIO_NUM_35;
65 default:
return GPIO_NUM_NC;
80 static Controller _instance;
101 void add(adc_channel_t adc_channel);
111 [[nodiscard]] uint16_t
read_raw(adc_channel_t adc_channel, uint16_t samples = 1)
const;
121 [[nodiscard]] uint16_t
read_millivolts(adc_channel_t adc_channel, uint16_t samples = 1)
const;
void configure(const controller_config_t &config)
Configures the ADC Controller.
Definition adc.cpp:42
static Controller & get_instance()
Returns a reference to the static controller instance.
Definition adc.h:79
uint16_t read_raw(adc_channel_t adc_channel, uint16_t samples=1) const
Reads the current raw ADC reading.
Definition adc.cpp:127
Controller & operator=(const Controller &)=delete
uint16_t read_millivolts(adc_channel_t adc_channel, uint16_t samples=1) const
Reads the current voltage in millivolts.
Definition adc.cpp:159
void shutdown()
Safely shuts down the controller and hardware.
Definition adc.cpp:70
Controller(const Controller &)=delete
void add(adc_channel_t adc_channel)
Adds an ADC input to the controller.
Definition adc.cpp:101
log_source
Definition log_sources.h:12
@ LOG_SOURCE_HAL_ADC
Definition log_sources.h:17
A namespace containing all components of the ADC hardware abstraction layer.
Definition adc.h:20
adc_atten_t attenuation
Definition adc.h:22
adc_bitwidth_t bitwidth
Definition adc.h:23
adc_oneshot_clk_src_t clock_source
Definition adc.h:25
adc_ulp_mode_t ulp_mode
Definition adc.h:24