Crate bno08x_rs

Crate bno08x_rs 

Source
Expand description

§BNO08x IMU Driver

A Rust userspace driver for the BNO08x family of 9-axis IMU sensors from Bosch/Hillcrest Labs.

§Overview

The BNO08x is a System-in-Package (SiP) that integrates:

  • Triaxial 14-bit accelerometer
  • Triaxial 16-bit gyroscope
  • Triaxial geomagnetic sensor
  • 32-bit microcontroller running sensor fusion firmware

This crate provides a safe Rust interface for communicating with the sensor over SPI, handling the SHTP (Sensor Hub Transport Protocol) and providing high-level access to fused and raw sensor data.

§Features

  • Sensor Fusion: Rotation vectors (absolute, game, geomagnetic)
  • Raw Sensors: Accelerometer, gyroscope, magnetometer
  • Derived Data: Linear acceleration, gravity vector
  • Configurable Rates: 1 Hz to 1 kHz update rates
  • GPIO Integration: Device tree symbolic name support for Linux
  • Callbacks: Event-driven sensor data handling

§Quick Start

use bno08x_rs::{BNO08x, SENSOR_REPORTID_ACCELEROMETER};

fn main() -> std::io::Result<()> {
    // Create driver using GPIO symbolic names
    let mut imu = BNO08x::new_spi_from_symbol(
        "/dev/spidev1.0", // SPI device
        "IMU_INT",        // Interrupt GPIO name
        "IMU_RST",        // Reset GPIO name
    )?;

    // Initialize and configure
    imu.init()?;
    imu.enable_report(SENSOR_REPORTID_ACCELEROMETER, 100)?; // 10 Hz

    // Main loop
    loop {
        imu.handle_all_messages(100);
        let accel = imu.accelerometer()?;
        println!("Accel: {:?}", accel);
    }
}

§Sensor Reports

Enable specific sensor reports using their report ID constants:

§Hardware Requirements

  • Linux with SPI (spidev) and GPIO (gpiod) support
  • BNO08x sensor connected via SPI
  • GPIO for interrupt (HINTN) and reset (RSTN) signals

§More Information

Re-exports§

pub use constants::SENSOR_REPORTID_ACCELEROMETER;
pub use constants::SENSOR_REPORTID_GRAVITY;
pub use constants::SENSOR_REPORTID_GYROSCOPE;
pub use constants::SENSOR_REPORTID_GYROSCOPE_UNCALIB;
pub use constants::SENSOR_REPORTID_LINEAR_ACCEL;
pub use constants::SENSOR_REPORTID_MAGNETIC_FIELD;
pub use constants::SENSOR_REPORTID_ROTATION_VECTOR;
pub use constants::SENSOR_REPORTID_ROTATION_VECTOR_GAME;
pub use constants::SENSOR_REPORTID_ROTATION_VECTOR_GEOMAGNETIC;
pub use driver::BNO08x;
pub use driver::DriverError;
pub use reports::SensorData;

Modules§

constants
Constants for the BNO08x sensor driver.
driver
BNO08x IMU driver implementation.
frs
Flash Record System (FRS) operations for the BNO08x driver.
interface
Communication interface abstractions for the BNO08x driver.
reports
Sensor report handling for the BNO08x driver.

Enums§

Error
Low-level errors from the communication interface