diff options
author | Brian Cully <bjc@kublai.com> | 2019-08-07 18:47:19 -0400 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2019-08-07 18:47:19 -0400 |
commit | 97adac62ea8f62b1de5e777889f309486e337dc3 (patch) | |
tree | 73bc5c48103af233e0d39a1a062c2a6919dcd779 | |
parent | 862a82f35284eef20f757f800da013769ca82cc6 (diff) | |
download | bleusb-97adac62ea8f62b1de5e777889f309486e337dc3.tar.gz bleusb-97adac62ea8f62b1de5e777889f309486e337dc3.zip |
Add USB stuff.
-rw-r--r-- | Cargo.lock | 57 | ||||
-rw-r--r-- | Cargo.toml | 14 | ||||
-rwxr-xr-x | src/main.rs | 32 |
3 files changed, 95 insertions, 8 deletions
@@ -33,6 +33,21 @@ dependencies = [ [[package]] name = "atsamd-hal" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "atsamd21e18a 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitfield 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "paste 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "atsamd-hal" version = "0.6.0" dependencies = [ "atsamd21e18a 0.5.0", @@ -46,6 +61,27 @@ dependencies = [ ] [[package]] +name = "atsamd-usb-host" +version = "0.1.0" +dependencies = [ + "atsamd-hal 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "starb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "usb-host 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "atsamd21e18a" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cortex-m 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", + "vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "atsamd21e18a" version = "0.5.0" dependencies = [ @@ -73,6 +109,8 @@ name = "bleusb" version = "0.1.0" dependencies = [ "apa102-spi 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "atsamd-usb-host 0.1.0", + "bootkbd 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "clint 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "cortex-m 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "cortex-m-rt 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -83,6 +121,16 @@ dependencies = [ "smart-leds-trait 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "starb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "trinket_m0 0.4.0", + "usb-host 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "bootkbd" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "usb-host 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -325,6 +373,11 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "usb-host" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "vcell" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -347,8 +400,11 @@ dependencies = [ "checksum aligned 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d3a316c7ea8e1e9ece54862c992def5a7ac14de9f5832b69d71760680efeeefa" "checksum apa102-spi 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "244c305e53cabeadfce23409fe24bfcedaa20166aa3f16f6c4ab256302158fd5" "checksum as-slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "293dac66b274fab06f95e7efb05ec439a6b70136081ea522d270bc351ae5bb27" +"checksum atsamd-hal 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9affce3b8d443195536c0b398a55a152cc962366c24824ea833bb22afd49b3d6" +"checksum atsamd21e18a 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "139787a30d118dd09a2e9570f5404cf582b70afe9b53dd1194239f9be382b897" "checksum bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a3caf393d93b2d453e80638d0674597020cef3382ada454faacd43d1a55a735a" "checksum bitfield 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719" +"checksum bootkbd 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2c25e23fc8d9fa858f4f8fe7d7483cdcb74d5ed5a9ccfe46120184f9cf7c4559" "checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" "checksum clint 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "200296af81a4cbe7da52afd9e5c35b7782eca865678caf2280251b777c9c37aa" "checksum cortex-m 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0b159a1e8306949579de3698c841dba58058197b65c60807194e4fa1e7a554" @@ -379,6 +435,7 @@ dependencies = [ "checksum syn 0.15.42 (registry+https://github.com/rust-lang/crates.io-index)" = "eadc09306ca51a40555dd6fc2b415538e9e18bc9f870e47b1a524a79fe2dcf5e" "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" +"checksum usb-host 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b28da4134d769440fac400a8c871e5c4407ff5e99d1136e616c8b571e73144d1" "checksum vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "45c297f0afb6928cd08ab1ff9d95e99392595ea25ae1b5ecf822ff8764e57a0d" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d67cb4616d99b940db1d6bd28844ff97108b498a6ca850e5b6191a532063286" @@ -1,10 +1,11 @@ [package] name = "bleusb" +description = "Send boot keyboard reports over I²C." version = "0.1.0" authors = ["Brian Cully <bjc@kublai.com>"] edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +license = "GPL-3.0-or-later" +repository = "https://github.com/bjc/bleusb.git" [dependencies] embedded-hal = "0.2" @@ -19,8 +20,13 @@ cortex-m-rt = "0.6" smart-leds-trait = "0.2" smart-leds = "0.2" apa102-spi = "0.2" +usb-host = "0.1" +bootkbd = "0.1" +atsamd-usb-host = { path = "../usbh/atsamd-usb-host" } [patch.crates-io] -#atsamd-hal = { git = "https://github.com/atsamd-rs/atsamd", rev = "97d55c19" } -#trinket_m0 = { git = "https://github.com/atsamd-rs/atsamd", rev = "97d55c19" } +#atsamd-hal = { path = "../usbh/atsamd/hal" } trinket_m0 = { path = "../usbh/atsamd/boards/trinket_m0" } + +[features] +default = ["atsamd-usb-host/samd21e18a"] 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() } }); |