ff94fefeea723ea85b2beda7ed7b254d754091dd.svn-base 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2016 Zibin Zheng <[email protected]>
  3. * All rights reserved
  4. */
  5. #ifndef _MULTI_BUTTON_H_
  6. #define _MULTI_BUTTON_H_
  7. //#include "stdint.h"
  8. #include "TypeDef.h"
  9. #include "string.h"
  10. //According to your need to modify the constants.
  11. #define TICKS_INTERVAL 6 //ms
  12. #define DEBOUNCE_TICKS 3 //MAX 8
  13. #define SHORT_TICKS (120 /TICKS_INTERVAL)
  14. #define LONG_TICKS (2000 /TICKS_INTERVAL)
  15. #define LONG_TICKS_TRIG (120 /TICKS_INTERVAL) //³¤°´,ÖÜÆÚÐÔµ÷ÓÃ
  16. typedef void ( *BtnCallback ) ( void* );
  17. typedef enum
  18. {
  19. PRESS_DOWN = 0,
  20. PRESS_UP,
  21. PRESS_REPEAT,
  22. SINGLE_CLICK,
  23. DOUBLE_CLICK,
  24. LONG_RRESS_START,
  25. LONG_PRESS_HOLD,
  26. number_of_event,
  27. NONE_PRESS
  28. } PressEvent;
  29. typedef struct Button
  30. {
  31. uint16_t ticks;
  32. uint8_t repeat : 4;
  33. uint8_t event : 4;
  34. uint8_t state : 3;
  35. uint8_t debounce_cnt : 3;
  36. uint8_t active_level : 1;
  37. uint8_t button_level : 1;
  38. uint8_t ( *hal_button_Level ) ( void );
  39. BtnCallback cb[number_of_event];
  40. struct Button* next;
  41. } Button;
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. void button_init_Head ( void );
  46. void button_init ( struct Button* handle, uint8_t ( *pin_level ) (), uint8_t active_level );
  47. void button_attach ( struct Button* handle, PressEvent event, BtnCallback cb );
  48. PressEvent get_button_event ( struct Button* handle );
  49. int button_start ( struct Button* handle );
  50. void button_stop ( struct Button* handle );
  51. void button_ticks ( void );
  52. #ifdef __cplusplus
  53. }
  54. #endif
  55. #endif