diff options
Diffstat (limited to 'quantum/keyboard.h')
-rw-r--r-- | quantum/keyboard.h | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/quantum/keyboard.h b/quantum/keyboard.h new file mode 100644 index 000000000..08f4e84f9 --- /dev/null +++ b/quantum/keyboard.h | |||
@@ -0,0 +1,90 @@ | |||
1 | /* | ||
2 | Copyright 2011,2012,2013 Jun Wako <wakojun@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #pragma once | ||
19 | |||
20 | #include <stdbool.h> | ||
21 | #include <stdint.h> | ||
22 | |||
23 | #ifdef __cplusplus | ||
24 | extern "C" { | ||
25 | #endif | ||
26 | |||
27 | /* key matrix position */ | ||
28 | typedef struct { | ||
29 | uint8_t col; | ||
30 | uint8_t row; | ||
31 | } keypos_t; | ||
32 | |||
33 | /* key event */ | ||
34 | typedef struct { | ||
35 | keypos_t key; | ||
36 | bool pressed; | ||
37 | uint16_t time; | ||
38 | } keyevent_t; | ||
39 | |||
40 | /* equivalent test of keypos_t */ | ||
41 | #define KEYEQ(keya, keyb) ((keya).row == (keyb).row && (keya).col == (keyb).col) | ||
42 | |||
43 | /* Rules for No Event: | ||
44 | * 1) (time == 0) to handle (keyevent_t){} as empty event | ||
45 | * 2) Matrix(255, 255) to make TICK event available | ||
46 | */ | ||
47 | static inline bool IS_NOEVENT(keyevent_t event) { return event.time == 0 || (event.key.row == 255 && event.key.col == 255); } | ||
48 | static inline bool IS_PRESSED(keyevent_t event) { return (!IS_NOEVENT(event) && event.pressed); } | ||
49 | static inline bool IS_RELEASED(keyevent_t event) { return (!IS_NOEVENT(event) && !event.pressed); } | ||
50 | |||
51 | /* Tick event */ | ||
52 | #define TICK \ | ||
53 | (keyevent_t) { .key = (keypos_t){.row = 255, .col = 255}, .pressed = false, .time = (timer_read() | 1) } | ||
54 | |||
55 | /* it runs once at early stage of startup before keyboard_init. */ | ||
56 | void keyboard_setup(void); | ||
57 | /* it runs once after initializing host side protocol, debug and MCU peripherals. */ | ||
58 | void keyboard_init(void); | ||
59 | /* it runs repeatedly in main loop */ | ||
60 | void keyboard_task(void); | ||
61 | /* it runs when host LED status is updated */ | ||
62 | void keyboard_set_leds(uint8_t leds); | ||
63 | /* it runs whenever code has to behave differently on a slave */ | ||
64 | bool is_keyboard_master(void); | ||
65 | /* it runs whenever code has to behave differently on left vs right split */ | ||
66 | bool is_keyboard_left(void); | ||
67 | |||
68 | void keyboard_pre_init_kb(void); | ||
69 | void keyboard_pre_init_user(void); | ||
70 | void keyboard_post_init_kb(void); | ||
71 | void keyboard_post_init_user(void); | ||
72 | |||
73 | void housekeeping_task(void); // To be executed by the main loop in each backend TMK protocol | ||
74 | void housekeeping_task_kb(void); // To be overridden by keyboard-level code | ||
75 | void housekeeping_task_user(void); // To be overridden by user/keymap-level code | ||
76 | |||
77 | uint32_t last_input_activity_time(void); // Timestamp of the last matrix or encoder activity | ||
78 | uint32_t last_input_activity_elapsed(void); // Number of milliseconds since the last matrix or encoder activity | ||
79 | |||
80 | uint32_t last_matrix_activity_time(void); // Timestamp of the last matrix activity | ||
81 | uint32_t last_matrix_activity_elapsed(void); // Number of milliseconds since the last matrix activity | ||
82 | |||
83 | uint32_t last_encoder_activity_time(void); // Timestamp of the last encoder activity | ||
84 | uint32_t last_encoder_activity_elapsed(void); // Number of milliseconds since the last encoder activity | ||
85 | |||
86 | uint32_t get_matrix_scan_rate(void); | ||
87 | |||
88 | #ifdef __cplusplus | ||
89 | } | ||
90 | #endif | ||