From: Roderick Colenbrander <roderick@gaikai.com>
To: linux-input@vger.kernel.org
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <benjamin.tissoires@redhat.com>,
Simon Wood <simon@mungewell.org>,
Frank Praznik <frank.praznik@gmail.com>,
Tim Bird <tim.bird@am.sony.com>,
Roderick Colenbrander <roderick.colenbrander@sony.com>
Subject: [PATCH 6/7] HID: sony: Report hardware timestamp for DS4 sensor values
Date: Thu, 8 Dec 2016 19:09:55 -0800 [thread overview]
Message-ID: <1481252996-25288-7-git-send-email-roderick@gaikai.com> (raw)
In-Reply-To: <1481252996-25288-1-git-send-email-roderick@gaikai.com>
From: Roderick Colenbrander <roderick.colenbrander@sony.com>
Report the hardware timestamp inside each HID report through
MSC_TIMESTAMP for motion sensor values.
Signed-off-by: Roderick Colenbrander <roderick.colenbrander@sony.com>
---
drivers/hid/hid-sony.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index a7a3692..9f79d1b 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -781,6 +781,7 @@ struct motion_output_report_02 {
* additional +2.
*/
#define DS4_INPUT_REPORT_BUTTON_OFFSET 5
+#define DS4_INPUT_REPORT_TIMESTAMP_OFFSET 10
#define DS4_INPUT_REPORT_GYRO_X_OFFSET 13
#define DS4_INPUT_REPORT_BATTERY_OFFSET 30
#define DS4_INPUT_REPORT_TOUCHPAD_OFFSET 33
@@ -838,6 +839,11 @@ struct sony_sc {
u8 led_delay_on[MAX_LEDS];
u8 led_delay_off[MAX_LEDS];
u8 led_count;
+
+ bool timestamp_initialized;
+ u16 prev_timestamp;
+ unsigned int timestamp_us;
+
bool ds4_dongle_connected;
/* DS4 calibration data */
struct ds4_calibration_data ds4_calib_data[6];
@@ -1032,6 +1038,7 @@ static void dualshock4_parse_report(struct sony_sc *sc, u8 *rd, int size)
unsigned long flags;
int n, m, offset, num_touch_data, max_touch_data;
u8 cable_state, battery_capacity, battery_charging;
+ u16 timestamp;
/* When using Bluetooth the header is 2 bytes longer, so skip these. */
int data_offset = (sc->quirks & DUALSHOCK4_CONTROLLER_USB) ? 0 : 2;
@@ -1040,6 +1047,24 @@ static void dualshock4_parse_report(struct sony_sc *sc, u8 *rd, int size)
offset = data_offset + DS4_INPUT_REPORT_BUTTON_OFFSET;
input_report_key(sc->touchpad, BTN_LEFT, rd[offset+2] & 0x2);
+ /* Convert timestamp (in 5.33us unit) to timestamp_us */
+ offset = data_offset + DS4_INPUT_REPORT_TIMESTAMP_OFFSET;
+ timestamp = get_unaligned_le16(&rd[offset]);
+ if (!sc->timestamp_initialized) {
+ sc->timestamp_us = ((unsigned int)timestamp * 16) / 3;
+ sc->timestamp_initialized = true;
+ } else {
+ u16 delta;
+
+ if (sc->prev_timestamp > timestamp)
+ delta = (U16_MAX - sc->prev_timestamp + timestamp + 1);
+ else
+ delta = timestamp - sc->prev_timestamp;
+ sc->timestamp_us += (delta * 16) / 3;
+ }
+ sc->prev_timestamp = timestamp;
+ input_event(sc->sensor_dev, EV_MSC, MSC_TIMESTAMP, sc->timestamp_us);
+
offset = data_offset + DS4_INPUT_REPORT_GYRO_X_OFFSET;
for (n = 0; n < 6; n++) {
/* Store data in int for more precision during mult_frac. */
@@ -1386,6 +1411,8 @@ static int sony_register_sensors(struct sony_sc *sc)
input_abs_set_res(sc->sensor_dev, ABS_RY, DS4_GYRO_RES_PER_DEG_S);
input_abs_set_res(sc->sensor_dev, ABS_RZ, DS4_GYRO_RES_PER_DEG_S);
+ __set_bit(EV_MSC, sc->sensor_dev->evbit);
+ __set_bit(MSC_TIMESTAMP, sc->sensor_dev->mscbit);
__set_bit(INPUT_PROP_ACCELEROMETER, sc->sensor_dev->propbit);
ret = input_register_device(sc->sensor_dev);
--
2.7.4
next prev parent reply other threads:[~2016-12-09 3:10 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-09 3:09 [PATCH 0/7] HID: sony: DS4 fixes and improvements Roderick Colenbrander
2016-12-09 3:09 ` [PATCH 1/7] HID: sony: Fix error handling bug when touchpad registration fails Roderick Colenbrander
2016-12-19 14:08 ` Jiri Kosina
2016-12-09 3:09 ` [PATCH 2/7] HID: sony: Use DS4 MAC address as unique identifier on USB Roderick Colenbrander
2016-12-19 14:08 ` Jiri Kosina
2016-12-09 3:09 ` [PATCH 3/7] HID: sony: Ignore DS4 dongle reports when no device is connected Roderick Colenbrander
2016-12-19 14:08 ` Jiri Kosina
2016-12-09 3:09 ` [PATCH 4/7] HID: sony: Report DS4 motion sensors through a separate device Roderick Colenbrander
2016-12-09 3:09 ` [PATCH 5/7] HID: sony: Calibrate DS4 motion sensors Roderick Colenbrander
2016-12-09 3:09 ` Roderick Colenbrander [this message]
2016-12-09 3:09 ` [PATCH 7/7] HID: sony: Remove report descriptor fixup for DS4 Roderick Colenbrander
2016-12-09 17:51 ` [PATCH 0/7] HID: sony: DS4 fixes and improvements Bird, Timothy
2017-01-03 13:58 ` Jiri Kosina
2017-01-03 21:01 ` Roderick Colenbrander
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1481252996-25288-7-git-send-email-roderick@gaikai.com \
--to=roderick@gaikai.com \
--cc=benjamin.tissoires@redhat.com \
--cc=dmitry.torokhov@gmail.com \
--cc=frank.praznik@gmail.com \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=roderick.colenbrander@sony.com \
--cc=simon@mungewell.org \
--cc=tim.bird@am.sony.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.