embassy/embassy-nrf/src/usb.rs

31 lines
813 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-15 17:59:56 +01:00
pub struct UsbBus;
unsafe impl UsbPeripheral for UsbBus {
2021-12-14 21:51:50 +01:00
// todo hardcoding
const REGISTERS: *const () = crate::pac::USBD::ptr() as *const ();
}
2021-12-15 17:59:56 +01:00
impl UsbBus {
2021-12-15 00:48:48 +01:00
// todo should it consume a USBD peripheral?
2021-12-15 17:59:56 +01:00
pub fn new() -> UsbBusAllocator<Usbd<UsbBus>> {
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-15 17:59:56 +01:00
Usbd::new(UsbBus)
2021-12-14 21:51:50 +01:00
}
}
unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {}