BMP581 Driver 1.0.0
API reference
Loading...
Searching...
No Matches
bmp581_bus_interface.hpp
Go to the documentation of this file.
1
36#pragma once
37
38#include <cstddef>
39#include <cstdint>
40#include <type_traits>
41
42namespace bmp581 {
43
45enum class Interface : uint8_t {
46 Unspecified = 0,
47 I2c = 1,
48 Spi = 2,
49};
50
51namespace detail {
52
53template <typename Bus, typename = void>
57
58template <typename Bus>
59struct DeclaredInterface<Bus, std::void_t<decltype(Bus::kInterface)>> {
60 static_assert(std::is_same_v<std::remove_cv_t<decltype(Bus::kInterface)>, Interface>,
61 "bmp581: the adapter's kInterface must be a bmp581::Interface");
62 static constexpr Interface value = Bus::kInterface;
63};
64
65} // namespace detail
66
68template <typename Bus>
70
75template <typename Derived>
77public:
79 bool WriteRegs(uint8_t reg, const uint8_t* data, std::size_t len) noexcept {
80 return static_cast<Derived*>(this)->WriteRegs(reg, data, len);
81 }
82
84 bool ReadRegs(uint8_t reg, uint8_t* out, std::size_t len) noexcept {
85 return static_cast<Derived*>(this)->ReadRegs(reg, out, len);
86 }
87
89 void DelayUs(uint32_t us) noexcept { static_cast<Derived*>(this)->DelayUs(us); }
90
92 bool EnsureInitialized() noexcept {
93 return static_cast<Derived*>(this)->EnsureInitialized();
94 }
95};
96
97} // namespace bmp581
CRTP base for the BMP581 register transport.
Definition bmp581_bus_interface.hpp:76
bool WriteRegs(uint8_t reg, const uint8_t *data, std::size_t len) noexcept
Write len bytes starting at register reg (auto-increment).
Definition bmp581_bus_interface.hpp:79
bool ReadRegs(uint8_t reg, uint8_t *out, std::size_t len) noexcept
Read len bytes starting at register reg (auto-increment).
Definition bmp581_bus_interface.hpp:84
bool EnsureInitialized() noexcept
Lazy bus bring-up; must return true before any transfer.
Definition bmp581_bus_interface.hpp:92
void DelayUs(uint32_t us) noexcept
Blocking delay in microseconds (soft reset 2 ms, standby 2.5 ms, NVM 0.8 ms).
Definition bmp581_bus_interface.hpp:89
Definition bmp581.hpp:19
Interface
Bus an adapter drives, declared as static constexpr Interface kInterface (optional).
Definition bmp581_bus_interface.hpp:45
@ Unspecified
not declared: the driver handles both I2C and SPI behaviour
constexpr Interface kBusInterface
The interface adapter Bus declares, or Interface::Unspecified.
Definition bmp581_bus_interface.hpp:69
@ Bus
register read/write failed
Definition bmp581_bus_interface.hpp:54
static constexpr Interface value
Definition bmp581_bus_interface.hpp:55