Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
78e43e9
fix: use PhantomData<Cell<()>> to actually enforce !Sync
snabb Apr 26, 2026
df70b07
fix: add Eq derive to DeviceState
snabb Apr 26, 2026
09fd2b9
fix: complete InterruptStatus test coverage for all decoded bits
snabb Apr 26, 2026
bc6af57
fix: add explicit discriminants to ActiveLevel and OutputMode
snabb Apr 26, 2026
0b1df83
fix: add register constants for interrupt status registers
snabb Apr 26, 2026
007b138
fix: use debug_assert! instead of assert! in read_fifo_words
snabb Apr 26, 2026
cab81ad
fix: add CI checks (fmt + clippy) for embassy sub-crate
snabb Apr 26, 2026
f2228cd
fix: add Default impl for FifoConfig
snabb Apr 26, 2026
f819d86
fix: add Default derive for FifoConfig
snabb Apr 26, 2026
ed096df
style: apply rustfmt to import formatting in driver files
snabb Apr 26, 2026
972ccae
fix: remove spurious !Sync marker from Bmi323Async
snabb May 1, 2026
dd7b1a6
fix: set range cache defaults to match BMI323 POR silicon state
snabb May 1, 2026
85f1abb
fix: replace magic numbers with named constants in enable_feature_engine
snabb May 1, 2026
57a2813
fix: add missing i3c_sync() accessor to InterruptStatus
snabb May 1, 2026
8a42b66
fix: rename FeatureStatus to ErrorStatus to match BMI323 datasheet
snabb May 1, 2026
dab9170
fix: introduce MAX_WORDS_PER_READ constant and strengthen FIFO assertion
snabb May 1, 2026
a261f2f
fix: document FIFO watermark field width and confirm mask is correct
snabb May 1, 2026
b4c2519
fix: read self-test status before sleeping in poll loop
snabb May 1, 2026
164091d
fix: add datasheet citation to soft-reset delay
snabb May 1, 2026
3f8c2b0
fix: add inter-poll delay to enable_feature_engine to prevent spuriou…
snabb May 2, 2026
7bace52
fix: detect BMI323 invalid-temperature sentinel (raw 0x8000)
snabb May 2, 2026
4923643
docs: add datasheet section references to all register constants and …
snabb May 3, 2026
15c957d
docs: add datasheet references to conversions, protocol details, and …
snabb May 3, 2026
93f7a43
refactor: unify blocking and async drivers via maybe-async
snabb May 4, 2026
b14710f
refactor: remove save/restore state from run_self_test
snabb May 4, 2026
3d6de93
fix: propagate GPIO error from wait_for_interrupt via Error::GpioError
snabb May 4, 2026
b3c7801
refactor: replace magic FEATURE_IO1 status values with named constants
snabb May 4, 2026
0659f8e
docs: add all FEATURE_IO1 error_status constants from datasheet
snabb May 4, 2026
56da279
refactor: add FIFO_CTRL_FLUSH and INTERRUPT_HOLD_MAX constants
snabb May 4, 2026
3b8a9de
fix: mask AltConfigSwitchSource fields to 4 bits before encoding
snabb May 4, 2026
f66ed71
docs: note reset_on_user_config_write interaction in set_accel/gyro_c…
snabb May 4, 2026
d97b5a5
fix: remove unused imports from lib.rs doctests
snabb May 4, 2026
bd255f5
fix: suppress dead_code warnings for reference-only feature engine st…
snabb May 4, 2026
09701f5
feat: add Default impls for MotionAxes, InterruptPinConfig, StepCount…
snabb May 4, 2026
eea0d77
refactor: merge blocking/async test variants into single source files
snabb May 4, 2026
5924ea5
Use sensor manufacturer's full name in docs
snabb May 5, 2026
31c802f
docs: document blocking and async feature flags in README
snabb May 5, 2026
b7ddcdc
feat: implement Display and core::error::Error for Error<E>
snabb May 5, 2026
a322e92
fix: add compile_error guards for mutually exclusive blocking/async f…
snabb May 5, 2026
c9569ff
feat!: make async the default feature, blocking requires --no-default…
snabb May 5, 2026
e0931ea
feat!: async default; blocking no longer needs --no-default-features
snabb May 5, 2026
5652564
fix: suppress "file present in multiple build targets" Cargo warnings
snabb May 5, 2026
779964f
ci: add --all-targets to clippy steps to cover test files
snabb May 5, 2026
881e90e
test: verify driver bookkeeping defaults match BMI323 POR (G2/Dps125)
snabb May 5, 2026
eb9c45d
fix: reset bookkeeping cache to POR defaults on soft_reset/re-init
snabb May 5, 2026
a6f7afa
docs: clarify AccelConfig/GyroConfig defaults are active presets, not…
snabb May 5, 2026
97a6828
ci: add MSRV job to validate rust-version = 1.85
snabb May 5, 2026
c01e79b
Fix build
snabb May 5, 2026
261a32d
cargo fmt
snabb May 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 44 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@ jobs:
- name: Format check
run: cargo fmt --check

