Skip to content

Commit 5e3e8f1

Browse files
Benjamin TissoiresJiri Kosina
authored andcommitted
HID: bpf: add heuristics to the Huion Inspiroy 2S eraser button
When pressing the phsyical eraser button (remapped by us to the Secondary Barrel Switch) while the tip is down, the device gives us several false reports with a Tip Switch 0: press| |release SBS: [0 0 ... 1 1 1 ... 1 0 0 0 0 0 0 ...] TS: [1 1 ... 1 0 1 ... 1 1 0 0 0 1 1 ...] In both press/release the number of Tip Switch 0 reports can be up to 4 and *sometimes* the Tip Switch is released in the same report as the button press/release event. Paper over this by forcing the tip down for a few reports if it was down before the button toggled. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Link: https://gitlab.freedesktop.org/libevdev/udev-hid-bpf/-/merge_requests/195 Signed-off-by: Benjamin Tissoires <bentiss@kernel.org> Signed-off-by: Jiri Kosina <jkosina@suse.com>
1 parent 88b5468 commit 5e3e8f1

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

drivers/hid/bpf/progs/Huion__Inspiroy-2-S.bpf.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ char EXPECTED_FIRMWARE_ID[] = "HUION_T21j_";
163163

164164

165165
__u8 last_button_state;
166+
__u8 last_tip_state;
167+
__u8 last_sec_barrel_state;
168+
__u8 force_tip_down_count;
166169

167170
static const __u8 fixed_rdesc_pad[] = {
168171
UsagePage_GenericDesktop
@@ -522,9 +525,31 @@ int BPF_PROG(inspiroy_2_fix_events, struct hid_bpf_ctx *hctx)
522525
pad_report->wheel = wheel;
523526

524527
return sizeof(struct pad_report);
525-
}
528+
} else if (data[1] & 0x80) { /* Pen reports with InRange 1 */
529+
__u8 tip_state = data[1] & 0x1;
530+
__u8 sec_barrel_state = data[1] & 0x4;
531+
532+
if (force_tip_down_count > 0) {
533+
data[1] |= 0x1;
534+
--force_tip_down_count;
535+
if (tip_state)
536+
force_tip_down_count = 0;
537+
}
526538

527-
/* Pen reports need nothing done */
539+
/* Tip was down and we just pressed or released the
540+
* secondary barrel switch (the physical eraser
541+
* button). The device will send up to 4
542+
* reports with Tip Switch 0 and sometimes
543+
* this report has Tip Switch 0.
544+
*/
545+
if (last_tip_state &&
546+
last_sec_barrel_state != sec_barrel_state) {
547+
force_tip_down_count = 4;
548+
data[1] |= 0x1;
549+
}
550+
last_tip_state = tip_state;
551+
last_sec_barrel_state = sec_barrel_state;
552+
}
528553
}
529554

530555
return 0;

0 commit comments

Comments
 (0)