HardFOC Core
API reference
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Ads7952Handler Class Reference

Unified handler for ADS7952 12-channel SAR ADC with BaseAdc integration. More...

#include <Ads7952Handler.h>

Inheritance diagram for Ads7952Handler:

Public Member Functions

 Ads7952Handler (BaseSpi &spi_interface, const Ads7952HandlerConfig &config=GetDefaultAds7952Config()) noexcept
 Construct ADS7952 handler with SPI interface.
 
 ~Ads7952Handler () noexcept override=default
 Destructor — automatically cleans up driver resources.
 
 Ads7952Handler (const Ads7952Handler &)=delete
 
Ads7952Handler & operator= (const Ads7952Handler &)=delete
 
 Ads7952Handler (Ads7952Handler &&)=delete
 
Ads7952Handler & operator= (Ads7952Handler &&)=delete
 
bool Initialize () noexcept override
 Initialize the ADS7952 ADC (lazy initialization).
 
bool Deinitialize () noexcept override
 Deinitialize the ADC and release driver resources.
 
hf_u8_t GetMaxChannels () const noexcept override
 Get maximum number of ADC channels (always 12 for ADS7952).
 
bool IsChannelAvailable (hf_channel_id_t channel) const noexcept override
 Check if a channel is available (0–11).
 
hf_adc_err_t ReadChannelV (hf_channel_id_t channel, float &voltage, hf_u8_t samples=1, hf_time_t timeout_ms=0) noexcept override
 Read a channel and return voltage.
 
hf_adc_err_t ReadChannelCount (hf_channel_id_t channel, hf_u32_t &count, hf_u8_t samples=1, hf_time_t timeout_ms=0) noexcept override
 Read a channel and return raw count.
 
hf_adc_err_t ReadChannel (hf_channel_id_t channel, hf_u32_t &count, float &voltage, hf_u8_t samples=1, hf_time_t timeout_ms=0) noexcept override
 Read a channel and return both raw count and voltage.
 
hf_adc_err_t ReadMultipleChannels (const hf_channel_id_t *channels, hf_u8_t num_channels, hf_u32_t *counts, float *voltages) noexcept override
 Read multiple channels in a single batch using Auto-1 mode.
 
bool ReadAllChannels (ads7952::ChannelReadings &readings) noexcept
 Read all 12 channels using Auto-1 mode.
 
bool ReadAuto1Channels (uint16_t mask, ads7952::ChannelReadings &readings) noexcept
 Auto-1 burst for a channel mask; stay in Auto-1 (no Manual hop).
 
uint8_t RawManualFrames (uint8_t channel, uint16_t *out, uint8_t n) noexcept
 Bring-up trace: raw 16-bit response words for a manual select.
 
bool ProgramAlarm (uint8_t channel, ads7952::AlarmBound bound, uint16_t threshold_12bit) noexcept
 Program alarm threshold for a channel (in 12-bit counts).
 
bool ProgramAlarmVoltage (uint8_t channel, ads7952::AlarmBound bound, float voltage) noexcept
 Program alarm threshold for a channel (in voltage).
 
bool SetRange (ads7952::Range range) noexcept
 Set the ADC input range.
 
float GetActiveVref () const noexcept
 Get the current effective reference voltage.
 
ads7952::ADS7952< Ads7952SpiAdapter > * GetDriver () noexcept
 Get raw pointer to the ADS7952 driver for advanced operations.
 
const ads7952::ADS7952< Ads7952SpiAdapter > * GetDriver () const noexcept
 
template<typename Fn >
auto visitDriver (Fn &&fn) noexcept -> decltype(fn(std::declval< ads7952::ADS7952< Ads7952SpiAdapter > & >()))
 Visit the underlying ADS7952 driver under handler mutex protection.
 
const char * GetDescription () const noexcept
 Get handler description string.
 
bool GetHandlerDiagnostics (Ads7952Diagnostics &diag) const noexcept
 Get current diagnostics snapshot.
 
void DumpDiagnostics () const noexcept
 Dump comprehensive diagnostics to log.
 
uint8_t GetDeviceIndex () const noexcept
 Get the logical device index.
 

Private Member Functions

bool EnsureInitializedLocked () noexcept
 Ensure initialized while mutex is already held.
 
bool ApplyConfiguration () noexcept
 Apply configuration to the driver after init.
 
ads7952::ReadResult ReadChannelLocked (uint8_t channel) noexcept
 Perform a single-channel read under lock (no mutex acquire).
 

Private Attributes

BaseSpi & spi_ref_
 Reference to SPI interface.
 
std::unique_ptr< Ads7952SpiAdapter > spi_adapter_
 CRTP SPI adapter.
 
std::unique_ptr< ads7952::ADS7952< Ads7952SpiAdapter > > adc_driver_
 ADS7952 driver.
 
Ads7952HandlerConfig config_
 Handler configuration.
 
RtosMutex handler_mutex_
 Thread safety mutex.
 
char description_ [64]
 Description string.
 
uint32_t total_reads_ {0}
 Successful read count.
 
