logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

keyboard.h (5609B)


  1. /*
  2. Copyright 2011,2012,2013 Jun Wako <wakojun@gmail.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #pragma once
  15. #include <stdbool.h>
  16. #include <stdint.h>
  17. #include "timer.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /* key matrix position */
  22. typedef struct {
  23. uint8_t col;
  24. uint8_t row;
  25. } keypos_t;
  26. typedef enum keyevent_type_t { TICK_EVENT = 0, KEY_EVENT = 1, ENCODER_CW_EVENT = 2, ENCODER_CCW_EVENT = 3, COMBO_EVENT = 4, DIP_SWITCH_ON_EVENT = 5, DIP_SWITCH_OFF_EVENT = 6 } keyevent_type_t;
  27. /* key event */
  28. typedef struct {
  29. keypos_t key;
  30. uint16_t time;
  31. keyevent_type_t type;
  32. bool pressed;
  33. } keyevent_t;
  34. /* equivalent test of keypos_t */
  35. #define KEYEQ(keya, keyb) ((keya).row == (keyb).row && (keya).col == (keyb).col)
  36. /* special keypos_t entries */
  37. #define KEYLOC_ENCODER_CW 253
  38. #define KEYLOC_ENCODER_CCW 252
  39. #define KEYLOC_DIP_SWITCH_ON 251
  40. #define KEYLOC_DIP_SWITCH_OFF 250
  41. static inline bool IS_NOEVENT(const keyevent_t event) {
  42. return event.type == TICK_EVENT;
  43. }
  44. static inline bool IS_EVENT(const keyevent_t event) {
  45. return event.type != TICK_EVENT;
  46. }
  47. static inline bool IS_KEYEVENT(const keyevent_t event) {
  48. return event.type == KEY_EVENT;
  49. }
  50. static inline bool IS_COMBOEVENT(const keyevent_t event) {
  51. return event.type == COMBO_EVENT;
  52. }
  53. static inline bool IS_ENCODEREVENT(const keyevent_t event) {
  54. return event.type == ENCODER_CW_EVENT || event.type == ENCODER_CCW_EVENT;
  55. }
  56. static inline bool IS_DIPSWITCHEVENT(const keyevent_t event) {
  57. return event.type == DIP_SWITCH_ON_EVENT || event.type == DIP_SWITCH_OFF_EVENT;
  58. }
  59. /* Common keypos_t object factory */
  60. #define MAKE_KEYPOS(row_num, col_num) ((keypos_t){.row = (row_num), .col = (col_num)})
  61. /* Common keyevent_t object factory */
  62. #define MAKE_EVENT(row_num, col_num, press, event_type) ((keyevent_t){.key = MAKE_KEYPOS((row_num), (col_num)), .pressed = (press), .time = timer_read(), .type = (event_type)})
  63. /**
  64. * @brief Constructs a key event for a pressed or released key.
  65. */
  66. #define MAKE_KEYEVENT(row_num, col_num, press) MAKE_EVENT((row_num), (col_num), (press), KEY_EVENT)
  67. /**
  68. * @brief Constructs a combo event.
  69. */
  70. #define MAKE_COMBOEVENT(press) MAKE_EVENT(0, 0, (press), COMBO_EVENT)
  71. /**
  72. * @brief Constructs a internal tick event that is used to drive the internal QMK state machine.
  73. */
  74. #define MAKE_TICK_EVENT MAKE_EVENT(0, 0, false, TICK_EVENT)
  75. #ifdef ENCODER_MAP_ENABLE
  76. /* Encoder events */
  77. # define MAKE_ENCODER_CW_EVENT(enc_id, press) MAKE_EVENT(KEYLOC_ENCODER_CW, (enc_id), (press), ENCODER_CW_EVENT)
  78. # define MAKE_ENCODER_CCW_EVENT(enc_id, press) MAKE_EVENT(KEYLOC_ENCODER_CCW, (enc_id), (press), ENCODER_CCW_EVENT)
  79. #endif // ENCODER_MAP_ENABLE
  80. #ifdef DIP_SWITCH_MAP_ENABLE
  81. /* Dip Switch events */
  82. # define MAKE_DIPSWITCH_ON_EVENT(switch_id, press) MAKE_EVENT(KEYLOC_DIP_SWITCH_ON, (switch_id), (press), DIP_SWITCH_ON_EVENT)
  83. # define MAKE_DIPSWITCH_OFF_EVENT(switch_id, press) MAKE_EVENT(KEYLOC_DIP_SWITCH_OFF, (switch_id), (press), DIP_SWITCH_OFF_EVENT)
  84. #endif // DIP_SWITCH_MAP_ENABLE
  85. /* it runs once at early stage of startup before keyboard_init. */
  86. void keyboard_setup(void);
  87. /* it runs once after initializing host side protocol, debug and MCU peripherals. */
  88. void keyboard_init(void);
  89. /* it runs repeatedly in main loop */
  90. void keyboard_task(void);
  91. /* it runs whenever code has to behave differently on a slave */
  92. bool is_keyboard_master(void);
  93. /* it runs whenever code has to behave differently on left vs right split */
  94. bool is_keyboard_left(void);
  95. void keyboard_pre_init_kb(void);
  96. void keyboard_pre_init_user(void);
  97. void keyboard_post_init_kb(void);
  98. void keyboard_post_init_user(void);
  99. void housekeeping_task(void); // To be executed by the main loop in each backend TMK protocol
  100. void housekeeping_task_kb(void); // To be overridden by keyboard-level code
  101. void housekeeping_task_user(void); // To be overridden by user/keymap-level code
  102. uint32_t last_input_activity_time(void); // Timestamp of the last matrix or encoder or pointing device activity
  103. uint32_t last_input_activity_elapsed(void); // Number of milliseconds since the last matrix or encoder or pointing device activity
  104. uint32_t last_matrix_activity_time(void); // Timestamp of the last matrix activity
  105. uint32_t last_matrix_activity_elapsed(void); // Number of milliseconds since the last matrix activity
  106. uint32_t last_encoder_activity_time(void); // Timestamp of the last encoder activity
  107. uint32_t last_encoder_activity_elapsed(void); // Number of milliseconds since the last encoder activity
  108. uint32_t last_pointing_device_activity_time(void); // Timestamp of the last pointing device activity
  109. uint32_t last_pointing_device_activity_elapsed(void); // Number of milliseconds since the last pointing device activity
  110. void set_activity_timestamps(uint32_t matrix_timestamp, uint32_t encoder_timestamp, uint32_t pointing_device_timestamp); // Set the timestamps of the last matrix and encoder activity
  111. uint32_t get_matrix_scan_rate(void);
  112. #ifdef __cplusplus
  113. }
  114. #endif