42#define ADS7952_HEADER_INCLUDED
80template <
typename SpiType>
165 return (
static_cast<float>(count) * vref) /
static_cast<float>(
reg::MAX_COUNT);
267 uint16_t threshold_12bit)
noexcept;
297 float voltage)
noexcept;
380 return gpio_output_state_;
391 float GetVref() const noexcept {
return vref_; }
394 float GetVA() const noexcept {
return va_; }
405 void SetVref(
float vref)
noexcept;
417 void SetVA(
float va)
noexcept;
445 uint8_t
RawManualFrames(uint8_t channel, uint16_t* out, uint8_t n)
noexcept;
468 bool spiTransfer16(uint16_t command, uint16_t* response =
nullptr) noexcept;
474 bool Initialize() noexcept;
477 uint16_t commonControlBits() const noexcept;
487 template <typename Commit>
488 bool programControlBits(uint16_t ctrl, Commit commit) noexcept;
491 static constexpr uint8_t popcount16(uint16_t x) noexcept;
505 bool initialized_ = false;
511 uint16_t auto1_mask_ =
ADS7952_CFG::DEFAULT_AUTO1_MASK;
512 uint8_t auto2_last_ch_ =
ADS7952_CFG::DEFAULT_AUTO2_LAST_CH;
513 uint8_t gpio_output_state_ = 0;
514 uint8_t manual_channel_ = 0;
520#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.
uint8_t GetGPIOOutputs() const noexcept
Get the GPIO output levels last written (bits [3:0]).
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).
PowerDown GetPowerDown() const noexcept
Get the current power-down setting.
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.
bool SetGPIOOutputs(uint8_t gpio_state) noexcept
Set GPIO output pin levels (for pins configured as outputs).
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.
uint8_t RawManualFrames(uint8_t channel, uint16_t *out, uint8_t n) noexcept
Clock raw 16-bit frames and return every response word unparsed.
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; in effect on the chip when this returns.
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; in effect on the chip when this returns.
bool EnsureInitialized(bool force=false) noexcept
Ensure the driver is initialized — idempotent, safe to call repeatedly.
@ Normal
Normal operation.
@ Manual
Host selects channel each frame.
constexpr uint16_t MAX_COUNT
Maximum 12-bit conversion value.