sorta works, too many interupts?

This commit is contained in:
Jacob Rosenthal
2021-12-14 16:48:48 -07:00
parent 07cbd41131
commit 3debe604fb
3 changed files with 16 additions and 40 deletions

View File

@ -1,14 +1,8 @@
#![macro_use]
use core::marker::PhantomData;
use embassy::util::Unborrow;
use crate::interrupt::Interrupt;
use crate::pac;
use embassy_hal_common::usb::{ClassSet, IntoClassSet, USBInterrupt};
pub use embassy_hal_common::usb::{ReadInterface, State, UsbSerial, WriteInterface};
pub use embassy_hal_common::usb::*;
use nrf_usbd::{UsbPeripheral, Usbd};
use usb_device::{bus::UsbBusAllocator, class_prelude::UsbBus, device::UsbDevice};
use usb_device::bus::UsbBusAllocator;
pub struct UsbThing;
unsafe impl UsbPeripheral for UsbThing {
@ -17,37 +11,20 @@ unsafe impl UsbPeripheral for UsbThing {
}
impl UsbThing {
// todo should it consume a USBD peripheral?
pub fn new() -> UsbBusAllocator<Usbd<UsbThing>> {
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()
})
};
Usbd::new(UsbThing)
}
}
unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {}
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>,
}
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 }
}
}