diff options
author | Nicolas Boichat <drinkcat@chromium.org> | 2017-08-07 16:20:02 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-08-16 06:03:49 -0700 |
commit | fb58920c9e6c301d2e1931e3c783230af992c647 (patch) | |
tree | 78793abe226c3418e0b281573413e1c8458b4758 | |
parent | 845739c02267db7596a9388012af0cb3f0629703 (diff) | |
download | chrome-ec-fb58920c9e6c301d2e1931e3c783230af992c647.tar.gz |
usb_hid_touchpad: Add timestamp field to touch events
We use the unofficial, Windows 8, Relative Scan time HID usage
(Digitizer page, 0x56) to add timestamps to our HID touchpad
events.
The timestamps is a rolling, unsigned, 16-bit integer, with a
resolution of 100us (so it wraps around every 6.5s).
The host will be able to synchronize to that timestamp, resetting
an offset every time the touchpad is quiet a certain amount of
time (e.g. 1 second).
BRANCH=none
BUG=b:63685117
TEST=Flash hammer, timestamps are reported in HID descriptor.
Change-Id: Ie5d56a9df14e464d2cdcd559f550d6e3cc81961f
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/603041
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | chip/stm32/usb_hid_touchpad.c | 10 | ||||
-rw-r--r-- | driver/touchpad_elan.c | 14 | ||||
-rw-r--r-- | include/usb_hid_touchpad.h | 3 |
3 files changed, 27 insertions, 0 deletions
diff --git a/chip/stm32/usb_hid_touchpad.c b/chip/stm32/usb_hid_touchpad.c index ff3ec8d265..a16988f03c 100644 --- a/chip/stm32/usb_hid_touchpad.c +++ b/chip/stm32/usb_hid_touchpad.c @@ -139,6 +139,16 @@ static const uint8_t report_desc[] = { 0x75, 0x01, /* Report Size (1) */ 0x95, 0x01, /* Report Count (1) */ 0x81, 0x02, /* Input (Data,Var,Abs) */ + /* Timestamp */ + 0x05, 0x0D, /* Usage Page (Digitizer) */ + 0x55, 0x0C, /* Unit Exponent (-4) */ + 0x66, 0x01, 0x10, /* Unit (System: SI Linear, Time: Seconds) */ + 0x47, 0xFF, 0xFF, 0x00, 0x00, /* Physical Maximum (65535) */ + 0x27, 0xFF, 0xFF, 0x00, 0x00, /* Logical Maximum (65535) */ + 0x75, 0x10, /* Report Size (16) */ + 0x95, 0x01, /* Report Count (1) */ + 0x09, 0x56, /* Usage (0x56, Relative Scan Time) */ + 0x81, 0x02, /* Input (Data,Var,Abs) */ 0xC0, /* End Collection */ }; diff --git a/driver/touchpad_elan.c b/driver/touchpad_elan.c index 7ba75fa3aa..744ddd6904 100644 --- a/driver/touchpad_elan.c +++ b/driver/touchpad_elan.c @@ -7,6 +7,7 @@ #include "console.h" #include "touchpad_elan.h" #include "gpio.h" +#include "hwtimer.h" #include "i2c.h" #include "task.h" #include "timer.h" @@ -111,6 +112,12 @@ static int elan_tp_write_cmd(uint16_t reg, uint16_t val) static int finger_status[ETP_MAX_FINGERS] = {0}; +/* + * Timestamp of last interrupt (32 bits are enough as we divide the value by 100 + * and then put it in a 16-bit field). + */ +static uint32_t irq_ts; + static int elan_tp_read_report(void) { int rv; @@ -120,6 +127,10 @@ static int elan_tp_read_report(void) uint8_t hover_info; uint8_t *finger = tp_buf+ETP_FINGER_DATA_OFFSET; struct usb_hid_touchpad_report report; + uint16_t timestamp; + + /* Compute and save timestamp early in case another interrupt comes. */ + timestamp = irq_ts / USB_HID_TOUCHPAD_TIMESTAMP_UNIT; i2c_lock(CONFIG_TOUCHPAD_I2C_PORT, 1); rv = i2c_xfer(CONFIG_TOUCHPAD_I2C_PORT, CONFIG_TOUCHPAD_I2C_ADDR, @@ -186,6 +197,7 @@ static int elan_tp_read_report(void) } report.count = ri; + report.timestamp = timestamp; set_touchpad_report(&report); @@ -314,6 +326,8 @@ int touchpad_get_info(struct touchpad_info *tp) void elan_tp_interrupt(enum gpio_signal signal) { + irq_ts = __hw_clock_source_read(); + task_wake(TASK_ID_TOUCHPAD); } diff --git a/include/usb_hid_touchpad.h b/include/usb_hid_touchpad.h index 16d95b76a1..d7d6dc0363 100644 --- a/include/usb_hid_touchpad.h +++ b/include/usb_hid_touchpad.h @@ -8,6 +8,8 @@ #ifndef __CROS_EC_USB_HID_KEYBOARD_H #define __CROS_EC_USB_HID_KEYBOARD_H +#define USB_HID_TOUCHPAD_TIMESTAMP_UNIT 100 /* usec */ + struct usb_hid_touchpad_report { uint8_t id; /* 0x01 */ struct { @@ -22,6 +24,7 @@ struct usb_hid_touchpad_report { } __packed finger[5]; uint8_t count:7; uint8_t button:1; + uint16_t timestamp; } __packed; /* class implementation interfaces */ |