GT911多点触摸改单点触摸
由于早期linux桌面不支持多点触摸,GT911驱动为5点触摸,导致系统虽然读取到触摸数据,但是无法在桌面上使用触摸,更改GT911驱动为单点触摸即可解决该问题。
查看系统上报触摸数据
执行evtest /dev/input/event1命令检测触屏上报的事件及坐标。
输出如下:
Properties:
Property type 1 (INPUT_PROP_DIRECT)
Testing ... (interrupt to exit)
Event: time 1501925732.831106, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 7
Event: time 1501925732.831106, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 642
Event: time 1501925732.831106, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 257
Event: time 1501925732.831106, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 14
Event: time 1501925732.831106, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 14
Event: time 1501925732.831106, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1
Event: time 1501925732.831106, -------------- SYN_REPORT ------------
Event: time 1501925733.140501, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value -1
Event: time 1501925733.140501, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 0
Event: time 1501925733.140501, -------------- SYN_REPORT ------------
可以看到系统已经成功驱动触摸并读取到触摸数据,但是触摸数据为多点触摸导致linux桌面无法使用,将多点触摸数据上报改为单点即可解决,下面进行代码修改。
源代码修改
-
打开GT911驱动源码头文件drivers/input/touchscreen/gt9xx.h
进行如下修改:
//#define GTP_MAX_TOUCH 5 #define GTP_MAX_TOUCH 1
-
打开GT911驱动源码源文件drivers/input/touchscreen/gt9xx.c
修改触摸按下上报函数static void gtp_touch_down(struct goodix_ts_data *ts, s32 id, s32 x, s32 y, s32 w)
static void gtp_touch_down(struct goodix_ts_data *ts, s32 id, s32 x, s32 y, s32 w) { // input_mt_slot(ts->input_dev, id); // input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id); // input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x); // input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y); // input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w); // input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w); //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ input_report_key(ts->input_dev, BTN_TOUCH, 1); input_report_abs(ts->input_dev, ABS_X, x); input_report_abs(ts->input_dev, ABS_Y, y); }
修改触摸抬起函数static void gtp_touch_up(struct goodix_ts_data *ts, s32 id)
static void gtp_touch_up(struct goodix_ts_data *ts, s32 id) { // input_mt_slot(ts->input_dev, id); // input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, -1); //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ input_report_key(ts->input_dev, BTN_TOUCH, 0); GTP_DEBUG("Touch id[%2d] release!", id); }
修改输入设备注册函数static s8 gtp_request_input_dev(struct goodix_ts_data *ts)
static s8 gtp_request_input_dev(struct goodix_ts_data *ts) { s8 ret = -1; GTP_DEBUG_FUNC(); ts->input_dev = input_allocate_device(); if (ts->input_dev == NULL) { GTP_ERROR("Failed to allocate input device."); return -ENOMEM; } ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ts->input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); // input_mt_init_slots(ts->input_dev, GTP_MAX_TOUCH, 1); // in case of "out of memory" __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit); // input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, ts->abs_x_max, 0, 0); // input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, ts->abs_y_max, 0, 0); // input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0); // input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); // input_set_abs_params(ts->input_dev, ABS_MT_TRACKING_ID, 0, 255, 0, 0); //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ input_set_abs_params(ts->input_dev, ABS_X, 0, ts->abs_x_max, 0, 0); input_set_abs_params(ts->input_dev, ABS_Y, 0, ts->abs_y_max, 0, 0); ts->input_dev->name = goodix_ts_name; ts->input_dev->phys = goodix_input_phys; ts->input_dev->id.bustype = BUS_I2C; ts->input_dev->id.vendor = 0xDEAD; ts->input_dev->id.product = 0xBEEF; ts->input_dev->id.version = 10427; ret = input_register_device(ts->input_dev); if (ret) { GTP_ERROR("Register %s input device failed", ts->input_dev->name); return -ENODEV; } return 0; }
-
更改完成后重新编译内核并更新内核到系统,即可在linux桌面中使用触摸。