26#ifndef COMPONENT_HANDLER_ADS7952_HANDLER_H_
27#define COMPONENT_HANDLER_ADS7952_HANDLER_H_
33#include "core/hf-core-drivers/external/hf-ads7952-driver/inc/ads7952.hpp"
34#include "base/BaseSpi.h"
35#include "base/BaseAdc.h"
67 bool transfer(
const uint8_t* tx, uint8_t* rx, std::size_t len)
noexcept;
98 .range = ads7952::Range::TwoVref,
99 .initial_mode = ads7952::Mode::Manual,
100 .auto1_channel_mask = ads7952::kAllChannels,
101 .auto2_last_channel = 11,
215 hf_adc_err_t
ReadChannelV(hf_channel_id_t channel,
float& voltage,
216 hf_u8_t samples = 1, hf_time_t timeout_ms = 0) noexcept override;
227 hf_u8_t samples = 1, hf_time_t timeout_ms = 0) noexcept override;
238 hf_adc_err_t
ReadChannel(hf_channel_id_t channel, hf_u32_t& count,
float& voltage,
239 hf_u8_t samples = 1, hf_time_t timeout_ms = 0) noexcept override;
250 hf_u32_t* counts,
float* voltages) noexcept override;
270 ads7952::ChannelReadings& readings) noexcept;
279 uint8_t
RawManualFrames(uint8_t channel, uint16_t* out, uint8_t n) noexcept;
288 bool ProgramAlarm(uint8_t channel, ads7952::AlarmBound bound, uint16_t threshold_12bit) noexcept;
297 bool ProgramAlarmVoltage(uint8_t channel, ads7952::AlarmBound bound,
float voltage) noexcept;
304 bool SetRange(ads7952::Range range) noexcept;
329 template <typename Fn>
331 using ReturnType =
decltype(fn(std::declval<ads7952::ADS7952<Ads7952SpiAdapter>&>()));
334 if constexpr (std::is_void_v<ReturnType>) {
400 BaseSpi& spi_interface,
std::unique_ptr< Ads7952Handler > CreateAds7952Handler(BaseSpi &spi_interface, const Ads7952HandlerConfig &config=GetDefaultAds7952Config()) noexcept
Create ADS7952 handler instance.
Definition Ads7952Handler.cpp:486
Ads7952HandlerConfig GetDefaultAds7952Config() noexcept
Default ADS7952 handler config (2.5 V Vref, 5.0 V VA, 2×Vref range).
Definition Ads7952Handler.h:94
Unified handler for ADS7952 12-channel SAR ADC with BaseAdc integration.
Definition Ads7952Handler.h:149
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.
Definition Ads7952Handler.cpp:233
bool Initialize() noexcept override
Initialize the ADS7952 ADC (lazy initialization).
Definition Ads7952Handler.cpp:60
bool ProgramAlarm(uint8_t channel, ads7952::AlarmBound bound, uint16_t threshold_12bit) noexcept
Program alarm threshold for a channel (in 12-bit counts).
Definition Ads7952Handler.cpp:322
std::unique_ptr< Ads7952SpiAdapter > spi_adapter_
CRTP SPI adapter.
Definition Ads7952Handler.h:365
~Ads7952Handler() noexcept override=default
Destructor — automatically cleans up driver resources.
bool SetRange(ads7952::Range range) noexcept
Set the ADC input range.
Definition Ads7952Handler.cpp:336
bool ProgramAlarmVoltage(uint8_t channel, ads7952::AlarmBound bound, float voltage) noexcept
Program alarm threshold for a channel (in voltage).
Definition Ads7952Handler.cpp:329
BaseSpi & spi_ref_
Reference to SPI interface.
Definition Ads7952Handler.h:364
uint32_t total_reads_
Successful read count.
Definition Ads7952Handler.h:372
Ads7952HandlerConfig config_
Handler configuration.
Definition Ads7952Handler.h:367
bool ApplyConfiguration() noexcept
Apply configuration to the driver after init.
Definition Ads7952Handler.cpp:445
bool IsChannelAvailable(hf_channel_id_t channel) const noexcept override
Check if a channel is available (0–11).
Definition Ads7952Handler.cpp:147
bool EnsureInitializedLocked() noexcept
Ensure initialized while mutex is already held.
Definition Ads7952Handler.cpp:437
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.
Definition Ads7952Handler.cpp:205
uint8_t GetDeviceIndex() const noexcept
Get the logical device index.
Definition Ads7952Handler.h:357
bool GetHandlerDiagnostics(Ads7952Diagnostics &diag) const noexcept
Get current diagnostics snapshot.
Definition Ads7952Handler.cpp:373
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.
Definition Ads7952Handler.cpp:315
RtosMutex handler_mutex_
Thread safety mutex.
Definition Ads7952Handler.h:368
auto visitDriver(Fn &&fn) noexcept -> decltype(fn(std::declval< ads7952::ADS7952< Ads7952SpiAdapter > & >()))
Visit the underlying ADS7952 driver under handler mutex protection.
Definition Ads7952Handler.h:330
ads7952::ADS7952< Ads7952SpiAdapter > * GetDriver() noexcept
Get raw pointer to the ADS7952 driver for advanced operations.
Definition Ads7952Handler.cpp:354
std::unique_ptr< ads7952::ADS7952< Ads7952SpiAdapter > > adc_driver_
ADS7952 driver.
Definition Ads7952Handler.h:366
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.
Definition Ads7952Handler.cpp:155
char description_[64]
Description string.
Definition Ads7952Handler.h:369
float GetActiveVref() const noexcept
Get the current effective reference voltage.
Definition Ads7952Handler.cpp:344
void DumpDiagnostics() const noexcept
Dump comprehensive diagnostics to log.
Definition Ads7952Handler.cpp:387
hf_u8_t GetMaxChannels() const noexcept override
Get maximum number of ADC channels (always 12 for ADS7952).
Definition Ads7952Handler.cpp:143
ads7952::ReadResult ReadChannelLocked(uint8_t channel) noexcept
Perform a single-channel read under lock (no mutex acquire).
Definition Ads7952Handler.cpp:475
const char * GetDescription() const noexcept
Get handler description string.
Definition Ads7952Handler.cpp:369
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.
Definition Ads7952Handler.cpp:180
uint32_t error_count_
Failed read count.
Definition Ads7952Handler.h:373
bool ReadAllChannels(ads7952::ChannelReadings &readings) noexcept
Read all 12 channels using Auto-1 mode.
Definition Ads7952Handler.cpp:289
bool ReadAuto1Channels(uint16_t mask, ads7952::ChannelReadings &readings) noexcept
Auto-1 burst for a channel mask; stay in Auto-1 (no Manual hop).
Definition Ads7952Handler.cpp:293
bool Deinitialize() noexcept override
Deinitialize the ADC and release driver resources.
Definition Ads7952Handler.cpp:126
CRTP adapter connecting BaseSpi interface to ADS7952 SpiInterface.
Definition Ads7952Handler.h:51
BaseSpi & spi_interface_
Definition Ads7952Handler.h:70
bool transfer(const uint8_t *tx, uint8_t *rx, std::size_t len) noexcept
Perform full-duplex SPI transfer (CRTP dispatch target).
Definition Ads7952Handler.cpp:28
Diagnostic information for an ADS7952 handler instance.
Definition Ads7952Handler.h:113
ads7952::Range current_range
Current input range setting.
Definition Ads7952Handler.h:117
bool initialized
Handler initialization state.
Definition Ads7952Handler.h:114
uint8_t device_index
Logical device index.
Definition Ads7952Handler.h:122
bool driver_ready
Driver instance active and ready.
Definition Ads7952Handler.h:115
uint32_t error_count
Total failed read operations.
Definition Ads7952Handler.h:121
ads7952::Mode current_mode
Current operating mode.
Definition Ads7952Handler.h:116
float active_vref
Effective Vref based on range.
Definition Ads7952Handler.h:119
float vref
Configured Vref.
Definition Ads7952Handler.h:118
uint32_t total_reads
Total successful read operations.
Definition Ads7952Handler.h:120
Configuration for ADS7952 handler initialization.
Definition Ads7952Handler.h:80
float vref
External reference voltage (e.g. 2.5V)
Definition Ads7952Handler.h:81
ads7952::Mode initial_mode
Initial operating mode (Manual/Auto1/Auto2)
Definition Ads7952Handler.h:84
uint8_t device_index
Logical index for multi-device setups (0-based)
Definition Ads7952Handler.h:87
ads7952::Range range
Input range (Vref or 2*Vref clamped to VA)
Definition Ads7952Handler.h:83
uint16_t auto1_channel_mask
Channel mask for Auto-1 mode (bit N = CH N)
Definition Ads7952Handler.h:85
float va
Analog supply voltage (e.g. 5.0V)
Definition Ads7952Handler.h:82
uint8_t auto2_last_channel
Last channel for Auto-2 mode (0–11)
Definition Ads7952Handler.h:86