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 21:51:50 +01:00
|
|
|
// todo using different type than Usb because T isnt Send
|
|
|
|
pub struct UsbBus;
|
|
|
|
unsafe impl UsbPeripheral for UsbBus {
|
|
|
|
// todo hardcoding
|
|
|
|
const REGISTERS: *const () = crate::pac::USBD::ptr() as *const ();
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UsbBus {
|
|
|
|
pub fn new() -> UsbBusAllocator<Usbd<UsbBus>> {
|
|
|
|
Usbd::new(UsbBus)
|
|
|
|
}
|
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 21:51:50 +01:00
|
|
|
pub fn new(_usb: impl Unborrow<Target = T> + 'd) -> Self {
|
2021-12-14 01:50:08 +01:00
|
|
|
let r = T::regs();
|
|
|
|
|
2021-12-14 21:51:50 +01:00
|
|
|
Self {
|
2021-12-14 01:50:08 +01:00
|
|
|
phantom: PhantomData,
|
2021-12-14 21:51:50 +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 21:51:50 +01:00
|
|
|
pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static {
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|