16#ifndef SBL_HW_HAL_ADC_ELECTRICAL_HPP_
17#define SBL_HW_HAL_ADC_ELECTRICAL_HPP_
32 return static_cast<float>((1u <<
bits) - 1u);
40 constexpr uint16_t
encode(
float volts)
const {
42 if (t < 0.0f) t = 0.0f;
43 if (t > 1.0f) t = 1.0f;
45 return static_cast<uint16_t
>(t *
counts_max() + 0.5f);
49 constexpr float decode(uint16_t counts)
const {
50 float t =
static_cast<float>(counts) /
counts_max();
Root namespace for all Sound Byte Libs code.
constexpr float counts_max() const
float hi_v
Voltage at full scale (or at code 0, if inverted)
uint8_t bits
Converter resolution.
constexpr uint16_t midpoint() const
Code that reads as 0 V โ the bipolar midpoint. Clamps if 0 V is out of range.
constexpr uint16_t encode(float volts) const
Code for a voltage at the jack, clamped to the converter's rails.
bool inverted
+V at the jack reads as a lower code
float lo_v
Voltage at code 0 (or at full scale, if inverted)
constexpr float decode(uint16_t counts) const
Voltage at the jack for a code.
constexpr float counts_per_volt() const