diff options
Diffstat (limited to 'common/keyboard.h')
| -rw-r--r-- | common/keyboard.h | 38 |
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 | /* |
| 2 | Copyright 2011 Jun Wako <wakojun@gmail.com> | 2 | Copyright 2011,2012,2013 Jun Wako <wakojun@gmail.com> |
| 3 | 3 | ||
| 4 | This program is free software: you can redistribute it and/or modify | 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 | 5 | it 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/>. | |||
| 26 | extern "C" { | 26 | extern "C" { |
| 27 | #endif | 27 | #endif |
| 28 | 28 | ||
| 29 | /* key matrix position */ | ||
| 29 | typedef struct { | 30 | typedef 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? | ||
| 36 | typedef union { | ||
| 37 | uint16_t raw; | ||
| 38 | keypos_t pos; | ||
| 32 | } key_t; | 39 | } key_t; |
| 33 | 40 | ||
| 41 | /* key event */ | ||
| 34 | typedef struct { | 42 | typedef 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 | ||
| 39 | typedef 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 | ||
| 49 | extern uint8_t current_layer; | ||
| 50 | extern uint8_t default_layer; | ||
| 51 | 67 | ||
| 52 | void keyboard_init(void); | 68 | void keyboard_init(void); |
| 53 | void keyboard_task(void); | 69 | void keyboard_task(void); |
