aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2016-04-16 18:51:58 -0400
committerJack Humbert <jack.humb@gmail.com>2016-04-16 18:51:58 -0400
commitab19ebd08a8b955775e6fa94cdf6b8d128d8b43c (patch)
tree7120e8037a1a9935b3b9e4109e251530f893c3b3
parent5f648b6c4060d586c343ea05562c607e2630dfc4 (diff)
downloadqmk_firmware-ab19ebd08a8b955775e6fa94cdf6b8d128d8b43c.tar.gz
qmk_firmware-ab19ebd08a8b955775e6fa94cdf6b8d128d8b43c.zip
MAGIC functionality, AG swap in default layout
-rw-r--r--keyboard/planck/keymaps/default/README.md32
-rw-r--r--keyboard/preonic/Makefile2
-rw-r--r--keyboard/preonic/keymaps/default/keymap.c19
-rw-r--r--quantum/keymap_common.c250
-rw-r--r--quantum/keymap_common.h28
-rw-r--r--tmk_core/common.mk3
-rw-r--r--tmk_core/common/keyboard.c8
-rw-r--r--tmk_core/common/keymap.h3
-rw-r--r--tmk_core/common/magic.c36
-rw-r--r--tmk_core/common/magic.h6
10 files changed, 226 insertions, 161 deletions
diff --git a/keyboard/planck/keymaps/default/README.md b/keyboard/planck/keymaps/default/README.md
index d2f43bbdb..de9680b49 100644
--- a/keyboard/planck/keymaps/default/README.md
+++ b/keyboard/planck/keymaps/default/README.md
@@ -1,34 +1,2 @@
1# The Default Planck Layout 1# The Default Planck Layout
2 2
3 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
4 [_QW] = { /* Qwerty */
5 {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC},
6 {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT},
7 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT },
8 {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
9 },
10 [_CM] = { /* Colemak */
11 {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC},
12 {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT},
13 {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT },
14 {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
15 },
16 [_DV] = { /* Dvorak */
17 {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC},
18 {KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH},
19 {KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT },
20 {M(0), KC_LCTL, KC_LALT, KC_LGUI, MO(_LW), KC_SPC, KC_SPC, MO(_RS), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
21 },
22 [_RS] = { /* RAISE */
23 {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
24 {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS},
25 {KC_TRNS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, DF(_QW), DF(_CM), DF(_DV), RESET, KC_TRNS},
26 {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
27 },
28 [_LW] = { /* LOWER */
29 {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC},
30 {KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE},
31 {KC_TRNS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, DF(_QW), DF(_CM), DF(_DV), RESET, KC_TRNS},
32 {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
33 }
34 }; \ No newline at end of file
diff --git a/keyboard/preonic/Makefile b/keyboard/preonic/Makefile
index eaf9ef927..9199968c3 100644
--- a/keyboard/preonic/Makefile
+++ b/keyboard/preonic/Makefile
@@ -130,7 +130,7 @@ OPT_DEFS += -DBOOTLOADER_SIZE=4096
130# change to "no" to disable the options, or define them in the makefile.mk in 130# change to "no" to disable the options, or define them in the makefile.mk in
131# the appropriate keymap folder that will get included automatically 131# the appropriate keymap folder that will get included automatically
132# 132#
133BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) 133BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
134MOUSEKEY_ENABLE = yes # Mouse keys(+4700) 134MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
135EXTRAKEY_ENABLE = yes # Audio control and System control(+450) 135EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
136CONSOLE_ENABLE = yes # Console for debug(+400) 136CONSOLE_ENABLE = yes # Console for debug(+400)
diff --git a/keyboard/preonic/keymaps/default/keymap.c b/keyboard/preonic/keymaps/default/keymap.c
index 6824f68b6..e1f9b6202 100644
--- a/keyboard/preonic/keymaps/default/keymap.c
+++ b/keyboard/preonic/keymaps/default/keymap.c
@@ -153,9 +153,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
153 * |------+------+------+------+------+------+------+------+------+------+------+------| 153 * |------+------+------+------+------+------+------+------+------+------+------+------|
154 * | | Reset| | | | | | | | | | Del | 154 * | | Reset| | | | | | | | | | Del |
155 * |------+------+------+------+------+-------------+------+------+------+------+------| 155 * |------+------+------+------+------+-------------+------+------+------+------+------|
156 * | | | |Audoff|Aud on| | |Qwerty|Colemk|Dvorak| | | 156 * | | | |Audoff|Aud on|AGnorm|AGswap|Qwerty|Colemk|Dvorak| | |
157 * |------+------+------+------+------+------|------+------+------+------+------+------| 157 * |------+------+------+------+------+------|------+------+------+------+------+------|
158 * | | | | | | | | | | | | | 158 * | | | |Musoff|Mus on| | | | | | | |
159 * |------+------+------+------+------+------+------+------+------+------+------+------| 159 * |------+------+------+------+------+------+------+------+------+------+------+------|
160 * | | | | | | | | | | | | 160 * | | | | | | | | | | | |
161 * `-----------------------------------------------------------------------------------' 161 * `-----------------------------------------------------------------------------------'
@@ -163,7 +163,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
163[_ADJUST] = { 163[_ADJUST] = {
164 {KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12}, 164 {KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12},
165 {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL}, 165 {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL},
166 {_______, _______, _______, AUD_ON, AUD_OFF, _______, _______, QWERTY, COLEMAK, DVORAK, _______, _______}, 166 {_______, _______, _______, AUD_ON, AUD_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, _______, _______},
167 {_______, _______, _______, MUS_ON, MUS_OFF, _______, _______, _______, _______, _______, _______, _______}, 167 {_______, _______, _______, MUS_ON, MUS_OFF, _______, _______, _______, _______, _______, _______, _______},
168 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______} 168 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
169}, 169},
@@ -231,6 +231,10 @@ float tone_music[][2] = {
231}; 231};
232#endif 232#endif
233 233
234void persistant_default_layer_set(uint16_t default_layer) {
235 eeconfig_write_default_layer(default_layer);
236 default_layer_set(default_layer);
237}
234 238
235const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) 239const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
236{ 240{
@@ -240,8 +244,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
240 #ifdef AUDIO_ENABLE 244 #ifdef AUDIO_ENABLE
241 play_notes(&tone_qwerty, 4, false); 245 play_notes(&tone_qwerty, 4, false);
242 #endif 246 #endif
243 eeconfig_write_default_layer(1UL<<_QWERTY); 247 persistant_default_layer_set(1UL<<_QWERTY);
244 default_layer_set(1UL<<_QWERTY);
245 } 248 }
246 break; 249 break;
247 case _COLEMAK: 250 case _COLEMAK:
@@ -249,8 +252,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
249 #ifdef AUDIO_ENABLE 252 #ifdef AUDIO_ENABLE
250 play_notes(&tone_colemak, 6, false); 253 play_notes(&tone_colemak, 6, false);
251 #endif 254 #endif
252 eeconfig_write_default_layer(1UL<<_COLEMAK); 255 persistant_default_layer_set(1UL<<_COLEMAK);
253 default_layer_set(1UL<<_COLEMAK);
254 } 256 }
255 break; 257 break;
256 case _DVORAK: 258 case _DVORAK:
@@ -258,8 +260,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
258 #ifdef AUDIO_ENABLE 260 #ifdef AUDIO_ENABLE
259 play_notes(&tone_dvorak, 8, false); 261 play_notes(&tone_dvorak, 8, false);
260 #endif 262 #endif
261 eeconfig_write_default_layer(1UL<<_DVORAK); 263 persistant_default_layer_set(1UL<<_DVORAK);
262 default_layer_set(1UL<<_DVORAK);
263 } 264 }
264 break; 265 break;
265 case _LOWER: 266 case _LOWER:
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 3a00d36f0..b91916685 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -27,6 +27,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
27#include "keymap_midi.h" 27#include "keymap_midi.h"
28#include "bootloader.h" 28#include "bootloader.h"
29 29
30extern keymap_config_t keymap_config;
31
30#include <stdio.h> 32#include <stdio.h>
31#include <inttypes.h> 33#include <inttypes.h>
32#ifdef AUDIO_ENABLE 34#ifdef AUDIO_ENABLE
@@ -47,120 +49,9 @@ action_t action_for_key(uint8_t layer, keypos_t key)
47 // 16bit keycodes - important 49 // 16bit keycodes - important
48 uint16_t keycode = keymap_key_to_keycode(layer, key); 50 uint16_t keycode = keymap_key_to_keycode(layer, key);
49 51
50 if (keycode >= 0x0100 && keycode < 0x2000) {
51 // Has a modifier
52 action_t action;
53 // Split it up
54 action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key
55 return action;
56 } else if (keycode >= 0x2000 && keycode < 0x3000) {
57 // Is a shortcut for function layer, pull last 12bits
58 // This means we have 4,096 FN macros at our disposal
59 return keymap_func_to_action(keycode & 0xFFF);
60 } else if (keycode >= 0x3000 && keycode < 0x4000) {
61 // When the code starts with 3, it's an action macro.
62 action_t action;
63 action.code = ACTION_MACRO(keycode & 0xFF);
64 return action;
65#ifdef BACKLIGHT_ENABLE
66 } else if (keycode >= BL_0 && keycode <= BL_15) {
67 action_t action;
68 action.code = ACTION_BACKLIGHT_LEVEL(keycode & 0x000F);
69 return action;
70 } else if (keycode == BL_DEC) {
71 action_t action;
72 action.code = ACTION_BACKLIGHT_DECREASE();
73 return action;
74 } else if (keycode == BL_INC) {
75 action_t action;
76 action.code = ACTION_BACKLIGHT_INCREASE();
77 return action;
78 } else if (keycode == BL_TOGG) {
79 action_t action;
80 action.code = ACTION_BACKLIGHT_TOGGLE();
81 return action;
82 } else if (keycode == BL_STEP) {
83 action_t action;
84 action.code = ACTION_BACKLIGHT_STEP();
85 return action;
86#endif
87 } else if (keycode == RESET) { // RESET is 0x5000, which is why this is here
88 action_t action;
89 clear_keyboard();
90 #ifdef AUDIO_ENABLE
91 play_notes(&goodbye, 3, false);
92 #endif
93 _delay_ms(250);
94 #ifdef ATREUS_ASTAR
95 *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
96 #endif
97 bootloader_jump();
98 return action;
99 } else if (keycode == DEBUG) { // DEBUG is 0x5001
100 // TODO: Does this actually work?
101 action_t action;
102 print("\nDEBUG: enabled.\n");
103 debug_enable = true;
104 return action;
105 } else if (keycode >= 0x5000 && keycode < 0x6000) {
106 // Layer movement shortcuts
107 // See .h to see constraints/usage
108 int type = (keycode >> 0x8) & 0xF;
109 if (type == 0x1) {
110 // Layer set "GOTO"
111 int when = (keycode >> 0x4) & 0x3;
112 int layer = keycode & 0xF;
113 action_t action;
114 action.code = ACTION_LAYER_SET(layer, when);
115 return action;
116 } else if (type == 0x2) {
117 // Momentary layer
118 int layer = keycode & 0xFF;
119 action_t action;
120 action.code = ACTION_LAYER_MOMENTARY(layer);
121 return action;
122 } else if (type == 0x3) {
123 // Set default layer
124 int layer = keycode & 0xFF;
125 action_t action;
126 action.code = ACTION_DEFAULT_LAYER_SET(layer);
127 return action;
128 } else if (type == 0x4) {
129 // Set default layer
130 int layer = keycode & 0xFF;
131 action_t action;
132 action.code = ACTION_LAYER_TOGGLE(layer);
133 return action;
134 }
135#ifdef MIDI_ENABLE
136 } else if (keycode >= 0x6000 && keycode < 0x7000) {
137 action_t action;
138 action.code = ACTION_FUNCTION_OPT(keycode & 0xFF, (keycode & 0x0F00) >> 8);
139 return action;
140#endif
141 } else if (keycode >= 0x7000 && keycode < 0x8000) {
142 action_t action;
143 action.code = ACTION_MODS_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
144 return action;
145 } else if (keycode >= 0x8000 && keycode < 0x9000) {
146 action_t action;
147 action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
148 return action;
149#ifdef UNICODE_ENABLE
150 } else if (keycode >= 0x8000000) {
151 action_t action;
152 uint16_t unicode = keycode & ~(0x8000);
153 action.code = ACTION_FUNCTION_OPT(unicode & 0xFF, (unicode & 0xFF00) >> 8);
154 return action;
155#endif
156 } else {
157
158 }
159
160 switch (keycode) { 52 switch (keycode) {
161 case KC_FN0 ... KC_FN31: 53 case KC_FN0 ... KC_FN31:
162 return keymap_fn_to_action(keycode); 54 return keymap_fn_to_action(keycode);
163#ifdef BOOTMAGIC_ENABLE
164 case KC_CAPSLOCK: 55 case KC_CAPSLOCK:
165 case KC_LOCKING_CAPS: 56 case KC_LOCKING_CAPS:
166 if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) { 57 if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) {
@@ -224,7 +115,6 @@ action_t action_for_key(uint8_t layer, keypos_t key)
224 return keycode_to_action(KC_BSLASH); 115 return keycode_to_action(KC_BSLASH);
225 } 116 }
226 return keycode_to_action(KC_BSPACE); 117 return keycode_to_action(KC_BSPACE);
227#endif
228 default: 118 default:
229 return keycode_to_action(keycode); 119 return keycode_to_action(keycode);
230 } 120 }
@@ -265,6 +155,142 @@ static action_t keycode_to_action(uint16_t keycode)
265 case KC_TRNS: 155 case KC_TRNS:
266 action.code = ACTION_TRANSPARENT; 156 action.code = ACTION_TRANSPARENT;
267 break; 157 break;
158 case 0x0100 ... 0x1FFF: ;
159 // Has a modifier
160 // Split it up
161 action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key
162 break;
163 case 0x2000 ... 0x2FFF:
164 // Is a shortcut for function layer, pull last 12bits
165 // This means we have 4,096 FN macros at our disposal
166 return keymap_func_to_action(keycode & 0xFFF);
167 break;
168 case 0x3000 ... 0x3FFF: ;
169 // When the code starts with 3, it's an action macro.
170 action.code = ACTION_MACRO(keycode & 0xFF);
171 break;
172 #ifdef BACKLIGHT_ENABLE
173 case BL_0 ... BL_15:
174 action.code = ACTION_BACKLIGHT_LEVEL(keycode & 0x000F);
175 break;
176 case BL_DEC:
177 action.code = ACTION_BACKLIGHT_DECREASE();
178 break;
179 case BL_INC:
180 action.code = ACTION_BACKLIGHT_INCREASE();
181 break;
182 case BL_TOGG:
183 action.code = ACTION_BACKLIGHT_TOGGLE();
184 break;
185 case BL_STEP:
186 action.code = ACTION_BACKLIGHT_STEP();
187 break;
188 #endif
189 case RESET: ; // RESET is 0x5000, which is why this is here
190 clear_keyboard();
191 #ifdef AUDIO_ENABLE
192 play_notes(&goodbye, 3, false);
193 #endif
194 _delay_ms(250);
195 #ifdef ATREUS_ASTAR
196 *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
197 #endif
198 bootloader_jump();
199 break;
200 case DEBUG: ; // DEBUG is 0x5001
201 print("\nDEBUG: enabled.\n");
202 debug_enable = true;
203 break;
204 case 0x5002 ... 0x50FF:
205 // MAGIC actions (BOOTMAGIC without the boot)
206 if (!eeconfig_is_enabled()) {
207 eeconfig_init();
208 }
209 /* keymap config */
210 keymap_config.raw = eeconfig_read_keymap();
211 if (keycode == MAGIC_SWAP_CONTROL_CAPSLOCK) {
212 keymap_config.swap_control_capslock = 1;
213 } else if (keycode == MAGIC_CAPSLOCK_TO_CONTROL) {
214 keymap_config.capslock_to_control = 1;
215 } else if (keycode == MAGIC_SWAP_LALT_LGUI) {
216 keymap_config.swap_lalt_lgui = 1;
217 } else if (keycode == MAGIC_SWAP_RALT_RGUI) {
218 keymap_config.swap_ralt_rgui = 1;
219 } else if (keycode == MAGIC_NO_GUI) {
220 keymap_config.no_gui = 1;
221 } else if (keycode == MAGIC_SWAP_GRAVE_ESC) {
222 keymap_config.swap_grave_esc = 1;
223 } else if (keycode == MAGIC_SWAP_BACKSLASH_BACKSPACE) {
224 keymap_config.swap_backslash_backspace = 1;
225 } else if (keycode == MAGIC_HOST_NKRO) {
226 keymap_config.nkro = 1;
227 } else if (keycode == MAGIC_SWAP_ALT_GUI) {
228 keymap_config.swap_lalt_lgui = 1;
229 keymap_config.swap_ralt_rgui = 1;
230 }
231 /* UNs */
232 else if (keycode == MAGIC_UNSWAP_CONTROL_CAPSLOCK) {
233 keymap_config.swap_control_capslock = 0;
234 } else if (keycode == MAGIC_UNCAPSLOCK_TO_CONTROL) {
235 keymap_config.capslock_to_control = 0;
236 } else if (keycode == MAGIC_UNSWAP_LALT_LGUI) {
237 keymap_config.swap_lalt_lgui = 0;
238 } else if (keycode == MAGIC_UNSWAP_RALT_RGUI) {
239 keymap_config.swap_ralt_rgui = 0;
240 } else if (keycode == MAGIC_UNNO_GUI) {
241 keymap_config.no_gui = 0;
242 } else if (keycode == MAGIC_UNSWAP_GRAVE_ESC) {
243 keymap_config.swap_grave_esc = 0;
244 } else if (keycode == MAGIC_UNSWAP_BACKSLASH_BACKSPACE) {
245 keymap_config.swap_backslash_backspace = 0;
246 } else if (keycode == MAGIC_UNHOST_NKRO) {
247 keymap_config.nkro = 0;
248 } else if (keycode == MAGIC_UNSWAP_ALT_GUI) {
249 keymap_config.swap_lalt_lgui = 0;
250 keymap_config.swap_ralt_rgui = 0;
251 }
252 eeconfig_write_keymap(keymap_config.raw);
253 break;
254 case 0x5100 ... 0x5FFF: ;
255 // Layer movement shortcuts
256 // See .h to see constraints/usage
257 int type = (keycode >> 0x8) & 0xF;
258 if (type == 0x1) {
259 // Layer set "GOTO"
260 int when = (keycode >> 0x4) & 0x3;
261 int layer = keycode & 0xF;
262 action.code = ACTION_LAYER_SET(layer, when);
263 } else if (type == 0x2) {
264 // Momentary layer
265 int layer = keycode & 0xFF;
266 action.code = ACTION_LAYER_MOMENTARY(layer);
267 } else if (type == 0x3) {
268 // Set default layer
269 int layer = keycode & 0xFF;
270 action.code = ACTION_DEFAULT_LAYER_SET(layer);
271 } else if (type == 0x4) {
272 // Set default layer
273 int layer = keycode & 0xFF;
274 action.code = ACTION_LAYER_TOGGLE(layer);
275 }
276 break;
277 #ifdef MIDI_ENABLE
278 case 0x6000 ... 0x6FFF:
279 action.code = ACTION_FUNCTION_OPT(keycode & 0xFF, (keycode & 0x0F00) >> 8);
280 break;
281 #endif
282 case 0x7000 ... 0x7FFF:
283 action.code = ACTION_MODS_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
284 break;
285 case 0x8000 ... 0x8FFF:
286 action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
287 break;
288 #ifdef UNICODE_ENABLE
289 case 0x8000000 ... 0x8FFFFFF:
290 uint16_t unicode = keycode & ~(0x8000);
291 action.code = ACTION_FUNCTION_OPT(unicode & 0xFF, (unicode & 0xFF00) >> 8);
292 break;
293 #endif
268 default: 294 default:
269 action.code = ACTION_NO; 295 action.code = ACTION_NO;
270 break; 296 break;
diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h
index 7452a1ff3..ce87e4770 100644
--- a/quantum/keymap_common.h
+++ b/quantum/keymap_common.h
@@ -30,7 +30,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
30// #include "print.h" 30// #include "print.h"
31#include "debug.h" 31#include "debug.h"
32 32
33#ifdef BOOTMAGIC_ENABLE
34/* NOTE: Not portable. Bit field order depends on implementation */ 33/* NOTE: Not portable. Bit field order depends on implementation */
35typedef union { 34typedef union {
36 uint16_t raw; 35 uint16_t raw;
@@ -45,8 +44,6 @@ typedef union {
45 bool nkro:1; 44 bool nkro:1;
46 }; 45 };
47} keymap_config_t; 46} keymap_config_t;
48keymap_config_t keymap_config;
49#endif
50 47
51 48
52/* translates key to keycode */ 49/* translates key to keycode */
@@ -168,6 +165,30 @@ extern const uint16_t fn_actions[];
168#define RESET 0x5000 165#define RESET 0x5000
169#define DEBUG 0x5001 166#define DEBUG 0x5001
170 167
168// MAGIC keycodes
169#define MAGIC_SWAP_CONTROL_CAPSLOCK 0x5002
170#define MAGIC_UNSWAP_CONTROL_CAPSLOCK 0x5003
171#define MAGIC_CAPSLOCK_TO_CONTROL 0x5004
172#define MAGIC_UNCAPSLOCK_TO_CONTROL 0x5005
173#define MAGIC_SWAP_LALT_LGUI 0x5006
174#define MAGIC_UNSWAP_LALT_LGUI 0x5007
175#define MAGIC_SWAP_RALT_RGUI 0x5008
176#define MAGIC_UNSWAP_RALT_RGUI 0x5009
177#define MAGIC_NO_GUI 0x500a
178#define MAGIC_UNNO_GUI 0x500b
179#define MAGIC_SWAP_GRAVE_ESC 0x500c
180#define MAGIC_UNSWAP_GRAVE_ESC 0x500d
181#define MAGIC_SWAP_BACKSLASH_BACKSPACE 0x500e
182#define MAGIC_UNSWAP_BACKSLASH_BACKSPACE 0x500f
183#define MAGIC_HOST_NKRO 0x5010
184#define MAGIC_UNHOST_NKRO 0x5011
185#define MAGIC_SWAP_ALT_GUI 0x5012
186#define MAGIC_UNSWAP_ALT_GUI 0x5013
187
188#define AG_SWAP MAGIC_SWAP_ALT_GUI
189#define AG_NORM MAGIC_UNSWAP_ALT_GUI
190
191
171// GOTO layer - 16 layers max 192// GOTO layer - 16 layers max
172// when: 193// when:
173// ON_PRESS = 1 194// ON_PRESS = 1
@@ -213,4 +234,5 @@ void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
213#define IS_LAYER_ON(layer) ((layer_state) & (1UL<<(layer))) 234#define IS_LAYER_ON(layer) ((layer_state) & (1UL<<(layer)))
214#define IS_LAYER_OFF(layer) ((!layer_state) & (1UL<<(layer))) 235#define IS_LAYER_OFF(layer) ((!layer_state) & (1UL<<(layer)))
215 236
237
216#endif 238#endif
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index f8006c670..9cb2eb8ec 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -21,6 +21,9 @@ ifeq ($(strip $(BOOTMAGIC_ENABLE)), yes)
21 SRC += $(COMMON_DIR)/bootmagic.c 21 SRC += $(COMMON_DIR)/bootmagic.c
22 SRC += $(COMMON_DIR)/avr/eeconfig.c 22 SRC += $(COMMON_DIR)/avr/eeconfig.c
23 OPT_DEFS += -DBOOTMAGIC_ENABLE 23 OPT_DEFS += -DBOOTMAGIC_ENABLE
24else
25 SRC += $(COMMON_DIR)/magic.c
26 SRC += $(COMMON_DIR)/avr/eeconfig.c
24endif 27endif
25 28
26ifeq ($(strip $(MOUSEKEY_ENABLE)), yes) 29ifeq ($(strip $(MOUSEKEY_ENABLE)), yes)
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 302b3ec87..1d9981848 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -27,7 +27,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
27#include "command.h" 27#include "command.h"
28#include "util.h" 28#include "util.h"
29#include "sendchar.h" 29#include "sendchar.h"
30#include "bootmagic.h" 30#ifdef BOOTMAGIC_ENABLE
31 #include "bootmagic.h"
32#else
33 #include "magic.h"
34#endif
31#include "eeconfig.h" 35#include "eeconfig.h"
32#include "backlight.h" 36#include "backlight.h"
33#ifdef MOUSEKEY_ENABLE 37#ifdef MOUSEKEY_ENABLE
@@ -86,6 +90,8 @@ void keyboard_init(void)
86 90
87#ifdef BOOTMAGIC_ENABLE 91#ifdef BOOTMAGIC_ENABLE
88 bootmagic(); 92 bootmagic();
93#else
94 magic();
89#endif 95#endif
90 96
91#ifdef BACKLIGHT_ENABLE 97#ifdef BACKLIGHT_ENABLE
diff --git a/tmk_core/common/keymap.h b/tmk_core/common/keymap.h
index e1a6f992e..abc9bdb32 100644
--- a/tmk_core/common/keymap.h
+++ b/tmk_core/common/keymap.h
@@ -22,8 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
22#include <stdbool.h> 22#include <stdbool.h>
23#include "action.h" 23#include "action.h"
24 24
25
26#ifdef BOOTMAGIC_ENABLE
27/* NOTE: Not portable. Bit field order depends on implementation */ 25/* NOTE: Not portable. Bit field order depends on implementation */
28typedef union { 26typedef union {
29 uint8_t raw; 27 uint8_t raw;
@@ -39,7 +37,6 @@ typedef union {
39 }; 37 };
40} keymap_config_t; 38} keymap_config_t;
41keymap_config_t keymap_config; 39keymap_config_t keymap_config;
42#endif
43 40
44 41
45/* translates key to keycode */ 42/* translates key to keycode */
diff --git a/tmk_core/common/magic.c b/tmk_core/common/magic.c
new file mode 100644
index 000000000..f21d1346c
--- /dev/null
+++ b/tmk_core/common/magic.c
@@ -0,0 +1,36 @@
1#include <stdint.h>
2#include <stdbool.h>
3#include <util/delay.h>
4#include "matrix.h"
5#include "bootloader.h"
6#include "debug.h"
7#include "keymap.h"
8#include "host.h"
9#include "action_layer.h"
10#include "eeconfig.h"
11#include "magic.h"
12
13keymap_config_t keymap_config;
14
15void magic(void)
16{
17 /* check signature */
18 if (!eeconfig_is_enabled()) {
19 eeconfig_init();
20 }
21
22 /* debug enable */
23 debug_config.raw = eeconfig_read_debug();
24
25 /* keymap config */
26 keymap_config.raw = eeconfig_read_keymap();
27
28#ifdef NKRO_ENABLE
29 keyboard_nkro = keymap_config.nkro;
30#endif
31
32 uint8_t default_layer = 0;
33 default_layer = eeconfig_read_default_layer();
34 default_layer_set((uint32_t)default_layer);
35
36} \ No newline at end of file
diff --git a/tmk_core/common/magic.h b/tmk_core/common/magic.h
new file mode 100644
index 000000000..3fa2d8b81
--- /dev/null
+++ b/tmk_core/common/magic.h
@@ -0,0 +1,6 @@
1#ifndef MAGIC_H
2#define MAGIC_H
3
4void magic(void);
5
6#endif