对应的DTS配置
位置:/Documentation/devicetree/bindings/input/gpio-keys.txt
Device-Tree bindings for input/gpio_keys.c keyboard driver
Required properties:
- compatible = "gpio-keys"; // 设备兼容性
// 对应gpio_key.c的gpio_keys_of_match
Optional properties:
- autorepeat: Boolean, Enable auto repeat feature of Linux input
subsystem. // 启动input子系统的auto repeat特性
- label: String, name of the input device.
Each button (key) is represented as a sub-node of "gpio-keys":
Subnode properties:
// 每个button (key) 都表示为“gpio-keys”的一个子节点:
- gpios: OF device-tree gpio specification. // gpios规格属性
- interrupts: the interrupt line for that input. // gpio中断
- label: Descriptive name of the key. // 名字
- linux,code: Keycode to emit. // input子系统的code
Note that either "interrupts" or "gpios" properties can be omitted, but not
both at the same time. Specifying both properties is allowed.
// 请注意,可以省略“interrupts”或“gpios”属性,但不能同时省略两者。 允许同时指定这两个属性。
Optional subnode-properties:
- linux,input-type: Specify event type this button/key generates.
If not specified defaults to <1> == EV_KEY.
// 指定按键的event type(input子系统定义),未指定默认为1 == EV_KEY
- debounce-interval: Debouncing interval time in milliseconds.
If not specified defaults to 5.
// 按键去抖间隔,未指定默认5ms
- wakeup-source: Boolean, button can wake-up the system.
(Legacy property supported: "gpio-key,wakeup")
// 按键可以唤醒系统
- linux,can-disable: Boolean, indicates that button is connected
to dedicated (not shared) interrupt which can be disabled to
suppress events from the button.
// 按钮连接到专用(非共享)中断,可以禁用该中断以关闭来自按钮的事件
// 共享中断:同1个gpio可以设置几个中断
Example nodes:
gpio-keys {
compatible = "gpio-keys";
autorepeat;
up {
label = "GPIO Key UP";
linux,code = <103>;
gpios = <&gpio1 0 1>;
};
down {
label = "GPIO Key DOWN";
linux,code = <108>;
interrupts = <1 IRQ_TYPE_LEVEL_HIGH 7>;
};
...
key/button配置参数
struct gpio_keys_button {
unsigned int code; // input event code (KEY_*, SW_*)
int gpio; // -1 if this key does not support gpio
int active_low; // true:表示当gpio是低电平时按钮被按下
const char *desc; // label,添加到gpio的按键上
unsigned int type; // input event type (%EV_KEY, %EV_SW, %EV_ABS)
int wakeup; // configure the button as a wake-up source
int debounce_interval; // 去抖动间隔,以毫秒为单位
bool can_disable; // true 表示允许用户空间通过 sysfs 禁用按键
int value; // EV_ABS 的轴值
unsigned int irq; // 中断按键下的 Irq 编号
struct gpio_desc *gpiod; // GPIO descriptor