按键驱动:gpio_key.c

这篇博客详细介绍了GPIO按键驱动的配置过程,包括DTS配置、按键参数、平台配置和控制逻辑。同时,讨论了platform_device的driver_data以及设备注册、probe函数和资源解析。重点提到了gpio_keys_get_devtree_pdata如何将DTS节点属性转化为结构体成员值,供驱动获取。
摘要由CSDN通过智能技术生成

对应的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
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在Android 12系统中,gpio_keys_irq_timer函数是gpio_keys驱动的一个回调函数,用于处理GPIO按键中断事件超时的情况。在某些情况下,GPIO按键中断事件可能因为某些原因一直没有被处理,导致出现超时的情况。为了避免这种情况出现,gpio_keys_irq_timer函数会在一定时间内检测GPIO按键事件是否已经被处理,如果没有被处理,则会自动触发一个虚拟的按键事件,以便能够及时地响应GPIO按键事件。 该函数的具体实现可以参考以下代码: ``` static void gpio_keys_irq_timer(unsigned long data) { struct gpio_keys_data *gpio_data = (struct gpio_keys_data *)data; unsigned long flags; spin_lock_irqsave(&gpio_data->lock, flags); if (gpio_data->state == KEY_PRESSED) { // 超时,触发虚拟按键事件 gpio_data->state = KEY_RELEASED; input_report_key(gpio_data->input, gpio_data->code, 0); input_sync(gpio_data->input); } spin_unlock_irqrestore(&gpio_data->lock, flags); } ``` 在这段代码中,我们可以看到gpio_keys_irq_timer函数主要完成以下几个操作: 1. 获取gpio_keys_data结构体指针,该结构体包含了GPIO按键GPIO编号等信息。 2. 检测GPIO按键事件是否已经被处理,如果没有被处理,则会自动触发一个虚拟的按键事件。 3. 触发虚拟按键事件后,将GPIO按键状态设置为已释放状态,并上报给输入子系统。 4. 最后释放锁,完成gpio_keys_irq_timer函数的执行。 通过以上操作,gpio_keys_irq_timer函数保证了在GPIO按键事件超时的情况下,能够及时地响应GPIO按键事件,从而保证了系统的稳定性和可靠性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

未停丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值