Skip to content

Commit 9ecd7a3

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 a83ec0c commit 9ecd7a3

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

framework_lib/src/commandline/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ use crate::power;
5050
use crate::smbios;
5151
use crate::smbios::ConfigDigit0;
5252
use crate::smbios::{dmidecode_string_val, get_smbios, is_framework};
53+
#[cfg(feature = "hidapi")]
54+
use crate::touchscreen::print_touchscreen_fw_ver;
5355
#[cfg(feature = "uefi")]
5456
use crate::uefi::enable_page_break;
5557
use crate::util;
@@ -474,6 +476,8 @@ fn print_versions(ec: &CrosEc) {
474476
}
475477
#[cfg(feature = "rusb")]
476478
check_camera_version();
479+
#[cfg(feature = "hidapi")]
480+
print_touchscreen_fw_ver().unwrap();
477481
}
478482

479483
fn print_esrt() {

framework_lib/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ extern crate log;
1616
pub mod audio_card;
1717
#[cfg(feature = "rusb")]
1818
pub mod camera;
19+
#[cfg(feature = "hidapi")]
20+
pub mod touchscreen;
1921

2022
#[cfg(feature = "uefi")]
2123
#[macro_use]

framework_lib/src/touchscreen.rs

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use hidapi::{HidApi, HidDevice, HidError};
2+
3+
pub const ILI_VID: u16 = 0x32AC;
4+
pub const USI_BITMAP: u8 = 1 << 1;
5+
pub const MPP_BITMAP: u8 = 1 << 2;
6+
7+
fn send_message(device: &HidDevice, message_id: u8, read_len: usize) -> Result<Vec<u8>, HidError> {
8+
let report_id = 0x03;
9+
let write_len = 0x01;
10+
let mut msg = vec![report_id, 0xA3, write_len, read_len as u8, message_id];
11+
device
12+
.send_feature_report(&msg)
13+
.expect("Failed to unlock device");
14+
15+
msg.pop();
16+
let mut buf: [u8; 255] = [0; 255];
17+
device.read(&mut buf[..read_len + msg.len()])?;
18+
Ok(buf[msg.len()..msg.len() + read_len].to_vec())
19+
}
20+
21+
fn check_fw_version(device: &HidDevice) -> Result<(), HidError> {
22+
println!("Touchscreen");
23+
24+
let res = send_message(device, 0x40, 8)?;
25+
let ver = res
26+
.iter()
27+
.skip(1)
28+
.fold(res[0].to_string(), |acc, &x| acc + "." + &x.to_string());
29+
println!(" Firmware Version: v{}", ver);
30+
31+
let res = send_message(device, 0x20, 16)?;
32+
println!(" USI Protocol: {:?}", (res[15] & USI_BITMAP) > 0);
33+
println!(" MPP Protocol: {:?}", (res[15] & MPP_BITMAP) > 0);
34+
35+
Ok(())
36+
}
37+
38+
pub fn print_touchscreen_fw_ver() -> Result<(), HidError> {
39+
match HidApi::new() {
40+
Ok(api) => {
41+
for dev_info in api.device_list() {
42+
let vid = dev_info.vendor_id();
43+
let pid = dev_info.product_id();
44+
let usage_page = dev_info.usage_page();
45+
46+
debug!("Found {:X}:{:X} Usage Page: {}", vid, pid, usage_page);
47+
if vid != 0x222A || pid != 0x5539 {
48+
continue;
49+
}
50+
if usage_page != 0xFF00 {
51+
continue;
52+
}
53+
54+
let device = dev_info.open_device(&api).unwrap();
55+
56+
// On Windows this value is "Control Interface", probably hijacked by the kernel driver
57+
debug!(
58+
" Product String: {}",
59+
dev_info.product_string().unwrap_or("")
60+
);
61+
62+
check_fw_version(&device)?;
63+
}
64+
}
65+
Err(e) => {
66+
eprintln!("Error: {e}");
67+
}
68+
};
69+
70+
Ok(())
71+
}

0 commit comments

Comments
 (0)