2 Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
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.
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.
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/>.
24 #include <avr/pgmspace.h>
27 #include "action_macro.h"
33 /* NOTE: Not portable. Bit field order depends on implementation */
37 bool swap_control_capslock:1;
38 bool capslock_to_control:1;
39 bool swap_lalt_lgui:1;
40 bool swap_ralt_rgui:1;
42 bool swap_grave_esc:1;
43 bool swap_backslash_backspace:1;
49 /* translates key to keycode */
50 uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
52 /* translates Fn keycode to action */
53 action_t keymap_fn_to_action(uint16_t keycode);
55 /* translates Fn keycode to action */
56 action_t keymap_func_to_action(uint16_t keycode);
58 extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
59 extern const uint16_t fn_actions[];
61 // Ability to use mods in layouts
62 #define LCTL(kc) kc | 0x0100
63 #define LSFT(kc) kc | 0x0200
64 #define LALT(kc) kc | 0x0400
65 #define LGUI(kc) kc | 0x0800
66 #define HYPR(kc) kc | 0x0F00
67 #define MEH(kc) kc | 0x0700
68 #define LCAG(kc) kc | 0x0D00 // Modifier Ctrl Alt and GUI
73 #define RCTL(kc) kc | 0x1100
74 #define RSFT(kc) kc | 0x1200
75 #define RALT(kc) kc | 0x1400
76 #define RGUI(kc) kc | 0x1800
78 // Aliases for shifted symbols
79 // Each key has a 4-letter code, and some have longer aliases too.
80 // While the long aliases are descriptive, the 4-letter codes
81 // make for nicer grid layouts (everything lines up), and are
82 // the preferred style for Quantum.
83 #define KC_TILD LSFT(KC_GRV) // ~
84 #define KC_TILDE KC_TILD
86 #define KC_EXLM LSFT(KC_1) // !
87 #define KC_EXCLAIM KC_EXLM
89 #define KC_AT LSFT(KC_2) // @
92 #define KC_HASH LSFT(KC_3) // #
95 #define KC_DLR LSFT(KC_4) // $
96 #define KC_DOLLAR KC_DLR
98 #define KC_PERC LSFT(KC_5) // %
99 #define KC_PERCENT KC_PERC
101 #define KC_CIRC LSFT(KC_6) // ^
102 #define KC_CIRCUMFLEX KC_CIRC
104 #define KC_AMPR LSFT(KC_7) // &
105 #define KC_AMPERSAND KC_AMPR
107 #define KC_ASTR LSFT(KC_8) // *
108 #define KC_ASTERISK KC_ASTR
110 #define KC_LPRN LSFT(KC_9) // (
111 #define KC_LEFT_PAREN KC_LPRN
113 #define KC_RPRN LSFT(KC_0) // )
114 #define KC_RIGHT_PAREN KC_RPRN
117 #define KC_UNDS LSFT(KC_MINS) // _
118 #define KC_UNDERSCORE KC_UNDS
120 #define KC_PLUS LSFT(KC_EQL) // +
122 #define KC_DQUO LSFT(KC_QUOT) // "
123 #define KC_DOUBLE_QUOTE KC_DQUO
125 #define KC_LCBR LSFT(KC_LBRC) // {
126 #define KC_LEFT_CURLY_BRACE KC_LCBR
128 #define KC_RCBR LSFT(KC_RBRC) // }
129 #define KC_RIGHT_CURLY_BRACE KC_RCBR
131 #define KC_LABK LSFT(KC_COMM) // <
132 #define KC_LEFT_ANGLE_BRACKET KC_LABK
134 #define KC_RABK LSFT(KC_DOT) // >
135 #define KC_RIGHT_ANGLE_BRACKET KC_RABK
137 #define KC_COLN LSFT(KC_SCLN) // :
138 #define KC_COLON KC_COLN
140 #define KC_PIPE LSFT(KC_BSLS) // |
142 #define KC_LT LSFT(KC_COMM) // <
145 #define KC_GT LSFT(KC_DOT) // >
148 #define KC_QUES LSFT(KC_SLSH) // ?
149 #define KC_QUESTION KC_QUES
152 #define KC_DQT LSFT(KC_QUOT) // "
153 #define KC_DOUBLE_QUOTE KC_DQT
155 #define KC_DELT KC_DELETE // Del key (four letter code)
157 // Alias for function layers than expand past FN31
158 #define FUNC(kc) kc | 0x2000
161 #define S(kc) LSFT(kc)
162 #define F(kc) FUNC(kc)
164 #define M(kc) (kc | 0x3000)
166 #define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE)
170 // L-ayer, T-ap - 256 keycode max, 16 layer max
171 #define LT(layer, kc) (kc | 0x4000 | ((layer & 0xF) << 8))
177 #define MAGIC_SWAP_CONTROL_CAPSLOCK 0x5002
178 #define MAGIC_UNSWAP_CONTROL_CAPSLOCK 0x5003
179 #define MAGIC_CAPSLOCK_TO_CONTROL 0x5004
180 #define MAGIC_UNCAPSLOCK_TO_CONTROL 0x5005
181 #define MAGIC_SWAP_LALT_LGUI 0x5006
182 #define MAGIC_UNSWAP_LALT_LGUI 0x5007
183 #define MAGIC_SWAP_RALT_RGUI 0x5008
184 #define MAGIC_UNSWAP_RALT_RGUI 0x5009
185 #define MAGIC_NO_GUI 0x500a
186 #define MAGIC_UNNO_GUI 0x500b
187 #define MAGIC_SWAP_GRAVE_ESC 0x500c
188 #define MAGIC_UNSWAP_GRAVE_ESC 0x500d
189 #define MAGIC_SWAP_BACKSLASH_BACKSPACE 0x500e
190 #define MAGIC_UNSWAP_BACKSLASH_BACKSPACE 0x500f
191 #define MAGIC_HOST_NKRO 0x5010
192 #define MAGIC_UNHOST_NKRO 0x5011
193 #define MAGIC_SWAP_ALT_GUI 0x5012
194 #define MAGIC_UNSWAP_ALT_GUI 0x5013
196 #define AG_SWAP MAGIC_SWAP_ALT_GUI
197 #define AG_NORM MAGIC_UNSWAP_ALT_GUI
199 #define KC_LEAD 0x5014
203 #define AU_OFF 0x5021
204 #define AU_TOG 0x5022
208 #define MU_OFF 0x5024
209 #define MU_TOG 0x5025
211 // Music voice iterate
212 #define MUV_IN 0x5026
213 #define MUV_DE 0x5027
217 #define MI_OFF 0x5029
219 // These affect the backlight (if your keyboard has one).
220 // We don't need to comment them out if your keyboard doesn't have a backlight,
221 // since they don't take up any space.
223 #define BL_OFF 0x5070
240 #define BL_DEC 0x5080
241 #define BL_INC 0x5081
242 #define BL_TOGG 0x5082
243 #define BL_STEP 0x5083
245 #define KC_LSPO 0x5084 // Left shift, open parens when tapped
246 #define KC_RSPC 0x5085 // Right shift, close parens when tapped
247 // GOTO layer - 16 layers max
251 // Unless you have a good reason not to do so, prefer ON_PRESS (1) as your default.
252 #define TO(layer, when) (layer | 0x5100 | (when << 0x4))
254 // Momentary switch layer - 256 layer max
255 #define MO(layer) (layer | 0x5200)
257 // Set default layer - 256 layer max
258 #define DF(layer) (layer | 0x5300)
260 // Toggle to layer - 256 layer max
261 #define TG(layer) (layer | 0x5400)
263 // One-shot layer - 256 layer max
264 #define OSL(layer) (layer | 0x5500)
267 #define OSM(layer) (layer | 0x5600)
269 // chording is currently at 0x57xx
271 // M-od, T-ap - 256 keycode max
272 #define MT(mod, kc) (kc | 0x7000 | ((mod & 0xF) << 8))
273 #define CTL_T(kc) MT(0x1, kc)
274 #define SFT_T(kc) MT(0x2, kc)
275 #define ALT_T(kc) MT(0x4, kc)
276 #define GUI_T(kc) MT(0x8, kc)
277 #define C_S_T(kc) MT(0x3, kc) // Control + Shift e.g. for gnome-terminal
278 #define MEH_T(kc) MT(0x7, kc) // Meh is a less hyper version of the Hyper key -- doesn't include Win or Cmd, so just alt+shift+ctrl
279 #define LCAG_T(kc) MT(0xD, kc) // Left control alt and gui
280 #define ALL_T(kc) MT(0xF, kc) // see http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/
282 // Dedicated keycode versions for Hyper and Meh, if you want to use them as standalone keys rather than mod-tap
283 #define KC_HYPR HYPR(KC_NO)
284 #define KC_MEH MEH(KC_NO)
286 #ifdef UNICODE_ENABLE
287 // For sending unicode codes.
288 // You may not send codes over 7FFF -- this supports most of UTF8.
289 // To have a key that sends out Œ, go UC(0x0152)
290 #define UNICODE(n) (n | 0x8000)
291 #define UC(n) UNICODE(n)
295 void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
296 #define IS_LAYER_ON(layer) (layer_state & (1UL << (layer)))
297 #define IS_LAYER_OFF(layer) (~layer_state & (1UL << (layer)))