2020-06-09 09:52:27 +00:00
|
|
|
#![no_main]
|
|
|
|
#![no_std]
|
|
|
|
|
|
|
|
use dk::{
|
|
|
|
peripheral::USBD,
|
|
|
|
usbd::{self, Event},
|
|
|
|
};
|
|
|
|
use panic_log as _; // panic handler
|
|
|
|
|
2020-06-12 15:54:45 +00:00
|
|
|
#[rtic::app(device = dk)]
|
2020-06-09 09:52:27 +00:00
|
|
|
const APP: () = {
|
|
|
|
struct Resources {
|
|
|
|
usbd: USBD,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[init]
|
|
|
|
fn init(_cx: init::Context) -> init::LateResources {
|
|
|
|
let board = dk::init().unwrap();
|
|
|
|
|
2020-06-25 17:14:39 +00:00
|
|
|
// initialize the USBD peripheral
|
|
|
|
// NOTE this will block if the USB cable is not connected to port J3
|
2020-06-09 09:52:27 +00:00
|
|
|
usbd::init(board.power, &board.usbd);
|
|
|
|
|
2020-06-25 17:14:39 +00:00
|
|
|
log::info!("USBD initialized");
|
2020-06-09 09:52:27 +00:00
|
|
|
|
|
|
|
init::LateResources { usbd: board.usbd }
|
|
|
|
}
|
|
|
|
|
|
|
|
#[task(binds = USBD, resources = [usbd])]
|
2020-06-25 17:14:39 +00:00
|
|
|
fn main(cx: main::Context) {
|
2020-06-09 09:52:27 +00:00
|
|
|
let usbd = cx.resources.usbd;
|
|
|
|
|
|
|
|
while let Some(event) = usbd::next_event(usbd) {
|
|
|
|
on_event(usbd, event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-25 17:14:39 +00:00
|
|
|
fn on_event(_usbd: &USBD, event: Event) {
|
|
|
|
log::info!("USB: {:?} @ {:?}", event, dk::uptime());
|
2020-06-09 09:52:27 +00:00
|
|
|
|
|
|
|
match event {
|
2020-06-25 17:14:39 +00:00
|
|
|
Event::UsbReset => todo!(),
|
2020-06-09 09:52:27 +00:00
|
|
|
|
2020-06-25 17:14:39 +00:00
|
|
|
Event::UsbEp0DataDone => todo!(),
|
2021-04-20 12:38:38 +00:00
|
|
|
// leave this at it is for now.
|
2020-06-09 09:52:27 +00:00
|
|
|
|
2021-04-23 11:18:24 +00:00
|
|
|
Event::UsbEp0Setup => {
|
|
|
|
log::info!("goal reached; move to the next section");
|
|
|
|
|
|
|
|
}
|
2020-06-09 09:52:27 +00:00
|
|
|
}
|
|
|
|
}
|