Skip to content

Commit

Permalink
oplus_touchscreen: Port SEC double tap support hax from oneplus/sm825…
Browse files Browse the repository at this point in the history
…0_s_12.1

- the new touchpanel driver was not detecting double tap for 8/8P correctly due to a faulty single tap implementation. This hack makes it work without doing major changes to the original implementation.

Change-Id: I8ece6165276abef1e3d28a4da3042d7eebff7d06
  • Loading branch information
luk1337 authored and HELLBOY017 committed Nov 26, 2022
1 parent 6d6e050 commit 1e0e97d
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,25 @@ static int sec_enable_black_gesture(struct chip_data_s6sy771 *chip_info, bool en
{
int ret = 0;
int i = 0;
bool single_tap_support_b = 0;
bool ear_sense_support_b = 0;
struct touchpanel_data *ts = i2c_get_clientdata(chip_info->client);

if (ts) {
single_tap_support_b = ts->single_tap_support;
ear_sense_support_b = ts->ear_sense_support;
}

TPD_INFO("%s, enable = %d\n", __func__, enable);
TPD_INFO("%s, enable = %d,single_tap_support_b = %d,ear_sense_support_b =%d\n", __func__, enable, single_tap_support_b, ear_sense_support_b);

if (enable) {
touch_i2c_write_word(chip_info->client, SEC_CMD_WAKEUP_GESTURE_MODE, 0xFF1F);
if (single_tap_support_b) {
touch_i2c_write_word(chip_info->client, SEC_CMD_WAKEUP_GESTURE_MODE, 0xFFFF);
} else {
touch_i2c_write_word(chip_info->client, SEC_CMD_WAKEUP_GESTURE_MODE, 0xFF1F);
}


for (i = 0; i < 20; i++) {
touch_i2c_write_byte(chip_info->client, SEC_CMD_SET_POWER_MODE, 0x01);
sec_mdelay(10);
Expand Down Expand Up @@ -125,12 +139,22 @@ static void sec_enable_gesture_mask(void *chip_data, uint32_t enable)
struct chip_data_s6sy771 *chip_info = (struct chip_data_s6sy771 *)chip_data;
int ret = -1;
int i = 0;
bool single_tap_support_b = 0;
struct touchpanel_data *ts = i2c_get_clientdata(chip_info->client);

TPD_INFO("%s, enable = %d\n", __func__, enable);
if (ts) {
single_tap_support_b = ts->single_tap_support;
}

TPD_INFO("%s, enable = %d,single_tap_support_b =%d\n", __func__, enable, single_tap_support_b);

if (enable) {
for (i = 0; i < 20; i++) {
touch_i2c_write_word(chip_info->client, SEC_CMD_WAKEUP_GESTURE_MODE, 0xFF1F);
if (single_tap_support_b) {
touch_i2c_write_word(chip_info->client, SEC_CMD_WAKEUP_GESTURE_MODE, 0xFFFF);
} else {
touch_i2c_write_word(chip_info->client, SEC_CMD_WAKEUP_GESTURE_MODE, 0xFF1F);
}
touch_i2c_write_byte(chip_info->client, SEC_CMD_SET_POWER_MODE, 0x01);
sec_mdelay(10);
ret = touch_i2c_read_byte(chip_info->client, SEC_CMD_SET_POWER_MODE);
Expand Down Expand Up @@ -1276,13 +1300,19 @@ static int sec_get_gesture_info(void *chip_data, struct gesture_info *gesture)
struct Coordinate limitPoint[4];
struct sec_gesture_status *p_event_gesture = NULL;
struct chip_data_s6sy771 *chip_info = (struct chip_data_s6sy771 *)chip_data;
bool ear_sense_support_b = 0;
struct touchpanel_data *ts = i2c_get_clientdata(chip_info->client);

if (ts) {
ear_sense_support_b = ts->ear_sense_support;
}

p_event_gesture = (struct sec_gesture_status *)chip_info->first_event;
if (p_event_gesture->coordLen > 18) {
p_event_gesture->coordLen = 18;
}

if (p_event_gesture->gestureId == GESTURE_EARSENSE) {
if ((p_event_gesture->gestureId == GESTURE_EARSENSE) && (ear_sense_support_b)) {
TPD_DETAIL("earsense gesture: away from panel\n");
return 0;
}
Expand Down Expand Up @@ -1439,6 +1469,24 @@ static int sec_get_gesture_info(void *chip_data, struct gesture_info *gesture)
gesture->Point_end.x = (coord[12] << 4) | ((coord[14] >> 4) & 0x0F);
gesture->Point_end.y = (coord[13] << 4) | ((coord[14] >> 0) & 0x0F);
break;

case GESTURE_SINGLE_TAP:
gesture->gesture_type = SingleTap;
gesture->Point_start.x = (coord[0] << 4) | ((coord[2] >> 4) & 0x0F);
gesture->Point_start.y = (coord[1] << 4) | ((coord[2] >> 0) & 0x0F);
break;

case GESTURE_S:
gesture->gesture_type = Sgestrue;
gesture->Point_start.x = (coord[0] << 4) | ((coord[2] >> 4) & 0x0F);
gesture->Point_start.y = (coord[1] << 4) | ((coord[2] >> 0) & 0x0F);
gesture->Point_1st.x = (coord[3] << 4) | ((coord[5] >> 4) & 0x0F);
gesture->Point_1st.y = (coord[4] << 4) | ((coord[5] >> 0) & 0x0F);
gesture->Point_2nd.x = (coord[6] << 4) | ((coord[8] >> 4) & 0x0F);
gesture->Point_2nd.y = (coord[7] << 4) | ((coord[8] >> 0) & 0x0F);
gesture->Point_end.x = (coord[9] << 4) | ((coord[11] >> 4) & 0x0F);
gesture->Point_end.y = (coord[10] << 4) | ((coord[11] >> 0) & 0x0F);
break;

default:
gesture->gesture_type = UnkownGesture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#define GESTURE_M 0x0A
#define GESTURE_W 0x0B
#define GESTURE_DOUBLE_LINE 0x0C
#define GESTURE_SINGLE_TAP 0x0E
#define GESTURE_S 0x0F
#define GESTURE_EARSENSE 0x0E

#define RESET_TO_NORMAL_TIME (70)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,23 @@ static int sec_enable_black_gesture(struct chip_data_s6sy791 *chip_info, bool en
{
int ret = 0;
int i = 0;
bool single_tap_support_b = 0;
bool ear_sense_support_b = 0;
struct touchpanel_data *ts = i2c_get_clientdata(chip_info->client);

if (ts) {
single_tap_support_b = ts->single_tap_support;
ear_sense_support_b = ts->ear_sense_support;
}

TPD_INFO("%s, enable = %d\n", __func__, enable);
TPD_INFO("%s, enable = %d,single_tap_support_b = %d,ear_sense_support_b =%d\n", __func__, enable, single_tap_support_b, ear_sense_support_b);

if (enable) {
touch_i2c_write_word(chip_info->client, SEC_CMD_WAKEUP_GESTURE_MODE, 0xFF1F);
if (single_tap_support_b) {
touch_i2c_write_word(chip_info->client, SEC_CMD_WAKEUP_GESTURE_MODE, 0xFFFF);
} else {
touch_i2c_write_word(chip_info->client, SEC_CMD_WAKEUP_GESTURE_MODE, 0xFF1F);
}
for (i = 0; i < 20; i++) {
touch_i2c_write_byte(chip_info->client, SEC_CMD_SET_POWER_MODE, 0x01);
sec_mdelay(10);
Expand Down Expand Up @@ -127,12 +139,22 @@ static void sec_enable_gesture_mask(void *chip_data, uint32_t enable)
struct chip_data_s6sy791 *chip_info = (struct chip_data_s6sy791 *)chip_data;
int ret = -1;
int i = 0;
bool single_tap_support_b = 0;
struct touchpanel_data *ts = i2c_get_clientdata(chip_info->client);

TPD_INFO("%s, enable = %d\n", __func__, enable);
if (ts) {
single_tap_support_b = ts->single_tap_support;
}

TPD_INFO("%s, enable = %d,single_tap_support_b =%d\n", __func__, enable, single_tap_support_b);

if (enable) {
for (i = 0; i < 20; i++) {
touch_i2c_write_word(chip_info->client, SEC_CMD_WAKEUP_GESTURE_MODE, 0xFF1F);
if (single_tap_support_b) {
touch_i2c_write_word(chip_info->client, SEC_CMD_WAKEUP_GESTURE_MODE, 0xFFFF);
} else {
touch_i2c_write_word(chip_info->client, SEC_CMD_WAKEUP_GESTURE_MODE, 0xFF1F);
}
touch_i2c_write_byte(chip_info->client, SEC_CMD_SET_POWER_MODE, 0x01);
sec_mdelay(10);
ret = touch_i2c_read_byte(chip_info->client, SEC_CMD_SET_POWER_MODE);
Expand Down Expand Up @@ -1216,13 +1238,19 @@ static int sec_get_gesture_info(void *chip_data, struct gesture_info *gesture)
struct Coordinate limitPoint[4];
struct sec_gesture_status *p_event_gesture = NULL;
struct chip_data_s6sy791 *chip_info = (struct chip_data_s6sy791 *)chip_data;
bool ear_sense_support_b = 0;
struct touchpanel_data *ts = i2c_get_clientdata(chip_info->client);

if (ts) {
ear_sense_support_b = ts->ear_sense_support;
}

p_event_gesture = (struct sec_gesture_status *)chip_info->first_event;
if (p_event_gesture->coordLen > 18) {
p_event_gesture->coordLen = 18;
}

if (p_event_gesture->gestureId == GESTURE_EARSENSE) {
if ((p_event_gesture->gestureId == GESTURE_EARSENSE) && (ear_sense_support_b)) {
TPD_DETAIL("earsense gesture: away from panel\n");
return 0;
}
Expand Down Expand Up @@ -1379,6 +1407,24 @@ static int sec_get_gesture_info(void *chip_data, struct gesture_info *gesture)
gesture->Point_end.x = (coord[12] << 4) | ((coord[14] >> 4) & 0x0F);
gesture->Point_end.y = (coord[13] << 4) | ((coord[14] >> 0) & 0x0F);
break;

case GESTURE_SINGLE_TAP:
gesture->gesture_type = SingleTap;
gesture->Point_start.x = (coord[0] << 4) | ((coord[2] >> 4) & 0x0F);
gesture->Point_start.y = (coord[1] << 4) | ((coord[2] >> 0) & 0x0F);
break;

case GESTURE_S:
gesture->gesture_type = Sgestrue;
gesture->Point_start.x = (coord[0] << 4) | ((coord[2] >> 4) & 0x0F);
gesture->Point_start.y = (coord[1] << 4) | ((coord[2] >> 0) & 0x0F);
gesture->Point_1st.x = (coord[3] << 4) | ((coord[5] >> 4) & 0x0F);
gesture->Point_1st.y = (coord[4] << 4) | ((coord[5] >> 0) & 0x0F);
gesture->Point_2nd.x = (coord[6] << 4) | ((coord[8] >> 4) & 0x0F);
gesture->Point_2nd.y = (coord[7] << 4) | ((coord[8] >> 0) & 0x0F);
gesture->Point_end.x = (coord[9] << 4) | ((coord[11] >> 4) & 0x0F);
gesture->Point_end.y = (coord[10] << 4) | ((coord[11] >> 0) & 0x0F);
break;

default:
gesture->gesture_type = UnkownGesture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#define GESTURE_M 0x0A
#define GESTURE_W 0x0B
#define GESTURE_DOUBLE_LINE 0x0C
#define GESTURE_SINGLE_TAP 0x0E
#define GESTURE_S 0x0F
#define GESTURE_EARSENSE 0x0E

#define RESET_TO_NORMAL_TIME (70)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ static int pm_qos_state = 0;
#define PM_QOS_TOUCH_WAKEUP_VALUE 400
#endif

static int sigle_num = 0;
static struct timeval tpstart, tpend;
static int pointx[2] = {0, 0};
static int pointy[2] = {0, 0};

#define ABS(a, b) ((a - b > 0) ? a - b : b - a)

/*******Part2:declear Area********************************/
void tp_delta_debug_read_func_another(void);

Expand Down Expand Up @@ -463,6 +470,36 @@ static void tp_geture_info_transform(struct gesture_info *gesture, struct resolu
gesture->Point_4th.y = gesture->Point_4th.y * resolution_info->LCD_HEIGHT / (resolution_info->max_y);
}

int sec_double_tap(struct gesture_info *gesture)
{
uint32_t timeuse = 0;

if (sigle_num == 0) {
do_gettimeofday(&tpstart);
pointx[0] = gesture->Point_start.x;
pointy[0] = gesture->Point_start.y;
sigle_num++;
TPD_DEBUG("first enter double tap\n");
} else if (sigle_num == 1) {
do_gettimeofday(&tpend);
pointx[1] = gesture->Point_start.x;
pointy[1] = gesture->Point_start.y;
sigle_num = 0;
timeuse = 1000000 * (tpend.tv_sec-tpstart.tv_sec) + tpend.tv_usec-tpstart.tv_usec;
TPD_DEBUG("timeuse = %d, distance[x] = %d, distance[y] = %d\n", timeuse, ABS(pointx[0], pointx[1]), ABS(pointy[0], pointy[1]));
if ((ABS(pointx[0], pointx[1]) < 150) && (ABS(pointy[0], pointy[1]) < 200) && (timeuse < 500000)) {
return 1;
} else {
TPD_DEBUG("not match double tap\n");
do_gettimeofday(&tpstart);
pointx[0] = gesture->Point_start.x;
pointy[0] = gesture->Point_start.y;
sigle_num = 1;
}
}
return 0;
}

static void tp_gesture_handle(struct touchpanel_data *ts)
{
struct gesture_info gesture_info_temp;
Expand All @@ -481,6 +518,13 @@ static void tp_gesture_handle(struct touchpanel_data *ts)
}

tp_geture_info_transform(&gesture_info_temp, &ts->resolution_info);
if (ts->single_tap_support) {
if (gesture_info_temp.gesture_type == SingleTap) {
if (sec_double_tap(&gesture_info_temp) == 1) {
gesture_info_temp.gesture_type = DouTap;
}
}
}

TPD_INFO("detect %s gesture\n", gesture_info_temp.gesture_type == DouTap ? "double tap" :
gesture_info_temp.gesture_type == UpVee ? "up vee" :
Expand Down

0 comments on commit 1e0e97d

Please sign in to comment.