95 inline constexpr uint8_t
kGPIO0 = 0x01;
97 inline constexpr uint8_t
kGPIO1 = 0x02;
99 inline constexpr uint8_t
kGPIO2 = 0x04;
103 inline constexpr uint8_t
kAll = 0x0F;
105 inline constexpr uint8_t
kNone = 0x00;
185 x = x - ((x >> 1) & 0x5555);
186 x = (x & 0x3333) + ((x >> 2) & 0x3333);
187 return static_cast<uint8_t
>((((x + (x >> 4)) & 0x0F0F) * 0x0101) >> 8);
215template <
typename... Channels>
217 static_assert((std::is_integral_v<Channels> && ...),
218 "ChannelMask arguments must be integers");
220 ((mask |=
static_cast<uint16_t
>(1U << (
static_cast<uint8_t
>(channels) & 0x0F))), ...);
221 return mask & 0x0FFF;
232 if (first > 11 || last > 11 || first > last)
return 0;
234 return static_cast<uint16_t
>(
235 ((1U << (last + 1)) - (1U << first)) & 0x0FFF);
277 if (vref <= 0.0f || voltage <= 0.0f)
return 0;
278 float raw = (voltage / vref) * 4095.0f;
279 if (raw > 4095.0f)
return 4095;
280 return static_cast<uint16_t
>(raw);
constexpr uint16_t ChannelRangeMask(uint8_t first, uint8_t last) noexcept
Build a contiguous channel range mask from first to last (inclusive).
constexpr uint16_t ChannelMask(Channels... channels) noexcept
Construct a channel enable bitmask from a list of channel numbers.
constexpr uint16_t VoltageToCount(float voltage, float vref) noexcept
Convert a voltage to a 12-bit ADC count.
constexpr uint8_t kGPIO0
Bit 0 — GPIO pin 0.
constexpr uint8_t kGPIO1
Bit 1 — GPIO pin 1.
constexpr uint8_t kAll
All 4 GPIO pins.
constexpr uint8_t kGPIO2
Bit 2 — GPIO pin 2.
constexpr uint8_t kNone
No GPIO pins.
constexpr uint8_t kGPIO3
Bit 3 — GPIO pin 3.
@ GPIO0_HighAndLowAlarm
GPIO0 = combined hi/lo alarm output.
@ GPIO0_HighAlarm
GPIO0 = high alarm output.
@ GPIO
Both as general-purpose I/O.
@ GPIO1_HighAlarm
GPIO1 = high alarm output.
@ GPIO1_LowAlarm_GPIO0_HighAlarm
GPIO1=low, GPIO0=high alarm.
@ Normal
Normal operation.
@ Auto2
Device sequences channels 0 to last_channel.
@ Auto1
Device sequences through programmed channel mask.
@ Manual
Host selects channel each frame.
@ Vref
0 to Vref (RANGE bit = 0)
@ TwoVref
0 to 2*Vref, clamped to VA (RANGE bit = 1)
@ Low
Low alarm threshold register.
@ High
High alarm threshold register.
@ SpiError
SPI transfer failure.
@ ProgrammingFailed
Device programming did not complete.
@ InvalidChannel
Channel number out of range (0-11)
@ NotInitialized
Driver not initialized.
@ Timeout
Operation timed out waiting for data.
@ ModeChangeFailed
Mode transition did not complete.
constexpr uint16_t kOddChannels
CH1, CH3, CH5, CH7, CH9, CH11.
constexpr uint16_t kFirstFour
CH0–CH3.
constexpr uint16_t kThirdFour
CH8–CH11.
constexpr uint16_t kSecondFour
CH4–CH7.
constexpr uint16_t kAllChannels
CH0–CH11 (all 12)
constexpr uint16_t kEvenChannels
CH0, CH2, CH4, CH6, CH8, CH10.
uint16_t valid_mask
Bitmask indicating which channels contain valid data.
bool hasChannel(uint8_t ch) const noexcept
Check if a specific channel has valid data in this reading.
static constexpr uint8_t MAX_CHANNELS
uint16_t count[MAX_CHANNELS]
Raw counts per channel.
bool ok() const noexcept
True when error equals Error::Ok.
uint8_t validChannelCount() const noexcept
Count channels currently marked valid.
float voltage[MAX_CHANNELS]
Converted voltages per channel.
bool gpio3_as_powerdown_input
GPIO3 controls power-down externally.
uint8_t direction_mask
GPIO direction control — bits [3:0], bit N = GPIO pin N.
bool gpio2_as_range_input
GPIO2 controls RANGE externally.
GPIO01AlarmMode alarm_mode
bool reset_all_registers
Reset all programming registers.
uint8_t channel
Channel that was read (from response)
uint16_t count
Raw 12-bit ADC count (0-4095)
bool ok() const noexcept
True when error equals Error::Ok.
float voltage
Converted voltage.