Fix Tapping: release key immediately but modifier #65
[jackhill/qmk/firmware.git] / common / keyboard.h
CommitLineData
0dde25e8 1/*
1e3e41a2 2Copyright 2011,2012,2013 Jun Wako <wakojun@gmail.com>
0dde25e8 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
acc974c6 18#ifndef KEYBOARD_H
19#define KEYBOARD_H
20
4ae979f6 21#include <stdbool.h>
9a938eec 22#include <stdint.h>
23
acc974c6 24
c5060ea8 25#ifdef __cplusplus
26extern "C" {
27#endif
4ae979f6 28
1e3e41a2 29/* key matrix position */
4ae979f6 30typedef struct {
4ae979f6 31 uint8_t col;
ee7ce433 32 uint8_t row;
ee7ce433 33} key_t;
34
1e3e41a2 35/* key event */
4ae979f6 36typedef struct {
f71a5217 37 key_t key;
4ae979f6 38 bool pressed;
411de9cc 39 uint16_t time;
4ae979f6 40} keyevent_t;
41
1e3e41a2 42/* equivalent test of key_t */
c4421f58 43#define KEYEQ(keya, keyb) ((keya).row == (keyb).row && (keya).col == (keyb).col)
1e3e41a2 44
8819cf6b 45/* Rules for No Event:
46 * 1) (time == 0) to handle (keyevent_t){} as empty event
47 * 2) Matrix(255, 255) to make TICK event available
48 */
49static inline bool IS_NOEVENT(keyevent_t event) { return event.time == 0 || (event.key.row == 255 && event.key.col == 255); }
50static inline bool IS_PRESSED(keyevent_t event) { return (!IS_NOEVENT(event) && event.pressed); }
51static inline bool IS_RELEASED(keyevent_t event) { return (!IS_NOEVENT(event) && !event.pressed); }
52
53/* Tick event */
ef873791 54#define TICK (keyevent_t){ \
c4421f58 55 .key = (key_t){ .row = 255, .col = 255 }, \
ef873791 56 .pressed = false, \
1e3e41a2 57 .time = (timer_read() | 1) \
ef873791 58}
f609712d 59
4ae979f6 60
2b8cd88a 61void keyboard_init(void);
4ae979f6 62void keyboard_task(void);
9a938eec 63void keyboard_set_leds(uint8_t leds);
4ae979f6 64
c5060ea8 65#ifdef __cplusplus
66}
67#endif
acc974c6 68
69#endif