8#include "bno08x_version.h"
19#include "sh2/sh2_SensorValue.h"
20#include "sh2/sh2_err.h"
43 static std::atomic<const void*> owner{
nullptr};
399template <
typename CommType>
406 explicit BNO085(CommType& comm) noexcept : io_(comm) {
440 bool Begin() noexcept;
458 void Close() noexcept;
640 const auto sa0 =
static_cast<uint8_t
>(appAddress & 0x01U);
641 const auto base =
static_cast<uint8_t
>(appAddress & 0xFEU);
715 int DfuFromMemory(
const uint8_t* data, uint32_t len,
const char* partNumber =
"1000-3608",
729 bool EnterBootloader(uint32_t resetLowMs = 10, uint32_t settleMs = 50) noexcept;
744 uint32_t enterResetLowMs = 10, uint32_t enterSettleMs = 50,
745 uint32_t exitResetLowMs = 2, uint32_t exitSettleMs = 100)
noexcept;
755 return HF_BNO08X_VERSION_STRING;
760 return HF_BNO08X_VERSION_MAJOR;
765 return HF_BNO08X_VERSION_MINOR;
770 return HF_BNO08X_VERSION_PATCH;
775 void prepareHalWrapper() noexcept;
778 bool acquireSh2Session() noexcept;
780 void releaseSh2Session() noexcept;
783 bool setPin(
bno08x::CtrlPin pin,
bool active) noexcept;
800 CommType* comm{
nullptr};
804 static int halOpen(sh2_Hal_t* self);
805 static void halClose(sh2_Hal_t* self);
806 static int halRead(sh2_Hal_t* self, uint8_t* buf,
unsigned len, uint32_t* t);
807 static int halWrite(sh2_Hal_t* self, uint8_t* buf,
unsigned len);
808 static uint32_t halGetTimeUs(sh2_Hal_t* self);
816 static void sensorCallback(
void* cookie, sh2_SensorEvent_t* event);
817 static void asyncCallback(
void* cookie, sh2_AsyncEvent_t* event);
826 void handleSensorEvent(
const sh2_SensorEvent_t* event)
noexcept;
828 void handleAsyncEvent(
const sh2_AsyncEvent_t* event)
noexcept;
830 bool configure(
BNO085Sensor sensor, uint32_t interval_us,
float sensitivity,
831 uint32_t batch_us = 0) noexcept;
843 static constexpr uint8_t RVC_FRAME_LEN_ = 19;
846 void rvcProcessByte(uint8_t c) noexcept;
851 uint8_t rvc_frame_[RVC_FRAME_LEN_]{};
852 uint8_t rvc_frame_len_{0};
863 static void dfuWrite32be(uint8_t* buf, uint32_t value)
noexcept;
864 static bool dfuIsKnownPartNumber(
const char* part)
noexcept;
865 static void dfuAppendCrc(uint8_t* packet, uint8_t len)
noexcept;
866 int dfuSend(uint8_t* p_data, uint32_t len)
noexcept;
867 int dfuSendAppSize(uint8_t* dfu_buff, uint32_t app_size)
noexcept;
868 int dfuSendPktSize(uint8_t* dfu_buff, uint8_t packet_len)
noexcept;
869 int dfuSendPkt(uint8_t* dfu_buff, uint8_t* p_data, uint32_t len)
noexcept;
870 int dfuSelectBootloaderAddress(uint8_t& appAddress,
bool& switched)
noexcept;
871 bool dfuRestoreAppAddress(uint8_t appAddress)
noexcept;
885 static constexpr std::size_t SENSOR_CACHE_SIZE_ = 0x2F;
886 std::array<sh2_SensorValue_t, SENSOR_CACHE_SIZE_> latest_{};
887 std::array<bool, SENSOR_CACHE_SIZE_> new_flag_{};
888 std::array<uint32_t, SENSOR_CACHE_SIZE_>
890 std::array<float, SENSOR_CACHE_SIZE_> last_sensitivity_{};
903 return HF_BNO08X_VERSION_STRING;
913#define BNO085_HEADER_INCLUDED
916#undef BNO085_HEADER_INCLUDED
API Definition for HcBin objects (Hillcrest Binary Files).
const HcBin_t firmware
Default compiled-in firmware image for DFU.
const char * GetBNO08xDriverVersion() noexcept
Get the BNO08x driver version string (free function).
Definition bno08x.hpp:902
constexpr int BNO08X_ERR_SH2_SESSION_IN_USE
GetLastError() value when Begin() is refused because another BNO085 object already holds the SH-2 ses...
Definition bno08x.hpp:33
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:27
Unified driver for the BNO08x IMU – SH-2 mode, RVC mode, and DFU.
Definition bno08x.hpp:400
int DfuWithOptions(const HcBin_t &fw, const DfuOptions &options) noexcept
Perform DFU with explicit validation and transfer options.
Definition bno08x.ipp:1125
bool DisableSensor(BNO085Sensor sensor) noexcept
Disable reporting for a sensor.
Definition bno08x.ipp:119
bool SetBootPin(bool state) noexcept
Drive the BOOTN pin to enter/exit DFU bootloader mode.
Definition bno08x.ipp:642
bool BeginRvc() noexcept
Initialise RVC mode.
Definition bno08x.ipp:774
bool HasNewData(BNO085Sensor sensor) const
Check if new data is available for a sensor.
Definition bno08x.ipp:149
SensorEvent GetLatest(BNO085Sensor sensor) noexcept
Retrieve the most recent event for a sensor.
Definition bno08x.ipp:421
bool EnableSensor(BNO085Sensor sensor, uint32_t interval_ms, float sensitivity=0.0f) noexcept
Enable periodic reporting for a sensor.
Definition bno08x.ipp:100
void ServiceRvc() noexcept
Poll for RVC frames and dispatch callbacks.
Definition bno08x.ipp:803
static constexpr uint8_t I2C_ADDRESS_APP
Application I2C address with SA0 low (datasheet figure 1-12); 0x4B with SA0 high.
Definition bno08x.hpp:626
void SetCallback(SensorCallback cb) noexcept
Register a callback for SH-2 sensor events.
Definition bno08x.ipp:137
static constexpr uint8_t GetDriverVersionMinor() noexcept
Get the compiled driver minor version number.
Definition bno08x.hpp:764
void CloseRvc() noexcept
Stop RVC processing and close the transport.
Definition bno08x.ipp:814
static constexpr uint8_t I2C_ADDRESS_BOOTLOADER
Bootloader I2C address with SA0 low (datasheet section 1.4); 0x29 with SA0 high.
Definition bno08x.hpp:628
int GetLastError() const
Get the last error code from the SH-2 driver.
Definition bno08x.hpp:592
BNO085(CommType &comm) noexcept
Construct the driver with a communication interface.
Definition bno08x.hpp:406
int DfuFromMemory(const DfuMemoryImage &image, const DfuOptions &options={}) noexcept
Perform DFU from an in-memory firmware image.
Definition bno08x.ipp:1074
BNO085DriverState GetState() const noexcept
Get the current high-level driver state.
Definition bno08x.hpp:599
void Update() noexcept
Pump the SH-2 service loop.
Definition bno08x.ipp:436
~BNO085() noexcept
Destructor. Closes active SH-2/RVC sessions.
Definition bno08x.hpp:413
static constexpr const char * GetDriverVersion() noexcept
Get the compiled driver version string.
Definition bno08x.hpp:754
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:1098
void Close() noexcept
Close the currently active session and release transport resources.
Definition bno08x.ipp:444
int Dfu(const HcBin_t &fw=firmware) noexcept
Perform a Device Firmware Update (DFU).
Definition bno08x.ipp:1067
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:648
bool SetWakePin(bool state) noexcept
Drive the WAKE pin (SPI mode only).
Definition bno08x.ipp:722
bool ExitBootloaderAndReboot(uint32_t resetLowMs=2, uint32_t settleMs=100) noexcept
Exit bootloader mode and reboot into application firmware.
Definition bno08x.ipp:686
static constexpr uint8_t BootloaderI2cAddress(uint8_t appAddress) noexcept
Bootloader I2C address for a port configured at appAddress.
Definition bno08x.hpp:639
static constexpr uint8_t GetDriverVersionMajor() noexcept
Get the compiled driver major version number.
Definition bno08x.hpp:759
static constexpr uint8_t GetDriverVersionPatch() noexcept
Get the compiled driver patch version number.
Definition bno08x.hpp:769
static bool Sh2SessionInUse() noexcept
True while any BNO085 object in the process holds the SH-2 session.
Definition bno08x.hpp:445
bool SelectInterface(BNO085Interface iface) noexcept
Select the host interface by driving PS0/PS1 pins.
Definition bno08x.ipp:736
bool HardwareReset(uint32_t lowMs=2) noexcept
Perform a hardware reset via the RSTN pin.
Definition bno08x.ipp:627
static constexpr uint32_t RESET_STARTUP_MS
Wait after releasing NRST before the hub can be addressed, in ms.
Definition bno08x.hpp:623
void SetRvcCallback(RvcCallback cb) noexcept
Register a callback for decoded RVC frames.
Definition bno08x.ipp:143
std::function< void(const DfuProgress &)> DfuProgressCallback
Callback for DFU progress updates.
Definition bno08x.hpp:323
BNO085DriverState
Current top-level operating state of the driver.
Definition bno08x.hpp:311
std::function< void(const RvcSensorValue &)> RvcCallback
Callback invoked when a decoded RVC frame is available.
Definition bno08x.hpp:299
BNO085Sensor
Identifiers for all SH-2 sensor reports supported by the BNO08x.
Definition bno08x.hpp:70
std::function< void(const SensorEvent &)> SensorCallback
Callback invoked when a new SH-2 sensor event is received.
Definition bno08x.hpp:296
@ 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.
std::atomic< const void * > & Sh2SessionOwner() noexcept
Owner of the process-wide SH-2 session (nullptr when free).
Definition bno08x.hpp:42
Personal activity classifier payload.
Definition bno08x.hpp:167
std::array< uint8_t, 10 > confidence
Definition bno08x.hpp:171
bool lastPage
Definition bno08x.hpp:169
uint8_t mostLikelyState
Definition bno08x.hpp:170
uint8_t page
Definition bno08x.hpp:168
Dead reckoning position/orientation/velocity payload.
Definition bno08x.hpp:197
Vector3 linearPosition
Definition bno08x.hpp:199
uint32_t timestamp
Definition bno08x.hpp:198
Vector3 linearVelocity
Definition bno08x.hpp:201
Quaternion rotation
Definition bno08x.hpp:200
Vector3 angularVelocity
Definition bno08x.hpp:202
Firmware image descriptor for class-aware memory DFU.
Definition bno08x.hpp:342
uint32_t preferredPacketLen
Optional preferred DFU packet size.
Definition bno08x.hpp:347
uint32_t length
Firmware length in bytes.
Definition bno08x.hpp:344
const uint8_t * data
Pointer to firmware bytes.
Definition bno08x.hpp:343
const char * partNumber
SW-Part-Number metadata value.
Definition bno08x.hpp:346
const char * format
FW-Format metadata value.
Definition bno08x.hpp:345
Controls DFU validation and transfer behavior.
Definition bno08x.hpp:329
DfuProgressCallback progress
Optional per-transfer progress callback.
Definition bno08x.hpp:335
uint8_t packetLenOverride
Optional DFU packet size override (1..64).
Definition bno08x.hpp:334
bool requirePartNumber
Validate SW-Part-Number metadata.
Definition bno08x.hpp:331
bool requireFormatMatch
Validate FW-Format metadata.
Definition bno08x.hpp:330
const char * requiredPartNumber
Optional exact part number match.
Definition bno08x.hpp:333
const char * requiredFormat
Required format when format check is enabled.
Definition bno08x.hpp:332
Progress sample emitted during DFU transfers.
Definition bno08x.hpp:317
uint32_t totalBytes
Total firmware bytes to send.
Definition bno08x.hpp:319
uint32_t bytesSent
Number of firmware bytes sent so far.
Definition bno08x.hpp:318
Unit quaternion with sensor accuracy indicator.
Definition bno08x.hpp:134
float y
Imaginary j component.
Definition bno08x.hpp:137
float z
Imaginary k component.
Definition bno08x.hpp:138
float x
Imaginary i component.
Definition bno08x.hpp:136
uint8_t accuracy
Calibration accuracy (0 = unreliable, 3 = fully calibrated)
Definition bno08x.hpp:139
float w
Real (scalar) component.
Definition bno08x.hpp:135
Raw optical flow payload from SH2_RAW_OPTICAL_FLOW.
Definition bno08x.hpp:178
int16_t dx
Definition bno08x.hpp:181
uint8_t frameAvg
Definition bno08x.hpp:188
int16_t dy
Definition bno08x.hpp:182
uint8_t frameMax
Definition bno08x.hpp:187
uint8_t shutter
Definition bno08x.hpp:186
uint8_t resX
Definition bno08x.hpp:184
int16_t dt
Definition bno08x.hpp:180
uint32_t timestamp
Definition bno08x.hpp:179
uint8_t laserOn
Definition bno08x.hpp:190
uint8_t frameMin
Definition bno08x.hpp:189
int16_t iq
Definition bno08x.hpp:183
uint8_t resY
Definition bno08x.hpp:185
Raw integer 3-axis sample (ADC counts) with optional metadata.
Definition bno08x.hpp:155
int16_t x
Definition bno08x.hpp:156
int16_t z
Definition bno08x.hpp:158
int16_t temperature
Used by RawGyroscope only.
Definition bno08x.hpp:159
uint32_t sensorTimeUs
Sensor-provided timestamp where available.
Definition bno08x.hpp:160
int16_t y
Definition bno08x.hpp:157
Raw RVC frame data in integer fixed-point format.
Definition bno08x.hpp:261
int16_t yaw
Yaw angle (units: 0.01 degrees)
Definition bno08x.hpp:263
int16_t acc_y
Y linear acceleration (units: 0.001 g)
Definition bno08x.hpp:267
uint64_t timestamp_uS
Timestamp in microseconds (set by the driver)
Definition bno08x.hpp:271
uint8_t mr
Motion request (0=no constraint, 1=stay stationary)
Definition bno08x.hpp:270
int16_t pitch
Pitch angle (units: 0.01 degrees)
Definition bno08x.hpp:264
uint8_t index
Frame sequence index (0-255)
Definition bno08x.hpp:262
int16_t roll
Roll angle (units: 0.01 degrees)
Definition bno08x.hpp:265
int16_t acc_x
X linear acceleration (units: 0.001 g)
Definition bno08x.hpp:266
int16_t acc_z
Z linear acceleration (units: 0.001 g)
Definition bno08x.hpp:268
uint8_t mi
Motion intent (0=unknown, 1=stationary, 3=in motion)
Definition bno08x.hpp:269
Decoded RVC frame data in floating-point natural units.
Definition bno08x.hpp:280
uint8_t mi
Motion intent.
Definition bno08x.hpp:288
float yaw_deg
Yaw angle in degrees.
Definition bno08x.hpp:282
float acc_x_g
X linear acceleration in g.
Definition bno08x.hpp:285
uint8_t index
Frame sequence index.
Definition bno08x.hpp:281
uint64_t timestamp_uS
Timestamp in microseconds.
Definition bno08x.hpp:290
float roll_deg
Roll angle in degrees.
Definition bno08x.hpp:284
float acc_y_g
Y linear acceleration in g.
Definition bno08x.hpp:286
float pitch_deg
Pitch angle in degrees.
Definition bno08x.hpp:283
uint8_t mr
Motion request.
Definition bno08x.hpp:289
float acc_z_g
Z linear acceleration in g.
Definition bno08x.hpp:287
Container for a single decoded SH-2 sensor report.
Definition bno08x.hpp:227
uint64_t timestamp
Event timestamp in microseconds.
Definition bno08x.hpp:229
BNO085Sensor sensor
Which sensor produced this event.
Definition bno08x.hpp:228
bool detected
Generic detection flag for event-like reports.
Definition bno08x.hpp:248
uint8_t motionIntent
Interactive ZRO motion intent.
Definition bno08x.hpp:243
ActivityClassifierEvent activity
Personal activity classifier payload.
Definition bno08x.hpp:242
uint8_t classification
Classifier result (stability/activity, etc.).
Definition bno08x.hpp:239
uint32_t stepCount
Cumulative step count (StepCounter)
Definition bno08x.hpp:237
TapEvent tap
Tap event details (TapDetector)
Definition bno08x.hpp:241
uint8_t motionRequest
Interactive ZRO motion request.
Definition bno08x.hpp:244
RawVector3 raw
Raw integer payload for raw IMU reports.
Definition bno08x.hpp:235
Vector3 vector
3-axis data (accel/gyro/mag/gravity/etc.)
Definition bno08x.hpp:230
uint8_t sleepState
Sleep detector state.
Definition bno08x.hpp:240
WheelEncoderEvent wheelEncoder
Definition bno08x.hpp:247
RawOpticalFlowEvent rawOpticalFlow
Definition bno08x.hpp:245
DeadReckoningPoseEvent deadReckoningPose
Definition bno08x.hpp:246
Vector3 bias
Bias for uncalibrated gyro/mag reports.
Definition bno08x.hpp:231
uint16_t eventFlags
Bitfield payload for gesture detector reports.
Definition bno08x.hpp:238
Quaternion rotation
Quaternion data (rotation vector reports)
Definition bno08x.hpp:233
Vector3 angularVelocity
Angular velocity for GyroIntegratedRV.
Definition bno08x.hpp:232
float scalar
Scalar payload (pressure/light/humidity/temp/etc.)
Definition bno08x.hpp:234
uint32_t latencyUs
Latency for step detector/counter reports.
Definition bno08x.hpp:236
Tap detector event details.
Definition bno08x.hpp:146
uint8_t direction
Tap direction: 0=+X, 1=-X, 2=+Y, 3=-Y, 4=+Z, 5=-Z.
Definition bno08x.hpp:148
bool doubleTap
True if double-tap, false if single-tap.
Definition bno08x.hpp:147
Three-axis vector with sensor accuracy indicator.
Definition bno08x.hpp:120
uint8_t accuracy
Calibration accuracy (0 = unreliable, 3 = fully calibrated)
Definition bno08x.hpp:124
float x
X-axis component.
Definition bno08x.hpp:121
float y
Y-axis component.
Definition bno08x.hpp:122
float z
Z-axis component.
Definition bno08x.hpp:123
Wheel encoder payload.
Definition bno08x.hpp:209
uint16_t data
Definition bno08x.hpp:213
uint32_t timestamp
Definition bno08x.hpp:210
uint8_t wheelIndex
Definition bno08x.hpp:211
uint8_t dataType
Definition bno08x.hpp:212