diff --git a/Cargo.toml b/Cargo.toml index eb07f8c..68664dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,6 @@ [workspace] -members = [ - ".", - "example", -] +members = [".", "example"] +default-members = [".", "example"] [package] name = "nrf-usbd" diff --git a/example/src/main.rs b/example/src/main.rs index d886e08..0b510c1 100644 --- a/example/src/main.rs +++ b/example/src/main.rs @@ -5,6 +5,7 @@ use defmt_rtt as _; use nrf_usbd::{UsbPeripheral, Usbd}; // global logger use panic_probe as _; +use usb_device::class_prelude::UsbBusAllocator; use core::str; use core::sync::atomic::{AtomicUsize, Ordering}; @@ -40,7 +41,7 @@ fn main() -> ! { info!("starting..."); - let usb_bus = Usbd::new(Peripheral); + let usb_bus = UsbBusAllocator::new(Usbd::new(Peripheral)); let mut serial = SerialPort::new(&usb_bus); let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd)) diff --git a/src/usbd.rs b/src/usbd.rs index aacbb15..9de821d 100644 --- a/src/usbd.rs +++ b/src/usbd.rs @@ -11,7 +11,7 @@ use core::mem::MaybeUninit; use core::sync::atomic::{compiler_fence, Ordering}; use critical_section::{CriticalSection, Mutex}; use usb_device::{ - bus::{PollResult, UsbBus, UsbBusAllocator}, + bus::{PollResult, UsbBus}, endpoint::{EndpointAddress, EndpointType}, UsbDirection, UsbError, }; @@ -57,6 +57,11 @@ struct EP0State { } /// USB device implementation. +/// +/// This type implements the [`UsbBus`] trait and can be passed to a [`UsbBusAllocator`] to +/// configure and use the USB device. +/// +/// [`UsbBusAllocator`]: usb_device::bus::UsbBusAllocator pub struct Usbd { _periph: Mutex, // argument passed to `UsbDeviceBuilder.max_packet_size_0` @@ -71,14 +76,14 @@ pub struct Usbd { } impl Usbd { - /// Creates a new USB bus, taking ownership of the raw peripheral. + /// Creates a new USB device wrapper, taking ownership of the raw peripheral. /// /// # Parameters /// /// * `periph`: The raw USBD peripheral. #[inline] - pub fn new(periph: T) -> UsbBusAllocator { - UsbBusAllocator::new(Self { + pub fn new(periph: T) -> Self { + Self { _periph: Mutex::new(periph), max_packet_size_0: 0, bufs: Buffers::new(), @@ -93,7 +98,7 @@ impl Usbd { is_set_address: false, })), busy_in_endpoints: Mutex::new(Cell::new(0)), - }) + } } fn regs<'a>(&self, _cs: &'a CriticalSection) -> &'a RegisterBlock {