buttons.h 889 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #ifndef _BUTTONS_H_
  3. #define _BUTTONS_H_
  4. /* time constant in ms */
  5. #define BTN_SCAN_PERIOD 10
  6. #define BTN_SCAN_PAUSE (200/BTN_SCAN_PERIOD)
  7. #define BTN_TIME_PRESSED (30/BTN_SCAN_PERIOD)
  8. #define BTN_TIME_HOLDED (500/BTN_SCAN_PERIOD)
  9. #define BTN_TIME_REPEATED (50/BTN_SCAN_PERIOD)
  10. #define BUTTON_PRESSED PAL_LOW
  11. /* type defs */
  12. typedef enum btn_num {
  13. Button1 = 0,
  14. Button2 = 1,
  15. Button3 = 2,
  16. Button4 = 3,
  17. Button_Num = 4
  18. } button_num_t;
  19. typedef enum btn_state {
  20. BTN_st_Clear = 0,
  21. BTN_st_Pressed,
  22. BTN_st_Holded,
  23. BTN_st_Released
  24. } button_state_t;
  25. /* Handler function type */
  26. typedef void (*btn_hndlr)(const button_state_t);
  27. /* function prototypes */
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. void buttons_Init(btn_hndlr ha[]);
  32. button_state_t buttons_GetState(const button_num_t btn);
  33. #ifdef __cplusplus
  34. }
  35. #endif
  36. #endif /* _BUTTONS_H_ */