From 8233b6ede120bcf9160e2b6a5e6f9a1b89b61094 Mon Sep 17 00:00:00 2001 From: Ezri Brimhall Date: Wed, 5 Nov 2025 09:54:49 -0700 Subject: [PATCH] Bulk commit for changes to K5 Max: - Introduced new keymap "infraviolet" - Basic keymap with only two layers - No support for VIA - RGB set to purple, no facilities for changing it - TODO: RGB not working currently, never turns on - Mac/Windows switch repurposed as backlight switch - Removed keyboard-level handling of Mac/Windows switch - Was not implemented properly, ignored return value of user function - Autoformatter went a bit silly on common/factory_test.c --- keyboards/keychron/common/factory_test.c | 46 ++++----- keyboards/keychron/k5_max/ansi/rgb/info.json | 66 ++++++------- .../ansi/rgb/keymaps/infraviolet/config.h | 23 +++++ .../ansi/rgb/keymaps/infraviolet/keymap.c | 93 +++++++++++++++++++ .../ansi/rgb/keymaps/infraviolet/rules.mk | 1 + keyboards/keychron/k5_max/k5_max.c | 3 - 6 files changed, 168 insertions(+), 64 deletions(-) create mode 100644 keyboards/keychron/k5_max/ansi/rgb/keymaps/infraviolet/config.h create mode 100644 keyboards/keychron/k5_max/ansi/rgb/keymaps/infraviolet/keymap.c create mode 100644 keyboards/keychron/k5_max/ansi/rgb/keymaps/infraviolet/rules.mk diff --git a/keyboards/keychron/common/factory_test.c b/keyboards/keychron/common/factory_test.c index 5296222925..ebf0e460b0 100644 --- a/keyboards/keychron/common/factory_test.c +++ b/keyboards/keychron/common/factory_test.c @@ -70,17 +70,7 @@ enum { KEY_PRESS_BACKLIGTH_TEST = KEY_PRESS_FN | KEY_PRESS_BL_KEY1 | KEY_PRESS_BL_KEY2, }; -enum { - FACTORY_TEST_CMD_BACKLIGHT = 0x01, - FACTORY_TEST_CMD_OS_SWITCH, - FACTORY_TEST_CMD_JUMP_TO_BL, - FACTORY_TEST_CMD_INT_PIN, - FACTORY_TEST_CMD_GET_TRANSPORT, - FACTORY_TEST_CMD_CHARGING_ADC, - FACTORY_TEST_CMD_RADIO_CARRIER, - FACTORY_TEST_CMD_GET_BUILD_TIME, - FACTORY_TEST_CMD_GET_DEVICE_ID -}; +enum { FACTORY_TEST_CMD_BACKLIGHT = 0x01, FACTORY_TEST_CMD_OS_SWITCH, FACTORY_TEST_CMD_JUMP_TO_BL, FACTORY_TEST_CMD_INT_PIN, FACTORY_TEST_CMD_GET_TRANSPORT, FACTORY_TEST_CMD_CHARGING_ADC, FACTORY_TEST_CMD_RADIO_CARRIER, FACTORY_TEST_CMD_GET_BUILD_TIME, FACTORY_TEST_CMD_GET_DEVICE_ID }; enum { P2P4G_CLEAR_PAIRING_TYPE_A = 0x01 << 0, @@ -133,14 +123,14 @@ static inline void factory_timer_check(void) { #ifdef RGB_MATRIX_ENABLE if (!rgb_matrix_is_enabled()) rgb_matrix_enable(); rgb_matrix_init(); -#if defined(KEYCHRON_RGB_ENABLE) && defined(EECONFIG_SIZE_CUSTOM_RGB) +# if defined(KEYCHRON_RGB_ENABLE) && defined(EECONFIG_SIZE_CUSTOM_RGB) eeconfig_reset_custom_rgb(); -#endif +# endif #endif #ifdef LK_WIRELESS_ENABLE -#ifdef EECONFIG_SIZE_WIRELESS_CONFIG +# ifdef EECONFIG_SIZE_WIRELESS_CONFIG wireless_config_reset(); -#endif +# endif wait_ms(50); lkbt51_factory_reset(P2P4G_CELAR_MASK); #endif @@ -450,10 +440,10 @@ void factory_test_rx(uint8_t *data, uint8_t length) { case FACTORY_TEST_CMD_GET_DEVICE_ID: payload[len++] = FACTORY_TEST_CMD_GET_DEVICE_ID; - payload[len++] = 12; // UUID length + payload[len++] = 12; // UUID length memcpy(&payload[len], (uint32_t *)UID_BASE, 4); - memcpy(&payload[len+4], (uint32_t *)UID_BASE+4, 4); - memcpy(&payload[len+8], (uint32_t *)UID_BASE+8, 4); + memcpy(&payload[len + 4], (uint32_t *)UID_BASE + 4, 4); + memcpy(&payload[len + 8], (uint32_t *)UID_BASE + 8, 4); len += 12; factory_test_send(payload, len); @@ -462,14 +452,14 @@ void factory_test_rx(uint8_t *data, uint8_t length) { } } -bool dip_switch_update_user(uint8_t index, bool active) { - if (report_os_sw_state) { -#ifdef INVERT_OS_SWITCH_STATE - active = !active; -#endif - uint8_t payload[3] = {FACTORY_TEST_CMD_OS_SWITCH, OS_SWITCH, active}; - factory_test_send(payload, 3); - } +/* bool dip_switch_update_user(uint8_t index, bool active) { */ +/* if (report_os_sw_state) { */ +/* #ifdef INVERT_OS_SWITCH_STATE */ +/* active = !active; */ +/* #endif */ +/* uint8_t payload[3] = {FACTORY_TEST_CMD_OS_SWITCH, OS_SWITCH, active}; */ +/* factory_test_send(payload, 3); */ +/* } */ - return true; -} +/* return true; */ +/* } */ diff --git a/keyboards/keychron/k5_max/ansi/rgb/info.json b/keyboards/keychron/k5_max/ansi/rgb/info.json index 9ace101719..36d2b441f2 100644 --- a/keyboards/keychron/k5_max/ansi/rgb/info.json +++ b/keyboards/keychron/k5_max/ansi/rgb/info.json @@ -1,36 +1,36 @@ { - "usb": { - "pid": "0x0A50", - "device_version": "1.0.0" - }, - "features": { - "rgb_matrix": true - }, - "rgb_matrix": { - "driver": "snled27351_spi", - "sleep": true, - "animations": { - "band_spiral_val": true, - "breathing": true, - "cycle_all": true, - "cycle_left_right": true, - "cycle_out_in": true, - "cycle_out_in_dual": true, - "cycle_pinwheel": true, - "cycle_spiral": true, - "cycle_up_down": true, - "digital_rain": true, - "dual_beacon": true, - "jellybean_raindrops": true, - "pixel_rain": true, - "rainbow_beacon": true, - "rainbow_moving_chevron": true, - "solid_reactive_multinexus": true, - "solid_reactive_multiwide": true, - "solid_reactive_simple": true, - "solid_splash": true, - "splash": true, - "typing_heatmap": true - } + "usb": { + "pid": "0x0A50", + "device_version": "1.0.0" + }, + "features": { + "rgb_matrix": true + }, + "rgb_matrix": { + "driver": "snled27351_spi", + "sleep": true, + "animations": { + "band_spiral_val": true, + "breathing": true, + "cycle_all": true, + "cycle_left_right": true, + "cycle_out_in": true, + "cycle_out_in_dual": true, + "cycle_pinwheel": true, + "cycle_spiral": true, + "cycle_up_down": true, + "digital_rain": true, + "dual_beacon": true, + "jellybean_raindrops": true, + "pixel_rain": true, + "rainbow_beacon": true, + "rainbow_moving_chevron": true, + "solid_reactive_multinexus": true, + "solid_reactive_multiwide": true, + "solid_reactive_simple": true, + "solid_splash": true, + "splash": true, + "typing_heatmap": true } + } } diff --git a/keyboards/keychron/k5_max/ansi/rgb/keymaps/infraviolet/config.h b/keyboards/keychron/k5_max/ansi/rgb/keymaps/infraviolet/config.h new file mode 100644 index 0000000000..6fe5f6a2a4 --- /dev/null +++ b/keyboards/keychron/k5_max/ansi/rgb/keymaps/infraviolet/config.h @@ -0,0 +1,23 @@ +/* Copyright 2025 infraviolet + * + * 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 + +#define RGB_MATRIX_SLEEP +#undef RGB_MATRIX_TIMEOUT +#define RGB_MATRIX_TIMEOUT 300000 + +#define USER_LAYER_COUNT 3 diff --git a/keyboards/keychron/k5_max/ansi/rgb/keymaps/infraviolet/keymap.c b/keyboards/keychron/k5_max/ansi/rgb/keymaps/infraviolet/keymap.c new file mode 100644 index 0000000000..6798b84a81 --- /dev/null +++ b/keyboards/keychron/k5_max/ansi/rgb/keymaps/infraviolet/keymap.c @@ -0,0 +1,93 @@ +/* Copyright 2025 infraviolet + * + * 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 +#include "keychron_common.h" +#include "os_detection.h" + +enum layers { + LAYER_BASE, + LAYER_FN, +}; + +// clang-format off +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [LAYER_BASE] = LAYOUT_108_ansi( + 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_PSCR, KC_F13, KC_F18, KC_F14, KC_F15, KC_F16, KC_F17, + 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_INS, KC_HOME, KC_PGUP, KC_NUM, KC_PSLS, KC_PAST, KC_PMNS, + 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_DEL, KC_END, KC_PGDN, KC_P7, KC_P8, KC_P9, + 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_P4, KC_P5, KC_P6, KC_PPLS, + 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_P1, KC_P2, KC_P3, + KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, KC_RGUI,MO(LAYER_FN),KC_RCTL,KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT, KC_PENT), + + [LAYER_FN] = LAYOUT_108_ansi( + _______, KC_BRID, KC_BRIU, KC_TASK, KC_FILE, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, _______, _______, _______, _______, _______, _______, _______, + _______, BT_HST1, BT_HST2, BT_HST3, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, QK_BOOT, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______), +}; + +// clang-format on +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + uint8_t mod_state = get_mods(); + + switch (keycode) { + case KC_SPC: + // If the keypress is space and we only have shift pressed, send KC_MINS (which when shifted gives underscore) instead of KC_SPC. + // This will allow us to still use key combos that include space _and_ shift _and_ some other modifier. + if (mod_state & MOD_MASK_SHIFT && !(mod_state & MOD_MASK_CAG)) { + if (record->event.pressed) { + register_code(KC_MINS); + } else { + unregister_code(KC_MINS); + } + return false; + } + return true; + + default: + return true; + } +} + +void keyboard_post_init_user(void) { + rgb_matrix_mode_noeeprom(RGB_MATRIX_BREATHING); + rgb_matrix_sethsv_noeeprom(HSV_PURPLE); + rgb_matrix_set_speed_noeeprom(32); +} + +bool dip_switch_update_user(uint8_t index, bool active) { + // reuse the macos/windows toggle that we don't want to use as a keyboard backlight toggle. + if (index == 0) { + if (active) { + rgb_matrix_disable_noeeprom(); + } else { + rgb_matrix_enable_noeeprom(); + } + return false; + } + return true; +} + +void eeconfig_init_user(void) { + // configure RGB + rgb_matrix_enable(); + rgb_matrix_mode(RGB_MATRIX_BREATHING); + rgb_matrix_sethsv(HSV_PURPLE); + rgb_matrix_set_speed(32); +} diff --git a/keyboards/keychron/k5_max/ansi/rgb/keymaps/infraviolet/rules.mk b/keyboards/keychron/k5_max/ansi/rgb/keymaps/infraviolet/rules.mk new file mode 100644 index 0000000000..64ac3dcb16 --- /dev/null +++ b/keyboards/keychron/k5_max/ansi/rgb/keymaps/infraviolet/rules.mk @@ -0,0 +1 @@ +OS_DETECTION_ENABLE = yes diff --git a/keyboards/keychron/k5_max/k5_max.c b/keyboards/keychron/k5_max/k5_max.c index 223caac788..f0ab1c6105 100644 --- a/keyboards/keychron/k5_max/k5_max.c +++ b/keyboards/keychron/k5_max/k5_max.c @@ -37,9 +37,6 @@ pin_t p24g_led_pins[] = P24G_HOST_LED_PIN_LIST; #endif bool dip_switch_update_kb(uint8_t index, bool active) { - if (index == 0) { - default_layer_set(1UL << (active ? 0 : 2)); - } dip_switch_update_user(index, active); return true;