HF-Core Platform 0.1.0-dev
Hardware-Agnostic Handler Layer & RTOS Utilities for HardFOC
Loading...
Searching...
No Matches
Bno08xHandler.h File Reference

Unified handler for BNO08x IMU sensor family with multi-interface support. More...

#include <cstdint>
#include <memory>
#include <array>
#include <functional>
#include <type_traits>
#include <utility>
#include "core/hf-core-drivers/external/hf-bno08x-driver/inc/bno08x.hpp"
#include "core/hf-core-drivers/external/hf-bno08x-driver/inc/bno08x_comm_interface.hpp"
#include "base/BaseI2c.h"
#include "base/BaseSpi.h"
#include "base/BaseGpio.h"
#include "RtosMutex.h"
Include dependency graph for Bno08xHandler.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  HalI2cBno08xComm
 I2C CRTP communication adapter for BNO08x. More...
 
class  HalSpiBno08xComm
 SPI CRTP communication adapter for BNO08x. More...
 
class  IBno08xDriverOps
 Internal abstract interface for type-erasing the BNO085<CommType> template. More...
 
class  Bno08xDriverImpl< CommType >
 Concrete type-erased driver wrapper. More...
 
struct  Bno08xVector3
 Enhanced vector with timestamp and accuracy. More...
 
struct  Bno08xQuaternion
 Enhanced quaternion with timestamp and accuracy. More...
 
struct  Bno08xEulerAngles
 Euler angles derived from quaternion. More...
 
struct  Bno08xImuData
 Complete IMU sensor data structure. More...
 
struct  Bno08xActivityData
 Activity and gesture detection data. More...
 
struct  Bno08xCalibrationStatus
 Sensor calibration status. More...
 
struct  Bno08xConfig
 BNO08x configuration structure. More...
 
class  Bno08xHandler
 Unified handler for BNO08x IMU sensor family. More...
 

Enumerations

enum class  Bno08xError : uint8_t {
  SUCCESS = 0 , NOT_INITIALIZED , INITIALIZATION_FAILED , INVALID_PARAMETER ,
  COMMUNICATION_FAILED , SENSOR_NOT_RESPONDING , CALIBRATION_FAILED , FIRMWARE_UPDATE_FAILED ,
  TIMEOUT , MUTEX_LOCK_FAILED , INVALID_INTERFACE , SENSOR_NOT_ENABLED ,
  DATA_NOT_AVAILABLE , HARDWARE_ERROR , UNSUPPORTED_OPERATION
}
 BNO08x handler error codes for consistent error reporting. More...
 

Functions

constexpr const char * Bno08xErrorToString (Bno08xError error) noexcept
 Convert Bno08xError to string for debugging.
 
std::unique_ptr< Bno08xHandlerCreateBno08xHandlerI2c (BaseI2c &i2c_device, const Bno08xConfig &config=Bno08xConfig{}, BaseGpio *reset_gpio=nullptr, BaseGpio *int_gpio=nullptr) noexcept
 Create BNO08x handler with I2C interface.
 
std::unique_ptr< Bno08xHandlerCreateBno08xHandlerSpi (BaseSpi &spi_device, const Bno08xConfig &config=Bno08xConfig{}, BaseGpio *reset_gpio=nullptr, BaseGpio *int_gpio=nullptr, BaseGpio *wake_gpio=nullptr) noexcept
 Create BNO08x handler with SPI interface.
 

Detailed Description

Unified handler for BNO08x IMU sensor family with multi-interface support.

This file provides the complete HAL-level integration for a BNO08x IMU sensor. It bridges the HardFOC base interfaces (BaseI2c, BaseSpi, BaseGpio) with the templated BNO085<CommType> driver from the hf-bno08x-driver library.

Architecture Overview

The file contains four layers:

  1. CRTP Communication Adapters (HalI2cBno08xComm, HalSpiBno08xComm): Bridge HardFOC BaseI2c/BaseSpi device-centric interfaces with the BNO08x driver's CRTP-based bno08x::CommInterface. Includes all 12 required methods (bus I/O, timing, and 5 pin control signals).
  2. Type-Erased Driver Interface (IBno08xDriverOps): Internal abstract class that hides the BNO085<CommType> template from the handler. Provides virtual methods for all driver operations. The one-vtable cost is negligible for an IMU updating at ~100 Hz.
  3. Template Driver Wrapper (Bno08xDriverImpl<CommType>): Owns both the CRTP comm adapter and the BNO085 driver instance, implementing IBno08xDriverOps by delegating to the real driver.
  4. Bno08xHandler (main class): Non-templated facade that owns a type-erased driver via unique_ptr. Provides:
    • Lazy initialization with hardware reset sequence
    • Complete SH-2 sensor data access (9-DOF fusion, gestures, activity)
    • GetSensor() for direct driver API (Update, EnableSensor, GetLatest, SetCallback, etc.)
    • Callback management for event-driven operation
    • Individual sensor enable/disable with configurable intervals
    • Hardware control (reset, boot, wake pins)
    • Thread-safe operations with RtosMutex protection
    • Comprehensive diagnostics

