Skip to content

Commit 8b26bcd

Browse files
committed
Allow reading touchscreen version on Laptop 13
Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 82a9544 commit 8b26bcd

3 files changed

Lines changed: 87 additions & 3 deletions

File tree

EXAMPLES.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,23 @@ Laptop Webcam Module (2nd Gen)
199199
Firmware Version: 1.1.1
200200
```
201201

202-
### Touchscreen (Laptop 12)
202+
### Touchscreen (Laptop 12, Laptop 13)
203203

204204
```
205+
# Laptop 12
205206
> framework_tool --versions
206207
[...]
207208
Touchscreen
208209
Firmware Version: v7.0.0.5.0.0.0.0
209210
Protocols: USI
211+
[...]
212+
213+
# Laptop 13
214+
> framework_tool --versions
215+
[...]
216+
Touchscreen
217+
Firmware Version: v1409
218+
[...]
210219
```
211220

212221
### Stylus (Laptop 12)

framework_lib/src/commandline/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,11 @@ fn print_versions(ec: &CrosEc) {
805805
let _ignore_err = print_touchpad_fw_ver();
806806

807807
#[cfg(feature = "hidapi")]
808-
if let Some(Platform::Framework12IntelGen13) = smbios::get_platform() {
809-
let _ignore_err = touchscreen::print_fw_ver();
808+
{
809+
let _ignore_err = touchscreen::print_himax_fw_ver();
810+
if let Some(Platform::Framework12IntelGen13) = smbios::get_platform() {
811+
let _ignore_err = touchscreen::print_fw_ver();
812+
}
810813
}
811814
#[cfg(feature = "hidapi")]
812815
print_dp_hdmi_details(false);

framework_lib/src/touchscreen.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@ use crate::touchscreen_win;
55

66
pub const ILI_VID: u16 = 0x222A;
77
pub const ILI_PID: u16 = 0x5539;
8+
pub const HX_VID: u16 = 0x3558;
9+
pub const HX_PID: u16 = 0x14FD;
810
const VENDOR_USAGE_PAGE: u16 = 0xFF00;
911
pub const USI_BITMAP: u8 = 1 << 1;
1012
pub const MPP_BITMAP: u8 = 1 << 2;
1113

1214
const REPORT_ID_FIRMWARE: u8 = 0x27;
1315
const REPORT_ID_USI_VER: u8 = 0x28;
1416

17+
const HX_REPORT_ID_CFG: u8 = 0x05;
18+
const HX_CFG_BUF_LEN: usize = 256;
19+
const HX_OFF_CID: usize = 52;
20+
const HX_OFF_VID: usize = 130;
21+
const HX_OFF_PID: usize = 132;
22+
1523
struct HidapiTouchScreen {
1624
device: HidDevice,
1725
}
@@ -248,6 +256,10 @@ pub fn print_fw_ver() -> Option<()> {
248256
}
249257
}
250258

259+
if print_himax_fw_ver().is_some() {
260+
return Some(());
261+
}
262+
251263
#[cfg(target_os = "windows")]
252264
let device = touchscreen_win::NativeWinTouchScreen::open_device(VENDOR_USAGE_PAGE, 0)?;
253265
#[cfg(not(target_os = "windows"))]
@@ -256,6 +268,66 @@ pub fn print_fw_ver() -> Option<()> {
256268
device.check_fw_version()
257269
}
258270

271+
pub fn print_himax_fw_ver() -> Option<()> {
272+
let api = match HidApi::new() {
273+
Ok(api) => api,
274+
Err(e) => {
275+
error!("Failed to open hidapi. Error: {e}");
276+
return None;
277+
}
278+
};
279+
280+
let dev_info = api
281+
.device_list()
282+
.find(|d| d.vendor_id() == HX_VID && d.product_id() == HX_PID)?;
283+
debug!(
284+
"Found Himax touchscreen {:04X}:{:04X} at {:?}",
285+
dev_info.vendor_id(),
286+
dev_info.product_id(),
287+
dev_info.path()
288+
);
289+
290+
let device = match dev_info.open_device(&api) {
291+
Ok(d) => d,
292+
Err(e) => {
293+
error!("Failed to open Himax touchscreen: {e}");
294+
return None;
295+
}
296+
};
297+
298+
let mut buf = [0u8; HX_CFG_BUF_LEN];
299+
buf[0] = HX_REPORT_ID_CFG;
300+
let n = match device.get_feature_report(&mut buf) {
301+
Ok(n) => n,
302+
Err(e) => {
303+
error!("Himax get_feature_report(0x05) failed: {e}");
304+
return None;
305+
}
306+
};
307+
debug!(" Read {} bytes from Himax Cfg report", n);
308+
309+
// Data is everything after the leading report-ID byte.
310+
let data = &buf[1..n.max(1)];
311+
if data.len() < HX_OFF_PID + 2 {
312+
error!(
313+
"Himax Cfg report too short: {} bytes (need {})",
314+
data.len(),
315+
HX_OFF_PID + 2
316+
);
317+
return None;
318+
}
319+
let cid = u16::from_be_bytes([data[HX_OFF_CID], data[HX_OFF_CID + 1]]);
320+
let vid = u16::from_be_bytes([data[HX_OFF_VID], data[HX_OFF_VID + 1]]);
321+
let pid = u16::from_be_bytes([data[HX_OFF_PID], data[HX_OFF_PID + 1]]);
322+
323+
println!("Touchscreen");
324+
debug!(" Vendor ID: {:04X}", vid);
325+
debug!(" Product ID: {:04X}", pid);
326+
println!(" Firmware Version: v{:04X}", cid);
327+
328+
Some(())
329+
}
330+
259331
pub fn enable_touch(enable: bool) -> Option<()> {
260332
#[cfg(target_os = "windows")]
261333
let device = touchscreen_win::NativeWinTouchScreen::open_device(VENDOR_USAGE_PAGE, 0)?;

0 commit comments

Comments
 (0)