From de3fd04ac7d8cb980f8fef90c85ecc61823567d9 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Tue, 25 Mar 2025 13:41:09 +0800 Subject: [PATCH 1/3] framework12: Support reading touchpad version Must already be on firmware 0E06 or higher. ``` > framework_tool --versions [...] Touchpad IC Type: 0239 Firmware Version: v0E06 ``` Signed-off-by: Daniel Schaefer --- framework_lib/src/touchpad.rs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/framework_lib/src/touchpad.rs b/framework_lib/src/touchpad.rs index fe4be04d..e3c2f4da 100644 --- a/framework_lib/src/touchpad.rs +++ b/framework_lib/src/touchpad.rs @@ -1,22 +1,30 @@ use hidapi::{HidApi, HidDevice, HidError}; pub const PIX_VID: u16 = 0x093A; -pub const PIX_REPORT_ID: u8 = 0x43; +pub const P274_REPORT_ID: u8 = 0x43; +pub const P239_REPORT_ID: u8 = 0x42; -fn read_byte(device: &HidDevice, addr: u8) -> Result { - device.send_feature_report(&[PIX_REPORT_ID, addr, 0x10, 0])?; +fn read_byte(device: &HidDevice, report_id: u8, addr: u8) -> Result { + device.send_feature_report(&[report_id, addr, 0x10, 0])?; let mut buf = [0u8; 4]; - buf[0] = PIX_REPORT_ID; + buf[0] = report_id; device.get_feature_report(&mut buf)?; Ok(buf[3]) } -fn read_ver(device: &HidDevice) -> Result { +fn read_239_ver(device: &HidDevice) -> Result { Ok(u16::from_le_bytes([ - read_byte(device, 0xb2)?, - read_byte(device, 0xb3)?, + read_byte(device, P239_REPORT_ID, 0x16)?, + read_byte(device, P239_REPORT_ID, 0x18)?, + ])) +} + +fn read_274_ver(device: &HidDevice) -> Result { + Ok(u16::from_le_bytes([ + read_byte(device, P274_REPORT_ID, 0xb2)?, + read_byte(device, P274_REPORT_ID, 0xb3)?, ])) } @@ -50,7 +58,13 @@ pub fn print_touchpad_fw_ver() -> Result<(), HidError> { println!("Touchpad"); println!(" IC Type: {:04X}", pid); - println!(" Firmware Version: v{:04X}", read_ver(&device)?); + let ver = match pid { + 0x0239 => format!("{:04X}", read_239_ver(&device)?), + 0x0274 => format!("{:04X}", read_274_ver(&device)?), + _ => "Unsupported".to_string(), + }; + println!(" Firmware Version: v{}", ver); + // If we found one, there's no need to look for more return Ok(()); } From e85b0d3853514649b3ac31ac763e59bdafe0e722 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sun, 30 Mar 2025 12:17:04 +0800 Subject: [PATCH 2/3] touchpad: Also print HID descriptor version On Windows you can read it using HidD_GetAttributes. The Linux kernel does not expose this. Signed-off-by: Daniel Schaefer --- framework_lib/src/touchpad.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/framework_lib/src/touchpad.rs b/framework_lib/src/touchpad.rs index e3c2f4da..08146b72 100644 --- a/framework_lib/src/touchpad.rs +++ b/framework_lib/src/touchpad.rs @@ -36,6 +36,7 @@ pub fn print_touchpad_fw_ver() -> Result<(), HidError> { let vid = dev_info.vendor_id(); let pid = dev_info.product_id(); let usage_page = dev_info.usage_page(); + let hid_ver = dev_info.release_number(); debug!( " Found {:04X}:{:04X} (Usage Page {:04X})", @@ -58,6 +59,7 @@ pub fn print_touchpad_fw_ver() -> Result<(), HidError> { println!("Touchpad"); println!(" IC Type: {:04X}", pid); + let ver = match pid { 0x0239 => format!("{:04X}", read_239_ver(&device)?), 0x0274 => format!("{:04X}", read_274_ver(&device)?), @@ -65,6 +67,16 @@ pub fn print_touchpad_fw_ver() -> Result<(), HidError> { }; println!(" Firmware Version: v{}", ver); + // Linux does not expose a useful version number for I2C HID devices + #[cfg(target_os = "linux")] + debug!(" HID Version {:04X}", hid_ver); + #[cfg(not(target_os = "linux"))] + if ver != format!("{:04X}", hid_ver) { + println!(" HID Version v{:04X}", hid_ver); + } else if log_enabled!(Level::Debug) { + println!(" HID Version v{:04X}", hid_ver); + } + // If we found one, there's no need to look for more return Ok(()); } From 6e1d4119716e452daa80575d6202b9084fc78f5b Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sat, 29 Mar 2025 19:05:29 +0800 Subject: [PATCH 3/3] touchpad: Dump whole config space Signed-off-by: Daniel Schaefer --- framework_lib/src/touchpad.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/framework_lib/src/touchpad.rs b/framework_lib/src/touchpad.rs index 08146b72..72bc30c8 100644 --- a/framework_lib/src/touchpad.rs +++ b/framework_lib/src/touchpad.rs @@ -1,4 +1,5 @@ use hidapi::{HidApi, HidDevice, HidError}; +use log::Level; pub const PIX_VID: u16 = 0x093A; pub const P274_REPORT_ID: u8 = 0x43; @@ -67,6 +68,35 @@ pub fn print_touchpad_fw_ver() -> Result<(), HidError> { }; println!(" Firmware Version: v{}", ver); + if log_enabled!(Level::Debug) { + println!(" Config space 1"); + print!(" "); + for x in 0..16 { + print!("0{:X} ", x); + } + println!(); + for y in 0..16 { + print!("{:X}0 ", y); + for x in 0..16 { + print!("{:02X} ", read_byte(&device, 0x42, x + 16 * y)?); + } + println!(); + } + println!(" Config space 2"); + print!(" "); + for x in 0..16 { + print!("0{:X} ", x); + } + println!(); + for y in 0..16 { + print!("{:X}0 ", y); + for x in 0..16 { + print!("{:02X} ", read_byte(&device, 0x43, x + 16 * y)?); + } + println!(); + } + } + // Linux does not expose a useful version number for I2C HID devices #[cfg(target_os = "linux")] debug!(" HID Version {:04X}", hid_ver);