diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index 6776d569..5008b8e6 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs @@ -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> { + 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, - 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, - I: USBInterrupt, -{ - pub unsafe fn new>( - 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 } - } -} diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml index 646ba496..a144cb71 100644 --- a/examples/nrf/Cargo.toml +++ b/examples/nrf/Cargo.toml @@ -9,7 +9,6 @@ version = "0.1.0" embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] } -embassy-hal-common = { version = "0.1.0", path = "../../embassy-hal-common" } defmt = "0.3" defmt-rtt = "0.3" diff --git a/examples/nrf/src/bin/usb_uart.rs b/examples/nrf/src/bin/usb_uart.rs index 9313fdb1..84bce65e 100644 --- a/examples/nrf/src/bin/usb_uart.rs +++ b/examples/nrf/src/bin/usb_uart.rs @@ -16,18 +16,19 @@ use panic_probe as _; // print out panic messages use embassy::executor::Spawner; use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; use embassy::time::{Duration, Timer}; -use embassy_nrf::usb::{ReadInterface, State, Usb, UsbSerial, UsbThing, WriteInterface}; +use embassy_nrf::usb::{State, Usb, UsbSerial, UsbThing}; use embassy_nrf::{interrupt, Peripherals}; use usb_device::device::{UsbDeviceBuilder, UsbVidPid}; #[embassy::main] -async fn main(_spawner: Spawner, p: Peripherals) { +async fn main(_spawner: Spawner, _p: Peripherals) { let mut tx_buffer = [0u8; 1024]; let mut rx_buffer = [0u8; 640]; let usb_bus = UsbThing::new(); let serial = UsbSerial::new(&usb_bus, &mut rx_buffer, &mut tx_buffer); + let device = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd)) .manufacturer("Fake company") .product("Serial port") @@ -42,7 +43,6 @@ async fn main(_spawner: Spawner, p: Peripherals) { let usb = unsafe { Usb::new(&mut state, device, serial, irq) }; pin_mut!(usb); - // usb.start(); let (mut read_interface, mut write_interface) = usb.as_ref().take_serial_0();