aboutsummaryrefslogtreecommitdiff
path: root/examples/teensy4_blinky/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/teensy4_blinky/src/main.rs')
-rw-r--r--examples/teensy4_blinky/src/main.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/examples/teensy4_blinky/src/main.rs b/examples/teensy4_blinky/src/main.rs
new file mode 100644
index 0000000..1b95e7b
--- /dev/null
+++ b/examples/teensy4_blinky/src/main.rs
@@ -0,0 +1,62 @@
+#![deny(unsafe_code)]
+#![deny(warnings)]
+#![no_main]
+#![no_std]
+#![feature(type_alias_impl_trait)]
+
+#[panic_handler]
+fn panic(_: &::core::panic::PanicInfo) -> ! {
+ ::teensy4_panic::sos()
+}
+
+use teensy4_bsp::{board, hal};
+
+use rtic_monotonics::imxrt::Gpt1 as Mono;
+use rtic_monotonics::imxrt::*;
+
+#[rtic::app(device = teensy4_bsp, dispatchers = [LPSPI1])]
+mod app {
+ use super::*;
+
+ #[shared]
+ struct Shared {}
+
+ #[local]
+ struct Local {
+ led: board::Led,
+ }
+
+ #[init]
+ fn init(cx: init::Context) -> (Shared, Local) {
+ let board::Resources {
+ pins,
+ mut gpio2,
+ mut gpt1,
+ ..
+ } = board::t40(cx.device);
+
+ // Initialize the systick interrupt & obtain the token to prove that we did
+ gpt1.set_clock_source(hal::gpt::ClockSource::PeripheralClock);
+ let gpt1_mono_token = rtic_monotonics::create_imxrt_gpt1_token!();
+ Mono::start(board::PERCLK_FREQUENCY, gpt1.release(), gpt1_mono_token);
+
+ // Setup LED
+ let led = board::led(&mut gpio2, pins.p13);
+ led.set();
+
+ // Schedule the blinking task
+ blink::spawn().ok();
+
+ (Shared {}, Local { led })
+ }
+
+ #[task(local = [led])]
+ async fn blink(cx: blink::Context) {
+ let blink::LocalResources { led, .. } = cx.local;
+
+ loop {
+ led.toggle();
+ Mono::delay(1000.millis()).await;
+ }
+ }
+}