linux中使用定时器去抖主要是因为性能问题,for循环也可以去抖,但是会影响机器性能,所以linux中都使用定时器去抖,解决机械按键的抖动问题。
linux内核中使用struct timer_list来描述一个定时器:
struct timer_list
{
sturct list_head entry;
unsigned long expires;
void (*function)(unsigned long );
unsigned long data;
struct tvec_base *base;
};
定时器使用流程:
1、定义定时器变量
2、初始化定时器:①init_timer初始化
②设置超时函数
3、add_timer注册定时器
4、mod_timer启动定时器