From ffd8202f009f76813a0279c9cb30f43f02cbd733 Mon Sep 17 00:00:00 2001 From: kirisauce Date: Wed, 8 Jan 2025 00:48:53 +0800 Subject: [PATCH] Fix: Avoid judging speed from its USB version and adjust Debug implementation --- src/descriptors.rs | 34 +++++++--------------------------- src/enumeration.rs | 12 ------------ 2 files changed, 7 insertions(+), 39 deletions(-) diff --git a/src/descriptors.rs b/src/descriptors.rs index 9cd6338..4a9cd96 100644 --- a/src/descriptors.rs +++ b/src/descriptors.rs @@ -13,7 +13,6 @@ use std::{ use log::warn; use crate::{ - enumeration::Speed, transfer::{Direction, EndpointType}, Error, }; @@ -201,11 +200,6 @@ impl<'a> DeviceDescriptor<'a> { assert!(buf[1] == DESCRIPTOR_TYPE_DEVICE); Self(buf) } - - /// Get speed of this device. The speed is judged by `usb_version` field. - pub fn speed(&self) -> Option { - Speed::from_usb_version(self.usb_version()) - } } descriptor_fields! { @@ -257,32 +251,19 @@ descriptor_fields! { } } -fn format_usb_version(ver: u16) -> &'static str { - match ver { - 0x0100 => "1.0", - 0x0110 => "1.1", - 0x0200 => "2.0", - 0x0210 => "2.0", // This means a USB 3.x device is running in USB 2.0 mode - 0x0300 => "3.0", - 0x0310 => "3.1", - 0x0320 => "3.2", - _ => "unknown", - } -} - impl<'a> Debug for DeviceDescriptor<'a> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("DeviceDescriptor") - .field("usb_version", &format_usb_version(self.usb_version())) - .field("class", &format_args!("0x{:02x}", self.class())) - .field("subclass", &format_args!("0x{:02x}", self.subclass())) - .field("protocol", &format_args!("0x{:02x}", self.protocol())) + .field("usb_version", &format_args!("0x{:04X}", self.usb_version())) + .field("class", &format_args!("0x{:02X}", self.class())) + .field("subclass", &format_args!("0x{:02X}", self.subclass())) + .field("protocol", &format_args!("0x{:02X}", self.protocol())) .field("max_packet_size_0", &self.max_packet_size_0()) - .field("vendor_id", &format_args!("0x{:04x}", self.vendor_id())) - .field("product_id", &format_args!("0x{:04x}", self.product_id())) + .field("vendor_id", &format_args!("0x{:04X}", self.vendor_id())) + .field("product_id", &format_args!("0x{:04X}", self.product_id())) .field( "device_version", - &format_args!("0x{:04x}", self.device_version()), + &format_args!("0x{:04X}", self.device_version()), ) .field( "manufacturer_string_index", @@ -294,7 +275,6 @@ impl<'a> Debug for DeviceDescriptor<'a> { &self.serial_number_string_index(), ) .field("num_configurations", &self.num_configurations()) - .field("speed", &self.speed()) .finish() } } diff --git a/src/enumeration.rs b/src/enumeration.rs index d3a109a..4acc573 100644 --- a/src/enumeration.rs +++ b/src/enumeration.rs @@ -370,18 +370,6 @@ impl Speed { _ => None, } } - - #[allow(dead_code)] // not used on all platforms - pub(crate) fn from_usb_version(ver: u16) -> Option { - match ver { - 0x0100 => Some(Speed::Low), - 0x0110 => Some(Speed::Full), - 0x0200 | 0x0210 => Some(Speed::High), - 0x0300 => Some(Speed::Super), - 0x0310 | 0x0320 => Some(Speed::SuperPlus), - _ => None, - } - } } /// Summary information about a device's interface, available before opening a device.