Skip to content

Commit

Permalink
lib: Add sync version (#2)
Browse files Browse the repository at this point in the history
The implementation is behind the `sync` feature.
  • Loading branch information
asasine authored Jan 9, 2025
2 parents 1313b72 + bc2d2d1 commit bca960d
Show file tree
Hide file tree
Showing 8 changed files with 952 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
run: cargo build --verbose --all-features --all-targets
- name: Run tests
run: cargo test --verbose --no-fail-fast --all-features --all-targets
- name: Run doc tests
run: cargo test --verbose --no-fail-fast --all-features --doc

format:
name: Check code formatting
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rust-analyzer.cargo.features": "all"
}
222 changes: 221 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ categories = ["aerospace", "embedded", "hardware-support", "no-std"]

[features]
embassy-time = ["dep:embassy-time"]
sync = ["dep:embedded-hal"]

[dependencies]
embedded-hal-async = "1.0.0"
embedded-hal = { version= "1.0.0", optional = true}
embassy-time = { version = "0.3.0", optional = true }
defmt = "0.3.8"
libm = "0.2.8"
Expand All @@ -26,4 +28,5 @@ embedded-hal-mock = { version = "0.11.0", default-features = false, features = [
"eh1",
"embedded-hal-async",
] }
linux-embedded-hal = "0.4.0"
tokio = { version = "1.37.0", features = ["macros", "rt"] }
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ The BMP390 is a digital sensor with pressure and temperature measurement based o

[`Bmp390`](https://docs.rs/bmp390/latest/bmp390/struct.Bmp390.html) is a driver for the BMP390 sensor. It provides methods to read the temperature and pressure from the sensor over [I2C](https://en.wikipedia.org/wiki/I%C2%B2C). It is built on top of the [`embedded_hal_async::i2c`](https://docs.rs/embedded-hal-async/latest/embedded_hal_async/i2c/index.html) traits to be compatible with a wide range of embedded platforms. Measurements utilize the [`uom`](https://docs.rs/uom/latest/uom/) crate to provide automatic, type-safe, and zero-cost units of measurement for [`Measurement`](https://docs.rs/bmp390/latest/bmp390/struct.Measurement.html).

Synchronous and asynchronous interfaces are available. The synchronous interface is built on top of the [`embedded-hal`](https://docs.rs/embedded-hal/latest/embedded_hal/) traits, while the asynchronous interface is built on top of the [`embedded-hal-async`](https://docs.rs/embedded-hal-async/latest/embedded_hal_async/) traits. The default features include the *asynchronous* interface, but the synchronous [`sync::Bmp390`](https://docs.rs/bmp390/latest/bmp390/sync/struct.Bmp390.html) one can be enabled with the `sync` feature.

## Datasheet
The [BMP390 Datasheet](https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp390-ds002.pdf) contains detailed information about the sensor's features, electrical characteristics, and registers. This package implements the functionality described in the datasheet and references the relevant sections in the documentation.
25 changes: 25 additions & 0 deletions examples/sync_linux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use bmp390::{sync::Bmp390, Address, Configuration};
use linux_embedded_hal::{Delay, I2cdev};
use uom::si::length::meter;

fn main() {
let i2c = I2cdev::new("/dev/i2c-1")
.map_err(bmp390::Error::I2c)
.expect("Failed to create I2C device");
let mut delay = Delay;

let config = Configuration::default();
let mut sensor = Bmp390::try_new(i2c, Address::Up, &mut delay, &config)
.expect("Failed to initialize BMP390 sensor");

let measurement = sensor.measure().expect("Failed to measure BMP390 data");

println!(
"Measurement: Pressure: {} hPa, Temperature: {} °C, Altitude: {} m",
measurement.pressure.get::<uom::si::pressure::hectopascal>(),
measurement
.temperature
.get::<uom::si::thermodynamic_temperature::degree_celsius>(),
measurement.altitude.get::<meter>()
);
}
Loading

0 comments on commit bca960d

Please sign in to comment.