HID Input 事件映射与输出控制

HID Input 事件映射与输出控制

1. 映射目标

hid-input.c 把 HID Usage 转为 Linux input:

HID Linux input
Keyboard/Keypad EV_KEY
Button BTN_* / KEY_*
Generic Desktop X/Y EV_RELEV_ABS
Wheel/Consumer REL_WHEEL / media keys
Digitizer ABS、touch、tool
LED EV_LED

2. Connect

1
2
3
4
5
6
hid_connect(HID_CONNECT_HIDINPUT)
-> hidinput_connect()
-> walk input reports/fields/usages
-> hidinput_allocate()
-> hidinput_configure_usage()
-> input_register_device()

一个 HID device 可因多个 Application Collection 或 HID_QUIRK_MULTI_INPUT 生成多个 input device。

3. Usage 映射扩展点

专用驱动可实现:

  • input_mapping():改写或忽略 usage;
  • input_mapped():通用映射完成后的调整;
  • event():在通用输入事件前处理;
  • report():整份 report 完成后处理。

返回值语义需按 HID API:错误使用会造成重复事件或 usage 丢失。

4. 运行时上报

hid_process_event() 调专用 driver event,再进入 hidinput_hid_event()。report 完成后 hidinput_report_event() 对相关 input device 执行 sync,并处理工具释放等状态。

5. Absolute 参数

Core 根据 logical/physical range、unit 和 exponent 设置:

  • input_set_abs_params()
  • resolution;
  • fuzz/flat;
  • multitouch axis。

损坏 descriptor 会导致坐标、分辨率或方向错误,通常由 report fixup 或专用映射修正。

6. Output/LED

键盘 LED 等输出可由 input event 回调更新 HID Output report:

1
2
3
4
5
userspace EV_LED
-> HID input event
-> set field value
-> hid_hw_request(HID_REQ_SET_REPORT)
-> transport

USB 可走 interrupt OUT 或 control;I2C HID 使用 SET_REPORT/输出寄存器。

7. Force Feedback

三类常见实现:

  • HID PID 标准:usbhid/hid-pidff.c
  • input_ff_create_memless() 的设备专用 rumble;
  • 专用协议,如 Logitech/Sony/PlayStation/Nintendo。

FF output report 可能包含强度、时长、effect slot。产品不使用时可裁剪相关专用驱动。

8. 电池

CONFIG_HID_BATTERY_STRENGTH 使 HID battery usage 注册 power_supply,并读取 Feature/Input report。无线手柄、键鼠可由 upower 等查看。

电池值可能存在:

  • 自定义量程;
  • UNKNOWN/NOT_CHARGING;
  • Feature report 查询延迟;
  • 设备专用缩放 quirk。

9. 多键与恢复

数组 report 通过旧值/新值差异释放和按下按键。暂停恢复时 hid_check_keys_pressed() 可用于判断仍有按键,避免错误 autosuspend。设备拔出由 input unregister 释放状态。

10. 调试

1
2
3
4
cat /proc/bus/input/devices
evtest /dev/input/eventX
libinput debug-events
getevent -l

Android getevent 看到的是 input 层结果,不能直接证明原始 HID report 正确;必要时同时抓 hidraw/debugfs。

文章互动

阅读 --

留言

0 条留言

正在加载留言…