Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[keymap] Keychron Q2 ANSI encoder with Caps Lock, Fn Layer and Caps Word RGB indicators #20199

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0b487e5
initial commit
mkillewald Mar 19, 2023
f86636f
updated readme
mkillewald Mar 19, 2023
1702c81
updated readme
mkillewald Mar 19, 2023
93e42f4
updated readme
mkillewald Mar 19, 2023
738d4fe
updated readme
mkillewald Mar 19, 2023
e8d47aa
updated readme
mkillewald Mar 19, 2023
babea5f
updated readme
mkillewald Mar 19, 2023
89eaaec
RGB_ORANGE in config.h produced yellow on my Q2, so I changed FN1_LAY…
mkillewald Mar 19, 2023
bfa3c56
updated readme
mkillewald Mar 19, 2023
8f2cc94
updated readme
mkillewald Mar 19, 2023
6704911
decreased red value by 1
mkillewald Mar 19, 2023
de6513c
updated readme
mkillewald Mar 19, 2023
3e14879
removed custom macros, retained same functionality
mkillewald Mar 20, 2023
1bdc2c5
updated readme
mkillewald Mar 20, 2023
01f94af
increased delay in Fn1+Q macro to 200 ms
mkillewald Mar 20, 2023
11eab1d
updated GPL header
mkillewald Mar 20, 2023
fab15d1
clean up
mkillewald Mar 20, 2023
44e0dee
removed unused code
mkillewald Mar 20, 2023
9f739e7
toggle RGB LEDs off before calling bootloader when RESET/QK_BOOT keyc…
mkillewald Mar 20, 2023
0514aae
removed unused custom keycodes. Can apply as Macro in VIA instead
mkillewald Mar 20, 2023
e219ac4
replaced bools with enum for bootloader_state
mkillewald Mar 22, 2023
8842ab1
removed commented out block
mkillewald Mar 31, 2023
1c4a6d0
changed from QK_KB_11 to QK_USER_0
mkillewald Apr 4, 2023
dbb60dd
removed .json file
mkillewald Apr 4, 2023
448188b
updated readme
mkillewald Apr 4, 2023
e4b163f
updated readme
mkillewald Apr 4, 2023
5fd4218
updated readme
mkillewald Apr 4, 2023
4cf3cd6
updated readme with new custom keycode identifiers
mkillewald Apr 4, 2023
1ca1117
Update keyboards/keychron/q2/ansi_encoder/keymaps/mkillewald/readme.md
mkillewald Apr 4, 2023
eed903f
hard coded layout changes previously provided by the optional .json file
mkillewald Apr 4, 2023
53a037f
updated readme
mkillewald Apr 4, 2023
0cf7dc2
removed period
mkillewald Apr 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions keyboards/keychron/q2/ansi_encoder/keymaps/mkillewald/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* Copyright 2023 @ Mike Killewald (https://github.com/mkillewald)
*
* 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

#ifdef CAPS_WORD_ENABLE
# define DOUBLE_TAP_SHIFT_TURNS_ON_CAPS_WORD
# define CAPS_WORD_INDICATOR_COLOR RGB_RED
# define CAPS_WORD_LIGHT_LOWER_LEFT_CORNER
#endif

#ifdef RGB_MATRIX_ENABLE
# define CAPS_LOCK_INDICATOR_COLOR RGB_RED
# define FN1_LAYER_COLOR 0xFE, 0x23, 0x00
# define FN2_LAYER_COLOR RGB_GREEN
#endif
183 changes: 183 additions & 0 deletions keyboards/keychron/q2/ansi_encoder/keymaps/mkillewald/keymap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/* Copyright 2023 @ Mike Killewald (https://github.com/mkillewald)
*
* 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 "keychron_common.h"
#include "keymap_user.h"
#include "keymap_user_config.h"
#ifdef RGB_MATRIX_ENABLE
# include "rgb_matrix_user.h"
#endif

// clang-format off

#ifdef RGB_MATRIX_ENABLE
enum my_bootloader_state {
BOOTLOADER_INACTIVE,
BOOTLOADER_PRESSED,
BOOTLOADER_WAIT,
BOOTLOADER_DO
} bootloader_state;
#endif

enum my_keycodes {
KC_LIGHT_TAB_TOGGLE = QK_USER_0,
KC_LIGHT_ALPHAS_TOGGLE,
KC_FN_LAYER_TRANSPARENT_KEYS_TOGGLE,
KC_FN_LAYER_COLOR_TOGGLE,
KC_LOCK_BLANK_MAC
};

#define KC_LTTOG KC_LIGHT_TAB_TOGGLE
#define KC_LATOG KC_LIGHT_ALPHAS_TOGGLE
#define KC_TKTOG KC_FN_LAYER_TRANSPARENT_KEYS_TOGGLE
#define KC_FCTOG KC_FN_LAYER_COLOR_TOGGLE
#define KC_LBMAC KC_LOCK_BLANK_MAC

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[MAC_BASE] = LAYOUT_ansi_67(
QK_GESC, 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_MUTE,
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_LCTL, KC_LOPTN, KC_LCMMD, KC_SPC, KC_RCMMD, MO(_FN1), MO(_FN3), KC_LEFT, KC_DOWN, KC_RGHT),

[WIN_BASE] = LAYOUT_ansi_67(
QK_GESC, 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_MUTE,
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_LCTL, KC_LWIN, KC_LALT, KC_SPC, KC_RALT, MO(_FN2), MO(_FN3), KC_LEFT, KC_DOWN, KC_RGHT),

// Mac Fn1
[_FN1] = LAYOUT_ansi_67(
KC_GRV, KC_BRID, KC_BRIU, KC_MCTL, KC_LPAD, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, _______, G(KC_0),
_______, KC_LBMAC, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, G(KC_LEFT),
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, G(KC_RGHT),
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______),

// Win Fn1
[_FN2] = LAYOUT_ansi_67(
KC_GRV, KC_BRID, KC_BRIU, KC_TASK, KC_FLXP, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, _______, C(KC_0),
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_END,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______),

// Combined Mac Win Fn2
[_FN3] = LAYOUT_ansi_67(
KC_TILD, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, RGB_TOG,
RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL,
_______, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, KC_HOME,
_______, KC_LTTOG, KC_LATOG, KC_TKTOG, KC_FCTOG, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______)
};

// clang-format on

#if defined(ENCODER_MAP_ENABLE)
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = {
[MAC_BASE] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) },
[WIN_BASE] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) },
[_FN1] = { ENCODER_CCW_CW(G(KC_MINS), G(KC_EQL)) },
[_FN2] = { ENCODER_CCW_CW(C(KC_MINS), C(KC_EQL)) },
[_FN3] = { ENCODER_CCW_CW(RGB_VAD, RGB_VAI) },
};
#endif

void housekeeping_task_user(void) {
#ifdef RGB_MATRIX_ENABLE
switch(bootloader_state) {
case BOOTLOADER_DO:
// bootloader was pressed two frames ago. RGB should now be off,
// so we can call the bootloader.
reset_keyboard();
break;
case BOOTLOADER_WAIT:
// bootloader was pressed on previous frame, we wait this frame and
// set flag to do bootloader at end of next frame. For some reason, my
// Q2 needed this extra wait frame.
bootloader_state = BOOTLOADER_DO;
break;
case BOOTLOADER_PRESSED:
// User pressed bootloader keycode and RGB was disabled earlier in this
// frame. However RGB changes wont take place immediately, so we set a
// flag here which will be caught at end of the next frame.
bootloader_state = BOOTLOADER_WAIT;
break;
default:
break;
}
#endif

housekeeping_task_keychron();
}

void matrix_init_user(void) {
#ifdef RGB_MATRIX_ENABLE
rgb_matrix_init_user();
#endif
}

void keyboard_post_init_user(void) {
user_config_read();
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (process_record_keychron(keycode, record)) {
switch (keycode) {
case QK_BOOT:
#ifdef RGB_MATRIX_ENABLE
// We want to turn off LEDs before calling bootloader, so here
// we call rgb_matrix_disable_noeeprom() and set a flag because
// the LEDs won't be updated until the next frame.
rgb_matrix_disable_noeeprom();
bootloader_state = BOOTLOADER_PRESSED;
return false; // Skip all further processing of this key
#endif
return true; // Allow further processing of this key
case KC_LIGHT_TAB_TOGGLE:
if (record->event.pressed) {
user_config_toggle_caps_lock_light_tab();
}
return false; // Skip all further processing of this key
case KC_LIGHT_ALPHAS_TOGGLE:
if (record->event.pressed) {
user_config_toggle_caps_lock_light_alphas();
}
return false; // Skip all further processing of this key
case KC_FN_LAYER_TRANSPARENT_KEYS_TOGGLE:
if (record->event.pressed) {
user_config_toggle_fn_layer_transparent_keys_off();
}
return false; // Skip all further processing of this key
case KC_FN_LAYER_COLOR_TOGGLE:
if (record->event.pressed) {
user_config_toggle_fn_layer_color_enable();
}
return false; // Skip all further processing of this key
case KC_LOCK_BLANK_MAC:
if (record->event.pressed) {
send_string(SS_LCTL(SS_LGUI("q")) SS_DELAY(225) SS_TAP(X_ESC));
}
return false; // Skip all further processing of this key
default:
return true; // Process all other keycodes normally
}
}
return true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Copyright 2023 @ Mike Killewald (https://github.com/mkillewald)
*
* 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

enum layers{
MAC_BASE, // Mac Base (layer 0)
WIN_BASE, // Win Base (layer 1)
_FN1, // Mac Fn1 (layer 2)
_FN2, // Win Fn1 (layer 3)
_FN3 // Mac/Win Fn2 (layer 4)
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* Copyright 2023 @ Mike Killewald (https://github.com/mkillewald)
*
* 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_user_config.h"

typedef union {
uint32_t raw;
struct {
bool caps_lock_light_tab :1;
bool caps_lock_light_alphas :1;
bool fn_layer_transparent_keys_off :1;
bool fn_layer_color_enable :1;
};
} user_config_t;

user_config_t user_config;

void eeconfig_init_user(void) {
user_config.raw = 0;
user_config.caps_lock_light_tab = false;
user_config.caps_lock_light_alphas = false;
user_config.fn_layer_transparent_keys_off = true;
user_config.fn_layer_color_enable = false;
eeconfig_update_user(user_config.raw);
}

void user_config_read(void) {
user_config.raw = eeconfig_read_user();
}

void user_config_write(void) {
eeconfig_update_user(user_config.raw);
}

bool user_config_get_caps_lock_light_tab(void) {
return user_config.caps_lock_light_tab;
}

bool user_config_get_caps_lock_light_alphas(void) {
return user_config.caps_lock_light_alphas;
}

bool user_config_get_fn_layer_transparent_keys_off(void) {
return user_config.fn_layer_transparent_keys_off;
}

bool user_config_get_fn_layer_color_enable(void) {
return user_config.fn_layer_color_enable;
}

void user_config_toggle_caps_lock_light_tab(void) {
user_config.caps_lock_light_tab ^= 1; // bitwise xor to toggle status bit
user_config_write();
}

void user_config_toggle_caps_lock_light_alphas(void) {
user_config.caps_lock_light_alphas ^= 1;
user_config_write();
}

void user_config_toggle_fn_layer_transparent_keys_off(void) {
user_config.fn_layer_transparent_keys_off ^= 1;
user_config_write();
}

void user_config_toggle_fn_layer_color_enable(void) {
user_config.fn_layer_color_enable ^= 1;
user_config_write();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Copyright 2023 @ Mike Killewald (https://github.com/mkillewald)
*
* 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

void user_config_read(void);
void user_config_write(void);
bool user_config_get_caps_lock_light_tab(void);
bool user_config_get_caps_lock_light_alphas(void);
bool user_config_get_fn_layer_transparent_keys_off(void);
bool user_config_get_fn_layer_color_enable(void);
void user_config_toggle_caps_lock_light_tab(void);
void user_config_toggle_caps_lock_light_alphas(void);
void user_config_toggle_fn_layer_transparent_keys_off(void);
void user_config_toggle_fn_layer_color_enable(void);
Loading