Stylus BTN_TOUCH instead of BTN_STYLUS

Xournal always uses the pen tool even when holding button or using eraser side of stylus. Trying different settings in Xournal did not change behavior. The input events show the problem by running sudo evtest.

All of the proper scan codes are listed by evtest

$ sudo evtest /dev/input/event6 Input driver version is 1.0.1 Input device ID: bus 0x18 vendor 0x0 product 0x0 version 0x0 Input device name: "elan_pen" Supported events: Event type 0 (EV_SYN) Event type 1 (EV_KEY) Event code 158 (KEY_BACK) Event code 321 (BTN_TOOL_RUBBER) Event code 330 (BTN_TOUCH) Event code 331 (BTN_STYLUS) Event code 332 (BTN_STYLUS2)

but when using the stylus, the even is almost always BTN_TOUCH.

I can occasionally see events for BTN_TOOL_RUBBER or BTN_STYLUS but they happen at the wrong time. I never see events for BTN_STYLUS2.

The behavior is that button down event value 1 will happen correctly the first time, but there is not a button release event value 0 until one of the other buttons of the stylus is used. Pressing the eraser down, up, down, up will only get the first down event. If instead you do a sequence like eraser down, eraser up, stylus down then there will be both the down and up events for the eraser, but eraser event does not happen until just before the stylus down event (even if it is many seconds later).

`$ sudo evtest /dev/input/event6 | grep “code 3”
Event code 321 (BTN_TOOL_RUBBER)
Event code 330 (BTN_TOUCH)
Event code 331 (BTN_STYLUS)
Event code 332 (BTN_STYLUS2)

#press tip
Event: time 1646153071.150750, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1
#release tip
Event: time 1646153071.991082, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 0

#press eraser
Event: time 1646153090.008240, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1
Event: time 1646153090.037771, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 0
Event: time 1646153090.041876, type 1 (EV_KEY), code 321 (BTN_TOOL_RUBBER), value 1
Event: time 1646153090.042080, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1
#release eraser
Event: time 1646153091.071959, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 0

#press tip
Event: time 1646153110.509076, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1
Event: time 1646153110.544403, type 1 (EV_KEY), code 321 (BTN_TOOL_RUBBER), value 0
#release tip
Event: time 1646153111.424647, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 0

#press tip with side button
Event: time 1646153217.361364, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1
Event: time 1646153217.389645, type 1 (EV_KEY), code 331 (BTN_STYLUS), value 1
#release tip with side button
Event: time 1646153218.531313, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 0

#press eraser
Event: time 1646153234.169866, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1
Event: time 1646153234.184921, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 0
Event: time 1646153234.189876, type 1 (EV_KEY), code 331 (BTN_STYLUS), value 0
Event: time 1646153234.191464, type 1 (EV_KEY), code 321 (BTN_TOOL_RUBBER), value 1
Event: time 1646153234.191523, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1

#release eraser
Event: time 1646153235.174955, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 0

#press eraser
Event: time 1646153342.557991, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1
#release eraser
Event: time 1646153344.764673, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 0
`

So a couple things are happening:

  1. BTN_STYLUS events are happening for the tip with the side button (should be BTN_STYLUS2)
  2. no events are happening for the tip (except the BTN_TOUCH events that happen all of the time)
  3. up events only happen when a different part of the stylus is down, even if it is seconds or minuets later.

Is the behavior of the driver configurable?

I’m willing to take a look at the elan_ts_i2c driver to see if I can find the issue. Where is the source?