embassy/embassy-nrf/src/usb.rs

54 lines
1.3 KiB
Rust
Raw Normal View History

#![macro_use]
use core::marker::PhantomData;
use embassy::util::Unborrow;
use crate::interrupt::Interrupt;
use crate::pac;
2021-12-14 23:47:54 +01:00
use embassy_hal_common::usb::{ClassSet, IntoClassSet, USBInterrupt};
pub use embassy_hal_common::usb::{ReadInterface, State, UsbSerial, WriteInterface};
use nrf_usbd::{UsbPeripheral, Usbd};
2021-12-14 23:47:54 +01:00
use usb_device::{bus::UsbBusAllocator, class_prelude::UsbBus, device::UsbDevice};
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 {
pub fn new() -> UsbBusAllocator<Usbd<UsbThing>> {
Usbd::new(UsbThing)
2021-12-14 21:51:50 +01:00
}
}
unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {}
2021-12-14 23:47:54 +01:00
pub struct Usb<'bus, B, T, I>
where
B: UsbBus,
T: ClassSet<B>,
I: USBInterrupt,
{
// Don't you dare moving out `PeripheralMutex`
usb: embassy_hal_common::usb::Usb<'bus, B, T, I>,
}
2021-12-14 23:47:54 +01:00
impl<'bus, B, T, I> Usb<'bus, B, T, I>
where
B: UsbBus,
T: ClassSet<B>,
I: USBInterrupt,
{
pub unsafe fn new<S: IntoClassSet<B, T>>(
state: &'bus mut State<'bus, B, T, I>,
device: UsbDevice<'bus, B>,
class_set: S,
irq: I,
) -> Self {
let usb = embassy_hal_common::usb::Usb::new(state, device, class_set, irq);
Self { usb }
}
}