Skip to content

Commit 0ba2b1d

Browse files
committed
touchscreen: Dump firmware version and protocol
``` > framework_tool --versions [...] Touchscreen Firmware Version: v7.0.0.4.0.0.0.0 USI Protocol: false MPP Protocol: true ``` Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 64c5561 commit 0ba2b1d

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

framework_lib/src/commandline/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use crate::smbios::ConfigDigit0;
5252
use crate::smbios::{dmidecode_string_val, get_smbios, is_framework};
5353
#[cfg(feature = "hidapi")]
5454
use crate::touchpad::print_touchpad_fw_ver;
55+
use crate::touchscreen::print_touchscreen_fw_ver;
5556
#[cfg(feature = "uefi")]
5657
use crate::uefi::enable_page_break;
5758
use crate::util;
@@ -479,6 +480,9 @@ fn print_versions(ec: &CrosEc) {
479480

480481
#[cfg(feature = "hidapi")]
481482
let _ignore_err = print_touchpad_fw_ver();
483+
484+
#[cfg(feature = "hidapi")]
485+
let _ignore_err = print_touchscreen_fw_ver();
482486
}
483487

484488
fn print_esrt() {

framework_lib/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub mod audio_card;
1818
pub mod camera;
1919
#[cfg(feature = "hidapi")]
2020
pub mod touchpad;
21+
#[cfg(feature = "hidapi")]
22+
pub mod touchscreen;
2123

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

framework_lib/src/touchscreen.rs

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
use hidapi::{HidApi, HidDevice, HidError};
2+
3+
pub const ILI_VID: u16 = 0x222A;
4+
pub const ILI_PID: u16 = 0x5539;
5+
pub const USI_BITMAP: u8 = 1 << 1;
6+
pub const MPP_BITMAP: u8 = 1 << 2;
7+
8+
fn send_message(device: &HidDevice, message_id: u8, read_len: usize) -> Result<Vec<u8>, HidError> {
9+
let report_id = 0x03;
10+
let write_len = 0x01;
11+
let mut msg = vec![report_id, 0xA3, write_len, read_len as u8, message_id];
12+
device.send_feature_report(&msg)?;
13+
14+
msg.pop();
15+
let mut buf: [u8; 255] = [0; 255];
16+
device.read(&mut buf[..read_len + msg.len()])?;
17+
Ok(buf[msg.len()..msg.len() + read_len].to_vec())
18+
}
19+
20+
fn check_fw_version(device: &HidDevice) -> Result<(), HidError> {
21+
let res = send_message(device, 0x40, 8)?;
22+
let ver = res
23+
.iter()
24+
.skip(1)
25+
.fold(res[0].to_string(), |acc, &x| acc + "." + &x.to_string());
26+
println!(" Firmware Version: v{}", ver);
27+
28+
let res = send_message(device, 0x20, 16)?;
29+
println!(" USI Protocol: {:?}", (res[15] & USI_BITMAP) > 0);
30+
println!(" MPP Protocol: {:?}", (res[15] & MPP_BITMAP) > 0);
31+
32+
Ok(())
33+
}
34+
35+
pub fn print_touchscreen_fw_ver() -> Result<(), HidError> {
36+
debug!("Looking for touchscreen HID device");
37+
match HidApi::new() {
38+
Ok(api) => {
39+
for dev_info in api.device_list() {
40+
let vid = dev_info.vendor_id();
41+
let pid = dev_info.product_id();
42+
let usage_page = dev_info.usage_page();
43+
44+
debug!(" Found {:04X}:{:04X} (Usage Page {:04X})", vid, pid, usage_page);
45+
if vid != ILI_VID {
46+
debug!(" Skipping VID:PID. Expected {:04X}:*", ILI_VID);
47+
continue;
48+
}
49+
if usage_page != 0xFF00 {
50+
debug!(" Skipping usage page. Expected {:04X}", 0xFF00);
51+
continue;
52+
}
53+
if pid != ILI_PID {
54+
debug!(" Warning: PID is {:04X}, expected {:04X}", pid, ILI_PID);
55+
}
56+
57+
debug!(" Found matching touchscreen HID device");
58+
println!("Touchscreen");
59+
println!(" IC Type: {:04X}", pid);
60+
61+
// Unwrapping because if we can enumerate it, we should be able to open it
62+
let device = dev_info.open_device(&api).unwrap();
63+
if let Err(e) = check_fw_version(&device) {
64+
error!("Failed to read touchscreen firmware version {:?}", e);
65+
continue;
66+
};
67+
}
68+
}
69+
Err(e) => {
70+
eprintln!("Failed to open hidapi. Error: {e}");
71+
return Err(e);
72+
}
73+
};
74+
75+
Ok(())
76+
}

0 commit comments

Comments
 (0)