diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index eb01dd6..99f1ec6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,9 +14,11 @@ mod crc; mod device; mod hid; +use cortex_m::asm::delay; use cortex_m_rt::entry; +use embedded_hal::digital::v2::OutputPin; use hal::prelude::*; -use stm32f103xx_usb::UsbBus; +use hal::usb::{Peripheral, UsbBus}; use usb_device::class::UsbClass; use crate::crc::Stm32Crc; @@ -44,10 +46,20 @@ fn main() -> ! { let mut gpioa = p.GPIOA.split(&mut rcc.apb2); - let usb_bus = UsbBus::usb_with_reset(p.USB, &mut rcc.apb1, &clocks, &mut gpioa.crh, gpioa.pa12); + let mut pin_dp = gpioa.pa12.into_push_pull_output(&mut gpioa.crh); + pin_dp.set_low().unwrap(); + delay(clocks.sysclk().0 / 100); + let pin_dp = pin_dp.into_floating_input(&mut gpioa.crh); + let pin_dm = gpioa.pa11; + + let usb = Peripheral { + usb: p.USB, + pin_dm, + pin_dp, + }; + let usb_bus = UsbBus::new(usb); let mut usb_class = HidClass::new(Nitrokey::new(crc), &usb_bus); let mut usb_dev = device::create_usb_device(&usb_bus); - usb_dev.force_reset().expect("USB reset failed"); loop { if usb_dev.poll(&mut [&mut usb_class]) { |