2022-04-06 00:00:29 +02:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
use defmt::unwrap;
|
2022-08-17 23:40:16 +02:00
|
|
|
use embassy_executor::Spawner;
|
2022-04-06 00:00:29 +02:00
|
|
|
use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin};
|
2022-08-22 21:46:09 +02:00
|
|
|
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
|
2022-08-22 22:00:06 +02:00
|
|
|
use embassy_sync::channel::{Channel, Receiver, Sender};
|
2022-08-17 23:40:16 +02:00
|
|
|
use embassy_time::{Duration, Timer};
|
2022-08-22 15:51:44 +02:00
|
|
|
use static_cell::StaticCell;
|
2022-06-12 22:15:44 +02:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
2022-04-06 00:00:29 +02:00
|
|
|
|
|
|
|
enum LedState {
|
|
|
|
On,
|
|
|
|
Off,
|
|
|
|
}
|
|
|
|
|
2022-08-22 15:51:44 +02:00
|
|
|
static CHANNEL: StaticCell<Channel<NoopRawMutex, LedState, 1>> = StaticCell::new();
|
2022-04-06 00:00:29 +02:00
|
|
|
|
2022-07-29 21:58:35 +02:00
|
|
|
#[embassy_executor::task]
|
2022-04-06 00:00:29 +02:00
|
|
|
async fn send_task(sender: Sender<'static, NoopRawMutex, LedState, 1>) {
|
|
|
|
loop {
|
|
|
|
sender.send(LedState::On).await;
|
|
|
|
Timer::after(Duration::from_secs(1)).await;
|
|
|
|
sender.send(LedState::Off).await;
|
|
|
|
Timer::after(Duration::from_secs(1)).await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-29 21:58:35 +02:00
|
|
|
#[embassy_executor::task]
|
2022-04-06 00:00:29 +02:00
|
|
|
async fn recv_task(led: AnyPin, receiver: Receiver<'static, NoopRawMutex, LedState, 1>) {
|
|
|
|
let mut led = Output::new(led, Level::Low, OutputDrive::Standard);
|
|
|
|
|
|
|
|
loop {
|
2023-08-11 11:58:22 +02:00
|
|
|
match receiver.receive().await {
|
2022-04-06 00:00:29 +02:00
|
|
|
LedState::On => led.set_high(),
|
|
|
|
LedState::Off => led.set_low(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-29 21:58:35 +02:00
|
|
|
#[embassy_executor::main]
|
2022-08-17 18:49:55 +02:00
|
|
|
async fn main(spawner: Spawner) {
|
|
|
|
let p = embassy_nrf::init(Default::default());
|
2022-08-22 15:51:44 +02:00
|
|
|
let channel = CHANNEL.init(Channel::new());
|
2022-04-06 00:00:29 +02:00
|
|
|
|
|
|
|
unwrap!(spawner.spawn(send_task(channel.sender())));
|
|
|
|
unwrap!(spawner.spawn(recv_task(p.P0_13.degrade(), channel.receiver())));
|
|
|
|
}
|