|
@@ -0,0 +1,307 @@
|
|
|
+
|
|
|
+ Copyright 2021 Andre Brait <andrebrait@gmail.com>
|
|
|
+
|
|
|
+This program is free software: you can redistribute it and/or modify
|
|
|
+it under the terms of the GNU General Public License as published by
|
|
|
+the Free Software Foundation, either version 2 of the License, or
|
|
|
+(at your option) any later version.
|
|
|
+
|
|
|
+This program is distributed in the hope that it will be useful,
|
|
|
+but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
+GNU General Public License for more details.
|
|
|
+
|
|
|
+You should have received a copy of the GNU General Public License
|
|
|
+along with this program. If not, see <http:
|
|
|
+*/
|
|
|
+
|
|
|
+#include QMK_KEYBOARD_H
|
|
|
+
|
|
|
+#ifdef RGB_MATRIX_ENABLE
|
|
|
+ #ifndef RGB_CONFIRMATION_BLINKING_TIME
|
|
|
+ #define RGB_CONFIRMATION_BLINKING_TIME 2000
|
|
|
+ #endif
|
|
|
+#endif
|
|
|
+
|
|
|
+
|
|
|
+const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [0] = LAYOUT(
|
|
|
+ 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,
|
|
|
+ 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,
|
|
|
+ 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,
|
|
|
+ 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,
|
|
|
+ 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,
|
|
|
+ KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1), KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT
|
|
|
+ ),
|
|
|
+
|
|
|
+ [1] = LAYOUT(
|
|
|
+ _______, KC_MYCM, KC_WHOM, KC_CALC, KC_MSEL, KC_MPRV, KC_MNXT, KC_MPLY, KC_MSTP, KC_MUTE, KC_VOLD, KC_VOLU, _______, KC_INS, _______,
|
|
|
+ _______, RGB_TOG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_PSCR,
|
|
|
+ _______, _______, RGB_VAI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RESET, _______,
|
|
|
+ _______, _______, RGB_VAD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
|
|
|
+ _______, _______, RGB_HUI, _______, _______, _______, NK_TOGG, _______, _______, _______, _______, _______, RGB_MOD, _______,
|
|
|
+ _______, _______, _______, _______, _______, _______, _______, RGB_SPD, RGB_RMOD, RGB_SPI
|
|
|
+ ),
|
|
|
+
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+const key_override_t up_key_override = ko_make_basic(MOD_MASK_CTRL, KC_UP, KC_PGUP);
|
|
|
+const key_override_t dn_key_override = ko_make_basic(MOD_MASK_CTRL, KC_DOWN, KC_PGDN);
|
|
|
+
|
|
|
+
|
|
|
+const key_override_t **key_overrides = (const key_override_t *[]){
|
|
|
+ &up_key_override,
|
|
|
+ &dn_key_override,
|
|
|
+ NULL
|
|
|
+};
|
|
|
+#ifdef ENCODER_ENABLE
|
|
|
+bool encoder_update_user(uint8_t index, bool clockwise) {
|
|
|
+ if (clockwise) {
|
|
|
+ tap_code(KC_VOLU);
|
|
|
+ } else {
|
|
|
+ tap_code(KC_VOLD);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
+#ifdef RGB_MATRIX_ENABLE
|
|
|
+
|
|
|
+
|
|
|
+#define LED_FLAG_CAPS LED_FLAG_NONE
|
|
|
+#define LED_FLAG_EFFECTS LED_FLAG_INDICATOR
|
|
|
+
|
|
|
+static void set_rgb_caps_leds(void);
|
|
|
+
|
|
|
+#if RGB_CONFIRMATION_BLINKING_TIME > 0
|
|
|
+static uint16_t effect_started_time = 0;
|
|
|
+static uint8_t r_effect = 0x0, g_effect = 0x0, b_effect = 0x0;
|
|
|
+static void start_effects(void);
|
|
|
+
|
|
|
+
|
|
|
+#ifndef TIME_SELECTED_BIT
|
|
|
+ #define TIME_SELECTED_BIT 8
|
|
|
+#endif
|
|
|
+#if TIME_SELECTED_BIT < 0 || TIME_SELECTED_BIT >= 16
|
|
|
+ #error "TIME_SELECTED_BIT must be a positive integer smaller than 16"
|
|
|
+#endif
|
|
|
+#define effect_red() r_effect = 0xFF, g_effect = 0x0, b_effect = 0x0
|
|
|
+#define effect_green() r_effect = 0x0, g_effect = 0xFF, b_effect = 0x0
|
|
|
+#endif
|
|
|
+
|
|
|
+bool led_update_user(led_t led_state) {
|
|
|
+ if (led_state.caps_lock) {
|
|
|
+ if (!rgb_matrix_is_enabled()) {
|
|
|
+
|
|
|
+ rgb_matrix_set_flags(LED_FLAG_CAPS);
|
|
|
+ rgb_matrix_enable();
|
|
|
+ }
|
|
|
+ } else if (rgb_matrix_get_flags() == LED_FLAG_CAPS) {
|
|
|
+
|
|
|
+ rgb_matrix_set_flags(LED_FLAG_ALL);
|
|
|
+ rgb_matrix_disable();
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
|
|
+ switch (keycode) {
|
|
|
+ #ifdef NKRO_ENABLE
|
|
|
+ #if RGB_CONFIRMATION_BLINKING_TIME > 0
|
|
|
+ case NK_TOGG:
|
|
|
+ if (record->event.pressed) {
|
|
|
+ if (keymap_config.nkro) {
|
|
|
+
|
|
|
+ effect_red();
|
|
|
+ } else {
|
|
|
+
|
|
|
+ effect_green();
|
|
|
+ }
|
|
|
+ start_effects();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case NK_ON:
|
|
|
+ if (record->event.pressed) {
|
|
|
+ if (!keymap_config.nkro) {
|
|
|
+
|
|
|
+ effect_green();
|
|
|
+ start_effects();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case NK_OFF:
|
|
|
+ if (record->event.pressed) {
|
|
|
+ if (keymap_config.nkro) {
|
|
|
+
|
|
|
+ effect_red();
|
|
|
+ start_effects();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ #endif
|
|
|
+ #endif
|
|
|
+ case RGB_MOD:
|
|
|
+ case RGB_RMOD:
|
|
|
+ case RGB_HUI:
|
|
|
+ case RGB_HUD:
|
|
|
+ case RGB_SAI:
|
|
|
+ case RGB_SAD:
|
|
|
+ case RGB_VAI:
|
|
|
+ case RGB_VAD:
|
|
|
+ case RGB_SPI:
|
|
|
+ case RGB_SPD:
|
|
|
+ if (record->event.pressed) {
|
|
|
+ if (rgb_matrix_get_flags() != LED_FLAG_ALL) {
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case RGB_TOG:
|
|
|
+ if (record->event.pressed) {
|
|
|
+ if (rgb_matrix_is_enabled()) {
|
|
|
+ switch (rgb_matrix_get_flags()) {
|
|
|
+ #if RGB_CONFIRMATION_BLINKING_TIME > 0
|
|
|
+ case LED_FLAG_EFFECTS:
|
|
|
+ #endif
|
|
|
+ case LED_FLAG_CAPS:
|
|
|
+
|
|
|
+
|
|
|
+ rgb_matrix_set_flags(LED_FLAG_ALL);
|
|
|
+
|
|
|
+ rgb_matrix_disable_noeeprom();
|
|
|
+ break;
|
|
|
+ case LED_FLAG_ALL:
|
|
|
+
|
|
|
+ #if RGB_CONFIRMATION_BLINKING_TIME > 0
|
|
|
+ if (effect_started_time > 0) {
|
|
|
+
|
|
|
+ rgb_matrix_set_flags(LED_FLAG_EFFECTS);
|
|
|
+
|
|
|
+ rgb_matrix_disable_noeeprom();
|
|
|
+ } else
|
|
|
+ #endif
|
|
|
+ if (host_keyboard_led_state().caps_lock) {
|
|
|
+
|
|
|
+ rgb_matrix_set_flags(LED_FLAG_CAPS);
|
|
|
+
|
|
|
+ rgb_matrix_disable_noeeprom();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void rgb_matrix_indicators_user() {
|
|
|
+ #if RGB_CONFIRMATION_BLINKING_TIME > 0
|
|
|
+ if (effect_started_time > 0) {
|
|
|
+
|
|
|
+ const uint16_t deltaTime = sync_timer_elapsed(effect_started_time);
|
|
|
+ if (deltaTime <= RGB_CONFIRMATION_BLINKING_TIME) {
|
|
|
+ const uint8_t led_state = ((~deltaTime) >> TIME_SELECTED_BIT) & 0x01;
|
|
|
+ const uint8_t val_r = led_state * r_effect;
|
|
|
+ const uint8_t val_g = led_state * g_effect;
|
|
|
+ const uint8_t val_b = led_state * b_effect;
|
|
|
+ rgb_matrix_set_color_all(val_r, val_g, val_b);
|
|
|
+ if (host_keyboard_led_state().caps_lock) {
|
|
|
+ set_rgb_caps_leds();
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+
|
|
|
+ effect_started_time = 0;
|
|
|
+ if (rgb_matrix_get_flags() == LED_FLAG_EFFECTS) {
|
|
|
+
|
|
|
+ if (host_keyboard_led_state().caps_lock) {
|
|
|
+
|
|
|
+ rgb_matrix_set_flags(LED_FLAG_CAPS);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ rgb_matrix_set_flags(LED_FLAG_ALL);
|
|
|
+ rgb_matrix_disable_noeeprom();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+ if (rgb_matrix_get_flags() == LED_FLAG_CAPS) {
|
|
|
+ rgb_matrix_set_color_all(0x0, 0x0, 0x0);
|
|
|
+ }
|
|
|
+ if (host_keyboard_led_state().caps_lock) {
|
|
|
+ set_rgb_caps_leds();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#if RGB_CONFIRMATION_BLINKING_TIME > 0
|
|
|
+static void start_effects() {
|
|
|
+ effect_started_time = sync_timer_read();
|
|
|
+ if (!rgb_matrix_is_enabled()) {
|
|
|
+
|
|
|
+ rgb_matrix_set_flags(LED_FLAG_EFFECTS);
|
|
|
+ rgb_matrix_enable_noeeprom();
|
|
|
+ } else if (rgb_matrix_get_flags() == LED_FLAG_CAPS) {
|
|
|
+
|
|
|
+ rgb_matrix_set_flags(LED_FLAG_EFFECTS);
|
|
|
+ }
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+static void set_rgb_caps_leds() {
|
|
|
+ rgb_matrix_set_color(67, 0xFF, 0x0, 0x0);
|
|
|
+ rgb_matrix_set_color(68, 0xFF, 0x0, 0x0);
|
|
|
+ rgb_matrix_set_color(70, 0xFF, 0x0, 0x0);
|
|
|
+ rgb_matrix_set_color(71, 0xFF, 0x0, 0x0);
|
|
|
+ rgb_matrix_set_color(73, 0xFF, 0x0, 0x0);
|
|
|
+ rgb_matrix_set_color(74, 0xFF, 0x0, 0x0);
|
|
|
+ rgb_matrix_set_color(76, 0xFF, 0x0, 0x0);
|
|
|
+ rgb_matrix_set_color(77, 0xFF, 0x0, 0x0);
|
|
|
+ rgb_matrix_set_color(80, 0xFF, 0x0, 0x0);
|
|
|
+ rgb_matrix_set_color(81, 0xFF, 0x0, 0x0);
|
|
|
+ rgb_matrix_set_color(83, 0xFF, 0x0, 0x0);
|
|
|
+ rgb_matrix_set_color(84, 0xFF, 0x0, 0x0);
|
|
|
+ rgb_matrix_set_color(87, 0xFF, 0x0, 0x0);
|
|
|
+ rgb_matrix_set_color(88, 0xFF, 0x0, 0x0);
|
|
|
+ rgb_matrix_set_color(91, 0xFF, 0x0, 0x0);
|
|
|
+ rgb_matrix_set_color(92, 0xFF, 0x0, 0x0);
|
|
|
+ rgb_matrix_set_color(3, 0xFF, 0x0, 0x0);
|
|
|
+}
|
|
|
+
|
|
|
+#endif
|