]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/keymap.h
Merge branch 'master' of http://github.com/jackhumbert/qmk_firmware
[qmk_firmware.git] / quantum / keymap.h
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"
24 #if defined(__AVR__)
25 #include <avr/pgmspace.h>
26 #endif
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
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
41 /* translates key to keycode */
42 uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
43
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,
85     QK_TAP_DANCE          = 0x7100,
86     QK_TAP_DANCE_MAX      = 0x71FF,
87 #ifdef UNICODE_ENABLE
88     QK_UNICODE            = 0x8000,
89     QK_UNICODE_MAX        = 0xFFFF,
90 #endif
91
92     // Loose keycodes - to be used directly
93
94     RESET = 0x7000,
95     DEBUG,
96     MAGIC_SWAP_CONTROL_CAPSLOCK,
97     MAGIC_CAPSLOCK_TO_CONTROL,
98     MAGIC_SWAP_LALT_LGUI,
99     MAGIC_SWAP_RALT_RGUI,
100     MAGIC_NO_GUI,
101     MAGIC_SWAP_GRAVE_ESC,
102     MAGIC_SWAP_BACKSLASH_BACKSPACE,
103     MAGIC_HOST_NKRO,
104     MAGIC_SWAP_ALT_GUI,
105     MAGIC_UNSWAP_CONTROL_CAPSLOCK,
106     MAGIC_UNCAPSLOCK_TO_CONTROL,
107     MAGIC_UNSWAP_LALT_LGUI,
108     MAGIC_UNSWAP_RALT_RGUI,
109     MAGIC_UNNO_GUI,
110     MAGIC_UNSWAP_GRAVE_ESC,
111     MAGIC_UNSWAP_BACKSLASH_BACKSPACE,
112     MAGIC_UNHOST_NKRO,
113     MAGIC_UNSWAP_ALT_GUI,
114     MAGIC_TOGGLE_NKRO,
115
116     // Leader key
117 #ifndef DISABLE_LEADER
118     KC_LEAD,
119 #endif
120
121     // Audio on/off/toggle
122     AU_ON,
123     AU_OFF,
124     AU_TOG,
125
126     // Music mode on/off/toggle
127     MU_ON,
128     MU_OFF,
129     MU_TOG,
130
131     // Music voice iterate
132     MUV_IN,
133     MUV_DE,
134
135     // Midi mode on/off
136     MIDI_ON,
137     MIDI_OFF,
138
139     // Backlight functionality
140     BL_0,
141     BL_1,
142     BL_2,
143     BL_3,
144     BL_4,
145     BL_5,
146     BL_6,
147     BL_7,
148     BL_8,
149     BL_9,
150     BL_10,
151     BL_11,
152     BL_12,
153     BL_13,
154     BL_14,
155     BL_15,
156     BL_DEC,
157     BL_INC,
158     BL_TOGG,
159     BL_STEP,
160
161     // RGB functionality
162     RGB_TOG,
163     RGB_MOD,
164     RGB_HUI,
165     RGB_HUD,
166     RGB_SAI,
167     RGB_SAD,
168     RGB_VAI,
169     RGB_VAD,
170
171     // Left shift, open paren
172     KC_LSPO,
173
174     // Right shift, close paren
175     KC_RSPC,
176
177     // always leave at the end
178     SAFE_RANGE
179 };
180
181 // Ability to use mods in layouts
182 #define LCTL(kc) (kc | QK_LCTL)
183 #define LSFT(kc) (kc | QK_LSFT)
184 #define LALT(kc) (kc | QK_LALT)
185 #define LGUI(kc) (kc | QK_LGUI)
186 #define RCTL(kc) (kc | QK_RCTL)
187 #define RSFT(kc) (kc | QK_RSFT)
188 #define RALT(kc) (kc | QK_RALT)
189 #define RGUI(kc) (kc | QK_RGUI)
190
191 #define HYPR(kc) (kc | QK_LCTL | QK_LSFT | QK_LALT | QK_LGUI)
192 #define MEH(kc)  (kc | QK_LCTL | QK_LSFT | QK_LALT)
193 #define LCAG(kc) (kc | QK_LCTL | QK_LALT | QK_LGUI)
194
195 #define MOD_HYPR 0xf
196 #define MOD_MEH 0x7
197
198
199 // Aliases for shifted symbols
200 // Each key has a 4-letter code, and some have longer aliases too.
201 // While the long aliases are descriptive, the 4-letter codes
202 // make for nicer grid layouts (everything lines up), and are
203 // the preferred style for Quantum.
204 #define KC_TILD LSFT(KC_GRV)    // ~
205 #define KC_TILDE    KC_TILD
206
207 #define KC_EXLM LSFT(KC_1)      // !
208 #define KC_EXCLAIM  KC_EXLM
209
210 #define KC_AT   LSFT(KC_2)      // @
211
212 #define KC_HASH LSFT(KC_3)      // #
213
214 #define KC_DLR  LSFT(KC_4)      // $
215 #define KC_DOLLAR   KC_DLR
216
217 #define KC_PERC LSFT(KC_5)      // %
218 #define KC_PERCENT  KC_PERC
219
220 #define KC_CIRC LSFT(KC_6)      // ^
221 #define KC_CIRCUMFLEX   KC_CIRC
222
223 #define KC_AMPR LSFT(KC_7)      // &
224 #define KC_AMPERSAND    KC_AMPR
225
226 #define KC_ASTR LSFT(KC_8)      // *
227 #define KC_ASTERISK KC_ASTR
228
229 #define KC_LPRN LSFT(KC_9)      // (
230 #define KC_LEFT_PAREN   KC_LPRN
231
232 #define KC_RPRN LSFT(KC_0)      // )
233 #define KC_RIGHT_PAREN  KC_RPRN
234
235 #define KC_UNDS LSFT(KC_MINS)   // _
236 #define KC_UNDERSCORE   KC_UNDS
237
238 #define KC_PLUS LSFT(KC_EQL)    // +
239
240 #define KC_LCBR LSFT(KC_LBRC)   // {
241 #define KC_LEFT_CURLY_BRACE KC_LCBR
242
243 #define KC_RCBR LSFT(KC_RBRC)   // }
244 #define KC_RIGHT_CURLY_BRACE    KC_RCBR
245
246 #define KC_LABK LSFT(KC_COMM)   // <
247 #define KC_LEFT_ANGLE_BRACKET   KC_LABK
248
249 #define KC_RABK LSFT(KC_DOT)    // >
250 #define KC_RIGHT_ANGLE_BRACKET  KC_RABK
251
252 #define KC_COLN LSFT(KC_SCLN)   // :
253 #define KC_COLON    KC_COLN
254
255 #define KC_PIPE LSFT(KC_BSLS)   // |
256
257 #define KC_LT LSFT(KC_COMM)     // <
258
259 #define KC_GT LSFT(KC_DOT)      // >
260
261 #define KC_QUES LSFT(KC_SLSH)   // ?
262 #define KC_QUESTION KC_QUES
263
264 #define KC_DQT LSFT(KC_QUOT)   // "
265 #define KC_DOUBLE_QUOTE KC_DQT
266 #define KC_DQUO KC_DQT
267
268 #define KC_DELT KC_DELETE // Del key (four letter code)
269
270 // Alias for function layers than expand past FN31
271 #define FUNC(kc) (kc | QK_FUNCTION)
272
273 // Aliases
274 #define S(kc) LSFT(kc)
275 #define F(kc) FUNC(kc)
276
277 #define M(kc) (kc | QK_MACRO)
278
279 #define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE)
280
281 // L-ayer, T-ap - 256 keycode max, 16 layer max
282 #define LT(layer, kc) (kc | QK_LAYER_TAP | ((layer & 0xF) << 8))
283
284 #define AG_SWAP MAGIC_SWAP_ALT_GUI
285 #define AG_NORM MAGIC_UNSWAP_ALT_GUI
286
287 #define BL_ON  BL_9
288 #define BL_OFF BL_0
289
290 #define MI_ON MIDI_ON
291 #define MI_OFF MIDI_OFF
292
293 // GOTO layer - 16 layers max
294 // when:
295 // ON_PRESS    = 1
296 // ON_RELEASE  = 2
297 // Unless you have a good reason not to do so, prefer  ON_PRESS (1) as your default.
298 #define TO(layer, when) (layer | QK_TO | (when << 0x4))
299
300 // Momentary switch layer - 256 layer max
301 #define MO(layer) (layer | QK_MOMENTARY)
302
303 // Set default layer - 256 layer max
304 #define DF(layer) (layer | QK_DEF_LAYER)
305
306 // Toggle to layer - 256 layer max
307 #define TG(layer) (layer | QK_TOGGLE_LAYER)
308
309 // One-shot layer - 256 layer max
310 #define OSL(layer) (layer | QK_ONE_SHOT_LAYER)
311
312 // One-shot mod
313 #define OSM(mod) (mod | QK_ONE_SHOT_MOD)
314
315 // M-od, T-ap - 256 keycode max
316 #define MT(mod, kc) (kc | QK_MOD_TAP | ((mod & 0xF) << 8))
317 #define CTL_T(kc) MT(MOD_LCTL, kc)
318 #define SFT_T(kc) MT(MOD_LSFT, kc)
319 #define ALT_T(kc) MT(MOD_LALT, kc)
320 #define GUI_T(kc) MT(MOD_LGUI, kc)
321 #define C_S_T(kc) MT((MOD_LCTL | MOD_LSFT), kc) // Control + Shift e.g. for gnome-terminal
322 #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
323 #define LCAG_T(kc) MT((MOD_LCTL | MOD_LALT | MOD_LGUI), kc) // Left control alt and gui
324 #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/
325
326 // Dedicated keycode versions for Hyper and Meh, if you want to use them as standalone keys rather than mod-tap
327 #define KC_HYPR HYPR(KC_NO)
328 #define KC_MEH  MEH(KC_NO)
329
330 #ifdef UNICODE_ENABLE
331     // For sending unicode codes.
332     // You may not send codes over 7FFF -- this supports most of UTF8.
333     // To have a key that sends out Œ, go UC(0x0152)
334     #define UNICODE(n) (n | QK_UNICODE)
335     #define UC(n) UNICODE(n)
336 #endif
337
338
339 #endif