iis2dlpc-rs
Provides a platform-agnostic, no_std-compatible driver for the ST IIS2DLPC sensor, supporting both I2C and SPI communication interfaces.
Sensor Overview
The IIS2DLPC is an ultra-low-power high-performance three-axis linear accelerometer with digital I²C/SPI output interface which leverages on the robust and mature manufacturing processes already used for the production of micromachined accelerometers.
The IIS2DLPC has user-selectable full scales of ±2g/±4g/±8g/±16g and is capable of measuring accelerations with output data rates from 1.6 Hz to 1600 Hz.
The IIS2DLPC has one high-performance mode and 4 low-power modes which can be changed on the fly, providing outstanding versatility and adaptability to the requirements of the application. The IIS2DLPC has an integrated 32-level first-in, first-out (FIFO) buffer allowing the user to store data in order to limit intervention by the host processor.
The embedded self-test capability allows the user to check the functioning of the sensor in the final application.
The IIS2DLPC has a dedicated internal engine to process motion and acceleration detection including free-fall, wakeup, highly configurable single/double-tap recognition, activity/inactivity, stationary/motion detection, portrait/landscape detection and 6D/4D orientation.
The IIS2DLPC is available in a small thin plastic land grid array package (LGA) and it is guaranteed to operate over an extended temperature range from -40 °C to +85 °C.
For more info, please visit the device page at https://www.st.com/en/mems-and-sensors/iis2dlpc.html
Installation
Add the driver to your Cargo.toml dependencies:
[]
= "2.0.0"
Or, add it directly from the terminal:
Usage
By default, the create exposes the asynchronous API, and it could be included using:
use asynchronous as iis2dlpc;
use *;
use *;
Blocking API (optional feature)
To use the blocking API instead of the asynchronous one, disable default features and enable the blocking feature in your Cargo.toml
[]
= { = "2.0.0", = false, = ["blocking"] }
or from the terminal:
Then import the blocking API:
use blocking as iis2dlpc;
use *;
use *;
Create an instance
Create an instance of the driver with the new_<bus> associated function, by passing an I2C (embedded_hal::i2c::I2c) instance and I2C address, or an SPI (embedded_hal::spi::SpiDevice) instance, along with a timing peripheral.
An example with I2C:
let mut sensor = new_i2c;
Check "Who Am I" Register
This step ensures correct communication with the sensor. It returns a unique ID to verify the sensor's identity.
let whoami = sensor.device_id_get.unwrap;
if whoami != ID
Configure
See details in specific examples; the following are common api calls:
// Restore default configuration
sensor.reset_set.unwrap;
while sensor.reset_get.unwrap == 1
// Enable Block Data Update
sensor.block_data_update_set.unwrap;
// Set Full scale
sensor.full_scale_set.unwrap;
// Configure power mode
sensor
.power_mode_set
.unwrap;
// Set Output Data Rate
sensor.data_rate_set.unwrap;
License
Distributed under the BSD-3 Clause license.
More Information: http://www.st.com.
Copyright (C) 2025 STMicroelectronics