From 507596bad20d0ccd0d8dc898405884b2025f3055 Mon Sep 17 00:00:00 2001 From: "eunwoo.nam" Date: Tue, 7 Jan 2025 20:44:29 +0900 Subject: [PATCH] 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 --- apps/examples/touchscreen/touchscreen_main.c | 35 +++++++++++++++--- os/drivers/input/ist415.c | 37 ++++++++++++++++---- os/drivers/input/touchscreen.c | 14 ++++++++ os/include/tinyara/input/touchscreen.h | 6 ++-- 4 files changed, 79 insertions(+), 13 deletions(-) diff --git a/apps/examples/touchscreen/touchscreen_main.c b/apps/examples/touchscreen/touchscreen_main.c index 6fae0cef7f..fe8ab80de1 100644 --- a/apps/examples/touchscreen/touchscreen_main.c +++ b/apps/examples/touchscreen/touchscreen_main.c @@ -168,14 +168,37 @@ static int touchsceen_specific_cmd(int argc, char*argv[]) return OK; } +static int touchsceen_suspend(bool cmd) +{ + 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 (cmd) { + if (ioctl(fd, TSIOC_SUSPEND, NULL) != OK) { + printf("Fail to TSIOC_SUSPEND %s, errno:%d\n", TOUCH_DEV_PATH, get_errno()); + } + } else { + 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 +219,14 @@ int touchscreen_main(int argc, char *argv[]) } if (argc == 2) { - if (!strcmp(argv[1], "start")) { + if (!strncmp(argv[1], "start", 5)) { return touchsceen_test_start(); - } else if (!strcmp(argv[1], "stop")) { + } else if (!strncmp(argv[1], "stop", 4)) { return touchsceen_test_stop(); + } else if (!strncmp(argv[1], "suspend", 7)) { + return touchsceen_suspend(true); + } else if (!strncmp(argv[1], "resume", 6)) { + return touchsceen_suspend(false); } } diff --git a/os/drivers/input/ist415.c b/os/drivers/input/ist415.c index 61ace2adef..06cd848971 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); @@ -483,11 +498,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__); dev->suspend = true; @@ -503,14 +520,18 @@ static void ist415_stop_device(struct ist415_dev_s *dev) ist415_disable(dev); ist415_power_off(dev); } + + 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__); dev->suspend = false; @@ -525,6 +546,8 @@ static void ist415_start_device(struct ist415_dev_s *dev) ist415_enable(dev); ist415_start(dev); } + + return OK; } /**************************************************************************** @@ -1080,7 +1103,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 */ }; /*