|
| 1 | +use hidapi::{HidApi, HidDevice, HidError}; |
| 2 | + |
| 3 | +pub const PIX_VID: u16 = 0x093A; |
| 4 | +pub const PIX_REPORT_ID: u8 = 0x43; |
| 5 | + |
| 6 | +fn read_byte(device: &HidDevice, addr: u8) -> Result<u8, HidError> { |
| 7 | + device.send_feature_report(&[PIX_REPORT_ID, addr, 0x10, 0])?; |
| 8 | + |
| 9 | + let mut buf = [0u8; 4]; |
| 10 | + buf[0] = PIX_REPORT_ID; |
| 11 | + |
| 12 | + device.get_feature_report(&mut buf)?; |
| 13 | + Ok(buf[3]) |
| 14 | +} |
| 15 | + |
| 16 | +fn read_ver(device: &HidDevice) -> Result<u16, HidError> { |
| 17 | + Ok(u16::from_le_bytes([ |
| 18 | + read_byte(device, 0xb2)?, |
| 19 | + read_byte(device, 0xb3)?, |
| 20 | + ])) |
| 21 | +} |
| 22 | + |
| 23 | +pub fn print_touchpad_fw_ver() -> Result<(), HidError> { |
| 24 | + debug!("Looking for touchpad HID device"); |
| 25 | + match HidApi::new() { |
| 26 | + Ok(api) => { |
| 27 | + for dev_info in api.device_list() { |
| 28 | + let vid = dev_info.vendor_id(); |
| 29 | + let pid = dev_info.product_id(); |
| 30 | + let usage_page = dev_info.usage_page(); |
| 31 | + |
| 32 | + debug!( |
| 33 | + " Found {:04X}:{:04X} (Usage Page {:04X})", |
| 34 | + vid, pid, usage_page |
| 35 | + ); |
| 36 | + if vid != PIX_VID || (pid != 0x0274 && pid != 0x0239) { |
| 37 | + debug!( |
| 38 | + " Skipping VID:PID. Expected {:04X}:{:04X}/{:04X}", |
| 39 | + PIX_VID, 0x0274, 0x0239 |
| 40 | + ); |
| 41 | + continue; |
| 42 | + } |
| 43 | + if usage_page != 0xFF00 { |
| 44 | + debug!(" Skipping usage page. Expected {:04X}", 0xFF00); |
| 45 | + continue; |
| 46 | + } |
| 47 | + |
| 48 | + debug!(" Found matching touchpad HID device"); |
| 49 | + let device = dev_info.open_device(&api).unwrap(); |
| 50 | + |
| 51 | + println!("Touchpad"); |
| 52 | + println!(" IC Type: {:04X}", pid); |
| 53 | + println!(" Firmware Version: v{:04X}", read_ver(&device)?); |
| 54 | + // If we found one, there's no need to look for more |
| 55 | + return Ok(()); |
| 56 | + } |
| 57 | + } |
| 58 | + Err(e) => { |
| 59 | + eprintln!("Failed to open hidapi. Error: {e}"); |
| 60 | + return Err(e); |
| 61 | + } |
| 62 | + }; |
| 63 | + |
| 64 | + Ok(()) |
| 65 | +} |
0 commit comments