keymap.c (12866B)
1 /* Copyright 2022 ML 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 2 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16 17 #include QMK_KEYBOARD_H 18 19 #include <string.h> 20 #include <math.h> 21 22 #include <lib/lib8tion/lib8tion.h> 23 24 // Each layer gets a name for readability, which is then used in the keymap matrix below. 25 // The underscores don't mean anything - you can have a layer called STUFF or any other name. 26 // Layer names don't all need to be of the same length, obviously, and you can also skip them 27 // entirely and just use numbers. 28 29 enum layer_names { 30 _BASE, 31 _FN, 32 }; 33 34 enum user_rgb_mode { 35 RGB_MODE_ALL, 36 RGB_MODE_NONE, 37 }; 38 39 typedef union { 40 uint32_t raw; 41 struct { 42 uint8_t rgb_mode :8; 43 }; 44 } user_config_t; 45 46 user_config_t user_config; 47 48 // enum layer_keycodes { }; 49 50 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 51 52 /* 53 ┌───┐┌───┬───┬───┬───┐┌───┬───┬───┬───┐┌───┬───┬───┬───┐┌───┐┌───┐ 54 │Esc││F1 │F2 │F3 │F4 ││F5 │F6 │F7 │F8 ││F9 │F10│F11│F12││Pse││Del│ 55 └───┘└───┴───┴───┴───┘└───┴───┴───┴───┘└───┴───┴───┴───┘└───┘└───┘ 56 ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐┌───┐ 57 │ ` │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 0 │ - │ = │ Bckspc││Del│ 58 ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤├───┤ 59 │ Tab │ q │ w │ e │ r │ t │ y │ u │ i │ o │ p │ [ │ ] │ \ ││PgU│ 60 ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤├───┤ 61 │ Caps │ a │ s │ d │ f │ g │ h │ j │ k │ l │ ; │ ' │ Enter ││PgD│ 62 ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────┬───┘└───┘ 63 │ LShift │ z │ x │ c │ v │ b │ n │ m │ , │ . │ / │ RSft │┌───┐ 64 ├────┬───┴┬──┴─┬─┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬─────┘│ ↑ │ 65 │LCrl│GUI │LAlt│ Space │RAlt│ Fn │ ┌───┼───┼───┐ 66 └────┴────┴────┴────────────────────────┴────┴────┘ │ ← │ ↓ │ → │ 67 └───┴───┴───┘ 68 ┌───┐┌───┬───┬───┬───┐┌───┬───┬───┬───┐┌───┬───┬───┬───┐┌───┐┌───┐ 69 │ ││ │ │ │ ││ │ │ │ ││ │ │ │ ││ ││ │ 70 └───┘└───┴───┴───┴───┘└───┴───┴───┴───┘└───┴───┴───┴───┘└───┘└───┘ 71 ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐┌───┐ 72 │ │ ! │ @ │ # │ $ │ % │ ^ │ & │ * │ ( │ ) │ _ │ + │ ~ │ ││ │ 73 ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴───┤├───┤ 74 │ │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │ { │ } │ | ││ │ 75 ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤├───┤ 76 │ Caps │ A │ S │ D │ F │ G │ H │ J │ K │ L │ : │ " │ ││ │ 77 ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────┬───┘└───┘ 78 │ LShift │ Z │ X │ C │ V │ B │ N │ M │ < │ > │ ? │ RSft │┌───┐ 79 ├────┬───┴┬──┴─┬─┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬─────┘│ │ 80 │ │ │ │ │ │ │ ┌───┼───┼───┐ 81 └────┴────┴────┴────────────────────────┴────┴────┘ │ │ │ │ 82 └───┴───┴───┘ 83 */ 84 /* Row: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 */ 85 [_BASE] = LAYOUT( 86 KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, KC_MUTE, 87 KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_HOME, 88 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGUP, 89 KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGDN, 90 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, 91 KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(_FN), KC_LEFT, KC_DOWN, KC_RIGHT 92 ), 93 94 /* 95 ┌───┐┌───┬───┬───┬───┐┌───┬───┬───┬───┐┌───┬───┬───┬───┐┌───┐┌───┐ 96 │Rst││ │ │ │ ││ │ │ │ ││ │ │ │ ││ ││Tog│ 97 └───┘└───┴───┴───┴───┘└───┴───┴───┴───┘└───┴───┴───┴───┘└───┘└───┘ 98 ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐┌───┐ 99 │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ││Hui│ 100 ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴───┤├───┤ 101 │ │ │ │ │ │ │ │ │ │ │ │ │ │ ││Hud│ 102 ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤├───┤ 103 │ │ │ │ │ │ │ │ │ │ │ │ │ ││ │ 104 ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────┬───┘└───┘ 105 │ │ │ │ │ │ │ │ │ │ │ │ │┌───┐ 106 ├────┬───┴┬──┴─┬─┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬─────┘│Vai│ 107 │ │ │ │ │ │ │ ┌───┼───┼───┐ 108 └────┴────┴────┴────────────────────────┴────┴────┘ │Spd│Vad│Spi│ 109 └───┴───┴───┘ 110 */ 111 /* Row: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 */ 112 [_FN] = LAYOUT( 113 QK_BOOT, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RM_TOGG, 114 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RM_HUEU, 115 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RM_HUED, 116 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, 117 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RM_VALU, 118 _______, _______, _______, _______, _______, _______, RM_SPDD, RM_VALD, RM_SPDU 119 ), 120 }; 121 122 void keyboard_post_init_user(void) { 123 user_config.raw = eeconfig_read_user(); 124 switch (user_config.rgb_mode) { 125 case RGB_MODE_ALL: 126 rgb_matrix_set_flags(LED_FLAG_ALL); 127 rgb_matrix_enable_noeeprom(); 128 break; 129 case RGB_MODE_NONE: 130 rgb_matrix_set_flags(LED_FLAG_NONE); 131 rgb_matrix_set_color_all(0, 0, 0); 132 break; 133 } 134 } 135 136 bool process_record_user(uint16_t keycode, keyrecord_t *record) { 137 switch (keycode) { 138 case QK_RGB_MATRIX_TOGGLE: 139 if (record->event.pressed) { 140 switch (rgb_matrix_get_flags()) { 141 case LED_FLAG_ALL: { 142 rgb_matrix_set_flags(LED_FLAG_NONE); 143 rgb_matrix_set_color_all(0, 0, 0); 144 user_config.rgb_mode = RGB_MODE_NONE; 145 } 146 break; 147 default: { 148 rgb_matrix_set_flags(LED_FLAG_ALL); 149 rgb_matrix_enable_noeeprom(); 150 user_config.rgb_mode = RGB_MODE_ALL; 151 } 152 break; 153 } 154 eeconfig_update_user(user_config.raw); 155 } 156 return false; 157 } 158 return true; 159 } 160 161 #ifdef ENCODER_MAP_ENABLE 162 const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { 163 [0] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) }, 164 [1] = { ENCODER_CCW_CW(RM_PREV, RM_NEXT) }, 165 }; 166 #endif 167 168 bool rgb_matrix_indicators_user(void) { 169 rgb_matrix_set_color(2, 0, 0, 0); 170 171 hsv_t hsv = rgb_matrix_config.hsv; 172 uint8_t time = scale16by8(g_rgb_timer, qadd8(32, 1)); 173 hsv.h = time; 174 rgb_t rgb = hsv_to_rgb(hsv); 175 176 if ((rgb_matrix_get_flags() & LED_FLAG_KEYLIGHT)) { 177 if (host_keyboard_led_state().caps_lock) { 178 rgb_matrix_set_color(2, rgb.r, rgb.g, rgb.b); 179 } 180 } else { 181 if (host_keyboard_led_state().caps_lock) { 182 rgb_matrix_set_color(2, rgb.r, rgb.g, rgb.b); 183 } else { 184 rgb_matrix_set_color(2, 0, 0, 0); 185 } 186 } 187 return false; 188 }