Crate stk8ba58

source ·
Expand description

Driver for the Sensortek STK8BA58 3-axis MEMS Accelerometer

Implements the Accelerometer trait from the accelerometer crate.

§How to use

§Reading the acceleration:

use stk8ba58::Stk8ba58;
use accelerometer::{vector::I16x3, Accelerometer};

// i2c is an I2C bus you have previously initialized with your HAL
let mut accelerometer = Stk8ba58::new(i2c);

let acceleration = accelerometer.accel_norm().unwrap();
let x_component = acceleration.x;
let y_component = acceleration.y;
let z_component = acceleration.z;

§Setting register flags:

use stk8ba58::{
    registers::{Write, INTEN1},
    Stk8ba58,
};

// i2c is an I2C bus you have previously initialized with your HAL
let mut accelerometer = Stk8ba58::new(i2c);

// Enable slope interrupt for the X and Y axis.
let flags = INTEN1::SLP_EN_X | INTEN1::SLP_EN_Y;
accelerometer.set_flags(flags).unwrap();

§Reading set values:

use stk8ba58::{
    registers::{Read, SleepDuration},
    Stk8ba58,
};

// i2c is an I2C bus you have previously initialized with your HAL
let mut accelerometer = Stk8ba58::new(i2c);

let sleep_duration = accelerometer.sleep_duration().unwrap();
if sleep_duration == SleepDuration::Ms10 {
    // Accelerometer is configured to have a 10ms sleep phase.
}

Modules§

Structs§

  • Software representation of the STK8BA58.