Expand description
A platform agnostic Rust driver for the TDK ICM20948, based on the
embedded-hal traits.
§The Device
The device is a MEMS based 9 degree of freedom ICM The IC contains 3 axis accelerometers, gyroscopes and manometers The IC can comunicate over a SPI or I2C bus
§The Library
Contains both I2C and SPI implemntations both sharing common code
§Very basic example
this might work on a pi or something similar
extern crate icm20948;
extern crate linux_embedded_hal as hal;
use hal::spidev::{self, SpidevOptions};
use hal::{Pin, Spidev};
use hal::sysfs_gpio::Direction;
use hal::Delay;
const ICM_CS_PIN: u64 = 8;
fn main(){
let mut spi = Spidev::open("/dev/spidev0.0").unwrap();
let options = SpidevOptions::new()
.bits_per_word(8)
.max_speed_hz(20_000)
.build();
spi.configure(&options).unwrap();
let mut cs = Pin::new(ICM_CS_PIN);
cs.export().unwrap();
cs.set_direction(Direction::Out).unwrap();
let mut icm = icm20948::ICMSPI::new(
&mut spi, &mut cs)
.expect("Failed to communicate with icm module!");
icm.init(&mut spi, &mut cs, &mut Delay);
let (xa, ya, za, xg, yg, zg) =
icm_obj.scale_raw_accel_gyro(icm_obj.get_values_accel_gyro(&mut spi, &mut cs).unwrap());
//println!("Sensed, {:?}, {:?}, {:?}, {:?}, {:?}, {:?}", xa, ya, za, xg, yg, zg);
}Structs§
- ICMCommon
- This struct holds and implements the functions that are bus independent for the ICM20948
- ICMI2C
- Prototype implementation for I2C
- ICMI2C
Owned - Prototype implementation for I2C
- ICMSPI
- Pre-Prototype implementation for SPI
Enums§
- Accel
Range Options - Enum describing possible ranges of the Accelerometers
- Gyro
Range Options - Enum describing possible ranges of the Gyros
- ICMError
- Enum used to report errors when using the ICM
Constants§
- ICM20948_
CHIP_ ADR - Default ICM20948 device address
- ICM20948_
CHIP_ ADR_ ALT - Alternative ICM20948 device address