- name: Clippy
run: cargo clippy --all-features -- -D warnings
- name: Clippy (async)
run: cargo clippy --all-targets --features async,defmt -- -D warnings

- name: Unit tests
run: cargo test
- name: Clippy (blocking)
run: cargo clippy --all-targets --features blocking,defmt -- -D warnings

- name: Unit tests all features
run: cargo test --all-features
- name: Tests (async)
run: cargo test --features async

- name: Generic examples
run: cargo check --examples
- name: Tests (blocking)
run: cargo test --features blocking

- name: Generic examples all features
run: cargo check --all-features --examples
- name: Examples check (async)
run: cargo check --examples --features async

- name: Examples check (blocking)
run: cargo check --examples --features blocking

- name: Package verification
run: cargo package
Expand All @@ -45,6 +48,30 @@ jobs:
working-directory: embassy-stm32g030f6-examples
run: cargo check --bins --target thumbv6m-none-eabi

- name: STM32 format check
working-directory: embassy-stm32g030f6-examples
run: cargo fmt --check

- name: STM32 clippy
working-directory: embassy-stm32g030f6-examples
run: cargo clippy --bins --target thumbv6m-none-eabi -- -D warnings

msrv:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v5

- name: Install Rust 1.85
uses: dtolnay/rust-toolchain@1.85

- name: MSRV check (async)
run: cargo check --features async

- name: MSRV check (blocking)
run: cargo check --features blocking

coverage:
runs-on: ubuntu-latest

Expand All @@ -60,8 +87,14 @@ jobs:
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov

- name: Coverage (async)
run: cargo llvm-cov --no-report --features async

- name: Coverage (blocking)
run: cargo llvm-cov --no-report --features blocking

- name: Generate coverage report
run: cargo llvm-cov --all-features --lcov --output-path lcov.info
run: cargo llvm-cov report --lcov --output-path lcov.info

- name: Upload to Codecov
uses: codecov/codecov-action@v5
Expand Down
79 changes: 76 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "bmi323-driver"
version = "0.1.0"
version = "0.2.0"
edition = "2024"
rust-version = "1.85"
license = "MIT"
description = "Generic no_std driver for the Bosch BMI323 IMU"
description = "Generic no_std driver for the Bosch Sensortec BMI323 IMU"
authors = ["Janne Snabb"]
readme = "README.md"
documentation = "https://docs.rs/bmi323-driver"
Expand All @@ -21,17 +21,90 @@ include = [
]

[package.metadata.docs.rs]
all-features = true
features = ["defmt"]
rustdoc-args = ["--cfg", "docsrs"]

[features]
# Async (embedded-hal-async) is the default when no feature is specified.
# "async" may be listed explicitly for clarity; it acts as a no-op but is used
# as a required-feature guard for async examples and tests so that they are not
# compiled in blocking mode.
# "blocking" opts into the synchronous embedded-hal API.
# Enabling both simultaneously causes a compile error.
default = []
async = []
blocking = ["maybe-async/is_sync"]
defmt = ["dep:defmt"]

[dependencies]
defmt = { version = "1.0.1", optional = true }
embedded-hal = "1.0.0"
embedded-hal-async = "1.0.0"
maybe-async = "0.2.10"

[target.'cfg(not(target_os = "none"))'.dev-dependencies]
embedded-hal-mock = { version = "0.11.1", default-features = false, features = ["eh1", "embedded-hal-async"] }

[[test]]
name = "i2c_transactions_blocking"
path = "tests/i2c_transactions_blocking.rs"
required-features = ["blocking"]

[[test]]
name = "i2c_transactions_async"
path = "tests/i2c_transactions_async.rs"
required-features = ["async"]

[[test]]
name = "spi_transactions_blocking"
path = "tests/spi_transactions_blocking.rs"
required-features = ["blocking"]

[[test]]
name = "spi_transactions_async"
path = "tests/spi_transactions_async.rs"
required-features = ["async"]

[[example]]
name = "blocking_i2c_basic"
required-features = ["blocking"]

[[example]]
name = "async_i2c_alt_config"
required-features = ["async"]

[[example]]
name = "async_i2c_flat"
required-features = ["async"]

[[example]]
name = "async_i2c_interrupt"
required-features = ["async"]

[[example]]
name = "async_i2c_no_motion"
required-features = ["async"]

[[example]]
name = "async_i2c_orientation"
required-features = ["async"]

