Expand description
High-level LIS2DE12 accelerometer driver with synchronous and asynchronous FIFO helpers.
This driver supports both I2C and SPI communication interfaces, with blocking and async modes.
§Examples
§Blocking I2C
use lis2de12::{Lis2de12, SlaveAddr};
// Create driver with default configuration
let mut sensor = Lis2de12::new_i2c(i2c, SlaveAddr::default())?;
// Read acceleration in g (floating point)
let accel = sensor.read_g()?;§Blocking SPI
use lis2de12::Lis2de12;
// Create driver with SPI interface
let mut sensor = Lis2de12::new_spi(spi)?;
// Read acceleration in milli-g (integer)
let accel_mg = sensor.read_mg()?;§Async I2C
use lis2de12::{Lis2de12Async, SlaveAddr};
// Create async driver with I2C
let mut sensor = Lis2de12Async::new_i2c(i2c, SlaveAddr::default()).await?;
// Read acceleration asynchronously
let accel = sensor.read_g().await?;§Async SPI
use lis2de12::Lis2de12Async;
// Create async driver with SPI
let mut sensor = Lis2de12Async::new_spi(spi).await?;
// Read acceleration asynchronously
let accel = sensor.read_g().await?;§Custom Configuration
use lis2de12::{Lis2de12, Lis2de12Config, SlaveAddr, Odr, Fs};
let config = Lis2de12Config {
odr: Odr::Hz400, // 400 Hz output data rate
scale: Fs::G8, // ±8g full scale
..Default::default()
};
let mut sensor = Lis2de12::new_i2c_with_config(i2c, SlaveAddr::default(), config)?;§Temperature Sensor
use lis2de12::{Lis2de12, Lis2de12Config, SlaveAddr};
// Enable temperature sensor in configuration
let config = Lis2de12Config {
temperature_enable: true,
..Default::default()
};
let mut sensor = Lis2de12::new_i2c_with_config(i2c, SlaveAddr::default(), config)?;
// Or enable it after initialization
sensor.set_temperature_sensor(true)?;
// Read temperature change in °C (relative to power-on reference)
// Positive = warmer, negative = cooler
let temp_delta = sensor.read_temperature()?;
// Or read raw 16-bit left-justified value
let temp_raw = sensor.read_temperature_raw()?;§SPI Mode
The LIS2DE12 requires SPI Mode 0 or Mode 3 (CPOL=0, CPHA=0 or CPOL=1, CPHA=1).
The driver uses the embedded-hal SpiDevice trait which handles chip select automatically.
Modules§
- field_
sets - Module containing the generated fieldsets of the registers and commands
Structs§
- Axes
Enable - Axis enable mask.
- Device
Interface - Blocking I²C interface wrapper.
- Fifo
Config - FIFO configuration options.
- Fifo
Status - Parsed FIFO status register snapshot.
- Lis2de12
- Blocking LIS2DE12 driver.
- Lis2de12
Config - High-level configuration applied during initialisation or runtime updates.
- Lis2de12
Device - Root block of the Lis2de12Device driver
- SpiInterface
- Blocking SPI interface wrapper.
Enums§
- Fifo
Mode - High-level FIFO operating modes mirroring the
FMregister field. - Fm
- Fs
- Odr
- Operating
Mode - Sensor operating mode controlling resolution and power consumption.
- Slave
Addr - Available LIS2DE12 I²C slave addresses (controlled by the SA0 pin).
- St
- TempEn
Constants§
- FIFO_
CAPACITY - Maximum FIFO depth in frames.
- FIFO_
FRAME_ BYTES - Number of bytes per FIFO frame (X, Y, Z 16-bit samples).
- FIFO_
WATERMARK_ MAX - Highest programmable FIFO watermark level.
Type Aliases§
- Fifo
Frame - FIFO frame buffer alias.
- Lis2de12
I2c - Type alias for I2C-based blocking driver.
- Lis2de12
Spi - Type alias for SPI-based blocking driver.