-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for getting device information from opened device on Linux #102
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Device descriptor is a good addition. It would be nice to have it on all platforms, but that can be added later if you don't have easy access to macOS and Windows.
I'm not sure the API to get DeviceInfo
is a good idea. Pretty much all the useful information is exposed in the device descriptor here.
For Android, using Java APIs to enumerate devices to populate DeviceInfo
before opening a device is probably a better idea: #86 (comment)
src/enumeration.rs
Outdated
|
||
#[allow(dead_code)] // not used on all platforms | ||
pub(crate) fn from_usb_version(ver: u16) -> Option<Self> { | ||
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, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't assume the speed from the USB version. Plenty of Full Speed devices devices specify 0x0200, or 0x0210 if they support BOS. I'd rather return None than take a wild guess like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank your for the correction! I will change them later.
3a17c2b
to
28cd2b7
Compare
@kevinmehall Besides, I'm trying implementing a new feature that could get device speed from an opened device through an ioctl enum usb_device_speed {
USB_SPEED_UNKNOWN = 0, /* enumerating */
USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */
USB_SPEED_HIGH, /* usb 2.0 */
USB_SPEED_WIRELESS, /* wireless (usb 2.5) */
USB_SPEED_SUPER, /* usb 3.0 */
USB_SPEED_SUPER_PLUS, /* usb 3.1 */
}; |
That seems like a better approach. It should probably return Option to cover the case of newer speeds introduced that we don't know about yet, or failure of the ioctl, and you can use that to leave |
Hi! I'm doing some works on Termux. Termux provides a command
termux-usb
for accessing USB device. But it give me only a file descriptor, and I need to get some basic information about the device. So I did some works to get information about the device itself from opened device.New Public APIs
Device::get_device_descriptor()
fnDevice::get_device_info()
descriptors::DeviceDescriptor
I'm sorry for the mistakes I made.
Changelog
20250108-1
device::Device::get_device_info
descriptors::DeviceDescriptor::speed
descriptors::DeviceDescriptor::format_usb_version
platform::linux_usbfs::device::LinuxDevice::get_busnum_and_devnum
enumeration::Speed::from_usb_version
platform::linux_usbfs::device::LinuxDevice::get_descriptors
todescriptors
Debug
implementation fordescriptors::DeviceDescriptor
to keep the same output formatNote: The type
descriptors::DeviceDescriptor
is defined as USB standard device descriptor.