2021-12-14 01:50:08 +01:00
|
|
|
#![macro_use]
|
|
|
|
|
2021-12-15 00:48:48 +01:00
|
|
|
pub use embassy_hal_common::usb::*;
|
2021-12-14 01:50:08 +01:00
|
|
|
use nrf_usbd::{UsbPeripheral, Usbd};
|
2021-12-15 00:48:48 +01:00
|
|
|
use usb_device::bus::UsbBusAllocator;
|
2021-12-14 01:50:08 +01:00
|
|
|
|
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
|
|
|
}
|
2021-12-14 01:50:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {}
|