8#include "bno08x_version.h"
18#include "sh2/sh2_SensorValue.h"
19#include "sh2/sh2_err.h"
374template <
typename CommType>
381 explicit BNO085(CommType& comm) noexcept : io_(comm) {
409 bool Begin() noexcept;
420 void Close() noexcept;
632 int DfuFromMemory(
const uint8_t* data, uint32_t len,
const char* partNumber =
"1000-3608",
643 bool EnterBootloader(uint32_t resetLowMs = 10, uint32_t settleMs = 50) noexcept;
657 uint32_t enterResetLowMs = 10, uint32_t enterSettleMs = 50,
658 uint32_t exitResetLowMs = 2, uint32_t exitSettleMs = 100)
noexcept;
668 return HF_BNO08X_VERSION_STRING;
673 return HF_BNO08X_VERSION_MAJOR;
678 return HF_BNO08X_VERSION_MINOR;
683 return HF_BNO08X_VERSION_PATCH;
688 void prepareHalWrapper() noexcept;
704 CommType* comm{
nullptr};
707 static int halOpen(sh2_Hal_t* self);
708 static void halClose(sh2_Hal_t* self);
709 static int halRead(sh2_Hal_t* self, uint8_t* buf,
unsigned len, uint32_t* t);
710 static int halWrite(sh2_Hal_t* self, uint8_t* buf,
unsigned len);
711 static uint32_t halGetTimeUs(sh2_Hal_t* self);
719 static void sensorCallback(
void* cookie, sh2_SensorEvent_t* event);
720 static void asyncCallback(
void* cookie, sh2_AsyncEvent_t* event);
729 void handleSensorEvent(
const sh2_SensorEvent_t* event)
noexcept;
731 void handleAsyncEvent(
const sh2_AsyncEvent_t* event)
noexcept;
733 bool configure(
BNO085Sensor sensor, uint32_t interval_us,
float sensitivity,
734 uint32_t batch_us = 0) noexcept;
746 static constexpr uint8_t RVC_FRAME_LEN_ = 19;
749 void rvcProcessByte(uint8_t c) noexcept;
754 uint8_t rvc_frame_[RVC_FRAME_LEN_]{};
755 uint8_t rvc_frame_len_{0};
766 static void dfuWrite32be(uint8_t* buf, uint32_t value)
noexcept;
767 static bool dfuIsKnownPartNumber(
const char* part)
noexcept;
768 static void dfuAppendCrc(uint8_t* packet, uint8_t len)
noexcept;
769 int dfuSend(uint8_t* dfu_buff, uint8_t* p_data, uint32_t len)
noexcept;
770 int dfuSendAppSize(uint8_t* dfu_buff, uint32_t app_size)
noexcept;
771 int dfuSendPktSize(uint8_t* dfu_buff, uint8_t packet_len)
noexcept;
772 int dfuSendPkt(uint8_t* dfu_buff, uint8_t* p_data, uint32_t len)
noexcept;
786 static constexpr std::size_t SENSOR_CACHE_SIZE_ = 0x2F;
787 std::array<sh2_SensorValue_t, SENSOR_CACHE_SIZE_> latest_{};
788 std::array<bool, SENSOR_CACHE_SIZE_> new_flag_{};
789 std::array<uint32_t, SENSOR_CACHE_SIZE_>
791 std::array<float, SENSOR_CACHE_SIZE_> last_sensitivity_{};
804 return HF_BNO08X_VERSION_STRING;
812#define BNO085_HEADER_INCLUDED
815#undef BNO085_HEADER_INCLUDED
API Definition for HcBin objects (Hillcrest Binary Files).
const HcBin_t firmware
Default compiled-in firmware image for DFU.
Definition firmware-bno.c:35
const char * GetBNO08xDriverVersion() noexcept
Get the BNO08x driver version string (free function).
Definition bno08x.hpp:803
Template method implementations for the BNO085 driver class.
CRTP-based communication interface for the BNO08x IMU family.
BNO085Interface
Identifies the host interface type that a CommInterface provides.
Definition bno08x_comm_interface.hpp:25
Unified driver for the BNO08x IMU – SH-2 mode, RVC mode, and DFU.
Definition bno08x.hpp:375
int DfuWithOptions(const HcBin_t &fw, const DfuOptions &options) noexcept
Perform DFU with explicit validation and transfer options.
Definition bno08x.ipp:1032
bool DisableSensor(BNO085Sensor sensor) noexcept
Disable reporting for a sensor.
Definition bno08x.ipp:110
bool BeginRvc() noexcept
Initialise RVC mode.
Definition bno08x.ipp:723
void HardwareReset(uint32_t lowMs=2) noexcept
Perform a hardware reset via the RSTN pin.
Definition bno08x.ipp:585
bool HasNewData(BNO085Sensor sensor) const
Check if new data is available for a sensor.
Definition bno08x.ipp:140
SensorEvent GetLatest(BNO085Sensor sensor) noexcept
Retrieve the most recent event for a sensor.
Definition bno08x.ipp:412
bool EnableSensor(BNO085Sensor sensor, uint32_t interval_ms, float sensitivity=0.0f) noexcept
Enable periodic reporting for a sensor.
Definition bno08x.ipp:91
void ServiceRvc() noexcept
Poll for RVC frames and dispatch callbacks.
Definition bno08x.ipp:752
void SetCallback(SensorCallback cb) noexcept
Register a callback for SH-2 sensor events.
Definition bno08x.ipp:128
static constexpr uint8_t GetDriverVersionMinor() noexcept
Get the compiled driver minor version number.
Definition bno08x.hpp:677
void CloseRvc() noexcept
Stop RVC processing and close the transport.
Definition bno08x.ipp:763
void SelectInterface(BNO085Interface iface) noexcept
Select the host interface by driving PS0/PS1 pins.
Definition bno08x.ipp:673
int GetLastError() const
Get the last error code from the SH-2 driver.
Definition bno08x.hpp:554
void SetWakePin(bool state) noexcept
Drive the WAKE pin (SPI mode only).
Definition bno08x.ipp:660
BNO085(CommType &comm) noexcept
Construct the driver with a communication interface.
Definition bno08x.hpp:381
int DfuFromMemory(const DfuMemoryImage &image, const DfuOptions &options={}) noexcept
Perform DFU from an in-memory firmware image.
Definition bno08x.ipp:981
BNO085DriverState GetState() const noexcept
Get the current high-level driver state.
Definition bno08x.hpp:561
void Update() noexcept
Pump the SH-2 service loop.
Definition bno08x.ipp:427
~BNO085() noexcept
Destructor. Closes active SH-2/RVC sessions.
Definition bno08x.hpp:388
static constexpr const char * GetDriverVersion() noexcept
Get the compiled driver version string.
Definition bno08x.hpp:667
int RunDfuFromMemory(const DfuMemoryImage &image, const DfuOptions &options={}, uint32_t enterResetLowMs=10, uint32_t enterSettleMs=50, uint32_t exitResetLowMs=2, uint32_t exitSettleMs=100) noexcept
Full class-aware DFU workflow: enter bootloader -> transfer firmware -> reboot to app.
Definition bno08x.ipp:1005
void Close() noexcept
Close the currently active session and release transport resources.
Definition bno08x.ipp:435
int Dfu(const HcBin_t &fw=firmware) noexcept
Perform a Device Firmware Update (DFU).
Definition bno08x.ipp:974
bool Begin() noexcept
Initialise the sensor in SH-2 mode.
Definition bno08x.ipp:40
bool EnterBootloader(uint32_t resetLowMs=10, uint32_t settleMs=50) noexcept
Enter bootloader mode using BOOTN + reset pin sequence.
Definition bno08x.ipp:603
void SetBootPin(bool state) noexcept
Drive the BOOTN pin to enter/exit DFU bootloader mode.
Definition bno08x.ipp:595
bool ExitBootloaderAndReboot(uint32_t resetLowMs=2, uint32_t settleMs=100) noexcept
Exit bootloader mode and reboot into application firmware.
Definition bno08x.ipp:632
static constexpr uint8_t GetDriverVersionMajor() noexcept
Get the compiled driver major version number.
Definition bno08x.hpp:672
static constexpr uint8_t GetDriverVersionPatch() noexcept
Get the compiled driver patch version number.
Definition bno08x.hpp:682
void SetRvcCallback(RvcCallback cb) noexcept
Register a callback for decoded RVC frames.
Definition bno08x.ipp:134
std::function< void(const DfuProgress &)> DfuProgressCallback
Callback for DFU progress updates.
Definition bno08x.hpp:302
BNO085DriverState
Current top-level operating state of the driver.
Definition bno08x.hpp:285
std::function< void(const RvcSensorValue &)> RvcCallback
Callback invoked when a decoded RVC frame is available.
Definition bno08x.hpp:273
BNO085Sensor
Identifiers for all SH-2 sensor reports supported by the BNO08x.
Definition bno08x.hpp:44
std::function< void(const SensorEvent &)> SensorCallback
Callback invoked when a new SH-2 sensor event is received.
Definition bno08x.hpp:270
@ HeartRateMonitor
Heart rate data.
@ MagneticFieldUncalibrated
Raw magnetic field (uT)
@ GyroUncalibrated
Raw angular velocity (rad/s)
@ PersonalActivityClassifier
Activity classification (walking, running, etc.)
@ StepDetector
Individual step detected.
@ ShakeDetector
Shake gesture detected.
@ PickupDetector
Pickup gesture detected.
@ ARVRStabilizedRV
AR/VR stabilised rotation vector.
@ CircleDetector
Circular motion detected.
@ IZroMotionRequest
Interactive ZRO motion intent/request.
@ RawOpticalFlow
Raw optical flow report.
@ GeomagneticRotationVector
Orientation using magnetometer for heading.
@ FlipDetector
Flip gesture detected.
@ StepCounter
Cumulative step count.
@ Gravity
Gravity vector (m/s^2)
@ SleepDetector
Sleep state detected.
@ WheelEncoder
Wheel encoder report.
@ RotationVector
Fused absolute orientation quaternion.
@ SignificantMotion
Significant motion detected.
@ AmbientLight
Ambient light level (lux)
@ Magnetometer
Calibrated magnetic field (uT)
@ TiltDetector
Tilt event detected.
@ RawMagnetometer
Raw magnetometer ADC counts.
@ TapDetector
Single or double tap event.
@ Pressure
Barometric pressure (hPa)
@ StabilityClassifier
Device stability state (on table, in hand, etc.)
@ Accelerometer
Calibrated acceleration vector (m/s^2)
@ LinearAcceleration
Acceleration minus gravity (m/s^2)
@ Gyroscope
Calibrated angular velocity (rad/s)
@ StabilityDetector
Stability change detected.
@ GyroIntegratedRV
High-rate gyro-integrated rotation vector.
@ GameRotationVector
Orientation without magnetometer heading.
@ RawAccelerometer
Raw accelerometer ADC counts.
@ ARVRStabilizedGameRV
AR/VR stabilised game rotation vector.
@ Humidity
Relative humidity (%)
@ DeadReckoningPose
Dead reckoning pose estimate.
@ Temperature
Temperature (deg C)
@ RawGyroscope
Raw gyroscope ADC counts.
@ Proximity
Proximity detector (cm)
@ PocketDetector
Device-in-pocket detected.
Personal activity classifier payload.
Definition bno08x.hpp:141
std::array< uint8_t, 10 > confidence
Definition bno08x.hpp:145
bool lastPage
Definition bno08x.hpp:143
uint8_t mostLikelyState
Definition bno08x.hpp:144
uint8_t page
Definition bno08x.hpp:142
Dead reckoning position/orientation/velocity payload.
Definition bno08x.hpp:171
Vector3 linearPosition
Definition bno08x.hpp:173
uint32_t timestamp
Definition bno08x.hpp:172
Vector3 linearVelocity
Definition bno08x.hpp:175
Quaternion rotation
Definition bno08x.hpp:174
Vector3 angularVelocity
Definition bno08x.hpp:176
Firmware image descriptor for class-aware memory DFU.
Definition bno08x.hpp:321
uint32_t preferredPacketLen
Optional preferred DFU packet size.
Definition bno08x.hpp:326
uint32_t length
Firmware length in bytes.
Definition bno08x.hpp:323
const uint8_t * data
Pointer to firmware bytes.
Definition bno08x.hpp:322
const char * partNumber
SW-Part-Number metadata value.
Definition bno08x.hpp:325
const char * format
FW-Format metadata value.
Definition bno08x.hpp:324
Controls DFU validation and transfer behavior.
Definition bno08x.hpp:308
DfuProgressCallback progress
Optional per-transfer progress callback.
Definition bno08x.hpp:314
uint8_t packetLenOverride
Optional DFU packet size override (1..64).
Definition bno08x.hpp:313
bool requirePartNumber
Validate SW-Part-Number metadata.
Definition bno08x.hpp:310
bool requireFormatMatch
Validate FW-Format metadata.
Definition bno08x.hpp:309
const char * requiredPartNumber
Optional exact part number match.
Definition bno08x.hpp:312
const char * requiredFormat
Required format when format check is enabled.
Definition bno08x.hpp:311
Progress sample emitted during DFU transfers.
Definition bno08x.hpp:296
uint32_t totalBytes
Total firmware bytes to send.
Definition bno08x.hpp:298
uint32_t bytesSent
Number of firmware bytes sent so far.
Definition bno08x.hpp:297
Unit quaternion with sensor accuracy indicator.
Definition bno08x.hpp:108
float y
Imaginary j component.
Definition bno08x.hpp:111
float z
Imaginary k component.
Definition bno08x.hpp:112
float x
Imaginary i component.
Definition bno08x.hpp:110
uint8_t accuracy
Calibration accuracy (0 = unreliable, 3 = fully calibrated)
Definition bno08x.hpp:113
float w
Real (scalar) component.
Definition bno08x.hpp:109
Raw optical flow payload from SH2_RAW_OPTICAL_FLOW.
Definition bno08x.hpp:152
int16_t dx
Definition bno08x.hpp:155
uint8_t frameAvg
Definition bno08x.hpp:162
int16_t dy
Definition bno08x.hpp:156
uint8_t frameMax
Definition bno08x.hpp:161
uint8_t shutter
Definition bno08x.hpp:160
uint8_t resX
Definition bno08x.hpp:158
int16_t dt
Definition bno08x.hpp:154
uint32_t timestamp
Definition bno08x.hpp:153
uint8_t laserOn
Definition bno08x.hpp:164
uint8_t frameMin
Definition bno08x.hpp:163
int16_t iq
Definition bno08x.hpp:157
uint8_t resY
Definition bno08x.hpp:159
Raw integer 3-axis sample (ADC counts) with optional metadata.
Definition bno08x.hpp:129
int16_t x
Definition bno08x.hpp:130
int16_t z
Definition bno08x.hpp:132
int16_t temperature
Used by RawGyroscope only.
Definition bno08x.hpp:133
uint32_t sensorTimeUs
Sensor-provided timestamp where available.
Definition bno08x.hpp:134
int16_t y
Definition bno08x.hpp:131
Raw RVC frame data in integer fixed-point format.
Definition bno08x.hpp:235
int16_t yaw
Yaw angle (units: 0.01 degrees)
Definition bno08x.hpp:237
int16_t acc_y
Y linear acceleration (units: 0.001 g)
Definition bno08x.hpp:241
uint64_t timestamp_uS
Timestamp in microseconds (set by the driver)
Definition bno08x.hpp:245
uint8_t mr
Motion request (0=no constraint, 1=stay stationary)
Definition bno08x.hpp:244
int16_t pitch
Pitch angle (units: 0.01 degrees)
Definition bno08x.hpp:238
uint8_t index
Frame sequence index (0-255)
Definition bno08x.hpp:236
int16_t roll
Roll angle (units: 0.01 degrees)
Definition bno08x.hpp:239
int16_t acc_x
X linear acceleration (units: 0.001 g)
Definition bno08x.hpp:240
int16_t acc_z
Z linear acceleration (units: 0.001 g)
Definition bno08x.hpp:242
uint8_t mi
Motion intent (0=unknown, 1=stationary, 3=in motion)
Definition bno08x.hpp:243
Decoded RVC frame data in floating-point natural units.
Definition bno08x.hpp:254
uint8_t mi
Motion intent.
Definition bno08x.hpp:262
float yaw_deg
Yaw angle in degrees.
Definition bno08x.hpp:256
float acc_x_g
X linear acceleration in g.
Definition bno08x.hpp:259
uint8_t index
Frame sequence index.
Definition bno08x.hpp:255
uint64_t timestamp_uS
Timestamp in microseconds.
Definition bno08x.hpp:264
float roll_deg
Roll angle in degrees.
Definition bno08x.hpp:258
float acc_y_g
Y linear acceleration in g.
Definition bno08x.hpp:260
float pitch_deg
Pitch angle in degrees.
Definition bno08x.hpp:257
uint8_t mr
Motion request.
Definition bno08x.hpp:263
float acc_z_g
Z linear acceleration in g.
Definition bno08x.hpp:261
Container for a single decoded SH-2 sensor report.
Definition bno08x.hpp:201
uint64_t timestamp
Event timestamp in microseconds.
Definition bno08x.hpp:203
BNO085Sensor sensor
Which sensor produced this event.
Definition bno08x.hpp:202
bool detected
Generic detection flag for event-like reports.
Definition bno08x.hpp:222
uint8_t motionIntent
Interactive ZRO motion intent.
Definition bno08x.hpp:217
ActivityClassifierEvent activity
Personal activity classifier payload.
Definition bno08x.hpp:216
uint8_t classification
Classifier result (stability/activity, etc.).
Definition bno08x.hpp:213
uint32_t stepCount
Cumulative step count (StepCounter)
Definition bno08x.hpp:211
TapEvent tap
Tap event details (TapDetector)
Definition bno08x.hpp:215
uint8_t motionRequest
Interactive ZRO motion request.
Definition bno08x.hpp:218
RawVector3 raw
Raw integer payload for raw IMU reports.
Definition bno08x.hpp:209
Vector3 vector
3-axis data (accel/gyro/mag/gravity/etc.)
Definition bno08x.hpp:204
uint8_t sleepState
Sleep detector state.
Definition bno08x.hpp:214
WheelEncoderEvent wheelEncoder
Definition bno08x.hpp:221
RawOpticalFlowEvent rawOpticalFlow
Definition bno08x.hpp:219
DeadReckoningPoseEvent deadReckoningPose
Definition bno08x.hpp:220
Vector3 bias
Bias for uncalibrated gyro/mag reports.
Definition bno08x.hpp:205
uint16_t eventFlags
Bitfield payload for gesture detector reports.
Definition bno08x.hpp:212
Quaternion rotation
Quaternion data (rotation vector reports)
Definition bno08x.hpp:207
Vector3 angularVelocity
Angular velocity for GyroIntegratedRV.
Definition bno08x.hpp:206
float scalar
Scalar payload (pressure/light/humidity/temp/etc.)
Definition bno08x.hpp:208
uint32_t latencyUs
Latency for step detector/counter reports.
Definition bno08x.hpp:210
Tap detector event details.
Definition bno08x.hpp:120
uint8_t direction
Tap direction: 0=+X, 1=-X, 2=+Y, 3=-Y, 4=+Z, 5=-Z.
Definition bno08x.hpp:122
bool doubleTap
True if double-tap, false if single-tap.
Definition bno08x.hpp:121
Three-axis vector with sensor accuracy indicator.
Definition bno08x.hpp:94
uint8_t accuracy
Calibration accuracy (0 = unreliable, 3 = fully calibrated)
Definition bno08x.hpp:98
float x
X-axis component.
Definition bno08x.hpp:95
float y
Y-axis component.
Definition bno08x.hpp:96
float z
Z-axis component.
Definition bno08x.hpp:97
Wheel encoder payload.
Definition bno08x.hpp:183
uint16_t data
Definition bno08x.hpp:187
uint32_t timestamp
Definition bno08x.hpp:184
uint8_t wheelIndex
Definition bno08x.hpp:185
uint8_t dataType
Definition bno08x.hpp:186