diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2016-04-16 18:51:58 -0400 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2016-04-16 18:51:58 -0400 |
| commit | ab19ebd08a8b955775e6fa94cdf6b8d128d8b43c (patch) | |
| tree | 7120e8037a1a9935b3b9e4109e251530f893c3b3 /quantum | |
| parent | 5f648b6c4060d586c343ea05562c607e2630dfc4 (diff) | |
| download | qmk_firmware-ab19ebd08a8b955775e6fa94cdf6b8d128d8b43c.tar.gz qmk_firmware-ab19ebd08a8b955775e6fa94cdf6b8d128d8b43c.zip | |
MAGIC functionality, AG swap in default layout
Diffstat (limited to 'quantum')
| -rw-r--r-- | quantum/keymap_common.c | 250 | ||||
| -rw-r--r-- | quantum/keymap_common.h | 28 |
2 files changed, 163 insertions, 115 deletions
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 | ||
| 30 | extern 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 */ |
| 35 | typedef union { | 34 | typedef 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; |
| 48 | keymap_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 |
