抑郁症健康,内容丰富有趣,生活中的好帮手!
抑郁症健康 > input子系统基础之按键5——按键驱动

input子系统基础之按键5——按键驱动

时间:2021-07-21 05:46:15

相关推荐

以下内容源于朱有鹏《物联网大讲堂》课程的学习,如有侵权,请告知删除。

1、模板(参考input_programming.txt)

(1)input类设备驱动模式非常固定,用参考模版修改即可

(2)新建驱动项目并粘贴模版内容

2、模板驱动的解析

3、着手移植驱动

4、驱动移植细节

5、驱动实践

#include <linux/input.h> #include <linux/module.h> #include <linux/init.h>#include <asm/irq.h> #include <asm/io.h>#include <mach/irqs.h>// arch/arm/mach-s5pv210/include/mach/irqs.h#include <linux/interrupt.h>#include <linux/gpio.h>/** X210:** POWER -> EINT1 -> GPH0_1* LEFT -> EINT2 -> GPH0_2* DOWN -> EINT3 -> GPH0_3* UP-> KP_COL0 -> GPH2_0* RIGHT -> KP_COL1 -> GPH2_1* MENU -> KP_COL3 -> GPH2_3 (KEY_A)* BACK -> KP_COL2 -> GPH2_2 (KEY_B)*/#define BUTTON_IRQIRQ_EINT2static struct input_dev *button_dev;static irqreturn_t button_interrupt(int irq, void *dummy) { int flag;s3c_gpio_cfgpin(S5PV210_GPH0(2), S3C_GPIO_SFN(0x0));// input模式flag = gpio_get_value(S5PV210_GPH0(2));s3c_gpio_cfgpin(S5PV210_GPH0(2), S3C_GPIO_SFN(0x0f));// eint2模式input_report_key(button_dev, KEY_LEFT, !flag);input_sync(button_dev);return IRQ_HANDLED; }static int __init button_init(void) { int error;error = gpio_request(S5PV210_GPH0(2), "GPH0_2");if(error)printk("key-s5pv210: request gpio GPH0(2) fail");s3c_gpio_cfgpin(S5PV210_GPH0(2), S3C_GPIO_SFN(0x0f));// eint2模式if (request_irq(BUTTON_IRQ, button_interrupt, IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, "button-x210", NULL)) { printk(KERN_ERR "key-s5pv210.c: Can't allocate irq %d\n", BUTTON_IRQ);return -EBUSY; }button_dev = input_allocate_device();if (!button_dev) { printk(KERN_ERR "key-s5pv210.c: Not enough memory\n");error = -ENOMEM;goto err_free_irq; }button_dev->evbit[0] = BIT_MASK(EV_KEY);button_dev->keybit[BIT_WORD(KEY_LEFT)] = BIT_MASK(KEY_LEFT);error = input_register_device(button_dev);if (error) { printk(KERN_ERR "key-s5pv210.c: Failed to register device\n");goto err_free_dev; }return 0;err_free_dev:input_free_device(button_dev);err_free_irq:free_irq(BUTTON_IRQ, button_interrupt);return error; }static void __exit button_exit(void) { input_unregister_device(button_dev); free_irq(BUTTON_IRQ, button_interrupt); }module_init(button_init); module_exit(button_exit); MODULE_LICENSE("GPL");MODULE_AUTHOR("aston <1264671872@>");MODULE_DESCRIPTION("key driver for x210 button.");

如果觉得《input子系统基础之按键5——按键驱动》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。