lis2de12
Platform-agnostic Rust driver for the ST LIS2DE12 ultra-low-power 3-axis accelerometer. The crate targets no_std environments, generates its register API at build time from a YAML manifest, and supports both blocking and asynchronous I²C and SPI transports.
Features
- I²C and SPI support - Use either interface with the same high-level API
- High-level blocking driver implementing
accelerometer::RawAccelerometer - Optional async driver (
Lis2de12Async) for both I²C and SPI - Auto-generated register-level API via
device-driver no_stdcompatible with optionaldefmtlogging integration
Getting Started
Add the crate to your Cargo.toml:
[]
= "0.1.2"
= "1.0"
# Optional features:
# lis2de12 = { version = "0.1.2", features = ["async"] }
# lis2de12 = { version = "0.1.2", features = ["defmt-03"] }
Blocking I²C usage
use I2c;
use ;
Blocking SPI usage
use SpiDevice;
use Lis2de12;
Note: The LIS2DE12 requires SPI Mode 0 or Mode 3 (CPOL=0, CPHA=0 or CPOL=1, CPHA=1). The driver uses the SpiDevice trait which handles chip select automatically.
Configuring the sensor
Use Lis2de12Config to bring the device out of power-down with your preferred output data rate, operating mode, scale, axis enables, and temperature sensing:
use I2c;
use ;
Asynchronous usage (Embassy, RTIC, etc.)
Enable the async feature and depend on embedded-hal-async:
use I2c;
use ;
async
Reading scaled samples
Both blocking and async drivers provide read_raw, read_mg, and read_g helpers to obtain measurements in the format that best suits your application:
use I2c;
use ;
The async variant exposes the same API surface, returning futures for each method.
FIFO configuration and burst reads
Configure the hardware FIFO to collect XYZ frames and drain them in bursts when the watermark is reached:
use I2c;
use ;
Async users get identical functionality via Lis2de12Async::read_fifo_frame, read_fifo_frames, and drain_fifo.
Register-level access
For advanced configuration you can interact with the generated register API directly:
use ;
Feature flags
| Feature | Default | Description |
|---|---|---|
async |
✗ | Enables the async driver (pulls in embedded-hal-async) |
defmt-03 |
✗ | Enables defmt logging support compatible with device-driver |
Build-time code generation
During cargo build, the build.rs script reads src/lis2de12.yaml, generates the register accessor API, and writes it into $OUT_DIR. End users do not need to run any manual code-generation steps.
Development
# Suggested commands
CI workflows verify formatting, lints, and no_std builds.
License
Licensed under either of
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the project by you shall be dual licensed as above (MIT OR Apache-2.0), without any additional terms or conditions.
Links
- 📦 Crate: https://crates.io/crates/lis2de12
- 📚 Docs: https://docs.rs/lis2de12
- 🗺️ Repository: https://github.com/leftger/lis2de12