Skip to content

Commit bca960d

Browse files
authored
lib: Add sync version (#2)
The implementation is behind the `sync` feature.
2 parents 1313b72 + bc2d2d1 commit bca960d

File tree

8 files changed

+952
-12
lines changed

8 files changed

+952
-12
lines changed

.github/workflows/rust.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
run: cargo build --verbose --all-features --all-targets
2424
- name: Run tests
2525
run: cargo test --verbose --no-fail-fast --all-features --all-targets
26+
- name: Run doc tests
27+
run: cargo test --verbose --no-fail-fast --all-features --doc
2628

2729
format:
2830
name: Check code formatting

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"rust-analyzer.cargo.features": "all"
3+
}

Cargo.lock

+221-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ categories = ["aerospace", "embedded", "hardware-support", "no-std"]
1212

1313
[features]
1414
embassy-time = ["dep:embassy-time"]
15+
sync = ["dep:embedded-hal"]
1516

1617
[dependencies]
1718
embedded-hal-async = "1.0.0"
19+
embedded-hal = { version= "1.0.0", optional = true}
1820
embassy-time = { version = "0.3.0", optional = true }
1921
defmt = "0.3.8"
2022
libm = "0.2.8"
@@ -26,4 +28,5 @@ embedded-hal-mock = { version = "0.11.0", default-features = false, features = [
2628
"eh1",
2729
"embedded-hal-async",
2830
] }
31+
linux-embedded-hal = "0.4.0"
2932
tokio = { version = "1.37.0", features = ["macros", "rt"] }

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ The BMP390 is a digital sensor with pressure and temperature measurement based o
99

1010
[`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).
1111

12+
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.
13+
1214
## Datasheet
1315
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.

examples/sync_linux.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use bmp390::{sync::Bmp390, Address, Configuration};
2+
use linux_embedded_hal::{Delay, I2cdev};
3+
use uom::si::length::meter;
4+
5+
fn main() {
6+
let i2c = I2cdev::new("/dev/i2c-1")
7+
.map_err(bmp390::Error::I2c)
8+
.expect("Failed to create I2C device");
9+
let mut delay = Delay;
10+
11+
let config = Configuration::default();
12+
let mut sensor = Bmp390::try_new(i2c, Address::Up, &mut delay, &config)
13+
.expect("Failed to initialize BMP390 sensor");
14+
15+
let measurement = sensor.measure().expect("Failed to measure BMP390 data");
16+
17+
println!(
18+
"Measurement: Pressure: {} hPa, Temperature: {} °C, Altitude: {} m",
19+
measurement.pressure.get::<uom::si::pressure::hectopascal>(),
20+
measurement
21+
.temperature
22+
.get::<uom::si::thermodynamic_temperature::degree_celsius>(),
23+
measurement.altitude.get::<meter>()
24+
);
25+
}

0 commit comments

Comments
 (0)