# generated from XKB map it include common map 0x410 exclam 0x02 shift onesuperior 0x02 altgr exclamdown 0x02 shift altgr quotedbl 0x03 shift twosuperior 0x03 altgr oneeighth 0x03 shift altgr sterling 0x04 shift threesuperior 0x04 altgr dollar 0x05 shift onequarter 0x05 altgr percent 0x06 shift onehalf 0x06 altgr threeeighths 0x06 shift altgr ampersand 0x07 shift threequarters 0x07 altgr fiveeighths 0x07 shift altgr slash 0x08 shift braceleft 0x08 altgr seveneighths 0x08 shift altgr parenleft 0x09 shift trademark 0x09 shift altgr parenright 0x0a shift plusminus 0x0a shift altgr equal 0x0b shift braceright 0x0b altgr degree 0x0b shift altgr apostrophe 0x0c question 0x0c shift grave 0x0c altgr questiondown 0x0c shift altgr igrave 0x0d asciicircum 0x0d shift asciitilde 0x0d altgr dead_ogonek 0x0d shift altgr at 0x10 altgr Greek_OMEGA 0x10 shift altgr lstroke 0x11 altgr Lstroke 0x11 shift altgr EuroSign 0x12 altgr cent 0x12 shift altgr paragraph 0x13 altgr registered 0x13 shift altgr tslash 0x14 altgr Tslash 0x14 shift altgr leftarrow 0x15 altgr yen 0x15 shift altgr downarrow 0x16 altgr uparrow 0x16 shift altgr rightarrow 0x17 altgr idotless 0x17 shift altgr oslash 0x18 altgr Ooblique 0x18 shift altgr thorn 0x19 altgr THORN 0x19 shift altgr egrave 0x1a eacute 0x1a shift bracketleft 0x1a altgr dead_abovering 0x1a shift altgr plus 0x1b asterisk 0x1b shift bracketright 0x1b altgr dead_macron 0x1b shift altgr ae 0x1e altgr AE 0x1e shift altgr ssharp 0x1f altgr section 0x1f shift altgr eth 0x20 altgr ETH 0x20 shift altgr dstroke 0x21 altgr ordfeminine 0x21 shift altgr eng 0x22 altgr ENG 0x22 shift altgr hstroke 0x23 altgr Hstroke 0x23 shift altgr kra 0x25 altgr lstroke 0x26 altgr Lstroke 0x26 shift altgr ograve 0x27 ccedilla 0x27 shift at 0x27 altgr dead_doubleacute 0x27 shift altgr agrave 0x28 degree 0x28 shift numbersign 0x28 altgr backslash 0x29 bar 0x29 shift notsign 0x29 altgr ugrave 0x2b section 0x2b shift dead_grave 0x2b altgr dead_breve 0x2b shift altgr guillemotleft 0x2c altgr guillemotright 0x2d altgr cent 0x2e altgr copyright 0x2e shift altgr leftdoublequotemark 0x2f altgr grave 0x2f shift altgr rightdoublequotemark 0x30 altgr mu 0x32 altgr masculine 0x32 shift altgr comma 0x33 semicolon 0x33 shift horizconnector 0x33 altgr multiply 0x33 shift altgr period 0x34 colon 0x34 shift periodcentered 0x34 altgr division 0x34 shift altgr minus 0x35 underscore 0x35 shift dead_belowdot 0x35 altgr dead_abovedot 0x35 shift altgr
path: root/tmk_core/common/keyboard.h
blob: f17003c2ff97c13e4c6585ed133b1e3bbb814463 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
Copyright 2011,2012,2013 Jun Wako <wakojun@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef KEYBOARD_H
#define KEYBOARD_H

#include <stdbool.h>
#include <stdint.h>


#ifdef __cplusplus
extern "C" {
#endif

/* key matrix position */
typedef struct {
    uint8_t col;
    uint8_t row;
} keypos_t;

/* key event */
typedef struct {
    keypos_t key;
    bool     pressed;
    uint16_t time;
} keyevent_t;

/* equivalent test of keypos_t */
#define KEYEQ(keya, keyb)       ((keya).row == (keyb).row && (keya).col == (keyb).col)

/* 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 */
#define TICK                    (keyevent_t){           \
    .key = (keypos_t){ .row = 255, .col = 255 },           \
    .pressed = false,                                   \
    .time = (timer_read() | 1)                          \
}

/* it runs once at early stage of startup before keyboard_init. */
void keyboard_setup(void);
/* it runs once after initializing host side protocol, debug and MCU peripherals. */
void keyboard_init(void);
/* it runs repeatedly in main loop */
void keyboard_task(void);
/* it runs when host LED status is updated */
void keyboard_set_leds(uint8_t leds);

#ifdef __cplusplus
}
#endif

#endif