From 68a956118540c9736c3cdcfcd3cb0dda18a8ed27 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Wed, 4 Aug 2021 11:42:53 +0200 Subject: [PATCH 01/11] Added andrebrait layout for GMMK Pro --- .../gmmk/pro/ansi/keymaps/andrebrait/keymap.c | 171 ++++++++++++++++++ .../pro/ansi/keymaps/andrebrait/readme.md | 22 +++ 2 files changed, 193 insertions(+) create mode 100644 keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c create mode 100644 keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md diff --git a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c new file mode 100644 index 000000000000..a178c85d9dc2 --- /dev/null +++ b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c @@ -0,0 +1,171 @@ +/* Copyright 2021 Glorious, LLC + Copyright 2021 Andre Brait + +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 . +*/ + +#include QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + +// ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Del Rotary(Play/Pause) +// ~ 1 2 3 4 5 6 7 8 9 0 - (=) BackSpc Home +// Tab Q W E R T Y U I O P [ ] \ PgUp +// Caps A S D F G H J K L ; " Enter PgDn +// Sh_L Z X C V B N M , . ? Sh_R Up End +// Ct_L Win_L Alt_L SPACE Alt_R FN Ct_R Left Down Right + + + // 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 + // 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 + // 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 + // if that's your preference. + // + // 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 + // it'll be back to normal when you plug it back in. + // + // This keyboard defaults to 6KRO instead of NKRO for compatibility reasons (some KVMs and BIOSes are incompatible with NKRO). + // Since this is, among other things, a "gaming" keyboard, a key combination to enable NKRO on the fly is provided for convenience. + // Press Fn+N to toggle between 6KRO and NKRO. This setting is persisted to the EEPROM and thus persists between restarts. + [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_MPLY, + 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, KC_MUTE, + _______, RGB_TOG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_PSCR, + _______, _______, RGB_VAI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RESET, _______, + _______, _______, RGB_VAD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, RGB_HUI, _______, _______, _______, NK_TOGG, _______, _______, _______, _______, _______, RGB_MOD, _______, + _______, _______, _______, _______, _______, _______, _______, RGB_SPD, RGB_RMOD, RGB_SPI + ), + + +}; + + +bool encoder_update_user(uint8_t index, bool clockwise) { + if (clockwise) { + tap_code(KC_VOLU); + } else { + tap_code(KC_VOLD); + } + return true; +} + +#ifdef RGB_MATRIX_ENABLE +/* Flag to indicate that the RGB Matrix is only ON because we need it for CAPS LOCK */ +bool rgb_matrix_turned_on_by_caps = false; + +bool led_update_user(led_t led_state) { + if (led_state.caps_lock) { + if (!rgb_matrix_is_enabled()) { + /* Turn ON the RGB Matrix for CAPS LOCK */ + rgb_matrix_turned_on_by_caps = true; + rgb_matrix_enable_noeeprom(); + } + } else if (rgb_matrix_turned_on_by_caps) { + /* RGB Matrix was only ON because of CAPS LOCK. Turn it OFF. */ + rgb_matrix_turned_on_by_caps = false; + rgb_matrix_disable_noeeprom(); + } + return true; +} + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { + 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_turned_on_by_caps) { + /* + Prevent changes to the RGB Matrix settings while it's supposed to be OFF. + Returning true will also persist the current state to EEPROM and we don't want + that when the RGB Matrix is only ON because of CAPS LOCK. + */ + return false; + } + } + break; + case RGB_TOG: + if (record->event.pressed) { + if (rgb_matrix_is_enabled()) { + if (rgb_matrix_turned_on_by_caps) { + /* + Transitioning (fake) OFF -> (real) ON. + Persist current state to EEPROM (it's already ON) + */ + rgb_matrix_turned_on_by_caps = false; + eeconfig_update_rgb_matrix(); + return false; + } else if (host_keyboard_led_state().caps_lock) { + /* + Transitioning (real) ON -> (fake) OFF. + Persist OFF to EEPROM but keep it ON + */ + rgb_matrix_turned_on_by_caps = true; + rgb_matrix_disable_noeeprom(); + eeconfig_update_rgb_matrix(); + rgb_matrix_enable_noeeprom(); + return false; + } + } + } + break; + } + return true; +} + +void rgb_matrix_indicators_user(void) { + if (host_keyboard_led_state().caps_lock) { + if (rgb_matrix_turned_on_by_caps) { + /* + RGB Matrix is suppposed to be OFF. + Clear all LEDs before setting the ones for CAPS LOCK. + */ + rgb_matrix_set_color_all(RGB_OFF); + } + rgb_matrix_set_color(67, RGB_RED); // Left side LED 1 + rgb_matrix_set_color(68, RGB_RED); // Right side LED 1 + rgb_matrix_set_color(70, RGB_RED); // Left side LED 2 + rgb_matrix_set_color(71, RGB_RED); // Right side LED 2 + rgb_matrix_set_color(73, RGB_RED); // Left side LED 3 + rgb_matrix_set_color(74, RGB_RED); // Right side LED 3 + rgb_matrix_set_color(76, RGB_RED); // Left side LED 4 + rgb_matrix_set_color(77, RGB_RED); // Right side LED 4 + rgb_matrix_set_color(80, RGB_RED); // Left side LED 5 + rgb_matrix_set_color(81, RGB_RED); // Right side LED 5 + rgb_matrix_set_color(83, RGB_RED); // Left side LED 6 + rgb_matrix_set_color(84, RGB_RED); // Right side LED 6 + rgb_matrix_set_color(87, RGB_RED); // Left side LED 7 + rgb_matrix_set_color(88, RGB_RED); // Right side LED 7 + rgb_matrix_set_color(91, RGB_RED); // Left side LED 8 + rgb_matrix_set_color(92, RGB_RED); // Right side LED 8 + rgb_matrix_set_color(3, RGB_RED); // CAPS LED + } +} +#endif diff --git a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md new file mode 100644 index 000000000000..720d25ded737 --- /dev/null +++ b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md @@ -0,0 +1,22 @@ +# andrebrait's GMMK Pro layout + +This is pretty much the stock layout with a few things moved around. +It basically reflects my needs for both Delete and Insert being readily available for coding, as well as a full Home/PgUp/PgDwn/End column. + +The differences are as follows: + +- NKRO enabled by default +- Layer 0: + - Print Screen (default) -> Delete + - Delete (default) -> Home + - Rotary Knob press (default) -> Play/Pause +- Layer 1 (accessed by pressing Fn): + - Fn + Delete -> Insert + - Fn + Home -> Print Screen + - Fn + Rotary Knob press -> Mute + +This keymap also includes CAPS LOCK ON indicator.\ +All left and right side LEDs, and the Caps key LED will turn solid red while CAPS LOCK is ON. + +No other changes have been made. \ +The other keys on each layer have been kept intact. From e1f1611f036adca5bbdb62cc200cc9ea2774ecbb Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Tue, 10 Aug 2021 11:38:49 +0200 Subject: [PATCH 02/11] Use RGB Matrix flags to control state --- .../gmmk/pro/ansi/keymaps/andrebrait/keymap.c | 102 +++++++----------- 1 file changed, 37 insertions(+), 65 deletions(-) diff --git a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c index a178c85d9dc2..5f869ce777f5 100644 --- a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c +++ b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c @@ -70,22 +70,16 @@ bool encoder_update_user(uint8_t index, bool clockwise) { } #ifdef RGB_MATRIX_ENABLE -/* Flag to indicate that the RGB Matrix is only ON because we need it for CAPS LOCK */ -bool rgb_matrix_turned_on_by_caps = false; - -bool led_update_user(led_t led_state) { - if (led_state.caps_lock) { - if (!rgb_matrix_is_enabled()) { - /* Turn ON the RGB Matrix for CAPS LOCK */ - rgb_matrix_turned_on_by_caps = true; - rgb_matrix_enable_noeeprom(); - } - } else if (rgb_matrix_turned_on_by_caps) { - /* RGB Matrix was only ON because of CAPS LOCK. Turn it OFF. */ - rgb_matrix_turned_on_by_caps = false; - rgb_matrix_disable_noeeprom(); +void keyboard_post_init_user(void) { + /* + Custom handling of RGB_TOG means it is impossible to toggle the RGB Matrix on and off and we + need it to be enabled for the CAPS LOCK indicator to work, so enable it and then make sure it + gets persisted to the EEPROM. + */ + if (!rgb_matrix_is_enabled()) { + rgb_matrix_enable_noeeprom(); + eeconfig_update_rgb_matrix(); } - return true; } bool process_record_user(uint16_t keycode, keyrecord_t *record) { @@ -101,39 +95,21 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { case RGB_SPI: case RGB_SPD: if (record->event.pressed) { - if (rgb_matrix_turned_on_by_caps) { - /* - Prevent changes to the RGB Matrix settings while it's supposed to be OFF. - Returning true will also persist the current state to EEPROM and we don't want - that when the RGB Matrix is only ON because of CAPS LOCK. - */ + if (rgb_matrix_get_flags() == LED_FLAG_NONE) { + /* Ignore changes to RGB settings while only using it for CAPS LOCK */ return false; } } break; case RGB_TOG: if (record->event.pressed) { - if (rgb_matrix_is_enabled()) { - if (rgb_matrix_turned_on_by_caps) { - /* - Transitioning (fake) OFF -> (real) ON. - Persist current state to EEPROM (it's already ON) - */ - rgb_matrix_turned_on_by_caps = false; - eeconfig_update_rgb_matrix(); - return false; - } else if (host_keyboard_led_state().caps_lock) { - /* - Transitioning (real) ON -> (fake) OFF. - Persist OFF to EEPROM but keep it ON - */ - rgb_matrix_turned_on_by_caps = true; - rgb_matrix_disable_noeeprom(); - eeconfig_update_rgb_matrix(); - rgb_matrix_enable_noeeprom(); - return false; - } + if (rgb_matrix_get_flags() == LED_FLAG_ALL) { + rgb_matrix_set_flags(LED_FLAG_NONE); + } else { + rgb_matrix_set_flags(LED_FLAG_ALL); } + eeconfig_update_rgb_matrix(); + return false; } break; } @@ -141,31 +117,27 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { } void rgb_matrix_indicators_user(void) { + if (rgb_matrix_get_flags() == LED_FLAG_NONE) { + rgb_matrix_set_color_all(0x0, 0x0, 0x0); + } if (host_keyboard_led_state().caps_lock) { - if (rgb_matrix_turned_on_by_caps) { - /* - RGB Matrix is suppposed to be OFF. - Clear all LEDs before setting the ones for CAPS LOCK. - */ - rgb_matrix_set_color_all(RGB_OFF); - } - rgb_matrix_set_color(67, RGB_RED); // Left side LED 1 - rgb_matrix_set_color(68, RGB_RED); // Right side LED 1 - rgb_matrix_set_color(70, RGB_RED); // Left side LED 2 - rgb_matrix_set_color(71, RGB_RED); // Right side LED 2 - rgb_matrix_set_color(73, RGB_RED); // Left side LED 3 - rgb_matrix_set_color(74, RGB_RED); // Right side LED 3 - rgb_matrix_set_color(76, RGB_RED); // Left side LED 4 - rgb_matrix_set_color(77, RGB_RED); // Right side LED 4 - rgb_matrix_set_color(80, RGB_RED); // Left side LED 5 - rgb_matrix_set_color(81, RGB_RED); // Right side LED 5 - rgb_matrix_set_color(83, RGB_RED); // Left side LED 6 - rgb_matrix_set_color(84, RGB_RED); // Right side LED 6 - rgb_matrix_set_color(87, RGB_RED); // Left side LED 7 - rgb_matrix_set_color(88, RGB_RED); // Right side LED 7 - rgb_matrix_set_color(91, RGB_RED); // Left side LED 8 - rgb_matrix_set_color(92, RGB_RED); // Right side LED 8 - rgb_matrix_set_color(3, RGB_RED); // CAPS LED + rgb_matrix_set_color(67, 0xFF, 0x0, 0x0); // Left side LED 1 + rgb_matrix_set_color(68, 0xFF, 0x0, 0x0); // Right side LED 1 + rgb_matrix_set_color(70, 0xFF, 0x0, 0x0); // Left side LED 2 + rgb_matrix_set_color(71, 0xFF, 0x0, 0x0); // Right side LED 2 + rgb_matrix_set_color(73, 0xFF, 0x0, 0x0); // Left side LED 3 + rgb_matrix_set_color(74, 0xFF, 0x0, 0x0); // Right side LED 3 + rgb_matrix_set_color(76, 0xFF, 0x0, 0x0); // Left side LED 4 + rgb_matrix_set_color(77, 0xFF, 0x0, 0x0); // Right side LED 4 + rgb_matrix_set_color(80, 0xFF, 0x0, 0x0); // Left side LED 5 + rgb_matrix_set_color(81, 0xFF, 0x0, 0x0); // Right side LED 5 + rgb_matrix_set_color(83, 0xFF, 0x0, 0x0); // Left side LED 6 + rgb_matrix_set_color(84, 0xFF, 0x0, 0x0); // Right side LED 6 + rgb_matrix_set_color(87, 0xFF, 0x0, 0x0); // Left side LED 7 + rgb_matrix_set_color(88, 0xFF, 0x0, 0x0); // Right side LED 7 + rgb_matrix_set_color(91, 0xFF, 0x0, 0x0); // Left side LED 8 + rgb_matrix_set_color(92, 0xFF, 0x0, 0x0); // Right side LED 8 + rgb_matrix_set_color(3, 0xFF, 0x0, 0x0); // CAPS LED } } #endif From 0966838df2996694c0cfb0532a3c497b51e1ada1 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Tue, 10 Aug 2021 11:57:40 +0200 Subject: [PATCH 03/11] Revert changes to the Rotary Knob button --- keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c | 4 ++-- keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c index 5f869ce777f5..57eed584cbd9 100644 --- a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c +++ b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c @@ -39,7 +39,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // Since this is, among other things, a "gaming" keyboard, a key combination to enable NKRO on the fly is provided for convenience. // Press Fn+N to toggle between 6KRO and NKRO. This setting is persisted to the EEPROM and thus persists between restarts. [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_MPLY, + 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, @@ -48,7 +48,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ), [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, KC_MUTE, + _______, 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, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, diff --git a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md index 720d25ded737..ca64059f2bf5 100644 --- a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md +++ b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md @@ -9,11 +9,9 @@ The differences are as follows: - Layer 0: - Print Screen (default) -> Delete - Delete (default) -> Home - - Rotary Knob press (default) -> Play/Pause - Layer 1 (accessed by pressing Fn): - Fn + Delete -> Insert - Fn + Home -> Print Screen - - Fn + Rotary Knob press -> Mute This keymap also includes CAPS LOCK ON indicator.\ All left and right side LEDs, and the Caps key LED will turn solid red while CAPS LOCK is ON. From 221e5054de38d5f9b46bbeb625696bebac44e1f7 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Tue, 10 Aug 2021 15:49:20 +0200 Subject: [PATCH 04/11] Remove mentions of NKRO on the readme --- keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md | 1 - 1 file changed, 1 deletion(-) diff --git a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md index ca64059f2bf5..207e154ae01e 100644 --- a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md +++ b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md @@ -5,7 +5,6 @@ It basically reflects my needs for both Delete and Insert being readily availabl The differences are as follows: -- NKRO enabled by default - Layer 0: - Print Screen (default) -> Delete - Delete (default) -> Home From 55cc27a86ce299596f6fd98191c7b7f7e68e82c8 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Wed, 11 Aug 2021 15:22:49 +0200 Subject: [PATCH 05/11] Tweaks, cleaner caps implementation --- .../gmmk/pro/ansi/keymaps/andrebrait/config.h | 27 ++++++++++++++ .../gmmk/pro/ansi/keymaps/andrebrait/keymap.c | 35 +++++++++++-------- .../pro/ansi/keymaps/andrebrait/readme.md | 4 +++ .../gmmk/pro/ansi/keymaps/andrebrait/rules.mk | 3 ++ 4 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 keyboards/gmmk/pro/ansi/keymaps/andrebrait/config.h create mode 100644 keyboards/gmmk/pro/ansi/keymaps/andrebrait/rules.mk diff --git a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/config.h b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/config.h new file mode 100644 index 000000000000..3a831c77206f --- /dev/null +++ b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/config.h @@ -0,0 +1,27 @@ +/* Copyright 2021 Andre Brait + * + * 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 . + */ + +#pragma once + +#ifdef DEBOUNCE + #undef DEBOUNCE +#endif +#define DEBOUNCE 2 + +#ifdef RGB_MATRIX_ENABLE + #define RGB_DISABLE_TIMEOUT 1200000 // 20 minutes (20 * 60 * 1000ms) + #define RGB_DISABLE_WHEN_USB_SUSPENDED +#endif diff --git a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c index 57eed584cbd9..b7c469e99816 100644 --- a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c +++ b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c @@ -70,16 +70,19 @@ bool encoder_update_user(uint8_t index, bool clockwise) { } #ifdef RGB_MATRIX_ENABLE -void keyboard_post_init_user(void) { - /* - Custom handling of RGB_TOG means it is impossible to toggle the RGB Matrix on and off and we - need it to be enabled for the CAPS LOCK indicator to work, so enable it and then make sure it - gets persisted to the EEPROM. - */ - if (!rgb_matrix_is_enabled()) { - rgb_matrix_enable_noeeprom(); - eeconfig_update_rgb_matrix(); +bool led_update_user(led_t led_state) { + if (led_state.caps_lock) { + if (!rgb_matrix_is_enabled()) { + /* Turn ON the RGB Matrix for CAPS LOCK */ + rgb_matrix_set_flags(LED_FLAG_NONE); + rgb_matrix_enable(); + } + } else if (rgb_matrix_get_flags() == LED_FLAG_NONE) { + /* RGB Matrix was only ON because of CAPS LOCK. Turn it OFF. */ + rgb_matrix_set_flags(LED_FLAG_ALL); + rgb_matrix_disable(); } + return true; } bool process_record_user(uint16_t keycode, keyrecord_t *record) { @@ -103,13 +106,15 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { break; case RGB_TOG: if (record->event.pressed) { - if (rgb_matrix_get_flags() == LED_FLAG_ALL) { - rgb_matrix_set_flags(LED_FLAG_NONE); - } else { - rgb_matrix_set_flags(LED_FLAG_ALL); + if (host_keyboard_led_state().caps_lock) { + if (rgb_matrix_get_flags() == LED_FLAG_ALL) { + rgb_matrix_set_flags(LED_FLAG_NONE); + } else { + rgb_matrix_set_flags(LED_FLAG_ALL); + } + /* Disabling it here so it will be re-enabled by the processing of the toggle */ + rgb_matrix_disable_noeeprom(); } - eeconfig_update_rgb_matrix(); - return false; } break; } diff --git a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md index 207e154ae01e..156eccd51e2a 100644 --- a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md +++ b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md @@ -5,6 +5,10 @@ It basically reflects my needs for both Delete and Insert being readily availabl The differences are as follows: +- Shorter DEBOUNCE time (2 ms) +- Per-key debounce algorithm (sym_defer_pk) +- RGB turns off after 20 minutes of inactivity +- RGB turns off when USB is suspended - Layer 0: - Print Screen (default) -> Delete - Delete (default) -> Home diff --git a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/rules.mk b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/rules.mk new file mode 100644 index 000000000000..650c79fbdcc5 --- /dev/null +++ b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/rules.mk @@ -0,0 +1,3 @@ +# Enable additional features. + +DEBOUNCE_TYPE = sym_defer_pk From 3927fc0357e869440b8fb88b39865a9380642735 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Wed, 11 Aug 2021 17:28:40 +0200 Subject: [PATCH 06/11] Make debounce 5ms, fix keyboard not waking up --- keyboards/gmmk/pro/ansi/keymaps/andrebrait/config.h | 2 +- keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md | 2 +- keyboards/gmmk/pro/pro.c | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/config.h b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/config.h index 3a831c77206f..869e882629dd 100644 --- a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/config.h +++ b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/config.h @@ -19,7 +19,7 @@ #ifdef DEBOUNCE #undef DEBOUNCE #endif -#define DEBOUNCE 2 +#define DEBOUNCE 5 #ifdef RGB_MATRIX_ENABLE #define RGB_DISABLE_TIMEOUT 1200000 // 20 minutes (20 * 60 * 1000ms) diff --git a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md index 156eccd51e2a..e7f9978cee70 100644 --- a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md +++ b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/readme.md @@ -5,7 +5,7 @@ It basically reflects my needs for both Delete and Insert being readily availabl The differences are as follows: -- Shorter DEBOUNCE time (2 ms) +- Short DEBOUNCE time (5 ms) - Per-key debounce algorithm (sym_defer_pk) - RGB turns off after 20 minutes of inactivity - RGB turns off when USB is suspended diff --git a/keyboards/gmmk/pro/pro.c b/keyboards/gmmk/pro/pro.c index 816d089a585d..50d2f0e4fa1e 100644 --- a/keyboards/gmmk/pro/pro.c +++ b/keyboards/gmmk/pro/pro.c @@ -14,3 +14,15 @@ * along with this program. If not, see . */ #include "pro.h" + +#ifdef RGB_MATRIX_ENABLE +void suspend_power_down_kb(void) { + rgb_matrix_set_suspend_state(true); + suspend_power_down_user(); +} + + void suspend_wakeup_init_kb(void) { + rgb_matrix_set_suspend_state(false); + suspend_wakeup_init_user(); +} +#endif From 1dca346805598088dc7d2e77a12ed8575fa21f3c Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Wed, 11 Aug 2021 18:07:54 +0200 Subject: [PATCH 07/11] Add blinking indicator for NKRO toggle, cleanup --- .../gmmk/pro/ansi/keymaps/andrebrait/keymap.c | 168 +++++++++++++++--- 1 file changed, 142 insertions(+), 26 deletions(-) diff --git a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c index b7c469e99816..33e41088f1fe 100644 --- a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c +++ b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c @@ -17,6 +17,15 @@ along with this program. If not, see . #include QMK_KEYBOARD_H +#ifdef RGB_MATRIX_ENABLE + #ifndef RGB_CONFIRMATION_BLINKING_TIME + #define RGB_CONFIRMATION_BLINKING_TIME 2000 // 2 seconds + #endif + #if RGB_CONFIRMATION_BLINKING_TIME > 0 + #include + #endif // RGB_CONFIRMATION_BLINKING_TIME > 0 +#endif // RGB_MATRIX_ENABLE + const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Del Rotary(Play/Pause) @@ -70,6 +79,12 @@ bool encoder_update_user(uint8_t index, bool clockwise) { } #ifdef RGB_MATRIX_ENABLE + +#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; +#endif + bool led_update_user(led_t led_state) { if (led_state.caps_lock) { if (!rgb_matrix_is_enabled()) { @@ -87,6 +102,31 @@ bool led_update_user(led_t led_state) { bool process_record_user(uint16_t keycode, keyrecord_t *record) { switch (keycode) { + #ifdef NKRO_ENABLE + #if RGB_CONFIRMATION_BLINKING_TIME > 0 + case NK_TOGG: + /* For some reason we need to invert this */ + if (keymap_config.nkro) { + r_effect = 0x0, g_effect = 0xFF, b_effect = 0x0; + } else { + r_effect = 0xFF, g_effect = 0x0, b_effect = 0x0; + } + effect_started_time = sync_timer_read(); + break; + case NK_ON: + if (!keymap_config.nkro) { + r_effect = 0x0, g_effect = 0xFF, b_effect = 0x0; + effect_started_time = sync_timer_read(); + } + break; + case NK_OFF: + if (keymap_config.nkro) { + r_effect = 0xFF, g_effect = 0x0, b_effect = 0x0; + effect_started_time = sync_timer_read(); + } + break; + #endif + #endif case RGB_MOD: case RGB_RMOD: case RGB_HUI: @@ -98,51 +138,127 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { case RGB_SPI: case RGB_SPD: if (record->event.pressed) { - if (rgb_matrix_get_flags() == LED_FLAG_NONE) { - /* Ignore changes to RGB settings while only using it for CAPS LOCK */ + if (rgb_matrix_get_flags() != LED_FLAG_ALL) { + /* Ignore changes to RGB settings while only it's supposed to be OFF */ return false; } } break; case RGB_TOG: if (record->event.pressed) { - if (host_keyboard_led_state().caps_lock) { - if (rgb_matrix_get_flags() == LED_FLAG_ALL) { - rgb_matrix_set_flags(LED_FLAG_NONE); - } else { - rgb_matrix_set_flags(LED_FLAG_ALL); + if (rgb_matrix_is_enabled()) { + switch (rgb_matrix_get_flags()) { + #if RGB_CONFIRMATION_BLINKING_TIME > 0 + case LED_FLAG_INDICATOR: + #endif + case LED_FLAG_NONE: + /* Turned ON because of EFFECTS or CAPS, is actually OFF */ + /* Change to LED_FLAG_ALL to signal it's really ON */ + rgb_matrix_set_flags(LED_FLAG_ALL); + /* Will be re-enabled by the processing of the toggle */ + rgb_matrix_disable_noeeprom(); + return true; + case LED_FLAG_ALL: + /* Is actually ON */ + #if RGB_CONFIRMATION_BLINKING_TIME > 0 + if (effect_started_time > 0) { + /* Change to LED_FLAG_INDICATOR to signal EFFECTS */ + rgb_matrix_set_flags(LED_FLAG_INDICATOR); + /* Will be re-enabled by the processing of the toggle */ + rgb_matrix_disable_noeeprom(); + } else + #endif + if (host_keyboard_led_state().caps_lock) { + /* Change to LED_FLAG_NONE to signal CAPS */ + rgb_matrix_set_flags(LED_FLAG_NONE); + /* Will be re-enabled by the processing of the toggle */ + rgb_matrix_disable_noeeprom(); + } + return true; } - /* Disabling it here so it will be re-enabled by the processing of the toggle */ - rgb_matrix_disable_noeeprom(); + } else { + /* Is actually OFF, let the normal handling happen */ + return true; } } break; } + #if RGB_CONFIRMATION_BLINKING_TIME > 0 + if (effect_started_time > 0) { + if (!rgb_matrix_is_enabled()) { + /* Turn it ON, signal the cause (EFFECTS) */ + rgb_matrix_set_flags(LED_FLAG_INDICATOR); + rgb_matrix_enable_noeeprom(); + } else if (rgb_matrix_get_flags() == LED_FLAG_NONE) { + /* It's already ON, promote the cause from CAPS to EFFECTS */ + rgb_matrix_set_flags(LED_FLAG_INDICATOR); + } + } + #endif return true; } +static void set_rgb_caps_leds(void); + +static void set_rgb_caps_leds() { + rgb_matrix_set_color(67, 0xFF, 0x0, 0x0); // Left side LED 1 + rgb_matrix_set_color(68, 0xFF, 0x0, 0x0); // Right side LED 1 + rgb_matrix_set_color(70, 0xFF, 0x0, 0x0); // Left side LED 2 + rgb_matrix_set_color(71, 0xFF, 0x0, 0x0); // Right side LED 2 + rgb_matrix_set_color(73, 0xFF, 0x0, 0x0); // Left side LED 3 + rgb_matrix_set_color(74, 0xFF, 0x0, 0x0); // Right side LED 3 + rgb_matrix_set_color(76, 0xFF, 0x0, 0x0); // Left side LED 4 + rgb_matrix_set_color(77, 0xFF, 0x0, 0x0); // Right side LED 4 + rgb_matrix_set_color(80, 0xFF, 0x0, 0x0); // Left side LED 5 + rgb_matrix_set_color(81, 0xFF, 0x0, 0x0); // Right side LED 5 + rgb_matrix_set_color(83, 0xFF, 0x0, 0x0); // Left side LED 6 + rgb_matrix_set_color(84, 0xFF, 0x0, 0x0); // Right side LED 6 + rgb_matrix_set_color(87, 0xFF, 0x0, 0x0); // Left side LED 7 + rgb_matrix_set_color(88, 0xFF, 0x0, 0x0); // Right side LED 7 + rgb_matrix_set_color(91, 0xFF, 0x0, 0x0); // Left side LED 8 + rgb_matrix_set_color(92, 0xFF, 0x0, 0x0); // Right side LED 8 + rgb_matrix_set_color(3, 0xFF, 0x0, 0x0); // CAPS LED +} + void rgb_matrix_indicators_user(void) { + #if RGB_CONFIRMATION_BLINKING_TIME > 0 + if (effect_started_time != 0) { + /* Render blinking EFFECTS */ + uint16_t deltaTime = sync_timer_elapsed(effect_started_time); + if (deltaTime <= RGB_CONFIRMATION_BLINKING_TIME) { + uint16_t time = scale16by8(deltaTime, UINT8_MAX / 2); + uint8_t led_state = sin8(time) >> 7; + uint8_t val_r = led_state * r_effect; + uint8_t val_g = led_state * g_effect; + 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 { + /* EFFECTS duration is finished */ + effect_started_time = 0; + if (rgb_matrix_get_flags() == LED_FLAG_INDICATOR) { + /* It was turned ON because of EFFECTS */ + if (host_keyboard_led_state().caps_lock) { + /* CAPS is still ON. Demote to CAPS */ + rgb_matrix_set_flags(LED_FLAG_NONE); + } else { + /* There is nothing else keeping RGB enabled. Reset flags and turn if off. */ + rgb_matrix_set_flags(LED_FLAG_ALL); + rgb_matrix_disable_noeeprom(); + } + } + } + } + #endif if (rgb_matrix_get_flags() == LED_FLAG_NONE) { rgb_matrix_set_color_all(0x0, 0x0, 0x0); } if (host_keyboard_led_state().caps_lock) { - rgb_matrix_set_color(67, 0xFF, 0x0, 0x0); // Left side LED 1 - rgb_matrix_set_color(68, 0xFF, 0x0, 0x0); // Right side LED 1 - rgb_matrix_set_color(70, 0xFF, 0x0, 0x0); // Left side LED 2 - rgb_matrix_set_color(71, 0xFF, 0x0, 0x0); // Right side LED 2 - rgb_matrix_set_color(73, 0xFF, 0x0, 0x0); // Left side LED 3 - rgb_matrix_set_color(74, 0xFF, 0x0, 0x0); // Right side LED 3 - rgb_matrix_set_color(76, 0xFF, 0x0, 0x0); // Left side LED 4 - rgb_matrix_set_color(77, 0xFF, 0x0, 0x0); // Right side LED 4 - rgb_matrix_set_color(80, 0xFF, 0x0, 0x0); // Left side LED 5 - rgb_matrix_set_color(81, 0xFF, 0x0, 0x0); // Right side LED 5 - rgb_matrix_set_color(83, 0xFF, 0x0, 0x0); // Left side LED 6 - rgb_matrix_set_color(84, 0xFF, 0x0, 0x0); // Right side LED 6 - rgb_matrix_set_color(87, 0xFF, 0x0, 0x0); // Left side LED 7 - rgb_matrix_set_color(88, 0xFF, 0x0, 0x0); // Right side LED 7 - rgb_matrix_set_color(91, 0xFF, 0x0, 0x0); // Left side LED 8 - rgb_matrix_set_color(92, 0xFF, 0x0, 0x0); // Right side LED 8 - rgb_matrix_set_color(3, 0xFF, 0x0, 0x0); // CAPS LED + set_rgb_caps_leds(); } } + #endif From 8db2f21e169bcaac545c0e8b55fece7c97b66767 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Wed, 11 Aug 2021 22:12:15 +0200 Subject: [PATCH 08/11] Add required checks for NKRO toggle press --- .../gmmk/pro/ansi/keymaps/andrebrait/keymap.c | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c index 33e41088f1fe..f754f3da6876 100644 --- a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c +++ b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c @@ -80,6 +80,8 @@ bool encoder_update_user(uint8_t index, bool clockwise) { #ifdef RGB_MATRIX_ENABLE +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; @@ -105,24 +107,29 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { #ifdef NKRO_ENABLE #if RGB_CONFIRMATION_BLINKING_TIME > 0 case NK_TOGG: - /* For some reason we need to invert this */ - if (keymap_config.nkro) { - r_effect = 0x0, g_effect = 0xFF, b_effect = 0x0; - } else { - r_effect = 0xFF, g_effect = 0x0, b_effect = 0x0; + if (record->event.pressed) { + if (!keymap_config.nkro) { + r_effect = 0x0, g_effect = 0xFF, b_effect = 0x0; + } else { + r_effect = 0xFF, g_effect = 0x0, b_effect = 0x0; + } + effect_started_time = sync_timer_read(); } - effect_started_time = sync_timer_read(); break; case NK_ON: - if (!keymap_config.nkro) { - r_effect = 0x0, g_effect = 0xFF, b_effect = 0x0; - effect_started_time = sync_timer_read(); + if (record->event.pressed) { + if (!keymap_config.nkro) { + r_effect = 0x0, g_effect = 0xFF, b_effect = 0x0; + effect_started_time = sync_timer_read(); + } } break; case NK_OFF: - if (keymap_config.nkro) { - r_effect = 0xFF, g_effect = 0x0, b_effect = 0x0; - effect_started_time = sync_timer_read(); + if (record->event.pressed) { + if (keymap_config.nkro) { + r_effect = 0xFF, g_effect = 0x0, b_effect = 0x0; + effect_started_time = sync_timer_read(); + } } break; #endif @@ -198,8 +205,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { return true; } -static void set_rgb_caps_leds(void); - static void set_rgb_caps_leds() { rgb_matrix_set_color(67, 0xFF, 0x0, 0x0); // Left side LED 1 rgb_matrix_set_color(68, 0xFF, 0x0, 0x0); // Right side LED 1 From 7ce71800083613349a9f8a13e5f7ffd32a1fead2 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Thu, 12 Aug 2021 00:39:48 +0200 Subject: [PATCH 09/11] Cleanup and refactor some repeated code --- .../gmmk/pro/ansi/keymaps/andrebrait/config.h | 5 - .../gmmk/pro/ansi/keymaps/andrebrait/keymap.c | 113 ++++++++++-------- 2 files changed, 62 insertions(+), 56 deletions(-) diff --git a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/config.h b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/config.h index 869e882629dd..1438d317fbd2 100644 --- a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/config.h +++ b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/config.h @@ -16,11 +16,6 @@ #pragma once -#ifdef DEBOUNCE - #undef DEBOUNCE -#endif -#define DEBOUNCE 5 - #ifdef RGB_MATRIX_ENABLE #define RGB_DISABLE_TIMEOUT 1200000 // 20 minutes (20 * 60 * 1000ms) #define RGB_DISABLE_WHEN_USB_SUSPENDED diff --git a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c index f754f3da6876..febca3b97414 100644 --- a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c +++ b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c @@ -26,6 +26,7 @@ along with this program. If not, see . #endif // RGB_CONFIRMATION_BLINKING_TIME > 0 #endif // RGB_MATRIX_ENABLE +// clang-format off const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Del Rotary(Play/Pause) @@ -67,8 +68,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }; +// clang-format on - +#ifdef ENCODER_ENABLE bool encoder_update_user(uint8_t index, bool clockwise) { if (clockwise) { tap_code(KC_VOLU); @@ -77,6 +79,7 @@ bool encoder_update_user(uint8_t index, bool clockwise) { } return true; } +#endif // ENCODER_ENABLE #ifdef RGB_MATRIX_ENABLE @@ -85,7 +88,11 @@ 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; -#endif +static void start_effects(void); + +#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 // RGB_CONFIRMATION_BLINKING_TIME > 0 bool led_update_user(led_t led_state) { if (led_state.caps_lock) { @@ -108,32 +115,36 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { #if RGB_CONFIRMATION_BLINKING_TIME > 0 case NK_TOGG: if (record->event.pressed) { - if (!keymap_config.nkro) { - r_effect = 0x0, g_effect = 0xFF, b_effect = 0x0; + if (keymap_config.nkro) { + /* Turning NKRO OFF */ + effect_red(); } else { - r_effect = 0xFF, g_effect = 0x0, b_effect = 0x0; + /* Turning NKRO ON */ + effect_green(); } - effect_started_time = sync_timer_read(); + start_effects(); } break; case NK_ON: if (record->event.pressed) { if (!keymap_config.nkro) { - r_effect = 0x0, g_effect = 0xFF, b_effect = 0x0; - effect_started_time = sync_timer_read(); + /* Turning NKRO ON */ + effect_green(); + start_effects(); } } break; case NK_OFF: if (record->event.pressed) { if (keymap_config.nkro) { - r_effect = 0xFF, g_effect = 0x0, b_effect = 0x0; - effect_started_time = sync_timer_read(); + /* Turning NKRO OFF */ + effect_red(); + start_effects(); } } break; - #endif - #endif + #endif // RGB_CONFIRMATION_BLINKING_TIME > 0 + #endif // NKRO_ENABLE case RGB_MOD: case RGB_RMOD: case RGB_HUI: @@ -164,7 +175,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { rgb_matrix_set_flags(LED_FLAG_ALL); /* Will be re-enabled by the processing of the toggle */ rgb_matrix_disable_noeeprom(); - return true; + break; case LED_FLAG_ALL: /* Is actually ON */ #if RGB_CONFIRMATION_BLINKING_TIME > 0 @@ -181,51 +192,17 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { /* Will be re-enabled by the processing of the toggle */ rgb_matrix_disable_noeeprom(); } - return true; + break; } - } else { - /* Is actually OFF, let the normal handling happen */ - return true; } } break; } - #if RGB_CONFIRMATION_BLINKING_TIME > 0 - if (effect_started_time > 0) { - if (!rgb_matrix_is_enabled()) { - /* Turn it ON, signal the cause (EFFECTS) */ - rgb_matrix_set_flags(LED_FLAG_INDICATOR); - rgb_matrix_enable_noeeprom(); - } else if (rgb_matrix_get_flags() == LED_FLAG_NONE) { - /* It's already ON, promote the cause from CAPS to EFFECTS */ - rgb_matrix_set_flags(LED_FLAG_INDICATOR); - } - } - #endif return true; } -static void set_rgb_caps_leds() { - rgb_matrix_set_color(67, 0xFF, 0x0, 0x0); // Left side LED 1 - rgb_matrix_set_color(68, 0xFF, 0x0, 0x0); // Right side LED 1 - rgb_matrix_set_color(70, 0xFF, 0x0, 0x0); // Left side LED 2 - rgb_matrix_set_color(71, 0xFF, 0x0, 0x0); // Right side LED 2 - rgb_matrix_set_color(73, 0xFF, 0x0, 0x0); // Left side LED 3 - rgb_matrix_set_color(74, 0xFF, 0x0, 0x0); // Right side LED 3 - rgb_matrix_set_color(76, 0xFF, 0x0, 0x0); // Left side LED 4 - rgb_matrix_set_color(77, 0xFF, 0x0, 0x0); // Right side LED 4 - rgb_matrix_set_color(80, 0xFF, 0x0, 0x0); // Left side LED 5 - rgb_matrix_set_color(81, 0xFF, 0x0, 0x0); // Right side LED 5 - rgb_matrix_set_color(83, 0xFF, 0x0, 0x0); // Left side LED 6 - rgb_matrix_set_color(84, 0xFF, 0x0, 0x0); // Right side LED 6 - rgb_matrix_set_color(87, 0xFF, 0x0, 0x0); // Left side LED 7 - rgb_matrix_set_color(88, 0xFF, 0x0, 0x0); // Right side LED 7 - rgb_matrix_set_color(91, 0xFF, 0x0, 0x0); // Left side LED 8 - rgb_matrix_set_color(92, 0xFF, 0x0, 0x0); // Right side LED 8 - rgb_matrix_set_color(3, 0xFF, 0x0, 0x0); // CAPS LED -} -void rgb_matrix_indicators_user(void) { +void rgb_matrix_indicators_user() { #if RGB_CONFIRMATION_BLINKING_TIME > 0 if (effect_started_time != 0) { /* Render blinking EFFECTS */ @@ -257,7 +234,7 @@ void rgb_matrix_indicators_user(void) { } } } - #endif + #endif // RGB_CONFIRMATION_BLINKING_TIME > 0 if (rgb_matrix_get_flags() == LED_FLAG_NONE) { rgb_matrix_set_color_all(0x0, 0x0, 0x0); } @@ -266,4 +243,38 @@ void rgb_matrix_indicators_user(void) { } } -#endif +#if RGB_CONFIRMATION_BLINKING_TIME > 0 +static void start_effects() { + effect_started_time = sync_timer_read(); + if (!rgb_matrix_is_enabled()) { + /* Turn it ON, signal the cause (EFFECTS) */ + rgb_matrix_set_flags(LED_FLAG_INDICATOR); + rgb_matrix_enable_noeeprom(); + } else if (rgb_matrix_get_flags() == LED_FLAG_NONE) { + /* It's already ON, promote the cause from CAPS to EFFECTS */ + rgb_matrix_set_flags(LED_FLAG_INDICATOR); + } +} +#endif // RGB_CONFIRMATION_BLINKING_TIME > 0 + +static void set_rgb_caps_leds() { + rgb_matrix_set_color(67, 0xFF, 0x0, 0x0); // Left side LED 1 + rgb_matrix_set_color(68, 0xFF, 0x0, 0x0); // Right side LED 1 + rgb_matrix_set_color(70, 0xFF, 0x0, 0x0); // Left side LED 2 + rgb_matrix_set_color(71, 0xFF, 0x0, 0x0); // Right side LED 2 + rgb_matrix_set_color(73, 0xFF, 0x0, 0x0); // Left side LED 3 + rgb_matrix_set_color(74, 0xFF, 0x0, 0x0); // Right side LED 3 + rgb_matrix_set_color(76, 0xFF, 0x0, 0x0); // Left side LED 4 + rgb_matrix_set_color(77, 0xFF, 0x0, 0x0); // Right side LED 4 + rgb_matrix_set_color(80, 0xFF, 0x0, 0x0); // Left side LED 5 + rgb_matrix_set_color(81, 0xFF, 0x0, 0x0); // Right side LED 5 + rgb_matrix_set_color(83, 0xFF, 0x0, 0x0); // Left side LED 6 + rgb_matrix_set_color(84, 0xFF, 0x0, 0x0); // Right side LED 6 + rgb_matrix_set_color(87, 0xFF, 0x0, 0x0); // Left side LED 7 + rgb_matrix_set_color(88, 0xFF, 0x0, 0x0); // Right side LED 7 + rgb_matrix_set_color(91, 0xFF, 0x0, 0x0); // Left side LED 8 + rgb_matrix_set_color(92, 0xFF, 0x0, 0x0); // Right side LED 8 + rgb_matrix_set_color(3, 0xFF, 0x0, 0x0); // CAPS LED +} + +#endif // RGB_MATRIX_ENABLE From 9e6db4b0cfe07194d6fc5537e037a4853861b25e Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Thu, 12 Aug 2021 00:40:41 +0200 Subject: [PATCH 10/11] Only include encoder functions if ENABLE_ENCODER --- keyboards/gmmk/pro/ansi/keymaps/default/keymap.c | 5 ++++- keyboards/gmmk/pro/ansi/keymaps/via/keymap.c | 5 ++++- keyboards/gmmk/pro/iso/keymaps/default/keymap.c | 5 ++++- keyboards/gmmk/pro/iso/keymaps/via/keymap.c | 2 ++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/keyboards/gmmk/pro/ansi/keymaps/default/keymap.c b/keyboards/gmmk/pro/ansi/keymaps/default/keymap.c index c3ddc21c357f..65ccaf88f293 100644 --- a/keyboards/gmmk/pro/ansi/keymaps/default/keymap.c +++ b/keyboards/gmmk/pro/ansi/keymaps/default/keymap.c @@ -16,6 +16,7 @@ along with this program. If not, see . #include QMK_KEYBOARD_H +// clang-format off const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Prt Rotary(Mute) @@ -57,8 +58,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }; +// clang-format on - +#ifdef ENCODER_ENABLE bool encoder_update_user(uint8_t index, bool clockwise) { if (clockwise) { tap_code(KC_VOLU); @@ -67,3 +69,4 @@ bool encoder_update_user(uint8_t index, bool clockwise) { } return true; } +#endif // ENCODER_ENABLE diff --git a/keyboards/gmmk/pro/ansi/keymaps/via/keymap.c b/keyboards/gmmk/pro/ansi/keymaps/via/keymap.c index 8ffce0c21c8d..9b13f75a85f9 100644 --- a/keyboards/gmmk/pro/ansi/keymaps/via/keymap.c +++ b/keyboards/gmmk/pro/ansi/keymaps/via/keymap.c @@ -16,6 +16,7 @@ along with this program. If not, see . #include QMK_KEYBOARD_H +// clang-format off const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Prt Rotary(Mute) @@ -74,8 +75,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ), }; +// clang-format on - +#ifdef ENCODER_ENABLE bool encoder_update_user(uint8_t index, bool clockwise) { if (clockwise) { tap_code(KC_VOLU); @@ -84,3 +86,4 @@ bool encoder_update_user(uint8_t index, bool clockwise) { } return true; } +#endif // ENCODER_ENABLE diff --git a/keyboards/gmmk/pro/iso/keymaps/default/keymap.c b/keyboards/gmmk/pro/iso/keymaps/default/keymap.c index 123ae805d3da..5fd5f4f7fbd8 100644 --- a/keyboards/gmmk/pro/iso/keymaps/default/keymap.c +++ b/keyboards/gmmk/pro/iso/keymaps/default/keymap.c @@ -16,6 +16,7 @@ along with this program. If not, see . #include QMK_KEYBOARD_H +// clang-format off const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Prt Rotary(Mute) @@ -57,8 +58,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }; +// clang-format on - +#ifdef ENCODER_ENABLE bool encoder_update_user(uint8_t index, bool clockwise) { if (clockwise) { tap_code(KC_VOLU); @@ -67,3 +69,4 @@ bool encoder_update_user(uint8_t index, bool clockwise) { } return true; } +#endif ENCODER_ENABLE diff --git a/keyboards/gmmk/pro/iso/keymaps/via/keymap.c b/keyboards/gmmk/pro/iso/keymaps/via/keymap.c index 7dae95e4d91c..c83af17fe103 100644 --- a/keyboards/gmmk/pro/iso/keymaps/via/keymap.c +++ b/keyboards/gmmk/pro/iso/keymaps/via/keymap.c @@ -79,6 +79,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }; // clang-format on +#ifdef ENCODER_ENABLE bool encoder_update_user(uint8_t index, bool clockwise) { if (clockwise) { tap_code(KC_VOLU); @@ -87,3 +88,4 @@ bool encoder_update_user(uint8_t index, bool clockwise) { } return true; } +#endif // ENCODER_ENABLE From ab9b75cb56a3c27d3752984e290938e2238802df Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Thu, 12 Aug 2021 01:05:45 +0200 Subject: [PATCH 11/11] Revert changes to base keyboard code --- keyboards/gmmk/pro/pro.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/keyboards/gmmk/pro/pro.c b/keyboards/gmmk/pro/pro.c index 50d2f0e4fa1e..816d089a585d 100644 --- a/keyboards/gmmk/pro/pro.c +++ b/keyboards/gmmk/pro/pro.c @@ -14,15 +14,3 @@ * along with this program. If not, see . */ #include "pro.h" - -#ifdef RGB_MATRIX_ENABLE -void suspend_power_down_kb(void) { - rgb_matrix_set_suspend_state(true); - suspend_power_down_user(); -} - - void suspend_wakeup_init_kb(void) { - rgb_matrix_set_suspend_state(false); - suspend_wakeup_init_user(); -} -#endif