mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2024-09-25 21:10:00 +00:00
886487dee6
- add intermediate-step solutions - add more hints - refactor exercise & text to have the same amount of work on all OSes - add `usb` parser solutions - make `dk-run` less silent - rename rtic binaries (shorter names) - link to the main svd2rust API docs
52 lines
1.1 KiB
Rust
52 lines
1.1 KiB
Rust
#![no_main]
|
|
#![no_std]
|
|
|
|
use dk::{
|
|
peripheral::USBD,
|
|
usbd::{self, Event},
|
|
};
|
|
use panic_log as _; // panic handler
|
|
|
|
#[rtic::app(device = dk)]
|
|
const APP: () = {
|
|
struct Resources {
|
|
usbd: USBD,
|
|
}
|
|
|
|
#[init]
|
|
fn init(_cx: init::Context) -> init::LateResources {
|
|
let board = dk::init().unwrap();
|
|
|
|
// initialize the USBD peripheral
|
|
// NOTE this will block if the USB cable is not connected to port J3
|
|
usbd::init(board.power, &board.usbd);
|
|
|
|
log::info!("USBD initialized");
|
|
|
|
init::LateResources { usbd: board.usbd }
|
|
}
|
|
|
|
#[task(binds = USBD, resources = [usbd])]
|
|
fn main(cx: main::Context) {
|
|
let usbd = cx.resources.usbd;
|
|
|
|
while let Some(event) = usbd::next_event(usbd) {
|
|
on_event(usbd, event)
|
|
}
|
|
}
|
|
};
|
|
|
|
fn on_event(_usbd: &USBD, event: Event) {
|
|
log::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
|
|
|
match event {
|
|
Event::UsbReset => todo!(),
|
|
|
|
Event::UsbEp0DataDone => todo!(),
|
|
|
|
Event::UsbEp0Setup => {
|
|
log::info!("goal reached; move to the next section");
|
|
dk::exit()
|
|
}
|
|
}
|
|
}
|