forked from qmk/qmk_firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom keymap with 8 layes and more advanced RGB things
- Loading branch information
Showing
10 changed files
with
368 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* Copyright 2022 @ Keychron (https://www.keychron.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://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
/* Set dynamic keymap layer counts */ | ||
#define DYNAMIC_KEYMAP_LAYER_COUNT 8 | ||
|
||
// Unicode config | ||
#define UNICODE_SELECTED_MODES UC_WINC | ||
|
||
/* RGB Matrix Configuration */ | ||
#ifdef RGB_MATRIX_ENABLE | ||
# define RGB_DISABLE_WHEN_USB_SUSPENDED | ||
# define RGB_MATRIX_KEYPRESSES | ||
# define RGB_MATRIX_FRAMEBUFFER_EFFECTS | ||
|
||
# define NUM_LOCK_ON_COLOR RGB_OFF | ||
# define NUM_LOCK_OFF_COLOR RGB_RED | ||
# define NUM_LOCK_INDICATOR_LIGHT_NUMS | ||
|
||
# define LAYER_1_COLOR RGB_OFF | ||
# define LAYER_2_COLOR RGB_YELLOW | ||
# define LAYER_3_COLOR RGB_GREEN | ||
# define LAYER_4_COLOR RGB_BLUE | ||
|
||
# define FN_LAYER_TRANSPARENT_KEYS_OFF | ||
#endif |
123 changes: 123 additions & 0 deletions
123
keyboards/keychron/q0/rev_0100/keymaps/fwest98/keymap.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* Copyright 2021 @ Keychron (https://www.keychron.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://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include QMK_KEYBOARD_H | ||
|
||
#include "keymap_setup.h" | ||
#ifdef RGB_MATRIX_ENABLE | ||
# include "rgb_matrix_user.h" | ||
#endif | ||
|
||
enum custom_keycodes { | ||
KC_DRGB = USER00 | ||
}; | ||
|
||
const uint32_t PROGMEM unicode_map[] = { | ||
}; | ||
|
||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
[BASE_1] = LAYOUT_numpad_6x4( | ||
MO(FN_1), KC_ESC, KC_BSPACE, KC_TAB, | ||
KC_NUMLOCK, KC_PSLS, KC_PAST, KC_PMNS, | ||
KC_P7, KC_P8, KC_P9, | ||
KC_P4, KC_P5, KC_P6, KC_PPLS, | ||
KC_P1, KC_P2, KC_P3, | ||
KC_P0, KC_PDOT, KC_PENT), | ||
|
||
[FN_1] = LAYOUT_numpad_6x4( | ||
KC_NO, TO(BASE_2), TO(BASE_3), TO(BASE_4), | ||
RGB_MOD, RGB_VAI, EE_CLR, QK_BOOT, | ||
RGB_RMOD, RGB_VAD, RGB_HUD, | ||
RGB_SAI, RGB_SPI, KC_MPRV, KC_DRGB, | ||
RGB_SAD, RGB_SPD, KC_MPLY, | ||
RGB_TOG, KC_MNXT, KC_TRNS), | ||
|
||
[BASE_2] = LAYOUT_numpad_6x4( | ||
KC_NO, MO(FN_2), KC_NO, KC_NO, | ||
KC_NO, KC_NO, KC_NO, KC_NO, | ||
KC_NO, KC_NO, KC_NO, | ||
KC_NO, KC_NO, KC_NO, KC_NO, | ||
KC_NO, KC_NO, KC_NO, | ||
KC_NO, KC_NO, KC_NO), | ||
|
||
[FN_2] = LAYOUT_numpad_6x4( | ||
TO(BASE_1), KC_TRNS, TO(BASE_3), TO(BASE_4), | ||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, | ||
KC_TRNS, KC_TRNS, KC_TRNS, | ||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, | ||
KC_TRNS, KC_TRNS, KC_TRNS, | ||
KC_TRNS, KC_TRNS, KC_TRNS), | ||
|
||
[BASE_3] = LAYOUT_numpad_6x4( | ||
KC_NO, KC_NO, MO(FN_3), KC_NO, | ||
KC_NO, KC_NO, KC_CALC, KC_NO, | ||
KC_NO, KC_NO, KC_NO, | ||
KC_NO, KC_NO, KC_NO, KC_NO, | ||
KC_NO, KC_NO, KC_NO, | ||
KC_NO, KC_NO, KC_NO), | ||
|
||
[FN_3] = LAYOUT_numpad_6x4( | ||
TO(BASE_1), TO(BASE_2), KC_TRNS, TO(BASE_4), | ||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, | ||
KC_TRNS, KC_TRNS, KC_TRNS, | ||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, | ||
KC_TRNS, KC_TRNS, KC_TRNS, | ||
KC_TRNS, KC_TRNS, KC_TRNS), | ||
|
||
[BASE_4] = LAYOUT_numpad_6x4( | ||
KC_NO, KC_NO, KC_NO, MO(FN_4), | ||
KC_NO, KC_NO, KC_NO, KC_NO, | ||
KC_NO, KC_NO, KC_NO, | ||
KC_NO, KC_NO, KC_NO, KC_NO, | ||
KC_NO, KC_NO, KC_NO, | ||
KC_NO, KC_NO, KC_NO), | ||
|
||
[FN_4] = LAYOUT_numpad_6x4( | ||
TO(BASE_1), TO(BASE_2), TO(BASE_3), KC_TRNS, | ||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, | ||
KC_TRNS, KC_TRNS, KC_TRNS, | ||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, | ||
KC_TRNS, KC_TRNS, KC_TRNS, | ||
KC_TRNS, KC_TRNS, KC_TRNS) | ||
}; | ||
|
||
void matrix_init_user(void) { | ||
# ifdef RGB_MATRIX_ENABLE | ||
rgb_matrix_init_user(); | ||
# endif | ||
} | ||
|
||
bool process_record_user(uint16_t keycode, keyrecord_t *record) { | ||
// Enable RGB on any keypress if currently disabled after hotkey | ||
static bool rgb_sleep = false; | ||
if(rgb_sleep && record->event.pressed) { | ||
rgb_matrix_enable_noeeprom(); | ||
rgb_sleep = false; | ||
} | ||
|
||
switch (keycode) { | ||
// Disable RGB on custom keycode | ||
case KC_DRGB: | ||
if (record->event.pressed && rgb_matrix_is_enabled()) { | ||
rgb_matrix_disable_noeeprom(); | ||
rgb_sleep = true; | ||
} | ||
return false; // no further processing of this custom key | ||
|
||
default: | ||
return true; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
keyboards/keychron/q0/rev_0100/keymaps/fwest98/keymap_setup.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* Copyright 2021 @ Grayson Carr | ||
* | ||
* 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://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
// clang-format off | ||
|
||
enum layers { | ||
BASE_1, | ||
FN_1, | ||
BASE_2, | ||
FN_2, | ||
BASE_3, | ||
FN_3, | ||
BASE_4, | ||
FN_4 | ||
}; | ||
|
||
// clang-format on |
132 changes: 132 additions & 0 deletions
132
keyboards/keychron/q0/rev_0100/keymaps/fwest98/rgb_matrix_user.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* Copyright 2021 @ Grayson Carr | ||
* | ||
* 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://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include QMK_KEYBOARD_H | ||
#include "keymap_setup.h" | ||
#include "rgb_matrix_user.h" | ||
|
||
keypos_t led_index_key_position[DRIVER_LED_TOTAL]; | ||
|
||
// Initialise RGB matrix; invert the mapping of g_led_config.matrix_co, | ||
// so instead of a mapping from key position to led index, we now create | ||
// led intex to key position. | ||
void rgb_matrix_init_user(void) { | ||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
for (uint8_t col = 0; col < MATRIX_COLS; col++) { | ||
uint8_t led_index = g_led_config.matrix_co[row][col]; | ||
if (led_index != NO_LED) { | ||
led_index_key_position[led_index] = (keypos_t){.row = row, .col = col}; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Callback by QMK for advanced indicators | ||
void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { | ||
uint8_t current_layer = get_highest_layer(layer_state); | ||
switch (current_layer) { | ||
case FN_1: | ||
#ifdef FN_LAYER_TRANSPARENT_KEYS_OFF | ||
rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, is_transparent, RGB_OFF); | ||
#endif | ||
// Fall-through for layer colours | ||
|
||
case BASE_1: | ||
#ifdef LAYER_1_COLOR // Layer-specific colour | ||
if (!rgb_color_is_transparent(LAYER_1_COLOR)) { | ||
rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, not_transparent, LAYER_1_COLOR); | ||
} | ||
#endif | ||
#ifdef NUM_LOCK_ON_COLOR // Custom colour when numlock is on | ||
if (!rgb_color_is_transparent(NUM_LOCK_ON_COLOR) && host_keyboard_led_state().num_lock) { | ||
rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, is_num_lock_indicator, NUM_LOCK_ON_COLOR); | ||
} | ||
#endif | ||
#ifdef NUM_LOCK_OFF_COLOR // Custom colour when numlock if off | ||
if (!rgb_color_is_transparent(NUM_LOCK_OFF_COLOR) && !host_keyboard_led_state().num_lock) { | ||
rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, is_num_lock_indicator, NUM_LOCK_OFF_COLOR); | ||
} | ||
#endif | ||
break; | ||
|
||
case FN_2: | ||
#ifdef FN_LAYER_TRANSPARENT_KEYS_OFF | ||
rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, is_transparent, RGB_OFF); | ||
#endif | ||
// Fall-through for layer colours | ||
|
||
case BASE_2: | ||
#ifdef LAYER_2_COLOR // Layer-specific colour | ||
if (!rgb_color_is_transparent(LAYER_2_COLOR)) { | ||
rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, not_transparent, LAYER_2_COLOR); | ||
} | ||
#endif | ||
break; | ||
|
||
case FN_3: | ||
#ifdef FN_LAYER_TRANSPARENT_KEYS_OFF | ||
rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, is_transparent, RGB_OFF); | ||
#endif | ||
// Fall-through for layer colours | ||
|
||
case BASE_3: | ||
#ifdef LAYER_3_COLOR // Layer-specific colour | ||
if (!rgb_color_is_transparent(LAYER_3_COLOR)) { | ||
rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, not_transparent, LAYER_3_COLOR); | ||
} | ||
#endif | ||
break; | ||
|
||
case FN_4: | ||
#ifdef FN_LAYER_TRANSPARENT_KEYS_OFF | ||
rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, is_transparent, RGB_OFF); | ||
#endif | ||
// Fall-through for layer colours | ||
|
||
case BASE_4: | ||
#ifdef LAYER_4_COLOR // Layer-specific colour | ||
if (!rgb_color_is_transparent(LAYER_4_COLOR)) { | ||
rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, not_transparent, LAYER_4_COLOR); | ||
} | ||
#endif | ||
break; | ||
} | ||
} | ||
|
||
void rgb_matrix_set_color_by_keycode(uint8_t led_min, uint8_t led_max, uint8_t layer, bool (*is_keycode)(uint16_t), uint8_t red, uint8_t green, uint8_t blue) { | ||
for (uint8_t i = led_min; i < led_max; i++) { | ||
uint16_t keycode = keymap_key_to_keycode(layer, led_index_key_position[i]); | ||
if ((*is_keycode)(keycode)) { | ||
rgb_matrix_set_color(i, red, green, blue); | ||
} | ||
} | ||
} | ||
|
||
bool rgb_color_is_transparent(uint8_t red, uint8_t green, uint8_t blue) { | ||
// We define "off"/"black" to be "transparent" aka we don't modify the colors | ||
return (red == 0 && green == 0 && blue == 0); | ||
} | ||
|
||
bool is_num_lock_indicator(uint16_t keycode) { | ||
#ifdef NUM_LOCK_INDICATOR_LIGHT_NUMS | ||
return (KC_P1 <= keycode && keycode <= KC_P0) || keycode == KC_NUMLOCK || keycode == KC_PDOT; | ||
#else | ||
return keycode == KC_NUMLOCK; | ||
#endif | ||
} | ||
|
||
bool is_transparent(uint16_t keycode) { return keycode == KC_TRNS; } | ||
bool not_transparent(uint16_t keycode) { return !is_transparent(keycode); } |
28 changes: 28 additions & 0 deletions
28
keyboards/keychron/q0/rev_0100/keymaps/fwest98/rgb_matrix_user.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* Copyright 2021 @ Grayson Carr | ||
* | ||
* 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://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#undef NUM_LOCK_LED_INDEX // Disable default numlock led behaviour | ||
|
||
void rgb_matrix_init_user(void); | ||
|
||
void rgb_matrix_set_color_by_keycode(uint8_t led_min, uint8_t led_max, uint8_t layer, bool (*is_keycode)(uint16_t), uint8_t red, uint8_t green, uint8_t blue); | ||
bool rgb_color_is_transparent(uint8_t red, uint8_t green, uint8_t blue); | ||
|
||
bool is_num_lock_indicator(uint16_t keycode); | ||
bool is_transparent(uint16_t keycode); | ||
bool not_transparent(uint16_t keycode); |
Oops, something went wrong.