Skip to content

Commit 897c20a

Browse files
author
Florian Fleissner
committed
Implemented host_keymaps
host_keymaps enable defining keymaps in a natural fashion. Instead of using Key constants like Key_A or LSHIFT(Key_A) it allows to conveniently write "a" or "A". The mappings between ascii and unicode characters to USB-HID keys works by reverse engineering the host keymaps. If the host keymap is known, then the mapping between HID-report keys like Key_A, Key_LeftShift, etc. and the generated printable and non-printable keys on the host is well defined. This mapping can easily be reverse engineered, e.g. based on common keymaps like us_en but also for any other keymap that involves non-ascii symbols. host_keymaps also introduces unicode symbols for the most common keys on any keyboard that commonly represent non-printable characters. This allows for a KEYMAP(...) definition to closely resemble what would be printed on the keys of a keyboard with the actual keymap. The newly introduced host_keymap system is easily extensible and allows users to define their own non-english keymaps. A work-in-progress version of the EurKey keymap for most european languages also comes with this commit. It is however just started and needs some more work. It is mainly meant to demonstrate how one keymap can be defined based on another one (here EurKey is based on us_en), overriding only some of the keys and relying on the base keymap to take care of handling any non-overridden keys. Signed-off-by: Florian Fleissner <[email protected]>
1 parent 3cb97a3 commit 897c20a

File tree

8 files changed

+1118
-0
lines changed

8 files changed

