map220v / sm8150-mainline

WIP Mainline kernel for Xiaomi Pad 5
Other
33 stars 16 forks source link

Is it possiable to use xiaomi smart pen on linux? #3

Closed amazingfate closed 10 months ago

amazingfate commented 11 months ago

We are now using nt36523 touchscreen driver from @lujianhua. And https://github.com/map220v/sm8150-mainline/commit/bdec74573c383fad5a5300f8c6a33cc96caa15d3 has enabled pen support. I am running xiaomi pad 5 pro with the same touchscreen driver and that enble-pen patch. I bought a xiaomi smart pen and I can pair it via bluetooth by method from this XDA post. But only the two keys on pen works as PgUp and PgDn. I can see no events from command libinput-debug-events when drawing on touchscreen.

At the moment Windows has already supported xiaomi smart pen. So I guess there is still some work to get done on linux system side(kernel driver or userspace libinput?)

Here is my NVT driver log:

[    2.706031] [NVT-ts] nvt_ts_probe 1239: probe start
[    2.706183] [NVT-ts] nvt_ts_probe 1291: mode=0, max_speed_hz=19200000
[    2.706284] [NVT-ts] nvt_parse_dt 686: novatek,irq-gpio=585
[    2.706338] [NVT-ts] nvt_parse_dt 689: novatek,pen-support=1
[    2.706423] [NVT-ts] nvt_parse_dt 692: novatek,wgp-stylus=1
[    2.706476] [NVT-ts] nvt_parse_dt 699: SWRST_N8_ADDR=0x03F0FE
[    2.706561] [NVT-ts] nvt_parse_dt 708: SPI_RD_FAST_ADDR=0x03F310
[    2.706647] [NVT-ts] nvt_parse_dt 722: spi-max-frequency: 19200000
[    2.725357] [NVT-ts] nvt_ts_probe 1365: Set default fw_ver=0, x_num=32, y_num=50, abs_x_max=1600, abs_y_max=2560, max_button_num=0!
[    2.725536] input: NVTCapacitiveTouchScreen as /devices/virtual/input/input4
[    2.725721] input: NVTCapacitivePen as /devices/virtual/input/input5
[    2.725844] [NVT-ts] nvt_ts_probe 1453: int_trigger_type=1
[    2.726282] [NVT-ts] nvt_ts_probe 1462: request irq 197 succeed
[    2.726799] [NVT-ts] nvt_ts_probe 1495: NVT_TOUCH_ESD_PROTECT is 1
[    2.727158] [NVT-ts] nvt_ts_probe 1528: end
[    6.881416] [NVT-ts] update_firmware_request 302: filename is novatek/nt36523-boe.bin
[    6.884622] [NVT-ts] nvt_bin_header_parser 125: cascade_2nd_header_info = 1
[    6.884640] [NVT-ts] nvt_bin_header_parser 156: ovly_info = 0, ilm_dlm_num = 2, ovly_sec_num = 0, info_sec_num = 14, partition = 16
[    6.890497] [NVT-ts] nvt_tx_auto_copy_mode 328: tx auto copy mode enable
[    7.039066] [NVT-ts] nvt_update_firmware 821: Update firmware success! <154371 us>
[    7.039200] [NVT-ts] nvt_get_fw_info 644: fw_ver = 0x0B, fw_type = 0x01, x_num=32, y_num=50
[    7.039357] [NVT-ts] nvt_read_pid 581: PID=595C
[    7.039440] [NVT-ts] disable_pen_input_device 1180: ++
[    7.081529] [NVT-ts] disable_pen_input_device 1204: pen charge state is DISABLE, ENABLE pen input device
[    7.081544] [NVT-ts] disable_pen_input_device 1209: --
[    7.081643] [NVT-ts] nvt_get_fw_info 644: fw_ver = 0x0B, fw_type = 0x01, x_num=32, y_num=50
[    7.081768] [NVT-ts] nvt_read_pid 581: PID=595C
map220v commented 11 months ago

This code should enable pen reporing in nvt firmware, if there are no pen events in input5 then try replacing "!!disable" by 0, and try testing pen without bluetooth connection, maybe it will help.

Also you can uncomment this to see if pen event's are being sent.

amazingfate commented 11 months ago

After replacing "!!disable" by 0, and uncommenting pen dump buf print, I can't get pen dump buf printed when drawing with pen with or without bluetooth connected. When touching screen with finger I can see dump buf printed started with FF FF.

amazingfate commented 10 months ago

I think xiaomi elish is using a new driver for its touchscreen pen. I can see kernel driver has loaded a firmware named novatek_nt36523_k81a_fw02_pen.bin, and I can't see this from xiaomi's kernel code elish-r-oss. I will give up this pen on xiaomi elish.