28#ifndef BMP581_SPI_INTERFACE_HPP
29#define BMP581_SPI_INTERFACE_HPP
78template <
typename Derived>
99template <typename Port>
101 detail::ExactHook<Port, bool()
noexcept>::Take(&Port::EnsureInitialized);
102 detail::ExactHook<Port, bool(
const uint8_t*, uint8_t*, std::size_t)
noexcept>::Take(
109inline constexpr uint32_t kSpiReadFlag = 0x80U;
111inline constexpr uint32_t kSpiAddressMask = 0x7FU;
121template <SpiPort Port>
122class SpiRegisterBus {
125 explicit SpiRegisterBus(Port& port) noexcept : port_(port) {}
128 Port& GetPort() &
noexcept {
133 [[nodiscard]]
bool AddressValid() const noexcept {
139 Error SelectInterface() noexcept {
140 return Read(reg::kChipId, std::span<uint8_t>{rx_.data(), 1U});
145 Error Read(uint8_t reg, std::span<uint8_t> out)
noexcept {
146 if (out.empty() || (out.size() > kSpiMaxBurst)) {
147 return Error::InvalidArgument;
149 const std::size_t count = out.size();
151 tx_[0] =
static_cast<uint8_t
>(kSpiReadFlag | (
static_cast<uint32_t
>(reg) & kSpiAddressMask));
152 if (!port_.Transfer(tx_.data(), rx_.data(), count + 1U)) {
155 for (std::size_t i = 0U; i < count; ++i) {
156 out[i] = rx_[1U + i];
162 Error WriteByte(uint8_t reg, uint8_t value)
noexcept {
163 const std::array<uint8_t, 2> frame{
164 static_cast<uint8_t
>(
static_cast<uint32_t
>(reg) & kSpiAddressMask), value};
165 return port_.Transfer(frame.data(),
nullptr, frame.size()) ? Error::Ok :
Error::
Bus;
169 Error WriteResetCommand() noexcept {
170 return WriteByte(reg::kCmd, reg::kCmdSoftReset);
175 std::array<uint8_t, 1U + kSpiMaxBurst> tx_{};
176 std::array<uint8_t, 1U + kSpiMaxBurst> rx_{};
Compile-time helpers of the BMP581 driver: typed integer literals, exact hook matching,...
BMP581 register map: addresses, bit fields and reset values (datasheet section 7).
Public types of the BMP581 driver: errors, Result<T>, configuration, measurements and the datasheet's...
CRTP base of the platform SPI port.
Definition bmp581_spi_interface.hpp:79
SpiInterface(const SpiInterface &)=delete
Ports are not copied: the driver holds a reference.
SpiInterface() noexcept=default
Only the derived port is constructed.
SpiInterface & operator=(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 bmp581_spi_interface.hpp:100
constexpr uint32_t kFifoMaxBytes
Bytes of a full FIFO, either frame size.
Definition bmp581_types.hpp:381
Error
Why a call failed. Every call of the driver returns one of these in its Result.
Definition bmp581_types.hpp:40
What the BMP581 needs from the SPI bus (sections 5.2.1, 5.5, table 18). A port and a board configurat...
Definition bmp581_spi_interface.hpp:45
constexpr uint32_t kMinCsHighNs
Definition bmp581_spi_interface.hpp:57
constexpr uint32_t kCsHoldNs
Last SCK edge to CSB high, the CSB lag time (table 18, T_hold_csb).
Definition bmp581_spi_interface.hpp:62
constexpr uint32_t kMaxClockHz
Highest SCK frequency with VDDIO at or above 1.62 V and C_bus up to 80 pF (table 4,...
Definition bmp581_spi_interface.hpp:52
constexpr uint32_t kMaxClockLowVoltageHz
Highest SCK frequency below VDDIO 1.62 V with C_bus up to 40 pF (table 4, f_spi_lowv).
Definition bmp581_spi_interface.hpp:54
constexpr uint32_t kCsSetupNs
Definition bmp581_spi_interface.hpp:60
constexpr bool kMsbFirst
Each byte is clocked most significant bit first (figures 8 to 11).
Definition bmp581_spi_interface.hpp:50
constexpr uint8_t kSpiMode
Definition bmp581_spi_interface.hpp:48
constexpr bool kContinuousWord
false: SCK may pause between the bytes of one frame while CSB stays low (section 5....
Definition bmp581_spi_interface.hpp:64
The BMP581 driver: everything it declares lives here; internals in detail.
Definition bmp581.hpp:32