|
| 1 | +/* Copyright 2021 Glorious, LLC <[email protected]> |
| 2 | + Copyright 2021 Andre Brait <[email protected]> |
| 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 | +#ifdef RGB_MATRIX_ENABLE |
| 21 | + #ifndef RGB_CONFIRMATION_BLINKING_TIME |
| 22 | + #define RGB_CONFIRMATION_BLINKING_TIME 2000 // 2 seconds |
| 23 | + #endif |
| 24 | + #if RGB_CONFIRMATION_BLINKING_TIME > 0 |
| 25 | + #include <lib/lib8tion/lib8tion.h> |
| 26 | + #endif // RGB_CONFIRMATION_BLINKING_TIME > 0 |
| 27 | +#endif // RGB_MATRIX_ENABLE |
| 28 | + |
| 29 | +// clang-format off |
| 30 | +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { |
| 31 | + |
| 32 | +// ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Del Rotary(Play/Pause) |
| 33 | +// ~ 1 2 3 4 5 6 7 8 9 0 - (=) BackSpc Home |
| 34 | +// Tab Q W E R T Y U I O P [ ] \ PgUp |
| 35 | +// Caps A S D F G H J K L ; " Enter PgDn |
| 36 | +// Sh_L Z X C V B N M , . ? Sh_R Up End |
| 37 | +// Ct_L Win_L Alt_L SPACE Alt_R FN Ct_R Left Down Right |
| 38 | + |
| 39 | + |
| 40 | + // The FN key by default maps to a momentary toggle to layer 1 to provide access to the RESET key (to put the board into bootloader mode). Without |
| 41 | + // this mapping, you have to open the case to hit the button on the bottom of the PCB (near the USB cable attachment) while plugging in the USB |
| 42 | + // cable to get the board into bootloader mode - definitely not fun when you're working on your QMK builds. Remove this and put it back to KC_RGUI |
| 43 | + // if that's your preference. |
| 44 | + // |
| 45 | + // To put the keyboard in bootloader mode, use FN+backslash. If you accidentally put it into bootloader, you can just unplug the USB cable and |
| 46 | + // it'll be back to normal when you plug it back in. |
| 47 | + // |
| 48 | + // This keyboard defaults to 6KRO instead of NKRO for compatibility reasons (some KVMs and BIOSes are incompatible with NKRO). |
| 49 | + // Since this is, among other things, a "gaming" keyboard, a key combination to enable NKRO on the fly is provided for convenience. |
| 50 | + // Press Fn+N to toggle between 6KRO and NKRO. This setting is persisted to the EEPROM and thus persists between restarts. |
| 51 | + [0] = LAYOUT( |
| 52 | + 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, |
| 53 | + 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, |
| 54 | + 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, |
| 55 | + 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, |
| 56 | + 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, KC_END, |
| 57 | + KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1), KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT |
| 58 | + ), |
| 59 | + |
| 60 | + [1] = LAYOUT( |
| 61 | + _______, KC_MYCM, KC_WHOM, KC_CALC, KC_MSEL, KC_MPRV, KC_MNXT, KC_MPLY, KC_MSTP, KC_MUTE, KC_VOLD, KC_VOLU, _______, KC_INS, _______, |
| 62 | + _______, RGB_TOG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_PSCR, |
| 63 | + _______, _______, RGB_VAI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RESET, _______, |
| 64 | + _______, _______, RGB_VAD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, |
| 65 | + _______, _______, RGB_HUI, _______, _______, _______, NK_TOGG, _______, _______, _______, _______, _______, RGB_MOD, _______, |
| 66 | + _______, _______, _______, _______, _______, _______, _______, RGB_SPD, RGB_RMOD, RGB_SPI |
| 67 | + ), |
| 68 | + |
| 69 | + |
| 70 | +}; |
| 71 | +// clang-format on |
| 72 | + |
| 73 | +#ifdef ENCODER_ENABLE |
| 74 | +bool encoder_update_user(uint8_t index, bool clockwise) { |
| 75 | + if (clockwise) { |
| 76 | + tap_code(KC_VOLU); |
| 77 | + } else { |
| 78 | + tap_code(KC_VOLD); |
| 79 | + } |
| 80 | + return true; |
| 81 | +} |
| 82 | +#endif // ENCODER_ENABLE |
| 83 | + |
| 84 | +#ifdef RGB_MATRIX_ENABLE |
| 85 | + |
| 86 | +static void set_rgb_caps_leds(void); |
| 87 | + |
| 88 | +#if RGB_CONFIRMATION_BLINKING_TIME > 0 |
| 89 | +static uint16_t effect_started_time = 0; |
| 90 | +static uint8_t r_effect = 0x0, g_effect = 0x0, b_effect = 0x0; |
| 91 | +static void start_effects(void); |
| 92 | + |
| 93 | +#define effect_red() r_effect = 0xFF, g_effect = 0x0, b_effect = 0x0 |
| 94 | +#define effect_green() r_effect = 0x0, g_effect = 0xFF, b_effect = 0x0 |
| 95 | +#endif // RGB_CONFIRMATION_BLINKING_TIME > 0 |
| 96 | + |
| 97 | +bool led_update_user(led_t led_state) { |
| 98 | + if (led_state.caps_lock) { |
| 99 | + if (!rgb_matrix_is_enabled()) { |
| 100 | + /* Turn ON the RGB Matrix for CAPS LOCK */ |
| 101 | + rgb_matrix_set_flags(LED_FLAG_NONE); |
| 102 | + rgb_matrix_enable(); |
| 103 | + } |
| 104 | + } else if (rgb_matrix_get_flags() == LED_FLAG_NONE) { |
| 105 | + /* RGB Matrix was only ON because of CAPS LOCK. Turn it OFF. */ |
| 106 | + rgb_matrix_set_flags(LED_FLAG_ALL); |
| 107 | + rgb_matrix_disable(); |
| 108 | + } |
| 109 | + return true; |
| 110 | +} |
| 111 | + |
| 112 | +bool process_record_user(uint16_t keycode, keyrecord_t *record) { |
| 113 | + switch (keycode) { |
| 114 | + #ifdef NKRO_ENABLE |
| 115 | + #if RGB_CONFIRMATION_BLINKING_TIME > 0 |
| 116 | + case NK_TOGG: |
| 117 | + if (record->event.pressed) { |
| 118 | + if (keymap_config.nkro) { |
| 119 | + /* Turning NKRO OFF */ |
| 120 | + effect_red(); |
| 121 | + } else { |
| 122 | + /* Turning NKRO ON */ |
| 123 | + effect_green(); |
| 124 | + } |
| 125 | + start_effects(); |
| 126 | + } |
| 127 | + break; |
| 128 | + case NK_ON: |
| 129 | + if (record->event.pressed) { |
| 130 | + if (!keymap_config.nkro) { |
| 131 | + /* Turning NKRO ON */ |
| 132 | + effect_green(); |
| 133 | + start_effects(); |
| 134 | + } |
| 135 | + } |
| 136 | + break; |
| 137 | + case NK_OFF: |
| 138 | + if (record->event.pressed) { |
| 139 | + if (keymap_config.nkro) { |
| 140 | + /* Turning NKRO OFF */ |
| 141 | + effect_red(); |
| 142 | + start_effects(); |
| 143 | + } |
| 144 | + } |
| 145 | + break; |
| 146 | + #endif // RGB_CONFIRMATION_BLINKING_TIME > 0 |
| 147 | + #endif // NKRO_ENABLE |
| 148 | + case RGB_MOD: |
| 149 | + case RGB_RMOD: |
| 150 | + case RGB_HUI: |
| 151 | + case RGB_HUD: |
| 152 | + case RGB_SAI: |
| 153 | + case RGB_SAD: |
| 154 | + case RGB_VAI: |
| 155 | + case RGB_VAD: |
| 156 | + case RGB_SPI: |
| 157 | + case RGB_SPD: |
| 158 | + if (record->event.pressed) { |
| 159 | + if (rgb_matrix_get_flags() != LED_FLAG_ALL) { |
| 160 | + /* Ignore changes to RGB settings while only it's supposed to be OFF */ |
| 161 | + return false; |
| 162 | + } |
| 163 | + } |
| 164 | + break; |
| 165 | + case RGB_TOG: |
| 166 | + if (record->event.pressed) { |
| 167 | + if (rgb_matrix_is_enabled()) { |
| 168 | + switch (rgb_matrix_get_flags()) { |
| 169 | + #if RGB_CONFIRMATION_BLINKING_TIME > 0 |
| 170 | + case LED_FLAG_INDICATOR: |
| 171 | + #endif |
| 172 | + case LED_FLAG_NONE: |
| 173 | + /* Turned ON because of EFFECTS or CAPS, is actually OFF */ |
| 174 | + /* Change to LED_FLAG_ALL to signal it's really ON */ |
| 175 | + rgb_matrix_set_flags(LED_FLAG_ALL); |
| 176 | + /* Will be re-enabled by the processing of the toggle */ |
| 177 | + rgb_matrix_disable_noeeprom(); |
| 178 | + break; |
| 179 | + case LED_FLAG_ALL: |
| 180 | + /* Is actually ON */ |
| 181 | + #if RGB_CONFIRMATION_BLINKING_TIME > 0 |
| 182 | + if (effect_started_time > 0) { |
| 183 | + /* Change to LED_FLAG_INDICATOR to signal EFFECTS */ |
| 184 | + rgb_matrix_set_flags(LED_FLAG_INDICATOR); |
| 185 | + /* Will be re-enabled by the processing of the toggle */ |
| 186 | + rgb_matrix_disable_noeeprom(); |
| 187 | + } else |
| 188 | + #endif |
| 189 | + if (host_keyboard_led_state().caps_lock) { |
| 190 | + /* Change to LED_FLAG_NONE to signal CAPS */ |
| 191 | + rgb_matrix_set_flags(LED_FLAG_NONE); |
| 192 | + /* Will be re-enabled by the processing of the toggle */ |
| 193 | + rgb_matrix_disable_noeeprom(); |
| 194 | + } |
| 195 | + break; |
| 196 | + } |
| 197 | + } |
| 198 | + } |
| 199 | + break; |
| 200 | + } |
| 201 | + return true; |
| 202 | +} |
| 203 | + |
| 204 | + |
| 205 | +void rgb_matrix_indicators_user() { |
| 206 | + #if RGB_CONFIRMATION_BLINKING_TIME > 0 |
| 207 | + if (effect_started_time != 0) { |
| 208 | + /* Render blinking EFFECTS */ |
| 209 | + uint16_t deltaTime = sync_timer_elapsed(effect_started_time); |
| 210 | + if (deltaTime <= RGB_CONFIRMATION_BLINKING_TIME) { |
| 211 | + uint16_t time = scale16by8(deltaTime, UINT8_MAX / 2); |
| 212 | + uint8_t led_state = sin8(time) >> 7; |
| 213 | + uint8_t val_r = led_state * r_effect; |
| 214 | + uint8_t val_g = led_state * g_effect; |
| 215 | + uint8_t val_b = led_state * b_effect; |
| 216 | + rgb_matrix_set_color_all(val_r, val_g, val_b); |
| 217 | + if (host_keyboard_led_state().caps_lock) { |
| 218 | + set_rgb_caps_leds(); |
| 219 | + } |
| 220 | + return; |
| 221 | + } else { |
| 222 | + /* EFFECTS duration is finished */ |
| 223 | + effect_started_time = 0; |
| 224 | + if (rgb_matrix_get_flags() == LED_FLAG_INDICATOR) { |
| 225 | + /* It was turned ON because of EFFECTS */ |
| 226 | + if (host_keyboard_led_state().caps_lock) { |
| 227 | + /* CAPS is still ON. Demote to CAPS */ |
| 228 | + rgb_matrix_set_flags(LED_FLAG_NONE); |
| 229 | + } else { |
| 230 | + /* There is nothing else keeping RGB enabled. Reset flags and turn if off. */ |
| 231 | + rgb_matrix_set_flags(LED_FLAG_ALL); |
| 232 | + rgb_matrix_disable_noeeprom(); |
| 233 | + } |
| 234 | + } |
| 235 | + } |
| 236 | + } |
| 237 | + #endif // RGB_CONFIRMATION_BLINKING_TIME > 0 |
| 238 | + if (rgb_matrix_get_flags() == LED_FLAG_NONE) { |
| 239 | + rgb_matrix_set_color_all(0x0, 0x0, 0x0); |
| 240 | + } |
| 241 | + if (host_keyboard_led_state().caps_lock) { |
| 242 | + set_rgb_caps_leds(); |
| 243 | + } |
| 244 | +} |
| 245 | + |
| 246 | +#if RGB_CONFIRMATION_BLINKING_TIME > 0 |
| 247 | +static void start_effects() { |
| 248 | + effect_started_time = sync_timer_read(); |
| 249 | + if (!rgb_matrix_is_enabled()) { |
| 250 | + /* Turn it ON, signal the cause (EFFECTS) */ |
| 251 | + rgb_matrix_set_flags(LED_FLAG_INDICATOR); |
| 252 | + rgb_matrix_enable_noeeprom(); |
| 253 | + } else if (rgb_matrix_get_flags() == LED_FLAG_NONE) { |
| 254 | + /* It's already ON, promote the cause from CAPS to EFFECTS */ |
| 255 | + rgb_matrix_set_flags(LED_FLAG_INDICATOR); |
| 256 | + } |
| 257 | +} |
| 258 | +#endif // RGB_CONFIRMATION_BLINKING_TIME > 0 |
| 259 | + |
| 260 | +static void set_rgb_caps_leds() { |
| 261 | + rgb_matrix_set_color(67, 0xFF, 0x0, 0x0); // Left side LED 1 |
| 262 | + rgb_matrix_set_color(68, 0xFF, 0x0, 0x0); // Right side LED 1 |
| 263 | + rgb_matrix_set_color(70, 0xFF, 0x0, 0x0); // Left side LED 2 |
| 264 | + rgb_matrix_set_color(71, 0xFF, 0x0, 0x0); // Right side LED 2 |
| 265 | + rgb_matrix_set_color(73, 0xFF, 0x0, 0x0); // Left side LED 3 |
| 266 | + rgb_matrix_set_color(74, 0xFF, 0x0, 0x0); // Right side LED 3 |
| 267 | + rgb_matrix_set_color(76, 0xFF, 0x0, 0x0); // Left side LED 4 |
| 268 | + rgb_matrix_set_color(77, 0xFF, 0x0, 0x0); // Right side LED 4 |
| 269 | + rgb_matrix_set_color(80, 0xFF, 0x0, 0x0); // Left side LED 5 |
| 270 | + rgb_matrix_set_color(81, 0xFF, 0x0, 0x0); // Right side LED 5 |
| 271 | + rgb_matrix_set_color(83, 0xFF, 0x0, 0x0); // Left side LED 6 |
| 272 | + rgb_matrix_set_color(84, 0xFF, 0x0, 0x0); // Right side LED 6 |
| 273 | + rgb_matrix_set_color(87, 0xFF, 0x0, 0x0); // Left side LED 7 |
| 274 | + rgb_matrix_set_color(88, 0xFF, 0x0, 0x0); // Right side LED 7 |
| 275 | + rgb_matrix_set_color(91, 0xFF, 0x0, 0x0); // Left side LED 8 |
| 276 | + rgb_matrix_set_color(92, 0xFF, 0x0, 0x0); // Right side LED 8 |
| 277 | + rgb_matrix_set_color(3, 0xFF, 0x0, 0x0); // CAPS LED |
| 278 | +} |
| 279 | + |
| 280 | +#endif // RGB_MATRIX_ENABLE |
0 commit comments