This commit is contained in:
parent
ff61b0147f
commit
e3a0b6ec3d
2 changed files with 0 additions and 93 deletions
10
Cargo.toml
10
Cargo.toml
|
@ -26,13 +26,3 @@ fixed-macro = "1.2"
|
|||
|
||||
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
|
||||
|
||||
[dev-dependencies]
|
||||
embassy-executor = { version = "0.6.0", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "integrated-timers"] }
|
||||
embassy-futures = { version = "0.1.1" }
|
||||
embassy-usb-logger = { version = "0.2.0" }
|
||||
log = "0.4"
|
||||
|
||||
[[example]]
|
||||
name = "rp-pico-dht22"
|
||||
path = "example/rp_pico_dht22.rs"
|
||||
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_rp::{
|
||||
bind_interrupts,
|
||||
gpio::{Level, Output},
|
||||
peripherals::{PIN_15, PIO0, USB},
|
||||
pio::{InterruptHandler as PioInterruptHandler, Pio},
|
||||
usb::{Driver, InterruptHandler as USBInterrupthandler},
|
||||
};
|
||||
use embassy_time::Timer;
|
||||
|
||||
use dht_pio::{Dht, Dht22, DhtError};
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_info: &PanicInfo) -> ! {
|
||||
loop {
|
||||
unsafe {
|
||||
PANIC_LED.as_mut().unwrap().set_high();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static mut PANIC_LED: Option<Output<'static, PIN_15>> = None;
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
PIO0_IRQ_0 => PioInterruptHandler<PIO0>;
|
||||
USBCTRL_IRQ => USBInterrupthandler<USB>;
|
||||
});
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn logger_task(driver: Driver<'static, USB>) {
|
||||
embassy_usb_logger::run!(1024, log::LevelFilter::Info, driver);
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = embassy_rp::init(Default::default());
|
||||
|
||||
unsafe {
|
||||
PANIC_LED = Some(Output::new(p.PIN_15, Level::Low));
|
||||
}
|
||||
|
||||
let driver = Driver::new(p.USB, Irqs);
|
||||
spawner.spawn(logger_task(driver)).unwrap();
|
||||
|
||||
// pio access
|
||||
let pio = p.PIO0;
|
||||
let Pio {
|
||||
mut common,
|
||||
|
||||
// dht22 state machine
|
||||
sm1,
|
||||
..
|
||||
} = Pio::new(pio, Irqs);
|
||||
|
||||
// create DHT22
|
||||
let mut dht = Dht22::new(&mut common, sm1, p.PIN_0);
|
||||
|
||||
let dht_reading = async {
|
||||
loop {
|
||||
match dht.read().await {
|
||||
Ok(reading) => {
|
||||
log::info!("temp: {}, humid: {}", reading.temperature, reading.humidity);
|
||||
}
|
||||
Err(err) => match err {
|
||||
DhtError::Timeout => log::info!("dht timeout error"),
|
||||
DhtError::CrcMismatch(data, crc) => {
|
||||
log::info!("dht checksum error:\ndata: {data:032b}\ncrc: {crc:032b}");
|
||||
}
|
||||
DhtError::ReadError => log::info!("dht read error"),
|
||||
},
|
||||
}
|
||||
|
||||
Timer::after_secs(1).await;
|
||||
}
|
||||
};
|
||||
|
||||
dht_reading.await;
|
||||
}
|
Loading…
Reference in a new issue