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

Thread-safe BaseAdc handler for one ADS9324 on a SPI bus. More...

#include <Ads9324Handler.h>

Inheritance diagram for Ads9324Handler:

Public Member Functions

 Ads9324Handler (BaseSpi &spi, BaseGpio *convst, BaseGpio *drdy=nullptr, const Ads9324HandlerConfig &config=GetDefaultAds9324Config()) noexcept
 Construct handler (lazy — no SPI).
 
 ~Ads9324Handler () noexcept override=default
 Releases driver/adapter unique_ptrs.
 
 Ads9324Handler (const Ads9324Handler &)=delete
 
Ads9324Handler & operator= (const Ads9324Handler &)=delete
 
 Ads9324Handler (Ads9324Handler &&)=delete
 
Ads9324Handler & operator= (Ads9324Handler &&)=delete
 
bool Initialize () noexcept override
 Create adapter + driver, 1-lane SDOUT bring-up, DEVICE_ID, default PGA.
 
bool Deinitialize () noexcept override
 Destroy driver and adapter; leave GPIOs as-is.
 
hf_u8_t GetMaxChannels () const noexcept override
 Channel count for BaseAdc.
 
bool IsChannelAvailable (hf_channel_id_t channel) const noexcept override
 Whether channel is in [0, 15] (API 0 = AIN1).
 
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 voltage (averaged). Internally a full simultaneous snapshot per sample.
 
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 raw count (averaged). See ReadChannel for signed-code caveat.
 
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 count and voltage (averaged).
 
hf_adc_err_t ReadMultipleChannels (const hf_channel_id_t *channels, hf_u8_t num_channels, hf_u32_t *counts, float *voltages) noexcept override
 One snapshot, then index the requested channels.
 
bool ConfigureChannel (uint8_t channel, const ads9324::ChannelConfig &cfg) noexcept
 Program one channel PGA (mutex-protected).
 
