bmi323-driver
bmi323-driver is a no_std Rust driver for the Bosch BMI323 6-DoF IMU.
It is designed to be transport-agnostic, small, and usable both in generic embedded-hal applications and in async Embassy-based firmware.
init() performs a soft reset, so the driver starts from a known sensor state.
After init(), configure the accelerometer and gyroscope explicitly before
depending on sample reads. The driver does not promise application-ready accel
or gyro settings immediately after initialization.
Features
embedded-hal1.0 blocking API supportembedded-hal-async1.0 async API support- I2C and SPI transports
- accelerometer and gyroscope configuration
- burst accel/gyro reads
- FIFO configuration and reads
- interrupt pin electrical configuration and interrupt routing
- feature-engine enable sequence
- any-motion and no-motion configuration
- tap and orientation/flat configuration
- significant-motion and tilt configuration
- step detector and step counter support
- alternate accel/gyro configuration switching
- built-in accelerometer and gyroscope self-test
Non-goals
This crate does not own the host MCU interrupt GPIO. The BMI323 can route
interrupts to INT1 and INT2, but waiting on the external pin is left to the
application or framework:
- blocking users can poll or handle the MCU interrupt themselves, then read the BMI323 interrupt status register
- async users can wait on a GPIO implementing
embedded_hal_async::digital::Wait, then read or consume the BMI323 interrupt status
This keeps the crate portable across HALs and RTOS/executor choices.
Missing features and current limitations
This crate is usable today, but it does not yet cover the full BMI323 feature set. In particular:
- only I2C and SPI transports are implemented; there is no I3C transport API
- FIFO support is currently low-level:
- configuration, fill level reads, flush, and raw word reads are supported
- higher-level FIFO frame parsing and convenience helpers are not yet provided
- there are no public helpers yet for calibration, offset compensation, or similar factory/service operations
- the crate has mocked transaction tests for blocking and async I2C/SPI transports, but it does not yet have broad transaction coverage for every feature combination
Quick start
Explicit sensor configuration after init is expected. The AccelConfig and
GyroConfig defaults are:
AccelConfig::default():Normal,Avg1,OdrOver2,G8,Hz50GyroConfig::default():Normal,Avg1,OdrOver2,Dps2000,Hz50
These are convenience config values only. They are not applied to the chip
unless you call set_accel_config and set_gyro_config.
For AnyMotionConfig and NoMotionConfig, the threshold, hysteresis,
duration, wait-time, and interrupt-hold fields are now documented with their
BMI323 scaling, and helper conversion functions are provided so you do not need
to work in raw field encodings directly.
Blocking I2C
use ;
use DelayNs;
use I2c;
Async interrupt-driven usage
use ;
use DelayNs;
use Wait;
use I2c;
async
Feature flags
defmt: derivesdefmt::Formatfor public value types
Repository examples
examples/blocking_i2c_basic.rsBlocking I2C configuration and sample reads.examples/async_i2c_interrupt.rsGeneric async interrupt-driven setup usingembedded-hal-async.examples/async_i2c_no_motion.rsGeneric async no-motion detection setup usingembedded-hal-async.examples/async_i2c_tap.rsGeneric async tap-detection setup usingembedded-hal-async.examples/async_i2c_orientation.rsGeneric async orientation-detection setup usingembedded-hal-async.examples/async_i2c_flat.rsGeneric async flat-detection setup usingembedded-hal-async.examples/async_i2c_significant_motion.rsGeneric async significant-motion detection setup usingembedded-hal-async.examples/async_i2c_tilt.rsGeneric async tilt-detection setup usingembedded-hal-async.examples/async_i2c_step_counter.rsGeneric async step-detector and step-counter setup usingembedded-hal-async.examples/async_i2c_alt_config.rsGeneric async alternate accel-configuration switching using any-motion and no-motion.examples/async_i2c_self_test.rsGeneric async built-in accelerometer and gyroscope self-test.
Hardware-specific STM32G030F6 Embassy examples live in the separate sub-crate embassy-stm32g030f6-examples.
License
MIT. See LICENSE.