NTC Thermistor Driver
API reference
Loading...
Searching...
No Matches
ntc_adc_interface.hpp
Go to the documentation of this file.
1
6#pragma once
7#include <cstdint>
8
9namespace ntc {
10
14enum class AdcError : uint8_t {
15 Success = 0,
19 Timeout,
21};
22
55template <typename Derived> class AdcInterface {
56public:
61 [[nodiscard]] bool IsInitialized() const {
62 return static_cast<const Derived *>(this)->IsInitialized();
63 }
64
71 return static_cast<Derived *>(this)->EnsureInitialized();
72 }
73
79 [[nodiscard]] bool IsChannelAvailable(uint8_t channel) const {
80 return static_cast<const Derived *>(this)->IsChannelAvailable(channel);
81 }
82
89 AdcError ReadChannelCount(uint8_t channel, uint32_t *count) {
90 return static_cast<Derived *>(this)->ReadChannelCount(channel, count);
91 }
92
99 AdcError ReadChannelV(uint8_t channel, float *voltage_v) {
100 return static_cast<Derived *>(this)->ReadChannelV(channel, voltage_v);
101 }
102
107 [[nodiscard]] float GetReferenceVoltage() const {
108 return static_cast<const Derived *>(this)->GetReferenceVoltage();
109 }
110
115 [[nodiscard]] uint8_t GetResolutionBits() const {
116 return static_cast<const Derived *>(this)->GetResolutionBits();
117 }
118
119 // Prevent copying
120 AdcInterface(const AdcInterface &) = delete;
122
123 // Allow moving
126
127protected:
131 AdcInterface() = default;
132
137 ~AdcInterface() = default;
138};
139
140} // namespace ntc
CRTP-based template interface for ADC operations.
Definition ntc_adc_interface.hpp:55
AdcInterface & operator=(const AdcInterface &)=delete
uint8_t GetResolutionBits() const
Get the ADC resolution in bits.
Definition ntc_adc_interface.hpp:115
float GetReferenceVoltage() const
Get the reference voltage of the ADC.
Definition ntc_adc_interface.hpp:107
bool IsChannelAvailable(uint8_t channel) const
Check if a specific ADC channel is available.
Definition ntc_adc_interface.hpp:79
AdcInterface(AdcInterface &&)=default
bool EnsureInitialized()
Ensure ADC is initialized, initializing if necessary.
Definition ntc_adc_interface.hpp:70
bool IsInitialized() const
Check if ADC is initialized.
Definition ntc_adc_interface.hpp:61
AdcError ReadChannelV(uint8_t channel, float *voltage_v)
Read voltage value from specified channel.
Definition ntc_adc_interface.hpp:99
~AdcInterface()=default
Protected destructor.
AdcInterface(const AdcInterface &)=delete
AdcError ReadChannelCount(uint8_t channel, uint32_t *count)
Read raw ADC count value from specified channel.
Definition ntc_adc_interface.hpp:89
AdcInterface & operator=(AdcInterface &&)=default
AdcInterface()=default
Protected constructor to prevent direct instantiation.
Definition ntc_adc_interface.hpp:9
AdcError
ADC error codes.
Definition ntc_adc_interface.hpp:14
@ HardwareError
Hardware-level error.
@ Success
Operation successful.
@ ReadFailed
ADC read operation failed.
@ InvalidChannel
Invalid ADC channel.
@ NotInitialized
ADC not initialized.
@ Timeout
Operation timeout.