qt2410-buttons.c

来自「这份源码是用基于QT2410的嵌入式Linux开发的按键驱动程序以及测试程序.」· C语言 代码 · 共 85 行

C
85
字号
#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/miscdevice.h>#include <linux/sched.h>#include <linux/delay.h>#include <linux/poll.h>#include <linux/spinlock.h>#include <linux/irq.h>#include <linux/delay.h>#include <asm/hardware.h>#define DEVICE_NAME	"qt2410_btns"#define BUTTON_MAJOR 232#define IRQ_BUTTONS IRQ_EINT7//static int count = 0;//static int ready = 0;static int key_value = 0;static DECLARE_WAIT_QUEUE_HEAD(buttons_wait);static void buttons_io_port_init(void){	set_gpio_ctrl(GPIO_F0 | GPIO_PULLUP_DIS | GPIO_MODE_IN);//added	set_gpio_ctrl(GPIO_F2 | GPIO_PULLUP_DIS | GPIO_MODE_IN);//added}static int qt2410_buttons_read(struct file * file, char * buffer, size_t count, loff_t *ppos){        if (count != sizeof key_value)                return -EINVAL;	key_value = GPFDAT;//added        copy_to_user(buffer, &key_value, sizeof key_value);        return sizeof key_value;}static int qt2410_buttons_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){	switch(cmd) {	default:		return -EINVAL;	}}static struct file_operations qt2410_buttons_fops = {	owner:	THIS_MODULE,	ioctl:  qt2410_buttons_ioctl,//	poll: qt2410_buttons_select,	read: qt2410_buttons_read,};static devfs_handle_t devfs_handle;static int __init qt2410_buttons_init(void){	int ret;	ret = register_chrdev(BUTTON_MAJOR, DEVICE_NAME, &qt2410_buttons_fops);	if (ret < 0) {	  printk(DEVICE_NAME " can't register major number\n");	  return ret;	}	buttons_io_port_init();	devfs_handle = devfs_register(NULL, DEVICE_NAME, DEVFS_FL_DEFAULT,				BUTTON_MAJOR, 0, S_IFCHR | S_IRUSR | S_IWUSR, &qt2410_buttons_fops, NULL);	return 0;}static void __exit qt2410_buttons_exit(void){	devfs_unregister(devfs_handle);	unregister_chrdev(BUTTON_MAJOR, DEVICE_NAME);}module_init(qt2410_buttons_init);module_exit(qt2410_buttons_exit);MODULE_LICENSE("GPL");

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?