uint32_t error_count_ {0}
 Failed read count.
 

Detailed Description

Unified handler for ADS7952 12-channel SAR ADC with BaseAdc integration.

Provides a comprehensive interface for the ADS7952 ADC with:

Architecture follows the same patterns as As5047uHandler:

Constructor & Destructor Documentation

◆ Ads7952Handler() [1/3]

Ads7952Handler::Ads7952Handler ( BaseSpi &  spi_interface,
const Ads7952HandlerConfig &  config = GetDefaultAds7952Config() 
)
explicitnoexcept

Construct ADS7952 handler with SPI interface.

Parameters
spi_interfaceReference to BaseSpi implementation (e.g., EspSpiDevice)
configHandler configuration (Vref, VA, range, mode, etc.)
Note
Lightweight constructor following lazy initialization pattern. Driver objects are created during Initialize().

◆ ~Ads7952Handler()

Ads7952Handler::~Ads7952Handler ( )
overridedefaultnoexcept

Destructor — automatically cleans up driver resources.

◆ Ads7952Handler() [2/3]

Ads7952Handler::Ads7952Handler ( const Ads7952Handler &  )
delete

◆ Ads7952Handler() [3/3]

Ads7952Handler::Ads7952Handler ( Ads7952Handler &&  )
delete

Member Function Documentation

◆ ApplyConfiguration()

bool Ads7952Handler::ApplyConfiguration ( )
privatenoexcept

Apply configuration to the driver after init.

◆ Deinitialize()

bool Ads7952Handler::Deinitialize ( )
overridenoexcept

Deinitialize the ADC and release driver resources.

Returns
true if successful

◆ DumpDiagnostics()

void Ads7952Handler::DumpDiagnostics ( ) const
noexcept

Dump comprehensive diagnostics to log.

◆ EnsureInitializedLocked()

bool Ads7952Handler::EnsureInitializedLocked ( )
privatenoexcept

Ensure initialized while mutex is already held.

◆ GetActiveVref()

float Ads7952Handler::GetActiveVref ( ) const
noexcept

Get the current effective reference voltage.

Returns
Active Vref (accounting for range setting)

◆ GetDescription()

const char * Ads7952Handler::GetDescription ( ) const
noexcept

Get handler description string.

◆ GetDeviceIndex()

uint8_t Ads7952Handler::GetDeviceIndex ( ) const
inlinenoexcept

Get the logical device index.

◆ GetDriver() [1/2]

const ads7952::ADS7952< Ads7952SpiAdapter > * Ads7952Handler::GetDriver ( ) const
noexcept

◆ GetDriver() [2/2]

ads7952::ADS7952< Ads7952SpiAdapter > * Ads7952Handler::GetDriver ( )
noexcept

Get raw pointer to the ADS7952 driver for advanced operations.

Returns
Pointer to driver or nullptr if not initialized
Warning
Raw pointer — NOT mutex-protected. Prefer visitDriver().

◆ GetHandlerDiagnostics()

bool Ads7952Handler::GetHandlerDiagnostics ( Ads7952Diagnostics &  diag) const
noexcept

Get current diagnostics snapshot.

◆ GetMaxChannels()

hf_u8_t Ads7952Handler::GetMaxChannels ( ) const
overridenoexcept

Get maximum number of ADC channels (always 12 for ADS7952).

Returns
12

◆ Initialize()

bool Ads7952Handler::Initialize ( )
overridenoexcept

Initialize the ADS7952 ADC (lazy initialization).

Returns
true if successful

Creates the CRTP SPI adapter and ADS7952 driver instance, applies configuration (range, mode, channel mask), and verifies communication.

◆ IsChannelAvailable()

bool Ads7952Handler::IsChannelAvailable ( hf_channel_id_t  channel) const
overridenoexcept

Check if a channel is available (0–11).

Parameters
channelChannel ID (0-based)
Returns
true if channel is in valid range

◆ operator=() [1/2]

Ads7952Handler & Ads7952Handler::operator= ( Ads7952Handler &&  )
delete

◆ operator=() [2/2]

Ads7952Handler & Ads7952Handler::operator= ( const Ads7952Handler &  )
delete

◆ ProgramAlarm()

bool Ads7952Handler::ProgramAlarm ( uint8_t  channel,
ads7952::AlarmBound  bound,
uint16_t  threshold_12bit 
)
noexcept

Program alarm threshold for a channel (in 12-bit counts).

Parameters
channelChannel number (0–11)
boundHigh or Low alarm
threshold_12bit12-bit threshold value (0–4095)
Returns
true if programming succeeded

◆ ProgramAlarmVoltage()

bool Ads7952Handler::ProgramAlarmVoltage ( uint8_t  channel,
ads7952::AlarmBound  bound,
float  voltage 
)
noexcept

Program alarm threshold for a channel (in voltage).

Parameters
channelChannel number (0–11)
boundHigh or Low alarm
voltageThreshold voltage
Returns
true if programming succeeded

◆ RawManualFrames()

uint8_t Ads7952Handler::RawManualFrames ( uint8_t  channel,
uint16_t *  out,
uint8_t  n 
)
noexcept

