Skip to content

Commit

Permalink
Update to usb-device 0.3
Browse files Browse the repository at this point in the history
The new upstream package provides additional driver configurations,
including USB device revisions. Controlling bcdUSB can help users smooth
over device compliance issues.

Our public API is unchanged. However, we're only compatible with
usb-device 0.3 and its associated ecosystem of packages.
  • Loading branch information
mciantyre committed Apr 10, 2024
1 parent cc5381b commit db8b7e1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
[Unreleased]
------------

**BREAKING** Update to `usb-device` 0.3. By adopting this release, you're
required to use `usb-device` 0.3 and its compatible packages.

[0.2.2] 2023-09-15
------------------

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ exclude = [
bitflags = "1.2"
cortex-m = "0.7"
ral-registers = "0.1"
usb-device = "0.2"
usb-device = "0.3"

[dependencies.log]
optional = true
Expand Down
2 changes: 1 addition & 1 deletion src/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub use super::driver::Speed;
/// use usb_device::prelude::*;
/// let bus_allocator = usb_device::bus::UsbBusAllocator::new(bus_adapter);
/// let mut device = UsbDeviceBuilder::new(&bus_allocator, UsbVidPid(0x5824, 0x27dd))
/// .product("imxrt-usbd")
/// .strings(&[StringDescriptors::default().product("imxrt-usbd")]).unwrap()
/// // Other builder methods...
/// .build();
///
Expand Down
18 changes: 14 additions & 4 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ impl Endpoint {
let endptctrl = endpoint_control::register(usb, self.address.index());
match self.address.direction() {
UsbDirection::In => {
ral::modify_reg!(endpoint_control, &endptctrl, ENDPTCTRL, TXE: 0, TXT: EndpointType::Bulk as u32)
ral::modify_reg!(endpoint_control, &endptctrl, ENDPTCTRL, TXE: 0, TXT: into_raw_endpoint_type(EndpointType::Bulk))
}
UsbDirection::Out => {
ral::modify_reg!(endpoint_control, &endptctrl, ENDPTCTRL, RXE: 0, RXT: EndpointType::Bulk as u32)
ral::modify_reg!(endpoint_control, &endptctrl, ENDPTCTRL, RXE: 0, RXT: into_raw_endpoint_type(EndpointType::Bulk))
}
}
}
Expand Down Expand Up @@ -248,10 +248,10 @@ impl Endpoint {
let endptctrl = endpoint_control::register(usb, self.address.index());
match self.address.direction() {
UsbDirection::In => {
ral::modify_reg!(endpoint_control, &endptctrl, ENDPTCTRL, TXE: 1, TXR: 1, TXT: self.kind as u32)
ral::modify_reg!(endpoint_control, &endptctrl, ENDPTCTRL, TXE: 1, TXR: 1, TXT: into_raw_endpoint_type(self.kind))
}
UsbDirection::Out => {
ral::modify_reg!(endpoint_control, &endptctrl, ENDPTCTRL, RXE: 1, RXR: 1, RXT: self.kind as u32)
ral::modify_reg!(endpoint_control, &endptctrl, ENDPTCTRL, RXE: 1, RXR: 1, RXT: into_raw_endpoint_type(self.kind))
}
}
}
Expand Down Expand Up @@ -284,3 +284,13 @@ impl Endpoint {
}
}
}

/// Converts the endpoint type into its ENDPTCTRL endpoint type
/// enumerations.
///
/// See the ENDPTCTRL register documentation in the reference manual.
fn into_raw_endpoint_type(ep_type: EndpointType) -> u32 {
// Bits 0..1 represent the transfer type for the endpoint,
// and it's compatible with ENDPTCTRL's enumerated values.
(ep_type.to_bm_attributes() & 0b11u8).into()
}
2 changes: 1 addition & 1 deletion src/gpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
//! let bus_allocator = usb_device::bus::UsbBusAllocator::new(bus_adapter);
//!
//! let mut device = UsbDeviceBuilder::new(&bus_allocator, UsbVidPid(0x5824, 0x27dd))
//! .product("imxrt-usbd")
//! .strings(&[StringDescriptors::default().product("imxrt-usbd")]).unwrap()
//! .build();
//!
//! // You can still access the timer through the bus() method on
Expand Down

0 comments on commit db8b7e1

Please sign in to comment.