42#define ADS7952_HEADER_INCLUDED
75template <
typename SpiType>
160 return (
static_cast<float>(count) * vref) /
static_cast<float>(
reg::MAX_COUNT);
262 uint16_t threshold_12bit)
noexcept;
292 float voltage)
noexcept;
353 float GetVref() const noexcept {
return vref_; }
356 float GetVA() const noexcept {
return va_; }
367 void SetVref(
float vref)
noexcept;
379 void SetVA(
float va)
noexcept;
404 uint16_t spiTransfer16(uint16_t command)
noexcept;
410 bool Initialize() noexcept;
413 uint16_t commonControlBits() const noexcept;
416 static constexpr uint8_t popcount16(uint16_t x) noexcept;
430 bool initialized_ = false;
436 uint16_t auto1_mask_ =
ADS7952_CFG::DEFAULT_AUTO1_MASK;
437 uint8_t auto2_last_ch_ =
ADS7952_CFG::DEFAULT_AUTO2_LAST_CH;
438 uint8_t gpio_output_state_ = 0;
444#include "ads7952.ipp"
Compile-time configuration options for the ADS7952 driver.
Register definitions and SPI frame constants for the ADS7952.
CRTP-based SPI bus interface for ADS7952 driver.
Type definitions for the ADS7952 driver.
Main driver class for the ADS7952 ADC.
bool IsInitialized() const noexcept
Check if the driver has been initialized.
ADS7952 & operator=(const ADS7952 &)=delete
static constexpr uint8_t GetDriverVersionMinor() noexcept
Driver semantic minor version.
Range GetRange() const noexcept
Get the current input range setting.
Mode GetMode() const noexcept
Get the current operating mode.
float GetVA() const noexcept
Get the configured VA supply voltage.
float GetActiveVref() const noexcept
Get the active voltage reference (affected by range setting).
uint16_t GetAuto1ChannelMask() const noexcept
Get the Auto-1 programmed channel mask. Bit ordering: bit N = channel N (bit 0 = CH0,...
float GetVref() const noexcept
Get the configured Vref (REFP pin voltage).
uint8_t GetAuto2LastChannel() const noexcept
Get the Auto-2 programmed last channel.
static constexpr uint8_t GetDriverVersionMajor() noexcept
Driver semantic major version.
static constexpr uint8_t GetDriverVersionPatch() noexcept
Driver semantic patch version.
ADS7952(const ADS7952 &)=delete
constexpr float DEFAULT_VA
constexpr ads7952::Range DEFAULT_RANGE
constexpr float DEFAULT_VREF
float CountToVoltage(uint16_t count) const noexcept
Convert raw count to voltage using the currently active reference.
ChannelReadings ReadAllChannels() noexcept
Read all channels in the current Auto-1 sequence.
void SetVref(float vref) noexcept
Update the Vref value for voltage calculations.
bool ProgramAuto2LastChannel(uint8_t last_channel) noexcept
Program the Auto-2 last channel.
void SetGPIOOutputs(uint8_t gpio_state) noexcept
Set GPIO output pin levels (for pins configured as outputs).
bool ProgramGPIO(const GPIOConfig &config) noexcept
Program GPIO pin functions, direction, and alarm routing.
bool ProgramAlarm(uint8_t channel, AlarmBound bound, uint16_t threshold_12bit) noexcept
Program an alarm threshold for a single channel (count-based).
bool ProgramAlarmVoltage(uint8_t channel, AlarmBound bound, float voltage) noexcept
Program an alarm threshold for a single channel (voltage-based).
void SetVA(float va) noexcept
Update the VA supply voltage value.
uint16_t VoltageToCount(float voltage) const noexcept
Convert a voltage to a 12-bit ADC count using the active reference.
bool SetPowerDown(PowerDown pd) noexcept
Set the power-down mode.
ReadResult ReadChannel(uint8_t channel) noexcept
Read a single ADC channel (switches to Manual mode).
bool EnterManualMode(uint8_t channel=0) noexcept
Enter Manual mode, selecting the given channel for conversion.
bool EnterAuto2Mode(bool reset_counter=true) noexcept
Enter Auto-2 mode (sequences channels 0 through last_channel).
bool EnterAuto1Mode(bool reset_counter=true) noexcept
Enter Auto-1 mode (sequences through programmed channel mask).
bool ProgramAuto1Channels(uint16_t channel_mask) noexcept
Program the Auto-1 channel sequence.
bool SetRange(Range range) noexcept
Set the input voltage range and update active reference.
bool EnsureInitialized(bool force=false) noexcept
Ensure the driver is initialized — idempotent, safe to call repeatedly.
ADS7952(SpiType &spi, float vref=ADS7952_CFG::DEFAULT_VREF, float va=ADS7952_CFG::DEFAULT_VA, Range initial_range=ADS7952_CFG::DEFAULT_RANGE) noexcept
Construct a new ADS7952 driver instance.
@ Normal
Normal operation.
@ Manual
Host selects channel each frame.
constexpr uint16_t MAX_COUNT
Maximum 12-bit conversion value.