diff options
| author | Jacob Rosenthal <[email protected]> | 2021-12-14 13:51:50 -0700 |
|---|---|---|
| committer | Jacob Rosenthal <[email protected]> | 2021-12-14 13:51:50 -0700 |
| commit | f31140a70bbc7c14b07acf6305eb8a0a73560e5a (patch) | |
| tree | 93b4a873ebcaf88eadc35fd33e39c3b4f1817845 | |
| parent | 535d30335a7c4ae47e923c5e85851df80d2021a0 (diff) | |
revert
| -rw-r--r-- | embassy-nrf/src/usb.rs | 21 | ||||
| -rw-r--r-- | examples/nrf/src/bin/usb_uart.rs | 6 |
2 files changed, 19 insertions, 8 deletions
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index 4e3fcaaad..ca1d656a1 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs | |||
| @@ -8,8 +8,17 @@ use crate::pac; | |||
| 8 | use nrf_usbd::{UsbPeripheral, Usbd}; | 8 | use nrf_usbd::{UsbPeripheral, Usbd}; |
| 9 | use usb_device::bus::UsbBusAllocator; | 9 | use usb_device::bus::UsbBusAllocator; |
| 10 | 10 | ||
| 11 | unsafe impl<'d, T: Instance> UsbPeripheral for Usb<'d, T> { | 11 | // todo using different type than Usb because T isnt Send |
| 12 | const REGISTERS: *const () = T::regs as *const (); | 12 | pub struct UsbBus; |
| 13 | unsafe impl UsbPeripheral for UsbBus { | ||
| 14 | // todo hardcoding | ||
| 15 | const REGISTERS: *const () = crate::pac::USBD::ptr() as *const (); | ||
| 16 | } | ||
| 17 | |||
| 18 | impl UsbBus { | ||
| 19 | pub fn new() -> UsbBusAllocator<Usbd<UsbBus>> { | ||
| 20 | Usbd::new(UsbBus) | ||
| 21 | } | ||
| 13 | } | 22 | } |
| 14 | 23 | ||
| 15 | unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {} | 24 | unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {} |
| @@ -20,12 +29,12 @@ pub struct Usb<'d, T: Instance> { | |||
| 20 | 29 | ||
| 21 | impl<'d, T: Instance> Usb<'d, T> { | 30 | impl<'d, T: Instance> Usb<'d, T> { |
| 22 | #[allow(unused_unsafe)] | 31 | #[allow(unused_unsafe)] |
| 23 | pub fn new(_usb: impl Unborrow<Target = T> + 'd) -> UsbBusAllocator<Usbd<Self>> { | 32 | pub fn new(_usb: impl Unborrow<Target = T> + 'd) -> Self { |
| 24 | let r = T::regs(); | 33 | let r = T::regs(); |
| 25 | 34 | ||
| 26 | Usbd::new(Self { | 35 | Self { |
| 27 | phantom: PhantomData, | 36 | phantom: PhantomData, |
| 28 | }) | 37 | } |
| 29 | } | 38 | } |
| 30 | 39 | ||
| 31 | fn on_interrupt(_: *mut ()) { | 40 | fn on_interrupt(_: *mut ()) { |
| @@ -41,7 +50,7 @@ pub(crate) mod sealed { | |||
| 41 | } | 50 | } |
| 42 | } | 51 | } |
| 43 | 52 | ||
| 44 | pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static + Send { | 53 | pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static { |
| 45 | type Interrupt: Interrupt; | 54 | type Interrupt: Interrupt; |
| 46 | } | 55 | } |
| 47 | 56 | ||
diff --git a/examples/nrf/src/bin/usb_uart.rs b/examples/nrf/src/bin/usb_uart.rs index 86ead84b5..902075dfc 100644 --- a/examples/nrf/src/bin/usb_uart.rs +++ b/examples/nrf/src/bin/usb_uart.rs | |||
| @@ -17,7 +17,7 @@ use embassy::executor::Spawner; | |||
| 17 | use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; | 17 | use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; |
| 18 | use embassy::time::{Duration, Timer}; | 18 | use embassy::time::{Duration, Timer}; |
| 19 | use embassy_hal_common::usb::{State, Usb, UsbSerial}; | 19 | use embassy_hal_common::usb::{State, Usb, UsbSerial}; |
| 20 | use embassy_nrf::usb::Usb as UsbDevice; | 20 | use embassy_nrf::usb::{Usb as UsbDevice, UsbBus}; |
| 21 | use embassy_nrf::{interrupt, Peripherals}; | 21 | use embassy_nrf::{interrupt, Peripherals}; |
| 22 | use usb_device::device::{UsbDeviceBuilder, UsbVidPid}; | 22 | use usb_device::device::{UsbDeviceBuilder, UsbVidPid}; |
| 23 | 23 | ||
| @@ -26,7 +26,9 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 26 | let mut tx_buffer = [0u8; 1024]; | 26 | let mut tx_buffer = [0u8; 1024]; |
| 27 | let mut rx_buffer = [0u8; 640]; | 27 | let mut rx_buffer = [0u8; 640]; |
| 28 | 28 | ||
| 29 | let usb_bus = UsbDevice::new(p.USBD); | 29 | let _usb_dev = UsbDevice::new(p.USBD); |
| 30 | |||
| 31 | let usb_bus = UsbBus::new(); | ||
| 30 | 32 | ||
| 31 | let serial = UsbSerial::new(&usb_bus, &mut rx_buffer, &mut tx_buffer); | 33 | let serial = UsbSerial::new(&usb_bus, &mut rx_buffer, &mut tx_buffer); |
| 32 | 34 | ||
