NTC Thermistor Driver
API reference
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
ntc::AdcInterface< Derived > Class Template Reference

CRTP-based template interface for ADC operations. More...

#include <ntc_adc_interface.hpp>

Public Member Functions

bool IsInitialized () const
 Check if ADC is initialized.
 
bool EnsureInitialized ()
 Ensure ADC is initialized, initializing if necessary.
 
bool IsChannelAvailable (uint8_t channel) const
 Check if a specific ADC channel is available.
 
AdcError ReadChannelCount (uint8_t channel, uint32_t *count)
 Read raw ADC count value from specified channel.
 
AdcError ReadChannelV (uint8_t channel, float *voltage_v)
 Read voltage value from specified channel.
 
float GetReferenceVoltage () const
 Get the reference voltage of the ADC.
 
uint8_t GetResolutionBits () const
 Get the ADC resolution in bits.
 
 AdcInterface (const AdcInterface &)=delete
 
AdcInterface & operator= (const AdcInterface &)=delete
 
 AdcInterface (AdcInterface &&)=default
 
AdcInterface & operator= (AdcInterface &&)=default
 

Protected Member Functions

 AdcInterface ()=default
 Protected constructor to prevent direct instantiation.
 
 ~AdcInterface ()=default
 Protected destructor.
 

Detailed Description

template<typename Derived>
class ntc::AdcInterface< Derived >

CRTP-based template interface for ADC operations.

This template class provides a hardware-agnostic interface for ADC operations using the CRTP pattern. Platform-specific implementations should inherit from this template with themselves as the template parameter.

Benefits of CRTP:

Example usage:

class Esp32C6Adc : public ntc::AdcInterface<Esp32C6Adc> {
public:
bool IsInitialized() const { ... }
bool EnsureInitialized() { ... }
// ... implement other methods
void DelayMs(uint32_t ms) { vTaskDelay(pdMS_TO_TICKS(ms)); } // optional
};
CRTP-based template interface for ADC operations.
Definition ntc_adc_interface.hpp:55

Optional hook: void DelayMs(uint32_t ms) in the derived class. When the port provides it, the driver waits sample_delay_ms between averaged samples through it (an RTOS sleep or a timed busy-wait). A port without it takes the samples back to back and sample_delay_ms has no effect. The hook is detected at compile time; it is deliberately not declared in this base class.

Template Parameters
DerivedThe derived class type (CRTP pattern)

Constructor & Destructor Documentation

◆ AdcInterface() [1/3]

template<typename Derived >
ntc::AdcInterface< Derived >::AdcInterface ( const AdcInterface< Derived > &  )
delete

◆ AdcInterface() [2/3]

template<typename Derived >
ntc::AdcInterface< Derived >::AdcInterface ( AdcInterface< Derived > &&  )
default

◆ AdcInterface() [3/3]

template<typename Derived >
ntc::AdcInterface< Derived >::AdcInterface ( )
protecteddefault

Protected constructor to prevent direct instantiation.

◆ ~AdcInterface()

template<typename Derived >
ntc::AdcInterface< Derived >::~AdcInterface ( )
protecteddefault

Protected destructor.

Note
Derived classes can have public destructors

Member Function Documentation

◆ EnsureInitialized()

template<typename Derived >
bool ntc::AdcInterface< Derived >::EnsureInitialized ( )
inline

Ensure ADC is initialized, initializing if necessary.

Returns
true if ADC is initialized (or was successfully initialized), false otherwise

◆ GetReferenceVoltage()

template<typename Derived >
float ntc::AdcInterface< Derived >::GetReferenceVoltage ( ) const
inline

Get the reference voltage of the ADC.

Returns
Reference voltage in volts

◆ GetResolutionBits()

template<typename Derived >
uint8_t ntc::AdcInterface< Derived >::GetResolutionBits ( ) const
inline

Get the ADC resolution in bits.

Returns
ADC resolution (e.g., 12 for 12-bit ADC)

◆ IsChannelAvailable()

template<typename Derived >
bool ntc::AdcInterface< Derived >::IsChannelAvailable ( uint8_t  channel) const
inline

Check if a specific ADC channel is available.

Parameters
channelADC channel number to check
Returns
true if channel is available, false otherwise

◆ IsInitialized()

template<typename Derived >
bool ntc::AdcInterface< Derived >::IsInitialized ( ) const
inline

Check if ADC is initialized.

Returns
true if ADC is initialized, false otherwise

◆ operator=() [1/2]

template<typename Derived >
AdcInterface & ntc::AdcInterface< Derived >::operator= ( AdcInterface< Derived > &&  )
default

◆ operator=() [2/2]

template<typename Derived >
AdcInterface & ntc::AdcInterface< Derived >::operator= ( const AdcInterface< Derived > &  )
delete

◆ ReadChannelCount()

template<typename Derived >
AdcError ntc::AdcInterface< Derived >::ReadChannelCount ( uint8_t  channel,
uint32_t *  count 
)
inline

Read raw ADC count value from specified channel.

Parameters
channelADC channel to read from
countPointer to store the raw count value
Returns
AdcError::SUCCESS on success, error code otherwise

◆ ReadChannelV()

template<typename Derived >
AdcError ntc::AdcInterface< Derived >::ReadChannelV ( uint8_t  channel,
float *  voltage_v 
)
inline

Read voltage value from specified channel.

Parameters
channelADC channel to read from
voltage_vPointer to store the voltage value in volts
Returns
AdcError::SUCCESS on success, error code otherwise

The documentation for this class was generated from the following file: