]> git.donarmstrong.com Git - qmk_firmware.git/blobdiff - quantum/keymap_common.c
zweihander-osx: use eject instead of power
[qmk_firmware.git] / quantum / keymap_common.c
index 02d3c74be672ffb1fdcfd539112a206899084964..ba7269388bc749152d0846e7f3311cc0a46616f1 100644 (file)
@@ -24,8 +24,13 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "action_macro.h"
 #include "debug.h"
 #include "backlight.h"
-#include "keymap_midi.h"
 #include "bootloader.h"
+#include "eeconfig.h"
+#include "quantum.h"
+
+#ifdef MIDI_ENABLE
+       #include "keymap_midi.h"
+#endif
 
 extern keymap_config_t keymap_config;
 
@@ -33,22 +38,14 @@ extern keymap_config_t keymap_config;
 #include <inttypes.h>
 #ifdef AUDIO_ENABLE
     #include "audio.h"
-    #ifndef GOODBYE_TUNE
-    #define GOODBYE_TUNE { \
-        {440.0*pow(2.0,(31)/12.0), 8}, \
-        {440.0*pow(2.0,(24)/12.0), 8}, \
-        {440.0*pow(2.0,(19)/12.0), 12}, \
-    } 
-    #endif
-    float goodbye_tune[][2] = GOODBYE_TUNE;
-#endif
+#endif /* AUDIO_ENABLE */
 
 static action_t keycode_to_action(uint16_t keycode);
 
 /* converts key to action */
 action_t action_for_key(uint8_t layer, keypos_t key)
 {
-       // 16bit keycodes - important
+    // 16bit keycodes - important
     uint16_t keycode = keymap_key_to_keycode(layer, key);
 
     switch (keycode) {
@@ -157,20 +154,22 @@ static action_t keycode_to_action(uint16_t keycode)
         case KC_TRNS:
             action.code = ACTION_TRANSPARENT;
             break;
-        case 0x0100 ... 0x1FFF: ;
+        case LCTL(0) ... 0x1FFF: ;
             // Has a modifier
             // Split it up
             action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key
             break;
-        case 0x2000 ... 0x2FFF:
+        case FUNC(0) ... FUNC(0xFFF): ;
             // Is a shortcut for function layer, pull last 12bits
             // This means we have 4,096 FN macros at our disposal
             return keymap_func_to_action(keycode & 0xFFF);
             break;
-        case 0x3000 ... 0x3FFF: ;
-            // When the code starts with 3, it's an action macro.
+        case M(0) ... M(0xFF):
             action.code = ACTION_MACRO(keycode & 0xFF);
             break;
+        case LT(0, 0) ... LT(0xFF, 0xF):
+            action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
+            break;
     #ifdef BACKLIGHT_ENABLE
         case BL_0 ... BL_15:
             action.code = ACTION_BACKLIGHT_LEVEL(keycode & 0x000F);
@@ -191,7 +190,8 @@ static action_t keycode_to_action(uint16_t keycode)
         case RESET: ; // RESET is 0x5000, which is why this is here
             clear_keyboard();
             #ifdef AUDIO_ENABLE
-                PLAY_NOTE_ARRAY(goodbye_tune, false, 0);
+                stop_all_notes();
+                shutdown_user();
             #endif
             _delay_ms(250);
             #ifdef ATREUS_ASTAR
@@ -203,7 +203,7 @@ static action_t keycode_to_action(uint16_t keycode)
             print("\nDEBUG: enabled.\n");
             debug_enable = true;
             break;
-        case 0x5002 ... 0x50FF:
+        case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_UNSWAP_ALT_GUI:
             // MAGIC actions (BOOTMAGIC without the boot)
             if (!eeconfig_is_enabled()) {
                 eeconfig_init();
@@ -251,9 +251,9 @@ static action_t keycode_to_action(uint16_t keycode)
                 keymap_config.swap_lalt_lgui = 0;
                 keymap_config.swap_ralt_rgui = 0;
             }
-            eeconfig_write_keymap(keymap_config.raw);
+            eeconfig_update_keymap(keymap_config.raw);
             break;
-        case 0x5100 ... 0x5FFF: ;
+        case TO(0, 1) ... OSM(0xFF): ;
             // Layer movement shortcuts
             // See .h to see constraints/usage
             int type = (keycode >> 0x8) & 0xF;
@@ -274,25 +274,19 @@ static action_t keycode_to_action(uint16_t keycode)
                 // Set default layer
                 int layer = keycode & 0xFF;
                 action.code = ACTION_LAYER_TOGGLE(layer);
+            } else if (type == 0x5) {
+                // OSL(layer) - One-shot layer
+                int layer = keycode & 0xFF;
+                action.code = ACTION_LAYER_ONESHOT(layer);
+            } else if (type == 0x6) {
+                // OSM(mod) - One-shot mod
+                int mod = keycode & 0xFF;
+                action.code = ACTION_MODS_ONESHOT(mod);
             }
             break;
-    #ifdef MIDI_ENABLE
-        case 0x6000 ... 0x6FFF:
-            action.code =  ACTION_FUNCTION_OPT(keycode & 0xFF, (keycode & 0x0F00) >> 8);
-            break;
-    #endif
-        case 0x7000 ... 0x7FFF:
+        case MT(0, 0) ... MT(0xF, 0xFF):
             action.code = ACTION_MODS_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
             break;
-        case 0x8000 ... 0x8FFF:
-            action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
-            break;
-    #ifdef UNICODE_ENABLE
-        case 0x8000000 ... 0x8FFFFFF:
-            uint16_t unicode = keycode & ~(0x8000);
-            action.code =  ACTION_FUNCTION_OPT(unicode & 0xFF, (unicode & 0xFF00) >> 8);
-            break;
-    #endif
         default:
             action.code = ACTION_NO;
             break;
@@ -304,7 +298,7 @@ static action_t keycode_to_action(uint16_t keycode)
 /* translates key to keycode */
 uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
 {
-       // Read entire word (16bits)
+    // Read entire word (16bits)
     return pgm_read_word(&keymaps[(layer)][(key.row)][(key.col)]);
 }
 
@@ -316,7 +310,7 @@ action_t keymap_fn_to_action(uint16_t keycode)
 
 action_t keymap_func_to_action(uint16_t keycode)
 {
-       // For FUNC without 8bit limit
+    // For FUNC without 8bit limit
     return (action_t){ .code = pgm_read_word(&fn_actions[(int)keycode]) };
 }