debounce.c 623 B

1234567891011121314151617181920212223242526272829303132
  1. #include "drv_types.h"
  2. #include "debounce.h"
  3. static void debounce_timer_function(void *arg)
  4. {
  5. DEBOUNCE *db = (DEBOUNCE*)arg;
  6. db->notice(db->param);
  7. }
  8. void debounce_init(DEBOUNCE *db, DEBOUNCE_FUNCTION notice)
  9. {
  10. init_timer(&db->tm);
  11. db->notice = notice;
  12. db->param = NULL;
  13. }
  14. void debounce_exit(DEBOUNCE *db)
  15. {
  16. del_timer(&db->tm);
  17. }
  18. void debounce_notice(DEBOUNCE *db, void *param, UINT32 dDelay_ms)
  19. {
  20. del_timer(&db->tm);
  21. db->tm.expires = jiffies + ((HZ / 1000) * (dDelay_ms + 1));
  22. db->tm.data = (UINT32)db;
  23. db->tm.function = (void (*)(ULONG))debounce_timer_function;
  24. db->param = param;
  25. add_timer(&db->tm);
  26. }