embassy/embassy-nrf/src/usb.rs

31 lines
823 B
Rust
Raw Normal View History

#![macro_use]
2021-12-15 00:48:48 +01:00
pub use embassy_hal_common::usb::*;
use nrf_usbd::{UsbPeripheral, Usbd};
2021-12-15 00:48:48 +01:00
use usb_device::bus::UsbBusAllocator;
2021-12-14 23:47:54 +01:00
pub struct UsbThing;
unsafe impl UsbPeripheral for UsbThing {
2021-12-14 21:51:50 +01:00
// todo hardcoding
const REGISTERS: *const () = crate::pac::USBD::ptr() as *const ();
}
2021-12-14 23:47:54 +01:00
impl UsbThing {
2021-12-15 00:48:48 +01:00
// todo should it consume a USBD peripheral?
2021-12-14 23:47:54 +01:00
pub fn new() -> UsbBusAllocator<Usbd<UsbThing>> {
2021-12-15 00:48:48 +01:00
unsafe {
(*crate::pac::USBD::ptr()).intenset.write(|w| {
w.sof().set_bit();
w.usbevent().set_bit();
w.ep0datadone().set_bit();
w.ep0setup().set_bit();
w.usbreset().set_bit()
})
};
2021-12-14 23:47:54 +01:00
Usbd::new(UsbThing)
2021-12-14 21:51:50 +01:00
}
}
unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {}