qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

keymap.c (18523B)


      1 #include QMK_KEYBOARD_H
      2 
      3 //Following line allows macro to read current RGB settings
      4 extern rgblight_config_t rgblight_config;
      5 
      6 // Each layer gets a name for readability, which is then used in the keymap matrix below.
      7 // The underscores don't mean anything - you can have a layer called STUFF or any other name.
      8 // Layer names don't all need to be of the same length, obviously, and you can also skip them
      9 // entirely and just use numbers.
     10 #define _QWERTY 0
     11 #define _LOWER 1
     12 #define _RAISE 2
     13 #define _FNLAYER 3
     14 #define _NUMLAY 4
     15 #define _MOUSECURSOR 5
     16 #define _ADJUST 6
     17 
     18 enum preonic_keycodes {
     19   LOWER = SAFE_RANGE,
     20   RAISE,
     21   BACKLIT,
     22   RGBLED_TOGGLE,
     23   RGBLED_STEP_MODE,
     24   RGBLED_INCREASE_HUE,
     25   RGBLED_DECREASE_HUE,
     26   RGBLED_INCREASE_SAT,
     27   RGBLED_DECREASE_SAT,
     28   RGBLED_INCREASE_VAL,
     29   RGBLED_DECREASE_VAL,
     30   DEMOMACRO,
     31 };
     32 
     33 // Custom macros
     34 #define CTL_ESC     CTL_T(KC_ESC)               // Tap for Esc, hold for Ctrl
     35 #define CTL_TTAB    CTL_T(KC_TAB)               // Tap for Esc, hold for Ctrl
     36 #define CTL_ENT     CTL_T(KC_ENT)               // Tap for Enter, hold for Ctrl
     37 #define SFT_ENT     SFT_T(KC_ENT)               // Tap for Enter, hold for Shift
     38 // Requires KC_TRNS/_______ for the trigger key in the destination layer
     39 #define LT_FN(kc)   LT(_FNLAYER, kc)            // L-ayer T-ap Function Layer
     40 #define LT_MC(kc)   LT(_MOUSECURSOR, kc)        // L-ayer T-ap M-ouse C-ursor
     41 #define LT_RAI(kc)  LT(_RAISE, kc)              // L-ayer T-ap to Raise
     42 #define TG_NUMLAY   TG(_NUMLAY)                 //Toggle for layer _NUMLAY
     43 
     44 
     45 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
     46 
     47 /* Qwerty
     48  * ,------+------+------+------+------+------------------------------------------------.
     49  * |  Esc |   1  |   2  |   3  |   4  |   5  |   6  |   7  |   8  |   9  |   0  |   -  |
     50  * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
     51  * | Tab  |   Q  |   W  |   E  |   R  |   T  |   Y  |   U  |   I  |   O  |   P  | Bksp |   7  |   8  |   9  |
     52  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
     53  * | CAPS |   A  |   S  |   D  |   F  |   G  |   H  |   J  |   K  |   L  |   ;  |Enter |   4  |   5  |   6  |
     54  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
     55  * | Shift|   Z  |   X  |   C  |   V  |   B  |   N  |   M  |   ,  |   .  |   /  |   =  |   1  |   2  |   3  |
     56  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
     57  * |   ~  | Ctrl | Alt  | GUI  |Lower |Space |Space |Raise | RAlt | Ins  |  Del |NumLay|   0  |   .  |  ENT |
     58  * `--------------------------------------------------------------------------------------------------------'
     59  */
     60 [_QWERTY] = LAYOUT(
     61   KC_ESC,    KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,    KC_8,    KC_9,    KC_0,          KC_MINS,
     62   KC_TAB,    KC_Q,    KC_W,    KC_E,    KC_R,    KC_T,    KC_Y,    KC_U,    KC_I,    KC_O,    KC_P,           KC_BSPC,    KC_P7,   KC_P8,   KC_P9,
     63   KC_CAPS,   KC_A,    KC_S,    KC_D,    KC_F,    KC_G,    KC_H,    KC_J,    KC_K,    KC_L,    LT_MC(KC_SCLN), CTL_ENT,    KC_P4,   KC_P5,   KC_P6,
     64   KC_LSFT,   KC_Z,    KC_X,    KC_C,    KC_V,    KC_B,    KC_N,    KC_M,    KC_COMM, KC_DOT,  KC_SLSH,         KC_EQL,    KC_P1,   KC_P2,   KC_P3,
     65   KC_GRV,    KC_RCTL, KC_LALT, KC_LGUI, LOWER,   KC_SPC,  KC_SPC,  RAISE,   KC_RALT, KC_INS,  KC_DEL,       TG_NUMLAY,    KC_P0,   KC_PDOT, KC_PENT
     66 ),
     67 
     68 /* Lower
     69  * ,-----------------------------------------------------------------------------------.
     70  * |      |      |      |      |      |      |      |      |      |      |      |      |
     71  * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
     72  * |   1  |   2  |   3  |   4  |   5  |   6  |   7  |   8  |   9  |   0  |   ~  |  \   |      |      |      |
     73  * |------+------+------+------+------+-------------+------+------+------+------+------+------+------+------|
     74  * | CAPS |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |   _  |   +  |   {  |   }  |  |   |      |      |      |
     75  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
     76  * |      |  F7  |  F8  |  F9  |  F10 |  F11 |  F12 |ISO ~ |ISO | |   [  |   ]  |      |      |      |      |
     77  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
     78  * |      |      |      |      |      |      |      |      | Next | Vol- | Vol+ | Play |      |      |      |
     79  * `--------------------------------------------------------------------------------------------------------'
     80  */
     81 [_LOWER] = LAYOUT(
     82   KC_ESC,    KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,      KC_NO,      KC_NO,   KC_NO,   KC_NO,   KC_NO,
     83   KC_1,       KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,       KC_8,       KC_9,    KC_0,  KC_GRV, KC_BSLS, _______, _______, _______,
     84   KC_CAPS,   KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,    KC_UNDS,     KC_EQL, KC_LBRC, KC_RBRC, KC_PIPE, _______, _______, _______,
     85   _______,   KC_F7,   KC_F8,   KC_F9,  KC_F10,  KC_F11,  KC_F12, S(KC_NUHS), S(KC_NUBS), KC_LCBR, KC_RCBR, _______, _______, _______, _______,
     86   _______, _______, _______, _______, _______, _______, _______,    _______,    KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY, _______, _______, _______
     87 ),
     88 
     89 /* Raise
     90  * ,-----------------------------------------------------------------------------------.
     91  * |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |  F7  |  F8  |  F9  |  F10 |  F11 |  F12 |
     92  * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
     93  * |   1  |   2  |   3  |   4  |   5  |   6  |   7  |   8  |   9  |   0  |   ~  |  \   |      |      |      |
     94  * |------+------+------+------+------+-------------+------+------+------+------+------+------+------+------|
     95  * |      |   A  |  Up  |   D  | PrSc |      |   4  |   5  |   6  |   *  |   :  |  '   |      |      |      |
     96  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
     97  * |      |  Lt  |  Dn  |  Rt  | Mute |      |   1  |   2  |   3  |  Up  |   /  |      |      |      |      |
     98  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
     99  * |      |      |      |      |      |Space |   0  |      | Left | Down | Right|      |      |      |      |
    100  * `--------------------------------------------------------------------------------------------------------'
    101  */
    102 [_RAISE] = LAYOUT(
    103   KC_F1,    KC_F2,    KC_F3,    KC_F4,    KC_F5,   KC_F6, KC_F7,   KC_F8,      KC_F9,  KC_F10,   KC_F11,  KC_F12,
    104   KC_1,    KC_2,    KC_3,    KC_4,     KC_5,        KC_6,  KC_7,    KC_8,       KC_9,    KC_0,  KC_PLUS, KC_BSLS, _______, _______, _______,
    105   _______, KC_A,    KC_UP,   KC_D,     KC_PSCR,  _______,  KC_4,    KC_5,       KC_6, KC_PAST,  KC_COLN, KC_QUOT, _______, _______, _______,
    106   _______, KC_LEFT, KC_DOWN, KC_RIGHT, KC_MUTE,  _______,  KC_1,    KC_2,       KC_3,   KC_UP,  KC_SLSH, _______, _______, _______, _______,
    107   _______, _______, _______, _______,   _______,  KC_SPC,  KC_0,   _______,  KC_LEFT, KC_DOWN, KC_RIGHT, _______, _______, _______, _______
    108 ),
    109 
    110 /* FN layer on Esc key
    111  * ,-----------------------------------------------------------------------------------.
    112  * |      |      |      |      |      |      |      |      |      |      |      |      |
    113  * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
    114  * |      |   !  |   @  |   #  |   $  |   %  |   ^  |   &  |   *  |   (  |   )  |   +  |      |      |      |
    115  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
    116  * |      |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |   _  |   =  |   [  |   ]  |  '   |      |      |      |
    117  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
    118  * |      |  F7  |  F8  |  F9  |  F10 |  F11 |  F12 |ISO ~ |ISO | |   {  |   }  |      |      |      |      |
    119  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
    120  * |      |      |      |      |      |      |      |      | Next | Vol- | Vol+ | Play |      |      |      |
    121  * `--------------------------------------------------------------------------------------------------------'
    122  */
    123 [_FNLAYER] = LAYOUT(
    124   _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,   _______, _______,
    125   _______, KC_EXLM,   KC_AT, KC_HASH,  KC_DLR, KC_PERC, KC_CIRC,   KC_AMPR,    KC_ASTR, KC_LPRN, KC_RPRN, KC_PLUS, _______, _______, _______,
    126   _______,   KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_UNDS,     KC_EQL, KC_LBRC, KC_RBRC, KC_QUOT, _______, _______, _______,
    127   _______,   KC_F7,   KC_F8,   KC_F9,  KC_F10,  KC_F11,  KC_F12,S(KC_NUHS), S(KC_NUBS), KC_LCBR, KC_RCBR, _______, _______, _______, _______,
    128   _______, _______, _______, _______, _______, _______, _______,   _______,    KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY, _______, _______, _______
    129 ),
    130 
    131 /* Num Layer
    132  * ,-----------------------------------------------------------------------------------.
    133  * |      |      |      |      |      |      |      |      |      |      |      |      |
    134  * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
    135  * |      |      |      |      |      |      |      |      |      |      |      |      |  F7  |  F8  |  F9  |
    136  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
    137  * |      |      |      |      |      |      |      |      |      |      |      |      |  F4  |  F5  |  F6  |
    138  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
    139  * |      |      |      |      |      |      |      |      |      |      |      |      |      |  Up  |      |
    140  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
    141  * |      |      |      |      |      |      |      |      |      |      |      | Exit | Left | Down | Rght |
    142  * `--------------------------------------------------------------------------------------------------------'
    143  */
    144 [_NUMLAY] = LAYOUT(
    145   _______, _______, _______, _______, _______, _______,  _______, _______, _______, _______, _______, _______,
    146   _______, _______, _______, _______, _______, _______,  _______, _______, _______, _______, _______, _______, KC_INS,  KC_HOME,  KC_PGUP,
    147   _______, _______, _______, _______, _______, _______,  _______, _______, _______, _______, _______, _______, KC_DEL,   KC_END,  KC_PGDN,
    148   _______, _______, _______, _______, _______, _______,  _______, _______, _______, _______, _______, _______, KC_PMNS,    KC_UP,   KC_PPLS,
    149   _______, _______, _______, _______, _______, _______,  _______, _______, _______, _______, _______, _______, KC_LEFT, KC_DOWN, KC_RIGHT
    150 ),
    151 
    152 /* Mouse Layer (semi-col)
    153  * ,-----------------------------------------------------------------------------------.
    154  * |      |ACCL0| ACCL1| ACCL2 |      |      |      |      |      |      |      |      |
    155  * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
    156  * |      |      |      |      |      | Home | Wh_Up| WHL_L| M_Up | WHL_R|      |      |      |      |      |
    157  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
    158  * |      |      |      |      |      | End  | Wh_Dn| M_Lft| M_Dn | M_Rt |      |      |      |      |      |
    159  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
    160  * |      |      |      |      |      |      | BTN2 | BTN3 | BTN4 | BTN5 |      |      |      |      |      |
    161  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
    162  * |      |      |      |      |      | BTN1 |      |      |      | BTN1 |      |      |      |      |      |
    163  * `--------------------------------------------------------------------------------------------------------'
    164  */
    165 
    166 [_MOUSECURSOR] = LAYOUT(
    167   _______, MS_ACL0, MS_ACL1, MS_ACL2, _______, _______, _______, _______, _______, _______,   _______, _______,
    168   _______, _______, _______, _______, _______, KC_HOME, KC_PGUP, MS_WHLL, MS_UP,   MS_WHLR, DEMOMACRO, _______, _______, _______, _______,
    169   _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_END , KC_PGDN, MS_LEFT, MS_DOWN, MS_RGHT,   _______, _______, _______, _______, _______,
    170   _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______, MS_BTN2, MS_BTN3, MS_BTN4, MS_BTN5,   _______, _______, _______, _______, _______,
    171   _______, _______, _______, _______, _______, MS_BTN1, MS_BTN1, _______, _______, _______,   _______, _______, _______, _______, _______
    172 ),
    173 
    174 /* Adjust (Lower + Raise)
    175 
    176  * ,-----------------------------------------------------------------------------------.
    177  * | Reset|      |      |      |      |      |      |      |      | VolD | VolU | Mute |
    178  * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
    179  * |      |RGB TG|RGB ST|RGBH -|RGBH +|RGBS -|RGBS +|RGBV -|RGBV +|      |      |  Del |      |      |      |
    180  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
    181  * |      |      |      |Aud on|Audoff|AGnorm|AGswap|      |      |      |      |      |      |      |      |
    182  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
    183  * |      |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof|      | BL + |BL ST |BLSTEP| BL TG|      |      |      |
    184  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
    185  * |      |      |      |      |      |      |      |      |      |      |      |      |      |      |      |
    186  * `--------------------------------------------------------------------------------------------------------'
    187  */
    188 [_ADJUST] = LAYOUT(
    189   QK_BOOT,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO, KC_VOLD, KC_VOLU, KC_MUTE,
    190   _______, UG_TOGG, UG_NEXT, UG_HUEU, UG_HUED, UG_SATU, UG_SATD, UG_VALU, UG_VALD, _______, _______,  KC_DEL, _______, _______, _______,
    191   _______, _______, _______,   AU_ON,  AU_OFF, AG_NORM, AG_SWAP, _______, _______, _______, _______, _______, _______, _______, _______,
    192   _______, AU_PREV, AU_NEXT,   MU_ON,  MU_OFF,   MI_ON,  MI_OFF, _______, BL_DOWN, BL_UP,   BL_STEP, BL_TOGG, _______, _______, _______,
    193   _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
    194 )
    195 
    196 
    197 
    198 };
    199 
    200 // define variables for reactive RGB
    201 bool RGB_INIT = false;
    202 bool TOG_STATUS = false;
    203 bool NUMLAY_STATUS = false;
    204 int RGB_current_mode;
    205 
    206 
    207 void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
    208   if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
    209     rgblight_mode(RGB_current_mode);
    210     layer_on(layer3);
    211   } else {
    212     layer_off(layer3);
    213   }
    214 }
    215 
    216 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
    217   switch (keycode) {
    218     case LOWER:
    219       if (record->event.pressed) {
    220           //not sure how to have keyboard check mode and set it to a variable, so my work around
    221           //uses another variable that would be set to true after the first time a reactive key is pressed.
    222         if (RGB_INIT) {} else {
    223           RGB_current_mode = rgblight_config.mode;
    224           RGB_INIT = true;
    225         }
    226         if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
    227         } else {
    228           TOG_STATUS = !TOG_STATUS;
    229           rgblight_mode(16);
    230         }
    231         layer_on(_LOWER);
    232         update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
    233       } else {
    234         rgblight_mode(RGB_current_mode);   // revert RGB to initial mode prior to RGB mode change
    235         TOG_STATUS = false;
    236         layer_off(_LOWER);
    237         update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
    238       }
    239       return false;
    240       break;
    241     case RAISE:
    242       if (record->event.pressed) {
    243         //not sure how to have keyboard check mode and set it to a variable, so my work around
    244         //uses another variable that would be set to true after the first time a reactive key is pressed.
    245         if (RGB_INIT) {} else {
    246           RGB_current_mode = rgblight_config.mode;
    247           RGB_INIT = true;
    248         }
    249         if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
    250         } else {
    251           TOG_STATUS = !TOG_STATUS;
    252           rgblight_mode(15);
    253         }
    254         layer_on(_RAISE);
    255         update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
    256       } else {
    257         rgblight_mode(RGB_current_mode);  // revert RGB to initial mode prior to RGB mode change
    258         layer_off(_RAISE);
    259         TOG_STATUS = false;
    260         update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
    261       }
    262       return false;
    263       break;
    264     case BACKLIT:
    265       if (record->event.pressed) {
    266         register_code(KC_RSFT);
    267         #ifdef BACKLIGHT_ENABLE
    268           backlight_step();
    269         #endif
    270       } else {
    271         unregister_code(KC_RSFT);
    272       }
    273       return false;
    274       break;
    275       //my attempt for RGB layer lock indication via changing the mode, still have to figure out how to not have other keypress not override this mode
    276     case TG_NUMLAY:
    277       if (record->event.pressed) {
    278         if (RGB_INIT) {} else {
    279           RGB_current_mode = rgblight_config.mode;
    280           RGB_INIT = true;
    281         }
    282         NUMLAY_STATUS = !NUMLAY_STATUS;
    283         if (NUMLAY_STATUS) {
    284         rgblight_mode(4);
    285         layer_on(_NUMLAY);
    286         } else {
    287         rgblight_mode(RGB_current_mode);
    288         layer_off(_NUMLAY); }
    289       }
    290       return false;
    291       break;
    292     case QK_UNDERGLOW_MODE_NEXT:
    293       //led operations - RGB mode change now updates the RGB_current_mode to allow the right RGB mode to be set after reactive keys are released
    294       if (record->event.pressed) {
    295         rgblight_mode(RGB_current_mode);
    296         rgblight_step();
    297         RGB_current_mode = rgblight_config.mode;
    298       }
    299       return false;
    300       break;
    301     case DEMOMACRO:
    302       if (record->event.pressed) {
    303         SEND_STRING("hello world");
    304       }
    305       return false;
    306       break;
    307   }
    308   return true;
    309 }