10 releases

new 0.3.2 Dec 3, 2024
0.3.1 Nov 24, 2024
0.2.4 Jul 27, 2024
0.1.1 Jul 18, 2024

#178 in Hardware support

Download history 10/week @ 2024-09-13 12/week @ 2024-09-20 11/week @ 2024-09-27 2/week @ 2024-10-04 1/week @ 2024-10-11 1/week @ 2024-11-15 243/week @ 2024-11-22 140/week @ 2024-11-29

384 downloads per month

MIT/Apache

86KB
1K SLoC

icm426xx - ICM-426xx 6-axis motion sensor driver in Rust

crates.io docs.rs

This is a platform agnostic Rust driver for the ICM-426xx 6-axis motion sensor using the embedded-hal traits.

Currently supported devices:

  • ICM-42688-P

We support both the I2C and SPI interface, but currently only the SPI interface is tested. PRs are welcome!

Similarly, we support both the async and blocking interface, but currently only the async interface is tested.

Only the FIFO-based, 20-bit data mode is supported. Please open an issue if you need support for other modes.

Usage

use async_std::prelude::*; // Just for the runtime
use embedded_hal_mock::eh1::spi::{Mock as SpiMock, Transaction as SpiTransaction};
use embedded_hal_mock::eh1::digital::Mock as PinMock;
use embedded_hal_mock::eh1::digital::{State as PinState, Transaction as PinTransaction};
use embedded_hal_mock::eh1::delay::NoopDelay as Delay;
#[async_std::main]
async fn main() {
    let spi = SpiMock::new(&[]);
    let mut pin = PinMock::new(&[PinTransaction::set(PinState::High)]);
    let spidev =
        embedded_hal_bus::spi::ExclusiveDevice::new_no_delay(spi, pin.clone()).unwrap();

    let mut icm = icm426xx::ICM42688::new(spidev);
    let mut icm = icm.initialize(Delay).await.unwrap();
    let mut bank = icm.ll().bank::<{ icm426xx::register_bank::BANK0 }>();

    // print WHO_AM_I register
    let who_am_i = bank.who_am_i().async_read().await;
    loop {
        let fifo_count = icm.read_fifo_count().await;
        let mut fifo_buffer = [0u32; 128];
        let num_read = icm.read_fifo(&mut fifo_buffer).await.unwrap();
    }
}

CHANGELOG

  • 0.3.2: Fixed the initialization sequence to match the datasheet.

LICENSE

MIT OR Apache-2.0

Dependencies

~1.2–1.8MB
~35K SLoC