2020-06-09 09:52:27 +00:00
|
|
|
#![no_main]
|
|
|
|
#![no_std]
|
|
|
|
|
|
|
|
use cortex_m::asm;
|
|
|
|
use dk::{peripheral::USBD, usbd};
|
|
|
|
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();
|
|
|
|
|
|
|
|
// initialize the USB peripheral; will block until the USB cable is physically connected
|
|
|
|
usbd::init(board.power, &board.usbd);
|
|
|
|
|
|
|
|
// electrically connects the device to the host
|
|
|
|
usbd::connect(&board.usbd);
|
|
|
|
|
|
|
|
init::LateResources { usbd: board.usbd }
|
|
|
|
}
|
|
|
|
|
|
|
|
#[task(binds = USBD, resources = [usbd])]
|
|
|
|
fn usb(cx: usb::Context) {
|
|
|
|
let usbd = cx.resources.usbd;
|
|
|
|
|
|
|
|
log::info!("USB event occurred");
|
|
|
|
|
|
|
|
// electrically disconnects the device to the host
|
|
|
|
usbd::disconnect(usbd);
|
|
|
|
|
|
|
|
asm::bkpt();
|
|
|
|
}
|
|
|
|
};
|