23#ifndef ADS9324_SPI_INTERFACE_HPP
24#define ADS9324_SPI_INTERFACE_HPP
99template <
typename Derived>
126template <typename Port>
128 detail::ExactHook<Port, bool()
noexcept>::Take(&Port::EnsureInitialized);
129 detail::ExactHook<Port, bool(
const uint8_t*, uint8_t*, std::size_t)
noexcept>::Take(
136inline constexpr std::size_t kFrameBytes = 3;
139constexpr uint16_t ReadCommand(uint8_t address)
noexcept {
140 return reg::GenCfg1ReadAddress::Insert(reg::kRegRdEn, address);
148template <SpiPort Port>
151 explicit RegisterBus(Port& port) noexcept : port_(port) {}
153 Port& GetPort() &
noexcept {
158 Error Write(uint8_t address, uint16_t value)
noexcept {
160 tx_[1] =
static_cast<uint8_t
>(value >> 8U);
161 tx_[2] =
static_cast<uint8_t
>(value & 0xFFU);
162 return port_.Transfer(tx_.data(),
nullptr, kFrameBytes) ? Error::Ok :
Error::
Bus;
169 Result<uint16_t> Read(uint8_t address)
noexcept {
170 if (
const Error e = Write(reg::kGenCfg1, ReadCommand(address)); e != Error::Ok) {
171 return Result<uint16_t>::Failure(e);
175 if (!port_.Transfer(tx_.data(), rx_.data(), kFrameBytes)) {
176 return Result<uint16_t>::Failure(Error::Bus);
179 return Result<uint16_t>::Failure(Error::Bus);
181 return Result<uint16_t>::Success(
static_cast<uint16_t
>((
static_cast<uint32_t
>(rx_[0]) << 8U) |
182 static_cast<uint32_t
>(rx_[1])));
188 Error ReadStream(std::span<uint8_t> out)
noexcept {
189 if (out.empty() || (out.size() > kMaxFrameBytes)) {
190 return Error::InvalidArgument;
193 return port_.Transfer(zeros_.data(), out.data(), out.size()) ? Error::Ok : Error::Bus;
200 std::array<uint8_t, kFrameBytes> tx_{};
201 std::array<uint8_t, kFrameBytes> rx_{};
202 std::array<uint8_t, kMaxFrameBytes> zeros_{};
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,...
CRTP base of the platform port.
Definition ads9324_spi_interface.hpp:100
SpiInterface() noexcept=default
Only the derived port is constructed.
SpiInterface & operator=(const SpiInterface &)=delete
Ports are not copied: the driver holds a reference.
SpiInterface(const SpiInterface &)=delete
Ports are not copied: the driver holds a reference.
Satisfied by a class that derives from SpiInterface<Port> and implements the required hooks with exac...
Definition ads9324_spi_interface.hpp:127
constexpr uint32_t kSclkMaxHz
Highest SCLK frequency (section 5.6).
Definition ads9324_types.hpp:667
Error
Why a call failed. Every call of the driver returns one of these in its Result.
Definition ads9324_types.hpp:45
@ Bus
A port hook returned false.
The ADS9324 driver: everything it declares lives here; internals in detail.
Definition ads9324.hpp:32
constexpr uint8_t kSpiMode
Definition ads9324_spi_interface.hpp:48
constexpr bool kMsbFirst
Each byte is clocked most significant bit first.
Definition ads9324_spi_interface.hpp:50
constexpr uint32_t kMinCsHighNs
Shortest time CS stays high between two frames, thi_CS (section 5.6).
Definition ads9324_spi_interface.hpp:57
constexpr uint32_t kCsHoldNs
Last SCLK edge to CS high, tht_CSCK.
Definition ads9324_spi_interface.hpp:61
CtrlPin
Control pins the port may drive or read through the optional hooks.
Definition ads9324_spi_interface.hpp:75
@ Reset
RESET, active low on the package pin; idles high (INACTIVE).
@ Convst
CONVST: ACTIVE is a high level, and the line idles high (ACTIVE) between pulses.
@ DrdyAlarm
DRDY/ALARM: an input, read with GpioGet().
constexpr bool kContinuousWord
Definition ads9324_spi_interface.hpp:68
GpioSignal
Logical level of a control pin; the port maps it to the physical polarity.
Definition ads9324_spi_interface.hpp:83
@ ACTIVE
The pin function is asserted.
@ INACTIVE
The pin function is deasserted.
constexpr uint32_t kFrameBits
Bits in a register frame: 8 address bits and 16 data bits.
Definition ads9324_spi_interface.hpp:70
constexpr bool kFrameIsAtomic
Definition ads9324_spi_interface.hpp:64
constexpr uint32_t kMaxClockHz
Highest SCLK frequency, f_SCLK (section 5.6), for frames that read nothing back.
Definition ads9324_spi_interface.hpp:52
constexpr uint32_t kCsSetupNs
CS low to the first SCLK edge, tsu_CSCK.
Definition ads9324_spi_interface.hpp:59
constexpr uint32_t kMaxSdoutClockHz
Definition ads9324_spi_interface.hpp:55