最近按照国嵌培训视频做了一个按键驱动的项目,由于使用配置好的内核,该内核已经将按键驱动编译到系统当中,驱动程序中request_irq()返回-16,-16指的是该驱动已经被注册,解决办法是将内核中的按键驱动去掉,进入内核文件夹 make mennuconfig .driver_device ->inputdevice->keyboard 进入页面后 全部取消。保存退出 执行make uImage ARCH=arm CROSS_COMPILE=arm-linux-
#include <linux/init.h>
#include <linux/module.h>
#include <linux/miscdevice.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/io.h>
#include <linux/interrupt.h>
#define GPFCON 0X56000050
irqreturn_t key_int(int irq, void *dev_id)
{
//检测是否发生按键中断
//清除按键中断
//打印按键值
printk("interrupt\n");
return 0;
}
void key_hw_init()
{
unsigned int *gpio_config;
unsigned short data;
printk("initial success\n");
gpio_config = ioremap(GPFCON, 4);
data = readw(gpio_config);
data &= ~0b11;
data |= 0b10;
writew(data, gpio_config);
}
int key_open(struct inode * inode, struct file *filep)
{
return 0;
}
long key_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
{
return 0;
}
static struct file_operations key_fops =
{
.open = key_open,
.unlocked_ioctl = key_ioctl,
};
static struct miscdevice key_miscdev =
{
.minor = 200,
.name = "key",
.fops = &key_fops,
};
static int key1_init()
{
//注册混杂设备
misc_register(&key_miscdev);
int n = 3;
//注册中断
key_hw_init();
n = request_irq(IRQ_EINT0, key_int, IRQF_TRIGGER_FALLING, "key", 0);
printk("n=%d",n);
//按键初始化
return 0;
}
static void key1_exit()
{
misc_deregister(&key_miscdev);
//注销
free_irq(IRQ_EINT0,0);
}
module_init(key1_init);
module_exit(key1_exit);
中断处理函数的类型为irqreturn_t 必须有return 本人疏忽 没有写return 0;内核异常 驱动不好使