ADS9324 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
ads9324_encode.hpp
Go to the documentation of this file.
1
14#ifndef ADS9324_ENCODE_HPP
15#define ADS9324_ENCODE_HPP
16
17#include <algorithm>
18#include <array>
19#include <cstddef>
20#include <cstdint>
21#include <span>
22
23#include "ads9324_detail.hpp"
24#include "ads9324_registers.hpp"
25#include "ads9324_types.hpp"
26
27namespace ads9324::detail {
28
31struct RegisterImage {
32 std::array<std::array<uint16_t, reg::kAddressSpace>, reg::kBankCount> value{};
33 std::array<uint64_t, reg::kBankCount> touched{};
34};
35
37constexpr std::size_t BankIndex(reg::Bank bank) noexcept {
38 return static_cast<std::size_t>(ToUnderlying(bank));
39}
40
42constexpr uint64_t AddressBit(uint8_t address) noexcept {
43 return uint64_t{1} << (static_cast<uint32_t>(address) & 63U);
44}
45
47constexpr uint16_t Or(uint16_t a, uint16_t b) noexcept {
48 return static_cast<uint16_t>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
49}
50
52constexpr uint16_t Bit(bool condition, uint16_t mask) noexcept {
53 return condition ? mask : static_cast<uint16_t>(0U);
54}
55
57constexpr void Put(RegisterImage& img, reg::Bank bank, uint8_t address, uint16_t value) noexcept {
58 if (address >= reg::kAddressSpace) {
59 return;
60 }
61 img.value[BankIndex(bank)][address] = value;
62 img.touched[BankIndex(bank)] |= AddressBit(address);
63}
64
66constexpr uint16_t Get(const RegisterImage& img, reg::Bank bank, uint8_t address) noexcept {
67 return (address < reg::kAddressSpace) ? img.value[BankIndex(bank)][address]
68 : static_cast<uint16_t>(0U);
69}
70
72constexpr bool IsTouched(const RegisterImage& img, reg::Bank bank, uint8_t address) noexcept {
73 return (img.touched[BankIndex(bank)] & AddressBit(address)) != 0U;
74}
75
78constexpr void Merge(RegisterImage& img, reg::Bank bank, uint8_t address, uint16_t mask,
79 uint16_t bits) noexcept {
80 const uint32_t kept =
81 static_cast<uint32_t>(Get(img, bank, address)) & ~static_cast<uint32_t>(mask);
82 Put(img, bank, address, static_cast<uint16_t>(kept | (static_cast<uint32_t>(bits) & mask)));
83}
84
86template <Enumeration E>
87constexpr uint32_t Code(E e) noexcept {
88 return static_cast<uint32_t>(ToUnderlying(e));
89}
90
91constexpr void EncodeInterface(RegisterImage& img, const Interface& i) noexcept {
92 using reg::Bank;
93 uint16_t gc3 = reg::DoutLaneSel::Insert(0_u16, Code(i.lanes));
94 gc3 = reg::DoutLength::Insert(gc3, Code(i.length));
95 gc3 = Or(gc3, Bit(i.data_on_sdout, reg::kAdcDataSdoutEn));
96 gc3 = Or(gc3, Bit(i.format == DataFormat::OffsetBinary, reg::kEnOfsBinary));
97 gc3 = Or(gc3, Bit(i.randomize, reg::kEnXorPatt));
98 gc3 = Or(gc3, Bit(HasDiagByte(i), reg::kEnDiagFlag));
99 Put(img, Bank::Common, reg::kGenCfg3, gc3);
100 Put(img, Bank::Common, reg::kXorBitsCtl, i.randomize ? reg::kXorBitsRandomizer : 0_u16);
101 const auto& d = i.delay_ns;
102 uint16_t d1 = reg::DelaySdout::Insert(0_u16, d[0]);
103 d1 = reg::DelayD3::Insert(d1, d[4]);
104 d1 = reg::DelayD2::Insert(d1, d[3]);
105 d1 = reg::DelayD1::Insert(d1, d[2]);
106 d1 = reg::DelayD0::Insert(d1, d[1]);
107 uint16_t d2 = reg::DelayD7::Insert(0_u16, d[8]);
108 d2 = reg::DelayD6::Insert(d2, d[7]);
109 d2 = reg::DelayD5::Insert(d2, d[6]);
110 d2 = reg::DelayD4::Insert(d2, d[5]);
111 Put(img, Bank::Common, reg::kDigDelayCfg1, d1);
112 Put(img, Bank::Common, reg::kDigDelayCfg2, d2);
113 bool any_delay = false;
114 for (const uint8_t v : d) {
115 any_delay = any_delay || (v != 0U);
116 }
117 uint16_t gc4 = reg::DriveStrengthField::Insert(0_u16, Code(i.drive));
118 gc4 = Or(gc4, Bit(any_delay, reg::kDigDelayEn));
119 Put(img, Bank::Common, reg::kGenCfg4, gc4);
120}
121
122constexpr void EncodeAlarm(RegisterImage& img, const Alarm& a) noexcept {
123 using reg::Bank;
124 const bool or_masked = a.function == AlarmFunction::OrMasked;
125 // Assumption A41: a set mask bit leaves the source out of the OR.
126 const uint32_t mask = or_masked ? (~static_cast<uint32_t>(a.sources) & 0xFFU) : 0U;
127 uint16_t v = reg::DrdyAlrmSel::Insert(0_u16, Code(a.function));
128 v = reg::AlarmMask::Insert(v, mask);
129 v = Or(v, Bit(a.active_low, reg::kAlrmPol));
130 v = Or(v, Bit(a.pulse, reg::kAlrmType));
131 Put(img, Bank::Common, reg::kDrdyAlarmSel, v);
132 // GEN_CFG4 is shared with the interface encoder: merge only ALRM_DIS.
133 Merge(img, Bank::Common, reg::kGenCfg4, reg::kAlrmDis, Bit(a.disabled, reg::kAlrmDis));
134}
135
136constexpr uint16_t ReferenceBits(ReferenceSource source) noexcept {
137 switch (source) {
139 return reg::kRefselCtrlDis;
143 default:
144 break;
145 }
146 return 0_u16;
147}
148
151constexpr uint32_t ChannelSelCode(const ChannelSelect& select) noexcept {
152 const auto group = static_cast<uint32_t>(select.group);
153 switch (select.count) {
155 return group << 2U;
157 return group << 1U;
160 default:
161 break;
162 }
163 return group;
164}
165
166constexpr void EncodeAnalog(RegisterImage& img, const Config& c, uint16_t cal_mode) noexcept {
167 using reg::Bank;
168 Put(img, Bank::Common, reg::kAnaCfg1, ReferenceBits(c.reference));
169 uint16_t a2 = reg::AdcNumSel::Insert(0_u16, Code(c.channels.count));
170 a2 = reg::AdcChSel::Insert(a2, ChannelSelCode(c.channels));
171 a2 = Or(a2, Bit(c.low_speed_crosstalk, reg::kXtalkLowSpeed));
172 Put(img, Bank::Common, reg::kAnaCfg2, a2);
173 uint16_t cal = reg::AdcCalMode::Insert(0_u16, cal_mode);
174 cal = Or(cal, Bit(IsDifferential(c.inputs[0]), reg::kSeDiffAin1To8));
175 cal = Or(cal, Bit(IsDifferential(c.inputs[8]), reg::kSeDiffAin9To16));
176 Put(img, Bank::Common, reg::kAdcCal, cal);
177}
178
179constexpr bool AnyPhaseDelay(const Config& c) noexcept {
180 return std::ranges::any_of(c.inputs, [](const Input& in) { return in.phase_delay != 0U; });
181}
182
183constexpr void EncodeFilter(RegisterImage& img, const Config& c) noexcept {
184 using reg::Bank;
185 const Filter& f = c.filter;
186 uint16_t v = Bit(AnyPhaseDelay(c), reg::kPhaseDelayEn);
187 if (f.kind == FilterKind::Fir) {
188 v = reg::FirFiltSel::Insert(v, Code(f.fir));
189 } else if (f.kind == FilterKind::MovingAverage) {
190 v = reg::MvgAvgLen::Insert(v, Code(f.length));
191 } else if (f.kind == FilterKind::BlockAverage) {
192 v = reg::BlkAvgOsr::Insert(v, Code(f.length));
193 v = Or(v, Bit(f.internal_clock, reg::kIntTrigMode));
194 } else {
195 v = Or(v, 0_u16);
196 }
197 Put(img, Bank::Common, reg::kDigFilter, v);
198 // One gate for every digital filter (section 7.3.11.2, assumption A31).
199 const bool gate = f.kind != FilterKind::None;
200 Put(img, Bank::Common, reg::kGenCfg5, Bit(gate, Or(reg::kAvgModeOvrEn, reg::kAvgMode)));
201}
202
204constexpr uint8_t PgaByte(const Input& in) noexcept {
205 uint8_t b = reg::InputRangeField::Insert(0_u8, Code(in.range));
206 b = reg::CmRange::Insert(b, Code(in.type));
207 return reg::CmeCorrEn::Insert(b, in.cm_correction ? 1U : 0U);
208}
209
210constexpr uint16_t HalfMask(uint8_t local, uint16_t mask) noexcept {
211 return static_cast<uint16_t>(static_cast<uint32_t>(mask) << reg::HalfShift(local));
212}
213
214constexpr uint16_t Twos(int32_t value, uint32_t bits) noexcept {
215 return static_cast<uint16_t>(static_cast<uint32_t>(value) & ((uint32_t{1} << bits) - 1U));
216}
217
218constexpr void EncodeChannel(RegisterImage& img, uint8_t channel, const Input& in) noexcept {
219 const reg::ChannelLocation at = reg::Locate(channel);
220 const uint8_t l = at.local;
221 const uint32_t half = reg::HalfShift(l);
222 const auto pga = static_cast<uint16_t>(static_cast<uint32_t>(PgaByte(in)) << half);
223 Merge(img, at.bank, reg::PgaConfigAddress(l), HalfMask(l, 0x00FF_u16), pga);
224 const uint32_t bw_shift = 2U * static_cast<uint32_t>(l);
225 Merge(img, at.bank, reg::kPgaBwSel, static_cast<uint16_t>(3U << bw_shift),
226 static_cast<uint16_t>(Code(in.bandwidth) << bw_shift));
227 const auto delay = static_cast<uint16_t>(static_cast<uint32_t>(in.phase_delay) << half);
228 Merge(img, at.bank, reg::PhaseDelayAddress(l), HalfMask(l, 0x00FF_u16), delay);
229 Put(img, at.bank, reg::OffsetAddress(l), Twos(in.offset_quarter_lsb, 10U));
230 Put(img, at.bank, reg::GainAddress(l), Twos(in.gain, 14U));
231 const auto th = static_cast<uint16_t>(
232 (static_cast<uint32_t>(static_cast<uint8_t>(in.window.high_code)) << 8U) |
233 static_cast<uint32_t>(static_cast<uint8_t>(in.window.low_code)));
234 Put(img, at.bank, reg::DwcThAddress(l), th);
235 const auto hys = static_cast<uint16_t>(static_cast<uint32_t>(in.window.hysteresis) << half);
236 Merge(img, at.bank, reg::DwcHysAddress(l), HalfMask(l, 0x00FF_u16), hys);
237 const auto en = static_cast<uint16_t>(in.window.enabled ? (1U << l) : 0U);
238 Merge(img, at.bank, reg::kDwcCfg, static_cast<uint16_t>(1U << l), en);
239}
240
241constexpr void EncodeBankSettings(RegisterImage& img, const Config& c) noexcept {
242 for (uint32_t g = 0U; g < 2U; ++g) {
243 const reg::Bank bank = (g == 0U) ? reg::Bank::Ain1To8 : reg::Bank::Ain9To16;
244 Merge(img, bank, reg::kDwcCfg, 0x0F00_u16,
245 reg::DwcGlitchFilt::Insert(0_u16, c.window_glitch[g]));
246 uint16_t corr = Bit(!c.correction.offset_enabled, reg::kOfsCorrDis);
247 corr = Or(corr, Bit(!c.correction.gain_enabled, reg::kGanCorrDis));
248 Put(img, bank, reg::kCorrection, corr);
249 const TestPattern& t = c.test_pattern[g];
250 uint16_t cfg = reg::TpMode::Insert(0_u16, Code(t.kind));
251 cfg = Or(cfg, Bit(t.enabled, reg::kTpEn));
252 cfg = Or(cfg, Bit(!t.index_insertion, reg::kTpDisIdx));
253 cfg = Or(cfg, Bit(t.step_every_convst, reg::kTpUpdMode));
254 Put(img, bank, reg::kTpCfg, cfg);
255 for (uint32_t i = 0U; i < 8U; ++i) {
256 const reg::ChannelLocation at = reg::Locate(static_cast<uint8_t>((8U * g) + i));
257 Put(img, at.bank, reg::TpAddress(at.local), t.value[i]);
258 }
259 }
260}
261
269constexpr RegisterImage Encode(const Config& c, uint16_t cal_mode) noexcept {
270 RegisterImage img{};
271 EncodeInterface(img, c.interface);
272 EncodeAlarm(img, c.alarm);
273 EncodeAnalog(img, c, cal_mode);
274 EncodeFilter(img, c);
275 for (uint8_t ch = 0U; ch < reg::kChannelCount; ++ch) {
276 EncodeChannel(img, ch, c.inputs[ch]);
277 }
278 EncodeBankSettings(img, c);
279 return img;
280}
281
282// Table 7-18: 16-bit words, one lane on SDOUT is 0x0032 in GEN_CFG3.
283static_assert(Get(Encode(Config{}, 0U), reg::Bank::Common, reg::kGenCfg3) == 0x0032U);
284// The chip's reset state encodes to the reset values of the interface
285// registers.
286static_assert(Get(Encode(ChipResetConfig(), 0U), reg::Bank::Common, reg::kGenCfg3) == 0x0000U);
287static_assert(Get(Encode(Config{}, 0U), reg::Bank::Common, reg::kGenCfg4) == 0x0000U);
288// A randomizer asks for the DIAG byte, which carries the PRBS byte, and sets
289// XOR_BITS_CTL.
290static_assert(Get(Encode(
291 [] {
292 Config c{};
293 c.interface.randomize = true;
294 return c;
295 }(),
296 0U),
298// AIN16 is local index 0 of the second bank, the low byte of its first
299// PGA_CONFIG register.
300static_assert(Get(Encode(
301 [] {
302 Config c{};
303 c.inputs[15].range = InputRange::V10;
304 return c;
305 }(),
306 0U),
308
310constexpr bool IsClipped(int16_t code) noexcept {
311 return (code == 32767) || (code == -32768);
312}
313
316constexpr void DecodeWords(const Config& c, std::span<const uint8_t> bytes, uint16_t mask,
317 Frame& frame) noexcept {
318 const uint32_t per = (c.interface.length == WordLength::Bits24) ? 3U : 2U;
319 const uint32_t n = FrameChannels(c.channels);
320 for (uint32_t slot = 0U; slot < n; ++slot) {
321 const uint32_t at = slot * per;
322 const uint8_t ch = FrameSlotChannel(c.channels, slot);
323 const uint32_t word =
324 (static_cast<uint32_t>(bytes[at]) << 8U) | static_cast<uint32_t>(bytes[at + 1U]);
325 const auto raw = static_cast<uint16_t>(word ^ static_cast<uint32_t>(mask));
326 const int16_t code = WireToCode(raw, c.interface.format);
327 frame.raw[ch] = raw;
328 frame.codes[ch] = code;
329 frame.low_byte[ch] = (per == 3U) ? bytes[at + 2U] : static_cast<uint8_t>(0U);
330 frame.microvolts[ch] = CodeToMicrovolts(code, c.inputs[ch].range);
331 frame.present_mask =
332 static_cast<uint16_t>(static_cast<uint32_t>(frame.present_mask) | (1U << ch));
333 if (IsClipped(code)) {
334 frame.clipped_mask =
335 static_cast<uint16_t>(static_cast<uint32_t>(frame.clipped_mask) | (1U << ch));
336 }
337 }
338}
339
347constexpr Result<Frame> DecodeFrame(const Config& c, std::span<const uint8_t> bytes) noexcept {
348 if (bytes.size() != FrameBytes(c.interface, c.channels)) {
350 }
351 Frame frame{};
352 const uint32_t per = (c.interface.length == WordLength::Bits24) ? 3U : 2U;
353 const uint32_t trailer = FrameChannels(c.channels) * per;
354 const bool diag = HasDiagByte(c.interface);
355 frame.diag = diag ? bytes[trailer] : static_cast<uint8_t>(0U);
356 frame.prbs = c.interface.randomize ? bytes[trailer + 1U] : static_cast<uint8_t>(0U);
357 const uint16_t mask =
358 c.interface.randomize ? DerandomizeMask(frame.prbs) : static_cast<uint16_t>(0U);
359 DecodeWords(c, bytes, mask, frame);
360 frame.window_alert = (static_cast<uint32_t>(frame.diag) & kDiagWindowAlert) != 0U;
361 frame.reset_detected = (static_cast<uint32_t>(frame.diag) & kDiagResetDetect) != 0U;
362 return Result<Frame>::Success(frame);
363}
364
365// Table 7-12, 8 channels, group 0: AIN1 to AIN4 and AIN13 to AIN16.
366static_assert(FrameSlotChannel({.count = ChannelCount::Eight, .group = 0}, 4) == 12U);
367static_assert(FrameSlotChannel({.count = ChannelCount::Eight, .group = 1}, 0) == 4U);
368static_assert((ChannelSelCode({.count = ChannelCount::Four, .group = 1}) == 2U) &&
369 (ChannelSelCode({.count = ChannelCount::Eight, .group = 1}) == 4U));
370// Equation 7: PRBS 0x1F gives the mask 0x1FFF.
371static_assert(DerandomizeMask(0x1F) == 0x1FFFU);
372
375constexpr uint32_t RangeCode(InputRange r) noexcept {
376 return Code(r);
377}
378
379} // namespace ads9324::detail
380
381#endif // ADS9324_ENCODE_HPP
Compile-time helpers of the ADS9324 driver: typed integer literals, exact hook matching,...
ADS9324 register map: banks, addresses, bit fields, reset values and the channel layout (datasheet se...
Public types of the ADS9324 driver: errors, Result<T>, enumerations, configuration,...
constexpr ChannelLocation Locate(uint8_t channel) noexcept
The bank and local index of a channel (the AIN9 to AIN16 bank is reversed).
Definition ads9324_registers.hpp:247
constexpr uint8_t kXorBitsCtl
XOR_BITS_CTL: output randomizer.
Definition ads9324_registers.hpp:90
constexpr uint8_t GainAddress(uint8_t local) noexcept
The address of the GAN register of a local index.
Definition ads9324_registers.hpp:297
constexpr uint16_t kXorBitsRandomizer
Definition ads9324_registers.hpp:150
constexpr uint16_t kRefselCtrlDis
REFSEL_CTRL_DIS: ignore the REFSEL pin.
Definition ads9324_registers.hpp:183
constexpr uint16_t kSeDiffAin1To8
SE_DIFF_MODE_AIN1_8: 1 = differential.
Definition ads9324_registers.hpp:192
constexpr uint16_t kExtRefEn
EXT_REF_EN: external reference.
Definition ads9324_registers.hpp:184
constexpr uint16_t kAlrmPol
ALRM_POL: 1 = active low.
Definition ads9324_registers.hpp:156
constexpr uint8_t kDigDelayCfg2
DIG_DELAY_CFG2: D7 to D4 delay.
Definition ads9324_registers.hpp:94
constexpr uint8_t kTpCfg
TP_CFG: test pattern control.
Definition ads9324_registers.hpp:114
constexpr uint16_t kTpUpdMode
TP_UPD_MODE: 1 = ramp steps at every CONVST.
Definition ads9324_registers.hpp:227
constexpr uint8_t kPgaConfig
PGA_CONFIG, 4 registers, two channels each.
Definition ads9324_registers.hpp:106
constexpr uint16_t kEnDiagFlag
EN_DIAG_FLAG: DIAG byte after the data.
Definition ads9324_registers.hpp:142
constexpr uint8_t kDrdyAlarmSel
DRDY_ALARM_SEL: pin function.
Definition ads9324_registers.hpp:91
constexpr uint16_t kAvgModeOvrEn
AVG_MODE_OVR_EN.
Definition ads9324_registers.hpp:206
constexpr uint8_t kGenCfg5
GEN_CFG5: AVG_MODE gate.
Definition ads9324_registers.hpp:99
constexpr uint8_t kAnaCfg1
ANA_CFG1: reference source.
Definition ads9324_registers.hpp:95
constexpr uint16_t kAlrmDis
ALRM_DIS: 1 = alarm function disabled.
Definition ads9324_registers.hpp:162
constexpr uint16_t kGanCorrDis
GAN_CORR_DIS.
Definition ads9324_registers.hpp:230
constexpr uint16_t kDigDelayEn
DIG_DELAY_EN.
Definition ads9324_registers.hpp:163
constexpr uint16_t kIntTrigMode
INT_TRIG_MODE: internal oversampling clock.
Definition ads9324_registers.hpp:204
constexpr uint8_t kCorrection
GEN_CFG5 of a channel bank: correction bypass.
Definition ads9324_registers.hpp:116
constexpr uint16_t kEnXorPatt
EN_XOR_PATT: randomizer.
Definition ads9324_registers.hpp:141
constexpr uint16_t kAdcDataSdoutEn
ADC_DATA_SDOUT_EN.
Definition ads9324_registers.hpp:145
constexpr uint32_t HalfShift(uint8_t local) noexcept
The bit position of the odd (high) or even (low) half of a two-channel register.
Definition ads9324_registers.hpp:330
constexpr uint16_t kTpEn
TP_EN.
Definition ads9324_registers.hpp:228
constexpr uint8_t kBankCount
Number of register banks.
Definition ads9324_registers.hpp:55
constexpr uint8_t kGenCfg4
GEN_CFG4: drive strength, delay enable.
Definition ads9324_registers.hpp:92
constexpr uint16_t kAvgMode
AVG_MODE.
Definition ads9324_registers.hpp:207
Bank
A register bank. The value is the index of the bank in the driver's tables.
Definition ads9324_registers.hpp:47
constexpr uint8_t DwcThAddress(uint8_t local) noexcept
The address of the DWC_TH register of a local index.
Definition ads9324_registers.hpp:305
constexpr uint8_t kDigFilter
DIG_FILTER: digital filters and SYSREF.
Definition ads9324_registers.hpp:98
constexpr uint16_t kEnOfsBinary
EN_OFS_BINARY: 1 = offset binary.
Definition ads9324_registers.hpp:140
constexpr uint16_t kAlrmType
ALRM_TYPE: 1 = pulse (window alert only).
Definition ads9324_registers.hpp:155
constexpr uint16_t kTpDisIdx
TP_DIS_IDX: 1 = no channel index insertion.
Definition ads9324_registers.hpp:226
constexpr uint8_t PhaseDelayAddress(uint8_t local) noexcept
The address of the PHASE_DELAY register of a local index.
Definition ads9324_registers.hpp:281
constexpr uint8_t PgaConfigAddress(uint8_t local) noexcept
The address of the register that holds the PGA_CONFIG of a local index.
Definition ads9324_registers.hpp:273
constexpr uint8_t DwcHysAddress(uint8_t local) noexcept
The address of the DWC_HYS register of a local index.
Definition ads9324_registers.hpp:313
constexpr uint8_t OffsetAddress(uint8_t local) noexcept
The address of the OFS register of a local index.
Definition ads9324_registers.hpp:289
constexpr uint16_t kXtalkLowSpeed
CH_XTALK_LOW_SPEED.
Definition ads9324_registers.hpp:185
constexpr uint8_t kAnaCfg2
ANA_CFG2: channel mode, low-speed crosstalk.
Definition ads9324_registers.hpp:96
constexpr uint8_t kChannelCount
Number of channels.
Definition ads9324_registers.hpp:57
constexpr uint8_t kAdcCal
ADC_CAL: ADC calibration module.
Definition ads9324_registers.hpp:97
constexpr uint8_t TpAddress(uint8_t local) noexcept
The address of the TP_AIN register of a local index.
Definition ads9324_registers.hpp:321
constexpr uint8_t kDigDelayCfg1
DIG_DELAY_CFG1: SDOUT and D3 to D0 delay.
Definition ads9324_registers.hpp:93
constexpr uint16_t kSeDiffAin9To16
SE_DIFF_MODE_AIN9_16: 1 = differential.
Definition ads9324_registers.hpp:193
constexpr uint8_t kDwcCfg
DWC_CFG: enables, glitch filter, flag reset.
Definition ads9324_registers.hpp:111
constexpr uint8_t kGenCfg3
GEN_CFG3: data format and lanes.
Definition ads9324_registers.hpp:89
constexpr uint8_t kPgaBwSel
PGA_BW_SEL, 2 bits per channel.
Definition ads9324_registers.hpp:107
constexpr uint16_t kOfsCorrDis
OFS_CORR_DIS.
Definition ads9324_registers.hpp:229
constexpr uint8_t kAddressSpace
Addresses per bank table: the highest documented address is 0x3E.
Definition ads9324_registers.hpp:61
constexpr uint16_t kPhaseDelayEn
PHASE_DELAY_EN.
Definition ads9324_registers.hpp:200
@ Ain1To8
Channel registers AIN1 to AIN8, BANK_SEL code 010b.
@ Common
The common registers, BANK_SEL code 001b.
constexpr std::size_t FrameBytes(const Interface &interface, const ChannelSelect &select) noexcept
Bytes of one data frame (section 7.3.14).
Definition ads9324_types.hpp:1223
constexpr bool HasDiagByte(const Interface &interface) noexcept
Whether the frame ends with a DIAG byte: asked for, or implied by the randomizer (the datasheet shows...
Definition ads9324_types.hpp:1212
InputRange
Input range of a channel (INPUT_RANGE_AINn, Table 7-1).
Definition ads9324_types.hpp:200
constexpr uint8_t FrameSlotChannel(const ChannelSelect &select, uint32_t slot) noexcept
Which channel a slot of the frame carries (Table 7-12).
Definition ads9324_types.hpp:1179
constexpr int16_t WireToCode(uint16_t raw, DataFormat format) noexcept
The signed code of a wire value.
Definition ads9324_types.hpp:1134
constexpr uint8_t kDiagResetDetect
DIAG bit 0, RESET_DETECT_FLAG.
Definition ads9324_types.hpp:1248
static constexpr Result Success(T v) noexcept
A successful result.
Definition ads9324_types.hpp:131
constexpr int32_t CodeToMicrovolts(int32_t code, InputRange range) noexcept
Microvolts of a signed code: code x full scale / 32768, rounded half away from zero.
Definition ads9324_types.hpp:1111
constexpr Config ChipResetConfig() noexcept
The chip's reset state as a Config: eight lanes on D7 to D0, everything else as Config{}.
Definition ads9324_types.hpp:691
constexpr uint16_t DerandomizeMask(uint8_t prbs) noexcept
The XOR mask of the randomizer (equations 7 and 8, section 7.3.14.4).
Definition ads9324_types.hpp:1146
ReferenceSource
Where the ADC reference comes from (Table 7-3).
Definition ads9324_types.hpp:244
constexpr uint8_t kDiagWindowAlert
DIAG bit 6, DWC_ALERT_FLAG (Table 7-13).
Definition ads9324_types.hpp:1246
constexpr uint32_t FrameChannels(const ChannelSelect &select) noexcept
Number of channels in a frame.
Definition ads9324_types.hpp:1157
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition ads9324_types.hpp:139
@ InvalidArgument
An argument or a Config field is out of range; nothing was sent.
@ All16
16 channels. Reset value.
@ Four
4 channels; group 0 to 3.
@ Two
2 channels; group 0 to 7.
@ Eight
8 channels; group 0 or 1.
@ OffsetBinary
Straight offset binary.
@ Bits24
24 bits: the result and an extra byte.
@ Fir
A FIR filter, Filter::fir.
@ MovingAverage
Moving average over Filter::length conversions.
@ BlockAverage
Block average over Filter::length conversions.
@ Internal
Internal 4.096 V reference, REFSEL ignored.
@ Pin
The REFSEL pin chooses. Reset value.