X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fkeyboard.h;h=d1a922420b8483e01c6f50eedfcae4c83e96b711;hb=b9e265368fde73daff069788dcb58c8230d01b32;hp=e1cab31194ccaee402aee1e7d99a3ede61b7d309;hpb=8c80deb775ac151001dc1592a2e94e8677b49964;p=tmk_firmware.git diff --git a/common/keyboard.h b/common/keyboard.h index e1cab31..d1a9224 100644 --- a/common/keyboard.h +++ b/common/keyboard.h @@ -30,12 +30,6 @@ extern "C" { typedef struct { uint8_t col; uint8_t row; -} keypos_t; - -// TODO: need raw? keypos_t -> key_t? -typedef union { - uint16_t raw; - keypos_t pos; } key_t; /* key event */ @@ -46,20 +40,19 @@ typedef struct { } keyevent_t; /* equivalent test of key_t */ -#define KEYEQ(keya, keyb) ((keya).raw == (keyb).raw) - -/* (time == 0) means no event and assumes matrix has no 255 line. */ -#define IS_NOEVENT(event) ((event).time == 0 || ((event).key.pos.row == 255 && (event).key.pos.col == 255)) +#define KEYEQ(keya, keyb) ((keya).row == (keyb).row && (keya).col == (keyb).col) -#define NOEVENT (keyevent_t){ \ - .key.pos = (keypos_t){ .row = 255, .col = 255 }, \ - .pressed = false, \ - .time = 0 \ -} +/* Rules for No Event: + * 1) (time == 0) to handle (keyevent_t){} as empty event + * 2) Matrix(255, 255) to make TICK event available + */ +static inline bool IS_NOEVENT(keyevent_t event) { return event.time == 0 || (event.key.row == 255 && event.key.col == 255); } +static inline bool IS_PRESSED(keyevent_t event) { return (!IS_NOEVENT(event) && event.pressed); } +static inline bool IS_RELEASED(keyevent_t event) { return (!IS_NOEVENT(event) && !event.pressed); } -/* tick event */ +/* Tick event */ #define TICK (keyevent_t){ \ - .key.pos = (keypos_t){ .row = 255, .col = 255 }, \ + .key = (key_t){ .row = 255, .col = 255 }, \ .pressed = false, \ .time = (timer_read() | 1) \ }