Skip to content

Commit 440157c

Browse files
authored
usbhub: Print firmware version of usb hub (#202)
For example on Framework Desktop: [...] USB Hub RTL5424 Firmware Version: 1.8.8 [...]
1 parent 56522d2 commit 440157c

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

framework_lib/src/commandline/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ use crate::touchpad::print_touchpad_fw_ver;
6060
use crate::touchscreen;
6161
#[cfg(feature = "uefi")]
6262
use crate::uefi::enable_page_break;
63+
#[cfg(feature = "rusb")]
64+
use crate::usbhub::check_usbhub_version;
6365
use crate::util::{self, Config, Platform, PlatformFamily};
6466
#[cfg(feature = "hidapi")]
6567
use hidapi::HidApi;
@@ -705,6 +707,9 @@ fn print_versions(ec: &CrosEc) {
705707
#[cfg(feature = "rusb")]
706708
let _ignore_err = check_camera_version();
707709

710+
#[cfg(feature = "rusb")]
711+
let _ignore_err = check_usbhub_version();
712+
708713
#[cfg(feature = "rusb")]
709714
let _ignore_err = check_inputmodule_version();
710715

framework_lib/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub mod touchpad;
2525
pub mod touchscreen;
2626
#[cfg(all(feature = "hidapi", windows))]
2727
pub mod touchscreen_win;
28+
#[cfg(feature = "rusb")]
29+
pub mod usbhub;
2830

2931
#[cfg(feature = "uefi")]
3032
#[macro_use]

framework_lib/src/usbhub.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
pub const REALTEK_VID: u16 = 0x0BDA;
2+
pub const RTL5432_PID: u16 = 0x5432;
3+
pub const RTL5424_PID: u16 = 0x5424;
4+
5+
/// Get and print the firmware version of the usbhub
6+
pub fn check_usbhub_version() -> Result<(), rusb::Error> {
7+
for dev in rusb::devices().unwrap().iter() {
8+
let dev_descriptor = dev.device_descriptor().unwrap();
9+
if dev_descriptor.vendor_id() != REALTEK_VID
10+
|| (dev_descriptor.product_id() != RTL5432_PID
11+
&& dev_descriptor.product_id() != RTL5424_PID)
12+
{
13+
debug!(
14+
"Skipping {:04X}:{:04X}",
15+
dev_descriptor.vendor_id(),
16+
dev_descriptor.product_id()
17+
);
18+
continue;
19+
}
20+
21+
let dev_descriptor = dev.device_descriptor()?;
22+
println!("USB Hub RTL{:04X}", dev_descriptor.product_id());
23+
println!(" Firmware Version: {}", dev_descriptor.device_version());
24+
}
25+
Ok(())
26+
}

0 commit comments

Comments
 (0)