Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add touch ic suspend feature #6618

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 43 additions & 4 deletions apps/examples/touchscreen/touchscreen_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the ioctl is failed, it also returns OK. Is this ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

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 <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 +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();
}
}

Expand Down
42 changes: 34 additions & 8 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 All @@ -118,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);
}
}

/****************************************************************************
Expand Down Expand Up @@ -298,8 +305,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 +501,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 +523,18 @@ static void ist415_stop_device(struct ist415_dev_s *dev)
ist415_disable(dev);
ist415_power_off(dev);
}

return OK;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you let me know why you change the return type even this returns OK always?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ops in touchscreen, so some touch ic might have return fail

}

/****************************************************************************
* 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 +549,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 +1106,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