Skip to contentSkip to conversation

Writing a Driver for Xinmeng M71 Keyboard (Battery Status Support)

RFC Saalim Quadri 2 participants 3 messages Jun 22, 2025 – Jun 23, 2025 HID

lore
Share & tools
lore
#0 lore raw

Hello everyone,

I'm currently working with a Xinmeng M71 wireless keyboard, which is recognized by the kernel as a hid-generic device and functions well.

I'd like to extend its support in Linux by writing a driver that can expose its battery status to userspace,
I used hidtools to record descriptors of the keyboards, I discharged my keyboard over the week and charged it and recorded the responses from it, like when it started charging/discharging, I saw hex values change reporting me the percentage of the charge

E: 000002.772731 20 13 0a 01 00 04 05 63 01 00 00 00 00 00 00 00 00 00 00 00 8b
# ReportID: 19 /Array ['0a', '01', '0xff020002', '04', '05', '63', '11', '0xff020002', '0xff020002', '0xff020002', '0xff020002', '0xff020002', '0xff020002', '0xff020002', '0xff020002', '0xff020002', '0xff020002', '0xff020002', '9b']
E: 000005.642942 20 13 0a 01 00 04 05 63 11 00 00 00 00 00 00 00 00 00 00 00 9b
# ReportID: 19 /Array ['0a', '01', '0xff020002', '04', '05', '64', '11', '0xff020002', '0xff020002', '0xff020002', '0xff020002', '0xff020002', '0xff020002', '0xff020002', '0xff020002', '0xff020002', '0xff020002', '0xff020002', '9c']
E: 000005.860767 20 13 0a 01 00 04 05 64 11 00 00 00 00 00 00 00 00 00 00 00 9c

I would appreciate guidance on, how can I continue this, I am familiar with Linux Kernel and writing drivers, but would like to ask some pointers regarding the same. I saw a reference that logitech HID driver uses it, but it looked quite complex to me.

I'm comfortable writing kernel C code but relatively new to the HID subsystem. Any documentation pointers, example patches, or suggestions to get started would be highly appreciated.

Looking forward to your responses.

Thank you very much,

Sincerely,
Saalim Quadri

maintainer
#1 lore raw
Quoted 8 lines · Saalim Quadri

I would appreciate guidance on, how can I continue this, I am familiar with Linux Kernel and writing drivers, but would like to ask some pointers regarding the same. I saw a reference that logitech HID driver uses it, but it looked quite complex to me.

I'm comfortable writing kernel C code but relatively new to the HID subsystem. Any documentation pointers, example patches, or suggestions to get started would be highly appreciated.

Yeah, Logitech is probably the most complex (and thus not really appropriate :) ) driver to pick when trying to understand something. It's quite complex.

Specifically for handling battery interface, I'd suggest looking into some way more trivial driver that also exposes battery interface (in the most straightforward way) for inspiration, e.g. hid-asus, hid-kysona ...

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#2 lore raw

Thank you very much for the response,

I was able to parse the raw event and get the data, I am currently trying to figure out how to fetch the data on-demand and read the values, I took hid-kysona as reference.

I will be sending a patch soon for reviews

Thank you very much,

Sincerely,
Saalim Quadri