embassy/examples/stm32h7/src/bin/signal.rs

37 lines
826 B
Rust
Raw Normal View History

2022-06-03 19:47:17 +02:00
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
use defmt::{info, unwrap};
use embassy_executor::executor::Spawner;
use embassy_executor::time::{Duration, Timer};
2022-06-03 19:47:17 +02:00
use embassy_stm32::Peripherals;
use embassy_util::channel::signal::Signal;
2022-06-12 22:15:44 +02:00
use {defmt_rtt as _, panic_probe as _};
2022-06-03 19:47:17 +02:00
static SIGNAL: Signal<u32> = Signal::new();
#[embassy_executor::task]
2022-06-03 19:47:17 +02:00
async fn my_sending_task() {
let mut counter: u32 = 0;
loop {
Timer::after(Duration::from_secs(1)).await;
SIGNAL.signal(counter);
counter = counter.wrapping_add(1);
}
}
#[embassy_executor::main]
2022-06-03 19:47:17 +02:00
async fn main(spawner: Spawner, _p: Peripherals) {
unwrap!(spawner.spawn(my_sending_task()));
loop {
let received_counter = SIGNAL.wait().await;
info!("signalled, counter: {}", received_counter);
}
}