生活随笔
收集整理的這篇文章主要介紹了
input子系统基础之按键5——按键驱动
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
以下內(nèi)容源于朱有鵬《物聯(lián)網(wǎng)大講堂》課程的學(xué)習(xí),如有侵權(quán),請(qǐng)告知?jiǎng)h除。
1、模板(參考input_programming.txt)
(1)input類設(shè)備驅(qū)動(dòng)模式非常固定,用參考模版修改即可
(2)新建驅(qū)動(dòng)項(xiàng)目并粘貼模版內(nèi)容
2、模板驅(qū)動(dòng)的解析
3、著手移植驅(qū)動(dòng)
4、驅(qū)動(dòng)移植細(xì)節(jié)
5、驅(qū)動(dòng)實(shí)踐
#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_IRQ IRQ_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@qq.com>");
MODULE_DESCRIPTION("key driver for x210 button.");
總結(jié)
以上是生活随笔為你收集整理的input子系统基础之按键5——按键驱动的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。