Skip to content

Commit 8e192b2

Browse files
committed
touchpad: Show IC type and firmware version
Example on Framework 13: ``` > framework_tool --version [...] Touchpad IC Type: 0274 Firmware Version: v0704 ``` Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 9ecd7a3 commit 8e192b2

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

framework_lib/src/commandline/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ use crate::smbios;
5151
use crate::smbios::ConfigDigit0;
5252
use crate::smbios::{dmidecode_string_val, get_smbios, is_framework};
5353
#[cfg(feature = "hidapi")]
54+
use crate::touchpad::print_touchpad_fw_ver;
55+
#[cfg(feature = "hidapi")]
5456
use crate::touchscreen::print_touchscreen_fw_ver;
5557
#[cfg(feature = "uefi")]
5658
use crate::uefi::enable_page_break;
@@ -478,6 +480,8 @@ fn print_versions(ec: &CrosEc) {
478480
check_camera_version();
479481
#[cfg(feature = "hidapi")]
480482
print_touchscreen_fw_ver().unwrap();
483+
#[cfg(feature = "hidapi")]
484+
print_touchpad_fw_ver().unwrap();
481485
}
482486

483487
fn print_esrt() {

framework_lib/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ pub mod audio_card;
1717
#[cfg(feature = "rusb")]
1818
pub mod camera;
1919
#[cfg(feature = "hidapi")]
20+
pub mod touchpad;
21+
#[cfg(feature = "hidapi")]
2022
pub mod touchscreen;
2123

2224
#[cfg(feature = "uefi")]

framework_lib/src/touchpad.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use hidapi::{HidApi, HidDevice, HidError};
2+
3+
pub const PIX_VID: u16 = 0x093A;
4+
pub const PIX_REPORT_ID: u8 = 0x43;
5+
6+
fn read_byte(device: &HidDevice, addr: u8) -> Result<u8, HidError> {
7+
device.send_feature_report(&[PIX_REPORT_ID, addr, 0x10, 0])?;
8+
9+
let mut buf = [0u8; 4];
10+
buf[0] = PIX_REPORT_ID;
11+
12+
device.get_feature_report(&mut buf)?;
13+
Ok(buf[3])
14+
}
15+
16+
fn read_ver(device: &HidDevice) -> Result<u16, HidError> {
17+
Ok(u16::from_le_bytes([
18+
read_byte(device, 0xb2)?,
19+
read_byte(device, 0xb3)?,
20+
]))
21+
}
22+
23+
pub fn print_touchpad_fw_ver() -> Result<(), HidError> {
24+
match HidApi::new() {
25+
Ok(api) => {
26+
for dev_info in api.device_list() {
27+
let vid = dev_info.vendor_id();
28+
let pid = dev_info.product_id();
29+
let usage_page = dev_info.usage_page();
30+
31+
debug!("Found {:X}:{:X} Usage Page: {}", vid, pid, usage_page);
32+
if vid != PIX_VID || (pid != 0x0274 && pid != 0x0239) {
33+
continue;
34+
}
35+
if usage_page != 0xFF00 {
36+
continue;
37+
}
38+
39+
let device = dev_info.open_device(&api).unwrap();
40+
41+
// On Windows this value is "Control Interface", probably hijacked by the kernel driver
42+
debug!(
43+
" Product String: {}",
44+
dev_info.product_string().unwrap_or("")
45+
);
46+
47+
println!("Touchpad");
48+
println!(" IC Type: {:04X}", pid);
49+
println!(" Firmware Version: v{:04X}", read_ver(&device)?);
50+
}
51+
}
52+
Err(e) => {
53+
eprintln!("Error: {e}");
54+
}
55+
};
56+
57+
Ok(())
58+
}

0 commit comments

Comments
 (0)