Skip to content

Commit 844b782

Browse files
Use nrf-usbd
1 parent dbe0b5a commit 844b782

File tree

7 files changed

+35
-793
lines changed

7 files changed

+35
-793
lines changed

examples/usb/src/bin/serial.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
use panic_semihosting as _;
55

66
use cortex_m_rt::entry;
7-
use nrf52840_hal::usbd::Usbd;
87
use nrf52840_hal::clocks::Clocks;
8+
use nrf52840_hal::usbd::{UsbPeripheral, Usbd};
99
use nrf52840_pac::Peripherals;
1010
use usb_device::device::{UsbDeviceBuilder, UsbVidPid};
1111
use usbd_serial::{SerialPort, USB_CLASS_CDC};
@@ -16,7 +16,7 @@ fn main() -> ! {
1616
let clocks = Clocks::new(periph.CLOCK);
1717
let clocks = clocks.enable_ext_hfosc();
1818

19-
let usb_bus = Usbd::new(periph.USBD, &clocks);
19+
let usb_bus = Usbd::new(UsbPeripheral::new(periph.USBD, &clocks));
2020
let mut serial = SerialPort::new(&usb_bus);
2121

2222
let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd))
@@ -48,8 +48,8 @@ fn main() -> ! {
4848
match serial.write(&buf[write_offset..count]) {
4949
Ok(len) if len > 0 => {
5050
write_offset += len;
51-
},
52-
_ => {},
51+
}
52+
_ => {}
5353
}
5454
}
5555
}

examples/usb/src/bin/test_class.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
use panic_semihosting as _;
55

66
use cortex_m_rt::entry;
7-
use nrf52840_hal::usbd::Usbd;
87
use nrf52840_hal::clocks::Clocks;
8+
use nrf52840_hal::usbd::{UsbPeripheral, Usbd};
99
use nrf52840_pac::Peripherals;
1010
use usb_device::test_class::TestClass;
1111

@@ -15,7 +15,7 @@ fn main() -> ! {
1515
let clocks = Clocks::new(periph.CLOCK);
1616
let clocks = clocks.enable_ext_hfosc();
1717

18-
let usb_bus = Usbd::new(periph.USBD, &clocks);
18+
let usb_bus = Usbd::new(UsbPeripheral::new(periph.USBD, &clocks));
1919

2020
let mut test = TestClass::new(&usb_bus);
2121

nrf-hal-common/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ version = "0.2.3"
3939
optional = true
4040
version = "0.9.0"
4141

42-
[dependencies.usb-device]
43-
version = "0.2.7"
44-
optional = true
45-
4642
[dependencies.nrf52810-pac]
4743
optional = true
4844
version = "0.9.0"
@@ -67,6 +63,10 @@ version = "0.9.0"
6763
optional = true
6864
version = "0.2.1"
6965

66+
[dependencies.nrf-usbd]
67+
git = "https://github.com/nrf-rs/nrf-usbd.git"
68+
optional = true
69+
7070
[dependencies.embedded-hal]
7171
features = ["unproven"]
7272
version = "0.2.4"
@@ -77,6 +77,6 @@ doc = []
7777
52810 = ["nrf52810-pac"]
7878
52811 = ["nrf52811-pac"]
7979
52832 = ["nrf52832-pac"]
80-
52833 = ["nrf52833-pac", "usb-device"]
81-
52840 = ["nrf52840-pac", "usb-device"]
80+
52833 = ["nrf52833-pac", "nrf-usbd"]
81+
52840 = ["nrf52840-pac", "nrf-usbd"]
8282
9160 = ["nrf9160-pac"]

nrf-hal-common/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ pub mod uart;
8080
pub mod uarte;
8181
#[cfg(not(feature = "9160"))]
8282
pub mod uicr;
83-
pub mod wdt;
84-
#[cfg(feature = "usb-device")]
83+
#[cfg(feature = "nrf-usbd")]
8584
pub mod usbd;
85+
pub mod wdt;
8686

8787
pub mod prelude {
8888
pub use crate::hal::digital::v2::*;

nrf-hal-common/src/usbd.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use crate::clocks::ExternalOscillator;
2+
use crate::pac::USBD;
3+
use crate::Clocks;
4+
5+
pub use nrf_usbd::Usbd;
6+
7+
#[allow(dead_code)] // fields are unused and only hold ownership
8+
pub struct UsbPeripheral<'a> {
9+
usbd: USBD,
10+
clocks: &'a (),
11+
}
12+
13+
impl<'a> UsbPeripheral<'a> {
14+
pub fn new<L, LSTAT>(usbd: USBD, _clocks: &'a Clocks<ExternalOscillator, L, LSTAT>) -> Self {
15+
Self { usbd, clocks: &() }
16+
}
17+
}
18+
19+
unsafe impl<'a> nrf_usbd::UsbPeripheral for UsbPeripheral<'a> {
20+
const REGISTERS: *const () = USBD::ptr() as *const _;
21+
}

nrf-hal-common/src/usbd/errata.rs

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)