qmk_firmware

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

keymap.c (4762B)


      1 #include QMK_KEYBOARD_H
      2 #ifdef PROTOCOL_LUFA
      3 #include "lufa.h"
      4 #include "split_util.h"
      5 #endif
      6 
      7 extern keymap_config_t keymap_config;
      8 
      9 #ifdef RGBLIGHT_ENABLE
     10 //Following line allows macro to read current RGB settings
     11 extern rgblight_config_t rgblight_config;
     12 #endif
     13 
     14 extern uint8_t is_master;
     15 
     16 // Each layer gets a name for readability, which is then used in the keymap matrix below.
     17 // The underscores don't mean anything - you can have a layer called STUFF or any other name.
     18 // Layer names don't all need to be of the same length, obviously, and you can also skip them
     19 // entirely and just use numbers.
     20 enum layer_number {
     21     _QWERTY = 0,
     22     _MACROPAD,
     23     _FN,
     24     _ADJ
     25 };
     26 
     27 enum custom_keycodes {
     28   FN = SAFE_RANGE,
     29   ADJ,
     30   BACKLIT,
     31   RGBRST
     32 };
     33 
     34 enum macro_keycodes {
     35   KC_SAMPLEMACRO,
     36 };
     37 
     38 #define QWERT PDF(_QWERTY)
     39 #define MACROPAD PDF(_MACROPAD)
     40 
     41 #define FN_ESC  LT(_FN, KC_ESC)
     42 #define FN_CAPS  LT(_FN, KC_CAPS)
     43 // Define your non-alpha grouping in this define's LAYOUT, and all your BASE_LAYERS will share the same mod/macro columns
     44 
     45 #define BASE_LAYOUT( \
     46   _00, _01, _02, _03, _04, \
     47   _10, _11, _12, _13, _14, \
     48   _20, _21, _22, _23, _24, \
     49   _30, _31, _32, _33, _34 \
     50 ) \
     51 LAYOUT_ortho_5x6( \
     52       QK_GESC, _00,     _01,     _02,     _03,     _04, \
     53       KC_TAB,  _10,     _11,     _12,     _13,     _14, \
     54       FN_CAPS, _20,     _21,     _22,     _23,     _24, \
     55       KC_LSFT, _30,     _31,     _32,     _33,     _34, \
     56       KC_LCTL, KC_LGUI, KC_LALT, UG_TOGG, ADJ,  KC_SPC \
     57 )
     58 
     59 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
     60   [_QWERTY] = BASE_LAYOUT(
     61       KC_1,    KC_2,    KC_3,    KC_4,    KC_5,
     62       KC_Q,    KC_W,    KC_E,    KC_R,    KC_T,
     63       KC_A,    KC_S,    KC_D,    KC_F,    KC_G,
     64       KC_Z,    KC_X,    KC_C,    KC_V,    KC_B
     65   ),
     66 
     67   [_MACROPAD] = BASE_LAYOUT(
     68       KC_F13,    KC_F14,    KC_F15,    KC_F16,    KC_F17,
     69       KC_F18,    KC_F19,    KC_F20,    KC_F21,    KC_F22,
     70       KC_A,    KC_S,    KC_D,    KC_F,    KC_G,
     71       KC_Z,    KC_X,    KC_C,    KC_V,    KC_B
     72   ),
     73 
     74   [_FN] = LAYOUT_ortho_5x6(
     75       KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,
     76       _______, KC_PGDN, KC_UP,   KC_PGUP, _______, _______,
     77       _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______,
     78       _______, _______, _______, _______, _______, _______,
     79       _______, _______, _______, UG_NEXT, _______, _______
     80       ),
     81 
     82   [_ADJ] =  LAYOUT_ortho_5x6(
     83       KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,
     84       _______, UG_SATD, UG_VALU, UG_SATU, QK_BOOT, _______,
     85       _______, UG_HUED, UG_VALD, UG_HUEU, RGBRST,  _______,
     86       _______, _______, _______, _______, _______, _______,
     87       _______, _______, _______, UG_NEXT, _______, _______
     88       )
     89 };
     90 
     91 // define variables for reactive RGB
     92 bool TOG_STATUS = false;
     93 int RGB_current_mode;
     94 
     95 // Setting ADJ layer RGB back to default
     96 void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
     97   if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
     98     #ifdef RGBLIGHT_ENABLE
     99       //rgblight_mode(RGB_current_mode);
    100     #endif
    101     layer_on(layer3);
    102   } else {
    103     layer_off(layer3);
    104   }
    105 }
    106 
    107 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
    108   //uint8_t shifted = get_mods() & (MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT));
    109 
    110   switch (keycode) {
    111     case FN:
    112       if (record->event.pressed) {
    113         //not sure how to have keyboard check mode and set it to a variable, so my work around
    114         //uses another variable that would be set to true after the first time a reactive key is pressed.
    115         if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
    116         } else {
    117           TOG_STATUS = !TOG_STATUS;
    118           #ifdef RGBLIGHT_ENABLE
    119             //rgblight_mode(15);
    120           #endif
    121         }
    122         layer_on(_FN);
    123       } else {
    124         #ifdef RGBLIGHT_ENABLE
    125           //rgblight_mode(RGB_current_mode);  // revert RGB to initial mode prior to RGB mode change
    126         #endif
    127         layer_off(_FN);
    128         TOG_STATUS = false;
    129       }
    130       return false;
    131       break;
    132     case ADJ:
    133         if (record->event.pressed) {
    134           layer_on(_ADJ);
    135         } else {
    136           layer_off(_ADJ);
    137         }
    138         return false;
    139         break;
    140       //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
    141     case RGBRST:
    142       #ifdef RGBLIGHT_ENABLE
    143         if (record->event.pressed) {
    144           eeconfig_update_rgblight_default();
    145           rgblight_enable();
    146           RGB_current_mode = rgblight_config.mode;
    147         }
    148       #endif
    149       break;
    150   }
    151   return true;
    152 }
    153 
    154 void matrix_init_user(void) {
    155     #ifdef RGBLIGHT_ENABLE
    156       RGB_current_mode = rgblight_config.mode;
    157     #endif
    158 }