Skip to content

Commit de3fd04

Browse files
committed
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 <dhs@frame.work>
1 parent 6824174 commit de3fd04

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

framework_lib/src/touchpad.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
use hidapi::{HidApi, HidDevice, HidError};
22

33
pub const PIX_VID: u16 = 0x093A;
4-
pub const PIX_REPORT_ID: u8 = 0x43;
4+
pub const P274_REPORT_ID: u8 = 0x43;
5+
pub const P239_REPORT_ID: u8 = 0x42;
56

6-
fn read_byte(device: &HidDevice, addr: u8) -> Result<u8, HidError> {
7-
device.send_feature_report(&[PIX_REPORT_ID, addr, 0x10, 0])?;
7+
fn read_byte(device: &HidDevice, report_id: u8, addr: u8) -> Result<u8, HidError> {
8+
device.send_feature_report(&[report_id, addr, 0x10, 0])?;
89

910
let mut buf = [0u8; 4];
10-
buf[0] = PIX_REPORT_ID;
11+
buf[0] = report_id;
1112

1213
device.get_feature_report(&mut buf)?;
1314
Ok(buf[3])
1415
}
1516

16-
fn read_ver(device: &HidDevice) -> Result<u16, HidError> {
17+
fn read_239_ver(device: &HidDevice) -> Result<u16, HidError> {
1718
Ok(u16::from_le_bytes([
18-
read_byte(device, 0xb2)?,
19-
read_byte(device, 0xb3)?,
19+
read_byte(device, P239_REPORT_ID, 0x16)?,
20+
read_byte(device, P239_REPORT_ID, 0x18)?,
21+
]))
22+
}
23+
24+
fn read_274_ver(device: &HidDevice) -> Result<u16, HidError> {
25+
Ok(u16::from_le_bytes([
26+
read_byte(device, P274_REPORT_ID, 0xb2)?,
27+
read_byte(device, P274_REPORT_ID, 0xb3)?,
2028
]))
2129
}
2230

@@ -50,7 +58,13 @@ pub fn print_touchpad_fw_ver() -> Result<(), HidError> {
5058

5159
println!("Touchpad");
5260
println!(" IC Type: {:04X}", pid);
53-
println!(" Firmware Version: v{:04X}", read_ver(&device)?);
61+
let ver = match pid {
62+
0x0239 => format!("{:04X}", read_239_ver(&device)?),
63+
0x0274 => format!("{:04X}", read_274_ver(&device)?),
64+
_ => "Unsupported".to_string(),
65+
};
66+
println!(" Firmware Version: v{}", ver);
67+
5468
// If we found one, there's no need to look for more
5569
return Ok(());
5670
}

0 commit comments

Comments
 (0)