Skip to content

Commit 8a31d08

Browse files
Ping Chengjigpu
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]> [[email protected]: Imported into input-wacom (17d793f3ed53)] Signed-off-by: Ping Cheng <[email protected]>
1 parent 21c6b46 commit 8a31d08

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

4.5/wacom_wac.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,11 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
13181318

13191319
struct input_dev *pen_input = wacom->pen_input;
13201320
unsigned char *data = wacom->data;
1321+
int number_of_valid_frames = 0;
1322+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,4,0)
1323+
int time_interval = 15000000;
1324+
ktime_t time_packet_received = ktime_get();
1325+
#endif
13211326
int i;
13221327

13231328
if (wacom->features.type == INTUOSP2_BT ||
@@ -1338,12 +1343,34 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
13381343
wacom->id[0] |= (wacom->serial[0] >> 32) & 0xFFFFF;
13391344
}
13401345

1346+
/* number of valid frames */
13411347
for (i = 0; i < pen_frames; i++) {
13421348
unsigned char *frame = &data[i*pen_frame_len + 1];
13431349
bool valid = frame[0] & 0x80;
1350+
1351+
if (valid)
1352+
number_of_valid_frames++;
1353+
}
1354+
1355+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,4,0)
1356+
if (number_of_valid_frames) {
1357+
if (wacom->hid_data.time_delayed)
1358+
time_interval = ktime_get() - wacom->hid_data.time_delayed;
1359+
time_interval /= number_of_valid_frames;
1360+
wacom->hid_data.time_delayed = time_packet_received;
1361+
}
1362+
#endif
1363+
1364+
for (i = 0; i < number_of_valid_frames; i++) {
1365+
unsigned char *frame = &data[i*pen_frame_len + 1];
1366+
bool valid = frame[0] & 0x80;
13441367
bool prox = frame[0] & 0x40;
13451368
bool range = frame[0] & 0x20;
13461369
bool invert = frame[0] & 0x10;
1370+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,4,0)
1371+
int frames_number_reversed = number_of_valid_frames - i - 1;
1372+
int event_timestamp = time_packet_received - frames_number_reversed * time_interval;
1373+
#endif
13471374

13481375
if (!valid)
13491376
continue;
@@ -1356,6 +1383,7 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
13561383
wacom->tool[0] = 0;
13571384
wacom->id[0] = 0;
13581385
wacom->serial[0] = 0;
1386+
wacom->hid_data.time_delayed = 0;
13591387
return;
13601388
}
13611389

@@ -1392,6 +1420,7 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
13921420
get_unaligned_le16(&frame[11]));
13931421
}
13941422
}
1423+
13951424
if (wacom->tool[0]) {
13961425
input_report_abs(pen_input, ABS_PRESSURE, get_unaligned_le16(&frame[5]));
13971426
if (wacom->features.type == INTUOSP2_BT ||
@@ -1415,6 +1444,10 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
14151444

14161445
wacom->shared->stylus_in_proximity = prox;
14171446

1447+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,4,0)
1448+
/* add timestamp to unpack the frames */
1449+
input_set_timestamp(pen_input, event_timestamp);
1450+
#endif
14181451
input_sync(pen_input);
14191452
}
14201453
}

4.5/wacom_wac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ struct hid_data {
348348
int ps_connected;
349349
bool pad_input_event_flag;
350350
unsigned short sequence_number;
351+
int time_delayed;
351352
};
352353

353354
struct wacom_remote_data {

0 commit comments

Comments
 (0)