diff options
| author | Jacob Rosenthal <[email protected]> | 2021-12-13 18:13:38 -0700 |
|---|---|---|
| committer | Jacob Rosenthal <[email protected]> | 2021-12-13 18:13:42 -0700 |
| commit | 535d30335a7c4ae47e923c5e85851df80d2021a0 (patch) | |
| tree | 87523cad2e1a09242cee781b2af27869f30a2850 | |
| parent | 83a1237ea3f8b164749cb895b7bdb7a5696107f6 (diff) | |
make send, consolidate usb types
| -rw-r--r-- | embassy-nrf/src/usb.rs | 21 | ||||
| -rw-r--r-- | examples/nrf/src/bin/usb_uart.rs | 6 |
2 files changed, 8 insertions, 19 deletions
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index ca1d656a1..4e3fcaaad 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs | |||
| @@ -8,17 +8,8 @@ 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 | // todo using different type than Usb because T isnt Send | 11 | unsafe impl<'d, T: Instance> UsbPeripheral for Usb<'d, T> { |
| 12 | pub struct UsbBus; | 12 | const REGISTERS: *const () = T::regs as *const (); |
| 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 | } | ||
| 22 | } | 13 | } |
| 23 | 14 | ||
| 24 | unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {} | 15 | unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {} |
| @@ -29,12 +20,12 @@ pub struct Usb<'d, T: Instance> { | |||
| 29 | 20 | ||
| 30 | impl<'d, T: Instance> Usb<'d, T> { | 21 | impl<'d, T: Instance> Usb<'d, T> { |
| 31 | #[allow(unused_unsafe)] | 22 | #[allow(unused_unsafe)] |
| 32 | pub fn new(_usb: impl Unborrow<Target = T> + 'd) -> Self { | 23 | pub fn new(_usb: impl Unborrow<Target = T> + 'd) -> UsbBusAllocator<Usbd<Self>> { |
| 33 | let r = T::regs(); | 24 | let r = T::regs(); |
| 34 | 25 | ||
| 35 | Self { | 26 | Usbd::new(Self { |
| 36 | phantom: PhantomData, | 27 | phantom: PhantomData, |
| 37 | } | 28 | }) |
| 38 | } | 29 | } |
| 39 | 30 | ||
| 40 | fn on_interrupt(_: *mut ()) { | 31 | fn on_interrupt(_: *mut ()) { |
| @@ -50,7 +41,7 @@ pub(crate) mod sealed { | |||
| 50 | } | 41 | } |
| 51 | } | 42 | } |
| 52 | 43 | ||
| 53 | pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static { | 44 | pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static + Send { |
| 54 | type Interrupt: Interrupt; | 45 | type Interrupt: Interrupt; |
| 55 | } | 46 | } |
| 56 | 47 | ||
diff --git a/examples/nrf/src/bin/usb_uart.rs b/examples/nrf/src/bin/usb_uart.rs index 902075dfc..86ead84b5 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, UsbBus}; | 20 | use embassy_nrf::usb::Usb as UsbDevice; |
| 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,9 +26,7 @@ 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_dev = UsbDevice::new(p.USBD); | 29 | let usb_bus = UsbDevice::new(p.USBD); |
| 30 | |||
| 31 | let usb_bus = UsbBus::new(); | ||
| 32 | 30 | ||
| 33 | let serial = UsbSerial::new(&usb_bus, &mut rx_buffer, &mut tx_buffer); | 31 | let serial = UsbSerial::new(&usb_bus, &mut rx_buffer, &mut tx_buffer); |
| 34 | 32 | ||
