@@ -5,13 +5,21 @@ use crate::touchscreen_win;
55
66pub const ILI_VID : u16 = 0x222A ;
77pub const ILI_PID : u16 = 0x5539 ;
8+ pub const HX_VID : u16 = 0x3558 ;
9+ pub const HX_PID : u16 = 0x14FD ;
810const VENDOR_USAGE_PAGE : u16 = 0xFF00 ;
911pub const USI_BITMAP : u8 = 1 << 1 ;
1012pub const MPP_BITMAP : u8 = 1 << 2 ;
1113
1214const REPORT_ID_FIRMWARE : u8 = 0x27 ;
1315const 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+
1523struct 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+
259331pub 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