diff --git a/examples/app7.rs b/examples/app7.rs new file mode 100644 index 0000000000000000000000000000000000000000..691656f27c8d88be2a770d7879f1716b7f10c76b --- /dev/null +++ b/examples/app7.rs @@ -0,0 +1,61 @@ +#![no_main] +#![no_std] +use cortex_m_semihosting::hprintln; +use nrf52832_hal as hal; +#[allow(unused_imports)] +use panic_semihosting; +use rtfm::{app, Exclusive}; + +use embedded_hal::digital::OutputPin; +use hal::gpio; +use hal::gpio::p0::*; +use hal::gpio::Level; +use hal::gpio::*; +use hal::prelude::GpioExt; + +const PERIOD : u32 = 64_000_000; + +#[app(device = crate::hal::target)] +const APP: () = { + // Late resources + static mut LED: P0_14<gpio::Output<PushPull>> = (); + + #[init(spawn = [low])] + fn init() -> init::LateResources { + hprintln!("init").unwrap(); + let port0 = device.P0.split(); + let led = port0.p0_14.into_push_pull_output(Level::High); + spawn.low().unwrap(); + init::LateResources { LED : led } + } + + #[task(schedule = [high], resources = [LED])] + fn low() { + toggler(resources.LED, false); + + schedule.high( + scheduled + PERIOD.cycles() + ).unwrap(); + } + + #[task(schedule = [low], resources = [LED])] + fn high() { + toggler(resources.LED, true); + schedule.low( + scheduled + PERIOD.cycles() + ).unwrap(); + } + + extern "C" { + fn SWI1_EGU1(); + } +}; + +// Arument is Exclusive access to a specific pin +fn toggler(mut led : Exclusive<P0_14<Output<PushPull>>>, state : bool ) { + if state { + led.set_high(); + } else { + led.set_low(); + } +} diff --git a/examples/app8.rs b/examples/app8.rs new file mode 100644 index 0000000000000000000000000000000000000000..60ccc1639cccecf1d69584aa80d52316c68829c9 --- /dev/null +++ b/examples/app8.rs @@ -0,0 +1,62 @@ +#![no_main] +#![no_std] +use cortex_m_semihosting::hprintln; +use nrf52832_hal as hal; +#[allow(unused_imports)] +use panic_semihosting; +use rtfm::{app}; + +use embedded_hal::digital::OutputPin; +use hal::gpio; +use hal::gpio::p0::*; +use hal::gpio::Level; +use hal::gpio::*; +use hal::prelude::GpioExt; + +const PERIOD : u32 = 64_000_000; + +#[app(device = crate::hal::target)] +const APP: () = { + // Late resources + // static mut LED: OutputPin = (); <= size not known + static mut LED: P0_14<gpio::Output<PushPull>> = (); + + #[init(spawn = [low])] + fn init() -> init::LateResources { + hprintln!("init").unwrap(); + let port0 = device.P0.split(); + let led = port0.p0_14.into_push_pull_output(Level::High); + spawn.low().unwrap(); + init::LateResources { LED : led } + } + + #[task(schedule = [high], resources = [LED])] + fn low() { + toggler(&mut *resources.LED, false); + + schedule.high( + scheduled + PERIOD.cycles() + ).unwrap(); + } + + #[task(schedule = [low], resources = [LED])] + fn high() { + toggler(&mut *resources.LED, true); + schedule.low( + scheduled + PERIOD.cycles() + ).unwrap(); + } + + extern "C" { + fn SWI1_EGU1(); + } +}; + +// Arument is an Output pin +fn toggler(led : &mut OutputPin, state : bool ) { + if state { + led.set_high(); + } else { + led.set_low(); + } +} \ No newline at end of file