aboutsummaryrefslogtreecommitdiff
path: root/common/keyboard.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/keyboard.h')
-rw-r--r--common/keyboard.h38
1 files changed, 27 insertions, 11 deletions
diff --git a/common/keyboard.h b/common/keyboard.h
index 2353805e1..e1cab3119 100644
--- a/common/keyboard.h
+++ b/common/keyboard.h
@@ -1,5 +1,5 @@
1/* 1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com> 2Copyright 2011,2012,2013 Jun Wako <wakojun@gmail.com>
3 3
4This program is free software: you can redistribute it and/or modify 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 5it under the terms of the GNU General Public License as published by
@@ -26,28 +26,44 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
26extern "C" { 26extern "C" {
27#endif 27#endif
28 28
29/* key matrix position */
29typedef struct { 30typedef struct {
30 uint8_t row;
31 uint8_t col; 31 uint8_t col;
32 uint8_t row;
33} keypos_t;
34
35// TODO: need raw? keypos_t -> key_t?
36typedef union {
37 uint16_t raw;
38 keypos_t pos;
32} key_t; 39} key_t;
33 40
41/* key event */
34typedef struct { 42typedef struct {
35 key_t key; 43 key_t key;
36 bool pressed; 44 bool pressed;
45 uint16_t time;
37} keyevent_t; 46} keyevent_t;
38 47
39typedef struct { 48/* equivalent test of key_t */
40 keyevent_t event; 49#define KEYEQ(keya, keyb) ((keya).raw == (keyb).raw)
41 uint8_t code;
42 uint8_t mods;
43 uint16_t time;
44} keyrecord_t;
45 50
46#define KEYEQ(keya, keyb) (keya.row == keyb.row && keya.col == keyb.col) 51/* (time == 0) means no event and assumes matrix has no 255 line. */
52#define IS_NOEVENT(event) ((event).time == 0 || ((event).key.pos.row == 255 && (event).key.pos.col == 255))
47 53
54#define NOEVENT (keyevent_t){ \
55 .key.pos = (keypos_t){ .row = 255, .col = 255 }, \
56 .pressed = false, \
57 .time = 0 \
58}
59
60/* tick event */
61#define TICK (keyevent_t){ \
62 .key.pos = (keypos_t){ .row = 255, .col = 255 }, \
63 .pressed = false, \
64 .time = (timer_read() | 1) \
65}
48 66
49extern uint8_t current_layer;
50extern uint8_t default_layer;
51 67
52void keyboard_init(void); 68void keyboard_init(void);
53void keyboard_task(void); 69void keyboard_task(void);