|
发表于 2020-8-21 20:41:03
6521 浏览 0 回复
按键驱动添加定时器消抖
static struct timer_list buttons_timer1;static struct _KEYINFO *irq_pd1;
irqreturn_t irqkey_irq_handler1(int irq, void *data)
{
irq_pd1 = (struct _KEYINFO *)data;
mod_timer(&buttons_timer1, jiffies+HZ/1000);
//内核定义HZ为1000
return IRQ_HANDLED;
}
static void buttons_timer_function1(unsigned long data)
{
struct _KEYINFO * pindesc = irq_pd1;
if (!pindesc)
return;
if (gpio_get_value(key1.gpio_num))
{
input_report_key(irqkey_input, KEY_F1, 0);
printk("*******KEY_F1 0*************\n");
input_sync(irqkey_input);
}
else
{
input_report_key(irqkey_input, KEY_F1, 1);
input_sync(irqkey_input);
printk("*******KEY_F1 1*************\n");
}
}
proble(){
init_timer(&buttons_timer1);
buttons_timer1.function = buttons_timer_function1;
add_timer(&buttons_timer1);
}
|
|
|
|
|
|
|
登录或注册
|