diff options
| -rw-r--r-- | embassy-hal-common/src/usb/mod.rs | 2 | ||||
| -rw-r--r-- | embassy-nrf/src/lib.rs | 26 | ||||
| -rw-r--r-- | examples/nrf/src/bin/usb_uart.rs | 2 |
3 files changed, 17 insertions, 13 deletions
diff --git a/embassy-hal-common/src/usb/mod.rs b/embassy-hal-common/src/usb/mod.rs index 70a74bd52..bab72d8b6 100644 --- a/embassy-hal-common/src/usb/mod.rs +++ b/embassy-hal-common/src/usb/mod.rs | |||
| @@ -11,7 +11,7 @@ pub mod usb_serial; | |||
| 11 | 11 | ||
| 12 | use crate::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; | 12 | use crate::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; |
| 13 | use embassy::interrupt::Interrupt; | 13 | use embassy::interrupt::Interrupt; |
| 14 | use usb_serial::{ReadInterface, UsbSerial, WriteInterface}; | 14 | pub use usb_serial::{ReadInterface, UsbSerial, WriteInterface}; |
| 15 | 15 | ||
| 16 | /// Marker trait to mark an interrupt to be used with the [`Usb`] abstraction. | 16 | /// Marker trait to mark an interrupt to be used with the [`Usb`] abstraction. |
| 17 | pub unsafe trait USBInterrupt: Interrupt + Send {} | 17 | pub unsafe trait USBInterrupt: Interrupt + Send {} |
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 95e3b3e7b..13e7803a8 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs | |||
| @@ -73,21 +73,25 @@ pub(crate) use chip::pac; | |||
| 73 | 73 | ||
| 74 | pub use chip::{peripherals, Peripherals}; | 74 | pub use chip::{peripherals, Peripherals}; |
| 75 | 75 | ||
| 76 | use nrf_usbd::{UsbPeripheral, Usbd}; | 76 | #[cfg(any(feature = "nrf52820", feature = "nrf52833", feature = "nrf52840"))] |
| 77 | use usb_device::bus::UsbBusAllocator; | 77 | pub mod usb { |
| 78 | 78 | ||
| 79 | pub struct UsbBus; | 79 | use nrf_usbd::{UsbPeripheral, Usbd}; |
| 80 | unsafe impl UsbPeripheral for UsbBus { | 80 | use usb_device::bus::UsbBusAllocator; |
| 81 | const REGISTERS: *const () = pac::USBD::ptr() as *const (); | ||
| 82 | } | ||
| 83 | 81 | ||
| 84 | impl UsbBus { | 82 | pub struct UsbBus; |
| 85 | pub fn new() -> UsbBusAllocator<Usbd<UsbBus>> { | 83 | unsafe impl UsbPeripheral for UsbBus { |
| 86 | Usbd::new(UsbBus) | 84 | const REGISTERS: *const () = crate::pac::USBD::ptr() as *const (); |
| 85 | } | ||
| 86 | |||
| 87 | impl UsbBus { | ||
| 88 | pub fn new() -> UsbBusAllocator<Usbd<UsbBus>> { | ||
| 89 | Usbd::new(UsbBus) | ||
| 90 | } | ||
| 87 | } | 91 | } |
| 88 | } | ||
| 89 | 92 | ||
| 90 | unsafe impl embassy_hal_common::usb::USBInterrupt for interrupt::USBD {} | 93 | unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {} |
| 94 | } | ||
| 91 | 95 | ||
| 92 | pub mod interrupt { | 96 | pub mod interrupt { |
| 93 | pub use crate::chip::irqs::*; | 97 | pub use crate::chip::irqs::*; |
diff --git a/examples/nrf/src/bin/usb_uart.rs b/examples/nrf/src/bin/usb_uart.rs index b81fd5ee8..383edb348 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::UsbBus; | 20 | use embassy_nrf::usb::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 | ||
