aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Rosenthal <[email protected]>2021-12-12 21:32:51 -0700
committerJacob Rosenthal <[email protected]>2021-12-12 21:39:59 -0700
commite5dc63e8e99d1d818ed7ab3b13ffff3ee2c40a3d (patch)
tree001cd24b366eab9d88d658d198dfdf3583db0263
parentf430c0e8c2e9703220978d9976b058ecf0117c45 (diff)
usb feature gate
-rw-r--r--embassy-hal-common/src/usb/mod.rs2
-rw-r--r--embassy-nrf/src/lib.rs26
-rw-r--r--examples/nrf/src/bin/usb_uart.rs2
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
12use crate::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; 12use crate::peripheral::{PeripheralMutex, PeripheralState, StateStorage};
13use embassy::interrupt::Interrupt; 13use embassy::interrupt::Interrupt;
14use usb_serial::{ReadInterface, UsbSerial, WriteInterface}; 14pub 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.
17pub unsafe trait USBInterrupt: Interrupt + Send {} 17pub 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
74pub use chip::{peripherals, Peripherals}; 74pub use chip::{peripherals, Peripherals};
75 75
76use nrf_usbd::{UsbPeripheral, Usbd}; 76#[cfg(any(feature = "nrf52820", feature = "nrf52833", feature = "nrf52840"))]
77use usb_device::bus::UsbBusAllocator; 77pub mod usb {
78 78
79pub struct UsbBus; 79 use nrf_usbd::{UsbPeripheral, Usbd};
80unsafe impl UsbPeripheral for UsbBus { 80 use usb_device::bus::UsbBusAllocator;
81 const REGISTERS: *const () = pac::USBD::ptr() as *const ();
82}
83 81
84impl 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
90unsafe impl embassy_hal_common::usb::USBInterrupt for interrupt::USBD {} 93 unsafe impl embassy_hal_common::usb::USBInterrupt for crate::interrupt::USBD {}
94}
91 95
92pub mod interrupt { 96pub 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;
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::UsbBus; 20use embassy_nrf::usb::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