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>
32 static constexpr const char* TAG =
"HAL::ADC";
34 mutable SemaphoreHandle_t mutex;
39 adc_oneshot_unit_handle_t adc_handle =
nullptr;
40 adc_cali_handle_t cali_handle =
nullptr;
42 std::vector<adc_channel_t> registered_channels;
45 explicit Controller();
55 static gpio_num_t adc_channel_to_gpio(
const adc_channel_t adc_channel) {
56 switch (adc_channel) {
57 case ADC_CHANNEL_0:
return GPIO_NUM_36;
58 case ADC_CHANNEL_3:
return GPIO_NUM_39;
59 case ADC_CHANNEL_4:
return GPIO_NUM_32;
60 case ADC_CHANNEL_5:
return GPIO_NUM_33;
61 case ADC_CHANNEL_6:
return GPIO_NUM_34;
62 case ADC_CHANNEL_7:
return GPIO_NUM_35;
63 default:
return GPIO_NUM_NC;
78 static Controller _instance;
99 void add(adc_channel_t adc_channel);
109 [[nodiscard]] uint16_t
read_raw(adc_channel_t adc_channel, uint16_t samples = 1)
const;
119 [[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:36
static Controller & get_instance()
Returns a reference to the static controller instance.
Definition adc.h:77
uint16_t read_raw(adc_channel_t adc_channel, uint16_t samples=1) const
Reads the current raw ADC reading.
Definition adc.cpp:121
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:152
void shutdown()
Safely shuts down the controller and hardware.
Definition adc.cpp:64
Controller(const Controller &)=delete
void add(adc_channel_t adc_channel)
Adds an ADC input to the controller.
Definition adc.cpp:95
A namespace containing all components of the ADC hardware abstraction layer.
Definition adc.h:19
adc_atten_t attenuation
Definition adc.h:21
adc_bitwidth_t bitwidth
Definition adc.h:22
adc_oneshot_clk_src_t clock_source
Definition adc.h:24
adc_ulp_mode_t ulp_mode
Definition adc.h:23