Home

Awesome

bma400-rs

A platform-agnostic Rust driver for the BMA400 accelerometer implemented using embedded-hal traits

Status

Basic Usage

I²C - cargo add bma400 --features=i2c-default

// Import an embedded hal implementation
use linux_embedded_hal::I2cdev; // replace as appropriate w/ hal crate for your MCU
use bma400::{
    BMA400,
    PowerMode,
    Scale,
};
// i2c implements embedded-hal i2c::WriteRead and i2c::Write
let mut accelerometer = BMA400::new_i2c(i2c).unwrap();

SPI - cargo add bma400 --features=spi

// Import an embedded hal implementation
use linux_embedded_hal::{
 Spidev, 
 Pin
}; // replace as appropriate w/ hal crate for your MCU
use bma400::{
    BMA400,
    PowerMode,
    Scale,
};
// spi implements embedded-hal spi::Transfer and spi::Write
// csb_pin implements embedded-hal digital::v2::OutputPin
let mut accelerometer = BMA400::new_spi(spi, csb_pin).unwrap();

From here it's the same API for both:

// The accelerometer is in sleep mode at power on
// Let's wake it up and set the scale to 2g
accelerometer
    .config_accel()
    .with_power_mode(PowerMode::Normal)
    .with_scale(Scale::Range2G)
    .write().unwrap();
// Read a single measurment
if let Ok(measurement) = accelerometer.get_data() {
    assert_eq!(30, measurement.x);
    assert_eq!(16, measurement.y);
    assert_eq!(988, measurement.z);
}

For a full example using the tap interrupt mapped to a GPIO pin on the nrf52833, see examples/.

About the Sensor

(from the manufacturer)

Basic Description

12 bit, digital, triaxial acceleration sensor with smart on-chip motion and position-triggered interrupt features.

Key features

Typical applications

License

Licensed under your choice of either:

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 licensed as above, without any additional terms or conditions.