summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/main.rs32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index 84bc3c0..a89ac07 100755
--- a/src/main.rs
+++ b/src/main.rs
@@ -6,6 +6,8 @@ mod logger;
mod macros;
mod rtc;
+use atsamd_usb_host::SAMDHost;
+use bootkbd::BootKeyboard;
use clint::HandlerArray;
use core::mem;
use core::panic::PanicInfo;
@@ -24,8 +26,7 @@ use trinket_m0::{
time::*,
CorePeripherals, Peripherals,
};
-
-// I²C on trinket is on SERCOM2
+use usb_host::Driver;
static mut LED: usize = 0;
@@ -104,19 +105,42 @@ fn main() -> ! {
let mut rtc_handler = rtc::setup(dp.RTC, &mut clocks);
+ let (mut usb_host, mut usb_handler) = SAMDHost::new(
+ dp.USB,
+ pins.usb_sof,
+ pins.usb_dm,
+ pins.usb_dp,
+ Some(pins.usb_host_enable),
+ &mut pins.port,
+ &mut clocks,
+ &mut dp.PM,
+ &rtc::millis,
+ );
+
+ let mut bootkbd = BootKeyboard::new();
+ let mut drivers: [&mut dyn Driver; 1] = [&mut bootkbd];
+
HANDLERS.with_overrides(|hs| {
hs.register(0, &mut rtc_handler);
+ unsafe { cp.NVIC.set_priority(Interrupt::USB, 0) };
cp.NVIC.enable(Interrupt::RTC);
+ hs.register(1, &mut usb_handler);
+ unsafe { cp.NVIC.set_priority(Interrupt::USB, 1) };
+ cp.NVIC.enable(Interrupt::USB);
+
info!("Bootstrap complete.");
let mut last_tick = 0;
loop {
let tick = rtc::millis();
- if tick > last_tick + 1024 {
+ if tick >= last_tick + 1000 {
last_tick = tick;
- i2c_master.write(NRF_WIREADDR, b"!").expect("writing i2c");
+ let t: [u8; 4] = unsafe { core::mem::transmute(tick) };
+ i2c_master.write(NRF_WIREADDR, &t).ok();
}
+
+ usb_host.task(&mut drivers[..]);
wfi()
}
});