aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-nrf/src/usb.rs21
-rw-r--r--examples/nrf/src/bin/usb_uart.rs6
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;
8use nrf_usbd::{UsbPeripheral, Usbd}; 8use nrf_usbd::{UsbPeripheral, Usbd};
9use usb_device::bus::UsbBusAllocator; 9use usb_device::bus::UsbBusAllocator;
10 10
11unsafe 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 (); 12pub struct UsbBus;
13unsafe impl UsbPeripheral for UsbBus {
14 // todo hardcoding
15 const REGISTERS: *const () = crate::pac::USBD::ptr() as *const ();
16}
17
18impl UsbBus {
19 pub fn new() -> UsbBusAllocator<Usbd<UsbBus>> {
20 Usbd::new(UsbBus)
21 }
13} 22}
14 23
15unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {} 24unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {}
@@ -20,12 +29,12 @@ pub struct Usb<'d, T: Instance> {
20 29
21impl<'d, T: Instance> Usb<'d, T> { 30impl<'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
44pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static + Send { 53pub 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;
17use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; 17use embassy::io::{AsyncBufReadExt, AsyncWriteExt};
18use embassy::time::{Duration, Timer}; 18use embassy::time::{Duration, Timer};
19use embassy_hal_common::usb::{State, Usb, UsbSerial}; 19use embassy_hal_common::usb::{State, Usb, UsbSerial};
20use embassy_nrf::usb::Usb as UsbDevice; 20use embassy_nrf::usb::{Usb as UsbDevice, UsbBus};
21use embassy_nrf::{interrupt, Peripherals}; 21use embassy_nrf::{interrupt, Peripherals};
22use usb_device::device::{UsbDeviceBuilder, UsbVidPid}; 22use 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