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-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
|
|
|
}
|
2021-12-14 01:50:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {}
|