Bring-up trace: raw 16-bit response words for a manual select.

Parameters
channelChannel selected in frame 0.
outDestination for n words (DO15:12 address, DO11:0 data).
nFrames to clock (select + CONTINUEs).
Returns
Words written (0 when not initialized).

◆ ReadAllChannels()

bool Ads7952Handler::ReadAllChannels ( ads7952::ChannelReadings &  readings)
noexcept

Read all 12 channels using Auto-1 mode.

Parameters
readingsOutput: populated ChannelReadings structure
Returns
true if successful

◆ ReadAuto1Channels()

bool Ads7952Handler::ReadAuto1Channels ( uint16_t  mask,
ads7952::ChannelReadings &  readings 
)
noexcept

Auto-1 burst for a channel mask; stay in Auto-1 (no Manual hop).

Parameters
maskBits 0–11; 0 uses ads7952::kAllChannels.
[out]readingsPer-channel counts for bits set in mask.
Returns
true when every masked channel arrived.

◆ ReadChannel()

hf_adc_err_t Ads7952Handler::ReadChannel ( hf_channel_id_t  channel,
hf_u32_t &  count,
float &  voltage,
hf_u8_t  samples = 1,
hf_time_t  timeout_ms = 0 
)
overridenoexcept

Read a channel and return both raw count and voltage.

Parameters
channelChannel ID (0–11)
countOutput: raw 12-bit count
voltageOutput: converted voltage
samplesNumber of samples to average (default 1)
timeout_msTimeout in ms (0 = default)
Returns
ADC error code

◆ ReadChannelCount()

hf_adc_err_t Ads7952Handler::ReadChannelCount ( hf_channel_id_t  channel,
hf_u32_t &  count,
hf_u8_t  samples = 1,
hf_time_t  timeout_ms = 0 
)
overridenoexcept

Read a channel and return raw count.

Parameters
channelChannel ID (0–11)
countOutput: raw 12-bit ADC count (0–4095)
samplesNumber of samples to average (default 1)
timeout_msTimeout in ms (0 = default)
Returns
ADC error code

◆ ReadChannelLocked()

ads7952::ReadResult Ads7952Handler::ReadChannelLocked ( uint8_t  channel)
privatenoexcept

Perform a single-channel read under lock (no mutex acquire).

◆ ReadChannelV()

hf_adc_err_t Ads7952Handler::ReadChannelV ( hf_channel_id_t  channel,
float &  voltage,
hf_u8_t  samples = 1,
hf_time_t  timeout_ms = 0 
)
overridenoexcept

Read a channel and return voltage.

Parameters
channelChannel ID (0–11)
voltageOutput: converted voltage
samplesNumber of samples to average (default 1)
timeout_msTimeout in ms (0 = default)
Returns
ADC error code

◆ ReadMultipleChannels()

hf_adc_err_t Ads7952Handler::ReadMultipleChannels ( const hf_channel_id_t *  channels,
hf_u8_t  num_channels,
hf_u32_t *  counts,
float *  voltages 
)
overridenoexcept

Read multiple channels in a single batch using Auto-1 mode.

Parameters
channelsArray of channel IDs to read
num_channelsNumber of channels to read
countsOutput array: raw 12-bit counts (may be nullptr)
voltagesOutput array: converted voltages (may be nullptr)
Returns
ADC error code

◆ SetRange()

bool Ads7952Handler::SetRange ( ads7952::Range  range)
noexcept

Set the ADC input range.

Parameters
rangeVref or 2*Vref (clamped to VA)
Returns
true if successful

◆ visitDriver()

template<typename Fn >
auto Ads7952Handler::visitDriver ( Fn &&  fn) -> decltype(fn(std::declval<ads7952::ADS7952<Ads7952SpiAdapter>&>()))
inlinenoexcept

Visit the underlying ADS7952 driver under handler mutex protection.

Template Parameters
FnCallable accepting ADS7952<Ads7952SpiAdapter>&
Returns
Callable result or default-constructed value when driver is unavailable

Member Data Documentation

◆ adc_driver_

std::unique_ptr<ads7952::ADS7952<Ads7952SpiAdapter> > Ads7952Handler::adc_driver_
private

ADS7952 driver.

◆ config_

Ads7952HandlerConfig Ads7952Handler::config_
private

Handler configuration.

◆ description_

char Ads7952Handler::description_[64]
private

Description string.

◆ error_count_

uint32_t Ads7952Handler::error_count_ {0}
mutableprivate

Failed read count.

◆ handler_mutex_

RtosMutex Ads7952Handler::handler_mutex_
mutableprivate

Thread safety mutex.

◆ spi_adapter_

std::unique_ptr<Ads7952SpiAdapter> Ads7952Handler::spi_adapter_
private

CRTP SPI adapter.

◆ spi_ref_

BaseSpi& Ads7952Handler::spi_ref_
private

Reference to SPI interface.

◆ total_reads_

uint32_t Ads7952Handler::total_reads_ {0}
mutableprivate

Successful read count.


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