free_irq(IRQ_EINT17 , 3);
free_irq(IRQ_EINT219, 4);
参数为中断号和ID
return 0;
}
内核有个函数为:
int up = s3c2410_gpio_getpin(button_irqs->pin);读取
用switch写太麻烦,可以用结构体。
struct pin_desc{}
{
unsigned int pin;
unsigned int key_val;
}
/*键值:按下为0x01,0x02,0x03,0x04/
/*松开时,为0x81,0x82,0x83,0x84*/
static unsigned char key_val;
static DEVLARE_WAIT_QUEUE_HEAD(button_waitq);
中断事件标志,中断服务程序将它置1,third_drv_read将它清0
static volatile int ev_press = 0;
struct pin_desc pins_desc[4] = {
{S3C2410_GPF0 , 0X01},
{S3C2410_GPF2 , 0X02},
{S3C2410_GPG3 , 0X03},
{S3C2410_GPG11 , 0X04},
};
怎样调用这个数组?
在open函数中将值传入id!
处理函数:根据ID来判断哪个按键造成的中断!
static irqreturn_t buttons_irq(int irq , void *dev_id) irq貌似为中断号
{
struct pin_desc *pindesc = (struct pin_desc *)dev_id;
unsigned int pinval;
pinval = s3c2410_gpio_getpin(pindesc->pi);
if(pinval)
{
key_val = 0x80 | pindesc->key_val;
/*松开*/
}
else
{
/*按下*/
}
ev_press = 1;
wake_up_interruptible(&button_waitq);
return IRQ_HANDLED;
}
ssize_t third_drv_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
{
/*如果没有按键动作发生就休眠!!!即让出CPU,不返回值!
若按键按下就返回值!
*/
wait_event_interruptible(button_waitq,ev_press);
当ev_press = 0 ,他就会休眠。不等于0,往下运行。
copy_to_user(buf,key_val,1);
ev_press = 0;
return 0;
}