Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #7

Merged
merged 4 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
[package]
name = "pas-co2-rs"
version = "0.1.0-beta.1"
version = "0.1.0-beta.0"
edition = "2021"
authors = [
"Joel Schulz-Andres <[email protected]>",
"Julian Dickert <[email protected]>",
]
description = "Inofficial Rust driver for Infineon PAS CO2 sensor"
license = "MIT"
categories = ["no-std", "embedded", "sensor", "co2"]
repository = "https://github.com/Systemscape/pas-co2-rs"

description = "Inofficial Rust driver for Infineon PAS CO2 sensor"
license-file = "LICENSE"
readme = "README.md"
repository = "https://github.com/Systemscape/pas-co2-rs"

categories = ["no-std", "embedded", "sensor", "co2"]

[features]
default = ["defmt"]
Expand All @@ -20,6 +21,8 @@ defmt = ["dep:defmt", "embedded-hal/defmt-03"]
[dependencies]
defmt = { version = "0.3", optional = true }
embedded-hal = "1.0.0"
embedded-hal-async = "1.0.0"
num_enum = { version = "0.7.2", default-features = false }

[badges]
maintenance = { status = "actively-developed" }
maintenance = { status = "actively-developed" }
40 changes: 8 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
# pas-co2-rs
Inofficial Rust driver for Infineon XENSIV (TM) PAS CO2 sensor.

```rust
// Obtain an instance of the driver
let mut pas_co2 = PasCo2::new(i2c);
## Non-async I2C
Currently, there is no support for synchronous I2C, i.e., embedded-hal. Only embedded-hal-async is supported.
It is straightforward to add this, but would result in a lot of code duplication.

info!("Status: {}", pas_co2.get_status());
## Examples
You can find an example for the STM32F469 in the examples folder inside the repository.
This should be easy to adapt to any other platform thanks to embedded-hal.

// Set to idle mode (default)
let mut mode = MeasurementMode::default();
mode.operating_mode = measurement_mode::OperatingMode::Idle;
pas_co2.set_measurement_mode(mode).unwrap();

let pressure: u16 = 950; //hPa

pas_co2
.set_pressure_compensation(PressureCompensation(pressure))
.unwrap();

let status = pas_co2.get_status().unwrap();
info!("Status: {}", status);

pas_co2.clear_status().unwrap();

loop {
pas_co2.start_measurement().unwrap();

Timer::after_millis(1150).await;

let co2_ppm = pas_co2.get_co2_ppm().unwrap();

info!("CO2: {} ppm", co2_ppm);

Timer::after_millis(10000).await;
}
```
## Contributing
Feel free to contribute to this project by opening a pull-request or creating an issue for bugs, questions or suggestions.
15 changes: 10 additions & 5 deletions examples/stm32f4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@ name = "stm32f4-example"
license = "MIT"

[dependencies]
# Change stm32f429zi to your chip name, if necessary.
embassy-stm32 = { git = "https://github.com/embassy-rs/embassy.git", rev = "daaaf50298144a245d026e70f4fa3c6eb856276a", features = [
# Change stm32f469ni to your chip name, if necessary.
embassy-stm32 = { git = "https://github.com/embassy-rs/embassy.git", rev = "d8bd5907ca9dc1f239ca0e603b51ec723e1fef1b", features = [
"defmt",
"stm32f469ni",
"memory-x",
"unstable-pac",
"time-driver-any",
"exti"
] }

embassy-executor = { git = "https://github.com/embassy-rs/embassy.git", rev = "daaaf50298144a245d026e70f4fa3c6eb856276a", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
embassy-executor = { git = "https://github.com/embassy-rs/embassy.git", rev = "d8bd5907ca9dc1f239ca0e603b51ec723e1fef1b", features = [
"task-arena-size-32768",
"arch-cortex-m",
"executor-thread",
"defmt",
"integrated-timers",
] }

embassy-time = { git = "https://github.com/embassy-rs/embassy.git", rev = "daaaf50298144a245d026e70f4fa3c6eb856276a", features = [
embassy-time = { git = "https://github.com/embassy-rs/embassy.git", rev = "d8bd5907ca9dc1f239ca0e603b51ec723e1fef1b", features = [
"defmt",
"defmt-timestamp-uptime",
"tick-hz-32_768",
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f4/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[toolchain]
channel = "1.79"
targets = ["thumbv7em-none-eabi"]
56 changes: 41 additions & 15 deletions examples/stm32f4/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::time::Hertz;
use embassy_stm32::{bind_interrupts, i2c, peripherals};
use embassy_time::Timer;
use embassy_time::{Duration, Timer};

use pas_co2_rs::regs::*;
use pas_co2_rs::*;
Expand All @@ -24,39 +24,65 @@ async fn main(_spawner: Spawner) {
let mut config = embassy_stm32::i2c::Config::default();
config.sda_pullup = true;
config.scl_pullup = true;
config.timeout = Duration::from_secs(1);

let i2c = embassy_stm32::i2c::I2c::new_blocking(p.I2C1, p.PB8, p.PB9, Hertz(100_000), config);
info!("Configuring I2C");

let i2c = embassy_stm32::i2c::I2c::new(
p.I2C1,
p.PB8,
p.PB9,
Irqs,
p.DMA1_CH6,
p.DMA1_CH0,
Hertz(400_000),
config,
);

info!("Obtaining driver instance");

// Obtain an instance of the driver
let mut pas_co2 = PasCo2::new(i2c);

info!("Status: {}", pas_co2.get_status());
info!("Status: {}", pas_co2.get_status().await.unwrap());

// Set to idle mode (default)
let mut mode = MeasurementMode::default();
mode.operating_mode = measurement_mode::OperatingMode::Idle;
pas_co2.set_measurement_mode(mode).unwrap();
let mode = MeasurementMode {
operating_mode: OperatingMode::Idle,
..Default::default()
};

pas_co2.set_measurement_mode(mode).await.unwrap();

let pressure: u16 = 950; //hPa
pas_co2.set_pressure_compensation(pressure).await.unwrap();

defmt::info!("Testing write -> read");
let test_val = 0b1010_0101;
let read_val = pas_co2.test_write_read(test_val).await.unwrap();
defmt::assert_eq!(test_val, read_val);

pas_co2
.set_pressure_compensation(PressureCompensation(pressure))
.unwrap();
pas_co2.clear_status().await.unwrap();

let status = pas_co2.get_status().unwrap();
info!("Status: {}", status);
// Perform a forced calibration/compensation at 490 ppm reference

pas_co2.clear_status().unwrap();
/*
pas_co2
.do_forced_compensation(490, embassy_time::Delay)
.await
.unwrap();
*/

loop {
pas_co2.start_measurement().unwrap();
defmt::info!("Starting measurement");
pas_co2.start_measurement().await.unwrap();

Timer::after_millis(1150).await;

let co2_ppm = pas_co2.get_co2_ppm().unwrap();
let co2_ppm = pas_co2.get_co2_ppm().await.unwrap();

info!("CO2: {} ppm", co2_ppm);

Timer::after_millis(10000).await;
Timer::after_secs(10).await;
}
}
Loading