+1118
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* -*- mode: c++ -*-
2+
* Kaleidoscope-Unicode -- Unicode input helpers
3+
* Copyright (C) 2016, 2017, 2018 Keyboard.io, Inc
4+
*
5+
* This program is free software: you can redistribute it and/or modify it under
6+
* the terms of the GNU General Public License as published by the Free Software
7+
* Foundation, version 3.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12+
* details.
13+
*
14+
* You should have received a copy of the GNU General Public License along with
15+
* this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#include <Kaleidoscope.h>
19+
20+
#include "kaleidoscope/host_keymap/ascii/us_en.h"
21+
#include "kaleidoscope/host_keymap/unicode/us_en.h"
22+
23+
USE_HOST_KEYMAP(ascii, us_en)
24+
USE_HOST_KEYMAP(unicode, us_en)
25+
26+
// *INDENT-OFF*
27+
28+
KEYMAPS(
29+
[0] = KEYMAP_STACKED
30+
(
31+
XXX, "1", "2", "3", "4", "5", XXX,
32+
"`", "q", "w", "e", "r", "t", "\t",
33+
L"", "a", "s", "d", "f", "g",
34+
L"", "z", "x", "c", "v", "b", L"",
35+
36+
L"", L"", L"", L"",
37+
XXX,
38+
39+
XXX, "6", "7", "8", "9", "0", XXX,
40+
L"", "y", "u", "i", "o", "p", "=",
41+
"h", "j", "k", "l", ";", "\"",
42+
XXX, "n", "m", ",", ".", "/", "-",
43+
44+
L"r⇧", L"r⌥", L"", L"r⌃",
45+
XXX
46+
)
47+
)
48+
// *INDENT-ON*
49+
50+
//KALEIDOSCOPE_INIT_PLUGINS();
51+
52+
void setup() {
53+
Kaleidoscope.setup();
54+
}
55+
56+
void loop() {
57+
Kaleidoscope.loop();
58+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/* Kaleidoscope - Firmware for computer input devices
2+
* Copyright (C) 2013-2018 Keyboard.io, Inc.
3+
*
4+
* This program is free software: you can redistribute it and/or modify it under
5+
* the terms of the GNU General Public License as published by the Free Software
6+
* Foundation, version 3.
7+
*
8+
* This program is distributed in the hope that it will be useful, but WITHOUT
9+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11+
* details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with
14+
* this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
#pragma once
18+
19+
#include "kaleidoscope/host_keymap/host_keymap.h"
20+
21+
namespace kaleidoscope {
22+
namespace host_keymap {
23+
namespace ascii {
24+
25+
struct AsciiCharProcessor {
26+
static constexpr bool isEscapeChar(char c) {
27+
return c == '#';
28+
}
29+
30+
static constexpr bool isSeparator(char c) {
31+
return (c == ' ')
32+
|| (c == '\t')
33+
|| (c == '+');
34+
}
35+
36+
static constexpr bool isMirrorChar(char c) {
37+
return c == 'r';
38+
}
39+
};
40+
41+
#define _HOST_KEYMAP_CAST_ON_MODIFIERS_ASCII(OP) \
42+
OP('s', LSHIFT(k)) \
43+
OP('S', LSHIFT(k)) \
44+
OP('c', LCTRL(k)) \
45+
OP('C', LCTRL(k)) \
46+
OP('a', LALT(k)) \
47+
OP('A', RALT(k)) \
48+
OP('m', LGUI(k)) \
49+
OP('M', LGUI(k)) \
50+
OP('g', LGUI(k)) \
51+
OP('G', LGUI(k))
52+
53+
// Define a AsciiConverter template base class that any ascii keymap converters
54+
// are derived from by means of invoking the HOST_KEYMAP_ASCII_LANGUAGE_CONVERTER
55+
// function macro.
56+
//
57+
_HOST_KEYMAP_DEFINE_CHAR_CONVERTER(
58+
AsciiConverter, char, _HOST_KEYMAP_CAST_ON_MODIFIERS_ASCII)
59+
60+
#undef _HOST_KEYMAP_CAST_ON_MODIFIERS_ASCII
61+
62+
typedef _CharParsingStandardFallback<char> CharParsingStandardFallback;
63+
64+
} // namespace ascii
65+
} // namespace host_keymap
66+
} // namespace kaleidoscope
67+
68+
#define HOST_KEYMAP_ASCII_LANGUAGE_CONVERTER(LANGUAGE_KEYMAP, CHAR_PARSING_FALLBACK) \
69+
struct Converter : public AsciiConverter<Converter, AsciiCharProcessor> \
70+
{ \
71+
typedef AsciiConverter<Converter, AsciiCharProcessor> Parent; \
72+
\
73+
using typename Parent::StringMemberType; \
74+
using typename Parent::CharType; \
75+
\
76+
static constexpr bool isKeyChar(char c) { \
77+
return LANGUAGE_KEYMAP(_HOST_KEYMAP_IS_KEY_CHAR) \
78+
CHAR_PARSING_FALLBACK::isKeyChar(c); \
79+
} \
80+
\
81+
static constexpr Key charToKey(char c) { \
82+
return LANGUAGE_KEYMAP( \
83+
_HOST_KEYMAP_MAP_KEY_CHAR_TO_KALEIDOSCOPE_KEY \
84+
) \
85+
CHAR_PARSING_FALLBACK::charToKey(c); \
86+
} \
87+
};
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/* Kaleidoscope - Firmware for computer input devices
2+
* Copyright (C) 2013-2018 Keyboard.io, Inc.
3+
*
4+
* This program is free software: you can redistribute it and/or modify it under
5+
* the terms of the GNU General Public License as published by the Free Software
6+
* Foundation, version 3.
7+
*
8+
* This program is distributed in the hope that it will be useful, but WITHOUT
9+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11+
* details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with
14+
* this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
#pragma once
18+
19+
#include "kaleidoscope/key_defs.h"
20+
#include "kaleidoscope/key_defs_keyboard.h"
21+
#include "kaleidoscope/host_keymap/ascii/common.h"
22+
23+
#define ASCII_US_EN_KEYMAP(OP) \
24+
OP('\n', Key_Enter) \
25+
OP('\t', Key_Tab) \
26+
\
27+
OP('!', LSHIFT(Key_1)) \
28+
OP('@', LSHIFT(Key_2)) \
29+
OP('#', LSHIFT(Key_3)) \
30+
OP('$', LSHIFT(Key_4)) \
31+
OP('%', LSHIFT(Key_5)) \
32+
OP('&', LSHIFT(Key_7)) \
33+
OP('\'', Key_Quote) \
34+
OP('"', LSHIFT(Key_Quote)) \
35+
OP('(', LSHIFT(Key_9)) \
36+
OP(')', LSHIFT(Key_0)) \
37+
OP('*', LSHIFT(Key_8)) \
38+
OP('+', LSHIFT(Key_Equals)) \
39+
OP(',', Key_Comma) \
40+
OP('-', Key_Minus) \
41+
OP('.', Key_Period) \
42+
OP('/', Key_Slash) \
43+
OP('0', Key_0) \
44+
OP('1', Key_1) \
45+
OP('2', Key_2) \
46+
OP('3', Key_3) \
47+
OP('4', Key_4) \
48+
OP('5', Key_5) \
49+
OP('6', Key_6) \
50+
OP('7', Key_7) \
51+
OP('8', Key_8) \
52+
OP('9', Key_9) \
53+
OP(':', LSHIFT(Key_Semicolon)) \
54+
OP(';', Key_Semicolon) \
55+
OP('<', LSHIFT(Key_Comma)) \
56+
OP('=', Key_Equals) \
57+
OP('>', LSHIFT(Key_Period)) \
58+
OP('?', LSHIFT(Key_Slash)) \
59+
\
60+
OP('A', LSHIFT(Key_A)) \
61+
OP('B', LSHIFT(Key_B)) \
62+
OP('C', LSHIFT(Key_C)) \
63+
OP('D', LSHIFT(Key_D)) \
64+
OP('E', LSHIFT(Key_E)) \
65+
OP('F', LSHIFT(Key_F)) \
66+
OP('G', LSHIFT(Key_G)) \
67+
OP('H', LSHIFT(Key_H)) \
68+
OP('I', LSHIFT(Key_I)) \
69+
OP('J', LSHIFT(Key_J)) \
70+
OP('K', LSHIFT(Key_K)) \
71+
OP('L', LSHIFT(Key_L)) \
72+
OP('M', LSHIFT(Key_M)) \
73+
OP('N', LSHIFT(Key_N)) \
74+
OP('O', LSHIFT(Key_O)) \
75+
OP('P', LSHIFT(Key_P)) \
76+
OP('Q', LSHIFT(Key_Q)) \
77+
OP('R', LSHIFT(Key_R)) \
78+
OP('S', LSHIFT(Key_S)) \
79+
OP('T', LSHIFT(Key_T)) \
80+
OP('U', LSHIFT(Key_U)) \
81+
OP('V', LSHIFT(Key_V)) \
82+
OP('W', LSHIFT(Key_W)) \
83+
OP('X', LSHIFT(Key_X)) \
84+
OP('Y', LSHIFT(Key_Y)) \
85+
OP('Z', LSHIFT(Key_Z)) \
86+
\
87+
OP('[', Key_LeftBracket) \
88+
OP('\\', Key_Backslash) \
89+
OP(']', Key_RightBracket) \
90+
OP('^', LSHIFT(Key_6)) \
91+
OP('_', LSHIFT(Key_Minus)) \
92+
OP('`', Key_Backtick) \
93+
\
94+
OP('a', Key_A) \
95+
OP('b', Key_B) \
96+
OP('c', Key_C) \
97+
OP('d', Key_D) \
98+
OP('e', Key_E) \
99+
OP('f', Key_F) \
100+
OP('g', Key_G) \
101+
OP('h', Key_H) \
102+
OP('i', Key_I) \
103+
OP('j', Key_J) \
104+
OP('k', Key_K) \
105+
OP('l', Key_L) \
106+
OP('m', Key_M) \
107+
OP('n', Key_N) \
108+
OP('o', Key_O) \
109+
OP('p', Key_P) \
110+
OP('q', Key_Q) \
111+
OP('r', Key_R) \
112+
OP('s', Key_S) \
113+
OP('t', Key_T) \
114+
OP('u', Key_U) \
115+
OP('v', Key_V) \
116+
OP('w', Key_W) \
117+
OP('x', Key_X) \
118+
OP('y', Key_Y) \
119+
OP('z', Key_Z) \
120+
\
121+
OP('{', LSHIFT(Key_LeftBracket)) \
122+
OP('|', LSHIFT(Key_Backslash)) \
123+
OP('}', LSHIFT(Key_RightBracket)) \
124+
OP('~', Key_Minus) \
125+
OP(' ', Key_Spacebar)
126+
127+
namespace kaleidoscope {
128+
namespace host_keymap {
129+
namespace ascii {
130+
namespace us_en {
131+
132+
HOST_KEYMAP_ASCII_LANGUAGE_CONVERTER(
133+
ASCII_US_EN_KEYMAP,
134+
CharParsingStandardFallback
135+
)
136+
137+
} // namespace us_en
138+
} // namespace ascii
139+
} // namespace host_keymap
140+
} // namespace kaleidoscope
141+
142+
#undef ASCII_US_EN_KEYMAP

0 commit comments

Comments
 (0)