diff options
Diffstat (limited to 'common/keyboard.h')
| -rw-r--r-- | common/keyboard.h | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/common/keyboard.h b/common/keyboard.h index dd1ebb2bd..32c1bf464 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,6 +26,7 @@ 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 col; | 31 | uint8_t col; |
| 31 | uint8_t row; | 32 | uint8_t row; |
| @@ -36,29 +37,33 @@ typedef union { | |||
| 36 | keypos_t pos; | 37 | keypos_t pos; |
| 37 | } key_t; | 38 | } key_t; |
| 38 | 39 | ||
| 40 | /* key event */ | ||
| 39 | typedef struct { | 41 | typedef struct { |
| 40 | key_t key; | 42 | key_t key; |
| 41 | bool pressed; | 43 | bool pressed; |
| 42 | uint16_t time; | 44 | uint16_t time; |
| 43 | } keyevent_t; | 45 | } keyevent_t; |
| 44 | 46 | ||
| 47 | /* equivalent test of key_t */ | ||
| 45 | #define KEYEQ(keya, keyb) ((keya).raw == (keyb).raw) | 48 | #define KEYEQ(keya, keyb) ((keya).raw == (keyb).raw) |
| 46 | #define IS_NOEVENT(event) ((event).key.pos.row == 255 && (event).key.pos.col == 255) | 49 | |
| 50 | /* (time == 0) means no event and assumes matrix has no 255 line. */ | ||
| 51 | #define IS_NOEVENT(event) ((event).time == 0 || ((event).key.pos.row == 255 && (event).key.pos.col == 255)) | ||
| 52 | |||
| 47 | #define NOEVENT (keyevent_t){ \ | 53 | #define NOEVENT (keyevent_t){ \ |
| 48 | .key.pos = (keypos_t){ .row = 255, .col = 255 }, \ | 54 | .key.pos = (keypos_t){ .row = 255, .col = 255 }, \ |
| 49 | .pressed = false, \ | 55 | .pressed = false, \ |
| 50 | .time = 0 \ | 56 | .time = 0 \ |
| 51 | } | 57 | } |
| 58 | |||
| 59 | /* tick event */ | ||
| 52 | #define TICK (keyevent_t){ \ | 60 | #define TICK (keyevent_t){ \ |
| 53 | .key.pos = (keypos_t){ .row = 255, .col = 255 }, \ | 61 | .key.pos = (keypos_t){ .row = 255, .col = 255 }, \ |
| 54 | .pressed = false, \ | 62 | .pressed = false, \ |
| 55 | .time = timer_read() \ | 63 | .time = (timer_read() | 1) \ |
| 56 | } | 64 | } |
| 57 | 65 | ||
| 58 | 66 | ||
| 59 | extern uint8_t current_layer; | ||
| 60 | extern uint8_t default_layer; | ||
| 61 | |||
| 62 | void keyboard_init(void); | 67 | void keyboard_init(void); |
| 63 | void keyboard_task(void); | 68 | void keyboard_task(void); |
| 64 | void keyboard_set_leds(uint8_t leds); | 69 | void keyboard_set_leds(uint8_t leds); |
