From 5e3e8f1b44e420800f62c993878bf6ad43adb038 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Tue, 18 Nov 2025 18:16:29 +0100 Subject: [PATCH] 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 Link: https://gitlab.freedesktop.org/libevdev/udev-hid-bpf/-/merge_requests/195 Signed-off-by: Benjamin Tissoires Signed-off-by: Jiri Kosina --- .../hid/bpf/progs/Huion__Inspiroy-2-S.bpf.c | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/drivers/hid/bpf/progs/Huion__Inspiroy-2-S.bpf.c b/drivers/hid/bpf/progs/Huion__Inspiroy-2-S.bpf.c index 13f64fb49800..79453362bf97 100644 --- a/drivers/hid/bpf/progs/Huion__Inspiroy-2-S.bpf.c +++ b/drivers/hid/bpf/progs/Huion__Inspiroy-2-S.bpf.c @@ -163,6 +163,9 @@ char EXPECTED_FIRMWARE_ID[] = "HUION_T21j_"; __u8 last_button_state; +__u8 last_tip_state; +__u8 last_sec_barrel_state; +__u8 force_tip_down_count; static const __u8 fixed_rdesc_pad[] = { UsagePage_GenericDesktop @@ -522,9 +525,31 @@ int BPF_PROG(inspiroy_2_fix_events, struct hid_bpf_ctx *hctx) pad_report->wheel = wheel; return sizeof(struct pad_report); - } + } else if (data[1] & 0x80) { /* Pen reports with InRange 1 */ + __u8 tip_state = data[1] & 0x1; + __u8 sec_barrel_state = data[1] & 0x4; - /* Pen reports need nothing done */ + if (force_tip_down_count > 0) { + data[1] |= 0x1; + --force_tip_down_count; + if (tip_state) + force_tip_down_count = 0; + } + + /* Tip was down and we just pressed or released the + * secondary barrel switch (the physical eraser + * button). The device will send up to 4 + * reports with Tip Switch 0 and sometimes + * this report has Tip Switch 0. + */ + if (last_tip_state && + last_sec_barrel_state != sec_barrel_state) { + force_tip_down_count = 4; + data[1] |= 0x1; + } + last_tip_state = tip_state; + last_sec_barrel_state = sec_barrel_state; + } } return 0;