keymap.c (9673B)
1 /* 2 Copyright 2021-2022 Alin M Elena <alinm.elena@gmail.com> 3 4 This program is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #include QMK_KEYBOARD_H 19 20 enum layer_names { 21 _QW = 0, 22 _LWR, 23 _RSE, 24 _ADJ 25 }; 26 27 #ifdef RGBLIGHT_ENABLE 28 29 const rgblight_segment_t PROGMEM my_qwerty_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLIGHT_LED_COUNT, HSV_PURPLE}); 30 const rgblight_segment_t PROGMEM my_lwr_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLIGHT_LED_COUNT, HSV_CYAN}); 31 const rgblight_segment_t PROGMEM my_rse_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLIGHT_LED_COUNT, HSV_RED}); 32 const rgblight_segment_t PROGMEM my_adj_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLIGHT_LED_COUNT, HSV_GREEN}); 33 34 const rgblight_segment_t* const PROGMEM my_rgb_layers[] = RGBLIGHT_LAYERS_LIST(my_qwerty_layer, my_lwr_layer, my_rse_layer, my_adj_layer); 35 #endif 36 37 #define LOWER TT(_LWR) 38 #define RAISE TT(_RSE) 39 40 // clang-format off 41 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 42 /* Qwerty 43 * ,-----------------------------------------------------------------------------------. 44 * | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp | 45 * |------+------+------+------+------+------+------+------+------+------+------+------| 46 * | Esc | A | S | D | F | G | H | J | K | L | ; | " | 47 * |------+------+------+------+------+------+------+------+------+------+------+------| 48 * | Shift| Z | X | C | V | B | N | M | , | . | / |Enter | 49 * |------+------+------+------+------+------+------+------+------+------+------+------| 50 * | | Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | 51 * `-----------------------------------------------------------------------------------' 52 */ 53 [_QW] = LAYOUT_ortho_4x12( 54 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, 55 KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, 56 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , 57 KC_TRNS,KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT 58 ), 59 60 /* Lower 61 * ,-----------------------------------------------------------------------------------. 62 * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp | 63 * |------+------+------+------+------+------+------+------+------+------+------+------| 64 * | Del | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | | 65 * |------+------+------+------+------+------+------+------+------+------+------+------| 66 * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | Home | End | | 67 * |------+------+------+------+------+------+------+------+------+------+------+------| 68 * | | | | | | | | Next | Vol- | Vol+ | Play | 69 * `-----------------------------------------------------------------------------------' 70 */ 71 [_LWR] = LAYOUT_ortho_4x12( 72 KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC, 73 KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, 74 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, S(KC_NUHS), S(KC_NUBS), KC_HOME, KC_END, _______, 75 _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY 76 ), 77 78 /* Raise 79 * ,-----------------------------------------------------------------------------------. 80 * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp | 81 * |------+------+------+------+------+------+------+------+------+------+------+------| 82 * | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ | 83 * |------+------+------+------+------+------+------+------+------+------+------+------| 84 * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / |Pg Up |Pg Dn | | 85 * |------+------+------+------+------+------+------+------+------+------+------+------| 86 * | | | | | | | | Next | Vol- | Vol+ | Play | 87 * `-----------------------------------------------------------------------------------' 88 */ 89 [_RSE] = LAYOUT_ortho_4x12( 90 KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, 91 KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, 92 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, KC_PGUP, KC_PGDN, _______, 93 _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY 94 ), 95 96 /* Adjust (Lower + Raise) 97 * v------------------------RGB CONTROL--------------------v 98 * ,-----------------------------------------------------------------------------------. 99 * | | Reset|Debug | RGB |RGBMOD| HUE+ | HUE- | SAT+ | SAT- |BRGTH+|BRGTH-| Del | 100 * |------+------+------+------+------+------+------+------+------+------+------+------| 101 * | | |MUSmod|Aud on|Audoff|AGnorm|AGswap| | | | | | 102 * |------+------+------+------+------+------+------+------+------+------+------+------| 103 * | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | | | | | 104 * |------+------+------+------+------+------+------+------+------+------+------+------| 105 * | | | | | | | | | | | | 106 * `-----------------------------------------------------------------------------------' 107 */ 108 [_ADJ] = LAYOUT_ortho_4x12( 109 _______, QK_BOOT, DB_TOGG, UG_TOGG, UG_NEXT, UG_HUEU, UG_HUED, UG_SATU, UG_SATD, UG_VALU, UG_VALD, KC_DEL, 110 _______, _______, MU_NEXT, AU_ON, AU_OFF, AG_NORM, AG_SWAP, _______, _______, _______, _______, _______, 111 _______, AU_PREV, AU_NEXT, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______, 112 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ 113 ) 114 115 }; 116 // clang-format on 117 118 // let us assume we start with both layers off 119 bool toggle_lwr = false; 120 bool toggle_rse = false; 121 122 bool led_update_user(led_t led_state) { 123 // Disable the default LED update code, so that lock LEDs could be reused to show layer status. 124 return false; 125 } 126 127 void matrix_scan_user(void) { 128 led_lwr(toggle_lwr); 129 led_rse(toggle_rse); 130 led_t led_state = host_keyboard_led_state(); 131 led_caps(led_state.caps_lock); 132 if (layer_state_is(_ADJ)) { 133 led_lwr(true); 134 led_rse(true); 135 } 136 } 137 138 bool process_record_user(uint16_t keycode, keyrecord_t* record) { 139 switch (keycode) { 140 case (TT(_LWR)): 141 if (!record->event.pressed && record->tap.count == TAPPING_TOGGLE) { 142 // This runs before the TT() handler toggles the layer state, so the current layer state is the opposite of the final one after toggle. 143 toggle_lwr = !layer_state_is(_LWR); 144 } 145 return true; 146 break; 147 case (TT(_RSE)): 148 if (record->event.pressed && record->tap.count == TAPPING_TOGGLE) { 149 toggle_rse = !layer_state_is(_RSE); 150 } 151 return true; 152 break; 153 default: 154 return true; 155 } 156 } 157 158 layer_state_t layer_state_set_user(layer_state_t state) { 159 #ifdef RGBLIGHT_ENABLE 160 161 rgblight_set_layer_state(0, layer_state_cmp(state, _QW)); 162 rgblight_set_layer_state(1, layer_state_cmp(state, _LWR)); 163 rgblight_set_layer_state(2, layer_state_cmp(state, _RSE)); 164 rgblight_set_layer_state(3, layer_state_cmp(state, _ADJ)); 165 166 #endif 167 return update_tri_layer_state(state, _LWR, _RSE, _ADJ); 168 } 169 170 #ifdef RGBLIGHT_ENABLE 171 172 layer_state_t default_layer_state_set_user(layer_state_t state) { 173 rgblight_set_layer_state(0, layer_state_cmp(state, _QW)); 174 return state; 175 } 176 177 void keyboard_post_init_user(void) { 178 // Enable the LED layers 179 rgblight_layers = my_rgb_layers; 180 } 181 #endif 182 183 #ifdef ENCODER_ENABLE 184 185 # define MEDIA_KEY_DELAY 10 186 187 static inline void my_encoders(const uint8_t index, const bool clockwise) { 188 if (index == 0) { /* First encoder */ 189 if (IS_LAYER_ON(_LWR)) { 190 if (clockwise) { 191 rgblight_decrease_val_noeeprom(); 192 } else { 193 rgblight_increase_val_noeeprom(); 194 } 195 } else if (IS_LAYER_ON(_RSE)) { 196 if (clockwise) { 197 rgblight_decrease_hue_noeeprom(); 198 } else { 199 rgblight_increase_hue_noeeprom(); 200 } 201 202 } else { 203 if (clockwise) { 204 tap_code_delay(KC_VOLD, MEDIA_KEY_DELAY); 205 } else { 206 tap_code_delay(KC_VOLU, MEDIA_KEY_DELAY); 207 } 208 } 209 } 210 } 211 212 bool encoder_update_user(uint8_t index, bool clockwise) { 213 my_encoders(index, clockwise); 214 return true; 215 } 216 #endif