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 #ifdef BOOTMAGIC_ENABLE
34 /* NOTE: Not portable. Bit field order depends on implementation */
38 bool swap_control_capslock:1;
39 bool capslock_to_control:1;
40 bool swap_lalt_lgui:1;
41 bool swap_ralt_rgui:1;
43 bool swap_grave_esc:1;
44 bool swap_backslash_backspace:1;
48 keymap_config_t keymap_config;
52 /* translates key to keycode */
53 uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
55 /* translates Fn keycode to action */
56 action_t keymap_fn_to_action(uint16_t keycode);
58 /* translates Fn keycode to action */
59 action_t keymap_func_to_action(uint16_t keycode);
61 extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
62 extern const uint16_t fn_actions[];
64 // Ability to use mods in layouts
65 #define LCTL(kc) kc | 0x0100
66 #define LSFT(kc) kc | 0x0200
67 #define LALT(kc) kc | 0x0400
68 #define LGUI(kc) kc | 0x0800
69 #define HYPR(kc) kc | 0x0F00
70 #define MEH(kc) kc | 0x0700
71 #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) // @
90 #define KC_HASH LSFT(KC_3) // #
92 #define KC_DLR LSFT(KC_4) // $
93 #define KC_DOLLAR KC_DLR
95 #define KC_PERC LSFT(KC_5) // %
96 #define KC_PERCENT KC_PERC
98 #define KC_CIRC LSFT(KC_6) // ^
99 #define KC_CIRCUMFLEX KC_CIRC
101 #define KC_AMPR LSFT(KC_7) // &
102 #define KC_AMPERSAND KC_AMPR
104 #define KC_ASTR LSFT(KC_8) // *
105 #define KC_ASTERISK KC_ASTR
107 #define KC_LPRN LSFT(KC_9) // (
108 #define KC_LEFT_PAREN KC_LPRN
110 #define KC_RPRN LSFT(KC_0) // )
111 #define KC_RIGHT_PAREN KC_RPRN
113 #define KC_UNDS LSFT(KC_MINS) // _
114 #define KC_UNDERSCORE KC_UNDS
116 #define KC_PLUS LSFT(KC_EQL) // +
118 #define KC_LCBR LSFT(KC_LBRC) // {
119 #define KC_LEFT_CURLY_BRACE KC_LCBR
121 #define KC_RCBR LSFT(KC_RBRC) // }
122 #define KC_RIGHT_CURLY_BRACE KC_RCBR
124 #define KC_COLN LSFT(KC_SCLN) // :
125 #define KC_COLON KC_COLN
127 #define KC_PIPE LSFT(KC_BSLS) // |
129 #define KC_DELT KC_DELETE // Del key (four letter code)
131 // Alias for function layers than expand past FN31
132 #define FUNC(kc) kc | 0x2000
135 #define S(kc) LSFT(kc)
136 #define F(kc) FUNC(kc)
138 #define M(kc) kc | 0x3000
140 #define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE)
142 // These affect the backlight (if your keyboard has one).
143 // We don't need to comment them out if your keyboard doesn't have a backlight,
144 // since they don't take up any space.
146 #define BL_OFF 0x4000
163 #define BL_DEC 0x4010
164 #define BL_INC 0x4011
165 #define BL_TOGG 0x4012
166 #define BL_STEP 0x4013
171 // GOTO layer - 16 layers max
175 // Unless you have a good reason not to do so, prefer ON_PRESS (1) as your default.
176 #define TO(layer, when) (layer | 0x5100 | (when << 0x4))
178 // Momentary switch layer - 256 layer max
179 #define MO(layer) (layer | 0x5200)
181 // Set default layer - 256 layer max
182 #define DF(layer) (layer | 0x5300)
184 // Toggle to layer - 256 layer max
185 #define TG(layer) (layer | 0x5400)
187 // M-od, T-ap - 256 keycode max
188 #define MT(mod, kc) (kc | 0x7000 | ((mod & 0xF) << 8))
189 #define CTL_T(kc) MT(0x1, kc)
190 #define SFT_T(kc) MT(0x2, kc)
191 #define ALT_T(kc) MT(0x4, kc)
192 #define GUI_T(kc) MT(0x8, kc)
193 #define C_S_T(kc) MT(0x3, kc) // Control + Shift e.g. for gnome-terminal
194 #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
195 #define LCAG_T(kc) MT(0xD, kc) // Left control alt and gui
196 #define ALL_T(kc) MT(0xF, kc) // see http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/
198 // Dedicated keycode versions for Hyper and Meh, if you want to use them as standalone keys rather than mod-tap
199 #define KC_HYPR HYPR(KC_NO)
200 #define KC_MEH MEH(KC_NO)
202 // L-ayer, T-ap - 256 keycode max, 16 layer max
203 #define LT(layer, kc) (kc | 0x8000 | ((layer & 0xF) << 8))
205 // For sending unicode codes.
206 // You may not send codes over 1FFF -- this supports most of UTF8.
207 // To have a key that sends out Œ, go UC(0x0152)
208 #define UNICODE(n) (n | 0x8000)
209 #define UC(n) UNICODE(n)
212 void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
213 #define IS_LAYER_ON(layer) ((layer_state) & (1UL<<(layer)))
214 #define IS_LAYER_OFF(layer) ((!layer_state) & (1UL<<(layer)))