HF-BNO08x  0.1.0-dev
Loading...
Searching...
No Matches
Esp32Bno08xI2cBus Class Reference

ESP32 implementation of bno08x::CommInterface using ESP-IDF I2C master driver. More...

#include <esp32_bno08x_bus.hpp>

Inheritance diagram for Esp32Bno08xI2cBus:
[legend]
Collaboration diagram for Esp32Bno08xI2cBus:
[legend]

Classes

struct  I2CConfig
 I2C bus and device configuration structure. More...
 

Public Member Functions

 Esp32Bno08xI2cBus ()
 Constructor with default configuration.
 
 Esp32Bno08xI2cBus (const I2CConfig &config)
 Constructor with custom I2C configuration.
 
 ~Esp32Bno08xI2cBus ()
 Destructor - cleans up I2C resources.
 
BNO085Interface GetInterfaceType () noexcept
 Identify this transport as I2C (required by CommInterface).
 
bool Open () noexcept
 Open the I2C bus and initialize communication (required by CommInterface)
 
void Close () noexcept
 Close the I2C bus and release resources (required by CommInterface)
 
int Write (const uint8_t *data, uint32_t length) noexcept
 Write raw data to the BNO08x sensor (required by CommInterface)
 
int Read (uint8_t *data, uint32_t length) noexcept
 Read raw data from the BNO08x sensor (required by CommInterface)
 
bool Probe () noexcept
 Probe the I2C device to verify it's responding.
 
bool DataAvailable () noexcept
 Check if new data is available (required by CommInterface)
 
void Delay (uint32_t ms) noexcept
 Delay execution for specified time (required by CommInterface)
 
uint32_t GetTimeUs () noexcept
 Get current time in microseconds (required by CommInterface)
 
void GpioSet (bno08x::CtrlPin pin, bno08x::GpioSignal signal) noexcept
 Set a control pin to the specified signal state (required by CommInterface)
 
bool Init () noexcept
 Initialize the I2C bus, GPIO, and device handle.
 
void Deinit () noexcept
 Deinitialize the I2C bus and release all resources.
 
const I2CConfiggetConfig () const noexcept
 Get the I2C configuration.
 
bool isInitialized () const noexcept
 Check if the bus is initialized.
 
void HardwareReset (uint32_t lowMs=2, uint32_t bootDelayMs=200) noexcept
 Perform hardware reset pulse on the BNO08x.
 
- Public Member Functions inherited from bno08x::CommInterface< Esp32Bno08xI2cBus >
BNO085Interface GetInterfaceType () noexcept
 Report the transport type this implementation provides.
 
bool Open () noexcept
 Open and initialise the communication bus.
 
void Close () noexcept
 Close the communication bus and release resources.
 
int Write (const uint8_t *data, uint32_t length) noexcept
 Write raw bytes to the sensor.
 
int Read (uint8_t *data, uint32_t length) noexcept
 Read raw bytes from the sensor.
 
bool DataAvailable () noexcept
 Check whether the sensor has data ready.
 
void Delay (uint32_t ms) noexcept
 Block for a specified duration.
 
uint32_t GetTimeUs () noexcept
 Return the current monotonic time in microseconds.
 
void GpioSet (CtrlPin pin, GpioSignal signal) noexcept
 Set a control pin to the specified signal state.
 
void GpioSetActive (CtrlPin pin) noexcept
 Assert a control pin (set to ACTIVE).
 
void GpioSetInactive (CtrlPin pin) noexcept
 Deassert a control pin (set to INACTIVE).
 

Additional Inherited Members

- Protected Member Functions inherited from bno08x::CommInterface< Esp32Bno08xI2cBus >
 CommInterface ()=default
 Protected constructor – prevents direct instantiation.
 
 CommInterface (const CommInterface &)=delete
 Non-copyable.
 
 CommInterface (CommInterface &&) noexcept=default
 Movable.
 
 ~CommInterface ()=default
 Protected destructor – prevent polymorphic deletion through base.
 
CommInterfaceoperator= (const CommInterface &)=delete
 Non-copyable.
 
CommInterfaceoperator= (CommInterface &&) noexcept=default
 Movable.
 

Detailed Description

ESP32 implementation of bno08x::CommInterface using ESP-IDF I2C master driver.

This class mirrors the proven Esp32Pca9685Bus / Esp32Pcal9555Bus implementations for consistent I2C communication behavior across HardFOC drivers. The BNO08x uses the SH-2 packet protocol over I2C (raw byte transfers, no register addressing), so the interface methods differ from the register-addressed I2cInterface, but the underlying bus management is identical.

Key improvements over the previous implementation:

  • Device handle caching: avoids add_device/rm_device per transaction
  • Header-only: consistent with other HardFOC ESP32 bus implementations
  • Proper resource cleanup via Init()/Deinit() pattern
  • Factory function for convenient instantiation

Constructor & Destructor Documentation

◆ Esp32Bno08xI2cBus() [1/2]

Esp32Bno08xI2cBus::Esp32Bno08xI2cBus ( )
inline

Constructor with default configuration.

◆ Esp32Bno08xI2cBus() [2/2]

Esp32Bno08xI2cBus::Esp32Bno08xI2cBus ( const I2CConfig & config)
inlineexplicit

Constructor with custom I2C configuration.

