forked from mciantyre/teensy4-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RTIC USB example WIP. Terminates on usb.init. Part of mciantyre#64.
- Loading branch information
1 parent
8cf06cf
commit f647e5d
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use embedded_hal::digital::v2::ToggleableOutputPin; | ||
use panic_halt as _; | ||
use teensy4_bsp as bsp; | ||
|
||
#[rtic::app(device = teensy4_bsp, peripherals = true)] | ||
const APP: () = { | ||
struct Resources { | ||
led: bsp::LED, | ||
} | ||
|
||
#[init] | ||
fn init(mut cx: init::Context) -> init::LateResources { | ||
init_delay(); | ||
|
||
// Initialize the USB stack with the default logging settings. | ||
let usb_rx = cx.device.usb.init(bsp::usb::LoggingConfig { | ||
filters: &[("usb", None)], | ||
..Default::default() | ||
}); | ||
|
||
let led = bsp::configure_led(&mut cx.device.gpr, cx.device.pins.p13); | ||
init::LateResources { led } | ||
} | ||
|
||
#[task(binds = USB_OTG1, resources = [led])] | ||
fn usb(cx: usb::Context) { | ||
cx.resources.led.toggle().unwrap(); | ||
} | ||
|
||
#[idle] | ||
fn idle(_cx: idle::Context) -> ! { | ||
loop { | ||
core::sync::atomic::spin_loop_hint(); | ||
} | ||
} | ||
}; | ||
|
||
// If we reach WFI on teensy 4.0 too quickly it seems to halt. Here we wait a short while in `init` | ||
// to avoid this issue. The issue only appears to occur when rebooting the device (via the button), | ||
// however there appears to be no issue when power cycling the device. | ||
// | ||
// TODO: Investigate exactly why this appears to be necessary. | ||
fn init_delay() { | ||
for _ in 0..10_000_000 { | ||
core::sync::atomic::spin_loop_hint(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters