HF-BNO08x  0.1.0-dev
Loading...
Searching...
No Matches
bno08x_comm_interface.hpp
Go to the documentation of this file.
1#pragma once
7#include <cstdint>
8
9// ============================================================================
10// Interface Type Enum
11// ============================================================================
12
25enum class BNO085Interface : uint8_t {
26 I2C = 0,
27 UARTRVC = 1,
28 UART = 2,
29 SPI = 3
30};
31
32// ============================================================================
33// CommInterface CRTP Base
34// ============================================================================
35
36namespace bno08x {
37
38// ============================================================================
39// GPIO Enums -- Standardised Control Pin Model
40// ============================================================================
41
58enum class CtrlPin : uint8_t {
59 RSTN = 0,
60 BOOTN,
61 WAKE,
62 PS0,
63 PS1
64};
65
74enum class GpioSignal : uint8_t {
75 INACTIVE = 0,
76 ACTIVE = 1
77};
78
91template <typename Derived>
93public:
94 // --------------------------------------------------------------------------
97
107 return static_cast<Derived*>(this)->GetInterfaceType();
108 }
109
111
112 // --------------------------------------------------------------------------
115
125 bool Open() noexcept {
126 return static_cast<Derived*>(this)->Open();
127 }
128
135 void Close() noexcept {
136 static_cast<Derived*>(this)->Close();
137 }
138
149 int Write(const uint8_t* data, uint32_t length) noexcept {
150 return static_cast<Derived*>(this)->Write(data, length);
151 }
152
165 int Read(uint8_t* data, uint32_t length) noexcept {
166 return static_cast<Derived*>(this)->Read(data, length);
167 }
168
177 bool DataAvailable() noexcept {
178 return static_cast<Derived*>(this)->DataAvailable();
179 }
180
188 void Delay(uint32_t ms) noexcept {
189 static_cast<Derived*>(this)->Delay(ms);
190 }
191
201 uint32_t GetTimeUs() noexcept {
202 return static_cast<Derived*>(this)->GetTimeUs();
203 }
204
206
207 // --------------------------------------------------------------------------
214
224 void GpioSet(CtrlPin pin, GpioSignal signal) noexcept {
225 static_cast<Derived*>(this)->GpioSet(pin, signal);
226 }
227
235 void GpioSetActive(CtrlPin pin) noexcept {
237 }
238
246 void GpioSetInactive(CtrlPin pin) noexcept {
248 }
249
251
252protected:
254 CommInterface() = default;
256 ~CommInterface() = default;
257
258 CommInterface(const CommInterface&) = delete;
260 CommInterface(CommInterface&&) noexcept = default;
261 CommInterface& operator=(CommInterface&&) noexcept = default;
262};
263
264} // namespace bno08x
BNO085Interface
Identifies the host interface type that a CommInterface provides.
Definition bno08x_comm_interface.hpp:25
@ UARTRVC
UART in RVC mode (PS1=1, PS0=0). RVC frames only.
@ SPI
SPI bus (PS1=1, PS0=1). Supports SH-2 and DFU.
@ UART
UART in SH-2 mode (PS1=0, PS0=1). Supports SH-2 and DFU.
@ I2C
I2C bus (PS1=0, PS0=0). Supports SH-2 and DFU.
CRTP base class for BNO08x communication interfaces.
Definition bno08x_comm_interface.hpp:92
void GpioSet(CtrlPin pin, GpioSignal signal) noexcept
Set a control pin to the specified signal state.
Definition bno08x_comm_interface.hpp:224
CommInterface()=default
Protected constructor – prevents direct instantiation.
bool DataAvailable() noexcept
Check whether the sensor has data ready.
Definition bno08x_comm_interface.hpp:177
CommInterface(CommInterface &&) noexcept=default
Movable.
CommInterface & operator=(const CommInterface &)=delete
Non-copyable.
void Close() noexcept
Close the communication bus and release resources.
Definition bno08x_comm_interface.hpp:135
CommInterface(const CommInterface &)=delete
Non-copyable.
uint32_t GetTimeUs() noexcept
Return the current monotonic time in microseconds.
Definition bno08x_comm_interface.hpp:201
void GpioSetActive(CtrlPin pin) noexcept
Assert a control pin (set to ACTIVE).
Definition bno08x_comm_interface.hpp:235
int Write(const uint8_t *data, uint32_t length) noexcept
Write raw bytes to the sensor.
Definition bno08x_comm_interface.hpp:149
bool Open() noexcept
Open and initialise the communication bus.
Definition bno08x_comm_interface.hpp:125
void GpioSetInactive(CtrlPin pin) noexcept
Deassert a control pin (set to INACTIVE).
Definition bno08x_comm_interface.hpp:246
~CommInterface()=default
Protected destructor – prevent polymorphic deletion through base.
void Delay(uint32_t ms) noexcept
Block for a specified duration.
Definition bno08x_comm_interface.hpp:188
int Read(uint8_t *data, uint32_t length) noexcept
Read raw bytes from the sensor.
Definition bno08x_comm_interface.hpp:165
BNO085Interface GetInterfaceType() noexcept
Report the transport type this implementation provides.
Definition bno08x_comm_interface.hpp:106
Definition bno08x_comm_interface.hpp:36
CtrlPin
Identifies the hardware control pins of the BNO08x.
Definition bno08x_comm_interface.hpp:58
@ PS0
Protocol select bit 0 (active-high on the physical pin)
@ BOOTN
Bootloader entry (active-low on the physical pin)
@ RSTN
Hardware reset (active-low on the physical pin)
@ PS1
Protocol select bit 1 (active-high on the physical pin)
@ WAKE
Wake from suspend, SPI mode only (active-low on the physical pin)
GpioSignal
Abstract signal level for control pins.
Definition bno08x_comm_interface.hpp:74
@ ACTIVE
Pin function is asserted.
@ INACTIVE
Pin function is deasserted.