start playing around with dcf77
This commit is contained in:
parent
530ea9a0e5
commit
841b7025bb
2 changed files with 58 additions and 2 deletions
|
@ -14,3 +14,7 @@ embassy-stm32 = { git = "https://github.com/embassy-rs/embassy", features = ["de
|
|||
embassy-sync = { version = "0.3", features = ["nightly"] }
|
||||
embassy-time = { version = "0.1.3", features = ["defmt", "nightly"] }
|
||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
|
||||
[profile.release]
|
||||
debug = true
|
||||
opt-level = "z"
|
||||
|
|
56
src/main.rs
56
src/main.rs
|
@ -12,10 +12,10 @@ use embassy_executor::Spawner;
|
|||
use embassy_stm32::{
|
||||
exti::ExtiInput,
|
||||
gpio::{Input, Level, Output, Pull, Speed},
|
||||
peripherals::{PA5, PC13}
|
||||
peripherals::{PA0, PA1, PA5, PC13}
|
||||
};
|
||||
use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
|
||||
use embassy_time::{Duration, Timer};
|
||||
use embassy_time::{Duration, Instant, Timer};
|
||||
use panic_probe as _;
|
||||
use static_mutex::StaticMutex;
|
||||
|
||||
|
@ -24,6 +24,8 @@ type MutexGuard<'a, T> = embassy_sync::mutex::MutexGuard<'a, ThreadModeRawMutex,
|
|||
|
||||
type NucleoLed = Output<'static, PA5>;
|
||||
type NucleoButton = ExtiInput<'static, PC13>;
|
||||
type POn = Output<'static, PA0>;
|
||||
type Tco = ExtiInput<'static, PA1>;
|
||||
|
||||
static LED: StaticMutex<NucleoLed> = StaticMutex::new();
|
||||
static BLINKING: Mutex<bool> = Mutex::new(true);
|
||||
|
@ -54,10 +56,60 @@ async fn button_handler(mut button: NucleoButton) {
|
|||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn query_time(mut pon: POn, mut tco: Tco, interval: Duration) {
|
||||
loop {
|
||||
pon.set_low();
|
||||
info!("Waiting");
|
||||
tco.wait_for_falling_edge().await;
|
||||
// for _ in 0 .. 10 {
|
||||
// info!("Receiving");
|
||||
// let mut bytes = 0u64;
|
||||
// for _ in 0 .. 60 {
|
||||
// bytes = (bytes << 1) | (tco.is_low() as u64);
|
||||
// Timer::after(Duration::from_millis(100)).await;
|
||||
// }
|
||||
// info!("DCF77: {:X}", bytes);
|
||||
// }
|
||||
let start = Instant::now();
|
||||
let mut next = start;
|
||||
for _ in 0 .. 120 {
|
||||
let mut bytes = 0u16;
|
||||
for _ in 0 .. 10 {
|
||||
bytes = (bytes << 1) | (tco.is_low() as u16);
|
||||
next += Duration::from_millis(100);
|
||||
Timer::at(next).await;
|
||||
}
|
||||
println!(
|
||||
"{}{}{}{}{}{}{}{}{}{} ({})",
|
||||
(bytes >> 9) & 1,
|
||||
(bytes >> 8) & 1,
|
||||
(bytes >> 7) & 1,
|
||||
(bytes >> 6) & 1,
|
||||
(bytes >> 5) & 1,
|
||||
(bytes >> 4) & 1,
|
||||
(bytes >> 3) & 1,
|
||||
(bytes >> 2) & 1,
|
||||
(bytes >> 1) & 1,
|
||||
bytes & 1,
|
||||
start.elapsed().as_millis()
|
||||
);
|
||||
}
|
||||
pon.set_high();
|
||||
|
||||
Timer::after(interval).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
|
||||
let pon = Output::new(p.PA0, Level::High, Speed::Low);
|
||||
let tco = ExtiInput::new(Input::new(p.PA1, Pull::None), p.EXTI1);
|
||||
|
||||
unwrap!(spawner.spawn(query_time(pon, tco, Duration::from_secs(300))));
|
||||
|
||||
LED.init(Output::new(p.PA5, Level::Low, Speed::Low)).await;
|
||||
let button = ExtiInput::new(Input::new(p.PC13, Pull::Up), p.EXTI13);
|
||||
|
||||
|
|
Loading…
Reference in a new issue