[RK3399][Android7.1] 调试笔记 --- USB Touch坐标点颠倒处理

Platform: RK3399
OS: Android 7.1
Kernel: v4.4.83

背景:

接了HDMI的副屏上的USB Touch,发现使用的时候坐标点是颠倒的,于是在驱动中根据USB的
Vendor ID来进行判断,然后更正下上报坐标点的值。


解决方法:

diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index f62a9d6..7167144 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -164,6 +164,11 @@ static void mt_post_parse(struct mt_device *td);
 #define MT_USB_DEVICE(v, p)	HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
 #define MT_BT_DEVICE(v, p)	HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
 
+
+//Kris, use vendor id to decide if mirroring touch point or not.
+static int vendor_id;
+
+
 /*
  * these device-dependent functions determine what slot corresponds
  * to a valid contact that was just read.
@@ -639,6 +644,17 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
 		active = (s->touch_state || s->inrange_state) &&
 							s->confidence_state;
 
+		/* Kris, use vendor id to decide if mirroring touch point or not. { */
+		//hdmi touch
+		//vendor id: 0x222A
+		//max-x:16384
+		//max-y: 9600
+		if (vendor_id == 0x222a) {
+			s->x = 16384 - s->x;
+			s->y = 9600 - s->y;
+		}
+		/* Kris, use vendor id to decide if mirroring touch point or not. } */
+
 		input_mt_slot(input, slotnum);
 		input_mt_report_slot_state(input, MT_TOOL_FINGER, active);
 		if (active) {
@@ -764,6 +780,10 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
 	unsigned count;
 	int r, n;
 
+	/* Kris, use vendor id to decide if mirroring touch point or not. { */
+	vendor_id = hid->vendor;
+	/* Kris, use vendor id to decide if mirroring touch point or not. } */
+
 	/*
 	 * Includes multi-packet support where subsequent
 	 * packets are sent with zero contactcount.

附hid touch注册流程:

设备注册:

worker_thread -> usb会开线程去监听hub插拔事件
	process_one_work -> 
	  hub_event -> 有usb设备插入,这里是usb touch
	    usb_new_device ->
	      device_add ->
	        usb_probe_device -> drvier.c
	          udriver->probe ->
	            generic_probe ->
	              usb_set_configuration ->
	                device_add ->
	                  usb_probe_interface ->
	                    driver->probe ->
						  usbhid_probe ->
						    hid_allocate_device -> //注意到这里是bus是hid_bus_type
						      

驱动注册:

module_hid_driver(mt_driver) ->	
  __hid_driver_init -> 	//上面宏定义的扩展
    hid_register_driver ->
      __hid_register_driver ->
        driver_register ->  //bus是hid_bus_type
          hid_bus_match -> hid-core.c
            hid_match_device -> 这时候拿到的hdev就是前面hid_allocate_device分配的那个
              hid_match_id -> 根据hdrv->id_table匹配也就是[email protected]中的id_table
                hid_device_probe -> //匹配上之后继续执行bus probe
                  hdrv->probe ->
                    mt_probe ->
                      hid_parse
                      hid_hw_start ->
                        hid_connect ->
                          hidinput_connect -> 把hid和input子系统绑定关联起来
                            hidinput_allocate
                            input_register_device	 //注册一个input device
                        hdev->hiddev_connect ->	把hid和usb子系统绑定关联起来
							hiddev_connect -> hiddev.c
							  usb_register_dev

参考:

hid-multitouch驱动源代码分析
Linux设备驱动之HID驱动

你可能感兴趣的:(RK3399,子类__Touch)