[[example]]
name = "async_i2c_self_test"
required-features = ["async"]

[[example]]
name = "async_i2c_significant_motion"
required-features = ["async"]

[[example]]
name = "async_i2c_step_counter"
required-features = ["async"]

[[example]]
name = "async_i2c_tap"
required-features = ["async"]

[[example]]
name = "async_i2c_tilt"
required-features = ["async"]
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![license](https://img.shields.io/crates/l/bmi323-driver.svg)](https://github.com/snabb/bmi323-driver/blob/main/LICENSE)
[![rust-version](https://img.shields.io/badge/rust-1.85%2B-93450a.svg)](https://www.rust-lang.org/)

`bmi323-driver` is a `no_std` Rust driver for the Bosch BMI323 6-DoF IMU.
`bmi323-driver` is a `no_std` Rust driver for the Bosch Sensortec BMI323 6-DoF IMU.

The datasheet is available at Bosch Sensortec web site: https://www.bosch-sensortec.com/en/products/motion-sensors/imus/bmi323

Expand Down Expand Up @@ -142,7 +142,7 @@ where
{
let mut imu = Bmi323Async::new_i2c(i2c, I2C_ADDRESS_PRIMARY);
imu.init(delay).await?;
imu.enable_feature_engine().await?;
imu.enable_feature_engine(delay).await?;
imu.set_accel_config(AccelConfig {
mode: bmi323_driver::AccelMode::HighPerformance,
odr: OutputDataRate::Hz100,
Expand Down Expand Up @@ -186,6 +186,12 @@ where

## Feature flags

Async mode is the default when no feature flags are set. The `blocking` feature
opts into the synchronous `embedded-hal` API. Enabling both simultaneously
causes a compile error.

- `async`: no-op marker; async is the default behavior without `blocking`
- `blocking`: synchronous driver using `embedded-hal` traits
- `defmt`: derives `defmt::Format` for public value types

## Repository examples
Expand Down
14 changes: 13 additions & 1 deletion embassy-stm32g030f6-examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion embassy-stm32g030f6-examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2024"
publish = false

[dependencies]
bmi323-driver = { path = "..", features = ["defmt"] }
bmi323-driver = { path = "..", default-features = false, features = ["async", "defmt"] }
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7"
defmt = "1.0.1"
Expand Down
11 changes: 5 additions & 6 deletions embassy-stm32g030f6-examples/src/bin/alt_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
#![no_main]

use bmi323_driver::{
ActiveLevel, AltAccelSwitchProfile, AltConfigSwitchSource, Bmi323Async,
EventReportMode, I2C_ADDRESS_PRIMARY, InterruptChannel, InterruptPinConfig,
InterruptRoute, InterruptSource, MotionAxes, NoMotionConfig, OutputDataRate,
OutputMode, ReferenceUpdate,
ActiveLevel, AltAccelSwitchProfile, AltConfigSwitchSource, Bmi323, EventReportMode,
I2C_ADDRESS_PRIMARY, InterruptChannel, InterruptPinConfig, InterruptRoute, InterruptSource,
MotionAxes, NoMotionConfig, OutputDataRate, OutputMode, ReferenceUpdate,
};
use defmt::{error, info};
use defmt_rtt as _;
Expand Down Expand Up @@ -43,7 +42,7 @@ async fn main(_spawner: Spawner) {

let mut int1 = ExtiInput::new(p.PB3, p.EXTI3, Pull::Down, Irqs);
let mut delay = Delay;
let mut imu = Bmi323Async::new_i2c(i2c, I2C_ADDRESS_PRIMARY);
let mut imu = Bmi323::new_i2c(i2c, I2C_ADDRESS_PRIMARY);

if let Err(err) = imu.init(&mut delay).await {
error!("BMI323 init failed: {:?}", err);
Expand All @@ -52,7 +51,7 @@ async fn main(_spawner: Spawner) {
}
}

if let Err(err) = imu.enable_feature_engine().await {
if let Err(err) = imu.enable_feature_engine(&mut delay).await {
error!("BMI323 feature engine enable failed: {:?}", err);
loop {
cortex_m::asm::wfi();
Expand Down
10 changes: 5 additions & 5 deletions embassy-stm32g030f6-examples/src/bin/flat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#![no_main]

use bmi323_driver::{
AccelConfig, ActiveLevel, Bmi323Async, FeatureBlockingMode, FlatConfig,
I2C_ADDRESS_PRIMARY, InterruptChannel, InterruptPinConfig, InterruptRoute,
InterruptSource, OutputDataRate, OutputMode,
AccelConfig, ActiveLevel, Bmi323, FeatureBlockingMode, FlatConfig, I2C_ADDRESS_PRIMARY,
InterruptChannel, InterruptPinConfig, InterruptRoute, InterruptSource, OutputDataRate,
OutputMode,
};
use defmt::{error, info};
use defmt_rtt as _;
Expand Down Expand Up @@ -42,7 +42,7 @@ async fn main(_spawner: Spawner) {

let mut int1 = ExtiInput::new(p.PB3, p.EXTI3, Pull::Down, Irqs);
let mut delay = Delay;
let mut imu = Bmi323Async::new_i2c(i2c, I2C_ADDRESS_PRIMARY);
let mut imu = Bmi323::new_i2c(i2c, I2C_ADDRESS_PRIMARY);

if let Err(err) = imu.init(&mut delay).await {
error!("BMI323 init failed: {:?}", err);
Expand All @@ -51,7 +51,7 @@ async fn main(_spawner: Spawner) {
}
}

if let Err(err) = imu.enable_feature_engine().await {
if let Err(err) = imu.enable_feature_engine(&mut delay).await {
error!("BMI323 feature engine enable failed: {:?}", err);
loop {
cortex_m::asm::wfi();
Expand Down
10 changes: 5 additions & 5 deletions embassy-stm32g030f6-examples/src/bin/motion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#![no_main]

use bmi323_driver::{
AccelConfig, AccelMode, ActiveLevel, AnyMotionConfig, Bmi323Async, EventReportMode,
I2C_ADDRESS_PRIMARY, InterruptChannel, InterruptPinConfig, InterruptRoute,
InterruptSource, MotionAxes, OutputDataRate, OutputMode, ReferenceUpdate,
AccelConfig, AccelMode, ActiveLevel, AnyMotionConfig, Bmi323, EventReportMode,
I2C_ADDRESS_PRIMARY, InterruptChannel, InterruptPinConfig, InterruptRoute, InterruptSource,
MotionAxes, OutputDataRate, OutputMode, ReferenceUpdate,
};
use defmt::{error, info};
use defmt_rtt as _;
Expand Down Expand Up @@ -43,7 +43,7 @@ async fn main(_spawner: Spawner) {
let mut int1 = ExtiInput::new(p.PB3, p.EXTI3, Pull::Down, Irqs);
let mut delay = Delay;

let mut imu = Bmi323Async::new_i2c(i2c, I2C_ADDRESS_PRIMARY);
let mut imu = Bmi323::new_i2c(i2c, I2C_ADDRESS_PRIMARY);

if let Err(err) = imu.init(&mut delay).await {
error!("BMI323 init failed: {:?}", err);
Expand All @@ -52,7 +52,7 @@ async fn main(_spawner: Spawner) {
}
}

if let Err(err) = imu.enable_feature_engine().await {
if let Err(err) = imu.enable_feature_engine(&mut delay).await {
error!("BMI323 feature engine enable failed: {:?}", err);
loop {
cortex_m::asm::wfi();
Expand Down
11 changes: 5 additions & 6 deletions embassy-stm32g030f6-examples/src/bin/no_motion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
#![no_main]

use bmi323_driver::{
AccelConfig, ActiveLevel, AverageSamples, Bmi323Async, EventReportMode,
I2C_ADDRESS_PRIMARY, InterruptChannel, InterruptPinConfig, InterruptRoute,
InterruptSource, MotionAxes, NoMotionConfig, OutputDataRate, OutputMode,
ReferenceUpdate,
AccelConfig, ActiveLevel, AverageSamples, Bmi323, EventReportMode, I2C_ADDRESS_PRIMARY,
InterruptChannel, InterruptPinConfig, InterruptRoute, InterruptSource, MotionAxes,
NoMotionConfig, OutputDataRate, OutputMode, ReferenceUpdate,
};
use defmt::{error, info};
use defmt_rtt as _;
Expand Down Expand Up @@ -44,7 +43,7 @@ async fn main(_spawner: Spawner) {
let mut int1 = ExtiInput::new(p.PB3, p.EXTI3, Pull::Down, Irqs);
let mut delay = Delay;

let mut imu = Bmi323Async::new_i2c(i2c, I2C_ADDRESS_PRIMARY);
let mut imu = Bmi323::new_i2c(i2c, I2C_ADDRESS_PRIMARY);

if let Err(err) = imu.init(&mut delay).await {
error!("BMI323 init failed: {:?}", err);
Expand All @@ -53,7 +52,7 @@ async fn main(_spawner: Spawner) {
}
}

if let Err(err) = imu.enable_feature_engine().await {
if let Err(err) = imu.enable_feature_engine(&mut delay).await {
error!("BMI323 feature engine enable failed: {:?}", err);
loop {
cortex_m::asm::wfi();
Expand Down
Loading
Loading