Commit | Line | Data |
---|---|---|
db32864c JH |
1 | /* |
2 | Copyright 2012,2013 Jun Wako <wakojun@gmail.com> | |
3 | ||
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 | |
6 | the Free Software Foundation, either version 2 of the License, or | |
7 | (at your option) any later version. | |
8 | ||
9 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | */ | |
17 | ||
18 | #ifndef KEYMAP_H | |
19 | #define KEYMAP_H | |
20 | ||
21 | #include <stdint.h> | |
22 | #include <stdbool.h> | |
23 | #include "action.h" | |
4d4f7684 | 24 | #if defined(__AVR__) |
db32864c | 25 | #include <avr/pgmspace.h> |
4d4f7684 | 26 | #endif |
db32864c JH |
27 | #include "keycode.h" |
28 | #include "action_macro.h" | |
29 | #include "report.h" | |
30 | #include "host.h" | |
31 | // #include "print.h" | |
32 | #include "debug.h" | |
33 | #include "keycode_config.h" | |
34 | ||
4d4f7684 | 35 | // ChibiOS uses RESET in its FlagStatus enumeration |
36 | // Therefore define it as QK_RESET here, to avoid name collision | |
37 | #if defined(PROTOCOL_CHIBIOS) | |
38 | #define RESET QK_RESET | |
39 | #endif | |
40 | ||
db32864c JH |
41 | /* translates key to keycode */ |
42 | uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key); | |
43 | ||
db32864c JH |
44 | extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; |
45 | extern const uint16_t fn_actions[]; | |
46 | ||
47 | enum quantum_keycodes { | |
48 | // Ranges used in shortucuts - not to be used directly | |
49 | QK_TMK = 0x0000, | |
50 | QK_TMK_MAX = 0x00FF, | |
51 | QK_MODS = 0x0100, | |
52 | QK_LCTL = 0x0100, | |
53 | QK_LSFT = 0x0200, | |
54 | QK_LALT = 0x0400, | |
55 | QK_LGUI = 0x0800, | |
56 | QK_RCTL = 0x1100, | |
57 | QK_RSFT = 0x1200, | |
58 | QK_RALT = 0x1400, | |
59 | QK_RGUI = 0x1800, | |
60 | QK_MODS_MAX = 0x1FFF, | |
61 | QK_FUNCTION = 0x2000, | |
62 | QK_FUNCTION_MAX = 0x2FFF, | |
63 | QK_MACRO = 0x3000, | |
64 | QK_MACRO_MAX = 0x3FFF, | |
65 | QK_LAYER_TAP = 0x4000, | |
66 | QK_LAYER_TAP_MAX = 0x4FFF, | |
67 | QK_TO = 0x5000, | |
68 | QK_TO_MAX = 0x50FF, | |
69 | QK_MOMENTARY = 0x5100, | |
70 | QK_MOMENTARY_MAX = 0x51FF, | |
71 | QK_DEF_LAYER = 0x5200, | |
72 | QK_DEF_LAYER_MAX = 0x52FF, | |
73 | QK_TOGGLE_LAYER = 0x5300, | |
74 | QK_TOGGLE_LAYER_MAX = 0x53FF, | |
75 | QK_ONE_SHOT_LAYER = 0x5400, | |
76 | QK_ONE_SHOT_LAYER_MAX = 0x54FF, | |
77 | QK_ONE_SHOT_MOD = 0x5500, | |
78 | QK_ONE_SHOT_MOD_MAX = 0x55FF, | |
79 | #ifndef DISABLE_CHORDING | |
80 | QK_CHORDING = 0x5600, | |
81 | QK_CHORDING_MAX = 0x56FF, | |
82 | #endif | |
83 | QK_MOD_TAP = 0x6000, | |
84 | QK_MOD_TAP_MAX = 0x6FFF, | |
65faab3b JH |
85 | QK_TAP_DANCE = 0x7100, |
86 | QK_TAP_DANCE_MAX = 0x71FF, | |
5b2e455d PIN |
87 | #ifdef UNICODEMAP_ENABLE |
88 | QK_UNICODE_MAP = 0x7800, | |
89 | QK_UNICODE_MAP_MAX = 0x7FFF, | |
90 | #endif | |
db32864c JH |
91 | #ifdef UNICODE_ENABLE |
92 | QK_UNICODE = 0x8000, | |
93 | QK_UNICODE_MAX = 0xFFFF, | |
94 | #endif | |
95 | ||
96 | // Loose keycodes - to be used directly | |
97 | ||
98 | RESET = 0x7000, | |
99 | DEBUG, | |
100 | MAGIC_SWAP_CONTROL_CAPSLOCK, | |
101 | MAGIC_CAPSLOCK_TO_CONTROL, | |
102 | MAGIC_SWAP_LALT_LGUI, | |
103 | MAGIC_SWAP_RALT_RGUI, | |
104 | MAGIC_NO_GUI, | |
105 | MAGIC_SWAP_GRAVE_ESC, | |
106 | MAGIC_SWAP_BACKSLASH_BACKSPACE, | |
107 | MAGIC_HOST_NKRO, | |
108 | MAGIC_SWAP_ALT_GUI, | |
109 | MAGIC_UNSWAP_CONTROL_CAPSLOCK, | |
110 | MAGIC_UNCAPSLOCK_TO_CONTROL, | |
111 | MAGIC_UNSWAP_LALT_LGUI, | |
112 | MAGIC_UNSWAP_RALT_RGUI, | |
113 | MAGIC_UNNO_GUI, | |
114 | MAGIC_UNSWAP_GRAVE_ESC, | |
115 | MAGIC_UNSWAP_BACKSLASH_BACKSPACE, | |
116 | MAGIC_UNHOST_NKRO, | |
117 | MAGIC_UNSWAP_ALT_GUI, | |
558f3ec1 | 118 | MAGIC_TOGGLE_NKRO, |
db32864c JH |
119 | |
120 | // Leader key | |
121 | #ifndef DISABLE_LEADER | |
122 | KC_LEAD, | |
123 | #endif | |
124 | ||
125 | // Audio on/off/toggle | |
126 | AU_ON, | |
127 | AU_OFF, | |
128 | AU_TOG, | |
129 | ||
130 | // Music mode on/off/toggle | |
131 | MU_ON, | |
132 | MU_OFF, | |
133 | MU_TOG, | |
134 | ||
135 | // Music voice iterate | |
136 | MUV_IN, | |
137 | MUV_DE, | |
138 | ||
139 | // Midi mode on/off | |
13bb6b4b JH |
140 | MIDI_ON, |
141 | MIDI_OFF, | |
db32864c JH |
142 | |
143 | // Backlight functionality | |
144 | BL_0, | |
145 | BL_1, | |
146 | BL_2, | |
147 | BL_3, | |
148 | BL_4, | |
149 | BL_5, | |
150 | BL_6, | |
151 | BL_7, | |
152 | BL_8, | |
153 | BL_9, | |
154 | BL_10, | |
155 | BL_11, | |
156 | BL_12, | |
157 | BL_13, | |
158 | BL_14, | |
159 | BL_15, | |
160 | BL_DEC, | |
161 | BL_INC, | |
162 | BL_TOGG, | |
163 | BL_STEP, | |
e692ebf8 | 164 | |
165 | // RGB functionality | |
166 | RGB_TOG, | |
167 | RGB_MOD, | |
168 | RGB_HUI, | |
169 | RGB_HUD, | |
170 | RGB_SAI, | |
171 | RGB_SAD, | |
172 | RGB_VAI, | |
173 | RGB_VAD, | |
db32864c JH |
174 | |
175 | // Left shift, open paren | |
176 | KC_LSPO, | |
177 | ||
178 | // Right shift, close paren | |
13bb6b4b JH |
179 | KC_RSPC, |
180 | ||
181 | // always leave at the end | |
182 | SAFE_RANGE | |
db32864c JH |
183 | }; |
184 | ||
185 | // Ability to use mods in layouts | |
186 | #define LCTL(kc) (kc | QK_LCTL) | |
187 | #define LSFT(kc) (kc | QK_LSFT) | |
188 | #define LALT(kc) (kc | QK_LALT) | |
189 | #define LGUI(kc) (kc | QK_LGUI) | |
190 | #define RCTL(kc) (kc | QK_RCTL) | |
191 | #define RSFT(kc) (kc | QK_RSFT) | |
192 | #define RALT(kc) (kc | QK_RALT) | |
193 | #define RGUI(kc) (kc | QK_RGUI) | |
194 | ||
195 | #define HYPR(kc) (kc | QK_LCTL | QK_LSFT | QK_LALT | QK_LGUI) | |
196 | #define MEH(kc) (kc | QK_LCTL | QK_LSFT | QK_LALT) | |
197 | #define LCAG(kc) (kc | QK_LCTL | QK_LALT | QK_LGUI) | |
1048a588 | 198 | #define ALTG(kc) (kc | QK_RCTL | QK_RALT) |
db32864c JH |
199 | |
200 | #define MOD_HYPR 0xf | |
201 | #define MOD_MEH 0x7 | |
202 | ||
203 | ||
204 | // Aliases for shifted symbols | |
205 | // Each key has a 4-letter code, and some have longer aliases too. | |
206 | // While the long aliases are descriptive, the 4-letter codes | |
207 | // make for nicer grid layouts (everything lines up), and are | |
208 | // the preferred style for Quantum. | |
209 | #define KC_TILD LSFT(KC_GRV) // ~ | |
210 | #define KC_TILDE KC_TILD | |
211 | ||
212 | #define KC_EXLM LSFT(KC_1) // ! | |
213 | #define KC_EXCLAIM KC_EXLM | |
214 | ||
215 | #define KC_AT LSFT(KC_2) // @ | |
216 | ||
217 | #define KC_HASH LSFT(KC_3) // # | |
218 | ||
219 | #define KC_DLR LSFT(KC_4) // $ | |
220 | #define KC_DOLLAR KC_DLR | |
221 | ||
222 | #define KC_PERC LSFT(KC_5) // % | |
223 | #define KC_PERCENT KC_PERC | |
224 | ||
225 | #define KC_CIRC LSFT(KC_6) // ^ | |
226 | #define KC_CIRCUMFLEX KC_CIRC | |
227 | ||
228 | #define KC_AMPR LSFT(KC_7) // & | |
229 | #define KC_AMPERSAND KC_AMPR | |
230 | ||
231 | #define KC_ASTR LSFT(KC_8) // * | |
232 | #define KC_ASTERISK KC_ASTR | |
233 | ||
234 | #define KC_LPRN LSFT(KC_9) // ( | |
235 | #define KC_LEFT_PAREN KC_LPRN | |
236 | ||
237 | #define KC_RPRN LSFT(KC_0) // ) | |
238 | #define KC_RIGHT_PAREN KC_RPRN | |
239 | ||
240 | #define KC_UNDS LSFT(KC_MINS) // _ | |
241 | #define KC_UNDERSCORE KC_UNDS | |
242 | ||
243 | #define KC_PLUS LSFT(KC_EQL) // + | |
244 | ||
245 | #define KC_LCBR LSFT(KC_LBRC) // { | |
246 | #define KC_LEFT_CURLY_BRACE KC_LCBR | |
247 | ||
248 | #define KC_RCBR LSFT(KC_RBRC) // } | |
249 | #define KC_RIGHT_CURLY_BRACE KC_RCBR | |
250 | ||
251 | #define KC_LABK LSFT(KC_COMM) // < | |
252 | #define KC_LEFT_ANGLE_BRACKET KC_LABK | |
253 | ||
254 | #define KC_RABK LSFT(KC_DOT) // > | |
255 | #define KC_RIGHT_ANGLE_BRACKET KC_RABK | |
256 | ||
257 | #define KC_COLN LSFT(KC_SCLN) // : | |
258 | #define KC_COLON KC_COLN | |
259 | ||
260 | #define KC_PIPE LSFT(KC_BSLS) // | | |
261 | ||
262 | #define KC_LT LSFT(KC_COMM) // < | |
263 | ||
264 | #define KC_GT LSFT(KC_DOT) // > | |
265 | ||
266 | #define KC_QUES LSFT(KC_SLSH) // ? | |
267 | #define KC_QUESTION KC_QUES | |
268 | ||
269 | #define KC_DQT LSFT(KC_QUOT) // " | |
270 | #define KC_DOUBLE_QUOTE KC_DQT | |
271 | #define KC_DQUO KC_DQT | |
272 | ||
273 | #define KC_DELT KC_DELETE // Del key (four letter code) | |
274 | ||
275 | // Alias for function layers than expand past FN31 | |
276 | #define FUNC(kc) (kc | QK_FUNCTION) | |
277 | ||
278 | // Aliases | |
279 | #define S(kc) LSFT(kc) | |
280 | #define F(kc) FUNC(kc) | |
281 | ||
282 | #define M(kc) (kc | QK_MACRO) | |
283 | ||
284 | #define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE) | |
285 | ||
286 | // L-ayer, T-ap - 256 keycode max, 16 layer max | |
287 | #define LT(layer, kc) (kc | QK_LAYER_TAP | ((layer & 0xF) << 8)) | |
288 | ||
289 | #define AG_SWAP MAGIC_SWAP_ALT_GUI | |
290 | #define AG_NORM MAGIC_UNSWAP_ALT_GUI | |
291 | ||
292 | #define BL_ON BL_9 | |
293 | #define BL_OFF BL_0 | |
294 | ||
13bb6b4b JH |
295 | #define MI_ON MIDI_ON |
296 | #define MI_OFF MIDI_OFF | |
297 | ||
db32864c JH |
298 | // GOTO layer - 16 layers max |
299 | // when: | |
300 | // ON_PRESS = 1 | |
301 | // ON_RELEASE = 2 | |
302 | // Unless you have a good reason not to do so, prefer ON_PRESS (1) as your default. | |
e27a754b JE |
303 | // In fact, we changed it to assume ON_PRESS for sanity/simplicity. If needed, you can add your own |
304 | // keycode modeled after the old version, kept below for this. | |
305 | /* #define TO(layer, when) (layer | QK_TO | (when << 0x4)) */ | |
306 | #define TO(layer) (layer | QK_TO | (ON_PRESS << 0x4)) | |
db32864c JH |
307 | |
308 | // Momentary switch layer - 256 layer max | |
309 | #define MO(layer) (layer | QK_MOMENTARY) | |
310 | ||
311 | // Set default layer - 256 layer max | |
312 | #define DF(layer) (layer | QK_DEF_LAYER) | |
313 | ||
314 | // Toggle to layer - 256 layer max | |
315 | #define TG(layer) (layer | QK_TOGGLE_LAYER) | |
316 | ||
317 | // One-shot layer - 256 layer max | |
318 | #define OSL(layer) (layer | QK_ONE_SHOT_LAYER) | |
319 | ||
320 | // One-shot mod | |
e692ebf8 | 321 | #define OSM(mod) (mod | QK_ONE_SHOT_MOD) |
db32864c JH |
322 | |
323 | // M-od, T-ap - 256 keycode max | |
324 | #define MT(mod, kc) (kc | QK_MOD_TAP | ((mod & 0xF) << 8)) | |
325 | #define CTL_T(kc) MT(MOD_LCTL, kc) | |
326 | #define SFT_T(kc) MT(MOD_LSFT, kc) | |
327 | #define ALT_T(kc) MT(MOD_LALT, kc) | |
328 | #define GUI_T(kc) MT(MOD_LGUI, kc) | |
1a0bac8b JH |
329 | #define C_S_T(kc) MT((MOD_LCTL | MOD_LSFT), kc) // Control + Shift e.g. for gnome-terminal |
330 | #define MEH_T(kc) MT((MOD_LCTL | MOD_LSFT | MOD_LALT), kc) // Meh is a less hyper version of the Hyper key -- doesn't include Win or Cmd, so just alt+shift+ctrl | |
331 | #define LCAG_T(kc) MT((MOD_LCTL | MOD_LALT | MOD_LGUI), kc) // Left control alt and gui | |
332 | #define ALL_T(kc) MT((MOD_LCTL | MOD_LSFT | MOD_LALT | MOD_LGUI), kc) // see http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/ | |
db32864c JH |
333 | |
334 | // Dedicated keycode versions for Hyper and Meh, if you want to use them as standalone keys rather than mod-tap | |
335 | #define KC_HYPR HYPR(KC_NO) | |
336 | #define KC_MEH MEH(KC_NO) | |
337 | ||
338 | #ifdef UNICODE_ENABLE | |
339 | // For sending unicode codes. | |
340 | // You may not send codes over 7FFF -- this supports most of UTF8. | |
341 | // To have a key that sends out Œ, go UC(0x0152) | |
342 | #define UNICODE(n) (n | QK_UNICODE) | |
343 | #define UC(n) UNICODE(n) | |
344 | #endif | |
345 | ||
5b2e455d PIN |
346 | #ifdef UNICODEMAP_ENABLE |
347 | #define X(n) (n | QK_UNICODE_MAP) | |
348 | #endif | |
db32864c JH |
349 | |
350 | #endif |