From 1bf7b4d6c3baceeee0b64f3844fd31928d029917 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sat, 16 Apr 2022 02:17:24 +0200 Subject: [PATCH] usb: rename UsbDeviceBuilder -> Builder. --- embassy-usb-hid/src/lib.rs | 16 ++++------------ embassy-usb-serial/src/lib.rs | 4 ++-- embassy-usb/src/builder.rs | 6 +++--- embassy-usb/src/lib.rs | 2 +- examples/nrf/src/bin/usb_hid_keyboard.rs | 4 ++-- examples/nrf/src/bin/usb_hid_mouse.rs | 4 ++-- examples/nrf/src/bin/usb_serial.rs | 4 ++-- examples/nrf/src/bin/usb_serial_multitask.rs | 4 ++-- 8 files changed, 18 insertions(+), 26 deletions(-) diff --git a/embassy-usb-hid/src/lib.rs b/embassy-usb-hid/src/lib.rs index abcd6b5d..fa4b4743 100644 --- a/embassy-usb-hid/src/lib.rs +++ b/embassy-usb-hid/src/lib.rs @@ -16,7 +16,7 @@ use embassy_usb::driver::EndpointOut; use embassy_usb::{ control::{ControlHandler, InResponse, OutResponse, Request, RequestType}, driver::{Driver, Endpoint, EndpointError, EndpointIn}, - UsbDeviceBuilder, + Builder, }; #[cfg(feature = "usbd-hid")] @@ -98,7 +98,7 @@ pub struct HidReaderWriter<'d, D: Driver<'d>, const READ_N: usize, const WRITE_N } fn build<'d, D: Driver<'d>>( - builder: &mut UsbDeviceBuilder<'d, D>, + builder: &mut Builder<'d, D>, state: &'d mut State<'d>, config: Config<'d>, with_out_endpoint: bool, @@ -160,11 +160,7 @@ impl<'d, D: Driver<'d>, const READ_N: usize, const WRITE_N: usize> /// This will allocate one IN and one OUT endpoints. If you only need writing (sending) /// HID reports, consider using [`HidWriter::new`] instead, which allocates an IN endpoint only. /// - pub fn new( - builder: &mut UsbDeviceBuilder<'d, D>, - state: &'d mut State<'d>, - config: Config<'d>, - ) -> Self { + pub fn new(builder: &mut Builder<'d, D>, state: &'d mut State<'d>, config: Config<'d>) -> Self { let (ep_out, ep_in, offset) = build(builder, state, config, true); Self { @@ -246,11 +242,7 @@ impl<'d, D: Driver<'d>, const N: usize> HidWriter<'d, D, N> { /// HID reports. A lower value means better throughput & latency, at the expense /// of CPU on the device & bandwidth on the bus. A value of 10 is reasonable for /// high performance uses, and a value of 255 is good for best-effort usecases. - pub fn new( - builder: &mut UsbDeviceBuilder<'d, D>, - state: &'d mut State<'d>, - config: Config<'d>, - ) -> Self { + pub fn new(builder: &mut Builder<'d, D>, state: &'d mut State<'d>, config: Config<'d>) -> Self { let (ep_out, ep_in, _offset) = build(builder, state, config, false); assert!(ep_out.is_none()); diff --git a/embassy-usb-serial/src/lib.rs b/embassy-usb-serial/src/lib.rs index 7b25398d..43273902 100644 --- a/embassy-usb-serial/src/lib.rs +++ b/embassy-usb-serial/src/lib.rs @@ -11,7 +11,7 @@ use core::sync::atomic::{AtomicBool, Ordering}; use embassy::blocking_mutex::CriticalSectionMutex; use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request}; use embassy_usb::driver::{Endpoint, EndpointError, EndpointIn, EndpointOut}; -use embassy_usb::{driver::Driver, types::*, UsbDeviceBuilder}; +use embassy_usb::{driver::Driver, types::*, Builder}; /// This should be used as `device_class` when building the `UsbDevice`. pub const USB_CLASS_CDC: u8 = 0x02; @@ -163,7 +163,7 @@ impl<'d, D: Driver<'d>> CdcAcmClass<'d, D> { /// Creates a new CdcAcmClass with the provided UsbBus and max_packet_size in bytes. For /// full-speed devices, max_packet_size has to be one of 8, 16, 32 or 64. pub fn new( - builder: &mut UsbDeviceBuilder<'d, D>, + builder: &mut Builder<'d, D>, state: &'d mut State<'d>, max_packet_size: u16, ) -> Self { diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index 48667205..41cbfa94 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs @@ -118,7 +118,7 @@ impl<'a> Config<'a> { } /// Used to build new [`UsbDevice`]s. -pub struct UsbDeviceBuilder<'d, D: Driver<'d>> { +pub struct Builder<'d, D: Driver<'d>> { config: Config<'d>, handler: Option<&'d dyn DeviceStateHandler>, interfaces: Vec<(u8, &'d mut dyn ControlHandler), MAX_INTERFACE_COUNT>, @@ -134,7 +134,7 @@ pub struct UsbDeviceBuilder<'d, D: Driver<'d>> { pub bos_descriptor: BosWriter<'d>, } -impl<'d, D: Driver<'d>> UsbDeviceBuilder<'d, D> { +impl<'d, D: Driver<'d>> Builder<'d, D> { /// Creates a builder for constructing a new [`UsbDevice`]. /// /// `control_buf` is a buffer used for USB control request data. It should be sized @@ -175,7 +175,7 @@ impl<'d, D: Driver<'d>> UsbDeviceBuilder<'d, D> { config_descriptor.configuration(&config); bos_descriptor.bos(); - UsbDeviceBuilder { + Builder { driver, handler, config, diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index baeca099..7cd00fba 100644 --- a/embassy-usb/src/lib.rs +++ b/embassy-usb/src/lib.rs @@ -19,8 +19,8 @@ use self::descriptor::*; use self::driver::{Bus, Driver, Event}; use self::types::*; +pub use self::builder::Builder; pub use self::builder::Config; -pub use self::builder::UsbDeviceBuilder; /// The global state of the USB device. /// diff --git a/examples/nrf/src/bin/usb_hid_keyboard.rs b/examples/nrf/src/bin/usb_hid_keyboard.rs index a2d78b08..9fa7ab33 100644 --- a/examples/nrf/src/bin/usb_hid_keyboard.rs +++ b/examples/nrf/src/bin/usb_hid_keyboard.rs @@ -17,7 +17,7 @@ use embassy_nrf::pac; use embassy_nrf::usb::Driver; use embassy_nrf::Peripherals; use embassy_usb::control::OutResponse; -use embassy_usb::{Config, DeviceStateHandler, UsbDeviceBuilder}; +use embassy_usb::{Builder, Config, DeviceStateHandler}; use embassy_usb_hid::{HidReaderWriter, ReportId, RequestHandler, State}; use futures::future::join; use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor}; @@ -77,7 +77,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { let mut state = State::new(); - let mut builder = UsbDeviceBuilder::new( + let mut builder = Builder::new( driver, config, &mut device_descriptor, diff --git a/examples/nrf/src/bin/usb_hid_mouse.rs b/examples/nrf/src/bin/usb_hid_mouse.rs index 1e98dd1a..92aeffda 100644 --- a/examples/nrf/src/bin/usb_hid_mouse.rs +++ b/examples/nrf/src/bin/usb_hid_mouse.rs @@ -12,7 +12,7 @@ use embassy_nrf::pac; use embassy_nrf::usb::Driver; use embassy_nrf::Peripherals; use embassy_usb::control::OutResponse; -use embassy_usb::{Config, UsbDeviceBuilder}; +use embassy_usb::{Builder, Config}; use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State}; use futures::future::join; use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; @@ -54,7 +54,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { let mut state = State::new(); - let mut builder = UsbDeviceBuilder::new( + let mut builder = Builder::new( driver, config, &mut device_descriptor, diff --git a/examples/nrf/src/bin/usb_serial.rs b/examples/nrf/src/bin/usb_serial.rs index 987cc413..6081ee91 100644 --- a/examples/nrf/src/bin/usb_serial.rs +++ b/examples/nrf/src/bin/usb_serial.rs @@ -11,7 +11,7 @@ use embassy_nrf::pac; use embassy_nrf::usb::{Driver, Instance}; use embassy_nrf::Peripherals; use embassy_usb::driver::EndpointError; -use embassy_usb::{Config, UsbDeviceBuilder}; +use embassy_usb::{Builder, Config}; use embassy_usb_serial::{CdcAcmClass, State}; use futures::future::join; @@ -47,7 +47,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { let mut state = State::new(); - let mut builder = UsbDeviceBuilder::new( + let mut builder = Builder::new( driver, config, &mut device_descriptor, diff --git a/examples/nrf/src/bin/usb_serial_multitask.rs b/examples/nrf/src/bin/usb_serial_multitask.rs index 5fcb0e05..d4b3000e 100644 --- a/examples/nrf/src/bin/usb_serial_multitask.rs +++ b/examples/nrf/src/bin/usb_serial_multitask.rs @@ -12,7 +12,7 @@ use embassy_nrf::usb::Driver; use embassy_nrf::Peripherals; use embassy_nrf::{interrupt, peripherals}; use embassy_usb::driver::EndpointError; -use embassy_usb::{Config, UsbDevice, UsbDeviceBuilder}; +use embassy_usb::{Builder, Config, UsbDevice}; use embassy_usb_serial::{CdcAcmClass, State}; use defmt_rtt as _; // global logger @@ -72,7 +72,7 @@ async fn main(spawner: Spawner, p: Peripherals) { }); // Create embassy-usb DeviceBuilder using the driver and config. - let mut builder = UsbDeviceBuilder::new( + let mut builder = Builder::new( driver, config, &mut res.device_descriptor,