123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #ifndef KBF_ADC_H
- #define KBF_ADC_H
- // TODO put these in Kconfig
- #define KBF_ADC_ATTEN ADC_ATTEN_DB_0
- #define KBF_ADC_WIDTH ADC_WIDTH_BIT_12
- #define KBF_ADC_DEFAULT_VREF 1100
- #define KBF_ADC_NUM_SAMPLES 64
- #include <driver/adc.h>
- #include <esp_adc_cal.h>
- /**
- * Analog to Digital Converter functions
- */
- namespace kbf::adc {
- static constexpr const char *TAG = "kbf::adc";
- /**
- * ADC1 channel functions
- */
- class ADC1 {
- public:
- /**
- * Initialises ADC1 channel.
- *
- * @param channel ADC1 channel to use
- */
- explicit ADC1(int channel);
- /**
- * Reads raw data from the channel.
- *
- * @return read raw data
- */
- [[nodiscard]] uint32_t readRaw() const;
- /**
- * Reads raw data from the channel and converts it into voltage.
- *
- * @return read input voltage in mV
- */
- [[nodiscard]] uint32_t readVoltage() const;
- /**
- * Calculate voltage from raw input data using characteristics.
- *
- * @param raw input data
- * @return voltage value in mV
- */
- [[nodiscard]] uint32_t rawToVoltage(int raw) const;
- /**
- * ADC1 channel to use.
- */
- const adc1_channel_t channel;
- private:
- /**
- * ADC characteristics.
- */
- esp_adc_cal_characteristics_t *adcChars;
- };
- }
- #endif //KBF_ADC_H
|