Skip to content

Commit 17d793f

Browse files
PinglinuxJiri Kosina
authored andcommitted
HID: wacom: insert timestamp to packed Bluetooth (BT) events
To fully utilize the BT polling/refresh rate, a few input events are sent together to reduce event delay. This causes issue to the timestamp generated by input_sync since all the events in the same packet would pretty much have the same timestamp. This patch inserts time interval to the events by averaging the total time used for sending the packet. This decision was mainly based on observing the actual time interval between each BT polling. The interval doesn't seem to be constant, due to the network and system environment. So, using solutions other than averaging doesn't end up with valid timestamps. Signed-off-by: Ping Cheng <[email protected]> Reviewed-by: Jason Gerecke <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 2653e3f commit 17d793f

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

drivers/hid/wacom_wac.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,9 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
13081308

13091309
struct input_dev *pen_input = wacom->pen_input;
13101310
unsigned char *data = wacom->data;
1311+
int number_of_valid_frames = 0;
1312+
int time_interval = 15000000;
1313+
ktime_t time_packet_received = ktime_get();
13111314
int i;
13121315

13131316
if (wacom->features.type == INTUOSP2_BT ||
@@ -1328,12 +1331,30 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
13281331
wacom->id[0] |= (wacom->serial[0] >> 32) & 0xFFFFF;
13291332
}
13301333

1334+
/* number of valid frames */
13311335
for (i = 0; i < pen_frames; i++) {
13321336
unsigned char *frame = &data[i*pen_frame_len + 1];
13331337
bool valid = frame[0] & 0x80;
1338+
1339+
if (valid)
1340+
number_of_valid_frames++;
1341+
}
1342+
1343+
if (number_of_valid_frames) {
1344+
if (wacom->hid_data.time_delayed)
1345+
time_interval = ktime_get() - wacom->hid_data.time_delayed;
1346+
time_interval /= number_of_valid_frames;
1347+
wacom->hid_data.time_delayed = time_packet_received;
1348+
}
1349+
1350+
for (i = 0; i < number_of_valid_frames; i++) {
1351+
unsigned char *frame = &data[i*pen_frame_len + 1];
1352+
bool valid = frame[0] & 0x80;
13341353
bool prox = frame[0] & 0x40;
13351354
bool range = frame[0] & 0x20;
13361355
bool invert = frame[0] & 0x10;
1356+
int frames_number_reversed = number_of_valid_frames - i - 1;
1357+
int event_timestamp = time_packet_received - frames_number_reversed * time_interval;
13371358

13381359
if (!valid)
13391360
continue;
@@ -1346,6 +1367,7 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
13461367
wacom->tool[0] = 0;
13471368
wacom->id[0] = 0;
13481369
wacom->serial[0] = 0;
1370+
wacom->hid_data.time_delayed = 0;
13491371
return;
13501372
}
13511373

@@ -1382,6 +1404,7 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
13821404
get_unaligned_le16(&frame[11]));
13831405
}
13841406
}
1407+
13851408
if (wacom->tool[0]) {
13861409
input_report_abs(pen_input, ABS_PRESSURE, get_unaligned_le16(&frame[5]));
13871410
if (wacom->features.type == INTUOSP2_BT ||
@@ -1405,6 +1428,9 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
14051428

14061429
wacom->shared->stylus_in_proximity = prox;
14071430

1431+
/* add timestamp to unpack the frames */
1432+
input_set_timestamp(pen_input, event_timestamp);
1433+
14081434
input_sync(pen_input);
14091435
}
14101436
}

drivers/hid/wacom_wac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ struct hid_data {
324324
int ps_connected;
325325
bool pad_input_event_flag;
326326
unsigned short sequence_number;
327+
int time_delayed;
327328
};
328329

329330
struct wacom_remote_data {

0 commit comments

Comments
 (0)