Ownership Model

The handler owns all its internal resources:

Initialization Sequence

// 1. Obtain a BaseI2c device reference (address pre-configured, e.g. 0x4A)
// 2. Construct the handler (config enables accel+gyro+mag+rotation by default)
Bno08xHandler handler(i2c_device);
// 3. Initialize (runs Begin + applyConfigLocked to enable configured sensors)
if (handler.Initialize() != Bno08xError::SUCCESS) { return; }
// 4. Optionally enable extra sensors via driver access
handler.visitDriver([](IBno08xDriverOps& drv) {
drv.EnableSensor(BNO085Sensor::GameRotationVector, 10);
});
// 5. Set callback for event-driven data
handler.SetSensorCallback([](const SensorEvent& e) { ... });
// 6. Service loop
while (true) { handler.Update(); }
@ SUCCESS
Operation completed successfully.
Unified handler for BNO08x IMU sensor family.
Definition Bno08xHandler.h:484
Internal abstract interface for type-erasing the BNO085<CommType> template.
Definition Bno08xHandler.h:257
virtual bool EnableSensor(BNO085Sensor sensor, uint32_t interval_ms, float sensitivity) noexcept=0

Thread Safety

The handler uses RtosMutex (recursive) for thread-safe access to all handler-level operations.

See also
BNO085 Templated driver from hf-bno08x-driver
bno08x::CommInterface CRTP communication base class
Author
HardFOC Team
Date
2025

Enumeration Type Documentation

◆ Bno08xError

enum class Bno08xError : uint8_t
strong

BNO08x handler error codes for consistent error reporting.

Enumerator
SUCCESS 

Operation completed successfully.

NOT_INITIALIZED 

Handler or sensor not initialized.

INITIALIZATION_FAILED 

Begin() or config apply failed.

INVALID_PARAMETER 

Bad argument (e.g. invalid sensor)

COMMUNICATION_FAILED 

I2C/SPI or SH-2 I/O error.

SENSOR_NOT_RESPONDING 

Hub/sensor did not respond.

CALIBRATION_FAILED 

Calibration request failed.

FIRMWARE_UPDATE_FAILED 

DFU transfer failed.

TIMEOUT 

Operation timed out.

MUTEX_LOCK_FAILED 

Could not acquire handler mutex.

INVALID_INTERFACE 

Wrong interface type for operation.

SENSOR_NOT_ENABLED 

Sensor not enabled for read.

DATA_NOT_AVAILABLE 

No new data for requested sensor.

HARDWARE_ERROR 

GPIO or hardware fault.

UNSUPPORTED_OPERATION 

Feature not supported.

Function Documentation

◆ Bno08xErrorToString()

constexpr const char * Bno08xErrorToString ( Bno08xError error)
constexprnoexcept

Convert Bno08xError to string for debugging.

Here is the caller graph for this function:

◆ CreateBno08xHandlerI2c()

std::unique_ptr< Bno08xHandler > CreateBno08xHandlerI2c ( BaseI2c & i2c_device,
const Bno08xConfig & config = Bno08xConfig{},
BaseGpio * reset_gpio = nullptr,
BaseGpio * int_gpio = nullptr )
inlinenoexcept

Create BNO08x handler with I2C interface.

Parameters
i2c_deviceBaseI2c instance (address pre-configured)
configSensor configuration (default: Bno08xConfig{})
reset_gpioOptional RSTN GPIO (active-low)
int_gpioOptional INT GPIO (active-low, data ready)
Returns
Unique pointer to Bno08xHandler

◆ CreateBno08xHandlerSpi()

std::unique_ptr< Bno08xHandler > CreateBno08xHandlerSpi ( BaseSpi & spi_device,
const Bno08xConfig & config = Bno08xConfig{},
BaseGpio * reset_gpio = nullptr,
BaseGpio * int_gpio = nullptr,
BaseGpio * wake_gpio = nullptr )
inlinenoexcept

Create BNO08x handler with SPI interface.

Parameters
spi_deviceBaseSpi instance
configSensor configuration (default: Bno08xConfig{})
reset_gpioOptional RSTN GPIO (active-low)
int_gpioOptional INT GPIO (active-low, data ready)
wake_gpioOptional WAKE GPIO (active-low, SPI mode)
Returns
Unique pointer to Bno08xHandler