Add RTIC example.
This commit is contained in:
43
examples/nrf52840-rtic/src/bin/blinky.rs
Normal file
43
examples/nrf52840-rtic/src/bin/blinky.rs
Normal file
@ -0,0 +1,43 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[rtic::app(device = embassy_nrf, peripherals = false, dispatchers = [SWI0_EGU0, SWI1_EGU1])]
|
||||
mod app {
|
||||
use defmt::info;
|
||||
use embassy_nrf::gpio::{Level, Output, OutputDrive};
|
||||
use embassy_nrf::peripherals;
|
||||
use embassy_time::{Duration, Timer};
|
||||
|
||||
#[shared]
|
||||
struct Shared {}
|
||||
|
||||
#[local]
|
||||
struct Local {}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> (Shared, Local) {
|
||||
info!("Hello World!");
|
||||
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
blink::spawn(p.P0_13).map_err(|_| ()).unwrap();
|
||||
|
||||
(Shared {}, Local {})
|
||||
}
|
||||
|
||||
#[task(priority = 1)]
|
||||
async fn blink(_cx: blink::Context, pin: peripherals::P0_13) {
|
||||
let mut led = Output::new(pin, Level::Low, OutputDrive::Standard);
|
||||
|
||||
loop {
|
||||
info!("off!");
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
info!("on!");
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user