Crate bmi323

Crate bmi323 

Source
Expand description

§Bosch BMI323 IMU

crates.io Documentation

A no_std, async Rust driver for the Bosch BMI323 6-axis IMU sensor using embedded-hal-async I2C traits.

§Features

  • 🚀 Async I2C via embedded-hal-async
  • 📦 no_std compatible
  • 🎯 Type-safe configuration with strongly-typed enums and bitfields
  • 🔧 Comprehensive API for accelerometer, gyroscope, and advanced features
  • 📊 FIFO support with configurable watermarks
  • 🔔 Interrupt handling with flexible mapping
  • 🎨 Feature engine for motion detection, tap, step counting, orientation, and more
  • 📝 Optional defmt logging support

§Quick Start

use bmi323::{Bmi323, accel::AccelConfig, gyro::GyroConfig};

// Create the driver
let mut imu = Bmi323::new(i2c, delay);

// Initialize
imu.soft_reset().await?;
let chip_id = imu.get_id().await?;

// Configure accelerometer
let accel_config = AccelConfig::default();
imu.set_accel_conf(accel_config).await?;

// Read accelerometer data
let accel_data = imu.get_accel_data().await?; // Returns Vector3d<f32> in g
println!("Accel: x={}, y={}, z={}", accel_data.x, accel_data.y, accel_data.z);

// Configure gyroscope
let gyro_config = GyroConfig::default();
imu.set_gyro_conf(gyro_config).await?;

// Read gyroscope data
let gyro_data = imu.get_gyro_data().await?; // Returns Vector3d<f32> in dps

§Advanced Features

§Feature Engine

The BMI323 includes an on-chip feature engine for advanced motion detection:

// Enable the feature engine
imu.enable_feature_engine().await?;

// Configure tap detection
use bmi323::feature::tap::*;
let tap_config = TapConfig::default();
imu.set_tap_config(tap_config).await?;

// Configure step counter
use bmi323::feature::step::*;
let step_config = StepCounterConfig::default();
imu.set_step_counter_config(step_config).await?;

§FIFO

use bmi323::fifo::FifoConfig;

let fifo_config = FifoConfig {
    acc_en: true,
    gyr_en: true,
    stop_on_full: false,
    ..Default::default()
};
imu.set_fifo_config(fifo_config).await?;
imu.set_fifo_watermark(512).await?;

// Read FIFO data
let mut buffer = [0u8; 1024];
let bytes_read = imu.read_fifo_bytes(&mut buffer).await?;

§Interrupts

use bmi323::interrupt::*;

// Configure interrupt pins
let int1 = IntConfig {
    level: IntLevel::ActiveHigh,
    output: IntOutputMode::PushPull,
    enable: true,
};
imu.set_int_config(true, int1, IntConfig::default()).await?;

// Map features to interrupt pins
let int_map = IntMap {
    any_motion: IntPin::Int1,
    tap: IntPin::Int1,
    ..Default::default()
};
imu.set_int_map(int_map).await?;

§Cargo Features

  • defmt: Enable defmt logging support for debugging
  • events: Enable interrupt event processing with internal queue

§Hardware Support

This driver supports the BMI323 IMU via I2C. The BMI323 features:

  • 16-bit accelerometer with ±2g to ±16g ranges
  • 16-bit gyroscope with ±125°/s to ±2000°/s ranges
  • Programmable output data rates from 0.78 Hz to 6.4 kHz
  • 2KB FIFO buffer
  • Advanced motion features (tap, step, orientation, tilt, etc.)

§License

Licensed under either of:

at your option.

§Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

§Design Principles

  • Type-safe: Strongly-typed configuration structs with sensible defaults
  • Async-first: Built on embedded-hal-async I2C traits
  • Zero-copy: Direct register access where possible
  • Documented: Raw register fields include conversion formulas where applicable

§Module Organization

  • accel: Accelerometer configuration and data reading
  • gyro: Gyroscope configuration and data reading
  • fifo: FIFO buffer configuration and reading
  • interrupt: Interrupt pin configuration and status
  • [feature]: Feature engine for advanced motion detection
  • calib: Calibration utilities
  • selftest: Self-test functionality

§Basic Usage

let mut imu = Bmi323::new(i2c, delay);

// Initialize and verify chip
imu.soft_reset().await?;
let chip_id = imu.get_id().await?;

// Configure and read accelerometer
imu.set_accel_conf(AccelConfig::default()).await?;
let accel = imu.get_accel_data().await?;

Modules§

accel
Accelerometer configuration and data reading.
alt
any_no_motion
axis_remap
calib
fifo
FIFO buffer configuration and data reading.
flat
gyro
Gyroscope configuration and data reading.
interrupt
Interrupt configuration and status reading.
io
offset
orientation
selftest
sig_motion
step
tap
tilt

Structs§

Bmi323
BMI323 device driver instance.
FeatureDataStatus
Bit layout
FeatureEngineStatus
Bit layout
Features
Bit layout
MotionTiming
Helper for human‑readable timing used by Any‑/No‑motion.
SaturationFlags
Bit layout
XYZ
3-axis sensor data (raw 16-bit values).

Enums§

AverageNum
Number of samples to average. Reduces noise at the cost of latency and responsiveness. Applies to both data and some feature engines.
Bandwidth
Digital low‑pass bandwidth selection. The cutoff is relative to ODR.
BlockingRule
Suppress state changes when the device is in strong motion.
Error
Driver error type.
FeatureAddr
Feature memory base addresses (used with FEATURE_DATA_ADDR/TX).
FeatureEngineState
Values for FEATURE_IO1.state (bits[12:11]).
FeatureIoError
Decoded values for FEATURE_IO1.error_status (bits[3:0]).
OutputDataRate
Output data rate (ODR) for accelerometer and gyroscope.
Sensor