From df5ca7b928bee798245f7ffcbbd54061f5d356f2 Mon Sep 17 00:00:00 2001 From: "eunwoo.nam" Date: Tue, 7 Jan 2025 20:44:29 +0900 Subject: [PATCH 1/3] drivers/input: Add ist415 touch ic suspend feature. The touch device suspend feature is changing power mode to low power mode. In the low power mode, power comsumption is reduced and touch irq is not comming. But ist415 ic is checking double tap during low power mode, and it notify to apps the double tab event. In this commit, Add ioctl to control touch ic suspend/resume and example app Signed-off-by: eunwoo.nam --- os/drivers/input/ist415.c | 35 ++++++++++++++++++++------ os/drivers/input/touchscreen.c | 14 +++++++++++ os/include/tinyara/input/touchscreen.h | 6 +++-- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/os/drivers/input/ist415.c b/os/drivers/input/ist415.c index d9a0ec5729..1c378244e5 100644 --- a/os/drivers/input/ist415.c +++ b/os/drivers/input/ist415.c @@ -77,6 +77,8 @@ static void ist415_enable_touch(struct touchscreen_s *upper); static void ist415_disable_touch(struct touchscreen_s *upper); static int ist415_cmd(struct touchscreen_s *upper, int argc, char **argv); +static int ist415_suspend_device(struct touchscreen_s *upper); +static int ist415_resume_device(struct touchscreen_s *upper); static int ist415_process_event(struct ist415_dev_s *dev); static void ist415_timer_handler(int argc, uint32_t arg1); /**************************************************************************** @@ -91,7 +93,9 @@ struct i2c_config_s g_ist415_i2c_config = { static const struct touchscreen_ops_s g_ist415_ops = { ist415_enable_touch, /* enable */ ist415_disable_touch, /* disable */ - ist415_cmd /* cmd */ + ist415_cmd, /* cmd */ + ist415_suspend_device, /* suspend */ + ist415_resume_device /* resume */ }; /**************************************************************************** @@ -298,8 +302,19 @@ static int ist415_process_event(struct ist415_dev_s *dev) if (p_evt_gesture->gid == GESTURE_DOUBLETAP_WAKEUP) { uint16_t x = ((uint16_t) p_evt_gesture->gdata[1] << 8) | (uint16_t) p_evt_gesture->gdata[0]; uint16_t y = ((uint16_t) p_evt_gesture->gdata[3] << 8) | (uint16_t) p_evt_gesture->gdata[2]; + struct touch_sample_s pdata; ist415vdbg("Double Tap Wakeup~(%d, %d)\n", x, y); - // TODO: KnockKnock Event Process~ + pdata.point[0].id = 0; + pdata.point[0].x = x; + pdata.point[0].y = y; + pdata.point[0].h = 0; + pdata.point[0].w = 0; + pdata.point[0].pressure = 0; + pdata.point[0].flags = TOUCH_DOWN; + pdata.npoints = 1; + touch_report(dev->upper, &pdata); + pdata.point[0].flags = TOUCH_UP; + touch_report(dev->upper, &pdata); } } else { ist415wdbg("Not support gesture type:%d\n", p_evt_gesture->gtype); @@ -489,11 +504,13 @@ static void ist415_power_off(struct ist415_dev_s *dev) } /**************************************************************************** - * Name: ist415_stop_device + * Name: ist415_suspend_device ****************************************************************************/ -static void ist415_stop_device(struct ist415_dev_s *dev) +static int ist415_suspend_device(struct touchscreen_s *upper) { + struct ist415_dev_s *dev = upper->priv; + ist415vdbg("%s\n", __func__); while (sem_wait(&dev->sem) != OK) { @@ -517,14 +534,17 @@ static void ist415_stop_device(struct ist415_dev_s *dev) ist415_forced_release(dev); sem_post(&dev->sem); + return OK; } /**************************************************************************** - * Name: ist415_start_device + * Name: ist415_resume_device ****************************************************************************/ -static void ist415_start_device(struct ist415_dev_s *dev) +static int ist415_resume_device(struct touchscreen_s *upper) { + struct ist415_dev_s *dev = upper->priv; + ist415vdbg("%s\n", __func__); while (sem_wait(&dev->sem) != OK) { @@ -545,6 +565,7 @@ static void ist415_start_device(struct ist415_dev_s *dev) } sem_post(&dev->sem); + return OK; } /**************************************************************************** @@ -1107,7 +1128,7 @@ int ist415_initialize(const char *path, struct i2c_dev_s *i2c, struct ist415_con dev->sys_mode = SYS_MODE_TOUCH; dev->touch_type = (1 << TOUCH_TYPE_NORMAL) | (1 << TOUCH_TYPE_WET) | (1 << TOUCH_TYPE_PALMLARGE); - dev->knockknock = false; + dev->knockknock = true; dev->irq_working = false; dev->event_mode = false; diff --git a/os/drivers/input/touchscreen.c b/os/drivers/input/touchscreen.c index 3e1de9044a..5b8a6d9ffa 100755 --- a/os/drivers/input/touchscreen.c +++ b/os/drivers/input/touchscreen.c @@ -304,6 +304,20 @@ static int touch_ioctl(FAR struct file *filep, int cmd, unsigned long arg) ret = -EINVAL; } break; + case TSIOC_SUSPEND: + if (priv->ops && priv->ops->suspend) { + ret = priv->ops->suspend(priv); + } else { + ret = -EINVAL; + } + break; + case TSIOC_RESUME: + if (priv->ops && priv->ops->resume) { + ret = priv->ops->resume(priv); + } else { + ret = -EINVAL; + } + break; default: { touchdbg("ERROR: ioctl not found, cmd: %d\n", cmd); } diff --git a/os/include/tinyara/input/touchscreen.h b/os/include/tinyara/input/touchscreen.h index bfc5c52fc5..3503851294 100644 --- a/os/include/tinyara/input/touchscreen.h +++ b/os/include/tinyara/input/touchscreen.h @@ -84,8 +84,8 @@ #define TSIOC_GETCALIB _TSIOC(0x0002) /* arg: Pointer to int calibration value */ #define TSIOC_SETFREQUENCY _TSIOC(0x0003) /* arg: Pointer to uint32_t frequency value */ #define TSIOC_GETFREQUENCY _TSIOC(0x0004) /* arg: Pointer to uint32_t frequency value */ -#define TSIOC_DISABLE _TSIOC(0x0005) /* Disable touch interrupt */ -#define TSIOC_ENABLE _TSIOC(0x0006) /* Enable touch interrupt */ +#define TSIOC_SUSPEND _TSIOC(0x0005) /* Suspend touch interrupt */ +#define TSIOC_RESUME _TSIOC(0x0006) /* Resume touch interrupt */ #define TSIOC_SETAPPNOTIFY _TSIOC(0x0007) /* arg: Pointer to struct touch_set_callback_s. Support available only when CONFIG_TOUCH_CALLBACK is enabled */ #define TSIOC_CMD _TSIOC(0x0008) /* arg: Pointer to struct touchscreen_cmd_s */ #define TSC_FIRST 0x0001 /* First common command */ @@ -201,6 +201,8 @@ struct touchscreen_ops_s { void (*touch_enable)(struct touchscreen_s *upper); /* Enable touch */ void (*touch_disable)(struct touchscreen_s *upper); /* Disable touch */ int (*cmd)(struct touchscreen_s *upper, int argc, char **argv); + int (*suspend)(struct touchscreen_s *upper); /* Suspend touch */ + int (*resume)(struct touchscreen_s *upper); /* Resume touch */ }; /* From 8a2077b40339bcd9875f801257cfbdb8047fd225 Mon Sep 17 00:00:00 2001 From: "eunwoo.nam" Date: Tue, 21 Jan 2025 18:49:27 +0900 Subject: [PATCH 2/3] apps/examples/touchscreen: Add touch ic susepnding test. The suspend test is changing touch ic power mode NP(normal power) to LP (low power) In the commit, Add tash command "touchscreen suspend" and "touchscreen resume" Signed-off-by: eunwoo.nam --- apps/examples/touchscreen/touchscreen_main.c | 47 ++++++++++++++++++-- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/apps/examples/touchscreen/touchscreen_main.c b/apps/examples/touchscreen/touchscreen_main.c index 6fae0cef7f..6f937bdf04 100644 --- a/apps/examples/touchscreen/touchscreen_main.c +++ b/apps/examples/touchscreen/touchscreen_main.c @@ -168,14 +168,49 @@ static int touchsceen_specific_cmd(int argc, char*argv[]) return OK; } +static int touchsceen_suspend(void) +{ + int fd = open(TOUCH_DEV_PATH, O_RDWR); + if (fd < 0) { + printf("Fail to open %s, errno:%d\n", TOUCH_DEV_PATH, get_errno()); + return ERROR; + } + + if (ioctl(fd, TSIOC_SUSPEND, NULL) != OK) { + printf("Fail to TSIOC_SUSPEND %s, errno:%d\n", TOUCH_DEV_PATH, get_errno()); + close(fd); + return ERROR; + } + + close(fd); + return OK; +} + +static int touchsceen_resume(void) +{ + int fd = open(TOUCH_DEV_PATH, O_RDWR); + if (fd < 0) { + printf("Fail to open %s, errno:%d\n", TOUCH_DEV_PATH, get_errno()); + return ERROR; + } + + if (ioctl(fd, TSIOC_RESUME, NULL) != OK) { + printf("Fail to TSIOC_RESUME %s, errno:%d\n", TOUCH_DEV_PATH, get_errno()); + } + + close(fd); + return OK; +} static void show_usage(void) { printf("usage: touchscreen \n"); printf("Excute touchscreen testing or controling.\n\n"); printf("The touchscreen basic test command which printing coordinates and types:\n"); - printf(" start: Start the touchscreen basic test \n"); - printf(" stop : Stop the touchscreen basic test\n"); + printf(" start : Start the touchscreen basic test \n"); + printf(" stop : Stop the touchscreen basic test\n"); + printf(" suspend : Test suspend touchscreen ic operation\n"); + printf(" resume : Test reusme touchscreen ic operation\n"); } /**************************************************************************** @@ -196,10 +231,14 @@ int touchscreen_main(int argc, char *argv[]) } if (argc == 2) { - if (!strcmp(argv[1], "start")) { + if (!strncmp(argv[1], "start", 6)) { return touchsceen_test_start(); - } else if (!strcmp(argv[1], "stop")) { + } else if (!strncmp(argv[1], "stop", 5)) { return touchsceen_test_stop(); + } else if (!strncmp(argv[1], "suspend", 8)) { + return touchsceen_suspend(); + } else if (!strncmp(argv[1], "resume", 7)) { + return touchsceen_resume(); } } From ceda8e0cf19f28aa5a2eb5b9dd840ec9368a4cc3 Mon Sep 17 00:00:00 2001 From: "eunwoo.nam" Date: Tue, 7 Jan 2025 20:50:52 +0900 Subject: [PATCH 3/3] drives/input: Fix wrong touch event notification. In the ist415_forced_release function data.npoints can be 0. (There is no pushed touch point) But, since touch is reported even if touch point count is 0. Therefore, fix wrong null touch event Signed-off-by: eunwoo.nam --- os/drivers/input/ist415.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/os/drivers/input/ist415.c b/os/drivers/input/ist415.c index 1c378244e5..157334cde1 100644 --- a/os/drivers/input/ist415.c +++ b/os/drivers/input/ist415.c @@ -122,7 +122,10 @@ static void ist415_forced_release(struct ist415_dev_s *dev) dev->touched[i] = false; } } - touch_report(dev->upper, &data); + + if (data.npoints > 0) { + touch_report(dev->upper, &data); + } } /****************************************************************************