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:
| Report | Constant | Method | Units |
|---|---|---|---|
| Accelerometer | SENSOR_REPORTID_ACCELEROMETER | accelerometer() | m/s² |
| Gyroscope | SENSOR_REPORTID_GYROSCOPE | gyro() | rad/s |
| Magnetometer | SENSOR_REPORTID_MAGNETIC_FIELD | mag_field() | µT |
| Rotation Vector | SENSOR_REPORTID_ROTATION_VECTOR | rotation_quaternion() | quaternion |
| Game Rotation | SENSOR_REPORTID_ROTATION_VECTOR_GAME | game_rotation_quaternion() | quaternion |
| Geomagnetic Rotation | SENSOR_REPORTID_ROTATION_VECTOR_GEOMAGNETIC | geomag_rotation_quaternion() | quaternion |
| Linear Acceleration | SENSOR_REPORTID_LINEAR_ACCEL | linear_accel() | m/s² |
| Gravity | SENSOR_REPORTID_GRAVITY | gravity() | m/s² |
§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