From 31b140cbe93b354de7f2ff7526d681dc8915b589 Mon Sep 17 00:00:00 2001 From: Ian McIntyre Date: Mon, 29 Jun 2020 19:13:36 -0400 Subject: [PATCH] Add RTIC example with late resources As proposed by Mitch in #64. As of this commit, the Teensy CLI loader does not reject the *.hex file. See the previous commit for details. --- examples/rtic_led.rs | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/examples/rtic_led.rs b/examples/rtic_led.rs index c80b5418..71f48f07 100644 --- a/examples/rtic_led.rs +++ b/examples/rtic_led.rs @@ -11,38 +11,28 @@ #![no_std] #![no_main] -extern crate panic_halt; - -use embedded_hal::digital::v2::OutputPin; +use embedded_hal::digital::v2::ToggleableOutputPin; +use panic_halt as _; use teensy4_bsp as bsp; -#[rtic::app(device = teensy4_bsp, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)] +#[rtic::app(device = teensy4_bsp, peripherals = true)] const APP: () = { - #[init(schedule = [dummy])] - fn init(cx: init::Context) { - // Cortex-M peripherals - let _core = cx.core; - - // Device-specific peripherals - let mut device: bsp::Peripherals = cx.device; - - let mut led = bsp::configure_led(&mut device.gpr, device.pins.p13); - led.set_high().unwrap(); + struct Resources { + led: bsp::LED, } - #[task] - fn dummy(_: dummy::Context) { - + #[init] + fn init(mut cx: init::Context) -> init::LateResources { + // Prepare the LED. + let led = bsp::configure_led(&mut cx.device.gpr, cx.device.pins.p13); + init::LateResources { led } } - #[idle] - fn idle(_: idle::Context) -> ! { + #[idle(resources = [led])] + fn idle(cx: idle::Context) -> ! { + cx.resources.led.toggle().unwrap(); loop { core::sync::atomic::spin_loop_hint(); } } - - extern "C" { - fn LPUART8(); - } };