bool SetChannelOffset (uint8_t channel, int16_t ofs_10bit) noexcept
 Program OFS_AINx (10-bit two's-complement).
 
bool SetChannelGain (uint8_t channel, int16_t gan_14bit) noexcept
 Program GAN_AINx (14-bit two's complement). Correction = GAN / 65536.
 
bool ReadSnapshot (ads9324::Snapshot &snap) noexcept
 Simultaneous capture of all enabled channels.
 
ads9324::ADS9324< Ads9324SpiHostAdapter, Ads9324SpiHostAdapter > * GetDriver () noexcept
 Raw driver pointer.
 
const ads9324::ADS9324< Ads9324SpiHostAdapter, Ads9324SpiHostAdapter > * GetDriver () const noexcept
 Raw driver pointer.
 
template<typename Fn >
auto visitDriver (Fn &&fn) noexcept -> decltype(fn(std::declval< ads9324::ADS9324< Ads9324SpiHostAdapter, Ads9324SpiHostAdapter > & >()))
 Invoke fn with the driver while holding the handler mutex.
 
const char * GetDescription () const noexcept
 Human-readable instance tag (ADS9324_Handler_SPI_DevN).
 
bool GetHandlerDiagnostics (Ads9324Diagnostics &diag) const noexcept
 Copy diagnostics under the handler mutex.
 
void DumpDiagnostics () const noexcept
 Log CONVST/DRDY presence, DEVICE_ID, and read/error counts.
 
uint8_t GetDeviceIndex () const noexcept
 Logical device index from config.
 

Private Member Functions

bool EnsureInitializedLocked () noexcept
 Initialize if needed while handler_mutex_ is already held.
 

Private Attributes

BaseSpi & spi_ref_
 SPI device.
 
BaseGpio * convst_
 Required CONVST.
 
BaseGpio * drdy_
 Optional DRDY.
 
std::unique_ptr< Ads9324SpiHostAdapter > adapter_
 CRTP bridge.
 
std::unique_ptr< ads9324::ADS9324< Ads9324SpiHostAdapter, Ads9324SpiHostAdapter > > adc_driver_
 
Ads9324HandlerConfig config_
 Init defaults.
 
RtosMutex handler_mutex_
 Serializes all driver access except GetDriver().
 
char description_ [64] {}
 GetDescription buffer.
 
uint32_t total_reads_ {0}
 Successful operations.
 
uint32_t error_count_ {0}
 Failures.
 
uint16_t device_id_ {0}
 Cached DEVICE_ID.
 

Detailed Description

Thread-safe BaseAdc handler for one ADS9324 on a SPI bus.

CONVST is required for conversion. DRDY may be nullptr (timed fallback). Construction is lightweight; SPI and GPIO traffic start in Initialize.

Constructor & Destructor Documentation

◆ Ads9324Handler() [1/3]

Ads9324Handler::Ads9324Handler ( BaseSpi &  spi,
BaseGpio *  convst,
BaseGpio *  drdy = nullptr,
const Ads9324HandlerConfig &  config = GetDefaultAds9324Config() 
)
noexcept

Construct handler (lazy — no SPI).

Parameters
spiSPI device with the ADS9324 CS.
convstCONVST GPIO; must be non-null at Initialize.
drdyOptional DRDY; nullptr uses timed wait after CONVST.
configDefault PGA, data format, device index.

◆ ~Ads9324Handler()

Ads9324Handler::~Ads9324Handler ( )
overridedefaultnoexcept

Releases driver/adapter unique_ptrs.

◆ Ads9324Handler() [2/3]

Ads9324Handler::Ads9324Handler ( const Ads9324Handler &  )
delete

◆ Ads9324Handler() [3/3]

Ads9324Handler::Ads9324Handler ( Ads9324Handler &&  )
delete

Member Function Documentation

◆ ConfigureChannel()

bool Ads9324Handler::ConfigureChannel ( uint8_t  channel,
const ads9324::ChannelConfig &  cfg 
)
noexcept

Program one channel PGA (mutex-protected).

Parameters
channel0–15.
cfgInput type, range, bandwidth, CME.
Returns
true on success.

◆ Deinitialize()

bool Ads9324Handler::Deinitialize ( )
overridenoexcept

Destroy driver and adapter; leave GPIOs as-is.

Returns
Always true.

◆ DumpDiagnostics()

void Ads9324Handler::DumpDiagnostics ( ) const
noexcept

Log CONVST/DRDY presence, DEVICE_ID, and read/error counts.

◆ EnsureInitializedLocked()

bool Ads9324Handler::EnsureInitializedLocked ( )
privatenoexcept

Initialize if needed while handler_mutex_ is already held.

Return values
falseDriver still unavailable.

◆ GetDescription()

const char * Ads9324Handler::GetDescription ( ) const
noexcept

Human-readable instance tag (ADS9324_Handler_SPI_DevN).

◆ GetDeviceIndex()

uint8_t Ads9324Handler::GetDeviceIndex ( ) const
inlinenoexcept

Logical device index from config.

◆ GetDriver() [1/2]

const ads9324::ADS9324< Ads9324SpiHostAdapter, Ads9324SpiHostAdapter > * Ads9324Handler::GetDriver ( ) const
noexcept

Raw driver pointer.

Returns
Driver or nullptr if not initialized.
Warning
Not mutex-protected. Prefer visitDriver.

◆ GetDriver() [2/2]

ads9324::ADS9324< Ads9324SpiHostAdapter, Ads9324SpiHostAdapter > * Ads9324Handler::GetDriver ( )
noexcept

Raw driver pointer.

Returns
Driver or nullptr if not initialized.
Warning
Not mutex-protected. Prefer visitDriver.

◆ GetHandlerDiagnostics()

bool Ads9324Handler::GetHandlerDiagnostics ( Ads9324Diagnostics &  diag) const
noexcept

Copy diagnostics under the handler mutex.

Parameters
[out]diagFilled snapshot.
Returns
Always true.

◆ GetMaxChannels()

hf_u8_t Ads9324Handler::GetMaxChannels ( ) const
overridenoexcept

Channel count for BaseAdc.

Returns
16.

◆ Initialize()

bool Ads9324Handler::Initialize ( )
overridenoexcept

Create adapter + driver, 1-lane SDOUT bring-up, DEVICE_ID, default PGA.

Return values
trueDevice ready.
falseCONVST missing, EnsureInitialized failed, or PGA write failed.

◆ IsChannelAvailable()

bool Ads9324Handler::IsChannelAvailable ( hf_channel_id_t  channel) const
overridenoexcept

Whether channel is in [0, 15] (API 0 = AIN1).

Parameters
channel0-based channel id.

◆ operator=() [1/2]

Ads9324Handler & Ads9324Handler::operator= ( Ads9324Handler &&  )
delete

◆ operator=() [2/2]

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

◆ ReadChannel()

hf_adc_err_t Ads9324Handler::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 count and voltage (averaged).

Each sample calls ads9324::ADS9324::ReadChannel, which itself runs a full 16-channel snapshot. Prefer ReadSnapshot or ReadMultipleChannels when several channels are needed.

Parameters
channel0–15.
[out]countMean of signed codes cast through uint16_t (two's complement bit pattern, not a magnitude).
[out]voltageMean voltage.
samplesAverage count.
timeout_msUnused.

◆ ReadChannelCount()

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

Read raw count (averaged). See ReadChannel for signed-code caveat.

Parameters
channel0–15.
[out]countAveraged count stored as uint16_t inside hf_u32_t.
samplesAverage count.
timeout_msUnused.

◆ ReadChannelV()

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

Read voltage (averaged). Internally a full simultaneous snapshot per sample.

Parameters
channel0–15.
[out]voltageAveraged voltage.
samplesAverage count (0 treated as 1).
timeout_msUnused (kept for BaseAdc signature).
Returns
ADC_SUCCESS or a hf_adc_err_t failure.

◆ ReadMultipleChannels()

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

One snapshot, then index the requested channels.

Parameters
channelsArray of channel ids.
num_channelsLength of channels.
[out]countsOptional per-channel counts (may be nullptr).
[out]voltagesOptional per-channel voltages (may be nullptr).

◆ ReadSnapshot()

bool Ads9324Handler::ReadSnapshot ( ads9324::Snapshot &  snap)
noexcept

Simultaneous capture of all enabled channels.

Parameters
[out]snapDriver snapshot (valid_mask + counts + voltages).
Returns
true when snap reports ok().

◆ SetChannelGain()

bool Ads9324Handler::SetChannelGain ( uint8_t  channel,
int16_t  gan_14bit 
)
noexcept

Program GAN_AINx (14-bit two's complement). Correction = GAN / 65536.

Parameters
channel0–15.
gan_14bitSigned gain, ads9324::kGainMin (−8192) to kGainMax (+8191); pass the signed value, not the raw 14-bit pattern.
Returns
false for a value outside the field (nothing is written) or a bus error.

◆ SetChannelOffset()

bool Ads9324Handler::SetChannelOffset ( uint8_t  channel,
int16_t  ofs_10bit 
)
noexcept

Program OFS_AINx (10-bit two's-complement).

Parameters
channel0–15.
ofs_10bitOffset, ads9324::kOffsetMin (−512) to kOffsetMax (+511).
Returns
false for a value outside the field (nothing is written) or a bus error.

◆ visitDriver()

template<typename Fn >
auto Ads9324Handler::visitDriver ( Fn &&  fn) -> decltype(fn( std::declval<ads9324::ADS9324<Ads9324SpiHostAdapter, Ads9324SpiHostAdapter>&>()))
inlinenoexcept

Invoke fn with the driver while holding the handler mutex.

Template Parameters
FnCallable accepting ADS9324<Ads9324SpiHostAdapter, Ads9324SpiHostAdapter>&.
Parameters
fnVisitor (window comparator, power-down, channel-count, …).
Returns
Visitor result, or default-constructed value if the driver is down.

Member Data Documentation

◆ adapter_

std::unique_ptr<Ads9324SpiHostAdapter> Ads9324Handler::adapter_
private

CRTP bridge.

◆ adc_driver_

std::unique_ptr<ads9324::ADS9324<Ads9324SpiHostAdapter, Ads9324SpiHostAdapter> > Ads9324Handler::adc_driver_
private

◆ config_

Ads9324HandlerConfig Ads9324Handler::config_
private

Init defaults.

◆ convst_

BaseGpio* Ads9324Handler::convst_
private

Required CONVST.

◆ description_

char Ads9324Handler::description_[64] {}
private

GetDescription buffer.

◆ device_id_

uint16_t Ads9324Handler::device_id_ {0}
private

Cached DEVICE_ID.

◆ drdy_

BaseGpio* Ads9324Handler::drdy_
private

Optional DRDY.

◆ error_count_

uint32_t Ads9324Handler::error_count_ {0}
mutableprivate

Failures.

◆ handler_mutex_

RtosMutex Ads9324Handler::handler_mutex_
mutableprivate

Serializes all driver access except GetDriver().

◆ spi_ref_

BaseSpi& Ads9324Handler::spi_ref_
private

SPI device.

◆ total_reads_

uint32_t Ads9324Handler::total_reads_ {0}
mutableprivate

Successful operations.


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