aboutsummaryrefslogtreecommitdiff
path: root/quantum/keyboard.h
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/keyboard.h')
-rw-r--r--quantum/keyboard.h90
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/*
2Copyright 2011,2012,2013 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along 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
24extern "C" {
25#endif
26
27/* key matrix position */
28typedef struct {
29 uint8_t col;
30 uint8_t row;
31} keypos_t;
32
33/* key event */
34typedef 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 */
47static inline bool IS_NOEVENT(keyevent_t event) { return event.time == 0 || (event.key.row == 255 && event.key.col == 255); }
48static inline bool IS_PRESSED(keyevent_t event) { return (!IS_NOEVENT(event) && event.pressed); }
49static 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. */
56void keyboard_setup(void);
57/* it runs once after initializing host side protocol, debug and MCU peripherals. */
58void keyboard_init(void);
59/* it runs repeatedly in main loop */
60void keyboard_task(void);
61/* it runs when host LED status is updated */
62void keyboard_set_leds(uint8_t leds);
63/* it runs whenever code has to behave differently on a slave */
64bool is_keyboard_master(void);
65/* it runs whenever code has to behave differently on left vs right split */
66bool is_keyboard_left(void);
67
68void keyboard_pre_init_kb(void);
69void keyboard_pre_init_user(void);
70void keyboard_post_init_kb(void);
71void keyboard_post_init_user(void);
72
73void housekeeping_task(void); // To be executed by the main loop in each backend TMK protocol
74void housekeeping_task_kb(void); // To be overridden by keyboard-level code
75void housekeeping_task_user(void); // To be overridden by user/keymap-level code
76
77uint32_t last_input_activity_time(void); // Timestamp of the last matrix or encoder activity
78uint32_t last_input_activity_elapsed(void); // Number of milliseconds since the last matrix or encoder activity
79
80uint32_t last_matrix_activity_time(void); // Timestamp of the last matrix activity
81uint32_t last_matrix_activity_elapsed(void); // Number of milliseconds since the last matrix activity
82
83uint32_t last_encoder_activity_time(void); // Timestamp of the last encoder activity
84uint32_t last_encoder_activity_elapsed(void); // Number of milliseconds since the last encoder activity
85
86uint32_t get_matrix_scan_rate(void);
87
88#ifdef __cplusplus
89}
90#endif