BNO08X Driver 0.1.0
API reference
Loading...
Searching...
No Matches
bno08x_interface.hpp
Go to the documentation of this file.
1// clang-format off: the table below must keep one row per line.
33// clang-format on
34#ifndef BNO08X_INTERFACE_HPP
35#define BNO08X_INTERFACE_HPP
36
37#include <concepts>
38#include <cstddef>
39#include <cstdint>
40#include <type_traits>
41
42#include "bno08x_detail.hpp"
45#include "bno08x_types.hpp"
47
48namespace bno08x {
49
59template <typename Derived>
61public:
63 HubInterface(const HubInterface&) = delete;
66
67protected:
69 HubInterface() noexcept = default;
71 ~HubInterface() noexcept = default;
72};
73
74namespace detail {
75
77template <typename Port>
78concept CommonHooks = requires {
79 ExactHook<Port, bool() noexcept>::Take(&Port::EnsureInitialized);
80 ExactHook<Port, uint32_t() noexcept>::Take(&Port::NowUs);
81};
82
84template <typename Port>
85concept I2cHooks = requires {
86 ExactHook<Port, bool(uint8_t, const uint8_t*, std::size_t) noexcept>::Take(&Port::I2cWrite);
87 ExactHook<Port, bool(uint8_t, uint8_t*, std::size_t) noexcept>::Take(&Port::I2cRead);
88 ExactHook<Port, bool() noexcept>::Take(&Port::IntAsserted);
89};
90
92template <typename Port>
93concept SpiHooks = requires {
94 ExactHook<Port, bool(const uint8_t*, uint8_t*, std::size_t) noexcept>::Take(&Port::SpiTransfer);
95 ExactHook<Port, bool(bool) noexcept>::Take(&Port::SetWake);
96 ExactHook<Port, bool() noexcept>::Take(&Port::IntAsserted);
97};
98
100template <typename Port>
101concept UartRxHooks = requires {
102 ExactHook<Port, std::size_t(uint8_t*, std::size_t) noexcept>::Take(&Port::UartRead);
103};
104
106template <typename Port>
107concept DeclaresUartWriteByte = requires(Port& port) { port.UartWriteByte(uint8_t{0}); };
108
110template <typename Port>
111concept HasUartWriteByte =
112 requires { ExactHook<Port, bool(uint8_t) noexcept>::Take(&Port::UartWriteByte); };
113
115template <typename Port>
116concept DeclaresUartWrite =
117 requires(Port& port, const uint8_t* p) { port.UartWrite(p, std::size_t{0}); };
118
120template <typename Port>
121concept HasUartWrite = requires {
122 ExactHook<Port, bool(const uint8_t*, std::size_t) noexcept>::Take(&Port::UartWrite);
123};
124
126template <typename Port>
127concept UartShtpHooks = UartRxHooks<Port> && (HasUartWriteByte<Port> || HasUartWrite<Port>);
128
130template <typename Port>
131concept DeclaresTransport = requires {
132 { Port::kTransport } -> std::convertible_to<Transport>;
133};
134
136template <typename Port, Transport T>
137concept IsTransport = DeclaresTransport<Port> && (Port::kTransport == T);
138
139} // namespace detail
140
146template <typename Port>
147concept HubPort =
148 std::derived_from<Port, HubInterface<Port>> && detail::CommonHooks<Port> &&
149 ((detail::IsTransport<Port, Transport::I2c> && detail::I2cHooks<Port>) ||
150 (detail::IsTransport<Port, Transport::Spi> && detail::SpiHooks<Port>) ||
151 (detail::IsTransport<Port, Transport::UartShtp> && detail::UartShtpHooks<Port>) ||
152 (detail::IsTransport<Port, Transport::UartRvc> && detail::UartRxHooks<Port>));
153
154} // namespace bno08x
155
156#endif // BNO08X_INTERFACE_HPP
Compile-time helpers of the BNO08X driver: typed integer literals, exact hook matching,...
What the BNO08x needs from the I2C bus (handbook KB-CPP-123); the port itself is in bno08x_interface....
What the BNO08x needs from the SPI bus (handbook KB-CPP-123); the port itself is in bno08x_interface....
Public types of the BNO08x driver: errors, Result<T>, configuration, events and the integer unit help...
What the BNO08x needs from the UART link (handbook KB-CPP-123); the port itself is in bno08x_interfac...
CRTP base of the platform port.
Definition bno08x_interface.hpp:60
HubInterface & operator=(const HubInterface &)=delete
Ports are not copied: the driver holds a reference.
HubInterface() noexcept=default
Only the derived port is constructed.
HubInterface(const HubInterface &)=delete
Ports are not copied: the driver holds a reference.
Satisfied by a class that derives from HubInterface<Port>, names its transport and implements that tr...
Definition bno08x_interface.hpp:147
The BNO08x driver: everything it declares lives here; internals in detail.
Definition bno08x.hpp:36