Skip to content

framework12: Support reading touchpad version #97

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

Merged
merged 3 commits into from
Apr 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 64 additions & 8 deletions framework_lib/src/touchpad.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
use hidapi::{HidApi, HidDevice, HidError};
use log::Level;

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<u8, HidError> {
device.send_feature_report(&[PIX_REPORT_ID, addr, 0x10, 0])?;
fn read_byte(device: &HidDevice, report_id: u8, addr: u8) -> Result<u8, HidError> {
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<u16, HidError> {
fn read_239_ver(device: &HidDevice) -> Result<u16, HidError> {
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<u16, HidError> {
Ok(u16::from_le_bytes([
read_byte(device, P274_REPORT_ID, 0xb2)?,
read_byte(device, P274_REPORT_ID, 0xb3)?,
]))
}

Expand All @@ -28,6 +37,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();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aokblast could you please check if this value is populated with your changes?
The kernel and hidapi on Linux don't expose that, except for USB. But windows does.
I checked that the FreeBSD kernel does expose it, could you please make sure your hidapi changes do as well?
You can run with -vvv verbose logging and it'll be printed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, we checked that it is populated on FreebBSD.


debug!(
" Found {:04X}:{:04X} (Usage Page {:04X})",
Expand All @@ -50,7 +60,53 @@ 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 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);
#[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(());
}
Expand Down