uf-dps3xx
uf-dps3xx is a platform-agnostic, no_std driver for the DPS3xx (DPS310, DPS368) family of pressure and temperature sensors.
It uses embedded-hal 1.0 I2C traits and is designed to stay simple in embedded applications.
Supported Hardware
- DPS310
- DPS368
- I2C transport only
- SPI is not implemented
Installation
[]
= "0.1"
Enable defmt formatting support with:
[]
= { = "0.1", = ["defmt"] }
Quick Start
The driver uses a typed state machine:
Dps3xx<_, Uninit>afternew_i2cDps3xx<_, Ready>after initialization completes
use DelayNs;
use ;
I2C Address
Use I2cAddress::Primary for 0x76 and I2cAddress::Secondary for 0x77.
If your board uses a different address, pass I2cAddress::Custom(address).
Initialization
Use init_blocking when you have a delay implementation and want a simple setup flow.
It waits for the sensor, performs the required temperature initialization sequence, reads calibration coefficients, and returns a ready driver.
let mut sensor = new_i2c?
.init_blocking
.map_err?;
Use init when your application has its own scheduler or event loop:
use ;
let sensor = new_i2c?;
let mut init = sensor.init.map_err?;
loop
Measurements
After initialization, call start_background to start continuous pressure and temperature measurement.
sensor.start_background?;
Read calibrated values with:
try_read_sample(): returnsOk(Some(Sample))when pressure and temperature are ready, otherwiseOk(None).read_sample(): returnsError::NoSampleReadywhen a full sample is not ready.read_raw_sample(): reads raw 24-bit pressure and temperature ADC values.
Use standby() to stop measurement.
Sample contains calibrated pressure in pascals and temperature in degrees Celsius:
Configuration
Config::default() uses 1 Hz pressure and temperature measurements with 1x oversampling.
use ;
let config = default
.pressure
.temperature
.temperature_source
.fifo
.interrupts
.init_timeout_ms;
Available rates are Hz1, Hz2, Hz4, Hz8, Hz16, Hz32, Hz64, and Hz128.
Available oversampling values are X1, X2, X4, X8, X16, X32, X64, and X128.
The driver validates measurement busy time in new_i2c. Invalid combinations return Error::InvalidConfig.
Config::suggested_poll_period_ms() returns a conservative polling interval for the configured rates.
Status And Device Info
status() reads the sensor status bits:
let status = sensor.status?;
if status.pressure_ready && status.temperature_ready
product_id() reads the device product ID register.
Errors
The main error type is:
Methods that consume the driver during a state transition return TransitionError on failure.
It keeps the driver so callers can recover the bus or inspect the error:
match sensor.reset
Bus Recovery
Use release() to recover the underlying I2C bus:
let i2c = sensor.release;
Examples
- examples/simple.rs shows a mocked init and sample read flow.
- examples/tbs-lucid-h7/src/main.rs shows an embedded setup for the TBS Lucid H7 flight controller.
Inspirations
License
This project is licensed under Apache-2.0. See LICENSE for details.