MCPcopy Index your code
hub / github.com/FrameworkComputer/framework-system / print_himax_fw_ver

Function print_himax_fw_ver

framework_lib/src/touchscreen.rs:271–329  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

269}
270
271pub 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(())

Callers 2

print_fw_verFunction · 0.85
print_versionsFunction · 0.85

Calls 1

open_deviceMethod · 0.45

Tested by

no test coverage detected