2021-12-14 01:50:08 +01:00
|
|
|
#![macro_use]
|
|
|
|
|
|
|
|
use core::marker::PhantomData;
|
|
|
|
use embassy::util::Unborrow;
|
|
|
|
|
|
|
|
use crate::interrupt::Interrupt;
|
|
|
|
use crate::pac;
|
|
|
|
use nrf_usbd::{UsbPeripheral, Usbd};
|
|
|
|
use usb_device::bus::UsbBusAllocator;
|
|
|
|
|
2021-12-14 02:13:38 +01:00
|
|
|
unsafe impl<'d, T: Instance> UsbPeripheral for Usb<'d, T> {
|
|
|
|
const REGISTERS: *const () = T::regs as *const ();
|
2021-12-14 01:50:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {}
|
|
|
|
|
|
|
|
pub struct Usb<'d, T: Instance> {
|
|
|
|
phantom: PhantomData<&'d mut T>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'d, T: Instance> Usb<'d, T> {
|
|
|
|
#[allow(unused_unsafe)]
|
2021-12-14 02:13:38 +01:00
|
|
|
pub fn new(_usb: impl Unborrow<Target = T> + 'd) -> UsbBusAllocator<Usbd<Self>> {
|
2021-12-14 01:50:08 +01:00
|
|
|
let r = T::regs();
|
|
|
|
|
2021-12-14 02:13:38 +01:00
|
|
|
Usbd::new(Self {
|
2021-12-14 01:50:08 +01:00
|
|
|
phantom: PhantomData,
|
2021-12-14 02:13:38 +01:00
|
|
|
})
|
2021-12-14 01:50:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn on_interrupt(_: *mut ()) {
|
|
|
|
let r = T::regs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) mod sealed {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
pub trait Instance {
|
|
|
|
fn regs() -> &'static pac::usbd::RegisterBlock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-14 02:13:38 +01:00
|
|
|
pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static + Send {
|
2021-12-14 01:50:08 +01:00
|
|
|
type Interrupt: Interrupt;
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! impl_usb {
|
|
|
|
($type:ident, $pac_type:ident, $irq:ident) => {
|
|
|
|
impl crate::usb::sealed::Instance for peripherals::$type {
|
|
|
|
fn regs() -> &'static pac::usbd::RegisterBlock {
|
|
|
|
unsafe { &*pac::$pac_type::ptr() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl crate::usb::Instance for peripherals::$type {
|
|
|
|
type Interrupt = crate::interrupt::$irq;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|