Skip to content

Commit

Permalink
Custom keymap with 8 layes and more advanced RGB things
Browse files Browse the repository at this point in the history
  • Loading branch information
FWest98 committed Jun 23, 2022
1 parent 45616cf commit 28c38e1
Show file tree
Hide file tree
Showing 10 changed files with 368 additions and 20 deletions.
2 changes: 1 addition & 1 deletion keyboards/keychron/q0/rev_0100/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
#define DRIVER_LED_TOTAL DRIVER_1_LED_TOTAL

/* Enable num-lock LED */
#define NUM_LOCK_LED_INDEX 4
// #define NUM_LOCK_LED_INDEX 4
17 changes: 0 additions & 17 deletions keyboards/keychron/q0/rev_0100/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

#include QMK_KEYBOARD_H
#include "test.h"

enum layers { _BASE, _FN1, _RESERVED1, _RESERVED2 };

Expand Down Expand Up @@ -52,19 +51,3 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS)
};

void matrix_scan_user(void) {
/* Set timers for factory reset and backlight test */
timer_task_start();
}

bool dip_switch_update_user(uint8_t index, bool active) {
/* Send default layer state to host */
system_switch_state_report(index, active);
return true;
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
process_other_record(keycode, record);
return true; // Process all other keycodes normally
}
41 changes: 41 additions & 0 deletions keyboards/keychron/q0/rev_0100/keymaps/fwest98/config.h
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 keyboards/keychron/q0/rev_0100/keymaps/fwest98/keymap.c
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 keyboards/keychron/q0/rev_0100/keymaps/fwest98/keymap_setup.h
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 keyboards/keychron/q0/rev_0100/keymaps/fwest98/rgb_matrix_user.c
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 keyboards/keychron/q0/rev_0100/keymaps/fwest98/rgb_matrix_user.h
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);
Loading

0 comments on commit 28c38e1

Please sign in to comment.