📄 simple_key.c
字号:
/*
* $Id$
* EAX-400 linux实验指导书配套实验代码
* 实验2.3 mini键盘(一个简单的单按键驱动程序)
* Copyright (c) 2006 Beijing EFLAG Technology Co.,LTD
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/config.h>#ifndef __KERNEL__ #define __KERNEL__#endif#ifndef MODULE #define MODULE#endif
#include <linux/input.h>#include <linux/module.h>#include <linux/init.h>#include <asm/irq.h>#include <asm/io.h>
#define SIMPLE_KEY_GPIO 17
#define SIMPLE_KEY_IRQ IRQ_GPIO(SIMPLE_KEY_GPIO)
#define SIMPLE_KEY_PORT 0x40000000 /* 需要根据事件设置修改 */
static struct input_dev simple_key_dev = {
name: "simple key",
idversion: 0x0100,
};static void simple_key_interrupt(int irq, void *dummy, struct pt_regs *fp){ /* 报告事件发生 */
input_report_key(&simple_key_dev, KEY_1, inb(SIMPLE_KEY_PORT) & 1);}static int __init simple_key_init(void){ if (request_irq(SIMPLE_KEY_IRQ, simple_key_interrupt, 0, "simple key", NULL)) { printk(KERN_ERR "simple_key.c: Can't allocate irq %d\n", SIMPLE_KEY_IRQ); return -EBUSY; } simple_key_dev.evbit[0] = BIT(EV_KEY); /* 设备产生的事件类型 */ simple_key_dev.keybit[LONG(KEY_1)] = BIT(KEY_1);/* 设备支持的按键 */ input_register_device(&simple_key_dev);
return 0;}static void __exit simple_key_exit(void){ input_unregister_device(&simple_key_dev); free_irq(SIMPLE_KEY_IRQ, simple_key_interrupt);}module_init(simple_key_init);module_exit(simple_key_exit);
MODULE_LICENSE("GPL");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -