key.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * @file key.h
  3. * @author chipsea
  4. * @brief
  5. * @version 0.1
  6. * @date 2020-11-30
  7. * @copyright Copyright (c) 2020, CHIPSEA Co., Ltd.
  8. * @note
  9. */
  10. /**************************************************************
  11. *
  12. *
  13. * Module Name: key
  14. * File name: key.h
  15. * Brief description:
  16. * key driver module
  17. * Data: 2020-06-30
  18. * Revision:V0.01
  19. ****************************************************************/
  20. #ifndef __KEY_H__
  21. #define __KEY_H__
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #include "types.h"
  26. #include "gpio.h"
  27. #define HAL_KEY_NUM 1 //config key's number
  28. #define HAL_KEY_EVENT 0x4000 //assign short key event in your app event process
  29. #define HAL_KEY_SUPPORT_LONG_PRESS //if use long key,please enable it
  30. #ifdef HAL_KEY_SUPPORT_LONG_PRESS
  31. #define KEY_DEMO_LONG_PRESS_EVT 0x8000 //if use long key,assign long key event in your app process
  32. #define HAL_KEY_LONG_PRESS_TIME 3000 //2s
  33. #endif
  34. #define HAL_KEY_DEBOUNCD 20 //20ms
  35. typedef enum{
  36. HAL_STATE_KEY_IDLE = 0x00,
  37. HAL_STATE_KEY_PRESS_DEBOUNCE = 0x01,
  38. HAL_STATE_KEY_PRESS = 0x02,
  39. HAL_STATE_KEY_RELEASE_DEBOUNCE = 0x03,
  40. }key_state_e;
  41. typedef enum{
  42. HAL_KEY_EVT_IDLE = 0x0000,
  43. HAL_KEY_EVT_PRESS = 0x0002,
  44. HAL_KEY_EVT_RELEASE = 0x0004,
  45. HAL_KEY_EVT_LONG_PRESS = 0x0010,
  46. HAL_KEY_EVT_LONG_RELEASE = 0x0020,
  47. } key_evt_t;
  48. typedef enum{
  49. HAL_LOW_IDLE = 0x00,
  50. HAL_HIGH_IDLE = 0x01,
  51. }idle_level_e;
  52. typedef void (* key_callbank_hdl_t)(uint8_t,key_evt_t);
  53. typedef struct gpio_key_t{
  54. GpioPin_t pin;
  55. key_state_e state;
  56. idle_level_e idle_level;
  57. }gpio_key;
  58. typedef struct gpio_internal_t{
  59. uint32_t timer_tick;
  60. bool in_enable;
  61. }gpio_internal;
  62. typedef struct key_state{
  63. gpio_key key[HAL_KEY_NUM];
  64. gpio_internal temp[HAL_KEY_NUM];
  65. uint8_t task_id;
  66. key_callbank_hdl_t key_callbank;
  67. }key_contex_t;
  68. void key_init(void);
  69. void gpio_key_timer_handler(uint8 index);
  70. extern key_contex_t key_state;
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74. #endif