Skip to content

Commit

Permalink
drivers/input: Add ist415 touch ic suspend feature.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ewoodev committed Jan 9, 2025
1 parent 42a022a commit 507596b
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 13 deletions.
35 changes: 31 additions & 4 deletions apps/examples/touchscreen/touchscreen_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <command #>\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");
}

/****************************************************************************
Expand All @@ -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);
}
}

Expand Down
37 changes: 30 additions & 7 deletions os/drivers/input/ist415.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
/****************************************************************************
Expand All @@ -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 */
};

/****************************************************************************
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -525,6 +546,8 @@ static void ist415_start_device(struct ist415_dev_s *dev)
ist415_enable(dev);
ist415_start(dev);
}

return OK;
}

/****************************************************************************
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions os/drivers/input/touchscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions os/include/tinyara/input/touchscreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
};

/*
Expand Down

0 comments on commit 507596b

Please sign in to comment.