Parameters
configI2C bus and device configuration

◆ ~Esp32Bno08xI2cBus()

Esp32Bno08xI2cBus::~Esp32Bno08xI2cBus ( )
inline

Destructor - cleans up I2C resources.

Member Function Documentation

◆ Close()

void Esp32Bno08xI2cBus::Close ( )
inlinenoexcept

Close the I2C bus and release resources (required by CommInterface)

◆ DataAvailable()

bool Esp32Bno08xI2cBus::DataAvailable ( )
inlinenoexcept

Check if new data is available (required by CommInterface)

When an interrupt pin is configured, checks its level (active low). Without an interrupt pin, always returns true (polling mode).

Returns
true if data is available

◆ Deinit()

void Esp32Bno08xI2cBus::Deinit ( )
inlinenoexcept

Deinitialize the I2C bus and release all resources.

◆ Delay()

void Esp32Bno08xI2cBus::Delay ( uint32_t ms)
inlinenoexcept

Delay execution for specified time (required by CommInterface)

Parameters
msDelay duration in milliseconds

◆ getConfig()

const I2CConfig & Esp32Bno08xI2cBus::getConfig ( ) const
inlinenoexcept

Get the I2C configuration.

Returns
Reference to the I2C configuration

◆ GetInterfaceType()

BNO085Interface Esp32Bno08xI2cBus::GetInterfaceType ( )
inlinenoexcept

Identify this transport as I2C (required by CommInterface).

◆ GetTimeUs()

uint32_t Esp32Bno08xI2cBus::GetTimeUs ( )
inlinenoexcept

Get current time in microseconds (required by CommInterface)

Returns
Current monotonic time in microseconds

◆ GpioSet()

void Esp32Bno08xI2cBus::GpioSet ( bno08x::CtrlPin pin,
bno08x::GpioSignal signal )
inlinenoexcept

Set a control pin to the specified signal state (required by CommInterface)

Maps GpioSignal to physical level based on pin polarity:

  • RSTN: active-low (ACTIVE → GPIO 0, INACTIVE → GPIO 1)
  • BOOTN/WAKE/PS0/PS1: not wired in this I2C implementation (no-op)
Parameters
pinWhich control pin to drive
signalACTIVE to assert, INACTIVE to deassert

◆ HardwareReset()

void Esp32Bno08xI2cBus::HardwareReset ( uint32_t lowMs = 2,
uint32_t bootDelayMs = 200 )
inlinenoexcept

Perform hardware reset pulse on the BNO08x.

Asserts reset (drives RSTN low) for the specified duration, then releases it. This should be called before attempting to communicate with the device.

Parameters
lowMsDuration to hold reset low in milliseconds (default 2ms)
bootDelayMsDelay after releasing reset to allow sensor boot (default 200ms)

◆ Init()

bool Esp32Bno08xI2cBus::Init ( )
inlinenoexcept

Initialize the I2C bus, GPIO, and device handle.

Performs full initialization: GPIO pins, I2C master bus, and cached device handle creation. Returns true immediately on subsequent calls if already initialized.

Returns
true if successful, false otherwise

◆ isInitialized()

bool Esp32Bno08xI2cBus::isInitialized ( ) const
inlinenoexcept

Check if the bus is initialized.

Returns
true if initialized, false otherwise

◆ Open()

bool Esp32Bno08xI2cBus::Open ( )
inlinenoexcept

Open the I2C bus and initialize communication (required by CommInterface)

Initializes the I2C master bus, GPIO pins (interrupt/reset), and creates a cached device handle for the configured BNO08x address. Subsequent calls return true immediately if already initialized.

Returns
true if successful, false otherwise

◆ Probe()

bool Esp32Bno08xI2cBus::Probe ( )
inlinenoexcept

Probe the I2C device to verify it's responding.

Performs a simple I2C read to check if the device acknowledges. For BNO08x using SHTP protocol:

  • ACK on address = device present
  • Clock stretching (timeout) = device present but no data (OK)
  • NAK = device not present or not responding
Returns
true if device ACKs (responds), false if NAK

◆ Read()

int Esp32Bno08xI2cBus::Read ( uint8_t * data,
uint32_t length )
inlinenoexcept

Read raw data from the BNO08x sensor (required by CommInterface)

Receives raw bytes over I2C. The BNO08x SH-2 protocol does not use register addressing — all data is received as raw byte streams.

When an interrupt pin is configured, this function checks it first to avoid unnecessary I2C transactions. If the interrupt pin indicates no data is available (pin is high), it returns 0 immediately.

Note: ESP-IDF's i2c_master_receive() automatically handles clock stretching, which is required by the BNO08x datasheet (the sensor can hold SCL low when it needs more time to prepare data).

Parameters
dataPointer to receive buffer
lengthNumber of bytes to read
Returns
Number of bytes read, 0 if no data, or negative on error

◆ Write()

int Esp32Bno08xI2cBus::Write ( const uint8_t * data,
uint32_t length )
inlinenoexcept

Write raw data to the BNO08x sensor (required by CommInterface)

Transmits raw bytes over I2C. The BNO08x SH-2 protocol does not use register addressing — all data is sent as raw byte streams.

Parameters
dataPointer to data buffer
lengthNumber of bytes to write
Returns
Number of bytes written, or negative on error

The documentation for this class was generated from the following file: