driver_keyscan.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * @File name : driver_keyscan.h
  3. * @Author : Bluetrum IOT Team
  4. * @Date : 2023-03-15
  5. * @Description : This file contains all the functions prototypes for the KEYSCAN library.
  6. *
  7. * Copyright (c) by Bluetrum, All Rights Reserved.
  8. */
  9. #ifndef _DRIVER_KEYSCAN_H
  10. #define _DRIVER_KEYSCAN_H
  11. #include "driver_com.h"
  12. /**
  13. * @brief KEYSCAN Group A Key ID Enumeration
  14. */
  15. typedef enum {
  16. KA1 = 0x00000001,
  17. KA2 = 0x00000002,
  18. KA3 = 0x00000004,
  19. KA4 = 0x00000008,
  20. KA5 = 0x00000010,
  21. KA6 = 0x00000020,
  22. KA7 = 0x00000040,
  23. KB2 = 0x00000080,
  24. KB3 = 0x00000100,
  25. KB4 = 0x00000200,
  26. KB5 = 0x00000400,
  27. KB6 = 0x00000800,
  28. KB7 = 0x00001000,
  29. KC3 = 0x00002000,
  30. KC4 = 0x00004000,
  31. KC5 = 0x00008000,
  32. KC6 = 0x00010000,
  33. KC7 = 0x00020000,
  34. KD4 = 0x00040000,
  35. KD5 = 0x00080000,
  36. KD6 = 0x00100000,
  37. KD7 = 0x00200000,
  38. KE5 = 0x00400000,
  39. KE6 = 0x00800000,
  40. KE7 = 0x01000000,
  41. KF6 = 0x02000000,
  42. KF7 = 0x04000000,
  43. KG7 = 0x08000000,
  44. } KEYSCAN_GROUP_A_KEY_ID_TYPEDEF;
  45. /**
  46. * @brief KEYSCAN Group B Key ID Enumeration
  47. */
  48. typedef enum {
  49. KJ0 = 0x00000001,
  50. KJ1 = 0x00000002,
  51. KJ2 = 0x00000004,
  52. KJ3 = 0x00000008,
  53. KJ4 = 0x00000010,
  54. KJ5 = 0x00000020,
  55. KJ6 = 0x00000040,
  56. KJ7 = 0x00000080,
  57. KI0 = 0x00000100,
  58. KI1 = 0x00000200,
  59. KI2 = 0x00000400,
  60. KI3 = 0x00000800,
  61. KI4 = 0x00001000,
  62. KI5 = 0x00002000,
  63. KI6 = 0x00004000,
  64. KI7 = 0x00008000,
  65. } KEYSCAN_GROUP_B_KEY_ID_TYPEDEF;
  66. /**
  67. * @brief KEYSCAN Interrupt Flag Definition
  68. */
  69. typedef enum {
  70. KEYSCAN_IT_VALID = 0x01,
  71. KEYSCAN_IT_INVALID = 0x02,
  72. } KEYSCAN_IT_TYPEDEF;
  73. /**
  74. * @brief Key Scan Software Release Reset Enumeration
  75. */
  76. typedef enum {
  77. KEYSCAN_SWRSTN_RESET = 0x00000000,
  78. KEYSCAN_SWRSTN_RELEASE_RESET = 0x00000080,
  79. } KEYSCAN_SWRSTN_TYPEDEF;
  80. /**
  81. * @brief Key Valid Wakeup System Enumeration
  82. */
  83. typedef enum {
  84. KEYSCAN_WKUP_DIS = 0x00000000,
  85. KEYSCAN_WKUP_EN = 0x00000008,
  86. } KEYSCAN_WKUP_TYPEDEF;
  87. /**
  88. * @brief Key Scan Lowpower Mode Enumeration
  89. */
  90. typedef enum {
  91. KEYSCAN_LOWPWR_DIS = 0x00000000,
  92. KEYSCAN_LOWPWR_EN = 0x00000004,
  93. } KEYSCAN_LOWPWR_TYPEDEF;
  94. /**
  95. * @brief Key Scan Mode Enumeration
  96. */
  97. typedef enum {
  98. KEYSCAN_MODE_NORMAL = 0x00000000,
  99. KEYSCAN_MODE_MATRIX = 0x00000002,
  100. } KEYSCAN_MODE_TYPEDEF;
  101. /**
  102. * @brief KEYSCAN Init Structure
  103. */
  104. typedef struct {
  105. uint8_t key_mask;
  106. uint8_t stable_times;
  107. uint8_t debounce_times;
  108. uint8_t wait_times;
  109. KEYSCAN_MODE_TYPEDEF key_mode;
  110. KEYSCAN_LOWPWR_TYPEDEF low_power_mode;
  111. KEYSCAN_SWRSTN_TYPEDEF sw_reset;
  112. KEYSCAN_WKUP_TYPEDEF wakeup;
  113. } keyscan_init_typedef;
  114. /********************** Function used to configure key_scan base **********************/
  115. void keyscan_init(keyscan_init_typedef *keyscan_init_struct);
  116. void keyscan_deinit(void);
  117. void keyscan_cmd(FUNCTIONAL_STATE state);
  118. void keyscan_pic_config(isr_t isr, int pr, KEYSCAN_IT_TYPEDEF interrupt_type, FUNCTIONAL_STATE state);
  119. FLAG_STATE keyscan_get_flag(KEYSCAN_IT_TYPEDEF interrupt_type);
  120. void keyscan_clear_flag(KEYSCAN_IT_TYPEDEF interrupt_type);
  121. uint32_t keyscan_get_groupA_key_id(void);
  122. uint32_t keyscan_get_groupB_key_id(void);
  123. bool keyscan_is_lowpwr_mode(void);
  124. #endif // _DRIVER_KEYSCAN_H