按键事件检测与事件处理

async   异步

inquire  询问

synch   同步

 1 typedef struct button {
 2     uint16_t ticks;
 3     uint8_t  repeat       : 4;
 4     uint8_t  event        : 4;
 5     uint8_t  state        : 3;
 6     uint8_t  debounce_cnt : 3;
 7     uint8_t  active_level : 1;
 8     uint8_t  button_level : 1;
 9     uint8_t  (*hal_button_Level)(void);
10     BtnCallback  cb[number_of_event];
11     struct button* next;
12 }button;

值得学习的地方:

uint8_t  event  :4;  

uint8_t  (*hal_button_Level)(void);   函数指针

struct button *next;                           链表

1 #define EVENT_CB(ev) if(handle->cb[ev]) handle->cb[ev]((button*)handle)

文章地址:https://github.com/0x1abin/MultiButton

posted @ 2021-11-01 11:11  我爱茜茜公主  阅读(154)  评论(0)    收藏  举报