2022-04-06 00:00:29 +02:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
use defmt::unwrap;
|
2022-07-29 21:58:35 +02:00
|
|
|
use embassy_executor::executor::Spawner;
|
|
|
|
use embassy_executor::time::{Duration, Timer};
|
2022-04-06 00:00:29 +02:00
|
|
|
use embassy_nrf::gpio::{Level, Output, OutputDrive};
|
|
|
|
use embassy_nrf::Peripherals;
|
2022-07-29 21:58:35 +02:00
|
|
|
use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
|
|
|
|
use embassy_util::channel::mpmc::Channel;
|
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,
|
|
|
|
}
|
|
|
|
|
|
|
|
static CHANNEL: Channel<ThreadModeRawMutex, LedState, 1> = Channel::new();
|
|
|
|
|
2022-07-29 21:58:35 +02:00
|
|
|
#[embassy_executor::task]
|
2022-04-06 00:00:29 +02:00
|
|
|
async fn my_task() {
|
|
|
|
loop {
|
|
|
|
CHANNEL.send(LedState::On).await;
|
|
|
|
Timer::after(Duration::from_secs(1)).await;
|
|
|
|
CHANNEL.send(LedState::Off).await;
|
|
|
|
Timer::after(Duration::from_secs(1)).await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-29 21:58:35 +02:00
|
|
|
#[embassy_executor::main]
|
2022-04-06 00:00:29 +02:00
|
|
|
async fn main(spawner: Spawner, p: Peripherals) {
|
|
|
|
let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard);
|
|
|
|
|
|
|
|
unwrap!(spawner.spawn(my_task()));
|
|
|
|
|
|
|
|
loop {
|
|
|
|
match CHANNEL.recv().await {
|
|
|
|
LedState::On => led.set_high(),
|
|
|
|
LedState::Off => led.set_low(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|