From f513c3105840a00bad74abc8eae2555033e285b6 Mon Sep 17 00:00:00 2001 From: Ezri Brimhall Date: Wed, 5 Nov 2025 11:03:06 -0700 Subject: [PATCH] Accidentally deleted too much, restoring... --- .../keychron/bluetooth/bat_level_animation.c | 142 +++ .../keychron/bluetooth/bat_level_animation.h | 23 + keyboards/keychron/bluetooth/battery.c | 140 +++ keyboards/keychron/bluetooth/battery.h | 60 ++ keyboards/keychron/bluetooth/bluetooth.c | 493 ++++++++++ keyboards/keychron/bluetooth/bluetooth.h | 89 ++ keyboards/keychron/bluetooth/bluetooth.mk | 23 + .../keychron/bluetooth/bluetooth_config.h | 38 + .../keychron/bluetooth/bluetooth_event_type.h | 44 + keyboards/keychron/bluetooth/bluetooth_main.c | 37 + keyboards/keychron/bluetooth/ckbt51.c | 606 ++++++++++++ keyboards/keychron/bluetooth/ckbt51.h | 157 ++++ keyboards/keychron/bluetooth/factory_test.c | 343 +++++++ keyboards/keychron/bluetooth/factory_test.h | 24 + keyboards/keychron/bluetooth/indicator.c | 607 ++++++++++++ keyboards/keychron/bluetooth/indicator.h | 118 +++ keyboards/keychron/bluetooth/lpm.c | 92 ++ keyboards/keychron/bluetooth/lpm.h | 30 + keyboards/keychron/bluetooth/lpm_stm32l432.c | 330 +++++++ keyboards/keychron/bluetooth/lpm_stm32l432.h | 19 + keyboards/keychron/bluetooth/report_buffer.c | 141 +++ keyboards/keychron/bluetooth/report_buffer.h | 56 ++ keyboards/keychron/bluetooth/rtc_timer.c | 43 + keyboards/keychron/bluetooth/rtc_timer.h | 43 + keyboards/keychron/bluetooth/transport.c | 190 ++++ keyboards/keychron/bluetooth/transport.h | 39 + keyboards/keychron/common/common.mk | 6 + .../common/debounce/asym_eager_defer_pk.c | 170 ++++ .../keychron/common/debounce/debounce.mk | 14 + .../common/debounce/eeconfig_debounce.h | 20 + .../common/debounce/keychron_debounce.c | 214 +++++ .../common/debounce/keychron_debounce.h | 56 ++ keyboards/keychron/common/debounce/none.c | 36 + keyboards/keychron/common/debounce/none.h | 36 + .../keychron/common/debounce/sym_defer_g.c | 51 + .../keychron/common/debounce/sym_defer_pk.c | 137 +++ .../keychron/common/debounce/sym_defer_pr.c | 80 ++ .../keychron/common/debounce/sym_eager_pk.c | 142 +++ .../keychron/common/debounce/sym_eager_pr.c | 134 +++ keyboards/keychron/common/dfu_info.c | 49 + keyboards/keychron/common/eeconfig_kb.c | 35 + keyboards/keychron/common/eeconfig_kb.h | 61 ++ keyboards/keychron/common/factory_test.c | 465 ++++++++++ keyboards/keychron/common/factory_test.h | 34 + keyboards/keychron/common/keychron_common.c | 184 ++++ keyboards/keychron/common/keychron_common.h | 96 ++ keyboards/keychron/common/keychron_common.mk | 31 + keyboards/keychron/common/keychron_raw_hid.c | 203 ++++ keyboards/keychron/common/keychron_raw_hid.h | 65 ++ keyboards/keychron/common/keychron_task.c | 141 +++ keyboards/keychron/common/keychron_task.h | 25 + .../common/language/eeconfig_language.h | 20 + keyboards/keychron/common/language/language.c | 60 ++ keyboards/keychron/common/language/language.h | 21 + .../keychron/common/language/language.mk | 7 + keyboards/keychron/common/matrix.c | 218 +++++ .../keychron/common/rgb/eeconfig_custom_rgb.h | 39 + keyboards/keychron/common/rgb/keychron_rgb.c | 494 ++++++++++ .../keychron/common/rgb/keychron_rgb_type.h | 59 ++ keyboards/keychron/common/rgb/mixed_rgb.c | 191 ++++ keyboards/keychron/common/rgb/per_key_rgb.c | 160 ++++ keyboards/keychron/common/rgb/retail_demo.c | 185 ++++ keyboards/keychron/common/rgb/retail_demo.h | 25 + keyboards/keychron/common/rgb/rgb.mk | 14 + .../keychron/common/rgb/rgb_matrix_kb.inc | 39 + .../common/rgb/rgb_matrix_kb_config.h | 26 + .../common/snap_click/eeconfig_snap_click.h | 26 + .../keychron/common/snap_click/snap_click.c | 201 ++++ .../keychron/common/snap_click/snap_click.h | 43 + .../keychron/common/snap_click/snap_click.mk | 7 + .../common/wireless/bat_level_animation.c | 163 ++++ .../common/wireless/bat_level_animation.h | 23 + keyboards/keychron/common/wireless/battery.c | 229 +++++ keyboards/keychron/common/wireless/battery.h | 61 ++ .../common/wireless/eeconfig_wireless.h | 20 + .../keychron/common/wireless/indicator.c | 773 ++++++++++++++++ .../keychron/common/wireless/indicator.h | 114 +++ .../wireless/keychron_wireless_common.c | 156 ++++ .../wireless/keychron_wireless_common.h | 26 + keyboards/keychron/common/wireless/lkbt51.c | 875 ++++++++++++++++++ keyboards/keychron/common/wireless/lkbt51.h | 131 +++ keyboards/keychron/common/wireless/lpm.c | 298 ++++++ keyboards/keychron/common/wireless/lpm.h | 36 + .../keychron/common/wireless/lpm_stm32f401.c | 114 +++ .../keychron/common/wireless/lpm_stm32f401.h | 33 + .../keychron/common/wireless/report_buffer.c | 144 +++ .../keychron/common/wireless/report_buffer.h | 61 ++ .../keychron/common/wireless/rtc_timer.c | 43 + .../keychron/common/wireless/rtc_timer.h | 35 + .../keychron/common/wireless/transport.c | 259 ++++++ .../keychron/common/wireless/transport.h | 42 + keyboards/keychron/common/wireless/wireless.c | 657 +++++++++++++ keyboards/keychron/common/wireless/wireless.h | 106 +++ .../keychron/common/wireless/wireless.mk | 21 + .../common/wireless/wireless_config.h | 31 + .../common/wireless/wireless_event_type.h | 45 + .../keychron/common/wireless/wireless_main.c | 36 + keyboards/keychron/k5_max/ansi/rgb/config.h | 55 ++ keyboards/keychron/k5_max/ansi/rgb/info.json | 36 + .../k5_max/ansi/rgb/keymaps/default/keymap.c | 68 ++ .../ansi/rgb/keymaps/infraviolet/config.h | 23 + .../ansi/rgb/keymaps/infraviolet/keymap.c | 93 ++ .../ansi/rgb/keymaps/infraviolet/rules.mk | 1 + .../k5_max/ansi/rgb/keymaps/via/keymap.c | 68 ++ .../k5_max/ansi/rgb/keymaps/via/rules.mk | 1 + keyboards/keychron/k5_max/ansi/rgb/rgb.c | 174 ++++ keyboards/keychron/k5_max/ansi/rgb/rules.mk | 1 + keyboards/keychron/k5_max/ansi/white/config.h | 52 ++ .../keychron/k5_max/ansi/white/info.json | 30 + .../ansi/white/keymaps/default/keymap.c | 68 ++ .../k5_max/ansi/white/keymaps/via/keymap.c | 68 ++ .../k5_max/ansi/white/keymaps/via/rules.mk | 1 + keyboards/keychron/k5_max/ansi/white/rules.mk | 1 + keyboards/keychron/k5_max/ansi/white/white.c | 172 ++++ keyboards/keychron/k5_max/board.h | 226 +++++ keyboards/keychron/k5_max/config.h | 93 ++ .../firmware/keychron_k5_max_ansi_rgb_via.bin | Bin 0 -> 95948 bytes .../keychron_k5_max_ansi_white_via.bin | Bin 0 -> 87200 bytes .../firmware/keychron_k5_max_iso_rgb_via.bin | Bin 0 -> 95956 bytes .../keychron_k5_max_iso_white_via.bin | Bin 0 -> 87208 bytes keyboards/keychron/k5_max/halconf.h | 31 + keyboards/keychron/k5_max/info.json | 272 ++++++ keyboards/keychron/k5_max/iso/rgb/config.h | 55 ++ keyboards/keychron/k5_max/iso/rgb/info.json | 36 + .../k5_max/iso/rgb/keymaps/default/keymap.c | 68 ++ .../k5_max/iso/rgb/keymaps/via/keymap.c | 68 ++ .../k5_max/iso/rgb/keymaps/via/rules.mk | 1 + keyboards/keychron/k5_max/iso/rgb/rgb.c | 175 ++++ keyboards/keychron/k5_max/iso/rgb/rules.mk | 1 + keyboards/keychron/k5_max/iso/white/config.h | 52 ++ keyboards/keychron/k5_max/iso/white/info.json | 30 + .../k5_max/iso/white/keymaps/default/keymap.c | 68 ++ .../k5_max/iso/white/keymaps/via/keymap.c | 68 ++ .../k5_max/iso/white/keymaps/via/rules.mk | 1 + keyboards/keychron/k5_max/iso/white/rules.mk | 1 + keyboards/keychron/k5_max/iso/white/white.c | 173 ++++ keyboards/keychron/k5_max/k5_max.c | 97 ++ keyboards/keychron/k5_max/mcuconf.h | 37 + keyboards/keychron/k5_max/readme.md | 23 + keyboards/keychron/k5_max/rules.mk | 4 + .../k5_max/via_json/k5_max_ansi_rgb.json | 342 +++++++ .../k5_max/via_json/k5_max_ansi_white.json | 281 ++++++ 142 files changed, 15894 insertions(+) create mode 100644 keyboards/keychron/bluetooth/bat_level_animation.c create mode 100644 keyboards/keychron/bluetooth/bat_level_animation.h create mode 100644 keyboards/keychron/bluetooth/battery.c create mode 100644 keyboards/keychron/bluetooth/battery.h create mode 100644 keyboards/keychron/bluetooth/bluetooth.c create mode 100644 keyboards/keychron/bluetooth/bluetooth.h create mode 100644 keyboards/keychron/bluetooth/bluetooth.mk create mode 100644 keyboards/keychron/bluetooth/bluetooth_config.h create mode 100644 keyboards/keychron/bluetooth/bluetooth_event_type.h create mode 100644 keyboards/keychron/bluetooth/bluetooth_main.c create mode 100644 keyboards/keychron/bluetooth/ckbt51.c create mode 100644 keyboards/keychron/bluetooth/ckbt51.h create mode 100644 keyboards/keychron/bluetooth/factory_test.c create mode 100644 keyboards/keychron/bluetooth/factory_test.h create mode 100644 keyboards/keychron/bluetooth/indicator.c create mode 100644 keyboards/keychron/bluetooth/indicator.h create mode 100644 keyboards/keychron/bluetooth/lpm.c create mode 100644 keyboards/keychron/bluetooth/lpm.h create mode 100644 keyboards/keychron/bluetooth/lpm_stm32l432.c create mode 100644 keyboards/keychron/bluetooth/lpm_stm32l432.h create mode 100644 keyboards/keychron/bluetooth/report_buffer.c create mode 100644 keyboards/keychron/bluetooth/report_buffer.h create mode 100644 keyboards/keychron/bluetooth/rtc_timer.c create mode 100644 keyboards/keychron/bluetooth/rtc_timer.h create mode 100644 keyboards/keychron/bluetooth/transport.c create mode 100644 keyboards/keychron/bluetooth/transport.h create mode 100644 keyboards/keychron/common/common.mk create mode 100644 keyboards/keychron/common/debounce/asym_eager_defer_pk.c create mode 100644 keyboards/keychron/common/debounce/debounce.mk create mode 100644 keyboards/keychron/common/debounce/eeconfig_debounce.h create mode 100644 keyboards/keychron/common/debounce/keychron_debounce.c create mode 100644 keyboards/keychron/common/debounce/keychron_debounce.h create mode 100644 keyboards/keychron/common/debounce/none.c create mode 100644 keyboards/keychron/common/debounce/none.h create mode 100644 keyboards/keychron/common/debounce/sym_defer_g.c create mode 100644 keyboards/keychron/common/debounce/sym_defer_pk.c create mode 100644 keyboards/keychron/common/debounce/sym_defer_pr.c create mode 100644 keyboards/keychron/common/debounce/sym_eager_pk.c create mode 100644 keyboards/keychron/common/debounce/sym_eager_pr.c create mode 100644 keyboards/keychron/common/dfu_info.c create mode 100644 keyboards/keychron/common/eeconfig_kb.c create mode 100644 keyboards/keychron/common/eeconfig_kb.h create mode 100644 keyboards/keychron/common/factory_test.c create mode 100644 keyboards/keychron/common/factory_test.h create mode 100644 keyboards/keychron/common/keychron_common.c create mode 100644 keyboards/keychron/common/keychron_common.h create mode 100644 keyboards/keychron/common/keychron_common.mk create mode 100644 keyboards/keychron/common/keychron_raw_hid.c create mode 100644 keyboards/keychron/common/keychron_raw_hid.h create mode 100644 keyboards/keychron/common/keychron_task.c create mode 100644 keyboards/keychron/common/keychron_task.h create mode 100644 keyboards/keychron/common/language/eeconfig_language.h create mode 100644 keyboards/keychron/common/language/language.c create mode 100644 keyboards/keychron/common/language/language.h create mode 100644 keyboards/keychron/common/language/language.mk create mode 100644 keyboards/keychron/common/matrix.c create mode 100644 keyboards/keychron/common/rgb/eeconfig_custom_rgb.h create mode 100644 keyboards/keychron/common/rgb/keychron_rgb.c create mode 100644 keyboards/keychron/common/rgb/keychron_rgb_type.h create mode 100644 keyboards/keychron/common/rgb/mixed_rgb.c create mode 100644 keyboards/keychron/common/rgb/per_key_rgb.c create mode 100644 keyboards/keychron/common/rgb/retail_demo.c create mode 100644 keyboards/keychron/common/rgb/retail_demo.h create mode 100644 keyboards/keychron/common/rgb/rgb.mk create mode 100644 keyboards/keychron/common/rgb/rgb_matrix_kb.inc create mode 100644 keyboards/keychron/common/rgb/rgb_matrix_kb_config.h create mode 100644 keyboards/keychron/common/snap_click/eeconfig_snap_click.h create mode 100644 keyboards/keychron/common/snap_click/snap_click.c create mode 100644 keyboards/keychron/common/snap_click/snap_click.h create mode 100644 keyboards/keychron/common/snap_click/snap_click.mk create mode 100644 keyboards/keychron/common/wireless/bat_level_animation.c create mode 100644 keyboards/keychron/common/wireless/bat_level_animation.h create mode 100644 keyboards/keychron/common/wireless/battery.c create mode 100644 keyboards/keychron/common/wireless/battery.h create mode 100644 keyboards/keychron/common/wireless/eeconfig_wireless.h create mode 100644 keyboards/keychron/common/wireless/indicator.c create mode 100644 keyboards/keychron/common/wireless/indicator.h create mode 100644 keyboards/keychron/common/wireless/keychron_wireless_common.c create mode 100644 keyboards/keychron/common/wireless/keychron_wireless_common.h create mode 100644 keyboards/keychron/common/wireless/lkbt51.c create mode 100644 keyboards/keychron/common/wireless/lkbt51.h create mode 100644 keyboards/keychron/common/wireless/lpm.c create mode 100644 keyboards/keychron/common/wireless/lpm.h create mode 100644 keyboards/keychron/common/wireless/lpm_stm32f401.c create mode 100644 keyboards/keychron/common/wireless/lpm_stm32f401.h create mode 100644 keyboards/keychron/common/wireless/report_buffer.c create mode 100644 keyboards/keychron/common/wireless/report_buffer.h create mode 100644 keyboards/keychron/common/wireless/rtc_timer.c create mode 100644 keyboards/keychron/common/wireless/rtc_timer.h create mode 100644 keyboards/keychron/common/wireless/transport.c create mode 100644 keyboards/keychron/common/wireless/transport.h create mode 100644 keyboards/keychron/common/wireless/wireless.c create mode 100644 keyboards/keychron/common/wireless/wireless.h create mode 100644 keyboards/keychron/common/wireless/wireless.mk create mode 100644 keyboards/keychron/common/wireless/wireless_config.h create mode 100644 keyboards/keychron/common/wireless/wireless_event_type.h create mode 100644 keyboards/keychron/common/wireless/wireless_main.c create mode 100644 keyboards/keychron/k5_max/ansi/rgb/config.h create mode 100644 keyboards/keychron/k5_max/ansi/rgb/info.json create mode 100644 keyboards/keychron/k5_max/ansi/rgb/keymaps/default/keymap.c 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 create mode 100644 keyboards/keychron/k5_max/ansi/rgb/keymaps/via/keymap.c create mode 100644 keyboards/keychron/k5_max/ansi/rgb/keymaps/via/rules.mk create mode 100644 keyboards/keychron/k5_max/ansi/rgb/rgb.c create mode 100644 keyboards/keychron/k5_max/ansi/rgb/rules.mk create mode 100644 keyboards/keychron/k5_max/ansi/white/config.h create mode 100644 keyboards/keychron/k5_max/ansi/white/info.json create mode 100644 keyboards/keychron/k5_max/ansi/white/keymaps/default/keymap.c create mode 100644 keyboards/keychron/k5_max/ansi/white/keymaps/via/keymap.c create mode 100644 keyboards/keychron/k5_max/ansi/white/keymaps/via/rules.mk create mode 100644 keyboards/keychron/k5_max/ansi/white/rules.mk create mode 100644 keyboards/keychron/k5_max/ansi/white/white.c create mode 100644 keyboards/keychron/k5_max/board.h create mode 100644 keyboards/keychron/k5_max/config.h create mode 100644 keyboards/keychron/k5_max/firmware/keychron_k5_max_ansi_rgb_via.bin create mode 100644 keyboards/keychron/k5_max/firmware/keychron_k5_max_ansi_white_via.bin create mode 100644 keyboards/keychron/k5_max/firmware/keychron_k5_max_iso_rgb_via.bin create mode 100644 keyboards/keychron/k5_max/firmware/keychron_k5_max_iso_white_via.bin create mode 100644 keyboards/keychron/k5_max/halconf.h create mode 100644 keyboards/keychron/k5_max/info.json create mode 100644 keyboards/keychron/k5_max/iso/rgb/config.h create mode 100644 keyboards/keychron/k5_max/iso/rgb/info.json create mode 100644 keyboards/keychron/k5_max/iso/rgb/keymaps/default/keymap.c create mode 100644 keyboards/keychron/k5_max/iso/rgb/keymaps/via/keymap.c create mode 100644 keyboards/keychron/k5_max/iso/rgb/keymaps/via/rules.mk create mode 100644 keyboards/keychron/k5_max/iso/rgb/rgb.c create mode 100644 keyboards/keychron/k5_max/iso/rgb/rules.mk create mode 100644 keyboards/keychron/k5_max/iso/white/config.h create mode 100644 keyboards/keychron/k5_max/iso/white/info.json create mode 100644 keyboards/keychron/k5_max/iso/white/keymaps/default/keymap.c create mode 100644 keyboards/keychron/k5_max/iso/white/keymaps/via/keymap.c create mode 100644 keyboards/keychron/k5_max/iso/white/keymaps/via/rules.mk create mode 100644 keyboards/keychron/k5_max/iso/white/rules.mk create mode 100644 keyboards/keychron/k5_max/iso/white/white.c create mode 100644 keyboards/keychron/k5_max/k5_max.c create mode 100644 keyboards/keychron/k5_max/mcuconf.h create mode 100644 keyboards/keychron/k5_max/readme.md create mode 100644 keyboards/keychron/k5_max/rules.mk create mode 100644 keyboards/keychron/k5_max/via_json/k5_max_ansi_rgb.json create mode 100644 keyboards/keychron/k5_max/via_json/k5_max_ansi_white.json diff --git a/keyboards/keychron/bluetooth/bat_level_animation.c b/keyboards/keychron/bluetooth/bat_level_animation.c new file mode 100644 index 0000000000..e63735bcff --- /dev/null +++ b/keyboards/keychron/bluetooth/bat_level_animation.c @@ -0,0 +1,142 @@ + +#include "quantum.h" +#include "bluetooth.h" +#include "indicator.h" +#include "lpm.h" +#if defined(PROTOCOL_CHIBIOS) +# include +#elif if defined(PROTOCOL_LUFA) +# include "lufa.h" +#endif +#include "eeprom.h" + +#ifndef BAT_LEVEL_GROWING_INTERVAL +# define BAT_LEVEL_GROWING_INTERVAL 150 +#endif + +#ifndef BAT_LEVEL_ON_INTERVAL +# define BAT_LEVEL_ON_INTERVAL 3000 +#endif + +#ifdef LED_MATRIX_ENABLE +# define LED_DRIVER_IS_ENABLED led_matrix_is_enabled +#endif + +#ifdef RGB_MATRIX_ENABLE +# define LED_DRIVER_IS_ENABLED rgb_matrix_is_enabled +#endif + +enum { + BAT_LVL_ANI_NONE, + BAT_LVL_ANI_GROWING, + BAT_LVL_ANI_BLINK_OFF, + BAT_LVL_ANI_BLINK_ON, +}; + +static uint8_t animation_state = 0; +static uint32_t bat_lvl_ani_timer_buffer = 0; +static uint8_t bat_percentage; +static uint8_t cur_percentage; +static uint32_t time_interval; +#ifdef RGB_MATRIX_ENABLE +static uint8_t r, g, b; +#endif + +extern indicator_config_t indicator_config; +extern backlight_state_t original_backlight_state; + +void bat_level_animiation_start(uint8_t percentage) { + /* Turn on backlight mode for indicator */ + indicator_enable(); + + animation_state = BAT_LVL_ANI_GROWING; + bat_percentage = percentage; + bat_lvl_ani_timer_buffer = sync_timer_read32(); + cur_percentage = 0; + time_interval = BAT_LEVEL_GROWING_INTERVAL; +#ifdef RGB_MATRIX_ENABLE + r = g = b = 255; +#endif +} + +void bat_level_animiation_stop(void) { + animation_state = BAT_LVL_ANI_NONE; +} + +bool bat_level_animiation_actived(void) { + return animation_state; +} + +void bat_level_animiation_indicate(void) { +#ifdef LED_MATRIX_ENABLE + uint8_t bat_lvl_led_list[10] = BAT_LEVEL_LED_LIST; + + for (uint8_t i = 0; i <= LED_MATRIX_LED_COUNT; i++) { + led_matrix_set_value(i, 0); + } + + if (animation_state == BAT_LVL_ANI_GROWING || animation_state == BAT_LVL_ANI_BLINK_ON) + for (uint8_t i = 0; i < cur_percentage / 10; i++) + led_matrix_set_value(bat_lvl_led_list[i], 255); +#endif + +#ifdef RGB_MATRIX_ENABLE + uint8_t bat_lvl_led_list[10] = BAT_LEVEL_LED_LIST; + + for (uint8_t i = 0; i <= RGB_MATRIX_LED_COUNT; i++) { + rgb_matrix_set_color(i, 0, 0, 0); + } + + if (animation_state == BAT_LVL_ANI_GROWING || animation_state == BAT_LVL_ANI_BLINK_ON) { + for (uint8_t i = 0; i < cur_percentage / 10; i++) { + rgb_matrix_set_color(bat_lvl_led_list[i], r, g, b); + } + } +#endif +} + +void bat_level_animiation_update(void) { + switch (animation_state) { + case BAT_LVL_ANI_GROWING: + if (cur_percentage < bat_percentage) + cur_percentage += 10; + else { + if (cur_percentage == 0) cur_percentage = 10; + animation_state = BAT_LVL_ANI_BLINK_OFF; + } + break; + + case BAT_LVL_ANI_BLINK_OFF: +#ifdef RGB_MATRIX_ENABLE + if (bat_percentage < 30) { + r = 255; + b = g = 0; + } else { + r = b = 0; + g = 255; + } +#endif + time_interval = BAT_LEVEL_ON_INTERVAL; + animation_state = BAT_LVL_ANI_BLINK_ON; + break; + + case BAT_LVL_ANI_BLINK_ON: + animation_state = BAT_LVL_ANI_NONE; + indicator_eeconfig_reload(); + if (indicator_config.value == 0 && !LED_DRIVER_IS_ENABLED()) { + indicator_disable(); + } + break; + + default: + break; + } + + bat_lvl_ani_timer_buffer = sync_timer_read32(); +} + +void bat_level_animiation_task(void) { + if (animation_state && sync_timer_elapsed32(bat_lvl_ani_timer_buffer) > time_interval) { + bat_level_animiation_update(); + } +} diff --git a/keyboards/keychron/bluetooth/bat_level_animation.h b/keyboards/keychron/bluetooth/bat_level_animation.h new file mode 100644 index 0000000000..716e924103 --- /dev/null +++ b/keyboards/keychron/bluetooth/bat_level_animation.h @@ -0,0 +1,23 @@ +/* Copyright 2022 @ lokher (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 . + */ + +#pragma once + +void bat_level_animiation_start(uint8_t percentage); +void bat_level_animiation_stop(void); +bool bat_level_animiation_actived(void); +void bat_level_animiation_indicate(void); +void bat_level_animiation_task(void); diff --git a/keyboards/keychron/bluetooth/battery.c b/keyboards/keychron/bluetooth/battery.c new file mode 100644 index 0000000000..8c6438d4c5 --- /dev/null +++ b/keyboards/keychron/bluetooth/battery.c @@ -0,0 +1,140 @@ +/* Copyright 2022 @ lokher (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 . + */ + +#include "quantum.h" +#include "bluetooth.h" +#include "battery.h" +#include "transport.h" +#include "ckbt51.h" +#include "lpm.h" +#include "indicator.h" +#include "rtc_timer.h" + +#define BATTERY_EMPTY_COUNT 10 +#define CRITICAL_LOW_COUNT 20 + +static uint32_t bat_monitor_timer_buffer = 0; +static uint16_t voltage = FULL_VOLTAGE_VALUE; +static uint8_t bat_empty = 0; +static uint8_t critical_low = 0; +static uint8_t bat_state; +static uint8_t power_on_sample = 0; + +void battery_init(void) { + bat_state = BAT_NOT_CHARGING; +} +__attribute__((weak)) void battery_measure(void) { + ckbt51_read_state_reg(0x05, 0x02); +} + +/* Calculate the voltage */ +__attribute__((weak)) void battery_calculate_voltage(uint16_t value) {} + +void battery_set_voltage(uint16_t value) { + voltage = value; +} + +uint16_t battery_get_voltage(void) { + return voltage; +} + +uint8_t battery_get_percentage(void) { + if (voltage > FULL_VOLTAGE_VALUE) return 100; + + if (voltage > EMPTY_VOLTAGE_VALUE) { + return ((uint32_t)voltage - EMPTY_VOLTAGE_VALUE) * 80 / (FULL_VOLTAGE_VALUE - EMPTY_VOLTAGE_VALUE) + 20; + } + + if (voltage > SHUTDOWN_VOLTAGE_VALUE) { + return ((uint32_t)voltage - SHUTDOWN_VOLTAGE_VALUE) * 20 / (EMPTY_VOLTAGE_VALUE - SHUTDOWN_VOLTAGE_VALUE); + } else + return 0; +} + +bool battery_is_empty(void) { + return bat_empty > BATTERY_EMPTY_COUNT; +} + +bool battery_is_critical_low(void) { + return critical_low > CRITICAL_LOW_COUNT; +} + +void battery_check_empty(void) { + if (voltage < EMPTY_VOLTAGE_VALUE) { + if (bat_empty <= BATTERY_EMPTY_COUNT) { + if (++bat_empty > BATTERY_EMPTY_COUNT) { +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) + indicator_battery_low_enable(true); +#endif +#if defined(LOW_BAT_IND_INDEX) + indicator_battery_low_backlit_enable(true); +#endif + power_on_sample = VOLTAGE_POWER_ON_MEASURE_COUNT; + } + } + } +} + +void battery_check_critical_low(void) { + if (voltage < SHUTDOWN_VOLTAGE_VALUE) { + if (critical_low <= CRITICAL_LOW_COUNT) { + if (++critical_low > CRITICAL_LOW_COUNT) bluetooth_low_battery_shutdown(); + } + } else if (critical_low <= CRITICAL_LOW_COUNT) { + critical_low = 0; + } +} + +bool battery_power_on_sample(void) { + return power_on_sample < VOLTAGE_POWER_ON_MEASURE_COUNT; +} + +void battery_task(void) { + uint32_t t = rtc_timer_elapsed_ms(bat_monitor_timer_buffer); + if (get_transport() == TRANSPORT_BLUETOOTH && bluetooth_get_state() == BLUETOOTH_CONNECTED) { + if ((battery_power_on_sample() +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) + && !indicator_is_enabled() +#endif + && t > BACKLIGHT_OFF_VOLTAGE_MEASURE_INTERVAL) || + t > VOLTAGE_MEASURE_INTERVAL) { + + battery_check_empty(); + battery_check_critical_low(); + + bat_monitor_timer_buffer = rtc_timer_read_ms(); + if (bat_monitor_timer_buffer > RTC_MAX_TIME) { + bat_monitor_timer_buffer = 0; + rtc_timer_clear(); + } + + battery_measure(); + power_on_sample++; + if (power_on_sample > VOLTAGE_POWER_ON_MEASURE_COUNT) power_on_sample = VOLTAGE_POWER_ON_MEASURE_COUNT; + } + } + + if ((bat_empty || critical_low) && usb_power_connected()) { + bat_empty = false; + critical_low = false; +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) + indicator_battery_low_enable(false); +#endif +#if defined(LOW_BAT_IND_INDEX) + indicator_battery_low_backlit_enable(false); +#endif + } +} diff --git a/keyboards/keychron/bluetooth/battery.h b/keyboards/keychron/bluetooth/battery.h new file mode 100644 index 0000000000..45de2bc23a --- /dev/null +++ b/keyboards/keychron/bluetooth/battery.h @@ -0,0 +1,60 @@ +/* Copyright 2022 @ lokher (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 . + */ + +#pragma once + +enum { + BAT_NOT_CHARGING = 0, + BAT_CHARGING, + BAT_CHARGING_FINISHED, +}; + +#ifndef FULL_VOLTAGE_VALUE +# define FULL_VOLTAGE_VALUE 4100 +#endif + +#ifndef EMPTY_VOLTAGE_VALUE +# define EMPTY_VOLTAGE_VALUE 3500 +#endif + +#ifndef SHUTDOWN_VOLTAGE_VALUE +# define SHUTDOWN_VOLTAGE_VALUE 3300 +#endif + +#ifndef VOLTAGE_MEASURE_INTERVAL +# define VOLTAGE_MEASURE_INTERVAL 3000 +#endif + +#ifndef VOLTAGE_POWER_ON_MEASURE_COUNT +# define VOLTAGE_POWER_ON_MEASURE_COUNT 15 +#endif + +#ifndef BACKLIGHT_OFF_VOLTAGE_MEASURE_INTERVAL +# define BACKLIGHT_OFF_VOLTAGE_MEASURE_INTERVAL 200 +#endif + +void battery_init(void); +void battery_measure(void); +void battery_calculte_voltage(uint16_t value); +void battery_set_voltage(uint16_t value); +uint16_t battery_get_voltage(void); +uint8_t battery_get_percentage(void); +void indicator_battery_low_enable(bool enable); +bool battery_is_empty(void); +bool battery_is_critical_low(void); +bool battery_power_on_sample(void); + +void battery_task(void); diff --git a/keyboards/keychron/bluetooth/bluetooth.c b/keyboards/keychron/bluetooth/bluetooth.c new file mode 100644 index 0000000000..3f539e271f --- /dev/null +++ b/keyboards/keychron/bluetooth/bluetooth.c @@ -0,0 +1,493 @@ +/* Copyright 2022 @ lokher (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 . + */ + +#include "action.h" +#include "quantum.h" +#include "bluetooth.h" +#include "report_buffer.h" +#include "lpm.h" +#include "battery.h" +#include "indicator.h" +#include "transport.h" +#include "rtc_timer.h" + +extern uint8_t pairing_indication; +extern host_driver_t chibios_driver; +extern report_buffer_t kb_rpt; +extern uint32_t retry_time_buffer; +extern uint8_t retry; + +#ifdef NKRO_ENABLE +extern nkro_t nkro; +#endif + +static uint8_t host_index = 0; +static uint8_t led_state = 0; + +extern bluetooth_transport_t bluetooth_transport; +static bluetooth_state_t bt_state = BLUETOOTH_RESET; +static bool pincodeEntry = false; +uint8_t bluetooth_report_protocol = true; + +/* declarations */ +uint8_t bluetooth_keyboard_leds(void); +void bluetooth_send_keyboard(report_keyboard_t *report); +void bluetooth_send_nkro(report_nkro_t *report); +void bluetooth_send_mouse(report_mouse_t *report); +void bluetooth_send_extra(report_extra_t *report); + +/* host struct */ +host_driver_t bluetooth_driver = {bluetooth_keyboard_leds, bluetooth_send_keyboard, bluetooth_send_nkro, bluetooth_send_mouse, bluetooth_send_extra}; + +#define BLUETOOTH_EVENT_QUEUE_SIZE 16 +bluetooth_event_t bt_event_queue[BLUETOOTH_EVENT_QUEUE_SIZE]; +uint8_t bt_event_queue_head; +uint8_t bt_event_queue_tail; + +void bluetooth_bt_event_queue_init(void) { + // Initialise the event queue + memset(&bt_event_queue, 0, sizeof(bt_event_queue)); + bt_event_queue_head = 0; + bt_event_queue_tail = 0; +} + +bool bluetooth_event_queue_enqueue(bluetooth_event_t event) { + uint8_t next = (bt_event_queue_head + 1) % BLUETOOTH_EVENT_QUEUE_SIZE; + if (next == bt_event_queue_tail) { + /* Override the first report */ + bt_event_queue_tail = (bt_event_queue_tail + 1) % BLUETOOTH_EVENT_QUEUE_SIZE; + } + bt_event_queue[bt_event_queue_head] = event; + bt_event_queue_head = next; + return true; +} + +static inline bool bluetooth_event_queue_dequeue(bluetooth_event_t *event) { + if (bt_event_queue_head == bt_event_queue_tail) { + return false; + } + *event = bt_event_queue[bt_event_queue_tail]; + bt_event_queue_tail = (bt_event_queue_tail + 1) % BLUETOOTH_EVENT_QUEUE_SIZE; + return true; +} + +/* + * Bluetooth init. + */ +void bluetooth_init(void) { + bt_state = BLUETOOTH_INITIALIZED; + + bluetooth_bt_event_queue_init(); +#ifndef DISABLE_REPORT_BUFFER + report_buffer_init(); +#endif + indicator_init(); +#ifdef BLUETOOTH_INT_INPUT_PIN + setPinInputHigh(BLUETOOTH_INT_INPUT_PIN); +#endif + + lpm_init(); + rtc_timer_init(); + +#ifdef BLUETOOTH_NKRO_ENABLE + keymap_config.raw = eeconfig_read_keymap(); + nkro.bluetooth = keymap_config.nkro; +#endif +} + +/* + * Bluetooth trasponrt init. Bluetooth module driver shall use this function to register a callback + * to its implementation. + */ +void bluetooth_set_transport(bluetooth_transport_t *transport) { + if (transport) memcpy(&bluetooth_transport, transport, sizeof(bluetooth_transport_t)); +} + +/* + * Enter pairing with current host index + */ +void bluetooth_pairing(void) { + if (battery_is_critical_low()) return; + + bluetooth_pairing_ex(0, NULL); + bt_state = BLUETOOTH_PARING; +} + +/* + * Enter pairing with specified host index and param + */ +void bluetooth_pairing_ex(uint8_t host_idx, void *param) { + if (battery_is_critical_low()) return; + + if (bluetooth_transport.pairing_ex) bluetooth_transport.pairing_ex(host_idx, param); + bt_state = BLUETOOTH_PARING; + + host_index = host_idx; +} + +/* + * Initiate connection request to paired host + */ +void bluetooth_connect(void) { + /* Work around empty report after wakeup, which leads to reconneect/disconnected loop */ + if (battery_is_critical_low() || sync_timer_read32() == 0) return; + + bluetooth_transport.connect_ex(0, 0); + bt_state = BLUETOOTH_RECONNECTING; +} + +/* + * Initiate connection request to paired host with argument + */ +void bluetooth_connect_ex(uint8_t host_idx, uint16_t timeout) { + if (battery_is_critical_low()) return; + + if (host_idx != 0) { + if (host_index == host_idx && bt_state == BLUETOOTH_CONNECTED) return; + host_index = host_idx; + led_state = 0; + } + bluetooth_transport.connect_ex(host_idx, timeout); + bt_state = BLUETOOTH_RECONNECTING; +} + +/* Initiate a disconnection */ +void bluetooth_disconnect(void) { + if (bluetooth_transport.disconnect) bluetooth_transport.disconnect(); +} + +/* Called when the BT device is reset. */ +static void bluetooth_enter_reset(uint8_t reason) { + bt_state = BLUETOOTH_RESET; + bluetooth_enter_reset_kb(reason); +} + +/* Enters discoverable state. Upon entering this state we perform the following actions: + * - change state to BLUETOOTH_PARING + * - set pairing indication + */ +static void bluetooth_enter_discoverable(uint8_t host_idx) { + bt_state = BLUETOOTH_PARING; + indicator_set(bt_state, host_idx); + bluetooth_enter_discoverable_kb(host_idx); +} + +/* + * Enters reconnecting state. Upon entering this state we perform the following actions: + * - change state to RECONNECTING + * - set reconnect indication + */ +static void bluetooth_enter_reconnecting(uint8_t host_idx) { + bt_state = BLUETOOTH_RECONNECTING; + indicator_set(bt_state, host_idx); + bluetooth_enter_reconnecting_kb(host_idx); +} + +/* Enters connected state. Upon entering this state we perform the following actions: + * - change state to CONNECTED + * - set connected indication + * - enable bluetooth NKRO is support + */ +static void bluetooth_enter_connected(uint8_t host_idx) { + bt_state = BLUETOOTH_CONNECTED; + indicator_set(bt_state, host_idx); + host_index = host_idx; + + clear_keyboard(); + + /* Enable NKRO since it may be disabled in pin code entry */ +#if defined(NKRO_ENABLE) && defined(BLUETOOTH_NKRO_ENABLE) + keymap_config.nkro = nkro.bluetooth; +#else + keymap_config.nkro = false; +#endif + + bluetooth_enter_connected_kb(host_idx); +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) + if (battery_is_empty()) { + indicator_battery_low_enable(true); + } +#endif +} + +/* Enters disconnected state. Upon entering this state we perform the following actions: + * - change state to DISCONNECTED + * - set disconnected indication + */ +static void bluetooth_enter_disconnected(uint8_t host_idx) { + uint8_t previous_state = bt_state; + bt_state = BLUETOOTH_DISCONNECTED; + + if (previous_state == BLUETOOTH_CONNECTED) { + lpm_timer_reset(); + indicator_set(BLUETOOTH_SUSPEND, host_idx); + } else + indicator_set(bt_state, host_idx); + +#ifndef DISABLE_REPORT_BUFFER + report_buffer_init(); +#endif + retry = 0; + bluetooth_enter_disconnected_kb(host_idx); +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) + indicator_battery_low_enable(false); +#endif +#if defined(LOW_BAT_IND_INDEX) + indicator_battery_low_backlit_enable(false); +#endif +} + +/* Enter pin code entry state. */ +static void bluetooth_enter_pin_code_entry(void) { +#if defined(NKRO_ENABLE) + keymap_config.nkro = FALSE; +#endif + pincodeEntry = true; + bluetooth_enter_pin_code_entry_kb(); +} + +/* Exit pin code entry state. */ +static void bluetooth_exit_pin_code_entry(void) { +#if defined(NKRO_ENABLE) + keymap_config.nkro = true; +#endif + pincodeEntry = false; + bluetooth_exit_pin_code_entry_kb(); +} + +__attribute__((weak)) void bluetooth_enter_reset_kb(uint8_t reason){}; +__attribute__((weak)) void bluetooth_enter_discoverable_kb(uint8_t host_idx){}; +__attribute__((weak)) void bluetooth_enter_reconnecting_kb(uint8_t host_idx){}; +__attribute__((weak)) void bluetooth_enter_connected_kb(uint8_t host_idx){}; +__attribute__((weak)) void bluetooth_enter_disconnected_kb(uint8_t host_idx){}; +__attribute__((weak)) void bluetooth_enter_pin_code_entry_kb(void) {} +__attribute__((weak)) void bluetooth_exit_pin_code_entry_kb(void){}; + +/* */ +static void bluetooth_hid_set_protocol(bool report_protocol) { + bluetooth_report_protocol = false; +} + +uint8_t bluetooth_keyboard_leds(void) { + if (bt_state == BLUETOOTH_CONNECTED) { + return led_state; + } + + return 0; +} + +extern keymap_config_t keymap_config; + +void bluetooth_send_keyboard(report_keyboard_t *report) { + if (bt_state == BLUETOOTH_PARING && !pincodeEntry) return; + + if (bt_state == BLUETOOTH_CONNECTED || (bt_state == BLUETOOTH_PARING && pincodeEntry)) { + if (bluetooth_transport.send_keyboard) { +#ifndef DISABLE_REPORT_BUFFER + bool firstBuffer = false; + if (report_buffer_is_empty() && report_buffer_next_inverval() && report_buffer_get_retry() == 0) { + firstBuffer = true; + } + + report_buffer_t report_buffer; + report_buffer.type = REPORT_TYPE_KB; + memcpy(&report_buffer.keyboard, report, sizeof(report_keyboard_t)); + report_buffer_enqueue(&report_buffer); + + if (firstBuffer) { + report_buffer_set_retry(0); + report_buffer_task(); + } +#else + bluetooth_transport.send_keyboard(&report->nkro.mods); +#endif + } + } else if (bt_state != BLUETOOTH_RESET) { + bluetooth_connect(); + } +} +void bluetooth_send_nkro(report_nkro_t *report) { + if (bt_state == BLUETOOTH_PARING && !pincodeEntry) return; + + if (bt_state == BLUETOOTH_CONNECTED || (bt_state == BLUETOOTH_PARING && pincodeEntry)) { + if (bluetooth_transport.send_keyboard) { +#ifndef DISABLE_REPORT_BUFFER + if (report_buffer_is_empty() && report_buffer_next_inverval()) { + bluetooth_transport.send_keyboard(&report->mods); + report_buffer_update_timer(); + } else { + report_buffer_t report_buffer; + report_buffer.type = REPORT_TYPE_NKRO; + memcpy(&report_buffer.nkro, report, sizeof(report_nkro_t)); + report_buffer_enqueue(&report_buffer); + } +#else + bluetooth_transport.send_nkro(&report->mods); +#endif + } + } else if (bt_state != BLUETOOTH_RESET) { + bluetooth_connect(); + } +} + +void bluetooth_send_mouse(report_mouse_t *report) { + if (bt_state == BLUETOOTH_CONNECTED) { + if (bluetooth_transport.send_mouse) bluetooth_transport.send_mouse((uint8_t *)report); + } else if (bt_state != BLUETOOTH_RESET) { + bluetooth_connect(); + } +} + +void bluetooth_send_system(uint16_t data) { + if (bt_state == BLUETOOTH_CONNECTED) { + if (bluetooth_transport.send_system) bluetooth_transport.send_system(data); + } else if (bt_state != BLUETOOTH_RESET) { + bluetooth_connect(); + } +} + +void bluetooth_send_consumer(uint16_t data) { + if (bt_state == BLUETOOTH_CONNECTED) { +#ifndef DISABLE_REPORT_BUFFER + if (report_buffer_is_empty() && report_buffer_next_inverval()) { + if (bluetooth_transport.send_consumer) bluetooth_transport.send_consumer(data); + report_buffer_update_timer(); + } else { + report_buffer_t report_buffer; + report_buffer.type = REPORT_TYPE_CONSUMER; + report_buffer.consumer = data; + report_buffer_enqueue(&report_buffer); + } +#else + if (bluetooth_transport.send_consumer) bluetooth_transport.send_consumer(data); +#endif + } else if (bt_state != BLUETOOTH_RESET) { + bluetooth_connect(); + } +} + +void bluetooth_send_extra(report_extra_t *report) { + if (report->report_id == REPORT_ID_SYSTEM) { + bluetooth_send_system(report->usage); + } else if (report->report_id == REPORT_ID_CONSUMER) { + bluetooth_send_consumer(report->usage); + } +} + +void bluetooth_low_battery_shutdown(void) { +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) + indicator_battery_low_enable(false); +#endif +#if defined(LOW_BAT_IND_INDEX) + indicator_battery_low_backlit_enable(false); +#endif + clear_keyboard(); + send_keyboard_report(); + wait_ms(50); + bluetooth_disconnect(); +} + +void bluetooth_event_queue_task(void) { + bluetooth_event_t event; + while (bluetooth_event_queue_dequeue(&event)) { + switch (event.evt_type) { + case EVT_RESET: + bluetooth_enter_reset(event.params.reason); + break; + case EVT_CONNECTED: + bluetooth_enter_connected(event.params.hostIndex); + break; + case EVT_DISCOVERABLE: + bluetooth_enter_discoverable(event.params.hostIndex); + break; + case EVT_RECONNECTING: + bluetooth_enter_reconnecting(event.params.hostIndex); + break; + case EVT_DISCONNECTED: + led_state = 0; + bluetooth_enter_disconnected(event.params.hostIndex); + break; + case EVT_BT_PINCODE_ENTRY: + bluetooth_enter_pin_code_entry(); + break; + case EVT_EXIT_BT_PINCODE_ENTRY: + bluetooth_exit_pin_code_entry(); + break; + case EVT_HID_INDICATOR: + led_state = event.params.led; + break; + case EVT_HID_SET_PROTOCOL: + bluetooth_hid_set_protocol(event.params.protocol); + break; + case EVT_CONECTION_INTERVAL: + report_buffer_set_inverval(event.params.interval); + break; + default: + break; + } + } +} + +void bluetooth_task(void) { + bluetooth_transport.task(); + bluetooth_event_queue_task(); +#ifndef DISABLE_REPORT_BUFFER + report_buffer_task(); +#endif + indicator_task(); + battery_task(); + lpm_task(); +} + +void send_string_task(void) { + if (get_transport() == TRANSPORT_BLUETOOTH && bluetooth_get_state()== BLUETOOTH_CONNECTED) { + bluetooth_transport.task(); +#ifndef DISABLE_REPORT_BUFFER + report_buffer_task(); +#endif + } +} + +bluetooth_state_t bluetooth_get_state(void) { + return bt_state; +}; + +__attribute__((weak)) bool process_record_kb_bt(uint16_t keycode, keyrecord_t *record) { + return true; +}; + +bool process_record_kb(uint16_t keycode, keyrecord_t *record) { + if (!process_record_user(keycode, record)) { + return false; + } + + if (get_transport() == TRANSPORT_BLUETOOTH) { + lpm_timer_reset(); + +#if defined(BAT_LOW_LED_PIN) || defined(LOW_BAT_IND_INDEX) + if (battery_is_empty() && bluetooth_get_state() == BLUETOOTH_CONNECTED && record->event.pressed) { +# if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) + indicator_battery_low_enable(true); +# endif +# if defined(LOW_BAT_IND_INDEX) + indicator_battery_low_backlit_enable(true); +# endif + } +#endif + } + return process_record_kb_bt(keycode, record); + // return process_record_user(keycode, record); +} diff --git a/keyboards/keychron/bluetooth/bluetooth.h b/keyboards/keychron/bluetooth/bluetooth.h new file mode 100644 index 0000000000..44e8ffdc70 --- /dev/null +++ b/keyboards/keychron/bluetooth/bluetooth.h @@ -0,0 +1,89 @@ +/* Copyright 2022 @ lokher (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 . + */ + +#pragma once + +#include "bluetooth_event_type.h" +#include "action.h" + +/* Low power mode */ +#ifndef LOW_POWER_MODE +# define LOW_POWER_MODE PM_STOP1 +#endif + +/* Wake pin used for blueooth module/controller to wake up MCU in low power mode*/ +#ifndef BLUETOOTH_INT_INPUT_PIN +# define WAKE_PIN A5 +#endif + +/* Type of an enumeration of the possible BT state.*/ +typedef enum { + BLUETOOTH_RESET, + BLUETOOTH_INITIALIZED, // 1 + BLUETOOTH_DISCONNECTED, // 2 + BLUETOOTH_CONNECTED, // 3 + BLUETOOTH_PARING, // 4 + BLUETOOTH_RECONNECTING, // 5 + BLUETOOTH_SUSPEND +} bluetooth_state_t; + +extern event_listener_t bt_driver; + +typedef struct { + void (*init)(bool); + void (*connect_ex)(uint8_t, uint16_t); + void (*pairing_ex)(uint8_t, void *); + void (*disconnect)(void); + void (*send_keyboard)(uint8_t *); + void (*send_nkro)(uint8_t *); + void (*send_consumer)(uint16_t); + void (*send_system)(uint16_t); + void (*send_mouse)(uint8_t *); + void (*task)(void); +} bluetooth_transport_t; + +void bluetooth_init(void); +void bluetooth_set_transport(bluetooth_transport_t *transport); +void bluetooth_task(void); + +bool bluetooth_event_queue_enqueue(bluetooth_event_t event); + +void bluetooth_connect(void); +void bluetooth_connect_ex(uint8_t host_idx, uint16_t timeout); +void bluetooth_disconnect(void); + +void bluetooth_pairing(void); +void bluetooth_pairing_ex(uint8_t host_idx, void *param); +bool bluetooth_is_activated(void); + +void bluetooth_enter_reset_kb(uint8_t reason); +void bluetooth_enter_discoverable_kb(uint8_t host_idx); +void bluetooth_enter_reconnecting_kb(uint8_t host_idx); +void bluetooth_enter_connected_kb(uint8_t host_idx); +void bluetooth_enter_disconnected_kb(uint8_t host_idx); +void bluetooth_enter_pin_code_entry_kb(void); +void bluetooth_exit_pin_code_entry_kb(void); + +void bluetooth_task(void); +void bluetooth_pre_task(void); +void bluetooth_post_task(void); +void send_string_task(void); + +bluetooth_state_t bluetooth_get_state(void); + +void bluetooth_low_battery_shutdown(void); + +bool process_record_kb_bt(uint16_t keycode, keyrecord_t *record); diff --git a/keyboards/keychron/bluetooth/bluetooth.mk b/keyboards/keychron/bluetooth/bluetooth.mk new file mode 100644 index 0000000000..3a57a6d75d --- /dev/null +++ b/keyboards/keychron/bluetooth/bluetooth.mk @@ -0,0 +1,23 @@ + +OPT_DEFS += -DKC_BLUETOOTH_ENABLE + +BLUETOOTH_DIR = bluetooth +SRC += \ + $(BLUETOOTH_DIR)/bluetooth.c \ + $(BLUETOOTH_DIR)/report_buffer.c \ + $(BLUETOOTH_DIR)/ckbt51.c \ + $(BLUETOOTH_DIR)/indicator.c \ + $(BLUETOOTH_DIR)/bluetooth_main.c \ + $(BLUETOOTH_DIR)/transport.c \ + $(BLUETOOTH_DIR)/lpm.c \ + $(BLUETOOTH_DIR)/lpm_stm32l432.c \ + $(BLUETOOTH_DIR)/battery.c \ + $(BLUETOOTH_DIR)/factory_test.c \ + $(BLUETOOTH_DIR)/bat_level_animation.c \ + $(BLUETOOTH_DIR)/rtc_timer.c + +VPATH += $(TOP_DIR)/keyboards/keychron/$(BLUETOOTH_DIR) + +# Work around RTC clock issue without touching chibios, refer to the link for this bug +# https://forum.chibios.org/viewtopic.php?f=35&t=6197 +OPT_DEFS += -DRCC_APBENR1_RTCAPBEN diff --git a/keyboards/keychron/bluetooth/bluetooth_config.h b/keyboards/keychron/bluetooth/bluetooth_config.h new file mode 100644 index 0000000000..26dbc81f6c --- /dev/null +++ b/keyboards/keychron/bluetooth/bluetooth_config.h @@ -0,0 +1,38 @@ +/* Copyright 2022 @ lokher (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 . + */ + +#ifndef BLUETOOTH_CONFIG_H +#define BLUETOOTH_CONFIG_H + +#include "config.h" + +// +#ifndef HOST_DEVICES_COUNT +# define HOST_DEVICES_COUNT 3 +#endif + +// Uint: Second +#ifndef DISCONNECTED_BACKLIGHT_OFF_DELAY_TIME +# define DISCONNECTED_BACKLIGHT_OFF_DELAY_TIME 40 +#endif + +// Uint: Second, the timer restarts on key activities. +#ifndef CONNECTED_BACKLIGHT_OFF_DELAY_TIME +# define CONNECTED_BACKLIGHT_OFF_DELAY_TIME 600 +#endif + +#endif + diff --git a/keyboards/keychron/bluetooth/bluetooth_event_type.h b/keyboards/keychron/bluetooth/bluetooth_event_type.h new file mode 100644 index 0000000000..47d8adbcf4 --- /dev/null +++ b/keyboards/keychron/bluetooth/bluetooth_event_type.h @@ -0,0 +1,44 @@ +/* Copyright 2022 @ lokher (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 . + */ + +#pragma once + +/* Type of an enumeration of the possible BT events.*/ +typedef enum { + EVT_NONE = 0, + EVT_RESET, + EVT_DISCOVERABLE, + EVT_RECONNECTING, + EVT_CONNECTED, + EVT_DISCONNECTED, + EVT_BT_PINCODE_ENTRY, + EVT_EXIT_BT_PINCODE_ENTRY, + EVT_HID_SET_PROTOCOL, + EVT_HID_INDICATOR, + EVT_CONECTION_INTERVAL, +} event_type_t; + +typedef struct { + event_type_t evt_type; /*The type of the event. */ + union { + uint8_t reason; /* Parameters to BLUETOOTH_RESET event */ + uint8_t hostIndex; /* Parameters to connection event from EVT_DISCOVERABLE to EVT_DISCONECTED */ + uint8_t led; /* Parameters to EVT_HID_INDICATOR event */ + uint8_t protocol; /* Parameters to EVT_HID_SET_PROTOCOL event */ + uint8_t interval; /* Parameters to EVT_CONECTION_INTERVAL event */ + } params; +} bluetooth_event_t; + diff --git a/keyboards/keychron/bluetooth/bluetooth_main.c b/keyboards/keychron/bluetooth/bluetooth_main.c new file mode 100644 index 0000000000..eabcc83826 --- /dev/null +++ b/keyboards/keychron/bluetooth/bluetooth_main.c @@ -0,0 +1,37 @@ +/* Copyright 2022 @ lokher (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 . + */ + +#include "quantum.h" +#include "bluetooth.h" +#include "transport.h" + +__attribute__((weak)) void bluetooth_pre_task(void) {} +__attribute__((weak)) void bluetooth_post_task(void) {} + +void bluetooth_tasks(void) { + bluetooth_pre_task(); + bluetooth_task(); + bluetooth_post_task(); + + /* usb_remote_wakeup() should be invoked last so that we have chance + * to switch to bluetooth after start-up when usb is not connected + */ + if (get_transport() == TRANSPORT_USB) usb_remote_wakeup(); +} + +void housekeeping_task_kb(void) { + bluetooth_tasks(); +} diff --git a/keyboards/keychron/bluetooth/ckbt51.c b/keyboards/keychron/bluetooth/ckbt51.c new file mode 100644 index 0000000000..8c8233996e --- /dev/null +++ b/keyboards/keychron/bluetooth/ckbt51.c @@ -0,0 +1,606 @@ +/* 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 . + */ + +#include +#include "quantum.h" +#include "ckbt51.h" +#include "bluetooth.h" +#include "battery.h" +#include "raw_hid.h" +#include "report_buffer.h" + +#ifndef RAW_EPSIZE +# define RAW_EPSIZE 32 +#endif + +#ifndef CKBT51_INT_INPUT_PIN +# error "CKBT51_INT_INPUT_PIN is not defined" +#endif + +#ifndef CKBT51_TX_RETRY_COUNT +# define CKBT51_TX_RETRY_COUNT 3 +#endif + +/* CKBT51 disable its uart peripheral to save power if uart inactivity for 3s, need to + * assert this pin and wait some time for its uart getting ready before sending data*/ +#define CKBT51_WAKE_WAIT_TIME 3000 // us + +enum { + /* HID Report */ + CKBT51_CMD_SEND_KB = 0x11, + CKBT51_CMD_SEND_KB_NKRO = 0x12, + CKBT51_CMD_SEND_CONSUMER = 0x13, + CKBT51_CMD_SEND_SYSTEM = 0x14, + CKBT51_CMD_SEND_FN = 0x15, // Not used currently + CKBT51_CMD_SEND_MOUSE = 0x16, // Not used currently + CKBT51_CMD_SEND_BOOT_KB = 0x17, + /* Bluetooth connections */ + CKBT51_CMD_PAIRING = 0x21, + CKBT51_CMD_CONNECT = 0x22, + CKBT51_CMD_DISCONNECT = 0x23, + CKBT51_CMD_SWITCH_HOST = 0x24, + CKBT51_CMD_READ_STATE_REG = 0x25, + /* Battery */ + CKBT51_CMD_BATTERY_MANAGE = 0x31, + CKBT51_CMD_UPDATE_BAT_LVL = 0x32, + /* Set/get parameters */ + CKBT51_CMD_GET_MODULE_INFO = 0x40, + CKBT51_CMD_SET_CONFIG = 0x41, + CKBT51_CMD_GET_CONFIG = 0x42, + CKBT51_CMD_SET_BDA = 0x43, + CKBT51_CMD_GET_BDA = 0x44, + CKBT51_CMD_SET_NAME = 0x45, + CKBT51_CMD_GET_NAME = 0x46, + /* DFU */ + CKBT51_CMD_GET_DFU_VER = 0x60, + CKBT51_CMD_HAND_SHAKE_TOKEN = 0x61, + CKBT51_CMD_START_DFU = 0x62, + CKBT51_CMD_SEND_FW_DATA = 0x63, + CKBT51_CMD_VERIFY_CRC32 = 0x64, + CKBT51_CMD_SWITCH_FW = 0x65, + /* Factory test */ + CKBT51_CMD_FACTORY_RESET = 0x71, + CKBT51_CMD_INT_PIN_TEST = 0x72, + CKBT51_CMD_RADIO_TEST = 0x73, + /* Event */ + CKBT51_EVT_CKBT51_CMD_RECEIVED = 0xA1, + CKBT51_EVT_OTA_RSP = 0xA3, + CKBT51_CONNECTION_EVT_ACK = 0xA4, +}; + +enum { + CKBT51_EVT_ACK = 0xA1, + CKBT51_EVT_QUERY_RSP = 0xA2, + CKBT51_EVT_RESET = 0xB0, + CKBT51_EVT_LE_CONNECTION = 0xB1, + CKBT51_EVT_HOST_TYPE = 0xB2, + CKBT51_EVT_CONNECTION = 0xB3, + CKBT51_EVT_HID_EVENT = 0xB4, + CKBT51_EVT_BATTERY = 0xB5, +}; + +enum { CKBT51_CONNECTED = 0x20, CKBT51_DISCOVERABLE = 0x21, CKBT51_RECONNECTING = 0x22, CKBT51_DISCONNECTED = 0x23, CKBT51_PINCODE_ENTRY = 0x24, CKBT51_EXIT_PINCODE_ENTRY = 0x25 }; + +enum { + ACK_SUCCESS = 0x00, + ACK_CHECKSUM_ERROR, + ACK_FIFO_HALF_WARNING, + ACK_FIFO_FULL_ERROR, +}; + +static uint8_t payload[PACKET_MAX_LEN]; +static uint8_t reg_offset = 0xFF; + +bluetooth_transport_t bluetooth_transport = {ckbt51_init, ckbt51_connect, ckbt51_become_discoverable, ckbt51_disconnect, ckbt51_send_keyboard, ckbt51_send_nkro, ckbt51_send_consumer, ckbt51_send_system, ckbt51_send_mouse, ckbt51_task}; + +void ckbt51_init(bool wakeup_from_low_power_mode) { +#if (HAL_USE_SERIAL == TRUE) + SerialConfig config = {460800, 0, USART_CR2_STOP1_BITS, 0}; + + if (wakeup_from_low_power_mode) { + sdInit(); + sdStart(&WT_DRIVER, &config); + + return; + } + + sdStart(&WT_DRIVER, &config); + palSetPadMode(WT_DRIVER_UART_TX_BANK, WT_DRIVER_UART_TX, PAL_MODE_ALTERNATE(WT_DRIVER_UART_TX_PAL_MODE)); + palSetPadMode(WT_DRIVER_UART_RX_BANK, WT_DRIVER_UART_RX, PAL_MODE_ALTERNATE(WT_DRIVER_UART_RX_PAL_MODE)); +#endif + + setPinOutput(CKBT51_INT_INPUT_PIN); + writePinHigh(CKBT51_INT_INPUT_PIN); +} + +void ckbt51_send_cmd(uint8_t* payload, uint8_t len, bool ack_enable, bool retry) { + static uint8_t sn = 0; + uint8_t i; + uint8_t pkt[PACKET_MAX_LEN] = {0}; + memset(pkt, 0, PACKET_MAX_LEN); + + if (!retry) ++sn; + if (sn == 0) ++sn; + + systime_t start = 0; + + for (i = 0; i < 3; i++) { + writePin(CKBT51_INT_INPUT_PIN, i % 2); + start = chVTGetSystemTime(); + while (chTimeI2US(chVTTimeElapsedSinceX(start)) < CKBT51_WAKE_WAIT_TIME / 3) { + }; + } + writePinHigh(CKBT51_INT_INPUT_PIN); + + uint16_t checksum = 0; + for (i = 0; i < len; i++) + checksum += payload[i]; + + i = 0; + pkt[i++] = 0xAA; + pkt[i++] = ack_enable ? 0x56 : 0x55; + pkt[i++] = len + 2; + pkt[i++] = ~(len + 2) & 0xFF; + pkt[i++] = sn; + memcpy(pkt + i, payload, len); + i += len; + pkt[i++] = checksum & 0xFF; + pkt[i++] = (checksum >> 8) & 0xFF; + + sdWrite(&WT_DRIVER, pkt, i); +} + +void ckbt51_send_keyboard(uint8_t* report) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = CKBT51_CMD_SEND_KB; + memcpy(payload + i, report, 8); + i += 8; + + ckbt51_send_cmd(payload, i, true, false); +} + +void ckbt51_send_nkro(uint8_t* report) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = CKBT51_CMD_SEND_KB_NKRO; + memcpy(payload + i, report, 20); // NKRO report lenght is limited to 20 bytes + i += 20; + + ckbt51_send_cmd(payload, i, true, false); +} + +void ckbt51_send_consumer(uint16_t report) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = CKBT51_CMD_SEND_CONSUMER; + payload[i++] = report & 0xFF; + payload[i++] = ((report) >> 8) & 0xFF; + i += 4; // QMK doesn't send multiple consumer reports, just skip 2nd and 3rd consumer reports + + ckbt51_send_cmd(payload, i, true, false); +} + +void ckbt51_send_system(uint16_t report) { + /* CKBT51 supports only System Sleep */ + if ((report & 0xFF) != 0x82) return; + + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = CKBT51_CMD_SEND_SYSTEM; + payload[i++] = 0x01 << ((report & 0xFF) - 0x82); + + ckbt51_send_cmd(payload, i, true, false); +} + +void ckbt51_send_mouse(uint8_t* report) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = CKBT51_CMD_SEND_MOUSE; // Cmd type + payload[i++] = report[1]; // Button + payload[i++] = report[2]; // X + payload[i++] = (report[2] & 0x80) ? 0xff : 0x00; // ckbt51 use 16bit report, set high byte + payload[i++] = report[3]; // Y + payload[i++] = (report[3] & 0x80) ? 0xff : 0x00; // ckbt51 use 16bit report, set high byte + payload[i++] = report[4]; // V wheel + payload[i++] = report[5]; // H wheel + + ckbt51_send_cmd(payload, i, false, false); +} + +/* Send ack to connection event, bluetooth module will retry 2 times if no ack received */ +void ckbt51_send_conn_evt_ack(void) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = CKBT51_CONNECTION_EVT_ACK; + + ckbt51_send_cmd(payload, i, false, false); +} + +void ckbt51_become_discoverable(uint8_t host_idx, void* param) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + pairing_param_t default_pairing_param = {0, 0, PAIRING_MODE_LESC_OR_SSP, BT_MODE_CLASSIC, 0, NULL}; + + if (param == NULL) { + param = &default_pairing_param; + } + pairing_param_t* p = (pairing_param_t*)param; + + payload[i++] = CKBT51_CMD_PAIRING; // Cmd type + payload[i++] = host_idx; // Host Index + payload[i++] = p->timeout & 0xFF; // Timeout + payload[i++] = (p->timeout >> 8) & 0xFF; + payload[i++] = p->pairingMode; + payload[i++] = p->BRorLE; // BR/LE + payload[i++] = p->txPower; // LE TX POWER + if (p->leName) { + memcpy(&payload[i], p->leName, strlen(p->leName)); + i += strlen(p->leName); + } + + ckbt51_send_cmd(payload, i, true, false); +} + +/* Timeout : 2 ~ 255 seconds */ +void ckbt51_connect(uint8_t hostIndex, uint16_t timeout) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = CKBT51_CMD_CONNECT; + payload[i++] = hostIndex; // Host index + payload[i++] = timeout & 0xFF; // Timeout + payload[i++] = (timeout >> 8) & 0xFF; + + ckbt51_send_cmd(payload, i, true, false); +} + +void ckbt51_disconnect(void) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = CKBT51_CMD_DISCONNECT; + payload[i++] = 0; // Sleep mode + + ckbt51_send_cmd(payload, i, true, false); +} + +void ckbt51_switch_host(uint8_t hostIndex) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = CKBT51_CMD_SWITCH_HOST; + payload[i++] = hostIndex; + + ckbt51_send_cmd(payload, i, true, false); +} + +void ckbt51_read_state_reg(uint8_t reg, uint8_t len) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = CKBT51_CMD_READ_STATE_REG; + payload[i++] = reg_offset = reg; + payload[i++] = len; + + // TODO + ckbt51_send_cmd(payload, i, false, false); +} + +void ckbt51_get_info(module_info_t* info) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = CKBT51_CMD_GET_MODULE_INFO; + ckbt51_send_cmd(payload, i, false, false); +} + +void ckbt51_set_param(module_param_t* param) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = CKBT51_CMD_SET_CONFIG; + memcpy(payload + i, param, sizeof(module_param_t)); + i += sizeof(module_param_t); + + ckbt51_send_cmd(payload, i, true, false); +} + +void ckbt51_get_param(module_param_t* param) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = CKBT51_CMD_GET_CONFIG; + + ckbt51_send_cmd(payload, i, false, false); +} + +void ckbt51_set_local_name(const char* name) { + uint8_t i = 0; + uint8_t len = strlen(name); + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = CKBT51_CMD_SET_NAME; + memcpy(payload + i, name, len); + i += len; + ckbt51_send_cmd(payload, i, true, false); +} + +void ckbt51_get_local_name(void) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = CKBT51_CMD_GET_NAME; + + ckbt51_send_cmd(payload, i, false, false); +} + +void ckbt51_factory_reset(void) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = CKBT51_CMD_FACTORY_RESET; + + ckbt51_send_cmd(payload, i, false, false); +} + +void ckbt51_int_pin_test(bool enable) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + payload[i++] = CKBT51_CMD_INT_PIN_TEST; + payload[i++] = enable; + + ckbt51_send_cmd(payload, i, false, false); +} + +void ckbt51_radio_test(uint8_t channel) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + payload[i++] = CKBT51_CMD_RADIO_TEST; + payload[i++] = channel; + payload[i++] = 0; + + ckbt51_send_cmd(payload, i, false, false); +} + +void ckbt51_dfu_tx(uint8_t rsp, uint8_t* data, uint8_t len, uint8_t sn) { + uint16_t checksum = 0; + uint8_t buf[RAW_EPSIZE] = {0}; + uint8_t i = 0; + + buf[i++] = 0x03; + buf[i++] = 0xAA; + buf[i++] = 0x57; + buf[i++] = len; + buf[i++] = ~len; + buf[i++] = sn; + buf[i++] = rsp; + memcpy(&buf[i], data, len); + i += len; + + for (uint8_t k = 0; k < i; k++) + checksum += buf[i]; + + raw_hid_send(buf, RAW_EPSIZE); + + if (len > 25) { + i = 0; + memset(buf, 0, RAW_EPSIZE); + buf[i++] = 0x03; + memcpy(&buf[i], data + 25, len - 25); + i = i + len - 25; + raw_hid_send(buf, RAW_EPSIZE); + } +} + +void ckbt51_dfu_rx(uint8_t* data, uint8_t length) { + if (data[0] == 0xAA && (data[1] == 0x55 || data[1] == 0x56) && data[2] == (~data[3] & 0xFF)) { + uint16_t checksum = 0; + uint8_t payload_len = data[2]; + + /* Check payload_len validity */ + if (payload_len > RAW_EPSIZE - PACKECT_HEADER_LEN) return; + + uint8_t* payload = &data[PACKECT_HEADER_LEN]; + + for (uint8_t i = 0; i < payload_len - 2; i++) { + checksum += payload[i]; + } + + /* Verify checksum */ + if ((checksum & 0xFF) != payload[payload_len - 2] || checksum >> 8 != payload[payload_len - 1]) return; + static uint8_t sn = 0; + + bool retry = true; + if (sn != data[4]) { + sn = data[4]; + retry = false; + } + + if ((payload[0] & 0xF0) == 0x60) { + ckbt51_send_cmd(payload, payload_len - 2, data[1] == 0x56, retry); + } + } +} + +__attribute__((weak)) void ckbt51_default_ack_handler(uint8_t* data, uint8_t len){}; + +static void ack_handler(uint8_t* data, uint8_t len) { + switch (data[1]) { + case CKBT51_CMD_SEND_KB: + case CKBT51_CMD_SEND_KB_NKRO: + case CKBT51_CMD_SEND_CONSUMER: + case CKBT51_CMD_SEND_SYSTEM: + case CKBT51_CMD_SEND_MOUSE: + switch (data[2]) { + case ACK_SUCCESS: + report_buffer_set_retry(0); + report_buffer_set_inverval(DEFAULT_REPORT_INVERVAL_MS); + break; + case ACK_FIFO_HALF_WARNING: + report_buffer_set_retry(0); + report_buffer_set_inverval(DEFAULT_REPORT_INVERVAL_MS + 5); + break; + case ACK_FIFO_FULL_ERROR: + report_buffer_set_retry(10); + break; + } + break; + default: + ckbt51_default_ack_handler(data, len); + break; + } +} + +static void query_rsp_handler(uint8_t* data, uint8_t len) { + if (data[2]) return; + + switch (data[1]) { + case CKBT51_CMD_READ_STATE_REG: + switch (reg_offset) { + case 0x05: + battery_calculte_voltage(data[3] | (data[4] << 8)); + break; + } + reg_offset = 0xFF; + break; + default: + break; + } +} + +static void ckbt51_event_handler(uint8_t evt_type, uint8_t* data, uint8_t len, uint8_t sn) { + bluetooth_event_t event = {0}; + + switch (evt_type) { + case CKBT51_EVT_ACK: + ack_handler(data, len); + break; + case CKBT51_EVT_RESET: + dprintf("CKBT51_EVT_RESET\n"); + event.evt_type = EVT_RESET; + event.params.reason = data[0]; + break; + case CKBT51_EVT_LE_CONNECTION: + dprintf("CKBT51_EVT_LE_CONNECTION\n"); + break; + case CKBT51_EVT_HOST_TYPE: + dprintf("CKBT51_EVT_HOST_TYPE\n"); + break; + case CKBT51_EVT_CONNECTION: + dprintf("CKBT51_EVT_CONNECTION %d\n", data[0]); + /* Only connection status change message will retry 2 times if no ack */ + ckbt51_send_conn_evt_ack(); + switch (data[0]) { + case CKBT51_CONNECTED: + event.evt_type = EVT_CONNECTED; + break; + case CKBT51_DISCOVERABLE: + event.evt_type = EVT_DISCOVERABLE; + break; + case CKBT51_RECONNECTING: + event.evt_type = EVT_RECONNECTING; + break; + case CKBT51_DISCONNECTED: + event.evt_type = EVT_DISCONNECTED; + break; + case CKBT51_PINCODE_ENTRY: + event.evt_type = EVT_BT_PINCODE_ENTRY; + break; + case CKBT51_EXIT_PINCODE_ENTRY: + event.evt_type = EVT_EXIT_BT_PINCODE_ENTRY; + break; + } + event.params.hostIndex = data[2]; + break; + case CKBT51_EVT_HID_EVENT: + dprintf("CKBT51_EVT_HID_EVENT\n"); + event.evt_type = EVT_HID_INDICATOR; + event.params.led = data[0]; + break; + case CKBT51_EVT_QUERY_RSP: + dprintf("CKBT51_EVT_QUERY_RSP\n"); + query_rsp_handler(data, len); + break; + case CKBT51_EVT_OTA_RSP: + dprintf("CKBT51_EVT_OTA_RSP\n"); + ckbt51_dfu_tx(CKBT51_EVT_OTA_RSP, data, len, sn); + break; + case CKBT51_EVT_BATTERY: + if (data[0] == 0x01) { + dprintf("CKBT51_EVT_BATTERY\n"); + battery_calculte_voltage(data[1] | (data[2] << 8)); + } + break; + default: + dprintf("Unknown event!!!\n"); + break; + } + + if (event.evt_type) bluetooth_event_queue_enqueue(event); +} + +void ckbt51_task(void) { + static bool wait_for_new_pkt = true; + static uint8_t len = 0xff; + static uint8_t sn = 0; + + if (wait_for_new_pkt && WT_DRIVER.iqueue.q_counter >= PACKECT_HEADER_LEN) { + uint8_t buf[32] = {0}; + + if (wait_for_new_pkt) { + if (sdGet(&WT_DRIVER) == 0xAA && sdGet(&WT_DRIVER) == 0x57) { + for (uint8_t i = 0; i < 3; i++) { + buf[i] = sdGet(&WT_DRIVER); + } + // Check wheather len is valid + if ((~buf[0] & 0xFF) == buf[1]) { + len = buf[0]; + sn = buf[2]; + + wait_for_new_pkt = false; + } + } + } + } + + if (!wait_for_new_pkt && WT_DRIVER.iqueue.q_counter >= len) { + uint8_t buf[32] = {0}; + + for (uint8_t i = 0; i < len; i++) { + buf[i] = sdGetTimeout(&WT_DRIVER, TIME_IMMEDIATE); + } + + wait_for_new_pkt = true; + + uint16_t checksum = 0; + for (int i = 0; i < len - 2; i++) + checksum += buf[i]; + + if ((checksum & 0xff) == buf[len - 2] && ((checksum >> 8) & 0xff) == buf[len - 1]) { + ckbt51_event_handler(buf[0], buf + 1, len - 3, sn); + } else { + // TODO: Error handle + } + } +} diff --git a/keyboards/keychron/bluetooth/ckbt51.h b/keyboards/keychron/bluetooth/ckbt51.h new file mode 100644 index 0000000000..123290f949 --- /dev/null +++ b/keyboards/keychron/bluetooth/ckbt51.h @@ -0,0 +1,157 @@ +/* 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 . + */ + +#pragma once + +#include "stdint.h" + +#ifdef WT_DRIVER_UART_BANK +# define WT_DRIVER_UART_TX_BANK WT_DRIVER_UART_BANK +# define WT_DRIVER_UART_RX_BANK WT_DRIVER_UART_BANK +#endif + +#ifndef WT_DRIVER_UART_TX_BANK +# define WT_DRIVER_UART_TX_BANK GPIOA +#endif + +#ifndef WT_DRIVER_UART_RX_BANK +# define WT_DRIVER_UART_RX_BANK GPIOA +#endif + +#ifndef WT_DRIVER_UART_TX +# define WT_DRIVER_UART_TX 2 +#endif + +#ifndef WT_DRIVER_UART_RX +# define WT_DRIVER_UART_RX 3 +#endif + +#ifndef WT_DRIVER +# define WT_DRIVER SD2 +#endif + +#ifdef USE_GPIOV1 +# ifndef WT_DRIVER_UART_TX_PAL_MODE +# define WT_DRIVER_UART_TX_PAL_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL +# endif +# ifndef WT_DRIVER_UART_RX_PAL_MODE +# define WT_DRIVER_UART_RX_PAL_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL +# endif +#else +// The default PAL alternate modes are used to signal that the pins are used for I2C +# ifndef WT_DRIVER_UART_TX_PAL_MODE +# define WT_DRIVER_UART_TX_PAL_MODE 7 +# endif +# ifndef WT_DRIVER_UART_RX_PAL_MODE +# define WT_DRIVER_UART_RX_PAL_MODE 7 +# endif +#endif + +// Error checking +#if !STM32_SERIAL_USE_USART1 && !STM32_SERIAL_USE_USART2 && !STM32_SERIAL_USE_USART3 && !STM32_SERIAL_USE_UART4 && !STM32_SERIAL_USE_UART5 && !STM32_SERIAL_USE_USART6 && !STM32_SERIAL_USE_UART7 && !STM32_SERIAL_USE_UART8 && !STM32_SERIAL_USE_LPUART1 +# error "BT driver activated but no USART/UART peripheral assigned" +#endif + +#define PACKECT_HEADER_LEN 5 +#define BDA_LEN 6 +#define PACKET_MAX_LEN 64 + +enum { + PAIRING_MODE_DEFAULT = 0x00, + PAIRING_MODE_JUST_WORK, + PAIRING_MODE_PASSKEY_ENTRY, + PAIRING_MODE_LESC_OR_SSP, + PAIRING_MODE_INVALID +}; + +enum { + BT_MODE_DEFAUL, + BT_MODE_CLASSIC, + BT_MODE_LE, // Note: CKBT51 doesn't support BLE + BT_MODE_INVALID, +}; + +typedef struct { + uint8_t hostIndex; + uint16_t timeout; /* Pairing timeout, valid value range from 30 to 3600 seconds, 0 for default */ + uint8_t pairingMode; /* 0: default, 1: Just Works, 2: Passkey Entry */ + uint8_t BRorLE; /* Only available for dual mode module. Keep 0 for single mode module */ + uint8_t txPower; /* Only available for BLE module */ + const char* leName; /* Only available for BLE module */ +} pairing_param_t; + +typedef struct { + uint8_t type; + uint16_t full_votage; + uint16_t empty_voltage; + uint16_t shutdown_voltage; +} battery_param_t; + +typedef struct { + uint8_t model_name[11]; + uint8_t mode; + uint8_t bluetooth_version; + uint8_t firmware_version[11]; + uint8_t hardware_version[11]; + uint16_t cmd_set_verson; +} __attribute__((packed)) module_info_t; + +typedef struct { + uint8_t event_mode; /* Must be 0x02 */ + uint16_t connected_idle_timeout; + uint16_t pairing_timeout; /* Range: 30 ~ 3600 second, 0 for default */ + uint8_t pairing_mode; /* 0: default, 1: Just Works, 2: Passkey Entry */ + uint16_t reconnect_timeout; /* 0: default, 0xFF: Unlimited time, 2 ~ 254 seconds */ + uint8_t report_rate; /* 90 or 133 */ + uint8_t rsvd1; + uint8_t rsvd2; + uint8_t vendor_id_source; /* 0: From Bluetooth SIG, 1: From USB-IF */ + uint16_t verndor_id; /* No effect, the vendor ID is 0x3434 */ + uint16_t product_id; + /* Below parametes is only available for BLE module */ + uint16_t le_connection_interval_min; + uint16_t le_connection_interval_max; + uint16_t le_connection_interval_timeout; +} __attribute__((packed)) module_param_t; + +void ckbt51_init(bool wakeup_from_low_power_mode); +void ckbt51_send_cmd(uint8_t* payload, uint8_t len, bool ack_enable, bool retry); + +void ckbt51_send_keyboard(uint8_t* report); +void ckbt51_send_nkro(uint8_t* report); +void ckbt51_send_consumer(uint16_t report); +void ckbt51_send_system(uint16_t report); +void ckbt51_send_mouse(uint8_t* report); + +void ckbt51_become_discoverable(uint8_t host_idx, void* param); +void ckbt51_connect(uint8_t hostIndex, uint16_t timeout); +void ckbt51_disconnect(void); +void ckbt51_switch_host(uint8_t hostIndex); +void ckbt51_read_state_reg(uint8_t reg, uint8_t len); + +void ckbt51_get_info(module_info_t* info); +void ckbt51_set_param(module_param_t* param); +void ckbt51_get_param(module_param_t* param); +void ckbt51_set_local_name(const char* name); +void ckbt51_get_local_name(void); + +void ckbt51_factory_reset(void); +void ckbt51_int_pin_test(bool enable); +void ckbt51_dfu_rx(uint8_t* data, uint8_t length); +void ckbt51_radio_test(uint8_t channel); + +void ckbt51_task(void); + diff --git a/keyboards/keychron/bluetooth/factory_test.c b/keyboards/keychron/bluetooth/factory_test.c new file mode 100644 index 0000000000..ebf5f4fef6 --- /dev/null +++ b/keyboards/keychron/bluetooth/factory_test.c @@ -0,0 +1,343 @@ +/* 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 . + */ + +#include "quantum.h" +#include "raw_hid.h" +#ifdef KC_BLUETOOTH_ENABLE +# include "transport.h" +# include "ckbt51.h" +#endif + +#ifndef RAW_EPSIZE +# define RAW_EPSIZE 32 +#endif + +#ifndef BL_TEST_KEY1 +# define BL_TEST_KEY1 KC_RIGHT +#endif + +#ifndef BL_TEST_KEY2 +# define BL_TEST_KEY2 KC_HOME +#endif + +extern bool bt_factory_reset; + +enum { + BACKLIGHT_TEST_OFF = 0, + BACKLIGHT_TEST_WHITE, + BACKLIGHT_TEST_RED, + BACKLIGHT_TEST_GREEN, + BACKLIGHT_TEST_BLUE, + BACKLIGHT_TEST_MAX, +}; + +enum { + KEY_PRESS_FN = 0x01 << 0, + KEY_PRESS_J = 0x01 << 1, + KEY_PRESS_Z = 0x01 << 2, + KEY_PRESS_BL_KEY1 = 0x01 << 3, + KEY_PRESS_BL_KEY2 = 0x01 << 4, + KEY_PRESS_FACTORY_RESET = KEY_PRESS_FN | KEY_PRESS_J | KEY_PRESS_Z, + 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, +}; + +enum { + OS_SWITCH = 0x01, +}; + +static uint32_t factory_reset_timer = 0; +static uint8_t factory_reset_state = 0; +static uint8_t backlight_test_mode = BACKLIGHT_TEST_OFF; + +static uint32_t factory_reset_ind_timer = 0; +static uint8_t factory_reset_ind_state = 0; +static bool report_os_sw_state = false; + +void factory_timer_start(void) { + factory_reset_timer = timer_read32() == 0 ? 1 : timer_read32(); +} + +static inline void factory_timer_check(void) { + if (sync_timer_elapsed32(factory_reset_timer) > 3000) { + factory_reset_timer = 0; + + if (factory_reset_state == KEY_PRESS_FACTORY_RESET) { + factory_reset_ind_timer = timer_read32() == 0 ? 1 : timer_read32(); + factory_reset_ind_state++; + + layer_state_t default_layer_tmp = default_layer_state; + eeconfig_init(); + default_layer_set(default_layer_tmp); +#ifdef LED_MATRIX_ENABLE + if (!led_matrix_is_enabled()) led_matrix_enable(); + led_matrix_init(); +#endif +#ifdef RGB_MATRIX_ENABLE + if (!rgb_matrix_is_enabled()) rgb_matrix_enable(); + rgb_matrix_init(); +#endif +#ifdef KC_BLUETOOTH_ENABLE + ckbt51_factory_reset(); + bt_factory_reset = true; +#endif + } else if (factory_reset_state == KEY_PRESS_BACKLIGTH_TEST) { +#ifdef LED_MATRIX_ENABLE + if (!led_matrix_is_enabled()) led_matrix_enable(); +#endif +#ifdef RGB_MATRIX_ENABLE + if (!rgb_matrix_is_enabled()) rgb_matrix_enable(); +#endif + backlight_test_mode = BACKLIGHT_TEST_WHITE; + } + + factory_reset_state = 0; + } +} + +static inline void factory_reset_ind_timer_check(void) { + if (factory_reset_ind_timer && timer_elapsed32(factory_reset_ind_timer) > 250) { + if (factory_reset_ind_state++ > 6) { + factory_reset_ind_timer = factory_reset_ind_state = 0; + } else { + factory_reset_ind_timer = timer_read32() == 0 ? 1 : timer_read32(); + } + } +} + +void process_record_factory_reset(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { +#if defined(FN_KEY1) || defined(FN_KEY2) +# ifdef FN_KEY1 + case FN_KEY1: /* fall through */ +# endif +# ifdef FN_KEY2 + case FN_KEY2: +# endif + if (record->event.pressed) { + factory_reset_state |= KEY_PRESS_FN; + } else { + factory_reset_state &= ~KEY_PRESS_FN; + factory_reset_timer = 0; + } + break; +#endif + case KC_J: + if (record->event.pressed) { + factory_reset_state |= KEY_PRESS_J; + if (factory_reset_state == 0x07) factory_timer_start(); + } else { + factory_reset_state &= ~KEY_PRESS_J; + factory_reset_timer = 0; + } + break; + case KC_Z: + if (record->event.pressed) { + factory_reset_state |= KEY_PRESS_Z; + if (factory_reset_state == 0x07) factory_timer_start(); + } else { + factory_reset_state &= ~KEY_PRESS_Z; + factory_reset_timer = 0; + } + break; +#ifdef BL_TEST_KEY1 + case BL_TEST_KEY1: + if (record->event.pressed) { + if (backlight_test_mode) { + if (++backlight_test_mode >= BACKLIGHT_TEST_MAX) { + backlight_test_mode = BACKLIGHT_TEST_WHITE; + } + } else { + factory_reset_state |= KEY_PRESS_BL_KEY1; + if (factory_reset_state == 0x19) factory_timer_start(); + } + } else { + factory_reset_state &= ~KEY_PRESS_BL_KEY1; + factory_reset_timer = 0; + } + break; +#endif +#ifdef BL_TEST_KEY2 + case BL_TEST_KEY2: + if (record->event.pressed) { + if (backlight_test_mode) { + backlight_test_mode = BACKLIGHT_TEST_OFF; + } else { + factory_reset_state |= KEY_PRESS_BL_KEY2; + if (factory_reset_state == 0x19) factory_timer_start(); + } + } else { + factory_reset_state &= ~KEY_PRESS_BL_KEY2; + factory_reset_timer = 0; + } + break; +#endif + } +} + +#ifdef LED_MATRIX_ENABLE +bool led_matrix_indicators_user(void) { + if (factory_reset_ind_state) { + led_matrix_set_value_all(factory_reset_ind_state % 2 ? 0 : 255); + } + + return true; +} +#endif + +#ifdef RGB_MATRIX_ENABLE +bool rgb_matrix_indicators_user(void) { + if (factory_reset_ind_state) { + backlight_test_mode = BACKLIGHT_TEST_OFF; + rgb_matrix_set_color_all(factory_reset_ind_state % 2 ? 0 : 255, 0, 0); + } else if (backlight_test_mode) { + switch (backlight_test_mode) { + case BACKLIGHT_TEST_WHITE: + rgb_matrix_set_color_all(255, 255, 255); + break; + case BACKLIGHT_TEST_RED: + rgb_matrix_set_color_all(255, 0, 0); + break; + case BACKLIGHT_TEST_GREEN: + rgb_matrix_set_color_all(0, 255, 0); + break; + case BACKLIGHT_TEST_BLUE: + rgb_matrix_set_color_all(0, 0, 255); + break; + } + } + + return true; +} +#endif + +void factory_reset_task(void) { + if (factory_reset_timer) factory_timer_check(); + if (factory_reset_ind_timer) factory_reset_ind_timer_check(); +} + +void factory_test_send(uint8_t *payload, uint8_t length) { + uint16_t checksum = 0; + uint8_t data[RAW_EPSIZE] = {0}; + + uint8_t i = 0; + data[i++] = 0xAB; + + memcpy(&data[i], payload, length); + i += length; + + for (uint8_t i = 1; i < RAW_EPSIZE - 3; i++) + checksum += data[i]; + data[RAW_EPSIZE - 2] = checksum & 0xFF; + data[RAW_EPSIZE - 1] = (checksum >> 8) & 0xFF; + + raw_hid_send(data, RAW_EPSIZE); +} + +void factory_test_rx(uint8_t *data, uint8_t length) { + if (data[0] == 0xAB) { + uint16_t checksum = 0; + + for (uint8_t i = 1; i < RAW_EPSIZE - 3; i++) { + checksum += data[i]; + } + /* Verify checksum */ + if ((checksum & 0xFF) != data[RAW_EPSIZE - 2] || checksum >> 8 != data[RAW_EPSIZE - 1]) return; + +#ifdef KC_BLUETOOTH_ENABLE + uint8_t payload[32]; + uint8_t len = 0; +#endif + + switch (data[1]) { + case FACTORY_TEST_CMD_BACKLIGHT: + backlight_test_mode = data[2]; + factory_reset_timer = 0; + break; + case FACTORY_TEST_CMD_OS_SWITCH: + report_os_sw_state = data[2]; + if (report_os_sw_state) { + dip_switch_read(true); + } + break; + case FACTORY_TEST_CMD_JUMP_TO_BL: + // if (memcmp(&data[2], "JumpToBootloader", strlen("JumpToBootloader")) == 0) bootloader_jump(); + break; +#ifdef KC_BLUETOOTH_ENABLE + case FACTORY_TEST_CMD_INT_PIN: + switch (data[2]) { + /* Enalbe/disable test */ + case 0xA1: + ckbt51_int_pin_test(data[3]); + break; + /* Set INT state */ + case 0xA2: + writePin(CKBT51_INT_INPUT_PIN, data[3]); + break; + /* Report INT state */ + case 0xA3: + payload[len++] = FACTORY_TEST_CMD_INT_PIN; + payload[len++] = 0xA3; + payload[len++] = readPin(BLUETOOTH_INT_INPUT_PIN); + factory_test_send(payload, len); + break; + } + break; + case FACTORY_TEST_CMD_GET_TRANSPORT: + payload[len++] = FACTORY_TEST_CMD_GET_TRANSPORT; + payload[len++] = get_transport(); + payload[len++] = readPin(USB_POWER_SENSE_PIN); + factory_test_send(payload, len); + break; +#endif +#ifdef BATTERY_CHARGE_DONE_DETECT_ADC + case FACTORY_TEST_CMD_CHARGING_ADC: + case 0xA1: + battery_charging_monitor(data[3]); + break; + case 0xA2: + payload[len++] = FACTORY_TEST_CMD_CHARGING_ADC; + payload[len++] = battery_adc_read_charging_pin(); + factory_test_send(payload, len); + break; +#endif + case FACTORY_TEST_CMD_RADIO_CARRIER: + if (data[2] < 79) ckbt51_radio_test(data[2]); + break; + } + } +} + +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; +} diff --git a/keyboards/keychron/bluetooth/factory_test.h b/keyboards/keychron/bluetooth/factory_test.h new file mode 100644 index 0000000000..d5ef301512 --- /dev/null +++ b/keyboards/keychron/bluetooth/factory_test.h @@ -0,0 +1,24 @@ +/* Copyright 2022 @ lokher (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 . + */ + +#pragma once + +#define FACTORY_RESET_CHECK process_record_factory_reset +#define FACTORY_RESET_TASK factory_reset_task + +void process_record_factory_reset(uint16_t keycode, keyrecord_t *record); +void factory_reset_task(void); +void factory_test_rx(uint8_t *data, uint8_t length); diff --git a/keyboards/keychron/bluetooth/indicator.c b/keyboards/keychron/bluetooth/indicator.c new file mode 100644 index 0000000000..4348460700 --- /dev/null +++ b/keyboards/keychron/bluetooth/indicator.c @@ -0,0 +1,607 @@ +/* Copyright 2021 @ lokher (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 . + */ + +#include "quantum.h" +#include "indicator.h" +#include "transport.h" +#include "battery.h" +#include "eeconfig.h" +#include "bluetooth_config.h" +#include "config.h" +#include "rtc_timer.h" + +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) +# ifdef LED_MATRIX_ENABLE +# include "led_matrix.h" +# endif +# ifdef RGB_MATRIX_ENABLE +# include "rgb_matrix.h" +# endif +# include "i2c_master.h" +# include "bat_level_animation.h" +# include "eeprom.h" +#endif + +#ifdef LED_MATRIX_ENABLE +# define DECIDE_TIME(t, duration) (duration == 0 ? LED_MATRIX_TIMEOUT_INFINITE : ((t > duration) ? t : duration)) +#endif +#ifdef RGB_MATRIX_ENABLE +# define DECIDE_TIME(t, duration) (duration == 0 ? RGB_MATRIX_TIMEOUT_INFINITE : ((t > duration) ? t : duration)) +#endif + +#define LED_ON 0x80 +#define INDICATOR_SET(s) memcpy(&indicator_config, &s##_config, sizeof(indicator_config_t)); + +enum { + BACKLIGHT_OFF = 0x00, + BACKLIGHT_ON_CONNECTED = 0x01, + BACKLIGHT_ON_UNCONNECTED = 0x02, +}; + +static indicator_config_t pairing_config = INDICATOR_CONFIG_PARING; +static indicator_config_t connected_config = INDICATOR_CONFIG_CONNECTD; +static indicator_config_t reconnecting_config = INDICATOR_CONFIG_RECONNECTING; +static indicator_config_t disconnected_config = INDICATOR_CONFIG_DISCONNECTED; +indicator_config_t indicator_config; +static bluetooth_state_t indicator_state; +static uint16_t next_period; +static indicator_type_t type; +static uint32_t indicator_timer_buffer = 0; + +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) +static uint32_t bat_low_pin_indicator = 0; +static uint32_t bat_low_blink_duration = 0; +# ifdef BAT_LOW_LED_PIN_STATE +bool bat_low_led_pin_state = false; +# endif +#endif + +#if defined(LOW_BAT_IND_INDEX) +static uint32_t bat_low_backlit_indicator = 0; +static uint8_t bat_low_ind_state = 0; +static uint32_t rtc_time = 0; +#endif + +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) +backlight_state_t original_backlight_state; + +static uint8_t host_led_matrix_list[HOST_DEVICES_COUNT] = HOST_LED_MATRIX_LIST; +#endif + +#ifdef HOST_LED_PIN_LIST +static pin_t host_led_pin_list[HOST_DEVICES_COUNT] = HOST_LED_PIN_LIST; +#endif + +#ifdef LED_MATRIX_ENABLE +# define LED_DRIVER led_matrix_driver +# define LED_INDICATORS_KB led_matrix_indicators_kb +# define LED_INDICATORS_USER led_matrix_indicators_user +# define LED_NONE_INDICATORS_KB led_matrix_none_indicators_kb +# define SET_ALL_LED_OFF() led_matrix_set_value_all(0) +# define SET_LED_OFF(idx) led_matrix_set_value(idx, 0) +# define SET_LED_ON(idx) led_matrix_set_value(idx, 255) +# define SET_LED_BT(idx) led_matrix_set_value(idx, 255) +# define SET_LED_LOW_BAT(idx) led_matrix_set_value(idx, 255) +# define LED_DRIVER_IS_ENABLED led_matrix_is_enabled +# define LED_DRIVER_EECONFIG_RELOAD() \ + eeprom_read_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); \ + if (!led_matrix_eeconfig.mode) { \ + eeconfig_update_led_matrix_default(); \ + } +# define LED_DRIVER_ALLOW_SHUTDOWN led_matrix_driver_allow_shutdown +# define LED_DRIVER_ENABLE_NOEEPROM led_matrix_enable_noeeprom +# define LED_DRIVER_DISABLE_NOEEPROM led_matrix_disable_noeeprom +# define LED_DRIVER_DISABLE_TIMEOUT_SET led_matrix_disable_timeout_set +# define LED_DRIVER_DISABLE_TIME_RESET led_matrix_disable_time_reset +#endif + +#ifdef RGB_MATRIX_ENABLE +# define LED_DRIVER rgb_matrix_driver +# define LED_INDICATORS_KB rgb_matrix_indicators_kb +# define LED_INDICATORS_USER rgb_matrix_indicators_user +# define LED_NONE_INDICATORS_KB rgb_matrix_none_indicators_kb +# define SET_ALL_LED_OFF() rgb_matrix_set_color_all(0, 0, 0) +# define SET_LED_OFF(idx) rgb_matrix_set_color(idx, 0, 0, 0) +# define SET_LED_ON(idx) rgb_matrix_set_color(idx, 255, 255, 255) +# define SET_LED_BT(idx) rgb_matrix_set_color(idx, 0, 0, 255) +# define SET_LED_LOW_BAT(idx) rgb_matrix_set_color(idx, 255, 0, 0) +# define LED_DRIVER_IS_ENABLED rgb_matrix_is_enabled +# define LED_DRIVER_EECONFIG_RELOAD() \ + eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); \ + if (!rgb_matrix_config.mode) { \ + eeconfig_update_rgb_matrix_default(); \ + } +# define LED_DRIVER_ALLOW_SHUTDOWN rgb_matrix_driver_allow_shutdown +# define LED_DRIVER_ENABLE_NOEEPROM rgb_matrix_enable_noeeprom +# define LED_DRIVER_DISABLE_NOEEPROM rgb_matrix_disable_noeeprom +# define LED_DRIVER_DISABLE_TIMEOUT_SET rgb_matrix_disable_timeout_set +# define LED_DRIVER_DISABLE_TIME_RESET rgb_matrix_disable_time_reset +#endif +void indicator_init(void) { + memset(&indicator_config, 0, sizeof(indicator_config)); + +#ifdef HOST_LED_PIN_LIST + for (uint8_t i = 0; i < HOST_DEVICES_COUNT; i++) { + setPinOutput(host_led_pin_list[i]); + writePin(host_led_pin_list[i], !HOST_LED_PIN_ON_STATE); + } +#endif + +#ifdef BAT_LOW_LED_PIN + setPinOutput(BAT_LOW_LED_PIN); + writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE); +#endif +} + +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) +void indicator_enable(void) { + if (!LED_DRIVER_IS_ENABLED()) { + LED_DRIVER_ENABLE_NOEEPROM(); + } +} + +inline void indicator_disable(void) { + LED_DRIVER_DISABLE_NOEEPROM(); +} + +void indicator_set_backlit_timeout(uint32_t time) { + LED_DRIVER_DISABLE_TIMEOUT_SET(time); +} + +static inline void indicator_reset_backlit_time(void) { + LED_DRIVER_DISABLE_TIME_RESET(); +} + +bool indicator_is_enabled(void) { + return LED_DRIVER_IS_ENABLED(); +} + +void indicator_eeconfig_reload(void) { + LED_DRIVER_EECONFIG_RELOAD(); +} + +#endif + +bool indicator_is_running(void) { + return +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) + bat_low_blink_duration || +#endif +#if defined(LOW_BAT_IND_INDEX) + bat_low_ind_state || +#endif + !!indicator_config.value; +} + +static void indicator_timer_cb(void *arg) { + if (*(indicator_type_t *)arg != INDICATOR_LAST) type = *(indicator_type_t *)arg; + + bool time_up = false; + switch (type) { + case INDICATOR_NONE: + break; + case INDICATOR_OFF: + next_period = 0; + time_up = true; + break; + + case INDICATOR_ON: + if (indicator_config.value) { + if (indicator_config.elapsed == 0) { + indicator_config.value |= LED_ON; + + if (indicator_config.duration) { + indicator_config.elapsed += indicator_config.duration; + } + } else + time_up = true; + } + break; + + case INDICATOR_ON_OFF: + if (indicator_config.value) { + if (indicator_config.elapsed == 0) { + indicator_config.value |= LED_ON; + next_period = indicator_config.on_time; + } else { + indicator_config.value = indicator_config.value & 0x0F; + next_period = indicator_config.duration - indicator_config.on_time; + } + + if ((indicator_config.duration == 0 || indicator_config.elapsed <= indicator_config.duration) && next_period != 0) { + indicator_config.elapsed += next_period; + } else { + time_up = true; + } + } + break; + + case INDICATOR_BLINK: + if (indicator_config.value) { + if (indicator_config.value & LED_ON) { + indicator_config.value = indicator_config.value & 0x0F; + next_period = indicator_config.off_time; + } else { + indicator_config.value |= LED_ON; + next_period = indicator_config.on_time; + } + + if ((indicator_config.duration == 0 || indicator_config.elapsed <= indicator_config.duration) && next_period != 0) { + indicator_config.elapsed += next_period; + } else { + time_up = true; + } + } + break; + default: + time_up = true; + + next_period = 0; + break; + } + +#ifdef HOST_LED_PIN_LIST + if (indicator_config.value) { + uint8_t idx = (indicator_config.value & 0x0F) - 1; + + if (idx < HOST_DEVICES_COUNT) { + if ((indicator_config.value & 0x80) && !time_up) { + writePin(host_led_pin_list[idx], HOST_LED_PIN_ON_STATE); + } else { + writePin(host_led_pin_list[idx], !HOST_LED_PIN_ON_STATE); + } + } + } +#endif + + if (time_up) { + /* Set indicator to off on timeup, avoid keeping light up until next update in raindrop effect */ + indicator_config.value = indicator_config.value & 0x0F; +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) + LED_INDICATORS_KB(); +#endif + indicator_config.value = 0; + } + + if (indicator_config.value == 0) { + indicator_eeconfig_reload(); + if (!LED_DRIVER_IS_ENABLED()) indicator_disable(); + } +} + +void indicator_set(bluetooth_state_t state, uint8_t host_index) { + if (get_transport() != TRANSPORT_BLUETOOTH) return; + dprintf("indicator set: %d, %d\n", state, host_index); + + static uint8_t current_state = 0; + static uint8_t current_host = 0; + + bool host_index_changed = false; + if (current_host != host_index && state != BLUETOOTH_DISCONNECTED) { + host_index_changed = true; + current_host = host_index; + } + + if (current_state != state || host_index_changed) { + current_state = state; + } else { + return; + } + + indicator_timer_buffer = sync_timer_read32(); + + /* Turn on backlight mode for indicator */ + indicator_enable(); + indicator_reset_backlit_time(); + + switch (state) { + case BLUETOOTH_DISCONNECTED: +#ifdef HOST_LED_PIN_LIST + writePin(host_led_pin_list[host_index - 1], !HOST_LED_PIN_ON_STATE); +#endif + INDICATOR_SET(disconnected); + indicator_config.value = (indicator_config.type == INDICATOR_NONE) ? 0 : host_index; + indicator_timer_cb((void *)&indicator_config.type); + + if (battery_is_critical_low()) { + indicator_set_backlit_timeout(1000); + } else { + /* Set timer so that user has chance to turn on the backlight when is off */ + indicator_set_backlit_timeout(DECIDE_TIME(DISCONNECTED_BACKLIGHT_DISABLE_TIMEOUT * 1000, indicator_config.duration)); + } + break; + + case BLUETOOTH_CONNECTED: + if (indicator_state != BLUETOOTH_CONNECTED) { + INDICATOR_SET(connected); + indicator_config.value = (indicator_config.type == INDICATOR_NONE) ? 0 : host_index; + indicator_timer_cb((void *)&indicator_config.type); + } + indicator_set_backlit_timeout(DECIDE_TIME(CONNECTED_BACKLIGHT_DISABLE_TIMEOUT * 1000, indicator_config.duration)); + break; + + case BLUETOOTH_PARING: + INDICATOR_SET(pairing); + indicator_config.value = (indicator_config.type == INDICATOR_NONE) ? 0 : LED_ON | host_index; + indicator_timer_cb((void *)&indicator_config.type); + indicator_set_backlit_timeout(DECIDE_TIME(DISCONNECTED_BACKLIGHT_DISABLE_TIMEOUT * 1000, indicator_config.duration)); + break; + + case BLUETOOTH_RECONNECTING: + INDICATOR_SET(reconnecting); + indicator_config.value = (indicator_config.type == INDICATOR_NONE) ? 0 : LED_ON | host_index; + indicator_timer_cb((void *)&indicator_config.type); + indicator_set_backlit_timeout(DECIDE_TIME(DISCONNECTED_BACKLIGHT_DISABLE_TIMEOUT * 1000, indicator_config.duration)); + break; + + case BLUETOOTH_SUSPEND: + INDICATOR_SET(disconnected); + indicator_config.value = (indicator_config.type == INDICATOR_NONE) ? 0 : host_index; + indicator_timer_cb((void *)&indicator_config.type); + indicator_set_backlit_timeout(100); + break; + + default: + break; + } + + indicator_state = state; +} + +void indicator_stop(void) { + indicator_config.value = 0; + indicator_eeconfig_reload(); + + if (indicator_is_enabled()) { + indicator_enable(); + } else { + indicator_disable(); + } +} + +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) +void indicator_battery_low_enable(bool enable) { + if (enable) { + if (bat_low_blink_duration == 0) { + bat_low_blink_duration = bat_low_pin_indicator = sync_timer_read32() | 1; + } else + bat_low_blink_duration = sync_timer_read32() | 1; + } else { +# if defined(BAT_LOW_LED_PIN) + writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE); +# else + bat_low_led_pin_state = false; +# endif + } +} +#endif + +#if defined(LOW_BAT_IND_INDEX) +void indicator_battery_low_backlit_enable(bool enable) { + if (enable) { + uint32_t t = rtc_timer_read_ms(); + /* Check overflow */ + if (rtc_time > t) { + if (bat_low_ind_state == 0) + rtc_time = t; // Update rtc_time if indicating is not running + else { + rtc_time += t; + } + } + /* Indicating at first time or after the interval */ + if ((rtc_time == 0 || t - rtc_time > LOW_BAT_LED_TRIG_INTERVAL) && bat_low_ind_state == 0) { + bat_low_backlit_indicator = enable ? (timer_read32() == 0 ? 1 : timer_read32()) : 0; + rtc_time = rtc_timer_read_ms(); + bat_low_ind_state = 1; + + indicator_enable(); + } + } else { + rtc_time = 0; + bat_low_ind_state = 0; + + indicator_eeconfig_reload(); + if (!LED_DRIVER_IS_ENABLED()) indicator_disable(); + } +} +#endif + +void indicator_battery_low(void) { +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) + if (bat_low_pin_indicator && sync_timer_elapsed32(bat_low_pin_indicator) > (LOW_BAT_LED_BLINK_PERIOD)) { +# if defined(BAT_LOW_LED_PIN) + togglePin(BAT_LOW_LED_PIN); +# else + bat_low_led_pin_state = !bat_low_led_pin_state; +# endif + bat_low_pin_indicator = sync_timer_read32() | 1; + // Turn off low battery indication if we reach the duration +# if defined(BAT_LOW_LED_PIN) + if (sync_timer_elapsed32(bat_low_blink_duration) > LOW_BAT_LED_BLINK_DURATION && palReadLine(BAT_LOW_LED_PIN) != BAT_LOW_LED_PIN_ON_STATE) { +# elif defined(BAT_LOW_LED_PIN_STATE) + if (sync_timer_elapsed32(bat_low_blink_duration) > LOW_BAT_LED_BLINK_DURATION) { +# endif + bat_low_blink_duration = bat_low_pin_indicator = 0; + } + } +#endif +#if defined(LOW_BAT_IND_INDEX) + if (bat_low_ind_state) { + if ((bat_low_ind_state & 0x0F) <= (LOW_BAT_LED_BLINK_TIMES) && sync_timer_elapsed32(bat_low_backlit_indicator) > (LOW_BAT_LED_BLINK_PERIOD)) { + if (bat_low_ind_state & 0x80) { + bat_low_ind_state &= 0x7F; + bat_low_ind_state++; + } else { + bat_low_ind_state |= 0x80; + } + + bat_low_backlit_indicator = sync_timer_read32() == 0 ? 1 : sync_timer_read32(); + + /* Restore backligth state */ + if ((bat_low_ind_state & 0x0F) > (LOW_BAT_LED_BLINK_TIMES)) { +# if defined(NUM_LOCK_INDEX) || defined(CAPS_LOCK_INDEX) || defined(SCROLL_LOCK_INDEX) || defined(COMPOSE_LOCK_INDEX) || defined(KANA_LOCK_INDEX) + if (LED_DRIVER_ALLOW_SHUTDOWN()) +# endif + indicator_disable(); + } + } else if ((bat_low_ind_state & 0x0F) > (LOW_BAT_LED_BLINK_TIMES)) { + bat_low_ind_state = 0; + } + } +#endif +} + +void indicator_task(void) { + bat_level_animiation_task(); + + if (indicator_config.value && sync_timer_elapsed32(indicator_timer_buffer) >= next_period) { + indicator_timer_cb((void *)&type); + indicator_timer_buffer = sync_timer_read32(); + } + + indicator_battery_low(); +} + +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) +__attribute__((weak)) void os_state_indicate(void) { +# if defined(NUM_LOCK_INDEX) + if (host_keyboard_led_state().num_lock) { + SET_LED_ON(NUM_LOCK_INDEX); + } +# endif +# if defined(CAPS_LOCK_INDEX) + if (host_keyboard_led_state().caps_lock) { +# if defined(DIM_CAPS_LOCK) + SET_LED_OFF(CAPS_LOCK_INDEX); +# else + SET_LED_ON(CAPS_LOCK_INDEX); +# endif + } +# endif +# if defined(SCROLL_LOCK_INDEX) + if (host_keyboard_led_state().scroll_lock) { + SET_LED_ON(SCROLL_LOCK_INDEX); + } +# endif +# if defined(COMPOSE_LOCK_INDEX) + if (host_keyboard_led_state().compose) { + SET_LED_ON(COMPOSE_LOCK_INDEX); + } +# endif +# if defined(KANA_LOCK_INDEX) + if (host_keyboard_led_state().kana) { + SET_LED_ON(KANA_LOCK_INDEX); + } +# endif +} + +bool LED_INDICATORS_KB(void) { + if (!LED_INDICATORS_USER()) { + return false; + } + + if (get_transport() == TRANSPORT_BLUETOOTH) { + /* Prevent backlight flash caused by key activities */ + if (battery_is_critical_low()) { + SET_ALL_LED_OFF(); + return false; + } + +# if (defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)) && defined(LOW_BAT_IND_INDEX) + if (battery_is_empty()) SET_ALL_LED_OFF(); + if (bat_low_ind_state && (bat_low_ind_state & 0x0F) <= LOW_BAT_LED_BLINK_TIMES) { + if (bat_low_ind_state & 0x80) + SET_LED_LOW_BAT(LOW_BAT_IND_INDEX); + else + SET_LED_OFF(LOW_BAT_IND_INDEX); + } +# endif + if (bat_level_animiation_actived()) { + bat_level_animiation_indicate(); + } + static uint8_t last_host_index = 0xFF; + + if (indicator_config.value) { + uint8_t host_index = indicator_config.value & 0x0F; + + if (indicator_config.highlight) { + SET_ALL_LED_OFF(); + } else if (last_host_index != host_index) { + SET_LED_OFF(host_led_matrix_list[last_host_index - 1]); + last_host_index = host_index; + } + + if (indicator_config.value & 0x80) { + SET_LED_BT(host_led_matrix_list[host_index - 1]); + } else { + SET_LED_OFF(host_led_matrix_list[host_index - 1]); + } + } else + os_state_indicate(); + + } else + os_state_indicate(); + + return false; +} + +bool led_update_kb(led_t led_state) { + bool res = led_update_user(led_state); + if (res) { + led_update_ports(led_state); + + if (!LED_DRIVER_IS_ENABLED()) { + # if defined(LED_MATRIX_DRIVER_SHUTDOWN_ENABLE) || defined(RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE) + LED_DRIVER.exit_shutdown(); + # endif + SET_ALL_LED_OFF(); + os_state_indicate(); + LED_DRIVER.flush(); + # if defined(LED_MATRIX_DRIVER_SHUTDOWN_ENABLE) || defined(RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE) + if (LED_DRIVER_ALLOW_SHUTDOWN()) LED_DRIVER.shutdown(); + # endif + } + } + + return res; +} + +void LED_NONE_INDICATORS_KB(void) { + os_state_indicate(); +} + +# if defined(LED_MATRIX_DRIVER_SHUTDOWN_ENABLE) || defined(RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE) +bool LED_DRIVER_ALLOW_SHUTDOWN(void) { +# if defined(NUM_LOCK_INDEX) + if (host_keyboard_led_state().num_lock) return false; +# endif +# if defined(CAPS_LOCK_INDEX) && !defined(DIM_CAPS_LOCK) + if (host_keyboard_led_state().caps_lock) return false; +# endif +# if defined(SCROLL_LOCK_INDEX) + if (host_keyboard_led_state().scroll_lock) return false; +# endif +# if defined(COMPOSE_LOCK_INDEX) + if (host_keyboard_led_state().compose) return false; +# endif +# if defined(KANA_LOCK_INDEX) + if (host_keyboard_led_state().kana) return false; +# endif + return true; +} +# endif + +#endif diff --git a/keyboards/keychron/bluetooth/indicator.h b/keyboards/keychron/bluetooth/indicator.h new file mode 100644 index 0000000000..a2eb3f019c --- /dev/null +++ b/keyboards/keychron/bluetooth/indicator.h @@ -0,0 +1,118 @@ +/* Copyright 2022 @ lokher (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 . + */ + +#pragma once + +#include "config.h" +#include "bluetooth.h" + +/* Indication of pairing */ +#ifndef INDICATOR_CONFIG_PARING +# define INDICATOR_CONFIG_PARING {INDICATOR_BLINK, 1000, 1000, 0, true, 0}; +#endif + +/* Indication on Connected */ +#ifndef INDICATOR_CONFIG_CONNECTD +# define INDICATOR_CONFIG_CONNECTD {INDICATOR_ON_OFF, 2000, 250, 2000, true, 0}; +#endif + +/* Reconnecting indication */ +#ifndef INDICATOR_CONFIG_RECONNECTING +# define INDICATOR_CONFIG_RECONNECTING {INDICATOR_BLINK, 100, 100, 600, true, 0}; +#endif + +/* Disconnected indication */ +#ifndef INDICATOR_CONFIG_DISCONNECTED +# define INDICATOR_CONFIG_DISCONNECTED {INDICATOR_NONE, 100, 100, 600, false, 0}; +#endif + +/* Uint: Second */ +#ifndef DISCONNECTED_BACKLIGHT_DISABLE_TIMEOUT +# define DISCONNECTED_BACKLIGHT_OFF_DELAY_TIME 40 +#endif + +/* Uint: Second, the timer restarts on key activities. */ +#ifndef CONNECTED_BACKLIGHT_DISABLE_TIMEOUT +# define CONNECTED_BACKLIGHT_OFF_DELAY_TIME 600 +#endif + +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) +/* Uint: ms */ +# ifndef LOW_BAT_LED_BLINK_PERIOD +# define LOW_BAT_LED_BLINK_PERIOD 1000 +# endif + +# ifndef LOW_BAT_LED_BLINK_DURATION +# define LOW_BAT_LED_BLINK_DURATION 10000 +# endif +#endif + +#ifdef LOW_BAT_IND_INDEX +/* Uint: ms */ +# ifndef LOW_BAT_LED_BLINK_PERIOD +# define LOW_BAT_LED_BLINK_PERIOD 500 +# endif + +# ifndef LOW_BAT_LED_BLINK_TIMES +# define LOW_BAT_LED_BLINK_TIMES 3 +# endif + +# ifndef LOW_BAT_LED_TRIG_INTERVAL +# define LOW_BAT_LED_TRIG_INTERVAL 30000 +# endif +#endif + +#if BT_HOST_MAX_COUNT > 6 +# pragma error("HOST_COUNT max value is 6") +#endif + +typedef enum { INDICATOR_NONE, INDICATOR_OFF, INDICATOR_ON, INDICATOR_ON_OFF, INDICATOR_BLINK, INDICATOR_LAST } indicator_type_t; + +typedef struct PACKED { + indicator_type_t type; + uint32_t on_time; + uint32_t off_time; + uint32_t duration; + bool highlight; + uint8_t value; + uint32_t elapsed; +} indicator_config_t; + +typedef struct PACKED { + uint8_t value; + bool saved; +} backlight_state_t; + +void indicator_init(void); +void indicator_set(bluetooth_state_t state, uint8_t host_index); +void indicator_backlight_timer_reset(bool enable); +bool indicator_hook_key(uint16_t keycode); +void indicator_enable(void); +void indicator_disable(void); +void indicator_stop(void); +void indicator_eeconfig_reload(void); +bool indicator_is_enabled(void); +bool indicator_is_running(void); +void os_state_indicate(void); + +#ifdef BAT_LOW_LED_PIN +void indicator_battery_low_enable(bool enable); +#endif +#if defined(LOW_BAT_IND_INDEX) +void indicator_battery_low_backlit_enable(bool enable); +#endif + +void indicator_task(void); diff --git a/keyboards/keychron/bluetooth/lpm.c b/keyboards/keychron/bluetooth/lpm.c new file mode 100644 index 0000000000..187c6d75c0 --- /dev/null +++ b/keyboards/keychron/bluetooth/lpm.c @@ -0,0 +1,92 @@ +/* Copyright 2022 @ lokher (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 . + */ + +/****************************************************************************** + * + * Filename: lpm.c + * + * Description: Contains low power mode implementation + * + ******************************************************************************/ + +#include "quantum.h" +#if defined(PROTOCOL_CHIBIOS) +# include +#endif +#include "bluetooth.h" +#include "indicator.h" +#include "lpm.h" +#include "transport.h" +#include "battery.h" + +extern matrix_row_t matrix[MATRIX_ROWS]; +extern bluetooth_transport_t bluetooth_transport; + +static uint32_t lpm_timer_buffer; +static bool lpm_time_up = false; +static matrix_row_t empty_matrix[MATRIX_ROWS] = {0}; + +void lpm_init(void) { +#ifdef USB_POWER_SENSE_PIN +# if (USB_POWER_CONNECTED_LEVEL == 0) + setPinInputHigh(USB_POWER_SENSE_PIN); +# else + setPinInputLow(USB_POWER_SENSE_PIN); +# endif +#endif + lpm_timer_reset(); +} + +inline void lpm_timer_reset(void) { + lpm_time_up = false; + lpm_timer_buffer = sync_timer_read32(); +} + +void lpm_timer_stop(void) { + lpm_time_up = false; + lpm_timer_buffer = 0; +} + +static inline bool lpm_any_matrix_action(void) { return memcmp(matrix, empty_matrix, sizeof(empty_matrix)); } + +/* Implement of entering low power mode and wakeup varies per mcu or platform */ +__attribute__((weak)) void enter_power_mode(pm_t mode) {} + +__attribute__((weak)) bool usb_power_connected(void) { +#ifdef USB_POWER_SENSE_PIN + return readPin(USB_POWER_SENSE_PIN) == USB_POWER_CONNECTED_LEVEL; +#endif + + return true; +} + +void lpm_task(void) { + if (!lpm_time_up && sync_timer_elapsed32(lpm_timer_buffer) > RUN_MODE_PROCESS_TIME) { + lpm_time_up = true; + lpm_timer_buffer = 0; + } + + if (get_transport() == TRANSPORT_BLUETOOTH && lpm_time_up && !indicator_is_running() +#ifdef LED_MATRIX_ENABLE + && led_matrix_is_driver_shutdown() +#endif +#ifdef RGB_MATRIX_ENABLE + && rgb_matrix_is_driver_shutdown() +#endif + && !lpm_any_matrix_action() && !battery_power_on_sample()) + + enter_power_mode(LOW_POWER_MODE); +} diff --git a/keyboards/keychron/bluetooth/lpm.h b/keyboards/keychron/bluetooth/lpm.h new file mode 100644 index 0000000000..bacc82a716 --- /dev/null +++ b/keyboards/keychron/bluetooth/lpm.h @@ -0,0 +1,30 @@ +/* Copyright 2022 @ lokher (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 . + */ + +#pragma once + +#ifndef RUN_MODE_PROCESS_TIME +# define RUN_MODE_PROCESS_TIME 1000 +#endif + +typedef enum { PM_RUN, PM_LOW_POWER_RUN, PM_SLEEP, PM_LOW_POWER_SLEEP, PM_STOP0, PM_STOP1, PM_STOP2, PM_STANDBY_WITH_RAM, PM_STANDBY, PM_SHUTDOWN } pm_t; + +void lpm_init(void); +void lpm_timer_reset(void); +void lpm_timer_stop(void); +bool usb_power_connected(void); +void enter_power_mode(pm_t mode); +void lpm_task(void); diff --git a/keyboards/keychron/bluetooth/lpm_stm32l432.c b/keyboards/keychron/bluetooth/lpm_stm32l432.c new file mode 100644 index 0000000000..288cb66765 --- /dev/null +++ b/keyboards/keychron/bluetooth/lpm_stm32l432.c @@ -0,0 +1,330 @@ +/* Copyright 2022 @ lokher (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 . + */ + +/****************************************************************************** + * + * Filename: lpm_stm32l432.c + * + * Description: Contains low power mode implementation + * + ******************************************************************************/ + +#include "quantum.h" +#include +#include "bluetooth.h" +#include "indicator.h" +#include "lpm.h" +#include "transport.h" +#include "battery.h" +#include "report_buffer.h" +#include "stm32_bd.inc" +#include "debounce.h" + +extern pin_t row_pins[MATRIX_ROWS]; +extern void select_all_cols(void); +extern bluetooth_transport_t bluetooth_transport; + +static pm_t power_mode = PM_RUN; + +static inline void stm32_clock_fast_init(void); + +bool lpm_set(pm_t mode) { + switch (mode) { +#ifdef LOW_POWER_RUN_MODE_ENABLE + case PM_RUN: + if (power_mode != PM_LOW_POWER_RUN)) return; + /* Set main regulator */ + PWR->CR1 &= ~PWR_CR1_LPR; + while (PWR->SR2 & PWR_SR2_REGLPF) + ; + // TODO: restore sysclk + return true; + // break; + + case PM_LOW_POWER_RUN: + if (power_mode != PM_RUN) return; + + // FLASH->ACR |= FLASH_ACR_RUN_PD; // Optional + // TODO: Decrease sysclk below 2 MHz + PWR->CR1 |= PWR_CR1_LPR; + return true; + // break; +#endif + case PM_SLEEP: + /* Wake source: Any interrupt or event */ + if (power_mode != PM_RUN) return false; + + SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; + break; + +#ifdef LOW_POWER_RUN_MODE_ENABLE + case PM_LOW_POWER_SLEEP: + /* Wake source: Any interrupt or event */ + if (power_mode != PM_LOW_POWER_RUN) return; /* Can only transit from PM_LOW_POWER_RUN */ + + SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; + __WFI(); + exit_low_power_mode(); + break; +#endif + case PM_STOP0: + /* Wake source: Reset pin, all I/Os, BOR, PVD, PVM, RTC, LCD, IWDG, + COMPx, USARTx, LPUART1, I2Cx, LPTIMx, USB, SWPMI */ + if (power_mode != PM_RUN) return false; + + SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; + PWR->CR1 |= PWR_CR1_LPMS_STOP0; + break; + + case PM_STOP1: + /* Wake source: Reset pin, all I/Os, BOR, PVD, PVM, RTC, LCD, IWDG, + COMPx, USARTx, LPUART1, I2Cx, LPTIMx, USB, SWPMI */ + if (power_mode != PM_RUN && power_mode != PM_LOW_POWER_RUN) return false; + + SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; + PWR->CR1 |= PWR_CR1_LPMS_STOP1; + break; + + case PM_STOP2: + /* Wake source: Reset pin, all I/Os, BOR, PVD, PVM, RTC, LCD, IWDG, + COMPx (x=1, 2), I2C3, LPUART1, LPTIM1, LPTIM2 */ + if (power_mode != PM_RUN) return false; + + SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; + PWR->CR1 |= PWR_CR1_LPMS_STOP2; + break; + + case PM_STANDBY_WITH_RAM: + /* Wake source: Reset, 5 I/O(PA0, PC13, PE6, PA2, PC5), BOR, RTC, IWDG */ + if (power_mode != PM_RUN && power_mode != PM_LOW_POWER_RUN) return false; + + SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; + PWR->CR1 |= PWR_CR1_LPMS_STANDBY; + PWR->CR3 |= PWR_CR3_RRS; + break; + + case PM_STANDBY: + /* Wake source: Reset, 2 I/O(PA0, PA2) in STM32L432Kx,, BOR, RTC, IWDG */ + if (power_mode != PM_RUN && power_mode != PM_LOW_POWER_RUN) return false; + + SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; + PWR->CR1 |= PWR_CR1_LPMS_STANDBY; + PWR->CR3 &= ~PWR_CR3_RRS; + break; + + case PM_SHUTDOWN: + /* Wake source: Reset, 2 I/O(PA0, PA2) in STM32L432Kx, RTC */ + if (power_mode != PM_RUN && power_mode != PM_LOW_POWER_RUN) return false; + + SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; + PWR->CR1 |= PWR_CR1_LPMS_SHUTDOWN; + break; + + default: + return false; + } + + return true; +} + +static inline void enter_low_power_mode_prepare(void) { +#if defined(KEEP_USB_CONNECTION_IN_BLUETOOTH_MODE) + /* Usb unit is actived and running, stop and disconnect first */ + usbStop(&USBD1); + usbDisconnectBus(&USBD1); + + /* Isolate USB to save power.*/ + PWR->CR2 &= ~PWR_CR2_USV; /*PWR_CR2_USV is available on STM32L4x2xx and STM32L4x3xx devices only. */ +#endif + + palEnableLineEvent(BLUETOOTH_INT_INPUT_PIN, PAL_EVENT_MODE_FALLING_EDGE); + palEnableLineEvent(USB_POWER_SENSE_PIN, PAL_EVENT_MODE_BOTH_EDGES); + + /* Enable key matrix wake up */ + pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; + + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + if (row_pins[x] != NO_PIN) { + palEnableLineEvent(row_pins[x], PAL_EVENT_MODE_BOTH_EDGES); + } + } + + select_all_cols(); + +#if defined(DIP_SWITCH_PINS) +# define NUMBER_OF_DIP_SWITCHES (sizeof(dip_switch_pad) / sizeof(pin_t)) + static pin_t dip_switch_pad[] = DIP_SWITCH_PINS; + + for (uint8_t i = 0; i < NUMBER_OF_DIP_SWITCHES; i++) { + setPinInputLow(dip_switch_pad[i]); + } +#endif +} + +static inline void lpm_wakeup(void) { + chSysLock(); + stm32_clock_fast_init(); + chSysUnlock(); + + if (bluetooth_transport.init) bluetooth_transport.init(true); + + chSysLock(); + SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; + + PWR->SCR |= PWR_SCR_CWUF; + PWR->SCR |= PWR_SCR_CSBF; + + /* TIMx is disable during stop/standby/sleep mode, init after wakeup */ + stInit(); + timer_init(); + chSysUnlock(); + battery_init(); + + /* Disable all wake up pins */ + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + if (row_pins[x] != NO_PIN) { + palDisableLineEvent(row_pins[x]); + } + } + palDisableLineEvent(BLUETOOTH_INT_INPUT_PIN); + +#ifdef USB_POWER_SENSE_PIN + palDisableLineEvent(USB_POWER_SENSE_PIN); + +# if defined(KEEP_USB_CONNECTION_IN_BLUETOOTH_MODE) + if (usb_power_connected()) { + hsi48_init(); + /* Remove USB isolation.*/ + // PWR->CR2 |= PWR_CR2_USV; /* PWR_CR2_USV is available on STM32L4x2xx and STM32L4x3xx devices only. */ + usb_power_connect(); + usb_start(&USBD1); + } +# endif + +#endif + +#if defined(DIP_SWITCH_PINS) + dip_switch_init(); + dip_switch_read(true); +#endif +} + +/* + * NOTE: + * 1. Shall not use PM_LOW_POWER_RUN, PM_LOW_POWER_SLEEP, due to PM_LOW_POWER_RUN + * need to decrease system clock below 2 MHz. Dynamic clock is not yet supported + * for STM32L432xx in latest ChibiOS 21.6.0 so far. + * 2. Care must be taken to use PM_STANDBY_WITH_RAM, PM_STANDBY, PM_SHUTDOWN due to + * limited wake source, thus can't be waken via keyscan. PM_SHUTDOWN need LSE. + * 3. Reference from AN4621: STM32L4 and STM32L4+ ultra-low-power features overview + * for detail wake source + */ + +void enter_power_mode(pm_t mode) { +#if defined(KEEP_USB_CONNECTION_IN_BLUETOOTH_MODE) + /* Don't enter low power mode if attached to the host */ + if (mode > PM_SLEEP && usb_power_connected()) return; +#endif + + if (!lpm_set(mode)) return; + enter_low_power_mode_prepare(); + + // __DSB(); + __WFI(); + // __ISB(); + + lpm_wakeup(); + lpm_timer_reset(); + report_buffer_init(); + + /* Call debounce_free() to avoid memory leak as debounce_init() invoked in matrix_init() allocates + * new memory when using per row/key debounce + */ + debounce_free(); + matrix_init(); + power_mode = PM_RUN; +} + +void usb_power_connect(void) { + PWR->CR2 |= PWR_CR2_USV; +} + +void usb_power_disconnect(void) { + PWR->CR2 &= ~PWR_CR2_USV; +} + +/* + * This is a simplified version of stm32_clock_init() by removing unnecessary clock initlization + * code snippet. The original stm32_clock_init() take about 2ms, but ckbt51 sends data via uart + * about 200us after wakeup pin is assert, it means that we must get everything ready before data + * coming when wakeup pin interrupt of MCU is triggerred. + * Here we reduce clock init time to less than 100us. + */ +void stm32_clock_fast_init(void) { +#if !STM32_NO_INIT + /* Clocks setup.*/ + msi_init(); // 6.x us + hsi16_init(); // 4.x us + + /* PLLs activation, if required.*/ + pll_init(); + pllsai1_init(); + pllsai2_init(); + /* clang-format off */ + /* Other clock-related settings (dividers, MCO etc).*/ + RCC->CFGR = STM32_MCOPRE | STM32_MCOSEL | STM32_STOPWUCK | + STM32_PPRE2 | STM32_PPRE1 | STM32_HPRE; + /* CCIPR register initialization, note, must take care of the _OFF + pseudo settings.*/ + { + uint32_t ccipr = STM32_DFSDMSEL | STM32_SWPMI1SEL | STM32_ADCSEL | + STM32_CLK48SEL | STM32_LPTIM2SEL | STM32_LPTIM1SEL | + STM32_I2C3SEL | STM32_I2C2SEL | STM32_I2C1SEL | + STM32_UART5SEL | STM32_UART4SEL | STM32_USART3SEL | + STM32_USART2SEL | STM32_USART1SEL | STM32_LPUART1SEL; +/* clang-format on */ +# if STM32_SAI2SEL != STM32_SAI2SEL_OFF + ccipr |= STM32_SAI2SEL; +# endif +# if STM32_SAI1SEL != STM32_SAI1SEL_OFF + ccipr |= STM32_SAI1SEL; +# endif + RCC->CCIPR = ccipr; + } + + /* Set flash WS's for SYSCLK source */ + if (STM32_FLASHBITS > STM32_MSI_FLASHBITS) { + FLASH->ACR = (FLASH->ACR & ~FLASH_ACR_LATENCY_Msk) | STM32_FLASHBITS; + while ((FLASH->ACR & FLASH_ACR_LATENCY_Msk) != (STM32_FLASHBITS & FLASH_ACR_LATENCY_Msk)) { + } + } + + /* Switching to the configured SYSCLK source if it is different from MSI.*/ +# if (STM32_SW != STM32_SW_MSI) + RCC->CFGR |= STM32_SW; /* Switches on the selected clock source. */ + /* Wait until SYSCLK is stable.*/ + while ((RCC->CFGR & RCC_CFGR_SWS) != (STM32_SW << 2)) + ; +# endif + + /* Reduce the flash WS's for SYSCLK source if they are less than MSI WSs */ + if (STM32_FLASHBITS < STM32_MSI_FLASHBITS) { + FLASH->ACR = (FLASH->ACR & ~FLASH_ACR_LATENCY_Msk) | STM32_FLASHBITS; + while ((FLASH->ACR & FLASH_ACR_LATENCY_Msk) != (STM32_FLASHBITS & FLASH_ACR_LATENCY_Msk)) { + } + } +#endif /* STM32_NO_INIT */ +} diff --git a/keyboards/keychron/bluetooth/lpm_stm32l432.h b/keyboards/keychron/bluetooth/lpm_stm32l432.h new file mode 100644 index 0000000000..065bf96b47 --- /dev/null +++ b/keyboards/keychron/bluetooth/lpm_stm32l432.h @@ -0,0 +1,19 @@ +/* Copyright 2022 @ lokher (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 . + */ + +#pragma once + +typedef enum { PM_RUN, PM_LOW_POWER_RUN, PM_SLEEP, PM_LOW_POWER_SLEEP, PM_STOP0, PM_STOP1, PM_STOP2, PM_STANDBY_WITH_RAM, PM_STANDBY, PM_SHUTDOWN } pm_t; diff --git a/keyboards/keychron/bluetooth/report_buffer.c b/keyboards/keychron/bluetooth/report_buffer.c new file mode 100644 index 0000000000..7494c42b97 --- /dev/null +++ b/keyboards/keychron/bluetooth/report_buffer.c @@ -0,0 +1,141 @@ +/* Copyright 2022 @ lokher (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 . + */ + +#include "quantum.h" +#include "report_buffer.h" +#include "bluetooth.h" +#include "lpm.h" + +/* The report buffer is mainly used to fix key press lost issue of macro + * when bluetooth module fifo isn't large enough. The maximun macro + * string length is determined by this queue size, and should be + * REPORT_BUFFER_QUEUE_SIZE devided by 2 since each character is implemented + * by sending a key pressing then a key releasing report. + * Please note that it cosume sizeof(report_buffer_t) * REPORT_BUFFER_QUEUE_SIZE + * bytes RAM, with default setting, used RAM size is + * sizeof(report_buffer_t) * 256 = 34* 256 = 8704 bytes + */ +#ifndef REPORT_BUFFER_QUEUE_SIZE +# define REPORT_BUFFER_QUEUE_SIZE 512 +#endif + +extern bluetooth_transport_t bluetooth_transport; + +/* report_interval value should be less than bluetooth connection interval because + * it takes some time for communicating between mcu and bluetooth module. Carefully + * set this value to feed the bt module so that we don't lost the key report nor lost + * the anchor point of bluetooth interval. The bluetooth connection interval varies + * if BLE is used, invoke report_buffer_set_inverval() to update the value + */ +uint8_t report_interval = DEFAULT_REPORT_INVERVAL_MS; + +static uint32_t report_timer_buffer = 0; +uint32_t retry_time_buffer = 0; +report_buffer_t report_buffer_queue[REPORT_BUFFER_QUEUE_SIZE]; +uint16_t report_buffer_queue_head; +uint16_t report_buffer_queue_tail; +report_buffer_t kb_rpt; +uint8_t retry = 0; + +void report_buffer_init(void) { + // Initialise the report queue + memset(&report_buffer_queue, 0, sizeof(report_buffer_queue)); + report_buffer_queue_head = 0; + report_buffer_queue_tail = 0; + retry = 0; + report_timer_buffer = sync_timer_read32(); +} + +bool report_buffer_enqueue(report_buffer_t *report) { + uint16_t next = (report_buffer_queue_head + 1) % REPORT_BUFFER_QUEUE_SIZE; + if (next == report_buffer_queue_tail) { + return false; + } + + report_buffer_queue[report_buffer_queue_head] = *report; + report_buffer_queue_head = next; + return true; +} + +inline bool report_buffer_dequeue(report_buffer_t *report) { + if (report_buffer_queue_head == report_buffer_queue_tail) { + return false; + } + + *report = report_buffer_queue[report_buffer_queue_tail]; + report_buffer_queue_tail = (report_buffer_queue_tail + 1) % REPORT_BUFFER_QUEUE_SIZE; + return true; +} + +bool report_buffer_is_empty() { + return report_buffer_queue_head == report_buffer_queue_tail; +} + +void report_buffer_update_timer(void) { + report_timer_buffer = sync_timer_read32(); +} + +bool report_buffer_next_inverval(void) { + return sync_timer_elapsed32(report_timer_buffer) > report_interval; +} + +void report_buffer_set_inverval(uint8_t interval) { + report_interval = interval; +} + +uint8_t report_buffer_get_retry(void) { + return retry; +} + +void report_buffer_set_retry(uint8_t times) { + retry = times; +} + +void report_buffer_task(void) { + if (bluetooth_get_state() == BLUETOOTH_CONNECTED && (!report_buffer_is_empty() || retry) && report_buffer_next_inverval()) { + bool pending_data = false; + + if (!retry) { + if (report_buffer_dequeue(&kb_rpt) && kb_rpt.type != REPORT_TYPE_NONE) { + if (sync_timer_read32() > 2) { + pending_data = true; + retry = RETPORT_RETRY_COUNT; + retry_time_buffer = sync_timer_read32(); + } + } + } else { + if (sync_timer_elapsed32(retry_time_buffer) > 7) { + pending_data = true; + --retry; + retry_time_buffer = sync_timer_read32(); + } + } + + if (pending_data) { +#if defined(NKRO_ENABLE) && defined(BLUETOOTH_NKRO_ENABLE) + if (kb_rpt.type == REPORT_TYPE_NKRO && bluetooth_transport.send_nkro) { + bluetooth_transport.send_nkro(&kb_rpt.nkro.mods); + } else if (kb_rpt.type == REPORT_TYPE_KB && bluetooth_transport.send_keyboard) + bluetooth_transport.send_keyboard(&kb_rpt.keyboard.mods); +#else + if (kb_rpt.type == REPORT_TYPE_KB && bluetooth_transport.send_keyboard) bluetooth_transport.send_keyboard(&kb_rpt.keyboard.mods); +#endif + if (kb_rpt.type == REPORT_TYPE_CONSUMER && bluetooth_transport.send_consumer) bluetooth_transport.send_consumer(kb_rpt.consumer); + report_timer_buffer = sync_timer_read32(); + lpm_timer_reset(); + } + } +} diff --git a/keyboards/keychron/bluetooth/report_buffer.h b/keyboards/keychron/bluetooth/report_buffer.h new file mode 100644 index 0000000000..64cffacffc --- /dev/null +++ b/keyboards/keychron/bluetooth/report_buffer.h @@ -0,0 +1,56 @@ +/* Copyright 2022 @ lokher (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 . + */ + +#pragma once + +#include "report.h" + +/* Default report interval value */ +#ifndef DEFAULT_REPORT_INVERVAL_MS +# define DEFAULT_REPORT_INVERVAL_MS 3 +#endif + +/* Default report interval value */ +#ifndef RETPORT_RETRY_COUNT +# define RETPORT_RETRY_COUNT 30 +#endif + +enum { + REPORT_TYPE_NONE, + REPORT_TYPE_KB, + REPORT_TYPE_NKRO, + REPORT_TYPE_CONSUMER, +}; + +typedef struct { + uint8_t type; + union { + report_keyboard_t keyboard; + report_nkro_t nkro; + uint16_t consumer; + }; +} report_buffer_t; + +void report_buffer_init(void); +bool report_buffer_enqueue(report_buffer_t *report); +bool report_buffer_dequeue(report_buffer_t *report); +bool report_buffer_is_empty(void); +void report_buffer_update_timer(void); +bool report_buffer_next_inverval(void); +void report_buffer_set_inverval(uint8_t interval); +uint8_t report_buffer_get_retry(void); +void report_buffer_set_retry(uint8_t times); +void report_buffer_task(void); diff --git a/keyboards/keychron/bluetooth/rtc_timer.c b/keyboards/keychron/bluetooth/rtc_timer.c new file mode 100644 index 0000000000..04ebd43995 --- /dev/null +++ b/keyboards/keychron/bluetooth/rtc_timer.c @@ -0,0 +1,43 @@ +/* Copyright 2023 @ lokher (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 . + */ + +#include "hal.h" + +#if (HAL_USE_RTC) + +# include "rtc_timer.h" + +void rtc_timer_init(void) { + rtc_timer_clear(); +} + +void rtc_timer_clear(void) { + RTCDateTime tm = {0, 0, 0, 0, 0, 0}; + rtcSetTime(&RTCD1, &tm); +} + +uint32_t rtc_timer_read_ms(void) { + RTCDateTime tm; + rtcGetTime(&RTCD1, &tm); + + return tm.millisecond; +} + +uint32_t rtc_timer_elapsed_ms(uint32_t last) { + return TIMER_DIFF_32(rtc_timer_read_ms(), last); +} + +#endif diff --git a/keyboards/keychron/bluetooth/rtc_timer.h b/keyboards/keychron/bluetooth/rtc_timer.h new file mode 100644 index 0000000000..aa73a31c8a --- /dev/null +++ b/keyboards/keychron/bluetooth/rtc_timer.h @@ -0,0 +1,43 @@ +/* Copyright 2023 @ lokher (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 . + */ + +#pragma once + +#include "timer.h" +#include + +#define RTC_MAX_TIME (24 * 3600 * 1000) // Set to 1 day + +#if 0 +# define TIMER_DIFF(a, b, max) ((max == UINT8_MAX) ? ((uint8_t)((a) - (b))) : ((max == UINT16_MAX) ? ((uint16_t)((a) - (b))) : ((max == UINT32_MAX) ? ((uint32_t)((a) - (b))) : ((a) >= (b) ? (a) - (b) : (max) + 1 - (b) + (a))))) +# define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX) +# define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX) +# define TIMER_DIFF_32(a, b) TIMER_DIFF(a, b, UINT32_MAX) +# define TIMER_DIFF_RAW(a, b) TIMER_DIFF_8(a, b) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +void rtc_timer_init(void); +void rtc_timer_clear(void); +uint32_t rtc_timer_read_ms(void); +uint32_t rtc_timer_elapsed_ms(uint32_t last); + +#ifdef __cplusplus +} +#endif diff --git a/keyboards/keychron/bluetooth/transport.c b/keyboards/keychron/bluetooth/transport.c new file mode 100644 index 0000000000..9fab44fcc8 --- /dev/null +++ b/keyboards/keychron/bluetooth/transport.c @@ -0,0 +1,190 @@ +/* Copyright 2022 @ lokher (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 . + */ + +#include "quantum.h" +#include "bluetooth.h" +#include "indicator.h" +#include "lpm.h" +#if defined(PROTOCOL_CHIBIOS) +# include +#endif +#include "transport.h" + +#ifndef REINIT_LED_DRIVER +# define REINIT_LED_DRIVER 1 +#endif + +#if defined(PROTOCOL_CHIBIOS) +extern host_driver_t chibios_driver; +#endif +extern host_driver_t bluetooth_driver; +extern keymap_config_t keymap_config; + +static transport_t transport = TRANSPORT_USB; + +#ifdef NKRO_ENABLE +nkro_t nkro = {false, false}; +#endif + +static void transport_changed(transport_t new_transport); + +__attribute__((weak)) void bt_transport_enable(bool enable) { + if (enable) { + if (host_get_driver() != &bluetooth_driver) { + host_set_driver(&bluetooth_driver); + + /* Disconnect and reconnect to sync the bluetooth state + * TODO: query bluetooth state to sync + */ + bluetooth_disconnect(); + bluetooth_connect(); + // TODO: Clear USB report + } + } else { + indicator_stop(); + + if (bluetooth_get_state() == BLUETOOTH_CONNECTED) { + report_keyboard_t empty_report = {0}; + bluetooth_driver.send_keyboard(&empty_report); + } + } +} + +/* There is no dedicated pin for USB power on chip such as STM32L432, but USB power + * can be connected and disconnected via registers. + * Overwrite these two functions if such chip is used. */ +__attribute__((weak)) void usb_power_connect(void) {} +__attribute__((weak)) void usb_power_disconnect(void) {} + +__attribute__((weak)) void usb_transport_enable(bool enable) { + if (enable) { + if (host_get_driver() != &chibios_driver) { +#if !defined(KEEP_USB_CONNECTION_IN_BLUETOOTH_MODE) + usb_power_connect(); + usb_start(&USBD1); +#endif + host_set_driver(&chibios_driver); + } + } else { + if (USB_DRIVER.state == USB_ACTIVE) { + report_keyboard_t empty_report = {0}; + chibios_driver.send_keyboard(&empty_report); + } + +#if !defined(KEEP_USB_CONNECTION_IN_BLUETOOTH_MODE) + usbStop(&USBD1); + usbDisconnectBus(&USBD1); + usb_power_disconnect(); +#endif + } +} + +void set_transport(transport_t new_transport) { + if (transport != new_transport) { + transport = new_transport; + + clear_keyboard(); + + switch (transport) { + case TRANSPORT_USB: + usb_transport_enable(true); + bt_transport_enable(false); + lpm_timer_stop(); +#ifdef NKRO_ENABLE +# if defined(BLUETOOTH_NKRO_ENABLE) + nkro.bluetooth = keymap_config.nkro; +# endif + keymap_config.nkro = nkro.usb; +#endif + break; + + case TRANSPORT_BLUETOOTH: + bt_transport_enable(true); + usb_transport_enable(false); + lpm_timer_reset(); +#if defined(NKRO_ENABLE) + nkro.usb = keymap_config.nkro; +# if defined(BLUETOOTH_NKRO_ENABLE) + keymap_config.nkro = nkro.bluetooth; +# else + keymap_config.nkro = FALSE; +# endif +#endif + break; + default: + break; + } + + transport_changed(transport); + } +} + +transport_t get_transport(void) { + return transport; +} + +/* Changing transport may cause bronw-out reset of led driver + * withoug MCU reset, which lead backlight to not work, + * reinit the led driver workgound this issue */ +static void reinit_led_drvier(void) { + /* Wait circuit to discharge for a while */ + systime_t start = chVTGetSystemTime(); + while (chTimeI2MS(chVTTimeElapsedSinceX(start)) < 100) { + }; + +#ifdef LED_MATRIX_ENABLE + led_matrix_init(); +#endif +#ifdef RGB_MATRIX_ENABLE + rgb_matrix_init(); +#endif +} + +void transport_changed(transport_t new_transport) { +#if (REINIT_LED_DRIVER) + reinit_led_drvier(); +#endif + +#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_TIMEOUT) +# if (RGB_MATRIX_TIMEOUT > 0) + rgb_matrix_disable_timeout_set(RGB_MATRIX_TIMEOUT_INFINITE); + rgb_matrix_disable_time_reset(); +# endif +#endif +#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_TIMEOUT) +# if (LED_MATRIX_TIMEOUT > 0) + led_matrix_disable_timeout_set(LED_MATRIX_TIMEOUT_INFINITE); + led_matrix_disable_time_reset(); +# endif +#endif +} + +void usb_remote_wakeup(void) { + if (USB_DRIVER.state == USB_SUSPENDED) { + while (USB_DRIVER.state == USB_SUSPENDED) { + /* Do this in the suspended state */ + suspend_power_down(); // on AVR this deep sleeps for 15ms + /* Remote wakeup */ + if (suspend_wakeup_condition()) { + usbWakeupHost(&USB_DRIVER); + } + } + wait_ms(500); + /* Woken up */ + // variables has been already cleared by the wakeup hook + send_keyboard_report(); + } +} diff --git a/keyboards/keychron/bluetooth/transport.h b/keyboards/keychron/bluetooth/transport.h new file mode 100644 index 0000000000..29722cd265 --- /dev/null +++ b/keyboards/keychron/bluetooth/transport.h @@ -0,0 +1,39 @@ +/* Copyright 2022 @ lokher (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 . + */ + +#pragma once + +typedef enum { + TRANSPORT_NONE, + TRANSPORT_USB, + TRANSPORT_BLUETOOTH, +} transport_t; + +#ifdef NKRO_ENABLE +typedef struct { + bool usb : 1; + bool bluetooth : 1; +} nkro_t; +#endif + +void set_transport(transport_t new_transport); +transport_t get_transport(void); + +void bt_transport_enable(bool enable); +void usb_power_connect(void); +void usb_power_disconnect(void); +void usb_transport_enable(bool enable); +void usb_remote_wakeup(void); diff --git a/keyboards/keychron/common/common.mk b/keyboards/keychron/common/common.mk new file mode 100644 index 0000000000..d3f283ef9a --- /dev/null +++ b/keyboards/keychron/common/common.mk @@ -0,0 +1,6 @@ +COMMON_DIR = common +SRC += $(COMMON_DIR)/matrix.c + +VPATH += $(TOP_DIR)/keyboards/keychron/$(COMMON_DIR) + +include $(TOP_DIR)/keyboards/keychron/$(COMMON_DIR)/debounce/debounce.mk diff --git a/keyboards/keychron/common/debounce/asym_eager_defer_pk.c b/keyboards/keychron/common/debounce/asym_eager_defer_pk.c new file mode 100644 index 0000000000..db24cb9359 --- /dev/null +++ b/keyboards/keychron/common/debounce/asym_eager_defer_pk.c @@ -0,0 +1,170 @@ +/* + * Copyright 2017 Alex Ong + * Copyright 2020 Andrei Purdea + * Copyright 2021 Simon Arlott + * Copyright 2024 @ 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 . + */ + +/* +Basic symmetric per-key algorithm. Uses an 8-bit counter per key. +When no state changes have occured for DEBOUNCE milliseconds, we push the state. +*/ + +#include "debounce.h" +#include "timer.h" +#include + +#ifdef PROTOCOL_CHIBIOS +# if CH_CFG_USE_MEMCORE == FALSE +# error ChibiOS is configured without a memory allocator. Your keyboard may have set `#define CH_CFG_USE_MEMCORE FALSE`, which is incompatible with this debounce algorithm. +# endif +#endif + +#define ROW_SHIFTER ((matrix_row_t)1) + +typedef struct { + bool pressed : 1; + uint8_t time : 7; +} debounce_counter_t; + +extern uint8_t debounce_time; + +static debounce_counter_t *debounce_counters = NULL; +static fast_timer_t last_time; +static bool counters_need_update; +static bool matrix_need_update; +static bool cooked_changed; + +# define DEBOUNCE_ELAPSED 0 + +static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t elapsed_time); +static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows); + +// we use num_rows rather than MATRIX_ROWS to support split keyboards +void asym_eager_defer_pk_debounce_init(uint8_t num_rows) { + debounce_counters = malloc(num_rows * MATRIX_COLS * sizeof(debounce_counter_t)); + + int i = 0; + for (uint8_t r = 0; r < num_rows; r++) { + for (uint8_t c = 0; c < MATRIX_COLS; c++) { + debounce_counters[i++].time = DEBOUNCE_ELAPSED; + } + } +} + +void asym_eager_defer_pk_debounce_free(void) { + if (debounce_counters != NULL) { + free(debounce_counters); + debounce_counters = NULL; + } +} + +bool asym_eager_defer_pk_debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { + + bool updated_last = false; + cooked_changed = false; + + if (counters_need_update) { + fast_timer_t now = timer_read_fast(); + fast_timer_t elapsed_time = TIMER_DIFF_FAST(now, last_time); + + last_time = now; + updated_last = true; + if (elapsed_time > UINT8_MAX) { + elapsed_time = UINT8_MAX; + } + + if (elapsed_time > 0) { + update_debounce_counters_and_transfer_if_expired(raw, cooked, num_rows, elapsed_time); + } + } + + if (changed || matrix_need_update) { + if (!updated_last) { + last_time = timer_read_fast(); + } + + transfer_matrix_values(raw, cooked, num_rows); + } + + return cooked_changed; +} + +static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t elapsed_time) { + debounce_counter_t *debounce_pointer = debounce_counters; + + counters_need_update = false; + matrix_need_update = false; + + for (uint8_t row = 0; row < num_rows; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + matrix_row_t col_mask = (ROW_SHIFTER << col); + + if (debounce_pointer->time != DEBOUNCE_ELAPSED) { + if (debounce_pointer->time <= elapsed_time) { + debounce_pointer->time = DEBOUNCE_ELAPSED; + + if (debounce_pointer->pressed) { + // key-down: eager + matrix_need_update = true; + } else { + // key-up: defer + matrix_row_t cooked_next = (cooked[row] & ~col_mask) | (raw[row] & col_mask); + cooked_changed |= cooked_next ^ cooked[row]; + cooked[row] = cooked_next; + } + } else { + debounce_pointer->time -= elapsed_time; + counters_need_update = true; + } + } + debounce_pointer++; + } + } +} + +static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) { + debounce_counter_t *debounce_pointer = debounce_counters; + + matrix_need_update = false; + + for (uint8_t row = 0; row < num_rows; row++) { + matrix_row_t delta = raw[row] ^ cooked[row]; + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + matrix_row_t col_mask = (ROW_SHIFTER << col); + + if (delta & col_mask) { + if (debounce_pointer->time == DEBOUNCE_ELAPSED) { + debounce_pointer->pressed = (raw[row] & col_mask); + debounce_pointer->time = debounce_time;; + counters_need_update = true; + + if (debounce_pointer->pressed) { + // key-down: eager + cooked[row] ^= col_mask; + cooked_changed = true; + } + } + } else if (debounce_pointer->time != DEBOUNCE_ELAPSED) { + if (!debounce_pointer->pressed) { + // key-up: defer + debounce_pointer->time = DEBOUNCE_ELAPSED; + } + } + debounce_pointer++; + } + } +} diff --git a/keyboards/keychron/common/debounce/debounce.mk b/keyboards/keychron/common/debounce/debounce.mk new file mode 100644 index 0000000000..d84c479ab5 --- /dev/null +++ b/keyboards/keychron/common/debounce/debounce.mk @@ -0,0 +1,14 @@ +DEBOUNCE_DIR = common/debounce +SRC += \ + $(DEBOUNCE_DIR)/sym_defer_g.c \ + $(DEBOUNCE_DIR)/sym_defer_pr.c \ + $(DEBOUNCE_DIR)/sym_defer_pk.c \ + $(DEBOUNCE_DIR)/sym_eager_pr.c \ + $(DEBOUNCE_DIR)/sym_eager_pk.c \ + $(DEBOUNCE_DIR)/asym_eager_defer_pk.c \ + $(DEBOUNCE_DIR)/none.c \ + $(DEBOUNCE_DIR)/keychron_debounce.c + +VPATH += $(TOP_DIR)/keyboards/keychron/$(DEBOUNCE_DIR) + +OPT_DEFS += -DDYNAMIC_DEBOUNCE_ENABLE diff --git a/keyboards/keychron/common/debounce/eeconfig_debounce.h b/keyboards/keychron/common/debounce/eeconfig_debounce.h new file mode 100644 index 0000000000..7c12f0f189 --- /dev/null +++ b/keyboards/keychron/common/debounce/eeconfig_debounce.h @@ -0,0 +1,20 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once + +#define EECONFIG_SIZE_DEBOUNCE 2 + diff --git a/keyboards/keychron/common/debounce/keychron_debounce.c b/keyboards/keychron/common/debounce/keychron_debounce.c new file mode 100644 index 0000000000..6296d85b81 --- /dev/null +++ b/keyboards/keychron/common/debounce/keychron_debounce.c @@ -0,0 +1,214 @@ + +/* Copyright 2024 @ 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 . + */ + +#include "keychron_debounce.h" +#include "raw_hid.h" +#include "quantum.h" +#include "eeconfig.h" +#include "eeconfig_kb.h" +#include "keychron_raw_hid.h" + +#ifdef SPLIT_KEYBOARD +# pragma(error "Split keyboard is not supported") +#endif + +#ifndef DEBOUNCE +# define DEBOUNCE 5 +#endif + +// Maximum debounce: 255ms +#if DEBOUNCE > UINT8_MAX +# undef DEBOUNCE +# define DEBOUNCE UINT8_MAX +#endif + +#ifndef DEFAULT_DEBOUNCE_TYPE + #define DEFAULT_DEBOUNCE_TYPE DEBOUNCE_SYM_EAGER_PER_KEY +#endif + +#define DEBOUNCE_SET_QMK 0 +#define OFFSET_DEBOUNCE ((uint8_t *)(EECONFIG_BASE_DYNAMIC_DEBOUNCE)) + +static uint8_t debounce_type = 0; +uint8_t debounce_time = 0; +static debounce_t debounce_func = {NULL, NULL, NULL}; + +extern void sym_defer_g_debounce_init(uint8_t num_rows); +extern bool sym_defer_g_debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed); +extern void sym_defer_g_debounce_free(void); + +extern void sym_defer_pr_debounce_init(uint8_t num_rows); +extern bool sym_defer_pr_debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed); +extern void sym_defer_pr_debounce_free(void); + +extern void sym_defer_pk_debounce_init(uint8_t num_rows); +extern bool sym_defer_pk_debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed); +extern void sym_defer_pk_debounce_free(void); + +extern void sym_eager_pr_debounce_init(uint8_t num_rows); +extern bool sym_eager_pr_debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed); +extern void sym_eager_pr_debounce_free(void); + +extern void sym_eager_pk_debounce_init(uint8_t num_rows); +extern bool sym_eager_pk_debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed); +extern void sym_eager_pk_debounce_free(void); + +extern void asym_eager_defer_pk_debounce_init(uint8_t num_rows); +extern bool asym_eager_defer_pk_debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed); +extern void asym_eager_defer_pk_debounce_free(void); + +extern void none_debounce_init(uint8_t num_rows); +extern bool none_debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed); +extern void none_debounce_free(void); + +void debounce_set(uint8_t new_debounce_type, uint8_t time, bool force); + +/** + * @brief Debounce raw matrix events according to the choosen debounce algorithm. + * + * @param raw The current key state + * @param cooked The debounced key state + * @param num_rows Number of rows to debounce + * @param changed True if raw has changed since the last call + * @return true Cooked has new keychanges after debouncing + * @return false Cooked is the same as before + */ + +bool debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { + if (debounce_func.debounce) debounce_func.debounce(raw, cooked, num_rows, changed); + + return false; +} + +void debounce_init(uint8_t num_rows) { + debounce_type = 0; + + // debounce_set(DEBOUNCE_SYM_EAGER_PER_KEY, DEBOUNCE); + if (!eeconfig_is_enabled()) { + eeconfig_init(); + } + uint8_t type = eeprom_read_byte(OFFSET_DEBOUNCE); + uint8_t time = eeprom_read_byte(OFFSET_DEBOUNCE + 1); + + if (type >= DEBOUNCE_MAX) type = DEFAULT_DEBOUNCE_TYPE; + + debounce_set(type, time, debounce_type == type); +} + +void debounce_free(void) { + if (debounce_func.debounce_free) debounce_func.debounce_free(); +} + +static bool debounce_save(void) { + eeprom_update_byte(OFFSET_DEBOUNCE, debounce_type); + eeprom_update_byte(OFFSET_DEBOUNCE + 1, debounce_time); + return true; +} + +void debounce_config_reset(void) { + debounce_set(DEFAULT_DEBOUNCE_TYPE, DEBOUNCE, true); + debounce_save(); +} + +void debounce_set(uint8_t new_debounce_type, uint8_t time, bool force) { + if (new_debounce_type == debounce_type && time == debounce_time && !force) return; + + debounce_free(); + + debounce_type = new_debounce_type; + debounce_time = time; + + if (debounce_time == 0) new_debounce_type = DEBOUNCE_NONE; + + switch (new_debounce_type) { + case DEBOUNCE_SYM_DEFER_GLOBAL: + debounce_func.debounce_init = sym_defer_g_debounce_init; + debounce_func.debounce = sym_defer_g_debounce; + debounce_func.debounce_free = sym_defer_g_debounce_free; + break; + + case DEBOUNCE_SYM_DEFER_PER_ROW: + debounce_func.debounce_init = sym_defer_pr_debounce_init; + debounce_func.debounce = sym_defer_pr_debounce; + debounce_func.debounce_free = sym_defer_pr_debounce_free; + break; + + case DEBOUNCE_SYM_DEFER_PER_KEY: + debounce_func.debounce_init = sym_defer_pk_debounce_init; + debounce_func.debounce = sym_defer_pk_debounce; + debounce_func.debounce_free = sym_defer_pk_debounce_free; + break; + + case DEBOUNCE_SYM_EAGER_PER_ROW: + debounce_func.debounce_init = sym_eager_pr_debounce_init; + debounce_func.debounce = sym_eager_pr_debounce; + debounce_func.debounce_free = sym_eager_pr_debounce_free; + break; + + case DEBOUNCE_SYM_EAGER_PER_KEY: + debounce_func.debounce_init = sym_eager_pk_debounce_init; + debounce_func.debounce = sym_eager_pk_debounce; + debounce_func.debounce_free = sym_eager_pk_debounce_free; + break; + + case DEBOUNCE_ASYM_EAGER_DEFER_PER_KEY: + debounce_func.debounce_init = asym_eager_defer_pk_debounce_init; + debounce_func.debounce = asym_eager_defer_pk_debounce; + debounce_func.debounce_free = asym_eager_defer_pk_debounce_free; + if (debounce_time > 127) debounce_time = 127; + break; + + case DEBOUNCE_NONE: + debounce_func.debounce_init = none_debounce_init; + debounce_func.debounce = none_debounce; + debounce_func.debounce_free = none_debounce_free; + break; + } + + if (debounce_func.debounce_init) debounce_func.debounce_init(MATRIX_ROWS); +} + +void debounce_time_set(uint8_t time) { + debounce_time = time; +} + +void debounce_rx(uint8_t *data, uint8_t length) { + uint8_t cmd = data[1]; + switch (cmd) { + case DEBOUNCE_GET: + data[2] = 0; + data[3] = DEBOUNCE_SET_QMK; + data[4] = debounce_type; + data[5] = debounce_time; + break; + + case DEBOUNCE_SET: { + uint8_t type = data[2]; + uint8_t time = data[3]; + if (type < DEBOUNCE_MAX) { + data[2] = 0; + debounce_set(type, time, false); + debounce_save(); + } else + data[2] = 1; + } break; + + default: + data[0] = 0xFF; + break; + } +} diff --git a/keyboards/keychron/common/debounce/keychron_debounce.h b/keyboards/keychron/common/debounce/keychron_debounce.h new file mode 100644 index 0000000000..40ea5800e2 --- /dev/null +++ b/keyboards/keychron/common/debounce/keychron_debounce.h @@ -0,0 +1,56 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once + +#include +#include +#include "matrix.h" + +enum { + DEBOUNCE_SYM_DEFER_GLOBAL, + DEBOUNCE_SYM_DEFER_PER_ROW, + DEBOUNCE_SYM_DEFER_PER_KEY, + DEBOUNCE_SYM_EAGER_PER_ROW, + DEBOUNCE_SYM_EAGER_PER_KEY, + DEBOUNCE_ASYM_EAGER_DEFER_PER_KEY, + DEBOUNCE_NONE, + DEBOUNCE_MAX, +}; + +typedef struct { + void (*debounce_init)(uint8_t); + bool (*debounce)(matrix_row_t [], matrix_row_t [], uint8_t, bool); + void (*debounce_free)(void); +} debounce_t; + +/** + * @brief Debounce raw matrix events according to the choosen debounce algorithm. + * + * @param raw The current key state + * @param cooked The debounced key state + * @param num_rows Number of rows to debounce + * @param changed True if raw has changed since the last call + * @return true Cooked has new keychanges after debouncing + * @return false Cooked is the same as before + */ +bool debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed); + +void debounce_init(uint8_t num_rows); +void debounce_config_reset(void); + +void debounce_free(void); +void debounce_rx(uint8_t *data, uint8_t length); diff --git a/keyboards/keychron/common/debounce/none.c b/keyboards/keychron/common/debounce/none.c new file mode 100644 index 0000000000..244236803c --- /dev/null +++ b/keyboards/keychron/common/debounce/none.c @@ -0,0 +1,36 @@ +/* Copyright 2021 Simon Arlott + * + * 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 "debounce.h" +#include + +void none_debounce_init(uint8_t num_rows) {} + +bool none_debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { + bool cooked_changed = false; + + if (changed) { + size_t matrix_size = num_rows * sizeof(matrix_row_t); + if (memcmp(cooked, raw, matrix_size) != 0) { + memcpy(cooked, raw, matrix_size); + cooked_changed = true; + } + } + + return cooked_changed; +} + +void none_debounce_free(void) {} diff --git a/keyboards/keychron/common/debounce/none.h b/keyboards/keychron/common/debounce/none.h new file mode 100644 index 0000000000..244236803c --- /dev/null +++ b/keyboards/keychron/common/debounce/none.h @@ -0,0 +1,36 @@ +/* Copyright 2021 Simon Arlott + * + * 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 "debounce.h" +#include + +void none_debounce_init(uint8_t num_rows) {} + +bool none_debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { + bool cooked_changed = false; + + if (changed) { + size_t matrix_size = num_rows * sizeof(matrix_row_t); + if (memcmp(cooked, raw, matrix_size) != 0) { + memcpy(cooked, raw, matrix_size); + cooked_changed = true; + } + } + + return cooked_changed; +} + +void none_debounce_free(void) {} diff --git a/keyboards/keychron/common/debounce/sym_defer_g.c b/keyboards/keychron/common/debounce/sym_defer_g.c new file mode 100644 index 0000000000..f1b475846c --- /dev/null +++ b/keyboards/keychron/common/debounce/sym_defer_g.c @@ -0,0 +1,51 @@ +/* +Copyright 2017 Alex Ong +Copyright 2021 Simon Arlott +Copyright 2024 @ 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 . +*/ + +/* +Basic global debounce algorithm. Used in 99% of keyboards at time of implementation +When no state changes have occured for DEBOUNCE milliseconds, we push the state. +*/ +#include "debounce.h" +#include "timer.h" +#include + +extern uint8_t debounce_time; +static bool debouncing = false; +static fast_timer_t debouncing_time; + +void sym_defer_g_debounce_init(uint8_t num_rows) {} + +bool sym_defer_g_debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { + bool cooked_changed = false; + + if (changed) { + debouncing = true; + debouncing_time = timer_read_fast(); + } else if (debouncing && timer_elapsed_fast(debouncing_time) >= debounce_time) { + size_t matrix_size = num_rows * sizeof(matrix_row_t); + if (memcmp(cooked, raw, matrix_size) != 0) { + memcpy(cooked, raw, matrix_size); + cooked_changed = true; + } + debouncing = false; + } + + return cooked_changed; +} + +void sym_defer_g_debounce_free(void) {} + diff --git a/keyboards/keychron/common/debounce/sym_defer_pk.c b/keyboards/keychron/common/debounce/sym_defer_pk.c new file mode 100644 index 0000000000..633d5c3ebc --- /dev/null +++ b/keyboards/keychron/common/debounce/sym_defer_pk.c @@ -0,0 +1,137 @@ +/* +Copyright 2017 Alex Ong +Copyright 2020 Andrei Purdea +Copyright 2021 Simon Arlott +Copyright 2024 @ 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 . +*/ + +/* +Basic symmetric per-key algorithm. Uses an 8-bit counter per key. +When no state changes have occured for DEBOUNCE milliseconds, we push the state. +*/ + +#include "debounce.h" +#include "timer.h" +#include + +#ifdef PROTOCOL_CHIBIOS +# if CH_CFG_USE_MEMCORE == FALSE +# error ChibiOS is configured without a memory allocator. Your keyboard may have set `#define CH_CFG_USE_MEMCORE FALSE`, which is incompatible with this debounce algorithm. +# endif +#endif + + +#define ROW_SHIFTER ((matrix_row_t)1) + +typedef uint8_t debounce_counter_t; + +extern uint8_t debounce_time; + +static debounce_counter_t *debounce_counters = NULL; +static fast_timer_t last_time; +static bool counters_need_update; +static bool cooked_changed; + +# define DEBOUNCE_ELAPSED 0 + +static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t elapsed_time); +static void start_debounce_counters(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows); + +// we use num_rows rather than MATRIX_ROWS to support split keyboards +void sym_defer_pk_debounce_init(uint8_t num_rows) { + debounce_counters = (debounce_counter_t *)malloc(num_rows * MATRIX_COLS * sizeof(debounce_counter_t)); + + int i = 0; + for (uint8_t r = 0; r < num_rows; r++) { + for (uint8_t c = 0; c < MATRIX_COLS; c++) { + debounce_counters[i++] = DEBOUNCE_ELAPSED; + } + } +} + +void sym_defer_pk_debounce_free(void) { + if (debounce_counters != NULL) { + free(debounce_counters); + debounce_counters = NULL; + } +} + +bool sym_defer_pk_debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { + bool updated_last = false; + cooked_changed = false; + + if (counters_need_update) { + fast_timer_t now = timer_read_fast(); + fast_timer_t elapsed_time = TIMER_DIFF_FAST(now, last_time); + + last_time = now; + updated_last = true; + if (elapsed_time > UINT8_MAX) { + elapsed_time = UINT8_MAX; + } + + if (elapsed_time > 0) { + update_debounce_counters_and_transfer_if_expired(raw, cooked, num_rows, elapsed_time); + } + } + + if (changed) { + if (!updated_last) { + last_time = timer_read_fast(); + } + + start_debounce_counters(raw, cooked, num_rows); + } + + return cooked_changed; +} + +static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t elapsed_time) { + counters_need_update = false; + debounce_counter_t *debounce_pointer = debounce_counters; + for (uint8_t row = 0; row < num_rows; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + if (*debounce_pointer != DEBOUNCE_ELAPSED) { + if (*debounce_pointer <= elapsed_time) { + *debounce_pointer = DEBOUNCE_ELAPSED; + matrix_row_t cooked_next = (cooked[row] & ~(ROW_SHIFTER << col)) | (raw[row] & (ROW_SHIFTER << col)); + cooked_changed |= cooked[row] ^ cooked_next; + cooked[row] = cooked_next; + } else { + *debounce_pointer -= elapsed_time; + counters_need_update = true; + } + } + debounce_pointer++; + } + } +} + +static void start_debounce_counters(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) { + debounce_counter_t *debounce_pointer = debounce_counters; + for (uint8_t row = 0; row < num_rows; row++) { + matrix_row_t delta = raw[row] ^ cooked[row]; + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + if (delta & (ROW_SHIFTER << col)) { + if (*debounce_pointer == DEBOUNCE_ELAPSED) { + *debounce_pointer = debounce_time;; + counters_need_update = true; + } + } else { + *debounce_pointer = DEBOUNCE_ELAPSED; + } + debounce_pointer++; + } + } +} diff --git a/keyboards/keychron/common/debounce/sym_defer_pr.c b/keyboards/keychron/common/debounce/sym_defer_pr.c new file mode 100644 index 0000000000..c295855061 --- /dev/null +++ b/keyboards/keychron/common/debounce/sym_defer_pr.c @@ -0,0 +1,80 @@ +/* +Copyright 2021 Chad Austin +Copyright 2024 @ 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 . +*/ + +/* +Symmetric per-row debounce algorithm. Changes only apply when +DEBOUNCE milliseconds have elapsed since the last change. +*/ + +#include "debounce.h" +#include "timer.h" +#include + +extern uint8_t debounce_time; + +static uint16_t last_time; +// [row] milliseconds until key's state is considered debounced. +static uint8_t* countdowns = NULL; +// [row] +static matrix_row_t* last_raw = NULL; + +void sym_defer_pr_debounce_init(uint8_t num_rows) { + countdowns = (uint8_t*)calloc(num_rows, sizeof(uint8_t)); + last_raw = (matrix_row_t*)calloc(num_rows, sizeof(matrix_row_t)); + last_time = timer_read(); +} + +void sym_defer_pr_debounce_free(void) { + if (countdowns != NULL) { + free(countdowns); + countdowns = NULL; + } + if (last_raw != NULL) { + free(last_raw); + last_raw = NULL; + } +} + +bool sym_defer_pr_debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { + uint16_t now = timer_read(); + uint16_t elapsed16 = TIMER_DIFF_16(now, last_time); + last_time = now; + uint8_t elapsed = (elapsed16 > 255) ? 255 : elapsed16; + bool cooked_changed = false; + + uint8_t* countdown = countdowns; + + for (uint8_t row = 0; row < num_rows; ++row, ++countdown) { + matrix_row_t raw_row = raw[row]; + + if (raw_row != last_raw[row]) { + *countdown = debounce_time; + last_raw[row] = raw_row; + } else if (*countdown > elapsed) { + *countdown -= elapsed; + } else if (*countdown) { + cooked_changed |= cooked[row] ^ raw_row; + cooked[row] = raw_row; + *countdown = 0; + } + } + + return cooked_changed; +} + +bool debounce_active(void) { + return true; +} diff --git a/keyboards/keychron/common/debounce/sym_eager_pk.c b/keyboards/keychron/common/debounce/sym_eager_pk.c new file mode 100644 index 0000000000..fe3655172c --- /dev/null +++ b/keyboards/keychron/common/debounce/sym_eager_pk.c @@ -0,0 +1,142 @@ +/* +Copyright 2017 Alex Ong +Copyright 2021 Simon Arlott +Copyright 2024 @ 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 . +*/ + +/* +Basic per-key algorithm. Uses an 8-bit counter per key. +After pressing a key, it immediately changes state, and sets a counter. +No further inputs are accepted until DEBOUNCE milliseconds have occurred. +*/ + +#include "debounce.h" +#include "timer.h" +#include + +#ifdef PROTOCOL_CHIBIOS +# if CH_CFG_USE_MEMCORE == FALSE +# error ChibiOS is configured without a memory allocator. Your keyboard may have set `#define CH_CFG_USE_MEMCORE FALSE`, which is incompatible with this debounce algorithm. +# endif +#endif + +extern uint8_t debounce_time; + +#define ROW_SHIFTER ((matrix_row_t)1) + +typedef uint8_t debounce_counter_t; + + +static debounce_counter_t *debounce_counters = NULL; +static fast_timer_t last_time; +static bool counters_need_update; +static bool matrix_need_update; +static bool cooked_changed; + +# define DEBOUNCE_ELAPSED 0 + +static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time); +static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows); + +// we use num_rows rather than MATRIX_ROWS to support split keyboards +void sym_eager_pk_debounce_init(uint8_t num_rows) { + debounce_counters = (debounce_counter_t *)malloc(num_rows * MATRIX_COLS * sizeof(debounce_counter_t)); + int i = 0; + for (uint8_t r = 0; r < num_rows; r++) { + for (uint8_t c = 0; c < MATRIX_COLS; c++) { + debounce_counters[i++] = DEBOUNCE_ELAPSED; + } + } +} + +void sym_eager_pk_debounce_free(void) { + if (debounce_counters != NULL) { + free(debounce_counters); + debounce_counters = NULL; + } +} + +bool sym_eager_pk_debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { + bool updated_last = false; + cooked_changed = false; + + if (counters_need_update) { + fast_timer_t now = timer_read_fast(); + fast_timer_t elapsed_time = TIMER_DIFF_FAST(now, last_time); + + last_time = now; + updated_last = true; + if (elapsed_time > UINT8_MAX) { + elapsed_time = UINT8_MAX; + } + + if (elapsed_time > 0) { + update_debounce_counters(num_rows, elapsed_time); + } + } + + if (changed || matrix_need_update) { + if (!updated_last) { + last_time = timer_read_fast(); + } + + transfer_matrix_values(raw, cooked, num_rows); + } + + return cooked_changed; +} + +// If the current time is > debounce counter, set the counter to enable input. +static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time) { + counters_need_update = false; + matrix_need_update = false; + debounce_counter_t *debounce_pointer = debounce_counters; + for (uint8_t row = 0; row < num_rows; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + if (*debounce_pointer != DEBOUNCE_ELAPSED) { + if (*debounce_pointer <= elapsed_time) { + *debounce_pointer = DEBOUNCE_ELAPSED; + matrix_need_update = true; + } else { + *debounce_pointer -= elapsed_time; + counters_need_update = true; + } + } + debounce_pointer++; + } + } +} + +// upload from raw_matrix to final matrix; +static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) { + matrix_need_update = false; + debounce_counter_t *debounce_pointer = debounce_counters; + for (uint8_t row = 0; row < num_rows; row++) { + matrix_row_t delta = raw[row] ^ cooked[row]; + matrix_row_t existing_row = cooked[row]; + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + matrix_row_t col_mask = (ROW_SHIFTER << col); + if (delta & col_mask) { + if (*debounce_pointer == DEBOUNCE_ELAPSED) { + *debounce_pointer = debounce_time; + counters_need_update = true; + existing_row ^= col_mask; // flip the bit. + cooked_changed = true; + } + } + debounce_pointer++; + } + cooked[row] = existing_row; + } +} diff --git a/keyboards/keychron/common/debounce/sym_eager_pr.c b/keyboards/keychron/common/debounce/sym_eager_pr.c new file mode 100644 index 0000000000..85488f1063 --- /dev/null +++ b/keyboards/keychron/common/debounce/sym_eager_pr.c @@ -0,0 +1,134 @@ +/* +Copyright 2019 Alex Ong +Copyright 2021 Simon Arlott +Copyright 2024 @ 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 . +*/ + +/* +Basic per-row algorithm. Uses an 8-bit counter per row. +After pressing a key, it immediately changes state, and sets a counter. +No further inputs are accepted until DEBOUNCE milliseconds have occurred. +*/ + +#include "debounce.h" +#include "timer.h" +#include + +#ifdef PROTOCOL_CHIBIOS +# if CH_CFG_USE_MEMCORE == FALSE +# error ChibiOS is configured without a memory allocator. Your keyboard may have set `#define CH_CFG_USE_MEMCORE FALSE`, which is incompatible with this debounce algorithm. +# endif +#endif + + +typedef uint8_t debounce_counter_t; + +extern uint8_t debounce_time; + +static bool matrix_need_update; + +static debounce_counter_t *debounce_counters = NULL; +static fast_timer_t last_time; +static bool counters_need_update; +static bool cooked_changed; + +# define DEBOUNCE_ELAPSED 0 + +static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time); +static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows); + +// we use num_rows rather than MATRIX_ROWS to support split keyboards +void sym_eager_pr_debounce_init(uint8_t num_rows) { + debounce_counters = (debounce_counter_t *)malloc(num_rows * sizeof(debounce_counter_t)); + for (uint8_t r = 0; r < num_rows; r++) { + debounce_counters[r] = DEBOUNCE_ELAPSED; + } +} + +void sym_eager_pr_debounce_free(void) { + if (debounce_counters != NULL) { + free(debounce_counters); + debounce_counters = NULL; + } +} + +bool sym_eager_pr_debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { + bool updated_last = false; + cooked_changed = false; + + if (counters_need_update) { + fast_timer_t now = timer_read_fast(); + fast_timer_t elapsed_time = TIMER_DIFF_FAST(now, last_time); + + last_time = now; + updated_last = true; + if (elapsed_time > UINT8_MAX) { + elapsed_time = UINT8_MAX; + } + + if (elapsed_time > 0) { + update_debounce_counters(num_rows, elapsed_time); + } + } + + if (changed || matrix_need_update) { + if (!updated_last) { + last_time = timer_read_fast(); + } + + transfer_matrix_values(raw, cooked, num_rows); + } + + return cooked_changed; +} + +// If the current time is > debounce counter, set the counter to enable input. +static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time) { + counters_need_update = false; + matrix_need_update = false; + debounce_counter_t *debounce_pointer = debounce_counters; + for (uint8_t row = 0; row < num_rows; row++) { + if (*debounce_pointer != DEBOUNCE_ELAPSED) { + if (*debounce_pointer <= elapsed_time) { + *debounce_pointer = DEBOUNCE_ELAPSED; + matrix_need_update = true; + } else { + *debounce_pointer -= elapsed_time; + counters_need_update = true; + } + } + debounce_pointer++; + } +} + +// upload from raw_matrix to final matrix; +static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) { + matrix_need_update = false; + debounce_counter_t *debounce_pointer = debounce_counters; + for (uint8_t row = 0; row < num_rows; row++) { + matrix_row_t existing_row = cooked[row]; + matrix_row_t raw_row = raw[row]; + + // determine new value basd on debounce pointer + raw value + if (existing_row != raw_row) { + if (*debounce_pointer == DEBOUNCE_ELAPSED) { + *debounce_pointer = debounce_time; + cooked_changed |= cooked[row] ^ raw_row; + cooked[row] = raw_row; + counters_need_update = true; + } + } + debounce_pointer++; + } +} diff --git a/keyboards/keychron/common/dfu_info.c b/keyboards/keychron/common/dfu_info.c new file mode 100644 index 0000000000..47c6012046 --- /dev/null +++ b/keyboards/keychron/common/dfu_info.c @@ -0,0 +1,49 @@ +/* Copyright 2024 @ 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 . + */ + +#include +#include "quantum.h" + +enum { + DFU_INFO_CHIP = 1, + DFU_INFO_TYPE, +}; + +enum { + BL_TYPE_STM32 = 1, + BL_TYPE_WB32, +}; + +void dfu_info_rx(uint8_t *data, uint8_t length) { + uint8_t i = 2; + + data[i++] = 0; // success + data[i++] = DFU_INFO_CHIP, + data[i++] = strlen(STR(QMK_MCU)); + memcpy(&data[i], STR(QMK_MCU), strlen(STR(QMK_MCU))); + i += strlen(STR(QMK_MCU)); + data[i++] = DFU_INFO_TYPE; + data[i++] = 1; + data[i++] = +#if defined(BOOTLOADER_STM32_DFU) + BL_TYPE_STM32 +#elif defined(BOOTLOADER_WB32_DFU) + BL_TYPE_WB32 +#else + 0 +#endif + ; +} diff --git a/keyboards/keychron/common/eeconfig_kb.c b/keyboards/keychron/common/eeconfig_kb.c new file mode 100644 index 0000000000..a0a15828ac --- /dev/null +++ b/keyboards/keychron/common/eeconfig_kb.c @@ -0,0 +1,35 @@ +/* Copyright 2024 @ 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 . + */ + +#include "eeconfig_kb.h" +#ifdef DYNAMIC_DEBOUNCE_ENABLE +# include "keychron_debounce.h" +#endif + +void eeconfig_init_kb_datablock(void) { +#ifdef DYNAMIC_DEBOUNCE_ENABLE + extern void debounce_config_reset(void); + debounce_config_reset(); +#endif +#if defined(SNAP_CLICK_ENABLE) + extern void snap_click_config_reset(void); + snap_click_config_reset(); +#endif +#if defined(KEYCHRON_RGB_ENABLE) && defined(RGB_MATRIX_ENABLE) + extern void eeconfig_reset_custom_rgb(void); + eeconfig_reset_custom_rgb(); +#endif +} diff --git a/keyboards/keychron/common/eeconfig_kb.h b/keyboards/keychron/common/eeconfig_kb.h new file mode 100644 index 0000000000..dd995bb993 --- /dev/null +++ b/keyboards/keychron/common/eeconfig_kb.h @@ -0,0 +1,61 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once + +#include "eeconfig_language.h" + +#define EECONFIG_BASE_LANGUAGE 37 +#define EECONFIG_END_LANGUAGE (EECONFIG_BASE_LANGUAGE + EECONFIG_SIZE_LANGUAGE) + +#ifdef DYNAMIC_DEBOUNCE_ENABLE +# include "eeconfig_debounce.h" +# define __EECONFIG_SIZE_DEBOUNCE EECONFIG_SIZE_DEBOUNCE +#else +# define __EECONFIG_SIZE_DEBOUNCE 0 +#endif +#define EECONFIG_BASE_DYNAMIC_DEBOUNCE EECONFIG_END_LANGUAGE +#define EECONFIG_END_DYNAMIC_DEBOUNCE (EECONFIG_BASE_DYNAMIC_DEBOUNCE + __EECONFIG_SIZE_DEBOUNCE) + +#ifdef SNAP_CLICK_ENABLE +# include "eeconfig_snap_click.h" +# define __EECONFIG_SIZE_SNAP_CLICK EECONFIG_SIZE_SNAP_CLICK +#else +# define __EECONFIG_SIZE_SNAP_CLICK 0 +#endif +#define EECONFIG_BASE_SNAP_CLICK (EECONFIG_END_DYNAMIC_DEBOUNCE) +#define EECONFIG_END_SNAP_CLICK (EECONFIG_BASE_SNAP_CLICK + __EECONFIG_SIZE_SNAP_CLICK) + +#if defined(KEYCHRON_RGB_ENABLE) && defined(RGB_MATRIX_ENABLE) +# include "eeconfig_custom_rgb.h" +# define __EECONFIG_SIZE_CUSTOM_RGB EECONFIG_SIZE_CUSTOM_RGB +#else +# define __EECONFIG_SIZE_CUSTOM_RGB 0 +#endif +#define EECONFIG_BASE_CUSTOM_RGB EECONFIG_END_SNAP_CLICK +#define EECONFIG_END_CUSTOM_RGB (EECONFIG_BASE_CUSTOM_RGB + __EECONFIG_SIZE_CUSTOM_RGB) + +#if defined(WIRELESS_CONFIG_ENABLE) +# include "eeconfig_wireless.h" +# define __EECONFIG_SIZE_WIRELESS_CONFIG EECONFIG_SIZE_WIRELESS_CONFIG +#else +# define __EECONFIG_SIZE_WIRELESS_CONFIG 0 +#endif +#define EECONFIG_BASE_WIRELESS_CONFIG EECONFIG_END_CUSTOM_RGB +#define EECONFIG_END_WIRELESS_CONFIG (EECONFIG_BASE_WIRELESS_CONFIG + __EECONFIG_SIZE_WIRELESS_CONFIG) + +#define EECONFIG_KB_DATA_SIZE (EECONFIG_END_WIRELESS_CONFIG - EECONFIG_BASE_LANGUAGE) + diff --git a/keyboards/keychron/common/factory_test.c b/keyboards/keychron/common/factory_test.c new file mode 100644 index 0000000000..ebf0e460b0 --- /dev/null +++ b/keyboards/keychron/common/factory_test.c @@ -0,0 +1,465 @@ +/* Copyright 2021~2025 @ 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 . + */ + +#include "quantum.h" +#include "raw_hid.h" +#include "via.h" + +#include "keychron_task.h" +#ifdef LK_WIRELESS_ENABLE +# include "transport.h" +# include "battery.h" +# include "lpm.h" +# include "lkbt51.h" +# include "indicator.h" +#endif +#ifdef DYNAMIC_DEBOUNCE_ENABLE +# include "keychron_debounce.h" +#endif +#ifdef SNAP_CLICK_ENABLE +# include "snap_click.h" +#endif +#include "config.h" +#include "version.h" + +#ifndef RAW_EPSIZE +# define RAW_EPSIZE 32 +#endif + +#ifndef BL_CYCLE_KEY +# define BL_CYCLE_KEY KC_RIGHT +#endif + +#ifndef BL_TRIG_KEY +# define BL_TRIG_KEY KC_HOME +#endif + +#ifndef P2P4G_CELAR_MASK +# define P2P4G_CELAR_MASK P2P4G_CLEAR_PAIRING_TYPE_C +#endif + +enum { + BACKLIGHT_TEST_OFF = 0, + BACKLIGHT_TEST_WHITE, + BACKLIGHT_TEST_RED, + BACKLIGHT_TEST_GREEN, + BACKLIGHT_TEST_BLUE, + BACKLIGHT_TEST_MAX, +}; + +enum { + KEY_PRESS_FN = 0x01 << 0, + KEY_PRESS_J = 0x01 << 1, + KEY_PRESS_Z = 0x01 << 2, + KEY_PRESS_BL_KEY1 = 0x01 << 3, + KEY_PRESS_BL_KEY2 = 0x01 << 4, + KEY_PRESS_FACTORY_RESET = KEY_PRESS_FN | KEY_PRESS_J | KEY_PRESS_Z, + 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 { + P2P4G_CLEAR_PAIRING_TYPE_A = 0x01 << 0, + P2P4G_CLEAR_PAIRING_TYPE_C = 0x01 << 1, +}; + +enum { + OS_SWITCH = 0x01, +}; + +static uint32_t factory_reset_timer = 0; +static uint8_t factory_reset_state = 0; +static uint8_t backlight_test_mode = BACKLIGHT_TEST_OFF; + +static uint32_t factory_reset_ind_timer = 0; +static uint8_t factory_reset_ind_state = 0; +static bool report_os_sw_state = false; +static uint8_t keys_released = 0; + +extern void eeconfig_reset_custom_rgb(void); + +void factory_timer_start(void) { + factory_reset_timer = timer_read32(); +} + +static inline void factory_timer_check(void) { + if (timer_elapsed32(factory_reset_timer) > 3000) { + factory_reset_timer = 0; + + if (factory_reset_state == KEY_PRESS_FACTORY_RESET) { + factory_reset_ind_timer = timer_read32(); + factory_reset_ind_state++; + keys_released = false; + + clear_keyboard(); // Avoid key being pressed after NKRO state changed + layer_state_t default_layer_tmp = default_layer_state; + eeconfig_init(); + keymap_config.raw = eeconfig_read_keymap(); + default_layer_set(default_layer_tmp); +#ifdef DYNAMIC_DEBOUNCE_ENABLE + debounce_config_reset(); +#endif +#ifdef SNAP_CLICK_ENABLE + snap_click_config_reset(); +#endif +#ifdef LED_MATRIX_ENABLE + if (!led_matrix_is_enabled()) led_matrix_enable(); + led_matrix_init(); +#endif +#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) + eeconfig_reset_custom_rgb(); +# endif +#endif +#ifdef LK_WIRELESS_ENABLE +# ifdef EECONFIG_SIZE_WIRELESS_CONFIG + wireless_config_reset(); +# endif + wait_ms(50); + lkbt51_factory_reset(P2P4G_CELAR_MASK); +#endif + } else if (factory_reset_state == KEY_PRESS_BACKLIGTH_TEST) { +#ifdef LED_MATRIX_ENABLE + if (!led_matrix_is_enabled()) led_matrix_enable(); +#endif +#ifdef RGB_MATRIX_ENABLE + if (!rgb_matrix_is_enabled()) rgb_matrix_enable(); +#endif + backlight_test_mode = BACKLIGHT_TEST_WHITE; + } + + factory_reset_state = 0; + } +} + +static inline void factory_reset_ind_timer_check(void) { + if (factory_reset_ind_timer && timer_elapsed32(factory_reset_ind_timer) > 250) { + if (factory_reset_ind_state++ > 6) { + factory_reset_ind_timer = factory_reset_ind_state = 0; + } else { + factory_reset_ind_timer = timer_read32(); + } + } +} + +bool process_record_factory_test(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { +#if defined(FN_KEY_1) || defined(FN_KEY_2) +# if defined(FN_KEY_1) + case FN_KEY_1: /* fall through */ +# endif +# if defined(FN_KEY_2) + case FN_KEY_2: +# endif +# if defined(FN_KEY_3) + case FN_KEY_3: +# endif + if (record->event.pressed) { + factory_reset_state |= KEY_PRESS_FN; + } else { + factory_reset_state &= ~KEY_PRESS_FN; + factory_reset_timer = 0; + } + break; +#endif + case KC_J: +#if defined(FN_J_KEY) + case FN_J_KEY: +#endif + if (record->event.pressed) { + factory_reset_state |= KEY_PRESS_J; + if (factory_reset_state == 0x07) factory_timer_start(); + if ((factory_reset_state & KEY_PRESS_FN) && keycode == KC_J) return false; + } else { + factory_reset_state &= ~KEY_PRESS_J; + factory_reset_timer = 0; + /* Avoid changing backlight effect on key released if FN_Z_KEY is mode*/ + if (keys_released & KEY_PRESS_J) { + keys_released &= ~KEY_PRESS_J; + if (keycode >= QK_BACKLIGHT_ON && keycode <= RGB_MODE_TWINKLE) return false; + } + } + break; + case KC_Z: +#if defined(FN_Z_KEY) + case FN_Z_KEY: +#endif + if (record->event.pressed) { + factory_reset_state |= KEY_PRESS_Z; + if (factory_reset_state == 0x07) factory_timer_start(); + if ((factory_reset_state & KEY_PRESS_FN) && keycode == KC_Z) return false; + } else { + factory_reset_state &= ~KEY_PRESS_Z; + factory_reset_timer = 0; + /* Avoid changing backlight effect on key released if FN_Z_KEY is mode*/ + if (keys_released & KEY_PRESS_Z) { + keys_released &= ~KEY_PRESS_Z; + if (keycode >= QK_BACKLIGHT_ON && keycode <= RGB_MODE_TWINKLE) return false; + } + } + break; +#if defined(BL_CYCLE_KEY) || defined(BL_CYCLE_KEY_2) +# if defined(BL_CYCLE_KEY) + case BL_CYCLE_KEY: +# endif +# if defined(FN_BL_CYCLE_KEY) + case FN_BL_CYCLE_KEY: +# endif + if (record->event.pressed) { + if (backlight_test_mode) { + if (++backlight_test_mode >= BACKLIGHT_TEST_MAX) { + backlight_test_mode = BACKLIGHT_TEST_WHITE; + } + } else { + factory_reset_state |= KEY_PRESS_BL_KEY1; + if (factory_reset_state == 0x19) { + factory_timer_start(); + } + } + } else { + factory_reset_state &= ~KEY_PRESS_BL_KEY1; + factory_reset_timer = 0; + } + break; +#endif +#if defined(BL_TRIG_KEY) || defined(BL_TRIG_KEY_2) +# if defined(BL_TRIG_KEY) + case BL_TRIG_KEY: +# endif +# if defined(FN_BL_TRIG_KEY) + case FN_BL_TRIG_KEY: +# endif + if (record->event.pressed) { + if (backlight_test_mode) { + backlight_test_mode = BACKLIGHT_TEST_OFF; + } else { + factory_reset_state |= KEY_PRESS_BL_KEY2; + if (factory_reset_state == 0x19) { + factory_timer_start(); + } + } + } else { + factory_reset_state &= ~KEY_PRESS_BL_KEY2; + factory_reset_timer = 0; + } + break; +#endif + } + + return true; +} + +#ifdef LED_MATRIX_ENABLE +bool factory_test_indicator(void) { + if (factory_reset_ind_state) { + led_matrix_set_value_all(factory_reset_ind_state % 2 ? 0 : 255); + return false; + } + + return true; +} +#endif + +#ifdef RGB_MATRIX_ENABLE +bool factory_test_indicator(void) { + if (factory_reset_ind_state) { + backlight_test_mode = BACKLIGHT_TEST_OFF; + rgb_matrix_set_color_all(factory_reset_ind_state % 2 ? 0 : 255, 0, 0); + return false; + } else if (backlight_test_mode) { + switch (backlight_test_mode) { + case BACKLIGHT_TEST_WHITE: + rgb_matrix_set_color_all(255, 255, 255); + break; + case BACKLIGHT_TEST_RED: + rgb_matrix_set_color_all(255, 0, 0); + break; + case BACKLIGHT_TEST_GREEN: + rgb_matrix_set_color_all(0, 255, 0); + break; + case BACKLIGHT_TEST_BLUE: + rgb_matrix_set_color_all(0, 0, 255); + break; + } + return false; + } + + return true; +} +#endif + +bool factory_reset_indicating(void) { + return factory_reset_ind_timer; +} + +bool factory_test_task(void) { + if (factory_reset_timer) factory_timer_check(); + if (factory_reset_ind_timer) factory_reset_ind_timer_check(); + + return true; +} + +void factory_test_send(uint8_t *payload, uint8_t length) { +#ifdef RAW_ENABLE + uint16_t checksum = 0; + uint8_t data[RAW_EPSIZE] = {0}; + + uint8_t i = 0; + data[i++] = 0xAB; + + memcpy(&data[i], payload, length); + i += length; + + for (uint8_t i = 1; i < RAW_EPSIZE - 3; i++) + checksum += data[i]; + data[RAW_EPSIZE - 2] = checksum & 0xFF; + data[RAW_EPSIZE - 1] = (checksum >> 8) & 0xFF; + + raw_hid_send(data, RAW_EPSIZE); +#endif +} + +void factory_test_rx(uint8_t *data, uint8_t length) { + if (data[0] == 0xAB) { + uint16_t checksum = 0; + + for (uint8_t i = 1; i < RAW_EPSIZE - 3; i++) { + checksum += data[i]; + } + /* Verify checksum */ + if ((checksum & 0xFF) != data[RAW_EPSIZE - 2] || checksum >> 8 != data[RAW_EPSIZE - 1]) return; + + uint8_t payload[32]; + uint8_t len = 0; + + switch (data[1]) { + case FACTORY_TEST_CMD_BACKLIGHT: + backlight_test_mode = data[2]; + factory_reset_timer = 0; + break; + case FACTORY_TEST_CMD_OS_SWITCH: + report_os_sw_state = data[2]; + if (report_os_sw_state) { + // dip_switch_read(true); + } + break; + case FACTORY_TEST_CMD_JUMP_TO_BL: + // if (memcmp(&data[2], "JumpToBootloader", strlen("JumpToBootloader")) == 0) bootloader_jump(); + break; +#ifdef LK_WIRELESS_ENABLE + case FACTORY_TEST_CMD_INT_PIN: + switch (data[2]) { + /* Enalbe/disable test */ + case 0xA1: + lkbt51_int_pin_test(data[3]); + break; + /* Set INT state */ + case 0xA2: + kc_printf("pin %d\n\r", data[3]); + writePin(BLUETOOTH_INT_OUTPUT_PIN, data[3]); + break; + /* Report INT state */ + // case 0xA3: + // payload[len++] = FACTORY_TEST_CMD_INT_PIN; + // payload[len++] = 0xA3; + // payload[len++] = readPin(LKBT51_INT_INPUT_PIN); + // factory_test_send(payload, len); + // break; + } + break; + case FACTORY_TEST_CMD_GET_TRANSPORT: + payload[len++] = FACTORY_TEST_CMD_GET_TRANSPORT; + payload[len++] = get_transport(); + payload[len++] = readPin(USB_POWER_SENSE_PIN); + factory_test_send(payload, len); + break; +#endif +#ifdef BATTERY_CHARGE_DONE_DETECT_ADC + case FACTORY_TEST_CMD_CHARGING_ADC: + case 0xA1: + battery_charging_monitor(data[3]); + break; + case 0xA2: + payload[len++] = FACTORY_TEST_CMD_CHARGING_ADC; + payload[len++] = battery_adc_read_charging_pin(); + factory_test_send(payload, len); + break; +#endif +#ifdef LK_WIRELESS_ENABLE + case FACTORY_TEST_CMD_RADIO_CARRIER: + if (data[2] < 79) lkbt51_radio_test(data[2]); + break; + +# ifdef WERELESS_PRESSURE_TEST + case 0x70: + switch (data[2]) { + /* Enalbe/disable test */ + case 0xB1: + SEND_STRING("abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890\n"); + break; + case 0xB2: + payload[len++] = 0x70; + payload[len++] = 0xB2; + payload[len++] = wireless_get_state(); + factory_test_send(payload, len); + break; + } + break; +# endif +#endif + case FACTORY_TEST_CMD_GET_BUILD_TIME: { + payload[len++] = FACTORY_TEST_CMD_GET_BUILD_TIME; + payload[len++] = 'v'; + if ((DEVICE_VER & 0xF000) != 0) itoa((DEVICE_VER >> 12), (char *)&payload[len++], 16); + itoa((DEVICE_VER >> 8) & 0xF, (char *)&payload[len++], 16); + payload[len++] = '.'; + itoa((DEVICE_VER >> 4) & 0xF, (char *)&payload[len++], 16); + payload[len++] = '.'; + itoa((DEVICE_VER >> 4) & 0xF, (char *)&payload[len++], 16); + payload[len++] = ' '; + memcpy(&payload[len], QMK_BUILDDATE, sizeof(QMK_BUILDDATE)); + len += sizeof(QMK_BUILDDATE); + factory_test_send(payload, len); + } break; + + case FACTORY_TEST_CMD_GET_DEVICE_ID: + payload[len++] = FACTORY_TEST_CMD_GET_DEVICE_ID; + 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); + + len += 12; + factory_test_send(payload, len); + break; + } + } +} + +/* 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; */ +/* } */ diff --git a/keyboards/keychron/common/factory_test.h b/keyboards/keychron/common/factory_test.h new file mode 100644 index 0000000000..a98d10043c --- /dev/null +++ b/keyboards/keychron/common/factory_test.h @@ -0,0 +1,34 @@ +/* Copyright 2022 @ lokher (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 . + */ + +#pragma once + +#define FACTORY_RESET_CHECK process_record_factory_test +#define FACTORY_RESET_TASK factory_test_task + +void factory_test_init(void); + +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) +bool factory_test_indicator(void); +#endif + +//void process_record_factory_test(uint16_t keycode, keyrecord_t *record); +bool factory_reset_indicating(void); +void factory_test_task(void); +void factory_test_rx(uint8_t *data, uint8_t length); + +bool process_record_factory_test(uint16_t keycode, keyrecord_t *record); + diff --git a/keyboards/keychron/common/keychron_common.c b/keyboards/keychron/common/keychron_common.c new file mode 100644 index 0000000000..043960454d --- /dev/null +++ b/keyboards/keychron/common/keychron_common.c @@ -0,0 +1,184 @@ +/* Copyright 2023 @ 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 . + */ + +#include QMK_KEYBOARD_H +#include "keychron_common.h" +#ifdef FACTORY_TEST_ENABLE +# include "factory_test.h" +#endif +#ifdef RETAIL_DEMO_ENABLE +# include "retail_demo.h" +#endif +#ifdef LK_WIRELESS_ENABLE +# include "lkbt51.h" +# include "wireless.h" +#endif +#ifdef LED_MATRIX_ENABLE +# include "led_matrix.h" +#endif + +bool is_siri_active = false; +uint32_t siri_timer = 0; + +static uint8_t mac_keycode[4] = { + KC_LOPT, + KC_ROPT, + KC_LCMD, + KC_RCMD, +}; + +// clang-format off +static key_combination_t key_comb_list[] = { + {2, {KC_LWIN, KC_TAB}}, + {2, {KC_LWIN, KC_E}}, + {3, {KC_LSFT, KC_LCMD, KC_4}}, + {2, {KC_LWIN, KC_C}}, +#ifdef WIN_LOCK_SCREEN_ENABLE + {2, {KC_LWIN, KC_L}}, +#endif +#ifdef MAC_LOCK_SCREEN_ENABLE + {3, {KC_LCTL, KC_LCMD, KC_Q}}, +#endif +}; +// clang-format on + +void keychron_common_init(void) { +#ifdef SNAP_CLICK_ENABLE + extern void snap_click_init(void); + snap_click_init(); +#endif +#if defined(RGB_MATRIX_ENABLE) && defined(KEYCHRON_RGB_ENABLE) + extern void eeconfig_init_custom_rgb(void); + eeconfig_init_custom_rgb(); +#endif +#ifdef LK_WIRELESS_ENABLE +# ifdef P2P4_MODE_SELECT_PIN + palSetLineMode(P2P4_MODE_SELECT_PIN, PAL_MODE_INPUT); +# endif +# ifdef BT_MODE_SELECT_PIN + palSetLineMode(BT_MODE_SELECT_PIN, PAL_MODE_INPUT); +# endif +# ifdef BAT_LOW_LED_PIN + writePin(BAT_LOW_LED_PIN, BAT_LOW_LED_PIN_ON_STATE); +# endif + + lkbt51_init(false); + wireless_init(); +#endif + +#ifdef ENCODER_ENABLE + encoder_cb_init(); +#endif +} + +bool process_record_keychron_common(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { + case KC_MCTRL: + if (record->event.pressed) { + register_code(KC_MISSION_CONTROL); + } else { + unregister_code(KC_MISSION_CONTROL); + } + return false; // Skip all further processing of this key + case KC_LNPAD: + if (record->event.pressed) { + register_code(KC_LAUNCHPAD); + } else { + unregister_code(KC_LAUNCHPAD); + } + return false; // Skip all further processing of this key + case KC_LOPTN: + case KC_ROPTN: + case KC_LCMMD: + case KC_RCMMD: + if (record->event.pressed) { + register_code(mac_keycode[keycode - KC_LOPTN]); + } else { + unregister_code(mac_keycode[keycode - KC_LOPTN]); + } + return false; // Skip all further processing of this key + case KC_SIRI: + if (record->event.pressed) { + if (!is_siri_active) { + is_siri_active = true; + register_code(KC_LCMD); + register_code(KC_SPACE); + } + siri_timer = timer_read32(); + } else { + // Do something else when release + } + return false; // Skip all further processing of this key + case KC_TASK: + case KC_FILE: + case KC_SNAP: + case KC_CTANA: +#ifdef WIN_LOCK_SCREEN_ENABLE + case KC_WLCK: +#endif +#ifdef MAC_LOCK_SCREEN_ENABLE + case KC_MLCK: +#endif + if (record->event.pressed) { + for (uint8_t i = 0; i < key_comb_list[keycode - KC_TASK].len; i++) { + register_code(key_comb_list[keycode - KC_TASK].keycode[i]); + } + } else { + for (uint8_t i = 0; i < key_comb_list[keycode - KC_TASK].len; i++) { + unregister_code(key_comb_list[keycode - KC_TASK].keycode[i]); + } + } + return false; // Skip all further processing of this key +#ifdef LED_MATRIX_ENABLE + case BL_SPI: + led_matrix_increase_speed(); + break; + case BL_SPD: + led_matrix_decrease_speed(); + break; +#endif + default: + return true; // Process all other keycodes normally + } + return true; +} + +void keychron_common_task(void) { + if (is_siri_active && timer_elapsed32(siri_timer) > 500) { + unregister_code(KC_LCMD); + unregister_code(KC_SPACE); + is_siri_active = false; + siri_timer = 0; + } +} + +#ifdef ENCODER_ENABLE +static void encoder_pad_cb(void *param) { + uint8_t index = (uint32_t)param; + encoder_inerrupt_read(index); +} + +void encoder_cb_init(void) { + pin_t encoders_pad_a[] = ENCODERS_PAD_A; + pin_t encoders_pad_b[] = ENCODERS_PAD_B; + for (uint32_t i = 0; i < NUM_ENCODERS; i++) { + palEnableLineEvent(encoders_pad_a[i], PAL_EVENT_MODE_BOTH_EDGES); + palEnableLineEvent(encoders_pad_b[i], PAL_EVENT_MODE_BOTH_EDGES); + palSetLineCallback(encoders_pad_a[i], encoder_pad_cb, (void *)i); + palSetLineCallback(encoders_pad_b[i], encoder_pad_cb, (void *)i); + } +} +#endif diff --git a/keyboards/keychron/common/keychron_common.h b/keyboards/keychron/common/keychron_common.h new file mode 100644 index 0000000000..e2a4a70480 --- /dev/null +++ b/keyboards/keychron/common/keychron_common.h @@ -0,0 +1,96 @@ +/* Copyright 2023 @ 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 . + */ + +#pragma once + +#include "stdint.h" + +// clang-format off +enum { + KC_LOPTN = QK_KB_0, + KC_ROPTN, + KC_LCMMD, + KC_RCMMD, + KC_MCTRL, + KC_LNPAD, + KC_TASK_VIEW, + KC_FILE_EXPLORER, + KC_SCREEN_SHOT, + KC_CORTANA, +#ifdef WIN_LOCK_SCREEN_ENABLE + KC_WIN_LOCK_SCREEN, + __KC_WIN_LOCK_SCREEN_NEXT, +#else + __KC_WIN_LOCK_SCREEN_NEXT = KC_CORTANA + 1, +#endif +#ifdef MAC_LOCK_SCREEN_ENABLE + KC_MAC_LOCK_SCREEN = __KC_WIN_LOCK_SCREEN_NEXT, + __KC_MAC_LOCK_SCREEN_NEXT, +#else + __KC_MAC_LOCK_SCREEN_NEXT = __KC_WIN_LOCK_SCREEN_NEXT, +#endif + KC_SIRI = __KC_MAC_LOCK_SCREEN_NEXT, +#ifdef LK_WIRELESS_ENABLE + BT_HST1, + BT_HST2, + BT_HST3, + P2P4G, + BAT_LVL, +#endif +#ifdef ANANLOG_MATRIX + PROF1, + PROF2, + PROF3, +#endif +#ifdef LED_MATRIX_ENABLE + BL_SPI, + BL_SPD, +#endif + NEW_SAFE_RANGE, +}; + +#ifndef LK_WIRELESS_ENABLE + #define BT_HST1 KC_TRANS + #define BT_HST2 KC_TRANS + #define BT_HST3 KC_TRANS + #define P2P4G KC_TRANS + #define BAT_LVL KC_TRANS +#endif +#ifndef ANANLOG_MATRIX + #define PROF1 KC_TRANS + #define PROF2 KC_TRANS + #define PROF3 KC_TRANS +#endif + +#define KC_TASK KC_TASK_VIEW +#define KC_FILE KC_FILE_EXPLORER +#define KC_SNAP KC_SCREEN_SHOT +#define KC_CTANA KC_CORTANA +#define KC_WLCK KC_WIN_LOCK_SCREEN +#define KC_MLCK KC_MAC_LOCK_SCREEN + +typedef struct PACKED { + uint8_t len; + uint8_t keycode[3]; +} key_combination_t; + +void keychron_common_init(void); +bool process_record_keychron_common(uint16_t keycode, keyrecord_t *record); +void keychron_common_task(void); + +#ifdef ENCODER_ENABLE +void encoder_cb_init(void); +#endif diff --git a/keyboards/keychron/common/keychron_common.mk b/keyboards/keychron/common/keychron_common.mk new file mode 100644 index 0000000000..3b1bf6d240 --- /dev/null +++ b/keyboards/keychron/common/keychron_common.mk @@ -0,0 +1,31 @@ +OPT_DEFS += -DFACTORY_TEST_ENABLE -DAPDAPTIVE_NKRO_ENABLE + +KEYCHRON_COMMON_DIR = common +SRC += \ + $(KEYCHRON_COMMON_DIR)/keychron_task.c \ + $(KEYCHRON_COMMON_DIR)/keychron_common.c \ + $(KEYCHRON_COMMON_DIR)/keychron_raw_hid.c \ + $(KEYCHRON_COMMON_DIR)/factory_test.c \ + $(KEYCHRON_COMMON_DIR)/eeconfig_kb.c \ + $(KEYCHRON_COMMON_DIR)/dfu_info.c + +VPATH += $(TOP_DIR)/keyboards/keychron/$(KEYCHRON_COMMON_DIR) + +INFO_RULES_MK = $(shell $(QMK_BIN) generate-rules-mk --quiet --escape --keyboard $(KEYBOARD) --output $(INTERMEDIATE_OUTPUT)/src/info_rules.mk) +include $(INFO_RULES_MK) + +include $(TOP_DIR)/keyboards/keychron/$(KEYCHRON_COMMON_DIR)/language/language.mk + +ifeq ($(strip $(DEBOUNCE_TYPE)), custom) +include $(TOP_DIR)/keyboards/keychron/$(KEYCHRON_COMMON_DIR)/debounce/debounce.mk +endif + +ifeq ($(strip $(SNAP_CLICK_ENABLE)), yes) +include $(TOP_DIR)/keyboards/keychron/$(KEYCHRON_COMMON_DIR)/snap_click/snap_click.mk +endif + +ifeq ($(strip $(KEYCHRON_RGB_ENABLE)), yes) +ifeq ($(strip $(RGB_MATRIX_ENABLE)), yes) +include $(TOP_DIR)/keyboards/keychron/$(KEYCHRON_COMMON_DIR)/rgb/rgb.mk +endif +endif diff --git a/keyboards/keychron/common/keychron_raw_hid.c b/keyboards/keychron/common/keychron_raw_hid.c new file mode 100644 index 0000000000..e21776f5c8 --- /dev/null +++ b/keyboards/keychron/common/keychron_raw_hid.c @@ -0,0 +1,203 @@ +/* Copyright 2024 @ 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 . + */ + +#include QMK_KEYBOARD_H +#include "keychron_common.h" +#include "keychron_raw_hid.h" +#include "raw_hid.h" +#include "version.h" +#include "language.h" +#ifdef FACTORY_TEST_ENABLE +# include "factory_test.h" +#endif +#ifdef LK_WIRELESS_ENABLE +# include "lkbt51.h" +#endif +#ifdef ANANLOG_MATRIX +# include "analog_matrix.h" +#endif +#ifdef DYNAMIC_DEBOUNCE_ENABLE +# include "keychron_debounce.h" +#endif +#ifdef SNAP_CLICK_ENABLE +# include "snap_click.h" +#endif +#ifdef LK_WIRELESS_ENABLE +# include "wireless.h" +#endif + +extern void dfu_info_rx(uint8_t *data, uint8_t length); + +void get_support_feature(uint8_t *data) { + data[0] = 0; + data[1] = FEATURE_DEFAULT_LAYER +#ifdef KC_BLUETOOTH_ENABLE + | FEATURE_BLUETOOTH +#endif +#ifdef LK_WIRELESS_ENABLE + | FEATURE_BLUETOOTH | FEATURE_P24G +#endif +#ifdef ANANLOG_MATRIX + | FEATURE_ANALOG_MATRIX +#endif +#ifdef INFO_CHAGNED_NOTIFY_ENABLE + | FEATURE_INFO_CHAGNED_NOTIFY +#endif +#ifdef DYNAMIC_DEBOUNCE_ENABLE + | FEATURE_DYNAMIC_DEBOUNCE +#endif +#ifdef SNAP_CLICK_ENABLE + | FEATURE_SNAP_CLICK +#endif +#ifdef KEYCHRON_RGB_ENABLE + | FEATURE_KEYCHRON_RGB +#endif + ; +} + +void get_firmware_version(uint8_t *data) { + uint8_t i = 0; + data[i++] = 'v'; + if ((DEVICE_VER & 0xF000) != 0) itoa((DEVICE_VER >> 12), (char *)&data[i++], 16); + itoa((DEVICE_VER >> 8) & 0xF, (char *)&data[i++], 16); + data[i++] = '.'; + itoa((DEVICE_VER >> 4) & 0xF, (char *)&data[i++], 16); + data[i++] = '.'; + itoa(DEVICE_VER & 0xF, (char *)&data[i++], 16); + data[i++] = ' '; + memcpy(&data[i], QMK_BUILDDATE, sizeof(QMK_BUILDDATE)); + i += sizeof(QMK_BUILDDATE); +} + + +__attribute__((weak)) void kc_rgb_matrix_rx(uint8_t *data, uint8_t length) {} + +bool kc_raw_hid_rx(uint8_t *data, uint8_t length) { + switch (data[0]) { + case KC_GET_PROTOCOL_VERSION: + data[1] = PROTOCOL_VERSION; + data[2] = 0; + data[3] = QMK_COMMAND_SET; + break; + + case KC_GET_FIRMWARE_VERSION: + get_firmware_version(&data[1]); + break; + + case KC_GET_SUPPORT_FEATURE: + get_support_feature(&data[1]); + break; + + case KC_GET_DEFAULT_LAYER: + data[1] = get_highest_layer(default_layer_state); + break; + + case 0xA7: + switch (data[1]) { + case MISC_GET_PROTOCOL_VER: + data[2] = 0; + data[3] = MISC_PROTOCOL_VERSION & 0xFF; + data[4] = (MISC_PROTOCOL_VERSION >> 8) & 0xFF; + data[5] = MISC_DFU_INFO | MISC_LANGUAGE +#ifdef DYNAMIC_DEBOUNCE_ENABLE + | MISC_DEBOUNCE +#endif +#ifdef SNAP_CLICK_ENABLE + | MISC_SNAP_CLICK +#endif +#ifdef LK_WIRELESS_ENABLE + | MISC_WIRELESS_LPM +#endif +#ifdef HSUSB_8K_ENABLE + | MISC_REPORT_REATE +#endif + ; + break; + + case DFU_INFO_GET: + dfu_info_rx(data, length); + break; + case LANGUAGE_GET ... LANGUAGE_SET: + language_rx(data, length); + break; + +#if defined(DYNAMIC_DEBOUNCE_ENABLE) + case DEBOUNCE_GET ... DEBOUNCE_SET: + debounce_rx(data, length); + break; +#endif +#if defined(SNAP_CLICK_ENABLE) + case SNAP_CLICK_GET_INFO ... SNAP_CLICK_SAVE: + snap_click_rx(data, length); + break; +#endif +#if defined(LK_WIRELESS_ENABLE) && defined(EECONFIG_BASE_WIRELESS_CONFIG) + case WIRELESS_LPM_GET ... WIRELESS_LPM_SET: + wireless_raw_hid_rx(data, length); + break; +#endif +#if defined(HSUSB_8K_ENABLE) + case REPORT_RATE_GET ... REPORT_RATE_SET: + report_rate_hid_rx(data, length); + break; +#endif + default: + data[0] = 0xFF; + data[1] = 0; + break; + } + break; + +#if defined(KEYCHRON_RGB_ENABLE) + case 0xA8: + kc_rgb_matrix_rx(data, length); + break; +#endif + +#ifdef ANANLOG_MATRIX + case 0xA9: + analog_matrix_rx(data, length); + return true; +#endif +#ifdef LK_WIRELESS_ENABLE + case 0xAA: + lkbt51_dfu_rx(data, length); + return true; + +#endif +#ifdef FACTORY_TEST_ENABLE + case 0xAB: + factory_test_rx(data, length); + return true; + +#endif + default: + return false; + } + + raw_hid_send(data, length); + return true; +} + +#if defined(VIA_ENABLE) +bool via_command_kb(uint8_t *data, uint8_t length) { + return kc_raw_hid_rx(data, length); +} +#else +void raw_hid_receive(uint8_t *data, uint8_t length) { + kc_raw_hid_rx(data, length); +} +#endif diff --git a/keyboards/keychron/common/keychron_raw_hid.h b/keyboards/keychron/common/keychron_raw_hid.h new file mode 100644 index 0000000000..4419f0f73f --- /dev/null +++ b/keyboards/keychron/common/keychron_raw_hid.h @@ -0,0 +1,65 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once + +#define PROTOCOL_VERSION 0x02 +#define MISC_PROTOCOL_VERSION 0x0002 +#define QMK_COMMAND_SET 2 + +enum { + KC_GET_PROTOCOL_VERSION = 0xA0, + KC_GET_FIRMWARE_VERSION = 0xA1, + KC_GET_SUPPORT_FEATURE = 0xA2, + KC_GET_DEFAULT_LAYER = 0xA3, +}; + +enum { + FEATURE_DEFAULT_LAYER = 0x01U << 0, + FEATURE_BLUETOOTH = 0x01U << 1, + FEATURE_P24G = 0x01U << 2, + FEATURE_ANALOG_MATRIX = 0x01U << 3, + FEATURE_INFO_CHAGNED_NOTIFY = 0x01U << 4, + FEATURE_DYNAMIC_DEBOUNCE = 0x01U << 5, + FEATURE_SNAP_CLICK = 0x01U << 6, + FEATURE_KEYCHRON_RGB = 0x01U << 7, +}; + +enum { + MISC_DFU_INFO = 0x01 << 0, + MISC_LANGUAGE = 0x01 << 1, + MISC_DEBOUNCE = 0x01 << 2, + MISC_SNAP_CLICK = 0x01 << 3, + MISC_WIRELESS_LPM = 0x01 << 4, + MISC_REPORT_REATE = 0x01 << 5, +}; + +enum { + MISC_GET_PROTOCOL_VER = 0x01, + DFU_INFO_GET, + LANGUAGE_GET, + LANGUAGE_SET, + DEBOUNCE_GET, // 5 + DEBOUNCE_SET, + SNAP_CLICK_GET_INFO, + SNAP_CLICK_GET, + SNAP_CLICK_SET, + SNAP_CLICK_SAVE, // A + WIRELESS_LPM_GET, + WIRELESS_LPM_SET, + REPORT_RATE_GET, + REPORT_RATE_SET, +}; diff --git a/keyboards/keychron/common/keychron_task.c b/keyboards/keychron/common/keychron_task.c new file mode 100644 index 0000000000..95fca0a9e5 --- /dev/null +++ b/keyboards/keychron/common/keychron_task.c @@ -0,0 +1,141 @@ +/* Copyright 2023~2025 @ 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 . + */ + +#include +#include "keychron_task.h" +#include "quantum.h" +#include "keychron_common.h" +#ifdef FACTORY_TEST_ENABLE +# include "factory_test.h" +#endif +#ifdef RETAIL_DEMO_ENABLE +# include "retail_demo.h" +#endif + +__attribute__((weak)) bool process_record_keychron_kb(uint16_t keycode, keyrecord_t *record) { + return true; +} + +bool process_record_keychron(uint16_t keycode, keyrecord_t *record) { +#ifdef LK_WIRELESS_ENABLE + extern bool process_record_wireless(uint16_t keycode, keyrecord_t * record); + if (!process_record_wireless(keycode, record)) return false; +#endif +#ifdef FACTORY_TEST_ENABLE + if (!process_record_factory_test(keycode, record)) return false; +#endif + +#ifdef SNAP_CLICK_ENABLE + extern bool process_record_snap_click(uint16_t keycode, keyrecord_t * record); + if (!process_record_snap_click(keycode, record)) return false; +#endif + + if (!process_record_keychron_kb(keycode, record)) return false; + +#if defined(KEYCHRON_RGB_ENABLE) && defined(EECONFIG_SIZE_CUSTOM_RGB) +# if defined(RETAIL_DEMO_ENABLE) + if (!process_record_retail_demo(keycode, record)) { + return false; + } +# endif + + extern bool process_record_keychron_rgb(uint16_t keycode, keyrecord_t *record); + if (!process_record_keychron_rgb(keycode, record)) { + return false; + } +#endif + + return true; +} + +#if defined(LED_MATRIX_ENABLE) +bool led_matrix_indicators_keychron(void) { +# ifdef LK_WIRELESS_ENABLE + extern bool led_matrix_indicators_bt(void); + led_matrix_indicators_bt(); +# endif +# ifdef FACTORY_TEST_ENABLE + factory_test_indicator(); +# endif + return true; +} +#endif + +#if defined(RGB_MATRIX_ENABLE) +bool rgb_matrix_indicators_keychron(void) { +# ifdef LK_WIRELESS_ENABLE + extern bool rgb_matrix_indicators_bt(void); + rgb_matrix_indicators_bt(); +# endif +# ifdef FACTORY_TEST_ENABLE + factory_test_indicator(); +# endif + return true; +} +#endif + +__attribute__((weak)) bool keychron_task_kb(void) { + return true; +} + +void keychron_task(void) { +#ifdef LK_WIRELESS_ENABLE + extern void wireless_tasks(void); + wireless_tasks(); +#endif +#ifdef FACTORY_TEST_ENABLE + factory_test_task(); +#endif +#if defined(RETAIL_DEMO_ENABLE) && defined(KEYCHRON_RGB_ENABLE) && defined(EECONFIG_SIZE_CUSTOM_RGB) + retail_demo_task(); +#endif + + keychron_common_task(); + + keychron_task_kb(); +} + +bool process_record_kb(uint16_t keycode, keyrecord_t *record) { + if (!process_record_user(keycode, record)) return false; + + if (!process_record_keychron(keycode, record)) return false; + + return true; +} + +#ifdef RGB_MATRIX_ENABLE +bool rgb_matrix_indicators_kb(void) { + if (!rgb_matrix_indicators_user()) return false; + + rgb_matrix_indicators_keychron(); + + return true; +} +#endif + +#ifdef LED_MATRIX_ENABLE +bool led_matrix_indicators_kb(void) { + if (!led_matrix_indicators_user()) return false; + + led_matrix_indicators_keychron(); + + return true; +} +#endif + +void housekeeping_task_kb(void) { + keychron_task(); +} diff --git a/keyboards/keychron/common/keychron_task.h b/keyboards/keychron/common/keychron_task.h new file mode 100644 index 0000000000..c96141a32a --- /dev/null +++ b/keyboards/keychron/common/keychron_task.h @@ -0,0 +1,25 @@ +/* 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 . + */ + +#pragma once + +#include "stdint.h" +#include "action.h" + +bool keychron_task_kb(void); +bool process_record_keychron_kb(uint16_t keycode, keyrecord_t *record); + +void keychron_task(void); diff --git a/keyboards/keychron/common/language/eeconfig_language.h b/keyboards/keychron/common/language/eeconfig_language.h new file mode 100644 index 0000000000..16aefcd147 --- /dev/null +++ b/keyboards/keychron/common/language/eeconfig_language.h @@ -0,0 +1,20 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once + +#define EECONFIG_SIZE_LANGUAGE 1 + diff --git a/keyboards/keychron/common/language/language.c b/keyboards/keychron/common/language/language.c new file mode 100644 index 0000000000..934cc31cdf --- /dev/null +++ b/keyboards/keychron/common/language/language.c @@ -0,0 +1,60 @@ +/* Copyright 2024 @ 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 . + */ + +#include +#include "eeconfig_kb.h" +#include "raw_hid.h" +#include "eeconfig.h" +#include "matrix.h" +#include "quantum.h" +#include "keychron_raw_hid.h" + +static uint8_t lang; + +static bool language_get(uint8_t *data) { + eeprom_read_block(&lang, (uint8_t *)(EECONFIG_BASE_LANGUAGE), sizeof(lang)); + data[1] = lang; + + return true; +} + +static bool language_set(uint8_t *data) { + lang = data[0]; + eeprom_update_block(&lang, (uint8_t *)(EECONFIG_BASE_LANGUAGE), sizeof(lang)); + + return true; +} + +void language_rx(uint8_t *data, uint8_t length) { + uint8_t cmd = data[1]; + bool success = true; + + switch (cmd) { + case LANGUAGE_GET: + success = language_get(&data[2]); + break; + + case LANGUAGE_SET: + success = language_set(&data[2]); + break; + + default: + data[0] = 0xFF; + break; + } + + data[2] = success ? 0 : 1; +} diff --git a/keyboards/keychron/common/language/language.h b/keyboards/keychron/common/language/language.h new file mode 100644 index 0000000000..0a320d7903 --- /dev/null +++ b/keyboards/keychron/common/language/language.h @@ -0,0 +1,21 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once + +void language_config_reset(void); +void language_rx(uint8_t *data, uint8_t length); + diff --git a/keyboards/keychron/common/language/language.mk b/keyboards/keychron/common/language/language.mk new file mode 100644 index 0000000000..6a9d01d0a1 --- /dev/null +++ b/keyboards/keychron/common/language/language.mk @@ -0,0 +1,7 @@ +LANGUAGE_DIR = common/language +SRC += \ + $(LANGUAGE_DIR)/language.c \ + +VPATH += $(TOP_DIR)/keyboards/keychron/$(LANGUAGE_DIR) + +OPT_DEFS += -DLANGUAGE_ENABLE diff --git a/keyboards/keychron/common/matrix.c b/keyboards/keychron/common/matrix.c new file mode 100644 index 0000000000..8fe7588118 --- /dev/null +++ b/keyboards/keychron/common/matrix.c @@ -0,0 +1,218 @@ +/* Copyright 2023 @ 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 . + */ + +#include "quantum.h" + +#ifndef HC595_STCP +# define HC595_STCP B0 +#endif +#ifndef HC595_SHCP +# define HC595_SHCP A1 +#endif +#ifndef HC595_DS +# define HC595_DS A7 +#endif + +#ifndef HC595_START_INDEX +# define HC595_START_INDEX 0 +#endif +#ifndef HC595_END_INDEX +# define HC595_END_INDEX 15 +#endif +#ifndef HC595_OFFSET_INDEX +# define HC595_OFFSET_INDEX 0 +#endif + +#if defined(HC595_START_INDEX) && defined(HC595_END_INDEX) +# if ((HC595_END_INDEX - HC595_START_INDEX + 1) > 16) +# define SIZE_T uint32_t +# define UNSELECT_ALL_COL 0xFFFFFFFF +# define SELECT_ALL_COL 0x00000000 +# elif ((HC595_END_INDEX - HC595_START_INDEX + 1) > 8) +# define SIZE_T uint16_t +# define UNSELECT_ALL_COL 0xFFFF +# define SELECT_ALL_COL 0x0000 +# else +# define SIZE_T uint8_t +# define UNSELECT_ALL_COL 0xFF +# define SELECT_ALL_COL 0x00 +# endif +#endif + +pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; +pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; + +static inline uint8_t readMatrixPin(pin_t pin) { + if (pin != NO_PIN) { + return readPin(pin); + } else { + return 1; + } +} + +static inline void setPinOutput_writeLow(pin_t pin) { + setPinOutput(pin); + writePinLow(pin); +} + +static inline void setPinOutput_writeHigh(pin_t pin) { + setPinOutput(pin); + writePinHigh(pin); +} + +static inline void HC595_delay(uint16_t n) { + while (n-- > 0) { + asm volatile("nop" ::: "memory"); + } +} + +static void HC595_output(SIZE_T data, bool bit_flag) { + uint8_t n = 1; + + ATOMIC_BLOCK_FORCEON { + for (uint8_t i = 0; i < (HC595_END_INDEX - HC595_START_INDEX + 1); i++) { + if (data & 0x1) { + writePinHigh(HC595_DS); + } else { + writePinLow(HC595_DS); + } + writePinHigh(HC595_SHCP); + HC595_delay(n); + writePinLow(HC595_SHCP); + HC595_delay(n); + if (bit_flag) { + break; + } else { + data = data >> 1; + } + } + writePinHigh(HC595_STCP); + HC595_delay(n); + writePinLow(HC595_STCP); + HC595_delay(n); + } +} + +static void select_col(uint8_t col) { + if (col < HC595_START_INDEX || col > HC595_END_INDEX) { + setPinOutput_writeLow(col_pins[col]); + } else { + if (col == HC595_START_INDEX) { + HC595_output(0x00, true); + if (col < HC595_OFFSET_INDEX) { + HC595_output(0x01, true); + } + } + } +} + +static void unselect_col(uint8_t col) { + if (col < HC595_START_INDEX || col > HC595_END_INDEX) { +#ifdef MATRIX_UNSELECT_DRIVE_HIGH + setPinOutput_writeHigh(col_pins[col]); +#else + setPinInputHigh(col_pins[col]); +#endif + } else { + HC595_output(0x01, true); + } +} + +static void unselect_cols(void) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + if (col < HC595_START_INDEX || col > HC595_END_INDEX) { +#ifdef MATRIX_UNSELECT_DRIVE_HIGH + setPinOutput_writeHigh(col_pins[col]); +#else + setPinInputHigh(col_pins[col]); +#endif + } else { + if (col == HC595_START_INDEX) { + HC595_output(UNSELECT_ALL_COL, false); + } + break; + } + } +} + +void select_all_cols(void) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + if (col < HC595_START_INDEX || col > HC595_END_INDEX) { + setPinOutput_writeLow(col_pins[col]); + } else { + if (col == HC595_START_INDEX) { + HC595_output(SELECT_ALL_COL, false); + } + break; + } + } +} + +static void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col, matrix_row_t row_shifter) { + // Select col + select_col(current_col); // select col + HC595_delay(200); + + // For each row... + for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { + // Check row pin state + if (readMatrixPin(row_pins[row_index]) == 0) { + // Pin LO, set col bit + current_matrix[row_index] |= row_shifter; + } else { + // Pin HI, clear col bit + current_matrix[row_index] &= ~row_shifter; + } + } + + // Unselect col + unselect_col(current_col); + HC595_delay(200); // wait for all Row signals to go HIGH +} + +void matrix_init_custom(void) { + setPinOutput(HC595_DS); + setPinOutput(HC595_STCP); + setPinOutput(HC595_SHCP); + + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + if (row_pins[x] != NO_PIN) { + setPinInputHigh(row_pins[x]); + } + } + + unselect_cols(); +} + +bool matrix_scan_custom(matrix_row_t current_matrix[]) { + matrix_row_t curr_matrix[MATRIX_ROWS] = {0}; + + // Set col, read rows + matrix_row_t row_shifter = MATRIX_ROW_SHIFTER; + for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++, row_shifter <<= 1) { + matrix_read_rows_on_col(curr_matrix, current_col, row_shifter); + } + + bool changed = memcmp(current_matrix, curr_matrix, sizeof(curr_matrix)) != 0; + if (changed) memcpy(current_matrix, curr_matrix, sizeof(curr_matrix)); + + return changed; +} + +void suspend_wakeup_init_kb(void) { + // code will run on keyboard wakeup + clear_keyboard(); +} diff --git a/keyboards/keychron/common/rgb/eeconfig_custom_rgb.h b/keyboards/keychron/common/rgb/eeconfig_custom_rgb.h new file mode 100644 index 0000000000..bc0cf34f49 --- /dev/null +++ b/keyboards/keychron/common/rgb/eeconfig_custom_rgb.h @@ -0,0 +1,39 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once + +#include "rgb_matrix_kb_config.h" + +#define OS_INDICATOR_CONFIG_SIZE 4 // sizeof(os_indicator_config_t) + +//#define OS_INDICATOR_CONFIG_OFFSET (PER_KEY_RGB_LED_COLOR_LIST_SIZE + RGB_MATRIX_LED_COUNT) +#define RETAIL_DEMO_SIZE 1 // sizeof(retail_demo_enable) + +#define PER_KEY_RGB_TYPE_SIZE 1 +#define PER_KEY_RGB_LED_COLOR_LIST_SIZE (RGB_MATRIX_LED_COUNT * 3) + +#define MIX_RGB_LAYER_FLAG_SIZE RGB_MATRIX_LED_COUNT +#define EFFECT_CONFIG_SIZE 8 // sizeof(effect_config_t) +#define EFFECT_LIST_SIZE (EFFECT_LAYERS * EFFECTS_PER_LAYER * EFFECT_CONFIG_SIZE) + +#define EECONFIG_SIZE_CUSTOM_RGB ( \ + OS_INDICATOR_CONFIG_SIZE \ + + RETAIL_DEMO_SIZE \ + + PER_KEY_RGB_TYPE_SIZE \ + + PER_KEY_RGB_LED_COLOR_LIST_SIZE \ + + MIX_RGB_LAYER_FLAG_SIZE \ + + EFFECT_LIST_SIZE) diff --git a/keyboards/keychron/common/rgb/keychron_rgb.c b/keyboards/keychron/common/rgb/keychron_rgb.c new file mode 100644 index 0000000000..83d9451d44 --- /dev/null +++ b/keyboards/keychron/common/rgb/keychron_rgb.c @@ -0,0 +1,494 @@ +/* Copyright 2024 @ 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 . + */ + +#include QMK_KEYBOARD_H +#include "raw_hid.h" +#include "keychron_common.h" +#include "keychron_rgb_type.h" +#include "eeconfig_kb.h" +#include "usb_main.h" +#include "color.h" +#ifdef LK_WIRELESS_ENABLE +#include "transport.h" +#endif +#include + +#if defined(KEYCHRON_RGB_ENABLE) && defined(EECONFIG_SIZE_CUSTOM_RGB) + +# define PER_KEY_RGB_VER 0x0001 + +# define OFFSET_OS_INDICATOR ((uint8_t *)(EECONFIG_BASE_CUSTOM_RGB)) +# define OFFSET_RETAIL_DEMO (OFFSET_OS_INDICATOR + sizeof(os_indicator_config_t)) +# define OFFSET_PER_KEY_RGB_TYPE (OFFSET_RETAIL_DEMO + sizeof(retail_demo_enable)) +# define OFFSET_PER_KEY_RGBS (OFFSET_PER_KEY_RGB_TYPE + sizeof(per_key_rgb_type)) +# define OFFSET_LAYER_FLAGS (OFFSET_PER_KEY_RGBS + sizeof(per_key_led)) +# define OFFSET_EFFECT_LIST (OFFSET_LAYER_FLAGS + sizeof(regions)) + +enum { + RGB_GET_PROTOCOL_VER = 0x01, + RGB_SAVE, + GET_INDICATORS_CONFIG, + SET_INDICATORS_CONFIG, + RGB_GET_LED_COUNT, + RGB_GET_LED_IDX, + PER_KEY_RGB_GET_TYPE, + PER_KEY_RGB_SET_TYPE, + PER_KEY_RGB_GET_COLOR, + PER_KEY_RGB_SET_COLOR, //10 + MIXED_EFFECT_RGB_GET_INFO, + MIXED_EFFECT_RGB_GET_REGIONS, + MIXED_EFFECT_RGB_SET_REGIONS, + MIXED_EFFECT_RGB_GET_EFFECT_LIST, + MIXED_EFFECT_RGB_SET_EFFECT_LIST, +}; + +extern uint8_t retail_demo_enable; +extern uint8_t per_key_rgb_type; +extern HSV per_key_led[RGB_MATRIX_LED_COUNT]; +extern HSV default_per_key_led[RGB_MATRIX_LED_COUNT]; + +extern uint8_t regions[RGB_MATRIX_LED_COUNT]; +extern uint8_t rgb_regions[RGB_MATRIX_LED_COUNT]; +extern effect_config_t effect_list[EFFECT_LAYERS][EFFECTS_PER_LAYER]; +extern uint8_t default_region[RGB_MATRIX_LED_COUNT]; + +os_indicator_config_t os_ind_cfg; + +extern void update_mixed_rgb_effect_count(void); + +void eeconfig_reset_custom_rgb(void) { + os_ind_cfg.disable.raw = 0; + os_ind_cfg.hsv.s = 0; + os_ind_cfg.hsv.h = os_ind_cfg.hsv.v = 0xFF; + + eeprom_update_block(&os_ind_cfg, OFFSET_OS_INDICATOR, sizeof(os_ind_cfg)); + retail_demo_enable = 0; + eeprom_read_block(&retail_demo_enable, (uint8_t *)(OFFSET_RETAIL_DEMO), sizeof(retail_demo_enable)); + per_key_rgb_type = 0; + eeprom_update_block(&per_key_rgb_type, OFFSET_PER_KEY_RGB_TYPE, sizeof(per_key_rgb_type)); + + memcpy(per_key_led, default_per_key_led, sizeof(per_key_led)); + eeprom_update_block(per_key_led, OFFSET_PER_KEY_RGBS, sizeof(per_key_led)); + + memcpy(regions, default_region, RGB_MATRIX_LED_COUNT); + eeprom_update_block(regions, OFFSET_LAYER_FLAGS, sizeof(regions)); + + memset(effect_list, 0, sizeof(effect_list)); + + effect_list[0][0].effect = 5; + effect_list[0][0].sat = 255; + effect_list[0][0].speed = 127; + effect_list[0][0].time = 5000; + + effect_list[1][0].effect = 2; + effect_list[1][0].hue = 0; + effect_list[1][0].sat = 255; + effect_list[1][0].speed = 127; + effect_list[1][0].time = 5000; + + eeprom_update_block(effect_list, OFFSET_EFFECT_LIST, sizeof(effect_list)); + update_mixed_rgb_effect_count(); +} + +void eeconfig_init_custom_rgb(void) { + memcpy(per_key_led, default_per_key_led, sizeof(per_key_led)); + eeprom_update_dword(EECONFIG_KEYBOARD, (EECONFIG_KB_DATA_VERSION)); + + eeprom_read_block(&os_ind_cfg, OFFSET_OS_INDICATOR, sizeof(os_ind_cfg)); + eeprom_read_block(&retail_demo_enable, (uint8_t *)(OFFSET_RETAIL_DEMO), sizeof(retail_demo_enable)); + + if (os_ind_cfg.hsv.v < 128) os_ind_cfg.hsv.v = 128; + // Load per key rgb led + eeprom_read_block(&per_key_rgb_type, OFFSET_PER_KEY_RGB_TYPE, sizeof(per_key_rgb_type)); + eeprom_read_block(per_key_led, OFFSET_PER_KEY_RGBS, sizeof(per_key_led)); + // Load mixed rgb + eeprom_read_block(regions, OFFSET_LAYER_FLAGS, sizeof(regions)); + eeprom_read_block(effect_list, OFFSET_EFFECT_LIST, sizeof(effect_list)); + update_mixed_rgb_effect_count(); + +} + +void rgb_save_retail_demo(void) { + eeprom_update_block(&retail_demo_enable, (uint8_t *)(OFFSET_RETAIL_DEMO), sizeof(retail_demo_enable)); +} + +static bool rgb_get_version(uint8_t *data) { + data[1] = PER_KEY_RGB_VER & 0xFF; + data[2] = (PER_KEY_RGB_VER >> 8) & 0xFF; + + return true; +} + +static bool rgb_get_led_count(uint8_t *data) { + data[1] = RGB_MATRIX_LED_COUNT; + + return true; +} + +static bool rgb_get_led_idx(uint8_t *data) { + uint8_t row = data[0]; + if (row > MATRIX_ROWS) return false; + + uint8_t led_idx[128]; + uint32_t row_mask = 0; + memcpy(&row_mask, &data[1], 3); + + for (uint8_t c = 0; c < MATRIX_COLS; c++) { + led_idx[0] = 0xFF; + if (row_mask & (0x01 << c)) { + rgb_matrix_map_row_column_to_led(row, c, led_idx); + } + data[1 + c] = led_idx[0]; + } + + return true; +} + +static bool per_key_rgb_get_type(uint8_t *data) { + extern uint8_t per_key_rgb_type; + data[1] = per_key_rgb_type; + + return true; +} + +static bool per_key_rgb_set_type(uint8_t *data) { + uint8_t type = data[0]; + + if (type >= PER_KEY_RGB_MAX) return false; + + per_key_rgb_type = data[0]; + + return true; +} + +static bool per_key_rgb_get_led_color(uint8_t *data) { + uint8_t start = data[0]; + uint8_t count = data[1]; + + if (count > 9) return false; + + for (uint8_t i = 0; i < count; i++) { + data[1 + i * 3] = per_key_led[start + i].h; + data[2 + i * 3] = per_key_led[start + i].s; + data[3 + i * 3] = per_key_led[start + i].v; + } + + return true; +} + +static bool per_key_rgb_set_led_color(uint8_t *data) { + uint8_t start = data[0]; + uint8_t count = data[1]; + + if (count > 9) return false; + + for (uint8_t i = 0; i < count; i++) { + per_key_led[start + i].h = data[2 + i * 3]; + per_key_led[start + i].s = data[3 + i * 3]; + per_key_led[start + i].v = data[4 + i * 3]; + } + + return true; +} + +static bool mixed_rgb_get_effect_info(uint8_t *data) { + data[1] = EFFECT_LAYERS; + data[2] = EFFECTS_PER_LAYER; + + return true; +} + +static bool mixed_rgb_get_regions(uint8_t *data) { + uint8_t start = data[0]; + uint8_t count = data[1]; + + if (count > 29 || start + count > RGB_MATRIX_LED_COUNT) return false; + memcpy(&data[1], ®ions[start], count); + + return true; +} + +bool mixed_rgb_set_regions(uint8_t *data) { + uint8_t start = data[0]; + uint8_t count = data[1]; + + if (count > 28 || start + count > RGB_MATRIX_LED_COUNT) return false; + for (uint8_t i = 0; i < count; i++) + if (data[2 + i] >= EFFECT_LAYERS) return false; + + memcpy(®ions[start], &data[2], count); + memcpy(&rgb_regions[start], &data[2], count); + + return true; +} +#define EFFECT_DATA_LEN 8 + +static bool mixed_rgb_get_effect_list(uint8_t *data) { + uint8_t region = data[0]; + uint8_t start = data[1]; + uint8_t count = data[2]; + + if (count > 3 || region > EFFECT_LAYERS || start + count > EFFECTS_PER_LAYER) return false; + + for (uint8_t i = 0; i < count; i++) { + data[1 + i * EFFECT_DATA_LEN] = effect_list[region][start + i].effect; + data[2 + i * EFFECT_DATA_LEN] = effect_list[region][start + i].hue; + data[3 + i * EFFECT_DATA_LEN] = effect_list[region][start + i].sat; + data[4 + i * EFFECT_DATA_LEN] = effect_list[region][start + i].speed; + memcpy(&data[5 + i * EFFECT_DATA_LEN], &effect_list[region][start + i].time, 4); + } + + return true; +} + +bool mixed_rgb_set_effect_list(uint8_t *data) { + uint8_t region = data[0]; + uint8_t start = data[1]; + uint8_t count = data[2]; + + if (count > 3 || region > EFFECT_LAYERS || start + count > EFFECTS_PER_LAYER) return false; + for (uint8_t i = 0; i < count; i++) { + if (data[3 + i * EFFECT_DATA_LEN] >= RGB_MATRIX_CUSTOM_MIXED_RGB) return false; + } + + for (uint8_t i = 0; i < count; i++) { + effect_list[region][start + i].effect = data[3 + i * EFFECT_DATA_LEN]; + effect_list[region][start + i].hue = data[4 + i * EFFECT_DATA_LEN]; + effect_list[region][start + i].sat = data[5 + i * EFFECT_DATA_LEN]; + effect_list[region][start + i].speed = data[6 + i * EFFECT_DATA_LEN]; + memcpy(&effect_list[region][start + i].time, &data[7 + i * EFFECT_DATA_LEN], 4); + } + update_mixed_rgb_effect_count(); + + return true; +} + +static bool kc_rgb_save(void) { + eeprom_update_block(&os_ind_cfg, OFFSET_OS_INDICATOR, sizeof(os_ind_cfg)); + eeprom_update_block(&per_key_rgb_type, OFFSET_PER_KEY_RGB_TYPE, sizeof(per_key_rgb_type)); + eeprom_update_block(per_key_led, OFFSET_PER_KEY_RGBS, RGB_MATRIX_LED_COUNT * sizeof(rgb_led_t)); + eeprom_update_block(regions, OFFSET_LAYER_FLAGS, RGB_MATRIX_LED_COUNT); + eeprom_update_block(effect_list, OFFSET_EFFECT_LIST, sizeof(effect_list)); + + return true; +} + +static bool get_indicators_config(uint8_t *data) { + data[1] = 0 +#if defined(NUM_LOCK_INDEX) && !defined(DIM_NUM_LOCK) + | (1 << 0x00) +#endif +#if defined(CAPS_LOCK_INDEX) && !defined(DIM_CAPS_LOCK) + | (1 << 0x01) +#endif +#if defined(SCROLL_LOCK_INDEX) + | (1 << 0x02) +#endif +#if defined(COMPOSE_LOCK_INDEX) + | (1 << 0x03) +#endif +#if defined(KANA_LOCK_INDEX) + | (1 << 0x04) +#endif +; + data[2] = os_ind_cfg.disable.raw; + data[3] = os_ind_cfg.hsv.h; + data[4] = os_ind_cfg.hsv.s; + data[5] = os_ind_cfg.hsv.v; + + return true; +} + +static bool set_indicators_config(uint8_t *data) { + os_ind_cfg.disable.raw = data[0]; + os_ind_cfg.hsv.h = data[1]; + os_ind_cfg.hsv.s = data[2]; + os_ind_cfg.hsv.v = data[3]; + + if (os_ind_cfg.hsv.v < 128) os_ind_cfg.hsv.v = 128; + led_update_kb(host_keyboard_led_state()); + + return true; +} + +void kc_rgb_matrix_rx(uint8_t *data, uint8_t length) { + uint8_t cmd = data[1]; + bool success = true; + + switch (cmd) { + case RGB_GET_PROTOCOL_VER: + success = rgb_get_version(&data[2]); + break; + + case RGB_SAVE: + success = kc_rgb_save(); + break; + + case GET_INDICATORS_CONFIG: + success = get_indicators_config(&data[2]); + break; + + case SET_INDICATORS_CONFIG: + success = set_indicators_config(&data[2]); + break; + + case RGB_GET_LED_COUNT: + success = rgb_get_led_count(&data[2]); + break; + + case RGB_GET_LED_IDX: + success = rgb_get_led_idx(&data[2]); + break; + + case PER_KEY_RGB_GET_TYPE: + success = per_key_rgb_get_type(&data[2]); + break; + + case PER_KEY_RGB_SET_TYPE: + success = per_key_rgb_set_type(&data[2]); + break; + + case PER_KEY_RGB_GET_COLOR: + success = per_key_rgb_get_led_color(&data[2]); + break; + + case PER_KEY_RGB_SET_COLOR: + success = per_key_rgb_set_led_color(&data[2]); + break; + + case MIXED_EFFECT_RGB_GET_INFO: + success = mixed_rgb_get_effect_info(&data[2]); + break; + + case MIXED_EFFECT_RGB_GET_REGIONS: + success = mixed_rgb_get_regions(&data[2]); + break; + + case MIXED_EFFECT_RGB_SET_REGIONS: + success = mixed_rgb_set_regions(&data[2]); + break; + + case MIXED_EFFECT_RGB_GET_EFFECT_LIST: + success = mixed_rgb_get_effect_list(&data[2]); + break; + + case MIXED_EFFECT_RGB_SET_EFFECT_LIST: + success = mixed_rgb_set_effect_list(&data[2]); + break; + + default: + data[0] = 0xFF; + break; + } + + data[2] = success ? 0 : 1; +} + +void os_state_indicate(void) { +# if defined(RGB_DISABLE_WHEN_USB_SUSPENDED) || defined(LED_DISABLE_WHEN_USB_SUSPENDED) + if (get_transport() == TRANSPORT_USB && USB_DRIVER.state == USB_SUSPENDED) return; +# endif + + RGB rgb = hsv_to_rgb(os_ind_cfg.hsv); + +# if defined(NUM_LOCK_INDEX) + if (host_keyboard_led_state().num_lock && !os_ind_cfg.disable.num_lock) { + rgb_matrix_set_color(NUM_LOCK_INDEX, rgb.r, rgb.g, rgb.b); + } +# endif +# if defined(CAPS_LOCK_INDEX) + if (host_keyboard_led_state().caps_lock && !os_ind_cfg.disable.caps_lock) { + rgb_matrix_set_color(CAPS_LOCK_INDEX, rgb.r, rgb.g, rgb.b); + } +# endif +# if defined(SCROLL_LOCK_INDEX) + if (host_keyboard_led_state().compose && !os_ind_cfg.disable.scroll_lock) { + rgb_matrix_set_color(SCROLL_LOCK_INDEX, rgb.r, rgb.g, rgb.b); + } +# endif +# if defined(COMPOSE_LOCK_INDEX) + if (host_keyboard_led_state().compose && !os_ind_cfg.disable.compose) { + rgb_matrix_set_color(COMPOSE_LOCK_INDEX, rgb.r, rgb.g, rgb.b); + } +# endif +# if defined(KANA_LOCK_INDEX) + if (host_keyboard_led_state().kana && !os_ind_cfg.disable.kana) { + rgb_matrix_set_color(KANA_LOCK_INDEX, rgb.r, rgb.g, rgb.b); + } +# endif + (void)rgb; +} + +bool process_record_keychron_rgb(uint16_t keycode, keyrecord_t *record) { + if (rgb_matrix_get_mode() == RGB_MATRIX_CUSTOM_MIXED_RGB || rgb_matrix_get_mode() == RGB_MATRIX_CUSTOM_PER_KEY_RGB) { + switch (keycode) { + case RGB_HUI ... RGB_SAD: + return false; + + case RGB_SPI: + if (rgb_matrix_get_mode() == RGB_MATRIX_CUSTOM_MIXED_RGB) { + return false; + } else { + rgb_matrix_config.speed = qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP); + eeprom_write_byte((uint8_t *)EECONFIG_RGB_MATRIX + offsetof(rgb_config_t, speed), rgb_matrix_config.speed); + } + break; + case RGB_SPD: + if (rgb_matrix_get_mode() == RGB_MATRIX_CUSTOM_MIXED_RGB) { + return false; + } else { + rgb_matrix_config.speed = qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP); + eeprom_write_byte((uint8_t *)EECONFIG_RGB_MATRIX + offsetof(rgb_config_t, speed), rgb_matrix_config.speed); + } + break; + + case RGB_VAI: +# ifdef RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL + if (!rgb_matrix_config.enable) { + rgb_matrix_toggle(); + return false; + } +# endif + rgb_matrix_config.hsv.v = qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP); +# ifdef RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL + while (rgb_matrix_config.hsv.v <= RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL) + rgb_matrix_config.hsv.v = qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP); +# endif + eeprom_write_byte((uint8_t *)EECONFIG_RGB_MATRIX + offsetof(rgb_config_t, hsv.v), rgb_matrix_config.hsv.v); + return false; + + case RGB_VAD: +# ifdef RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL + if (rgb_matrix_config.enable && rgb_matrix_config.hsv.v > RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL) +# endif + { + rgb_matrix_config.hsv.v = qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP); + eeprom_write_byte((uint8_t *)EECONFIG_RGB_MATRIX + offsetof(rgb_config_t, hsv.v), rgb_matrix_config.hsv.v); + } +# ifdef RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL + if (rgb_matrix_config.enable && rgb_matrix_config.hsv.v <= RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL) { + rgb_matrix_toggle(); + } +# endif + return false; + + default: + break; + } + } + return true; +} +#endif diff --git a/keyboards/keychron/common/rgb/keychron_rgb_type.h b/keyboards/keychron/common/rgb/keychron_rgb_type.h new file mode 100644 index 0000000000..f9e17d548c --- /dev/null +++ b/keyboards/keychron/common/rgb/keychron_rgb_type.h @@ -0,0 +1,59 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once +#include "color.h" + +enum { + PER_KEY_RGB_SOLID, + PER_KEY_RGB_BREATHING, + PER_KEY_RGB_REATIVE_SIMPLE, + PER_KEY_RGB_REATIVE_MULTI_WIDE, + PER_KEY_RGB_REATIVE_SPLASH, + PER_KEY_RGB_MAX, +}; + +typedef struct PACKED { + uint8_t effect; + uint8_t hue; + uint8_t sat; + uint8_t speed; + uint32_t time; +} effect_config_t; + +typedef union { + uint8_t raw; + struct { + bool num_lock : 1; + bool caps_lock : 1; + bool scroll_lock : 1; + bool compose : 1; + bool kana : 1; + uint8_t reserved : 3; + }; +} os_led_t; + +// TODO: +// typedef struct PACKED HSV2 { +// uint8_t h; +// uint8_t s; +// uint8_t v; +// } HSV2; + +typedef struct PACKED { + os_led_t disable; + HSV hsv; +} os_indicator_config_t; diff --git a/keyboards/keychron/common/rgb/mixed_rgb.c b/keyboards/keychron/common/rgb/mixed_rgb.c new file mode 100644 index 0000000000..16fcafa0ac --- /dev/null +++ b/keyboards/keychron/common/rgb/mixed_rgb.c @@ -0,0 +1,191 @@ +/* Copyright 2024 @ 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 . + */ + +#if defined(KEYCHRON_RGB_ENABLE) && defined(EECONFIG_SIZE_CUSTOM_RGB) + +#include "quantum.h" +#include "rgb_matrix.h" +#include "keychron_rgb_type.h" + +#define RGB_MATRIX_EFFECT(name, ...) \ + extern bool name(effect_params_t *params); +#include "rgb_matrix_effects.inc" +#include "rgb_matrix_kb.inc" +#undef RGB_MATRIX_EFFECT + +// PER_KEY_RGB data +extern uint8_t per_key_rgb_type; + +// MIXED_RGB data +extern uint8_t rgb_regions[RGB_MATRIX_LED_COUNT]; +uint8_t regions[RGB_MATRIX_LED_COUNT] = {0}; // +effect_config_t effect_list[EFFECT_LAYERS][EFFECTS_PER_LAYER]; + +uint8_t layer_effect_count[EFFECT_LAYERS] = {0}; +uint8_t layer_effect_index[EFFECT_LAYERS] = {0}; +uint32_t layer_effect_timer[EFFECT_LAYERS] = {0}; + +// Typing heatmap +uint8_t typingHeatmap = 0; + +static bool multiple_rgb_effect_runner(effect_params_t *params); + +void mixed_rgb_reset(void) { + typingHeatmap = 0; + for (uint8_t i=0; iinit) { + memcpy(rgb_regions, regions, RGB_MATRIX_LED_COUNT); + memset(layer_effect_index, 0, sizeof(layer_effect_index)); + + mixed_rgb_reset(); + } + + for (int8_t i=EFFECT_LAYERS-1; i>=0; i--) { + params->region = i; + ret = multiple_rgb_effect_runner(params); + } + + return ret; +} + +#define TRANSITION_TIME 1000 + +bool multiple_rgb_effect_runner(effect_params_t *params) { + HSV hsv= rgb_matrix_get_hsv(); + uint8_t backup_value = hsv.v; + + bool transation = false; + bool rendering = false; + uint8_t layer = params->region; + + uint8_t effect_index = layer_effect_index[layer]; + + if (effect_list[layer][effect_index].effect == RGB_MATRIX_TYPING_HEATMAP) + typingHeatmap |= 0x01 << layer; + else + typingHeatmap &= ~(0x01 << layer); + + uint8_t last_effect = effect_list[layer][layer_effect_index[layer]].effect; + + if (layer_effect_count[layer] > 1) { + if (timer_elapsed32(layer_effect_timer[layer]) > effect_list[layer][effect_index].time) { + layer_effect_timer[layer] = timer_read32(); + if (++layer_effect_index[layer] >= EFFECTS_PER_LAYER) layer_effect_index[layer] = 0; + + effect_index = layer_effect_index[layer]; + + if (effect_list[layer][effect_index].time == 0) return true; // + } + else if (timer_elapsed32(layer_effect_timer[layer]) > effect_list[layer][effect_index].time - TRANSITION_TIME) + { + hsv.v = backup_value*(effect_list[layer][effect_index].time - timer_elapsed32(layer_effect_timer[layer]))/TRANSITION_TIME; + transation = true; + } + + if (timer_elapsed32(layer_effect_timer[layer]) < TRANSITION_TIME) + { + hsv.v = backup_value*timer_elapsed32(layer_effect_timer[layer])/TRANSITION_TIME; + transation = true; + } + } else if (layer_effect_count[layer] == 1 && effect_list[layer][effect_index].effect == 0) { + for (uint8_t i=0; iregion] = i; + break; + } + } + } + + uint8_t effect = effect_list[layer][effect_index].effect; + if (effect == 0) ++layer_effect_index[layer]; // Skip effect 0 + if (layer_effect_index[layer] >= EFFECTS_PER_LAYER) layer_effect_index[layer] = 0; + + effect = effect_list[layer][effect_index].effect; + hsv.h = effect_list[layer][effect_index].hue; + hsv.s = effect_list[layer][effect_index].sat; + rgb_matrix_sethsv_noeeprom(hsv.h, hsv.s, hsv.v); + + rgb_matrix_set_speed_noeeprom(effect_list[layer][effect_index].speed); + + params->init = last_effect != effect; + + // each effect can opt to do calculations + // and/or request PWM buffer updates. + switch (effect) { + // --------------------------------------------- + // -----Begin rgb effect switch case macros----- +#define RGB_MATRIX_EFFECT(name, ...) \ + case RGB_MATRIX_##name: \ + rendering = name(params); \ + break; +#include "rgb_matrix_effects.inc" +#undef RGB_MATRIX_EFFECT + +#if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER) +# define RGB_MATRIX_EFFECT(name, ...) \ + case RGB_MATRIX_CUSTOM_##name: \ + rendering = name(params); \ + break; +# ifdef RGB_MATRIX_CUSTOM_KB +# include "rgb_matrix_kb.inc" +# endif +# undef RGB_MATRIX_EFFECT +#endif + // -----End rgb effect switch case macros------- + // --------------------------------------------- + } + + if (transation) { + rgb_matrix_sethsv_noeeprom(hsv.h, hsv.s, backup_value); + } + + return rendering; + +} + +void process_rgb_matrix_kb(uint8_t row, uint8_t col, bool pressed) { + if (pressed) + { + if (rgb_matrix_config.mode == RGB_MATRIX_CUSTOM_MIXED_RGB) { + extern void process_rgb_matrix_typing_heatmap(uint8_t row, uint8_t col); + if (typingHeatmap) process_rgb_matrix_typing_heatmap(row, col); + } + } +} +#endif diff --git a/keyboards/keychron/common/rgb/per_key_rgb.c b/keyboards/keychron/common/rgb/per_key_rgb.c new file mode 100644 index 0000000000..8cf18af824 --- /dev/null +++ b/keyboards/keychron/common/rgb/per_key_rgb.c @@ -0,0 +1,160 @@ +/* Copyright 2024 @ 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 . + */ + +#include "quantum.h" +#include "rgb_matrix.h" +#include "keychron_rgb_type.h" +#include +#include + +#if defined(KEYCHRON_RGB_ENABLE) + +// PER_KEY_RGB data +uint8_t per_key_rgb_type; +HSV per_key_led[RGB_MATRIX_LED_COUNT] = {0}; + +bool per_key_rgb_solid(effect_params_t *params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + HSV hsv; + + for (uint8_t i = led_min; i < led_max; i++) { + hsv = per_key_led[i]; + hsv.v = rgb_matrix_config.hsv.v; + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b); + } + return rgb_matrix_check_finished_leds(led_max); +} + +bool per_key_rgb_breahting(effect_params_t *params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + HSV hsv; + uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 8); + + for (uint8_t i = led_min; i < led_max; i++) { + hsv = per_key_led[i]; + hsv.v = scale8(abs8(sin8(time) - 128) * 2, rgb_matrix_config.hsv.v); + RGB rgb = hsv_to_rgb(hsv); + RGB_MATRIX_TEST_LED_FLAGS(); + rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b); + } + + return rgb_matrix_check_finished_leds(led_max); +} + +bool per_key_rgb_reactive_simple(effect_params_t *params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + uint16_t max_tick = 65535 / qadd8(rgb_matrix_config.speed, 1); + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + uint16_t tick = max_tick; + // Reverse search to find most recent key hit + for (int8_t j = g_last_hit_tracker.count - 1; j >= 0; j--) { + if (g_last_hit_tracker.index[j] == i && g_last_hit_tracker.tick[j] < tick) { + tick = g_last_hit_tracker.tick[j]; + break; + } + } + + uint16_t offset = scale16by8(tick, qadd8(rgb_matrix_config.speed, 1)); + HSV hsv = per_key_led[i]; + + hsv.v = scale8(255 - offset, rgb_matrix_config.hsv.v); + if (per_key_led[i].v < hsv.v) + hsv.v = per_key_led[i].v; + + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b); + } + return rgb_matrix_check_finished_leds(led_max); + +} + +typedef HSV (*reactive_splash_f)(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick); + +bool per_key_rgb_effect_runner_reactive_splash(uint8_t start, effect_params_t* params, reactive_splash_f effect_func) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + uint8_t count = g_last_hit_tracker.count; + for (uint8_t i = led_min; i < led_max; i++) { + RGB_MATRIX_TEST_LED_FLAGS(); + HSV hsv = rgb_matrix_config.hsv; + hsv.v = 0; + for (uint8_t j = start; j < count; j++) { + int16_t dx = g_led_config.point[i].x - g_last_hit_tracker.x[j]; + int16_t dy = g_led_config.point[i].y - g_last_hit_tracker.y[j]; + uint8_t dist = sqrt16(dx * dx + dy * dy); + uint16_t tick = scale16by8(g_last_hit_tracker.tick[j], qadd8(rgb_matrix_config.speed, 1)); + hsv = effect_func(hsv, dx, dy, dist, tick); + } + hsv.h = per_key_led[i].h; + hsv.s = per_key_led[i].s; + hsv.v = scale8(hsv.v, rgb_matrix_config.hsv.v); + if (per_key_led[i].v < hsv.v) + hsv.v = per_key_led[i].v; + RGB rgb = hsv_to_rgb(hsv); + rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b); + } + return rgb_matrix_check_finished_leds(led_max); +} + +static HSV solid_reactive_wide_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { + uint16_t effect = tick + dist * 5; + if (effect > 255) effect = 255; +# ifdef RGB_MATRIX_SOLID_REACTIVE_GRADIENT_MODE + hsv.h = scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 8) >> 4); +# endif + hsv.v = qadd8(hsv.v, 255 - effect); + return hsv; +} + +bool per_key_rgb_reactive_multi_wide(effect_params_t *params) { + return per_key_rgb_effect_runner_reactive_splash(0, params, &solid_reactive_wide_math); +} + +static HSV SPLASH_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) { + uint16_t effect = tick - dist; + if (effect > 255) effect = 255; + hsv.h += effect; + hsv.v = qadd8(hsv.v, 255 - effect); + return hsv; +} + +bool per_key_rgb_reactive_splash(effect_params_t *params) { + return per_key_rgb_effect_runner_reactive_splash(qsub8(g_last_hit_tracker.count, 1), params, &SPLASH_math); +} + +bool per_key_rgb(effect_params_t *params) { + switch (per_key_rgb_type) { + case PER_KEY_RGB_BREATHING: + return per_key_rgb_breahting(params); + + case PER_KEY_RGB_REATIVE_SIMPLE: + return per_key_rgb_reactive_simple(params); + + case PER_KEY_RGB_REATIVE_MULTI_WIDE: + return per_key_rgb_reactive_multi_wide(params); + + case PER_KEY_RGB_REATIVE_SPLASH: + return per_key_rgb_reactive_splash(params); + + default: + return per_key_rgb_solid(params); + } +} + +#endif diff --git a/keyboards/keychron/common/rgb/retail_demo.c b/keyboards/keychron/common/rgb/retail_demo.c new file mode 100644 index 0000000000..03f5360706 --- /dev/null +++ b/keyboards/keychron/common/rgb/retail_demo.c @@ -0,0 +1,185 @@ +/* Copyright 2024 @ 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 . + */ + +#include +#include "eeconfig_kb.h" +#include "retail_demo.h" +#include "eeconfig.h" +#include "matrix.h" +#include "quantum.h" +#ifdef LK_WIRELESS_ENABLE +# include "transport.h" +#endif + +#if defined(RETAIL_DEMO_ENABLE) && defined(KEYCHRON_RGB_ENABLE) && defined(EECONFIG_SIZE_CUSTOM_RGB) + +# ifndef RETAIL_DEMO_KEY_1 +# ifdef RGB_MATRIX_ENABLE +# define RETAIL_DEMO_KEY_1 RGB_HUI +# else +# define RETAIL_DEMO_KEY_1 KC_D +# endif +# endif + +# ifndef RETAIL_DEMO_KEY_2 +# ifdef RGB_MATRIX_ENABLE +# define RETAIL_DEMO_KEY_2 RGB_HUD +# else +# define RETAIL_DEMO_KEY_2 KC_E +# endif +# endif + +# ifndef EFFECT_DURATION +# define EFFECT_DURATION 10000 +# endif + +enum { + KEY_PRESS_FN = 0x01 << 0, + KEY_PRESS_D = 0x01 << 1, + KEY_PRESS_E = 0x01 << 2, + KEY_PRESS_RETAIL_DEMO = KEY_PRESS_FN | KEY_PRESS_D | KEY_PRESS_E, +}; + +uint8_t retail_demo_enable = 0; +static uint8_t retail_demo_combo = 0; +static uint32_t retail_demo_timer = 0; + +extern void rgb_save_retail_demo(void); + +bool process_record_retail_demo(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { + case MO(0)... MO(15): + if (record->event.pressed) + retail_demo_combo |= KEY_PRESS_FN; + else + retail_demo_combo &= ~KEY_PRESS_FN; + break; + + case RETAIL_DEMO_KEY_1: + if (record->event.pressed) { + retail_demo_combo |= KEY_PRESS_D; + if (retail_demo_combo == KEY_PRESS_RETAIL_DEMO) retail_demo_timer = timer_read32(); + } else { + retail_demo_combo &= ~KEY_PRESS_D; + retail_demo_timer = 0; + } + break; + + case RETAIL_DEMO_KEY_2: + if (record->event.pressed) { + retail_demo_combo |= KEY_PRESS_E; + if (retail_demo_combo == KEY_PRESS_RETAIL_DEMO) retail_demo_timer = timer_read32(); + } else { + retail_demo_combo &= ~KEY_PRESS_E; + retail_demo_timer = 0; + } + break; + } + + if (retail_demo_enable && keycode >= RGB_TOG && keycode <= RGB_SPD) return false; + + return true; +} + +void retail_demo_start(void) { + extern bool mixed_rgb_set_regions(uint8_t * data); + extern bool mixed_rgb_set_effect_list(uint8_t * data); + + uint8_t index = 0; + uint8_t this_count = 28; + uint8_t data[31] = {0}; + + // Set all LED to region 0 + while (index < RGB_MATRIX_LED_COUNT - 1) { + memset(data, 0, 31); + + if ((index + this_count) >= RGB_MATRIX_LED_COUNT) + this_count = RGB_MATRIX_LED_COUNT - 1 - index; + else + this_count = 28; + + data[0] = index; + data[1] = this_count; + mixed_rgb_set_regions(data); + + index += this_count; + } + + uint8_t effect_list[5] = {4, 7, 8, 11, 14}; + // Set effect list + for (uint8_t i = 0; i < 5; i++) { + data[0] = 0; // regsion + data[1] = i; // start + data[2] = 1; // count + data[3] = effect_list[i]; // effect + data[4] = 0; // hue + data[5] = 255; // sat + data[6] = 127; // speed; + data[7] = EFFECT_DURATION & 0xFF; + data[8] = (EFFECT_DURATION >> 8) & 0xFF; + data[9] = (EFFECT_DURATION >> 16) & 0xFF; + data[10] = (EFFECT_DURATION >> 24) & 0xFF; + + mixed_rgb_set_effect_list(data); + } + + HSV hsv = rgb_matrix_get_hsv(); + hsv.v = hsv.s = UINT8_MAX; + rgb_matrix_sethsv_noeeprom(hsv.h, hsv.s, hsv.v); + rgb_matrix_set_speed_noeeprom(RGB_MATRIX_DEFAULT_SPD); + rgb_matrix_mode_noeeprom(RGB_MATRIX_CUSTOM_MIXED_RGB); +} + +void retail_demo_stop(void) { + retail_demo_enable = false; + rgb_save_retail_demo(); + eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); +} + +static inline void retail_demo_timer_check(void) { + if (timer_elapsed32(retail_demo_timer) > 5000) { + retail_demo_timer = 0; + + if (retail_demo_combo == KEY_PRESS_RETAIL_DEMO) { + retail_demo_combo = 0; + retail_demo_enable = !retail_demo_enable; + + if (retail_demo_enable) { +# ifdef LK_WIRELESS_ENABLE + // Retail demo is allowed only in wireless mode + if (get_transport() != TRANSPORT_USB) { + retail_demo_enable = false; + return; + } +# endif + } else { + eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); + } + rgb_save_retail_demo(); + + if (!retail_demo_enable) { + extern void eeconfig_init_custom_rgb(void); + eeconfig_init_custom_rgb(); + } + } + } +} + +void retail_demo_task(void) { + if (retail_demo_timer) retail_demo_timer_check(); + if (retail_demo_enable && rgb_matrix_get_mode() != RGB_MATRIX_CUSTOM_MIXED_RGB) retail_demo_start(); +} +#endif diff --git a/keyboards/keychron/common/rgb/retail_demo.h b/keyboards/keychron/common/rgb/retail_demo.h new file mode 100644 index 0000000000..2870a91b60 --- /dev/null +++ b/keyboards/keychron/common/rgb/retail_demo.h @@ -0,0 +1,25 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once +#include "stdint.h" +#include "action.h" + +void retail_demo_start(void); +void retail_demo_stop(void); + +bool process_record_retail_demo(uint16_t keycode, keyrecord_t * record); +void retail_demo_task(void); diff --git a/keyboards/keychron/common/rgb/rgb.mk b/keyboards/keychron/common/rgb/rgb.mk new file mode 100644 index 0000000000..93e0b7ad21 --- /dev/null +++ b/keyboards/keychron/common/rgb/rgb.mk @@ -0,0 +1,14 @@ +OPT_DEFS += -DKEYCHRON_RGB_ENABLE -DRETAIL_DEMO_ENABLE + +RGB_MATRIX_CUSTOM_KB = yes +RGB_MATRIX_DIR = common/rgb + +SRC += \ + $(RGB_MATRIX_DIR)/keychron_rgb.c \ + $(RGB_MATRIX_DIR)/per_key_rgb.c \ + $(RGB_MATRIX_DIR)/mixed_rgb.c \ + $(RGB_MATRIX_DIR)/retail_demo.c + +VPATH += $(TOP_DIR)/keyboards/keychron/$(RGB_MATRIX_DIR) + + diff --git a/keyboards/keychron/common/rgb/rgb_matrix_kb.inc b/keyboards/keychron/common/rgb/rgb_matrix_kb.inc new file mode 100644 index 0000000000..4a538f0cac --- /dev/null +++ b/keyboards/keychron/common/rgb/rgb_matrix_kb.inc @@ -0,0 +1,39 @@ +/* Copyright 2024 @ 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 . + */ + +#include "rgb_matrix_kb_config.h" + +#if defined(KEYCHRON_RGB_ENABLE) && defined(EECONFIG_SIZE_CUSTOM_RGB) +//extern bool MIXED_RGB(effect_params_t *params); + +RGB_MATRIX_EFFECT(PER_KEY_RGB) +RGB_MATRIX_EFFECT(MIXED_RGB) + +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool PER_KEY_RGB(effect_params_t *params) { + extern bool per_key_rgb(effect_params_t *params); + return per_key_rgb(params); +} + +bool MIXED_RGB(effect_params_t *params) { + extern bool mixed_rgb(effect_params_t *params); + return mixed_rgb(params); +} + +#endif + +#endif diff --git a/keyboards/keychron/common/rgb/rgb_matrix_kb_config.h b/keyboards/keychron/common/rgb/rgb_matrix_kb_config.h new file mode 100644 index 0000000000..530a46b11c --- /dev/null +++ b/keyboards/keychron/common/rgb/rgb_matrix_kb_config.h @@ -0,0 +1,26 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once +#include "config.h" + +#ifndef EFFECT_LAYERS +#define EFFECT_LAYERS 2 +#endif + +#ifndef EFFECTS_PER_LAYER +#define EFFECTS_PER_LAYER 5 +#endif diff --git a/keyboards/keychron/common/snap_click/eeconfig_snap_click.h b/keyboards/keychron/common/snap_click/eeconfig_snap_click.h new file mode 100644 index 0000000000..d53879ca92 --- /dev/null +++ b/keyboards/keychron/common/snap_click/eeconfig_snap_click.h @@ -0,0 +1,26 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once + +#ifndef SNAP_CLICK_COUNT +# define SNAP_CLICK_COUNT 20 +#endif + +#define SIZE_OF_SNAP_CLICK_CONFIG_T 3 + +#define EECONFIG_SIZE_SNAP_CLICK (SNAP_CLICK_COUNT * SIZE_OF_SNAP_CLICK_CONFIG_T) + diff --git a/keyboards/keychron/common/snap_click/snap_click.c b/keyboards/keychron/common/snap_click/snap_click.c new file mode 100644 index 0000000000..b795df70b1 --- /dev/null +++ b/keyboards/keychron/common/snap_click/snap_click.c @@ -0,0 +1,201 @@ +/* Copyright 2024 @ 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 . + */ + +#include +#include "eeconfig_kb.h" +#include "snap_click.h" +#include "raw_hid.h" +#include "eeconfig.h" +#include "matrix.h" +#include "quantum.h" +#include "keychron_raw_hid.h" + +#if defined(SNAP_CLICK_ENABLE) &&defined(EECONFIG_SIZE_SNAP_CLICK) + +enum { + SNAP_CLICK_TYPE_NONE = 0, + SNAP_CLICK_TYPE_REGULAR, + SNAP_CLICK_TYPE_LAST_INPUT, + SNAP_CLICK_TYPE_FIRST_KEY, + SNAP_CLICK_TYPE_SECOND_KEY, + SNAP_CLICK_TYPE_NEUTRAL, + SNAP_CLICK_TYPE_MAX, +}; + +#define SC_MASK_BOTH_KEYS_PRESSED 3 + +snap_click_config_t snap_click_pair[SNAP_CLICK_COUNT]; +snap_click_state_t snap_click_state[SNAP_CLICK_COUNT]; + +void snap_click_config_reset(void) { + memset(snap_click_pair, 0, sizeof(snap_click_pair)); + eeprom_update_block(snap_click_pair, (uint8_t *)(EECONFIG_BASE_SNAP_CLICK), sizeof(snap_click_pair)); +} + +void snap_click_init(void) { + eeprom_read_block(snap_click_pair, (uint8_t *)(EECONFIG_BASE_SNAP_CLICK), sizeof(snap_click_pair)); + memset(snap_click_state, 0, sizeof(snap_click_state)); +} + +bool process_record_snap_click(uint16_t keycode, keyrecord_t * record) +{ + for (uint8_t i=0; itype && (keycode == p->key[0] || keycode == p->key[1])) + { + snap_click_state_t *pState = &snap_click_state[i]; + uint8_t index = keycode == p->key[1]; // 0 or 1 of key pair + + if (record->event.pressed) { + uint8_t state = 0x01 << index; + + if (pState->state == 0) { + // Single key down + pState->state_keys = pState->last_single_key = state; + } else if ((state & pState->state_keys) == 0) { // TODO: do we need checking? + // Both keys are pressed + pState->state_keys = SC_MASK_BOTH_KEYS_PRESSED; + switch (p->type) { + case SNAP_CLICK_TYPE_REGULAR: + case SNAP_CLICK_TYPE_LAST_INPUT: + unregister_code(p->key[1-index]); + register_code(p->key[index]); + break; + case SNAP_CLICK_TYPE_FIRST_KEY: + unregister_code(p->key[1]); + register_code(p->key[0]); + break; + case SNAP_CLICK_TYPE_SECOND_KEY: + unregister_code(p->key[0]); + register_code(p->key[1]); + break; + case SNAP_CLICK_TYPE_NEUTRAL: + unregister_code(p->key[1-index]); + break; + } + return false; + } + } else { + if (pState->state_keys == SC_MASK_BOTH_KEYS_PRESSED) { + // Snap click active + uint8_t state = 0x01 << (1-index); + pState->state_keys = pState->last_single_key = state; + + switch (p->type) { + case SNAP_CLICK_TYPE_REGULAR: + unregister_code(p->key[index]); + break; + case SNAP_CLICK_TYPE_LAST_INPUT: + case SNAP_CLICK_TYPE_FIRST_KEY: + case SNAP_CLICK_TYPE_SECOND_KEY: + if (is_key_pressed(p->key[index])) { + unregister_code(p->key[index]); + } + if (!is_key_pressed(p->key[1-index])) { + register_code(p->key[1-index]); + } + break; + case SNAP_CLICK_TYPE_NEUTRAL: + register_code(p->key[1-index]); + break; + } + + return false; + } else { + pState->state = 0; + } + } + } + } + + return true; +} + +static bool snap_click_get_info(uint8_t *data) { + data[1] = SNAP_CLICK_COUNT; + + return true; +} + +static bool snap_click_get(uint8_t *data) { + uint8_t start = data[0]; + uint8_t count = data[1]; + + if (count > 9 || start + count > SNAP_CLICK_COUNT) return false; + memcpy(&data[1], &snap_click_pair[start], count * sizeof(snap_click_config_t)); + + return true; +} + +static bool snap_click_set(uint8_t *data) { + uint8_t start = data[0]; + uint8_t count = data[1]; + + if (count > 9 || start + count > SNAP_CLICK_COUNT) return false; + for (uint8_t i=0; i= SNAP_CLICK_TYPE_MAX) + return false; + + if (type != 0 && (keycode1 == 0 || keycode2 == 0)) + return false; + } + memcpy(&snap_click_pair[start], &data[2], count * sizeof(snap_click_config_t)); + + return true; +} + +static bool snap_click_save(uint8_t *data) { + eeprom_update_block(snap_click_pair, (uint8_t *)(EECONFIG_BASE_SNAP_CLICK), sizeof(snap_click_pair)); + + return true; +} + +void snap_click_rx(uint8_t *data, uint8_t length) { + uint8_t cmd = data[1]; + bool success = true; + + switch (cmd) { + case SNAP_CLICK_GET_INFO: + success = snap_click_get_info(&data[2]); + break; + + case SNAP_CLICK_GET: + success = snap_click_get(&data[2]); + break; + + case SNAP_CLICK_SET: + success = snap_click_set(&data[2]); + break; + + case SNAP_CLICK_SAVE: + success = snap_click_save(&data[2]); + break; + + default: + data[0] = 0xFF; + break; + } + + data[2] = success ? 0 : 1; +} +#endif diff --git a/keyboards/keychron/common/snap_click/snap_click.h b/keyboards/keychron/common/snap_click/snap_click.h new file mode 100644 index 0000000000..6432116909 --- /dev/null +++ b/keyboards/keychron/common/snap_click/snap_click.h @@ -0,0 +1,43 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once + +typedef struct __attribute__((__packed__)) { + uint8_t type; + uint8_t key[2]; +} snap_click_config_t; +// size = 3 bytes + +typedef union { + uint8_t state; + struct { + uint8_t state_key_1:1; + uint8_t state_key_2:1; + uint8_t last_single_key_1:1; + uint8_t last_single_key_2:1; + uint8_t reserved:4; + }; + struct { + uint8_t state_keys:2; + uint8_t last_single_key:2; + uint8_t reserved2:4; + }; +} snap_click_state_t; + +void snap_click_config_reset(void); +void snap_click_rx(uint8_t *data, uint8_t length); + diff --git a/keyboards/keychron/common/snap_click/snap_click.mk b/keyboards/keychron/common/snap_click/snap_click.mk new file mode 100644 index 0000000000..cf86fe732d --- /dev/null +++ b/keyboards/keychron/common/snap_click/snap_click.mk @@ -0,0 +1,7 @@ +SNAP_CLICK_DIR = common/snap_click +SRC += \ + $(SNAP_CLICK_DIR)/snap_click.c \ + +VPATH += $(TOP_DIR)/keyboards/keychron/$(SNAP_CLICK_DIR) + +OPT_DEFS += -DSNAP_CLICK_ENABLE diff --git a/keyboards/keychron/common/wireless/bat_level_animation.c b/keyboards/keychron/common/wireless/bat_level_animation.c new file mode 100644 index 0000000000..43269d6836 --- /dev/null +++ b/keyboards/keychron/common/wireless/bat_level_animation.c @@ -0,0 +1,163 @@ + +/* Copyright 2023~2025 @ 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 . + */ + +#include "quantum.h" +#include "wireless.h" +#include "indicator.h" +#include "lpm.h" +#if defined(PROTOCOL_CHIBIOS) +# include +#elif if defined(PROTOCOL_LUFA) +# include "lufa.h" +#endif +#include "eeprom.h" + +#if (defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)) && defined(BAT_LEVEL_LED_LIST) + +#ifndef BAT_LEVEL_GROWING_INTERVAL +# define BAT_LEVEL_GROWING_INTERVAL 150 +#endif + +#ifndef BAT_LEVEL_ON_INTERVAL +# define BAT_LEVEL_ON_INTERVAL 3000 +#endif + +#ifdef LED_MATRIX_ENABLE +# define LED_DRIVER_IS_ENABLED led_matrix_is_enabled +#endif + +#ifdef RGB_MATRIX_ENABLE +# define LED_DRIVER_IS_ENABLED rgb_matrix_is_enabled +#endif + +enum { + BAT_LVL_ANI_NONE, + BAT_LVL_ANI_GROWING, + BAT_LVL_ANI_BLINK_OFF, + BAT_LVL_ANI_BLINK_ON, +}; + +static uint8_t animation_state = 0; +static uint32_t bat_lvl_ani_timer_buffer = 0; +static uint8_t bat_percentage; +static uint8_t cur_percentage; +static uint32_t time_interval; +#ifdef RGB_MATRIX_ENABLE +static uint8_t r, g, b; +#endif + +extern indicator_config_t indicator_config; +extern backlight_state_t original_backlight_state; + +void bat_level_animiation_start(uint8_t percentage) { + /* Turn on backlight mode for indicator */ + indicator_enable(); + + animation_state = BAT_LVL_ANI_GROWING; + bat_percentage = percentage; + bat_lvl_ani_timer_buffer = timer_read32(); + cur_percentage = 0; + time_interval = BAT_LEVEL_GROWING_INTERVAL; +#ifdef RGB_MATRIX_ENABLE + r = g = b = 255; +#endif +} + +void bat_level_animiation_stop(void) { + animation_state = BAT_LVL_ANI_NONE; +} + +bool bat_level_animiation_actived(void) { + return animation_state; +} + +void bat_level_animiation_indicate(void) { +#ifdef LED_MATRIX_ENABLE + uint8_t bat_lvl_led_list[10] = BAT_LEVEL_LED_LIST; + + for (uint8_t i = 0; i <= LED_MATRIX_LED_COUNT; i++) { + led_matrix_set_value(i, 0); + } + + if (animation_state == BAT_LVL_ANI_GROWING || animation_state == BAT_LVL_ANI_BLINK_ON) + for (uint8_t i = 0; i < cur_percentage / 10; i++) + led_matrix_set_value(bat_lvl_led_list[i], 255); +#endif + +#ifdef RGB_MATRIX_ENABLE + uint8_t bat_lvl_led_list[10] = BAT_LEVEL_LED_LIST; + + for (uint8_t i = 0; i <= RGB_MATRIX_LED_COUNT; i++) { + rgb_matrix_set_color(i, 0, 0, 0); + } + + if (animation_state == BAT_LVL_ANI_GROWING || animation_state == BAT_LVL_ANI_BLINK_ON) { + for (uint8_t i = 0; i < cur_percentage / 10; i++) { + rgb_matrix_set_color(bat_lvl_led_list[i], r, g, b); + } + } +#endif +} + +void bat_level_animiation_update(void) { + switch (animation_state) { + case BAT_LVL_ANI_GROWING: + if (cur_percentage < bat_percentage) + cur_percentage += 10; + else { + if (cur_percentage == 0) cur_percentage = 10; + animation_state = BAT_LVL_ANI_BLINK_OFF; + } + break; + + case BAT_LVL_ANI_BLINK_OFF: +#ifdef RGB_MATRIX_ENABLE + if (bat_percentage < 30) { + r = 255; + b = g = 0; + } else { + r = b = 0; + g = 255; + } +#endif + time_interval = BAT_LEVEL_ON_INTERVAL; + animation_state = BAT_LVL_ANI_BLINK_ON; + break; + + case BAT_LVL_ANI_BLINK_ON: + animation_state = BAT_LVL_ANI_NONE; + indicator_eeconfig_reload(); + if (indicator_config.value == 0 && !LED_DRIVER_IS_ENABLED()) { + indicator_disable(); + } + lpm_timer_reset(); + break; + + default: + break; + } + + bat_lvl_ani_timer_buffer = timer_read32(); +} + +void bat_level_animiation_task(void) { + if (animation_state && sync_timer_elapsed32(bat_lvl_ani_timer_buffer) > time_interval) { + bat_level_animiation_update(); + } +} + +#endif diff --git a/keyboards/keychron/common/wireless/bat_level_animation.h b/keyboards/keychron/common/wireless/bat_level_animation.h new file mode 100644 index 0000000000..d8e0e9f2ce --- /dev/null +++ b/keyboards/keychron/common/wireless/bat_level_animation.h @@ -0,0 +1,23 @@ +/* Copyright 2023~2025 @ lokher (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 . + */ + +#pragma once + +void bat_level_animiation_start(uint8_t percentage); +void bat_level_animiation_stop(void); +bool bat_level_animiation_actived(void); +void bat_level_animiation_indicate(void); +void bat_level_animiation_task(void); diff --git a/keyboards/keychron/common/wireless/battery.c b/keyboards/keychron/common/wireless/battery.c new file mode 100644 index 0000000000..60ab7722df --- /dev/null +++ b/keyboards/keychron/common/wireless/battery.c @@ -0,0 +1,229 @@ +/* Copyright 2022~2023 @ lokher (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 . + */ + +#include "quantum.h" +#include "wireless.h" +#include "battery.h" +#include "transport.h" +#include "lkbt51.h" +#include "lpm.h" +#include "indicator.h" +#include "rtc_timer.h" +#include "analog.h" + +#define BATTERY_EMPTY_COUNT 10 +#define CRITICAL_LOW_COUNT 20 + +/* Battery voltage resistive voltage divider setting of MCU */ +#ifndef RVD_R1 +# define RVD_R1 10 // Upper side resitor value (uint: KΩ) +#endif +#ifndef RVD_R2 +# define RVD_R2 10 // Lower side resitor value (uint: KΩ) +#endif + +/* Battery voltage resistive voltage divider setting of Bluetooth */ +#ifndef LKBT51_RVD_R1 +# define LKBT51_RVD_R1 560 +#endif +#ifndef LKBT51_RVD_R2 +# define LKBT51_RVD_R2 499 +#endif + +#ifndef VOLTAGE_TRIM_LED_MATRIX +# define VOLTAGE_TRIM_LED_MATRIX 30 +#endif + +#ifndef VOLTAGE_TRIM_RGB_MATRIX +# define VOLTAGE_TRIM_RGB_MATRIX 60 +#endif + +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) +extern uint8_t g_pwm_buffer[DRIVER_COUNT][192]; +#endif + +static uint32_t bat_monitor_timer_buffer = 0; +static uint16_t voltage = FULL_VOLTAGE_VALUE; +static uint8_t bat_empty = 0; +static uint8_t critical_low = 0; +static uint8_t bat_state; +static uint8_t power_on_sample = 0; + +void battery_init(void) { + bat_state = BAT_NOT_CHARGING; +#if defined(BAT_CHARGING_PIN) +# if (BAT_CHARGING_LEVEL == 0) + palSetLineMode(BAT_CHARGING_PIN, PAL_MODE_INPUT_PULLUP); +# else + palSetLineMode(BAT_CHARGING_PIN, PAL_MODE_INPUT_PULLDOWN); +# endif +#endif + +#ifdef BAT_ADC_ENABLE_PIN + palSetLineMode(BAT_ADC_ENABLE_PIN, PAL_MODE_OUTPUT_PUSHPULL); + writePin(BAT_ADC_ENABLE_PIN, 1); +#endif +#ifdef BAT_ADC_PIN + palSetLineMode(BAT_ADC_PIN, PAL_MODE_INPUT_ANALOG); +#endif +} + +void battery_stop(void) { +#if (HAL_USE_ADC) +# ifdef BAT_ADC_ENABLE_PIN + writePin(BAT_ADC_ENABLE_PIN, 0); +# endif +# ifdef BAT_ADC_PIN + palSetLineMode(BAT_ADC_PIN, PAL_MODE_INPUT_ANALOG); + analog_stop(BAT_ADC_PIN); +# endif +#endif +} + +__attribute__((weak)) void battery_measure(void) { + lkbt51_read_state_reg(0x05, 0x02); +} + +/* Calculate the voltage */ +__attribute__((weak)) void battery_calculate_voltage(bool vol_src_bt, uint16_t value) { + uint16_t voltage; + + if (vol_src_bt) + voltage = ((uint32_t)value) * (LKBT51_RVD_R1 + LKBT51_RVD_R2) / LKBT51_RVD_R2; + else + voltage = (uint32_t)value * 3300 / 1024 * (RVD_R1 + RVD_R2) / RVD_R2; + +#ifdef LED_MATRIX_ENABLE + if (led_matrix_is_enabled()) { + uint32_t totalBuf = 0; + + for (uint8_t i = 0; i < DRIVER_COUNT; i++) + for (uint8_t j = 0; j < 192; j++) + totalBuf += g_pwm_buffer[i][j]; + /* We assumpt it is linear relationship*/ + voltage += (VOLTAGE_TRIM_LED_MATRIX * totalBuf / LED_MATRIX_LED_COUNT / 255); + } +#endif +#ifdef RGB_MATRIX_ENABLE + if (rgb_matrix_is_enabled()) { + uint32_t totalBuf = 0; + + for (uint8_t i = 0; i < DRIVER_COUNT; i++) + for (uint8_t j = 0; j < 192; j++) + totalBuf += g_pwm_buffer[i][j]; + /* We assumpt it is linear relationship*/ + uint32_t compensation = VOLTAGE_TRIM_RGB_MATRIX * totalBuf / RGB_MATRIX_LED_COUNT / 255 / 3; + + voltage += compensation; + } +#endif + + battery_set_voltage(voltage); +} + +void battery_set_voltage(uint16_t value) { + voltage = value; +} + +uint16_t battery_get_voltage(void) { + return voltage; +} + +uint8_t battery_get_percentage(void) { + if (voltage > FULL_VOLTAGE_VALUE) return 100; + + if (voltage > EMPTY_VOLTAGE_VALUE) { + return ((uint32_t)voltage - EMPTY_VOLTAGE_VALUE) * 80 / (FULL_VOLTAGE_VALUE - EMPTY_VOLTAGE_VALUE) + 20; + } + + if (voltage > SHUTDOWN_VOLTAGE_VALUE) { + return ((uint32_t)voltage - SHUTDOWN_VOLTAGE_VALUE) * 20 / (EMPTY_VOLTAGE_VALUE - SHUTDOWN_VOLTAGE_VALUE); + } else + return 0; +} + +bool battery_is_empty(void) { + return bat_empty > BATTERY_EMPTY_COUNT; +} + +bool battery_is_critical_low(void) { + return critical_low > CRITICAL_LOW_COUNT; +} + +void battery_check_empty(void) { + if (voltage < EMPTY_VOLTAGE_VALUE) { + if (bat_empty <= BATTERY_EMPTY_COUNT) { + if (++bat_empty > BATTERY_EMPTY_COUNT) { + indicator_battery_low_enable(true); + power_on_sample = VOLTAGE_POWER_ON_MEASURE_COUNT; + } + } + } +} + +void battery_check_critical_low(void) { + if (voltage < SHUTDOWN_VOLTAGE_VALUE) { + if (critical_low <= CRITICAL_LOW_COUNT) { + if (++critical_low > CRITICAL_LOW_COUNT) wireless_low_battery_shutdown(); + } + } else if (critical_low <= CRITICAL_LOW_COUNT) { + critical_low = 0; + } +} + +bool battery_power_on_sample(void) { + return power_on_sample < VOLTAGE_POWER_ON_MEASURE_COUNT; +} + +void battery_task(void) { + uint32_t t = rtc_timer_elapsed_ms(bat_monitor_timer_buffer); + if ((get_transport() & TRANSPORT_WIRELESS) && (wireless_get_state() == WT_CONNECTED || battery_power_on_sample())) { +#if defined(BAT_CHARGING_PIN) + if (usb_power_connected() && t > VOLTAGE_MEASURE_INTERVAL) { + if (readPin(BAT_CHARGING_PIN) == BAT_CHARGING_LEVEL) + lkbt51_update_bat_state(BAT_CHARGING); + else + lkbt51_update_bat_state(BAT_FULL_CHARGED); + } +#endif + + if ((battery_power_on_sample() +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) + && !indicator_is_enabled() +#endif + && t > BACKLIGHT_OFF_VOLTAGE_MEASURE_INTERVAL) || + t > VOLTAGE_MEASURE_INTERVAL) { + + battery_check_empty(); + battery_check_critical_low(); + + bat_monitor_timer_buffer = rtc_timer_read_ms(); + if (bat_monitor_timer_buffer > RTC_MAX_TIME) { + bat_monitor_timer_buffer = 0; + rtc_timer_clear(); + } + + battery_measure(); + if (power_on_sample < VOLTAGE_POWER_ON_MEASURE_COUNT) power_on_sample++; + } + } + + if ((bat_empty || critical_low) && usb_power_connected()) { + bat_empty = false; + critical_low = false; + indicator_battery_low_enable(false); + } +} diff --git a/keyboards/keychron/common/wireless/battery.h b/keyboards/keychron/common/wireless/battery.h new file mode 100644 index 0000000000..caa4d0db81 --- /dev/null +++ b/keyboards/keychron/common/wireless/battery.h @@ -0,0 +1,61 @@ +/* Copyright 2022~2023 @ lokher (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 . + */ + +#pragma once + +enum { + BAT_NOT_CHARGING = 0, + BAT_CHARGING, + BAT_FULL_CHARGED, +}; + +#ifndef FULL_VOLTAGE_VALUE +# define FULL_VOLTAGE_VALUE 4100 +#endif + +#ifndef EMPTY_VOLTAGE_VALUE +# define EMPTY_VOLTAGE_VALUE 3500 +#endif + +#ifndef SHUTDOWN_VOLTAGE_VALUE +# define SHUTDOWN_VOLTAGE_VALUE 3300 +#endif + +#ifndef VOLTAGE_MEASURE_INTERVAL +# define VOLTAGE_MEASURE_INTERVAL 3000 +#endif + +#ifndef VOLTAGE_POWER_ON_MEASURE_COUNT +# define VOLTAGE_POWER_ON_MEASURE_COUNT 15 +#endif + +#ifndef BACKLIGHT_OFF_VOLTAGE_MEASURE_INTERVAL +# define BACKLIGHT_OFF_VOLTAGE_MEASURE_INTERVAL 200 +#endif + +void battery_init(void); +void battery_stop(void); + +void battery_measure(void); +void battery_calculate_voltage(bool vol_src_bt, uint16_t value); +void battery_set_voltage(uint16_t value); +uint16_t battery_get_voltage(void); +uint8_t battery_get_percentage(void); +bool battery_is_empty(void); +bool battery_is_critical_low(void); +bool battery_power_on_sample(void); + +void battery_task(void); diff --git a/keyboards/keychron/common/wireless/eeconfig_wireless.h b/keyboards/keychron/common/wireless/eeconfig_wireless.h new file mode 100644 index 0000000000..109e6d3c9a --- /dev/null +++ b/keyboards/keychron/common/wireless/eeconfig_wireless.h @@ -0,0 +1,20 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once + +#define EECONFIG_SIZE_WIRELESS_CONFIG 4 //sizeof(backlit_disable_time) + sizeof (connected_idle_time) + diff --git a/keyboards/keychron/common/wireless/indicator.c b/keyboards/keychron/common/wireless/indicator.c new file mode 100644 index 0000000000..6271466fe2 --- /dev/null +++ b/keyboards/keychron/common/wireless/indicator.c @@ -0,0 +1,773 @@ +/* Copyright 2023~2025 @ lokher (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 . + */ + +#include "quantum.h" +#include "indicator.h" +#include "transport.h" +#include "battery.h" +#include "eeconfig.h" +#include "wireless_config.h" +#include "config.h" +#include "rtc_timer.h" +#include "keychron_common.h" +#include "usb_main.h" +#ifdef FACTORY_TEST_ENABLE +# include "factory_test.h" +#endif +#include "lpm.h" +#include "keychron_task.h" +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) +# ifdef LED_MATRIX_ENABLE +# include "led_matrix.h" +# endif +# ifdef RGB_MATRIX_ENABLE +# include "rgb_matrix.h" +# endif +# include "bat_level_animation.h" +# include "eeprom.h" +#endif + +#define HOST_INDEX_MASK 0x0F +#define HOST_P2P4G 0x10 +#define LED_ON 0x80 + +// #define RGB_MATRIX_TIMEOUT_INFINITE 0xFFFFFFFF +#ifdef LED_MATRIX_ENABLE +# define DECIDE_TIME(t, duration) (duration == 0 ? LED_MATRIX_TIMEOUT_INFINITE : ((t > duration) ? t : duration)) +#endif +#ifdef RGB_MATRIX_ENABLE +# define DECIDE_TIME(t, duration) (duration == 0 ? RGB_MATRIX_TIMEOUT_INFINITE : ((t > duration) ? t : duration)) +#endif + +#define INDICATOR_SET(s) memcpy(&indicator_config, &s##_config, sizeof(indicator_config_t)); + +enum { + BACKLIGHT_OFF = 0x00, + BACKLIGHT_ON_CONNECTED = 0x01, + BACKLIGHT_ON_UNCONNECTED = 0x02, +}; + +extern uint16_t backlit_disable_time; + +static indicator_config_t pairing_config = INDICATOR_CONFIG_PARING; +static indicator_config_t connected_config = INDICATOR_CONFIG_CONNECTD; +static indicator_config_t reconnecting_config = INDICATOR_CONFIG_RECONNECTING; +static indicator_config_t disconnected_config = INDICATOR_CONFIG_DISCONNECTED; +indicator_config_t indicator_config; +static wt_state_t indicator_state; +static uint16_t next_period; +static indicator_type_t type; +static uint32_t indicator_timer_buffer = 0; + +#if defined(BAT_LOW_LED_PIN) || defined(SPACE_KEY_LOW_BAT_IND) +static uint32_t bat_low_backlit_indicator = 0; +static uint8_t bat_low_ind_state = 0; +static uint32_t rtc_time = 0; +#endif + +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) +backlight_state_t original_backlight_state; + +# ifdef BT_HOST_LED_MATRIX_LIST +static uint8_t bt_host_led_matrix_list[BT_HOST_DEVICES_COUNT] = BT_HOST_LED_MATRIX_LIST; +# endif + +# ifdef P2P4G_HOST_LED_MATRIX_LIST +static uint8_t p2p4g_host_led_matrix_list[P2P4G_HOST_DEVICES_COUNT] = P2P4G_HOST_LED_MATRIX_LIST; +# endif +#endif + +#ifdef BT_HOST_LED_PIN_LIST +static pin_t bt_led_pin_list[BT_HOST_DEVICES_COUNT] = BT_HOST_LED_PIN_LIST; +#endif + +#ifdef P24G_HOST_LED_PIN_LIST +static pin_t p24g_led_pin_list[P24G_HOST_DEVICES_COUNT] = P24G_HOST_LED_PIN_LIST; +#endif + +#ifdef LED_MATRIX_ENABLE +# define LED_DRIVER led_matrix_driver +# define LED_INDICATORS_KB led_matrix_indicators_bt +# define LED_INDICATORS_USER led_matrix_indicators_user +# define LED_NONE_INDICATORS_KB led_matrix_none_indicators_kb +# define SET_ALL_LED_OFF() led_matrix_set_value_all(0) +# define SET_LED_OFF(idx) led_matrix_set_value(idx, 0) +# define SET_LED_ON(idx) led_matrix_set_value(idx, 255) +# define SET_LED_BT(idx) led_matrix_set_value(idx, 255) +# define SET_LED_P24G(idx) led_matrix_set_value(idx, 255) +# define SET_LED_LOW_BAT(idx) led_matrix_set_value(idx, 255) +# define LED_DRIVER_IS_ENABLED led_matrix_is_enabled +# define LED_DRIVER_EECONFIG_RELOAD() \ + eeprom_read_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); \ + if (!led_matrix_eeconfig.mode) { \ + eeconfig_update_led_matrix_default(); \ + } +# define LED_DRIVER_ALLOW_SHUTDOWN led_matrix_driver_allow_shutdown +# define LED_DRIVER_SHUTDOWN led_matrix_driver_shutdown +# define LED_DRIVER_EXIT_SHUTDOWN led_matrix_driver_exit_shutdown +# define LED_DRIVER_ENABLE_NOEEPROM led_matrix_enable_noeeprom +# define LED_DRIVER_DISABLE_NOEEPROM led_matrix_disable_noeeprom +# define LED_DRIVER_DISABLE_TIMEOUT_SET led_matrix_disable_timeout_set +# define LED_DRIVER_DISABLE_TIME_RESET led_matrix_disable_time_reset +# define LED_DRIVER_TIMEOUTED led_matrix_timeouted +#endif + +#ifdef RGB_MATRIX_ENABLE +# define LED_DRIVER rgb_matrix_driver +# define LED_INDICATORS_KB rgb_matrix_indicators_bt +# define LED_INDICATORS_USER rgb_matrix_indicators_user +# define LED_NONE_INDICATORS_KB rgb_matrix_none_indicators_kb +# define SET_ALL_LED_OFF() rgb_matrix_set_color_all(0, 0, 0) +# define SET_LED_OFF(idx) rgb_matrix_set_color(idx, 0, 0, 0) +# define SET_LED_ON(idx) rgb_matrix_set_color(idx, 255, 255, 255) +# define SET_LED_BT(idx) rgb_matrix_set_color(idx, 0, 0, 255) +# define SET_LED_P24G(idx) rgb_matrix_set_color(idx, 0, 255, 0) +# define SET_LED_LOW_BAT(idx) rgb_matrix_set_color(idx, 255, 0, 0) +# define LED_DRIVER_IS_ENABLED rgb_matrix_is_enabled +# define LED_DRIVER_EECONFIG_RELOAD() \ + eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); \ + if (!rgb_matrix_config.mode) { \ + eeconfig_update_rgb_matrix_default(); \ + } +# define LED_DRIVER_ALLOW_SHUTDOWN rgb_matrix_driver_allow_shutdown +# define LED_DRIVER_SHUTDOWN rgb_matrix_driver_shutdown +# define LED_DRIVER_EXIT_SHUTDOWN rgb_matrix_driver_exit_shutdown +# define LED_DRIVER_ENABLE_NOEEPROM rgb_matrix_enable_noeeprom +# define LED_DRIVER_DISABLE_NOEEPROM rgb_matrix_disable_noeeprom +# define LED_DRIVER_DISABLE_TIMEOUT_SET rgb_matrix_disable_timeout_set +# define LED_DRIVER_DISABLE_TIME_RESET rgb_matrix_disable_time_reset +# define LED_DRIVER_TIMEOUTED rgb_matrix_timeouted +#endif + +bool LED_INDICATORS_KB(void); + +void indicator_init(void) { + memset(&indicator_config, 0, sizeof(indicator_config)); + +#if defined(BT_HOST_LED_PIN_LIST) + for (uint8_t i = 0; i < BT_HOST_DEVICES_COUNT; i++) { + setPinOutput(bt_led_pin_list[i]); + writePin(bt_led_pin_list[i], !HOST_LED_PIN_ON_STATE); + } +#endif + +#ifdef P24G_HOST_LED_PIN_LIST + for (uint8_t i = 0; i < P24G_HOST_DEVICES_COUNT; i++) { + setPinOutput(p24g_led_pin_list[i]); + writePin(p24g_led_pin_list[i], !HOST_LED_PIN_ON_STATE); + } +#endif + +#ifdef COMMON_BT_LED_PIN + setPinOutput(COMMON_BT_LED_PIN); + writePin(COMMON_BT_LED_PIN, !COMMON_BT_LED_PIN_ON_STATE); +#endif + +#ifdef COMMON_P24G_LED_PIN + setPinOutput(COMMON_P24G_LED_PIN); + writePin(COMMON_P24G_LED_PIN, !COMMON_BT_LED_PIN_ON_STATE); +#endif + +#ifdef BAT_LOW_LED_PIN +# ifdef POWER_ON_LED_DURATION + if (timer_read32() > POWER_ON_LED_DURATION) +# endif + { + setPinOutput(BAT_LOW_LED_PIN); + writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE); + } +#endif +} + +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) +void indicator_enable(void) { + if (!LED_DRIVER_IS_ENABLED()) { + LED_DRIVER_ENABLE_NOEEPROM(); + } +} + +inline void indicator_disable(void) { + LED_DRIVER_DISABLE_NOEEPROM(); +} + +void indicator_reset_backlit_time(void) { + LED_DRIVER_DISABLE_TIME_RESET(); +} + +void indicator_set_backlit_timeout(uint32_t time) { + LED_DRIVER_DISABLE_TIMEOUT_SET(time); + indicator_reset_backlit_time(); +} + +bool indicator_is_enabled(void) { + return LED_DRIVER_IS_ENABLED(); +} + +void indicator_eeconfig_reload(void) { + LED_DRIVER_EECONFIG_RELOAD(); +} + +#endif + +bool indicator_is_running(void) { + return +#if defined(BAT_LOW_LED_PIN) || defined(SPACE_KEY_LOW_BAT_IND) + bat_low_ind_state || +#endif + !!indicator_config.value; +} + +static void indicator_timer_cb(void *arg) { + if (*(indicator_type_t *)arg != INDICATOR_LAST) type = *(indicator_type_t *)arg; + + bool time_up = false; + switch (type) { + case INDICATOR_NONE: + break; + case INDICATOR_OFF: + next_period = 0; + time_up = true; + break; + + case INDICATOR_ON: + if (indicator_config.value) { + if (indicator_config.elapsed == 0) { + indicator_config.value |= LED_ON; + + if (indicator_config.duration) { + indicator_config.elapsed += indicator_config.duration; + } + } else + time_up = true; + } + break; + + case INDICATOR_ON_OFF: + if (indicator_config.value) { + if (indicator_config.elapsed == 0) { + indicator_config.value |= LED_ON; + next_period = indicator_config.on_time; + } else { + indicator_config.value = indicator_config.value & 0x1F; + next_period = indicator_config.duration - indicator_config.on_time; + } + + if ((indicator_config.duration == 0 || indicator_config.elapsed <= indicator_config.duration) && next_period != 0) { + indicator_config.elapsed += next_period; + } else { + time_up = true; + } + } + break; + + case INDICATOR_BLINK: + if (indicator_config.value) { + if (indicator_config.value & LED_ON) { + indicator_config.value = indicator_config.value & 0x1F; + next_period = indicator_config.off_time; + } else { + indicator_config.value |= LED_ON; + next_period = indicator_config.on_time; + } + + if ((indicator_config.duration == 0 || indicator_config.elapsed <= indicator_config.duration) && next_period != 0) { + indicator_config.elapsed += next_period; + } else { + time_up = true; + } + } + break; + default: + time_up = true; + + next_period = 0; + break; + } + +#if defined(BT_HOST_LED_PIN_LIST) || defined(P24G_HOST_LED_PIN_LIST) || defined(COMMON_BT_LED_PIN) || defined(COMMON_P24G_LED_PIN) + if (indicator_config.value) { + uint8_t idx = (indicator_config.value & HOST_INDEX_MASK) - 1; +# if defined(BT_HOST_LED_PIN_LIST) || defined(P24G_HOST_LED_PIN_LIST) + pin_t *led_lin_list = NULL; +# endif +# if defined(COMMON_BT_LED_PIN) || defined(COMMON_P24G_LED_PIN) + pin_t led_pin = NO_PIN; +# endif + uint8_t led_count; +# if defined(P24G_HOST_LED_PIN_LIST) || defined(COMMON_P24G_LED_PIN) + if (indicator_config.value & HOST_P2P4G) { + if (idx < P24G_HOST_DEVICES_COUNT) { +# if defined(P24G_HOST_LED_PIN_LIST) + led_lin_list = p24g_led_pin_list; +# endif +# if defined(COMMON_P24G_LED_PIN) + led_pin = COMMON_P24G_LED_PIN; +# endif + } + led_count = P24G_HOST_DEVICES_COUNT; + } else +# endif + { + if (idx < BT_HOST_DEVICES_COUNT) { +# if defined(BT_HOST_LED_PIN_LIST) + led_lin_list = bt_led_pin_list; +# endif +# if defined(COMMON_BT_LED_PIN) + led_pin = COMMON_BT_LED_PIN; +# endif + } + led_count = BT_HOST_DEVICES_COUNT; + } + +#if defined(BT_HOST_LED_PIN_LIST) || defined(P24G_HOST_LED_PIN_LIST) + for (uint8_t i = 0; i < led_count; i++) { + if (i != idx) { + if (led_lin_list) writePin(led_lin_list[idx], !HOST_LED_PIN_ON_STATE); + } + } +#endif + + if ((indicator_config.value & LED_ON) && !time_up) { + if (led_lin_list) writePin(led_lin_list[idx], HOST_LED_PIN_ON_STATE); +# if defined(COMMON_BT_LED_PIN) || defined(COMMON_P24G_LED_PIN) + if (led_pin != NO_PIN) writePin(led_pin, COMMON_BT_LED_PIN_ON_STATE); +# endif + } else { + if (led_lin_list) writePin(led_lin_list[idx], !HOST_LED_PIN_ON_STATE); +# if defined(COMMON_BT_LED_PIN) || defined(COMMON_P24G_LED_PIN) + if (led_pin != NO_PIN) writePin(led_pin, !COMMON_BT_LED_PIN_ON_STATE); +# endif + } + + } +#endif + + if (time_up) { + /* Set indicator to off on timeup, avoid keeping light up until next update in raindrop effect */ + indicator_config.value = indicator_config.value & 0x1F; +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) + LED_INDICATORS_KB(); +#endif + + indicator_config.value = 0; + lpm_timer_reset(); + } + + if (indicator_config.value == 0) { +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) + indicator_eeconfig_reload(); + if (!LED_DRIVER_IS_ENABLED()) indicator_disable(); +#endif + } +} + +void indicator_set(wt_state_t state, uint8_t host_index) { + if (get_transport() == TRANSPORT_USB) return; + + static uint8_t pre_state = 0; + static uint8_t current_state = 0; + static uint8_t current_host = 0; + bool host_index_changed = false; + + if (host_index == 24) host_index = HOST_P2P4G | 0x01; + + if (current_host != host_index && state != WT_DISCONNECTED) { + host_index_changed = true; + current_host = host_index; + } + + if (current_state != state || host_index_changed || state == WT_RECONNECTING) { + // Some BT chips need to reset to enter sleep mode, ignore it. + if (current_state == WT_SUSPEND && state == WT_DISCONNECTED) return; + + pre_state = current_state; + current_state = state; + (void)pre_state; + } else { + return; + } + + indicator_timer_buffer = timer_read32(); + +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) + /* Turn on backlight mode for indicator */ + indicator_enable(); + indicator_reset_backlit_time(); +#endif + + switch (state) { + case WT_DISCONNECTED: +#if defined(BT_HOST_LED_PIN_LIST) + if ((host_index & HOST_P2P4G) != HOST_P2P4G) writePin(bt_led_pin_list[(host_index & HOST_INDEX_MASK) - 1], !HOST_LED_PIN_ON_STATE); +#endif +#if defined(P24G_HOST_LED_PIN_LIST) + if (host_index & HOST_P2P4G) writePin(p24g_led_pin_list[(host_index & HOST_INDEX_MASK) - 1], !HOST_LED_PIN_ON_STATE); +#endif +#ifdef COMMON_BT_LED_PIN + writePin(COMMON_BT_LED_PIN, !COMMON_BT_LED_PIN_ON_STATE); +#endif +#ifdef COMMON_P24G_LED_PIN + writePin(COMMON_P24G_LED_PIN, !COMMON_BT_LED_PIN_ON_STATE); +#endif + INDICATOR_SET(disconnected); + indicator_config.value = (indicator_config.type == INDICATOR_NONE) ? 0 : host_index; + indicator_timer_cb((void *)&indicator_config.type); +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) + if (battery_is_critical_low()) { + indicator_set_backlit_timeout(1000); + + } else { + if (pre_state == WT_CONNECTED) + indicator_set_backlit_timeout(1000); + else + /* Set timer so that user has chance to turn on the backlight when is off */ + indicator_set_backlit_timeout(DECIDE_TIME(DISCONNECTED_BACKLIGHT_DISABLE_TIMEOUT * 1000, indicator_config.duration)); + } +#endif + break; + + case WT_CONNECTED: + if (indicator_state != WT_CONNECTED) { + INDICATOR_SET(connected); + indicator_config.value = (indicator_config.type == INDICATOR_NONE) ? 0 : host_index; + indicator_timer_cb((void *)&indicator_config.type); + } +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) + indicator_set_backlit_timeout(DECIDE_TIME(backlit_disable_time * 1000, indicator_config.duration)); +#endif + break; + + case WT_PARING: + INDICATOR_SET(pairing); + indicator_config.value = (indicator_config.type == INDICATOR_NONE) ? 0 : LED_ON | host_index; + indicator_timer_cb((void *)&indicator_config.type); +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) + indicator_set_backlit_timeout(DECIDE_TIME(DISCONNECTED_BACKLIGHT_DISABLE_TIMEOUT * 1000, indicator_config.duration)); +#endif + break; + + case WT_RECONNECTING: + INDICATOR_SET(reconnecting); + indicator_config.value = (indicator_config.type == INDICATOR_NONE) ? 0 : LED_ON | host_index; + indicator_timer_cb((void *)&indicator_config.type); +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) + indicator_set_backlit_timeout(DECIDE_TIME(DISCONNECTED_BACKLIGHT_DISABLE_TIMEOUT * 1000, indicator_config.duration)); +#endif + break; + + case WT_SUSPEND: + INDICATOR_SET(disconnected); + indicator_config.value = (indicator_config.type == INDICATOR_NONE) ? 0 : host_index; + indicator_timer_cb((void *)&indicator_config.type); +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) +# ifdef FACTORY_TEST_ENABLE + if (factory_reset_indicating()) + indicator_set_backlit_timeout(3000); + else +# endif + { + indicator_set_backlit_timeout(1000); + } +#endif + +#if defined(BT_HOST_LED_PIN_LIST) + for (uint8_t i = 0; i < BT_HOST_DEVICES_COUNT; i++) writePin(bt_led_pin_list[i], !HOST_LED_PIN_ON_STATE); +#endif +#if defined(P24G_HOST_LED_PIN_LIST) + for (uint8_t i = 0; i < P24G_HOST_DEVICES_COUNT; i++) writePin(p24g_led_pin_list[i], !HOST_LED_PIN_ON_STATE); +#endif +#ifdef COMMON_BT_LED_PIN + writePin(COMMON_BT_LED_PIN, !COMMON_BT_LED_PIN_ON_STATE); +#endif +#ifdef COMMON_P24G_LED_PIN + writePin(COMMON_P24G_LED_PIN, !COMMON_BT_LED_PIN_ON_STATE); +#endif + + break; + + default: + break; + } + + indicator_state = state; +} + +void indicator_stop(void) { + indicator_config.value = 0; +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) + indicator_eeconfig_reload(); + + if (indicator_is_enabled()) { + indicator_enable(); + } else { + indicator_disable(); + } +#endif +} + +void indicator_battery_low_enable(bool enable) { +#if defined(BAT_LOW_LED_PIN) || defined(SPACE_KEY_LOW_BAT_IND) + if (enable) { + uint32_t t = rtc_timer_read_ms(); + + /* Check overflow */ + if (rtc_time > t) { + if (bat_low_ind_state == 0) + rtc_time = t; // Update rtc_time if indicating is not running + else { + rtc_time += t; + } + } + + /* Indicating at first time or after the interval */ + if ((rtc_time == 0 || t - rtc_time > LOW_BAT_LED_TRIG_INTERVAL) && bat_low_ind_state == 0) { + bat_low_backlit_indicator = enable ? timer_read32() : 0; + rtc_time = rtc_timer_read_ms(); + bat_low_ind_state = 1; +# if defined(SPACE_KEY_LOW_BAT_IND) + indicator_enable(); +# endif + } + } else { + rtc_time = 0; + bat_low_ind_state = 0; +# if defined(BAT_LOW_LED_PIN) + writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE); +# endif +# if defined(SPACE_KEY_LOW_BAT_IND) + indicator_eeconfig_reload(); + if (!LED_DRIVER_IS_ENABLED()) indicator_disable(); +# endif + } +#endif +} + +void indicator_battery_low(void) { +#if defined(BAT_LOW_LED_PIN) || defined(SPACE_KEY_LOW_BAT_IND) + if (bat_low_ind_state) { + if ((bat_low_ind_state & 0x0F) <= (LOW_BAT_LED_BLINK_TIMES) && + timer_elapsed32(bat_low_backlit_indicator) > (LOW_BAT_LED_BLINK_PERIOD)) { + if (bat_low_ind_state & 0x80) { + bat_low_ind_state &= 0x7F; + bat_low_ind_state++; +# if defined(BAT_LOW_LED_PIN) + writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE); +# endif + } else { + bat_low_ind_state |= 0x80; +# if defined(BAT_LOW_LED_PIN) + writePin(BAT_LOW_LED_PIN, BAT_LOW_LED_PIN_ON_STATE); +# endif + } + + bat_low_backlit_indicator = timer_read32(); + + /* Restore backligth state */ + if ((bat_low_ind_state & 0x0F) > (LOW_BAT_LED_BLINK_TIMES)) { +# if defined(BAT_LOW_LED_PIN) + writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE); +# endif +# if defined(SPACE_KEY_LOW_BAT_IND) +# if defined(NUM_LOCK_INDEX) || defined(CAPS_LOCK_INDEX) || defined(SCROLL_LOCK_INDEX) || defined(COMPOSE_LOCK_INDEX) || defined(KANA_LOCK_INDEX) + if (LED_DRIVER_ALLOW_SHUTDOWN()) +# endif + indicator_disable(); +# endif + } + } else if ((bat_low_ind_state & 0x0F) > (LOW_BAT_LED_BLINK_TIMES)) { +# if defined(BAT_LOW_LED_PIN) + writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE); +# endif + bat_low_ind_state = 0; + lpm_timer_reset(); + } + } +#endif +} + +void indicator_task(void) { +#if defined(BAT_LEVEL_LED_LIST) + bat_level_animiation_task(); +#endif + if (indicator_config.value && timer_elapsed32(indicator_timer_buffer) >= next_period) { + indicator_timer_cb((void *)&type); + indicator_timer_buffer = timer_read32(); + } + + indicator_battery_low(); +} + +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) +__attribute__((weak)) void os_state_indicate(void) { +# if defined(RGB_DISABLE_WHEN_USB_SUSPENDED) || defined(LED_DISABLE_WHEN_USB_SUSPENDED) + if (get_transport() == TRANSPORT_USB && USB_DRIVER.state == USB_SUSPENDED) return; +# endif + +# if defined(NUM_LOCK_INDEX) + if (host_keyboard_led_state().num_lock) { +# if defined(DIM_NUM_LOCK) + SET_LED_OFF(NUM_LOCK_INDEX); +# else + SET_LED_ON(NUM_LOCK_INDEX); +# endif + } +# endif +# if defined(CAPS_LOCK_INDEX) + if (host_keyboard_led_state().caps_lock) { +# if defined(DIM_CAPS_LOCK) + SET_LED_OFF(CAPS_LOCK_INDEX); +# else + SET_LED_ON(CAPS_LOCK_INDEX); +# endif + } +# endif +# if defined(SCROLL_LOCK_INDEX) + if (host_keyboard_led_state().scroll_lock) { + SET_LED_ON(SCROLL_LOCK_INDEX); + } +# endif +# if defined(COMPOSE_LOCK_INDEX) + if (host_keyboard_led_state().compose) { + SET_LED_ON(COMPOSE_LOCK_INDEX); + } +# endif +# if defined(KANA_LOCK_INDEX) + if (host_keyboard_led_state().kana) { + SET_LED_ON(KANA_LOCK_INDEX); + } +# endif +} + +bool LED_INDICATORS_KB(void) { + if (get_transport() & TRANSPORT_WIRELESS) { + /* Prevent backlight flash caused by key activities */ + if (battery_is_critical_low()) { + SET_ALL_LED_OFF(); + return true; + } + + if (battery_is_empty()) SET_ALL_LED_OFF(); +# if defined(LOW_BAT_IND_INDEX) + if (bat_low_ind_state && (bat_low_ind_state & 0x0F) <= LOW_BAT_LED_BLINK_TIMES) { + uint8_t idx_list[] = LOW_BAT_IND_INDEX; + for (uint8_t i = 0; i < sizeof(idx_list); i++) { + if (bat_low_ind_state & LED_ON) { + SET_LED_LOW_BAT(idx_list[i]); + } else { + SET_LED_OFF(idx_list[i]); + } + } + } +# endif + +# if (defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)) && defined(BAT_LEVEL_LED_LIST) + if (bat_level_animiation_actived()) { + bat_level_animiation_indicate(); + } +# endif + static uint8_t last_host_index = 0xFF; + + if (indicator_config.value) { + uint8_t host_index = indicator_config.value & HOST_INDEX_MASK; + + if (indicator_config.highlight) { + SET_ALL_LED_OFF(); + } else if (last_host_index != host_index) { + if (indicator_config.value & HOST_P2P4G) + SET_LED_OFF(p2p4g_host_led_matrix_list[host_index - 1]); + else + SET_LED_OFF(bt_host_led_matrix_list[host_index - 1]); + last_host_index = host_index; + } + + if (indicator_config.value & LED_ON) { +# ifdef P2P4G_HOST_LED_MATRIX_LIST + if (indicator_config.value & HOST_P2P4G) + SET_LED_P24G(p2p4g_host_led_matrix_list[host_index - 1]); + else +# endif + SET_LED_BT(bt_host_led_matrix_list[host_index - 1]); + + } else { +# ifdef P2P4G_HOST_LED_MATRIX_LIST + if (indicator_config.value & HOST_P2P4G) + SET_LED_OFF(p2p4g_host_led_matrix_list[host_index - 1]); + else +# endif + SET_LED_OFF(bt_host_led_matrix_list[host_index - 1]); + } + } else + os_state_indicate(); + + } else + os_state_indicate(); + + if (!LED_INDICATORS_USER()) return true; + + return true; +} + +bool led_update_kb(led_t led_state) { + bool res = led_update_user(led_state); + if (res) { + led_update_ports(led_state); + + if (!LED_DRIVER_IS_ENABLED() || (LED_DRIVER_IS_ENABLED() && LED_DRIVER_TIMEOUTED())) { +# if defined(LED_MATRIX_DRIVER_SHUTDOWN_ENABLE) || defined(RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE) + LED_DRIVER_EXIT_SHUTDOWN(); +# endif + SET_ALL_LED_OFF(); + os_state_indicate(); + LED_DRIVER.flush(); +# if defined(LED_MATRIX_DRIVER_SHUTDOWN_ENABLE) || defined(RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE) + if (LED_DRIVER_ALLOW_SHUTDOWN()) LED_DRIVER_SHUTDOWN(); +# endif + } + } + + return res; +} + +void LED_NONE_INDICATORS_KB(void) { +# if defined(RGB_DISABLE_WHEN_USB_SUSPENDED) || defined(LED_DISABLE_WHEN_USB_SUSPENDED) + if (get_transport() == TRANSPORT_USB && USB_DRIVER.state == USB_SUSPENDED) return; +# endif + + os_state_indicate(); +} + +# if defined(LED_MATRIX_DRIVER_SHUTDOWN_ENABLE) || defined(RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE) +bool LED_DRIVER_ALLOW_SHUTDOWN(void) { +# if defined(NUM_LOCK_INDEX) + if (host_keyboard_led_state().num_lock) return false; +# endif +# if defined(CAPS_LOCK_INDEX) && !defined(DIM_CAPS_LOCK) + if (host_keyboard_led_state().caps_lock) return false; +# endif +# if defined(SCROLL_LOCK_INDEX) + if (host_keyboard_led_state().scroll_lock) return false; +# endif +# if defined(COMPOSE_LOCK_INDEX) + if (host_keyboard_led_state().compose) return false; +# endif +# if defined(KANA_LOCK_INDEX) + if (host_keyboard_led_state().kana) return false; +# endif + return true; +} +# endif + +#endif diff --git a/keyboards/keychron/common/wireless/indicator.h b/keyboards/keychron/common/wireless/indicator.h new file mode 100644 index 0000000000..6bbae137c4 --- /dev/null +++ b/keyboards/keychron/common/wireless/indicator.h @@ -0,0 +1,114 @@ +/* Copyright 2023~2025 @ lokher (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 . + */ + +#pragma once + +#include "config.h" +#include "wireless.h" + +/* Indication of pairing */ +#ifndef INDICATOR_CONFIG_PARING +# define INDICATOR_CONFIG_PARING {INDICATOR_BLINK, 1000, 1000, 0, true, 0}; +#endif + +/* Indication on Connected */ +#ifndef INDICATOR_CONFIG_CONNECTD +# define INDICATOR_CONFIG_CONNECTD {INDICATOR_ON_OFF, 2000, 250, 2000, true, 0}; +#endif + +/* Reconnecting indication */ +#ifndef INDICATOR_CONFIG_RECONNECTING +# define INDICATOR_CONFIG_RECONNECTING {INDICATOR_BLINK, 100, 100, 600, true, 0}; +#endif + +/* Disconnected indication */ +#ifndef INDICATOR_CONFIG_DISCONNECTED +# define INDICATOR_CONFIG_DISCONNECTED {INDICATOR_NONE, 100, 100, 600, false, 0}; +#endif + +/* Uint: Second */ +#ifndef DISCONNECTED_BACKLIGHT_DISABLE_TIMEOUT +# define DISCONNECTED_BACKLIGHT_DISABLE_TIMEOUT 40 +#endif + +/* Uint: Second, the timer restarts on key activities. */ +#ifndef CONNECTED_BACKLIGHT_DISABLE_TIMEOUT +# define CONNECTED_BACKLIGHT_DISABLE_TIMEOUT 600 +#endif + +/* Uint: ms */ +#ifndef LOW_BAT_LED_BLINK_PERIOD +# define LOW_BAT_LED_BLINK_PERIOD 1000 +#endif + +#ifndef LOW_BAT_LED_BLINK_TIMES +# define LOW_BAT_LED_BLINK_TIMES 5 +#endif + +#ifndef LOW_BAT_LED_TRIG_INTERVAL +# define LOW_BAT_LED_TRIG_INTERVAL 30000 +#endif + +#if ((defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)) && defined(LOW_BAT_IND_INDEX)) +# define SPACE_KEY_LOW_BAT_IND +#endif + +#if BT_HOST_MAX_COUNT > 6 +# pragma error("HOST_COUNT max value is 6") +#endif + +#ifndef P24G_HOST_DEVICES_COUNT +# define P24G_HOST_DEVICES_COUNT 1 +#endif + +typedef enum { + INDICATOR_NONE, + INDICATOR_OFF, + INDICATOR_ON, + INDICATOR_ON_OFF, + INDICATOR_BLINK, + INDICATOR_LAST, +} indicator_type_t; + +typedef struct { + indicator_type_t type; + uint32_t on_time; + uint32_t off_time; + uint32_t duration; + bool highlight; + uint8_t value; + uint32_t elapsed; +} indicator_config_t; + +typedef struct { + uint8_t value; + bool saved; +} backlight_state_t; + +void indicator_init(void); +void indicator_set(wt_state_t state, uint8_t host_index); +void indicator_set_backlit_timeout(uint32_t time); +void indicator_reset_backlit_time(void); +bool indicator_hook_key(uint16_t keycode); +void indicator_enable(void); +void indicator_disable(void); +void indicator_stop(void); +void indicator_eeconfig_reload(void); +bool indicator_is_enabled(void); +bool indicator_is_running(void); +void indicator_battery_low_enable(bool enable); + +void indicator_task(void); diff --git a/keyboards/keychron/common/wireless/keychron_wireless_common.c b/keyboards/keychron/common/wireless/keychron_wireless_common.c new file mode 100644 index 0000000000..2fa6273fa6 --- /dev/null +++ b/keyboards/keychron/common/wireless/keychron_wireless_common.c @@ -0,0 +1,156 @@ +/* Copyright 2022~2025 @ 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 . + */ + +#include QMK_KEYBOARD_H +#ifdef LK_WIRELESS_ENABLE +# include "lkbt51.h" +# include "wireless.h" +# include "indicator.h" +# include "transport.h" +# include "battery.h" +# include "bat_level_animation.h" +# include "lpm.h" +# include "keychron_wireless_common.h" +# include "keychron_task.h" +#endif +#include "keychron_common.h" + +bool firstDisconnect = true; + +static uint32_t pairing_key_timer; +static uint8_t host_idx = 0; +extern uint32_t connected_idle_time; + +bool process_record_keychron_wireless(uint16_t keycode, keyrecord_t *record) { + static uint8_t host_idx; + + switch (keycode) { + case BT_HST1 ... BT_HST3: + if (get_transport() == TRANSPORT_BLUETOOTH) { + if (record->event.pressed) { + host_idx = keycode - BT_HST1 + 1; + + pairing_key_timer = timer_read32(); + wireless_connect_ex(host_idx, 0); + } else { + host_idx = 0; + pairing_key_timer = 0; + } + } + break; + case P2P4G: + if (get_transport() == TRANSPORT_P2P4) { + if (record->event.pressed) { + host_idx = P24G_INDEX; + + pairing_key_timer = timer_read32(); + } else { + host_idx = 0; + pairing_key_timer = 0; + } + } + break; +#if (defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE)) && defined(BAT_LEVEL_LED_LIST) + case BAT_LVL: + if ((get_transport() & TRANSPORT_WIRELESS) && !usb_power_connected()) { + bat_level_animiation_start(battery_get_percentage()); + } + break; +#endif + + default: + break; + } + + return true; +} + +void lkbt51_param_init(void) { + /* Set bluetooth device name */ + lkbt51_set_local_name(PRODUCT); + wait_ms(3); + // clang-format off + /* Set bluetooth parameters */ + module_param_t param = {.event_mode = 0x02, + .connected_idle_timeout = connected_idle_time, + .pairing_timeout = 180, + .pairing_mode = 0, + .reconnect_timeout = 5, + .report_rate = 90, + .vendor_id_source = 1, + .verndor_id = 0x3434, // Must be 0x3434 + .product_id = PRODUCT_ID}; + // clang-format on + lkbt51_set_param(¶m); +} + +void wireless_enter_reset_kb(uint8_t reason) { + lkbt51_param_init(); +} + +void wireless_enter_disconnected_kb(uint8_t host_idx, uint8_t reason) { + /* CKBT51 bluetooth module boot time is slower, it enters disconnected after boot, + so we place initialization here. */ + if (firstDisconnect && timer_read32() < 1000) { + lkbt51_param_init(); + if (get_transport() == TRANSPORT_BLUETOOTH) wireless_connect(); + firstDisconnect = false; + } +} + +void keychron_wireless_common_task(void) { + if (pairing_key_timer) { + if (timer_elapsed32(pairing_key_timer) > 2000) { + pairing_key_timer = 0; + wireless_pairing_ex(host_idx, NULL); + } + } +} + +void wireless_pre_task(void) { + static uint8_t mode = 0; + static uint32_t time = 0; + + if (time == 0) { + if ((readPin(BT_MODE_SELECT_PIN) << 1 | readPin(P2P4_MODE_SELECT_PIN)) != mode) { + mode = readPin(BT_MODE_SELECT_PIN) << 1 | readPin(P2P4_MODE_SELECT_PIN); + time = timer_read32(); + } + } + + if ((time && timer_elapsed32(time) > 100) || get_transport() == TRANSPORT_NONE) { + if ((readPin(BT_MODE_SELECT_PIN) << 1 | readPin(P2P4_MODE_SELECT_PIN)) == mode) { + time = 0; + + switch (mode) { + case 0x01: + set_transport(TRANSPORT_BLUETOOTH); + break; + case 0x02: + set_transport(TRANSPORT_P2P4); + break; + case 0x03: + set_transport(TRANSPORT_USB); + break; + default: + break; + } + } else { + mode = readPin(BT_MODE_SELECT_PIN) << 1 | readPin(P2P4_MODE_SELECT_PIN); + time = timer_read32(); + } + } +} diff --git a/keyboards/keychron/common/wireless/keychron_wireless_common.h b/keyboards/keychron/common/wireless/keychron_wireless_common.h new file mode 100644 index 0000000000..eedfff8740 --- /dev/null +++ b/keyboards/keychron/common/wireless/keychron_wireless_common.h @@ -0,0 +1,26 @@ +/* Copyright 2023 @ 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 . + */ + +#include "stdint.h" +#ifdef VIA_ENABLE +# include "via.h" +#endif +#include "quantum_keycodes.h" + +void lkbt51_param_init(void); + +bool process_record_keychron_wireless(uint16_t keycode, keyrecord_t *record); +void keychron_wireless_common_task(void); diff --git a/keyboards/keychron/common/wireless/lkbt51.c b/keyboards/keychron/common/wireless/lkbt51.c new file mode 100644 index 0000000000..df380102b3 --- /dev/null +++ b/keyboards/keychron/common/wireless/lkbt51.c @@ -0,0 +1,875 @@ +/* Copyright 2023 @ 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 . + */ + +#include "quantum.h" +#include "lkbt51.h" +#include "wireless.h" +#include "wireless_event_type.h" +#include "battery.h" +#include "raw_hid.h" +#include "report_buffer.h" +#include "factory_test.h" + +extern void factory_test_send(uint8_t* payload, uint8_t length); + +#ifndef RAW_EPSIZE +# define RAW_EPSIZE 32 +#endif + +#ifndef SPI_SCK_PIN +# define SPI_SCK_PIN A5 +#endif +#ifndef SPI_MISO_PIN +# define SPI_MISO_PIN A6 +#endif +#ifndef SPI_MOSI_PIN +# define SPI_MOSI_PIN A7 +#endif + +#ifndef SPI_CLK_PAL_MODE +# define SPI_CLK_PAL_MODE 5 +#endif +#ifndef SPI_MISO_PAL_MODE +# define SPI_MISO_PAL_MODE 5 +#endif +#ifndef SPI_MOSI_PAL_MODE +# define SPI_MOSI_PAL_MODE 5 +#endif + +#ifndef LKBT51_INT_INPUT_PIN +# error "LKBT51_INT_INPUT_PIN is not defined" +#endif + +#ifndef LKBT51_TX_RETRY_COUNT +# define LKBT51_TX_RETRY_COUNT 3 +#endif + +// clang-format off +enum { + /* HID Report */ + LKBT51_CMD_SEND_KB = 0x11, + LKBT51_CMD_SEND_KB_NKRO = 0x12, + LKBT51_CMD_SEND_CONSUMER = 0x13, + LKBT51_CMD_SEND_SYSTEM = 0x14, + LKBT51_CMD_SEND_FN = 0x15, // Not used currently + LKBT51_CMD_SEND_MOUSE = 0x16, + LKBT51_CMD_SEND_BOOT_KB = 0x17, + /* Bluetooth connections */ + LKBT51_CMD_PAIRING = 0x21, + LKBT51_CMD_CONNECT = 0x22, + LKBT51_CMD_DISCONNECT = 0x23, + LKBT51_CMD_SWITCH_HOST = 0x24, + LKBT51_CMD_READ_STATE_REG = 0x25, + /* Battery */ + LKBT51_CMD_BATTERY_MANAGE = 0x31, + LKBT51_CMD_UPDATE_BAT_LVL = 0x32, + LKBT51_CMD_UPDATE_BAT_STATE = 0x33, + /* Set/get parameters */ + LKBT51_CMD_GET_MODULE_INFO = 0x40, + LKBT51_CMD_SET_CONFIG = 0x41, + LKBT51_CMD_GET_CONFIG = 0x42, + LKBT51_CMD_SET_BDA = 0x43, + LKBT51_CMD_GET_BDA = 0x44, + LKBT51_CMD_SET_NAME = 0x45, + LKBT51_CMD_GET_NAME = 0x46, + LKBT51_CMD_WRTE_CSTM_DATA = 0x49, + /* DFU */ + LKBT51_CMD_GET_DFU_VER = 0x60, + LKBT51_CMD_HAND_SHAKE_TOKEN = 0x61, + LKBT51_CMD_START_DFU = 0x62, + LKBT51_CMD_SEND_FW_DATA = 0x63, + LKBT51_CMD_VERIFY_CRC32 = 0x64, + LKBT51_CMD_SWITCH_FW = 0x65, + /* Factory test */ + LKBT51_CMD_FACTORY_RESET = 0x71, + LKBT51_CMD_IO_TEST = 0x72, + LKBT51_CMD_RADIO_TEST = 0x73, + /* Event */ + LKBT51_EVT_LKBT51_CMD_RECEIVED = 0xA1, + LKBT51_EVT_OTA_RSP = 0xA3, + LKBT51_CONNECTION_EVT_ACK = 0xA4, +}; + +enum { + LKBT51_EVT_ACK = 0xA1, + LKBT51_EVT_QUERY_RSP = 0xA2, + LKBT51_EVT_RESET = 0xB0, + LKBT51_EVT_LE_CONNECTION = 0xB1, + LKBT51_EVT_HOST_TYPE = 0xB2, + LKBT51_EVT_CONNECTION = 0xB3, + LKBT51_EVT_HID_EVENT = 0xB4, + LKBT51_EVT_BATTERY = 0xB5, +}; + +enum { + LKBT51_CONNECTED = 0x20, + LKBT51_DISCOVERABLE = 0x21, + LKBT51_RECONNECTING = 0x22, + LKBT51_DISCONNECTED = 0x23, + LKBT51_PINCODE_ENTRY = 0x24, + LKBT51_EXIT_PINCODE_ENTRY = 0x25, + LKBT51_SLEEP = 0x26 +}; + +enum { + ACK_SUCCESS = 0x00, + ACK_CHECKSUM_ERROR, + ACK_FIFO_HALF_WARNING, + ACK_FIFO_FULL_ERROR, +}; + +enum{ + LK_EVT_MSK_CONNECTION = 0x01 << 0, + LK_EVT_MSK_LED = 0x01 << 1, + LK_EVT_MSK_BATT = 0x01 << 2, + LK_EVT_MSK_RESET = 0x01 << 3, + LK_EVT_MSK_RPT_INTERVAL = 0x01 << 4, + LK_EVT_MSK_MD = 0x01 << 7, +}; + +// clang-format on + +static uint8_t payload[PACKET_MAX_LEN]; +static uint8_t reg_offset = 0xFF; +static uint8_t expect_len = 22; +static uint16_t connection_interval = 1; +static uint32_t wake_time; +static uint32_t factory_reset = 0; + +// clang-format off +wt_func_t wireless_transport = { + lkbt51_init, + lkbt51_connect, + lkbt51_become_discoverable, + lkbt51_disconnect, + lkbt51_send_keyboard, + lkbt51_send_nkro, + lkbt51_send_consumer, + lkbt51_send_system, + lkbt51_send_mouse, + lkbt51_update_bat_lvl, + lkbt51_task +}; +// clang-format on + +/* Init SPI */ +const SPIConfig spicfg = { + .circular = false, + .slave = false, + .data_cb = NULL, + .error_cb = NULL, + .ssport = PAL_PORT(BLUETOOTH_INT_OUTPUT_PIN), + .sspad = PAL_PAD(BLUETOOTH_INT_OUTPUT_PIN), + .cr1 = SPI_CR1_MSTR | SPI_CR1_BR_1 | SPI_CR1_BR_0, + .cr2 = 0U, +}; + +void lkbt51_init(bool wakeup_from_low_power_mode) { +#ifdef LKBT51_RESET_PIN + if (!wakeup_from_low_power_mode) { + setPinOutput(LKBT51_RESET_PIN); + writePinLow(LKBT51_RESET_PIN); + wait_ms(1); + writePinHigh(LKBT51_RESET_PIN); + } +#endif + +#if (HAL_USE_SPI == TRUE) + if (WT_DRIVER.state == SPI_UNINIT) { + setPinOutput(SPI_SCK_PIN); + writePinHigh(SPI_SCK_PIN); + + palSetLineMode(SPI_SCK_PIN, PAL_MODE_ALTERNATE(SPI_CLK_PAL_MODE)); + palSetLineMode(SPI_MISO_PIN, PAL_MODE_ALTERNATE(SPI_MISO_PAL_MODE)); + palSetLineMode(SPI_MOSI_PIN, PAL_MODE_ALTERNATE(SPI_MOSI_PAL_MODE)); + + if (wakeup_from_low_power_mode) { + spiInit(); + return; + } + + spiInit(); + } +#endif + + setPinOutput(BLUETOOTH_INT_OUTPUT_PIN); + writePinHigh(BLUETOOTH_INT_OUTPUT_PIN); + + setPinInputHigh(LKBT51_INT_INPUT_PIN); +} + +static inline void lkbt51_wake(void) { + if (timer_elapsed32(wake_time) > 3000) { + wake_time = timer_read32(); + + palWriteLine(BLUETOOTH_INT_OUTPUT_PIN, 0); + wait_ms(10); + palWriteLine(BLUETOOTH_INT_OUTPUT_PIN, 1); + wait_ms(300); + } +} + +void lkbt51_send_protocol_ver(uint16_t ver) { + uint8_t pkt[PACKET_MAX_LEN] = {0}; + memset(pkt, 0, PACKET_MAX_LEN); + + uint8_t i = 0; + + pkt[i++] = 0x84; + pkt[i++] = 0x7e; + pkt[i++] = 0x00; + pkt[i++] = 0x00; + pkt[i++] = 0xAA; + pkt[i++] = 0x54; + pkt[i++] = ver & 0xFF; + pkt[i++] = (ver >> 8) & 0xFF; + pkt[i++] = (uint8_t)(~0x54); + pkt[i++] = (uint8_t)(~0xAA); + +#if HAL_USE_SPI + expect_len = 10; + spiStart(&WT_DRIVER, &spicfg); + spiSelect(&WT_DRIVER); + spiSend(&WT_DRIVER, i, pkt); + spiUnselectI(&WT_DRIVER); + spiStop(&WT_DRIVER); +#endif +} + +void lkbt51_send_cmd(uint8_t* payload, uint8_t len, bool ack_enable, bool retry) { + static uint8_t sn = 0; + uint8_t i; + uint8_t pkt[PACKET_MAX_LEN] = {0}; + memset(pkt, 0, PACKET_MAX_LEN); + + if (!retry) ++sn; + if (sn == 0) ++sn; + + uint16_t checksum = 0; + for (i = 0; i < len; i++) + checksum += payload[i]; + + i = 0; + pkt[i++] = 0x84; + pkt[i++] = 0x7e; + pkt[i++] = 0x00; + pkt[i++] = 0x00; + pkt[i++] = 0xAA; + pkt[i++] = ack_enable ? 0x56 : 0x55; + pkt[i++] = len + 2; + pkt[i++] = ~(len + 2) & 0xFF; + pkt[i++] = sn; + + memcpy(pkt + i, payload, len); + i += len; + pkt[i++] = checksum & 0xFF; + pkt[i++] = (checksum >> 8) & 0xFF; +#if HAL_USE_SPI + if ((payload[0] & 0xF0) == 0x60) + expect_len = 64; + else + expect_len = 64; + + spiStart(&WT_DRIVER, &spicfg); + spiSelect(&WT_DRIVER); + spiSend(&WT_DRIVER, i, pkt); + spiUnselectI(&WT_DRIVER); + spiStop(&WT_DRIVER); +#endif +} + +void lkbt51_read(uint8_t* payload, uint8_t len) { + uint8_t i; + uint8_t pkt[PACKET_MAX_LEN] = {0}; + memset(pkt, 0, PACKET_MAX_LEN); + + i = 0; + pkt[i++] = 0x84; + pkt[i++] = 0x7f; + pkt[i++] = 0x00; + pkt[i++] = 0x80; + + i += len; + +#if HAL_USE_SPI + spiStart(&WT_DRIVER, &spicfg); + spiSelect(&WT_DRIVER); + spiExchange(&WT_DRIVER, i, pkt, payload); + spiUnselect(&WT_DRIVER); + spiStop(&WT_DRIVER); +#endif +} + +void lkbt51_send_keyboard(uint8_t* report) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = LKBT51_CMD_SEND_KB; + memcpy(payload + i, report, 8); + i += 8; + + lkbt51_send_cmd(payload, i, true, false); +} + +void lkbt51_send_nkro(uint8_t* report) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = LKBT51_CMD_SEND_KB_NKRO; + memcpy(payload + i, report, 20); // NKRO report lenght is limited to 20 bytes + i += 20; + + lkbt51_send_cmd(payload, i, true, false); +} + +void lkbt51_send_consumer(uint16_t report) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = LKBT51_CMD_SEND_CONSUMER; + payload[i++] = report & 0xFF; + payload[i++] = ((report) >> 8) & 0xFF; + i += 4; // QMK doesn't send multiple consumer reports, just skip 2nd and 3rd consumer reports + + lkbt51_send_cmd(payload, i, true, false); +} + +void lkbt51_send_system(uint16_t report) { + uint8_t hid_usage = report & 0xFF; + + if (hid_usage < 0x81 || hid_usage > 0x83) return; + + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = LKBT51_CMD_SEND_SYSTEM; + payload[i++] = 0x01 << (hid_usage - 0x81); + + lkbt51_send_cmd(payload, i, true, false); +} + +void lkbt51_send_mouse(uint8_t* report) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = LKBT51_CMD_SEND_MOUSE; // Cmd type + payload[i++] = report[1]; // Button + payload[i++] = report[2]; // X + payload[i++] = (report[2] & 0x80) ? 0xff : 0x00; // ckbt51 use 16bit report, set high byte + payload[i++] = report[3]; // Y + payload[i++] = (report[3] & 0x80) ? 0xff : 0x00; // ckbt51 use 16bit report, set high byte + payload[i++] = report[4]; // V wheel + payload[i++] = report[5]; // H wheel + + lkbt51_send_cmd(payload, i, false, false); +} + +/* Send ack to connection event, wireless module will retry 2 times if no ack received */ +void lkbt51_send_conn_evt_ack(void) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = LKBT51_CONNECTION_EVT_ACK; + + lkbt51_send_cmd(payload, i, false, false); +} + +void lkbt51_become_discoverable(uint8_t host_idx, void* param) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + pairing_param_t default_pairing_param = {0, 0, PAIRING_MODE_LESC_OR_SSP, BT_MODE_CLASSIC, 0, NULL}; + + if (param == NULL) { + param = &default_pairing_param; + } + pairing_param_t* p = (pairing_param_t*)param; + + payload[i++] = LKBT51_CMD_PAIRING; // Cmd type + payload[i++] = host_idx; // Host Index + payload[i++] = p->timeout & 0xFF; // Timeout + payload[i++] = (p->timeout >> 8) & 0xFF; + payload[i++] = p->pairingMode; + payload[i++] = p->BRorLE; // BR/LE + payload[i++] = p->txPower; // LE TX POWER + if (p->leName) { + memcpy(&payload[i], p->leName, strlen(p->leName)); + i += strlen(p->leName); + } + + lkbt51_wake(); + lkbt51_send_cmd(payload, i, true, false); +} + +/* Timeout : 2 ~ 255 seconds */ +void lkbt51_connect(uint8_t hostIndex, uint16_t timeout) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = LKBT51_CMD_CONNECT; + payload[i++] = hostIndex; // Host index + payload[i++] = timeout & 0xFF; // Timeout + payload[i++] = (timeout >> 8) & 0xFF; + + lkbt51_wake(); + lkbt51_send_cmd(payload, i, true, false); +} + +void lkbt51_disconnect(void) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = LKBT51_CMD_DISCONNECT; + payload[i++] = 0; // Sleep mode + + if (WT_DRIVER.state != SPI_READY) + spiStart(&WT_DRIVER, &spicfg); + spiSelect(&SPID1); + wait_ms(30); + // spiUnselect(&SPID1); + wait_ms(70); + + lkbt51_send_cmd(payload, i, true, false); +} + +void lkbt51_switch_host(uint8_t hostIndex) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = LKBT51_CMD_SWITCH_HOST; + payload[i++] = hostIndex; + + lkbt51_send_cmd(payload, i, true, false); +} + +void lkbt51_read_state_reg(uint8_t reg, uint8_t len) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = LKBT51_CMD_READ_STATE_REG; + payload[i++] = reg_offset = reg; + payload[i++] = len; + + // TODO + lkbt51_send_cmd(payload, i, false, false); +} + +void lkbt51_update_bat_lvl(uint8_t bat_lvl) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = LKBT51_CMD_UPDATE_BAT_LVL; + payload[i++] = bat_lvl; + lkbt51_send_cmd(payload, i, false, false); +} + +void lkbt51_update_bat_state(uint8_t bat_state) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = LKBT51_CMD_UPDATE_BAT_STATE; + payload[i++] = bat_state; + lkbt51_send_cmd(payload, i, false, false); +} + +void lkbt51_get_info(module_info_t* info) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = LKBT51_CMD_GET_MODULE_INFO; + lkbt51_send_cmd(payload, i, false, false); +} + +void lkbt51_set_param(module_param_t* param) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = LKBT51_CMD_SET_CONFIG; + memcpy(payload + i, param, sizeof(module_param_t)); + i += sizeof(module_param_t); + + lkbt51_send_cmd(payload, i, false, false); +} + +void lkbt51_get_param(module_param_t* param) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = LKBT51_CMD_GET_CONFIG; + + lkbt51_send_cmd(payload, i, false, false); +} + +void lkbt51_set_local_name(const char* name) { + uint8_t i = 0; + uint8_t len = strlen(name); + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = LKBT51_CMD_SET_NAME; + memcpy(payload + i, name, len); + i += len; + lkbt51_send_cmd(payload, i, false, false); +} + +void lkbt51_get_local_name(void) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = LKBT51_CMD_GET_NAME; + + lkbt51_send_cmd(payload, i, false, false); +} + +void lkbt51_factory_reset(uint8_t p2p4g_clr_msk) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + + payload[i++] = LKBT51_CMD_FACTORY_RESET; + payload[i++] = p2p4g_clr_msk; + + lkbt51_wake(); + lkbt51_send_cmd(payload, i, false, false); + factory_reset = timer_read32(); +} + +void lkbt51_int_pin_test(bool enable) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + payload[i++] = LKBT51_CMD_IO_TEST; + payload[i++] = enable; + + lkbt51_send_cmd(payload, i, false, false); +} + +void lkbt51_radio_test(uint8_t channel) { + uint8_t i = 0; + memset(payload, 0, PACKET_MAX_LEN); + payload[i++] = LKBT51_CMD_RADIO_TEST; + payload[i++] = channel; + payload[i++] = 0; + + lkbt51_send_cmd(payload, i, false, false); +} + +bool lkbt51_read_customize_data(uint8_t* data, uint8_t len) { + uint8_t i; + uint8_t buf[20] = {0}; + + i = 0; + buf[i++] = 0x84; + buf[i++] = 0x7a; + buf[i++] = 0x00; + buf[i++] = 0x80; + +#if HAL_USE_SPI + spiStart(&WT_DRIVER, &spicfg); + spiSelect(&WT_DRIVER); + spiExchange(&WT_DRIVER, 20, buf, payload); + uint16_t state = buf[5] | (buf[6] << 8); + if (state == 0x9527) spiExchange(&WT_DRIVER, len, data, payload); + spiUnselect(&WT_DRIVER); + spiStop(&WT_DRIVER); +#endif + + return true; +} + +void lkbt51_write_customize_data(uint8_t* data, uint8_t len) { + uint8_t i; + uint8_t pkt[PACKET_MAX_LEN] = {0}; + + i = 0; + pkt[i++] = 0x84; + pkt[i++] = 0x7a; + pkt[i++] = 0x00; + pkt[i++] = 0x00; + +#if HAL_USE_SPI + spiStart(&WT_DRIVER, &spicfg); + spiSelect(&WT_DRIVER); + spiSend(&WT_DRIVER, i, pkt); + spiSend(&WT_DRIVER, len, data); + spiUnselectI(&WT_DRIVER); + spiStop(&WT_DRIVER); +#endif + + i = 0; + memset(payload, 0, PACKET_MAX_LEN); + payload[i++] = LKBT51_CMD_WRTE_CSTM_DATA; + + lkbt51_send_cmd(payload, i, false, false); +} +#ifdef RAW_ENABLE +void lkbt51_dfu_tx(uint8_t rsp, uint8_t* data, uint8_t len, uint8_t sn) { + uint16_t checksum = 0; + uint8_t buf[RAW_EPSIZE] = {0}; + uint8_t i = 0; + + buf[i++] = 0x03; + buf[i++] = 0xAA; + buf[i++] = 0x57; + buf[i++] = len; + buf[i++] = ~len; + buf[i++] = sn; + buf[i++] = rsp; + memcpy(&buf[i], data, len); + i += len; + + for (uint8_t k = 0; k < i; k++) + checksum += buf[i]; + + raw_hid_send(buf, RAW_EPSIZE); + + if (len > 25) { + i = 0; + memset(buf, 0, RAW_EPSIZE); + buf[i++] = 0x03; + memcpy(&buf[i], data + 25, len - 25); + i = i + len - 25; + raw_hid_send(buf, RAW_EPSIZE); + } +} +#endif +void lkbt51_dfu_rx(uint8_t* data, uint8_t length) { + if (data[0] == 0xAA && (data[1] == 0x55 || data[1] == 0x56) && data[2] == (~data[3] & 0xFF)) { + uint16_t checksum = 0; + uint8_t payload_len = data[2]; + + /* Check payload_len validity */ + if (payload_len > RAW_EPSIZE - PACKECT_HEADER_LEN) return; + + uint8_t* payload = &data[PACKECT_HEADER_LEN]; + + for (uint8_t i = 0; i < payload_len - 2; i++) { + checksum += payload[i]; + } + + /* Verify checksum */ + if ((checksum & 0xFF) != payload[payload_len - 2] || checksum >> 8 != payload[payload_len - 1]) return; + static uint8_t sn = 0; + + bool retry = true; + if (sn != data[4]) { + sn = data[4]; + retry = false; + } + + if ((payload[0] & 0xF0) == 0x60) { + lkbt51_wake(); + lkbt51_send_cmd(payload, payload_len - 2, data[1] == 0x56, retry); + } + } +} + +static void ack_handler(uint8_t* data, uint8_t len) { + switch (data[1]) { + case LKBT51_CMD_SEND_KB: + case LKBT51_CMD_SEND_KB_NKRO: + case LKBT51_CMD_SEND_CONSUMER: + case LKBT51_CMD_SEND_SYSTEM: + case LKBT51_CMD_SEND_MOUSE: + switch (data[2]) { + case ACK_SUCCESS: + report_buffer_set_retry(0); + report_buffer_set_inverval(connection_interval); + break; + case ACK_FIFO_HALF_WARNING: + report_buffer_set_retry(0); + report_buffer_set_inverval(connection_interval + 5); + break; + case ACK_FIFO_FULL_ERROR: + report_buffer_set_inverval(connection_interval + 10); + break; + } + break; + default: + break; + } +} + +static void query_rsp_handler(uint8_t* data, uint8_t len) { + if (data[2]) return; + + switch (data[1]) { + case LKBT51_CMD_IO_TEST: + factory_test_send(data, len); + break; + default: + break; + } +} + +static void lkbt51_event_handler(uint8_t evt_type, uint8_t* data, uint8_t len, uint8_t sn) { + wireless_event_t event = {0}; + + switch (evt_type) { + case LKBT51_EVT_ACK: + ack_handler(data, len); + break; + case LKBT51_EVT_RESET: + kc_printf("LKBT51_EVT_RESET\n"); + event.evt_type = EVT_RESET; + event.params.reason = data[0]; + break; + case LKBT51_EVT_LE_CONNECTION: + kc_printf("LKBT51_EVT_LE_CONNECTION\n"); + break; + case LKBT51_EVT_HOST_TYPE: + kc_printf("LKBT51_EVT_HOST_TYPE\n"); + break; + case LKBT51_EVT_HID_EVENT: + kc_printf("LKBT51_EVT_HID_EVENT\n"); + event.evt_type = EVT_HID_INDICATOR; + event.params.led = data[0]; + break; + case LKBT51_EVT_QUERY_RSP: + kc_printf("LKBT51_EVT_QUERY_RSP\n\r"); + query_rsp_handler(data, len); + break; + case LKBT51_EVT_OTA_RSP: +#ifdef RAW_ENABLE + kc_printf("LKBT51_EVT_OTA_RSP\n"); + lkbt51_dfu_tx(LKBT51_EVT_OTA_RSP, data, len, sn); +#endif + break; + default: + kc_printf("Unknown event!!!\n"); + break; + } + + if (event.evt_type) wireless_event_enqueue(event); +} + +void lkbt51_task(void) { +#define VALID_DATA_START_INDEX 4 +#define BUFFER_SIZE 64 + + static bool wait_for_new_pkt = true; + static uint8_t len = 0xff; + static uint8_t sn = 0; + + if (readPin(LKBT51_INT_INPUT_PIN) == 0) { + uint8_t buf[BUFFER_SIZE] = {0}; + lkbt51_read(buf, expect_len); + + uint8_t* pbuf = buf + VALID_DATA_START_INDEX; + + if (pbuf[0] == 0xAA && pbuf[1] == 0x54 && pbuf[4] == (uint8_t)(~0x54) && pbuf[5] == (uint8_t)(~0xAA)) { + uint16_t protol_ver = pbuf[3] << 8 | pbuf[2]; + kc_printf("protol_ver: %x\n\r", protol_ver); + (void)protol_ver; + } else if (pbuf[0] == 0xAA) { + wireless_event_t event = {0}; + uint8_t evt_mask = pbuf[1]; + + if (evt_mask & LK_EVT_MSK_RESET) { + event.evt_type = EVT_RESET; + event.params.reason = pbuf[2]; + wireless_event_enqueue(event); + } + + if (evt_mask & LK_EVT_MSK_CONNECTION) { + lkbt51_send_conn_evt_ack(); + switch (pbuf[2]) { + case LKBT51_CONNECTED: + event.evt_type = EVT_CONNECTED; + break; + case LKBT51_DISCOVERABLE: + event.evt_type = EVT_DISCOVERABLE; + break; + case LKBT51_RECONNECTING: + event.evt_type = EVT_RECONNECTING; + break; + case LKBT51_DISCONNECTED: + event.evt_type = EVT_DISCONNECTED; + if (factory_reset && timer_elapsed32(factory_reset) < 3000) { + factory_reset = 0; + event.data = 1; + } + break; + case LKBT51_PINCODE_ENTRY: + event.evt_type = EVT_BT_PINCODE_ENTRY; + break; + case LKBT51_EXIT_PINCODE_ENTRY: + event.evt_type = EVT_EXIT_BT_PINCODE_ENTRY; + break; + case LKBT51_SLEEP: + event.evt_type = EVT_SLEEP; + break; + } + event.params.hostIndex = pbuf[3]; + + wireless_event_enqueue(event); + } + + if (evt_mask & LK_EVT_MSK_LED) { + memset(&event, 0, sizeof(event)); + event.evt_type = EVT_HID_INDICATOR; + event.params.led = pbuf[4]; + wireless_event_enqueue(event); + } + + if (evt_mask & LK_EVT_MSK_RPT_INTERVAL) { + uint32_t interval; + if (pbuf[8] & 0x80) { + interval = (pbuf[8] & 0x7F) * 1250; + } else { + interval = (pbuf[8] & 0x7F) * 125; + } + + connection_interval = interval / 1000; + if (connection_interval > 7) connection_interval /= 3; + + memset(&event, 0, sizeof(event)); + event.evt_type = EVT_CONECTION_INTERVAL; + event.params.interval = connection_interval; + wireless_event_enqueue(event); + } + + if (evt_mask & LK_EVT_MSK_BATT) { + battery_calculate_voltage(true, pbuf[6] << 8 | pbuf[5]); + } + } + + pbuf = buf; + if (wait_for_new_pkt) { + for (uint8_t i = 10; i < BUFFER_SIZE - 5; i++) { + if (buf[i] == 0xAA && buf[i + 1] == 0x57 // Packet Head + && (~buf[i + 2] & 0xFF) == buf[i + 3]) { // Check wheather len is valid + len = buf[i + 2]; + sn = buf[i + 4]; + pbuf = &buf[i + 5]; + wait_for_new_pkt = false; + } + } + } + + if (!wait_for_new_pkt && BUFFER_SIZE - 5 >= len) { + wait_for_new_pkt = true; + + uint16_t checksum = 0; + for (int i = 0; i < len - 2; i++) { + checksum += pbuf[i]; + } + + if ((checksum & 0xff) == pbuf[len - 2] && ((checksum >> 8) & 0xff) == pbuf[len - 1]) { + lkbt51_event_handler(pbuf[0], pbuf + 1, len - 3, sn); + } else { + // TODO: Error handle + } + } + } +} diff --git a/keyboards/keychron/common/wireless/lkbt51.h b/keyboards/keychron/common/wireless/lkbt51.h new file mode 100644 index 0000000000..529a7813bd --- /dev/null +++ b/keyboards/keychron/common/wireless/lkbt51.h @@ -0,0 +1,131 @@ +/* Copyright 2023 @ 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 . + */ + +#pragma once + +#include "stdint.h" +#include "hal.h" + +#ifndef WT_DRIVER +# define WT_DRIVER SPID1 +#endif + +// Error checking +#if HAL_USE_SPI == FALSE +# error "Please enable SPI to use LKBT51" +#endif + +#if !STM32_SPI_USE_SPI1 && !STM32_SPI_USE_SPI2 && !STM32_SPI_USE_SPI3 +# error "WT driver activated but no SPI peripheral assigned" +#endif + +#define PACKECT_HEADER_LEN 5 +#define BDA_LEN 6 +#define PACKET_MAX_LEN 64 +#define P24G_INDEX 24 + +enum { + PAIRING_MODE_DEFAULT = 0x00, + PAIRING_MODE_JUST_WORK, + PAIRING_MODE_PASSKEY_ENTRY, + PAIRING_MODE_LESC_OR_SSP, + PAIRING_MODE_INVALID, +}; + +enum { + BT_MODE_DEFAUL, + BT_MODE_CLASSIC, + BT_MODE_LE, + BT_MODE_INVALID, +}; + +typedef struct { + uint8_t hostIndex; + uint16_t timeout; /* Pairing timeout, valid value range from 30 to 3600 seconds, 0 for default */ + uint8_t pairingMode; /* 0: default, 1: Just Works, 2: Passkey Entry */ + uint8_t BRorLE; /* Only available for dual mode module. Keep 0 for single mode module */ + uint8_t txPower; /* Only available for BLE module */ + const char* leName; /* Only available for BLE module */ +} pairing_param_t; + +typedef struct { + uint8_t type; + uint16_t full_votage; + uint16_t empty_voltage; + uint16_t shutdown_voltage; +} battery_param_t; + +typedef struct { + uint8_t model_name[11]; + uint8_t mode; + uint8_t bluetooth_version; + uint8_t firmware_version[11]; + uint8_t hardware_version[11]; + uint16_t cmd_set_verson; +} __attribute__((packed)) module_info_t; + +typedef struct { + uint8_t event_mode; /* Must be 0x02 */ + uint16_t connected_idle_timeout; + uint16_t pairing_timeout; /* Range: 30 ~ 3600 second, 0 for default */ + uint8_t pairing_mode; /* 0: default, 1: Just Works, 2: Passkey Entry */ + uint16_t reconnect_timeout; /* 0: default, 0xFF: Unlimited time, 2 ~ 254 seconds */ + uint8_t report_rate; /* 90 or 133 */ + uint8_t rsvd1; + uint8_t rsvd2; + uint8_t vendor_id_source; /* 0: From Bluetooth SIG, 1: From USB-IF */ + uint16_t verndor_id; /* No effect, the vendor ID is 0x3434 */ + uint16_t product_id; + /* Below parametes is only available for BLE module */ + uint16_t le_connection_interval_min; + uint16_t le_connection_interval_max; + uint16_t le_connection_interval_timeout; +} __attribute__((packed)) module_param_t; + +void lkbt51_init(bool wakeup_from_low_power_mode); +void lkbt51_send_protocol_ver(uint16_t ver); + +void lkbt51_send_cmd(uint8_t* payload, uint8_t len, bool ack_enable, bool retry); + +void lkbt51_send_keyboard(uint8_t* report); +void lkbt51_send_nkro(uint8_t* report); +void lkbt51_send_consumer(uint16_t report); +void lkbt51_send_system(uint16_t report); +void lkbt51_send_mouse(uint8_t* report); + +void lkbt51_become_discoverable(uint8_t host_idx, void* param); +void lkbt51_connect(uint8_t hostIndex, uint16_t timeout); +void lkbt51_disconnect(void); +void lkbt51_switch_host(uint8_t hostIndex); +void lkbt51_read_state_reg(uint8_t reg, uint8_t len); + +void lkbt51_update_bat_lvl(uint8_t bat_lvl); +void lkbt51_update_bat_state(uint8_t bat_state); + +void lkbt51_get_info(module_info_t* info); +void lkbt51_set_param(module_param_t* param); +void lkbt51_get_param(module_param_t* param); +void lkbt51_set_local_name(const char* name); +void lkbt51_get_local_name(void); + +void lkbt51_factory_reset(uint8_t p2p4g_clr_msk); +void lkbt51_int_pin_test(bool enable); +void lkbt51_dfu_rx(uint8_t* data, uint8_t length); +void lkbt51_radio_test(uint8_t channel); +void lkbt51_write_customize_data(uint8_t* data, uint8_t len); +bool lkbt51_read_customize_data(uint8_t* data, uint8_t len); + +void lkbt51_task(void); diff --git a/keyboards/keychron/common/wireless/lpm.c b/keyboards/keychron/common/wireless/lpm.c new file mode 100644 index 0000000000..c6f9a12c1c --- /dev/null +++ b/keyboards/keychron/common/wireless/lpm.c @@ -0,0 +1,298 @@ +/* Copyright 2022~2023 @ lokher (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 . + */ + +/****************************************************************************** + * + * Filename: lpm.c + * + * Description: Contains low power mode implementation + * + ******************************************************************************/ + +#include "quantum.h" +#if defined(PROTOCOL_CHIBIOS) +# include +#endif +#include "debounce.h" +#include "wireless.h" +#include "indicator.h" +#include "lpm.h" +#include "transport.h" +#include "battery.h" +#include "report_buffer.h" +#include "keychron_common.h" + +extern matrix_row_t matrix[MATRIX_ROWS]; +extern wt_func_t wireless_transport; + +static uint32_t lpm_timer_buffer; +static bool lpm_time_up = false; +#ifndef OPTICAL_SWITCH +static matrix_row_t empty_matrix[MATRIX_ROWS] = {0}; +#endif + +pin_t pins_row[MATRIX_ROWS] = MATRIX_ROW_PINS; +pin_t pins_col[MATRIX_COLS] = MATRIX_COL_PINS; +; + +__attribute__((weak)) void select_all_cols(void) { + for (uint8_t i = 0; i < MATRIX_COLS; i++) { + if (pins_col[i] == NO_PIN) continue; + setPinOutput(pins_col[i]); + writePinLow(pins_col[i]); + } +} + +void lpm_init(void) { +#ifdef USB_POWER_SENSE_PIN +# if (USB_POWER_CONNECTED_LEVEL == 0) + setPinInputHigh(USB_POWER_SENSE_PIN); +# else + setPinInputLow(USB_POWER_SENSE_PIN); +# endif +#endif + lpm_timer_reset(); +} + +inline void lpm_timer_reset(void) { + lpm_time_up = false; + lpm_timer_buffer = timer_read32(); +} + +void lpm_timer_stop(void) { + lpm_time_up = false; + lpm_timer_buffer = 0; +} + +static inline bool lpm_any_matrix_action(void) { +#ifdef OPTICAL_SWITCH + bool any_key = false; + for (uint8_t i = 0; i < MATRIX_ROWS; i++) + if (matrix_get_row(i) != 0) { + any_key = true; + } + return any_key; +#else + return memcmp(matrix, empty_matrix, sizeof(empty_matrix)); +#endif +} + +/* Implement of entering low power mode and wakeup varies per mcu or platform */ +__attribute__((weak)) void enter_power_mode(pm_t mode) {} + +__attribute__((weak)) bool usb_power_connected(void) { +#ifdef USB_POWER_SENSE_PIN + return readPin(USB_POWER_SENSE_PIN) == USB_POWER_CONNECTED_LEVEL; +#else + return true; +#endif +} + +__attribute__((weak)) bool lpm_is_kb_idle(void) { + return true; +} + +__attribute__((weak)) bool lpm_set(pm_t mode) { + return false; +} + +bool pre_enter_low_power_mode(pm_t mode) { +#if defined(KEEP_USB_CONNECTION_IN_WIRELESS_MODE) + /* Don't enter low power mode if attached to the host */ + if (mode > PM_SLEEP && usb_power_connected()) return false; +#endif + + if (!lpm_set(mode)) return false; + +#if defined(KEEP_USB_CONNECTION_IN_WIRELESS_MODE) + /* Usb unit is actived and running, stop and disconnect first */ + usbStop(&USBD1); + usbDisconnectBus(&USBD1); + + /* Isolate USB to save power.*/ + // PWR->CR2 &= ~PWR_CR2_USV; /*PWR_CR2_USV is available on STM32L4x2xx and STM32L4x3xx devices only. */ +#endif + + palEnableLineEvent(LKBT51_INT_INPUT_PIN, PAL_EVENT_MODE_FALLING_EDGE); +#ifdef USB_POWER_SENSE_PIN + palEnableLineEvent(USB_POWER_SENSE_PIN, PAL_EVENT_MODE_BOTH_EDGES); +#endif +#ifdef P2P4_MODE_SELECT_PIN + palEnableLineEvent(P2P4_MODE_SELECT_PIN, PAL_EVENT_MODE_BOTH_EDGES); +#endif +#ifdef BT_MODE_SELECT_PIN + palEnableLineEvent(BT_MODE_SELECT_PIN, PAL_EVENT_MODE_BOTH_EDGES); +#endif + +#ifdef OPTICAL_SWITCH + + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + if (pins_row[x] != NO_PIN) { + writePinLow(pins_row[x]); + } + } + + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + if (pins_col[x] != NO_PIN) { + setPinInputLow(pins_col[x]); + } + } +#else + + /* Enable key matrix wake up */ + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + if (pins_row[x] != NO_PIN) { + palEnableLineEvent(pins_row[x], PAL_EVENT_MODE_BOTH_EDGES); + } + } +#endif + select_all_cols(); + +#if (HAL_USE_SPI == TRUE) + palSetLineMode(SPI_SCK_PIN, PAL_MODE_INPUT_PULLDOWN); + palSetLineMode(SPI_MISO_PIN, PAL_MODE_INPUT_PULLDOWN); + palSetLineMode(SPI_MOSI_PIN, PAL_MODE_INPUT_PULLDOWN); +#endif + palSetLineMode(A12, PAL_MODE_INPUT_PULLDOWN); + palSetLineMode(A11, PAL_MODE_INPUT_PULLDOWN); + +#if defined(DIP_SWITCH_PINS) +# define NUMBER_OF_DIP_SWITCHES (sizeof(dip_switch_pad) / sizeof(pin_t)) + static pin_t dip_switch_pad[] = DIP_SWITCH_PINS; + + for (uint8_t i = 0; i < NUMBER_OF_DIP_SWITCHES; i++) { + setPinInputLow(dip_switch_pad[i]); + } +#endif + battery_stop(); + + return true; +} + +static inline void lpm_wakeup(void) { + palSetLineMode(A11, PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING | PAL_MODE_ALTERNATE(10U)); + palSetLineMode(A12, PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING | PAL_MODE_ALTERNATE(10U)); + +#if (HAL_USE_SPI == TRUE) + palSetLineMode(SPI_SCK_PIN, PAL_MODE_ALTERNATE(5)); + palSetLineMode(SPI_MISO_PIN, PAL_MODE_ALTERNATE(5)); + palSetLineMode(SPI_MOSI_PIN, PAL_MODE_ALTERNATE(5)); +#endif + + halInit(); + +#if defined(DIP_SWITCH_PINS) + /* Init dip switch as early as possible, and read it later. */ + dip_switch_init(); +#endif + +#ifdef ENCODER_ENABLE + encoder_cb_init(); +#endif + + if (wireless_transport.init) wireless_transport.init(true); + battery_init(); + + /* Disable all wake up pins */ + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + if (pins_row[x] != NO_PIN) { + palDisableLineEvent(pins_row[x]); + } + } + + palDisableLineEvent(LKBT51_INT_INPUT_PIN); +#ifdef P2P4_MODE_SELECT_PIN + palDisableLineEvent(P2P4_MODE_SELECT_PIN); +#endif +#ifdef BT_MODE_SELECT_PIN + palDisableLineEvent(BT_MODE_SELECT_PIN); +#endif +#ifdef USB_POWER_SENSE_PIN + palDisableLineEvent(USB_POWER_SENSE_PIN); + +# if defined(KEEP_USB_CONNECTION_IN_WIRELESS_MODE) + if (usb_power_connected()) { + usb_event_queue_init(); + init_usb_driver(&USB_DRIVER); + } +# endif + +#endif + + + /* Call debounce_free() to avoiding memory leak of debounce_counters as debounce_init() + invoked in matrix_init() alloc new memory to debounce_counters */ + debounce_free(); + matrix_init(); + +#ifdef ENABLE_RGB_MATRIX_PIXEL_RAIN + extern void PIXEL_RAIN_init(void); + PIXEL_RAIN_init(); +#endif + +#ifdef ENABLE_RGB_MATRIX_PIXEL_FLOW + extern void PIXEL_FLOW_init(void); + PIXEL_FLOW_init(); +#endif + +#ifdef ENABLE_RGB_MATRIX_PIXEL_FRACTAL + extern void PIXEL_FRACTAL_init(void); + PIXEL_FRACTAL_init(); +#endif + +#if defined(DIP_SWITCH_PINS) + dip_switch_read(true); +#endif +} + +void lpm_task(void) { + if (!lpm_time_up && sync_timer_elapsed32(lpm_timer_buffer) > RUN_MODE_PROCESS_TIME) { + lpm_time_up = true; + lpm_timer_buffer = 0; + } + + if (usb_power_connected() && USBD1.state == USB_STOP) { + usb_event_queue_init(); + init_usb_driver(&USB_DRIVER); + } + + if ((get_transport() == TRANSPORT_BLUETOOTH || get_transport() == TRANSPORT_P2P4) && lpm_time_up && !indicator_is_running() && lpm_is_kb_idle()) { +#if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) + if ( +# ifdef LED_MATRIX_ENABLE + !led_matrix_is_enabled() || + (led_matrix_is_enabled() && led_matrix_is_driver_shutdown()) +# endif +# ifdef RGB_MATRIX_ENABLE + !rgb_matrix_is_enabled() || + (rgb_matrix_is_enabled() && rgb_matrix_is_driver_shutdown()) +# endif + ) +#endif + { + if (!lpm_any_matrix_action()) { + if (pre_enter_low_power_mode(LOW_POWER_MODE)) { + enter_power_mode(LOW_POWER_MODE); + + lpm_wakeup(); + lpm_timer_reset(); + report_buffer_init(); + lpm_set(PM_RUN); + } + } + } + } +} diff --git a/keyboards/keychron/common/wireless/lpm.h b/keyboards/keychron/common/wireless/lpm.h new file mode 100644 index 0000000000..ca6fc5d450 --- /dev/null +++ b/keyboards/keychron/common/wireless/lpm.h @@ -0,0 +1,36 @@ +/* Copyright 2023 @ lokher (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 . + */ + +#pragma once + +#ifndef RUN_MODE_PROCESS_TIME +# define RUN_MODE_PROCESS_TIME 1000 +#endif + +typedef enum { + PM_RUN, + PM_SLEEP, + PM_STOP, + PM_STANDBY, +} pm_t; + +void lpm_init(void); +void lpm_timer_reset(void); +void lpm_timer_stop(void); +bool usb_power_connected(void); +bool lpm_is_kb_idle(void); +void enter_power_mode(pm_t mode); +void lpm_task(void); diff --git a/keyboards/keychron/common/wireless/lpm_stm32f401.c b/keyboards/keychron/common/wireless/lpm_stm32f401.c new file mode 100644 index 0000000000..7a7e59109b --- /dev/null +++ b/keyboards/keychron/common/wireless/lpm_stm32f401.c @@ -0,0 +1,114 @@ +/* Copyright 2023 @ lokher (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 . + */ + +/****************************************************************************** + * + * Filename: lpm_stm32f401.c + * + * Description: Contains low power mode implementation + * + ******************************************************************************/ + +#include "quantum.h" +#include +#include "wireless.h" +#include "lpm.h" +#include "lpm_stm32f401.h" +#include "config.h" + +static pm_t power_mode = PM_RUN; + +bool lpm_set(pm_t mode) { + bool ret = true; + + switch (mode) { + case PM_SLEEP: + /* Wake source: Any interrupt or event */ + if (power_mode != PM_RUN) + ret = false; + else + SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; + break; + + case PM_STOP: + /* Wake source: Reset pin, all I/Os, BOR, PVD, PVM, RTC, LCD, IWDG, + COMPx, USARTx, LPUART1, I2Cx, LPTIMx, USB, SWPMI */ + if (power_mode != PM_RUN) + ret = false; + else { + SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; + PWR->CR |= +#if STOP_MODE_MAIN_REGULATOR_LOW_VOLTAGE + PWR_CR_MRLVDS | +#endif +#if STOP_MODE_LOW_POWER_REGULATOR_LOW_VOLTAG + PWR_CR_LPLVDS | +#endif +#if STOP_MODE_FLASH_POWER_DOWN + PWR_CR_FPDS | +#endif +#if STOP_MODE_LOW_POWER_DEEPSLEEP + PWR_CR_LPDS | +#endif + 0; + } + break; + + case PM_STANDBY: + if (power_mode != PM_RUN) + ret = false; + else { + SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; + } + break; + + default: + break; + } + power_mode = mode; + + return ret; +} + +void enter_power_mode(pm_t mode) { +#if STM32_HSE_ENABLED + /* Switch to HSI */ + RCC->CFGR = (RCC->CFGR & (~STM32_SW_MASK)) | STM32_SW_HSI; + while ((RCC->CFGR & RCC_CFGR_SWS) != (STM32_SW_HSI << 2)) + ; + + /* Set HSE off */ + RCC->CR &= ~RCC_CR_HSEON; + while ((RCC->CR & RCC_CR_HSERDY)) + ; + + /* To avoid power consumption of floating GPIO */ + palSetLineMode(H0, PAL_MODE_INPUT_PULLDOWN); + palSetLineMode(H1, PAL_MODE_INPUT_PULLDOWN); +#endif + + __WFI(); + + SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; + + writePinLow(BLUETOOTH_INT_OUTPUT_PIN); + stm32_clock_init(); + writePinHigh(BLUETOOTH_INT_OUTPUT_PIN); +} + +void usb_power_connect(void) {} + +void usb_power_disconnect(void) {} diff --git a/keyboards/keychron/common/wireless/lpm_stm32f401.h b/keyboards/keychron/common/wireless/lpm_stm32f401.h new file mode 100644 index 0000000000..3b25c3d57c --- /dev/null +++ b/keyboards/keychron/common/wireless/lpm_stm32f401.h @@ -0,0 +1,33 @@ +/* Copyright 2023 @ lokher (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 . + */ + +#pragma once + +#ifndef STOP_MODE_MAIN_REGULATOR_LOW_VOLTAGE +# define STOP_MODE_MAIN_REGULATOR_LOW_VOLTAGE TRUE +#endif + +#ifndef STOP_MODE_LOW_POWER_REGULATOR_LOW_VOLTAG +# define STOP_MODE_LOW_POWER_REGULATOR_LOW_VOLTAG TRUE +#endif + +#ifndef STOP_MODE_FLASH_POWER_DOWN +# define STOP_MODE_FLASH_POWER_DOWN TRUE +#endif + +#ifndef STOP_MODE_LOW_POWER_DEEPSLEEP +# define STOP_MODE_LOW_POWER_DEEPSLEEP TRUE +#endif diff --git a/keyboards/keychron/common/wireless/report_buffer.c b/keyboards/keychron/common/wireless/report_buffer.c new file mode 100644 index 0000000000..317ba8ce1d --- /dev/null +++ b/keyboards/keychron/common/wireless/report_buffer.c @@ -0,0 +1,144 @@ +/* Copyright 2023 @ lokher (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 . + */ + +#include "quantum.h" +#include "report_buffer.h" +#include "wireless.h" +#include "lpm.h" + +/* The report buffer is mainly used to fix key press lost issue of macro + * when wireless module fifo isn't large enough. The maximun macro + * string length is determined by this queue size, and should be + * REPORT_BUFFER_QUEUE_SIZE devided by 2 since each character is implemented + * by sending a key pressing then a key releasing report. + * Please note that it cosume sizeof(report_buffer_t) * REPORT_BUFFER_QUEUE_SIZE + * bytes RAM, with default setting, used RAM size is + * sizeof(report_buffer_t) * 256 = 34* 256 = 8704 bytes + */ +#ifndef REPORT_BUFFER_QUEUE_SIZE +# define REPORT_BUFFER_QUEUE_SIZE 256 +#endif + +extern wt_func_t wireless_transport; + +/* report_interval value should be less than bluetooth connection interval because + * it takes some time for communicating between mcu and bluetooth module. Carefully + * set this value to feed the bt module so that we don't lost the key report nor lost + * the anchor point of bluetooth interval. The bluetooth connection interval varies + * if BLE is used, invoke report_buffer_set_inverval() to update the value + */ +uint8_t report_interval = DEFAULT_2P4G_REPORT_INVERVAL_MS; + +static uint32_t report_timer_buffer = 0; +uint32_t retry_time_buffer = 0; +report_buffer_t report_buffer_queue[REPORT_BUFFER_QUEUE_SIZE]; +uint16_t report_buffer_queue_head; +uint16_t report_buffer_queue_tail; +report_buffer_t kb_rpt; +uint8_t retry = 0; + +void report_buffer_task(void); + +void report_buffer_init(void) { + // Initialise the report queue + memset(&report_buffer_queue, 0, sizeof(report_buffer_queue)); + report_buffer_queue_head = 0; + report_buffer_queue_tail = 0; + retry = 0; + report_timer_buffer = timer_read32(); +} + +bool report_buffer_enqueue(report_buffer_t *report) { + uint16_t next = (report_buffer_queue_head + 1) % REPORT_BUFFER_QUEUE_SIZE; + if (next == report_buffer_queue_tail) { + return false; + } + + report_buffer_queue[report_buffer_queue_head] = *report; + report_buffer_queue_head = next; + return true; +} + +inline bool report_buffer_dequeue(report_buffer_t *report) { + if (report_buffer_queue_head == report_buffer_queue_tail) { + return false; + } + + *report = report_buffer_queue[report_buffer_queue_tail]; + report_buffer_queue_tail = (report_buffer_queue_tail + 1) % REPORT_BUFFER_QUEUE_SIZE; + return true; +} + +bool report_buffer_is_empty() { + return report_buffer_queue_head == report_buffer_queue_tail; +} + +void report_buffer_update_timer(void) { + report_timer_buffer = timer_read32(); +} + +bool report_buffer_next_inverval(void) { + return timer_elapsed32(report_timer_buffer) > report_interval; +} + +void report_buffer_set_inverval(uint8_t interval) { + // OG_TRACE("report_buffer_set_inverval: %d\n\r", interval); + report_interval = interval; +} + +uint8_t report_buffer_get_retry(void) { + return retry; +} + +void report_buffer_set_retry(uint8_t times) { + retry = times; +} + +void report_buffer_task(void) { + if (wireless_get_state() == WT_CONNECTED && (!report_buffer_is_empty() || retry) && report_buffer_next_inverval()) { + bool pending_data = false; + + if (!retry) { + if (report_buffer_dequeue(&kb_rpt) && kb_rpt.type != REPORT_TYPE_NONE) { + if (timer_read32() > 2) { + pending_data = true; + retry = RETPORT_RETRY_COUNT; + retry_time_buffer = timer_read32(); + } + } + } else { + if (timer_elapsed32(retry_time_buffer) > 2) { + pending_data = true; + --retry; + retry_time_buffer = timer_read32(); + } + } + + if (pending_data) { +#if defined(NKRO_ENABLE) && defined(WIRELESS_NKRO_ENABLE) + if (kb_rpt.type == REPORT_TYPE_NKRO && wireless_transport.send_nkro) { + wireless_transport.send_nkro(&kb_rpt.nkro.mods); + } else if (kb_rpt.type == REPORT_TYPE_KB && wireless_transport.send_keyboard) + wireless_transport.send_keyboard(&kb_rpt.keyboard.mods); +#else + if (kb_rpt.type == REPORT_TYPE_KB && wireless_transport.send_keyboard) wireless_transport.send_keyboard(&kb_rpt.keyboard.mods); +#endif + if (kb_rpt.type == REPORT_TYPE_CONSUMER && wireless_transport.send_consumer) wireless_transport.send_consumer(kb_rpt.consumer); + report_timer_buffer = timer_read32(); + lpm_timer_reset(); + } + } +} diff --git a/keyboards/keychron/common/wireless/report_buffer.h b/keyboards/keychron/common/wireless/report_buffer.h new file mode 100644 index 0000000000..4d03d291e7 --- /dev/null +++ b/keyboards/keychron/common/wireless/report_buffer.h @@ -0,0 +1,61 @@ +/* Copyright 2022~2023 @ lokher (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 . + */ + +#pragma once + +#include "report.h" + +/* Default report interval value */ +#ifndef DEFAULT_BLE_REPORT_INVERVAL_MS +# define DEFAULT_BLE_REPORT_INVERVAL_MS 3 +#endif + +/* Default report interval value */ +#ifndef DEFAULT_2P4G_REPORT_INVERVAL_MS +# define DEFAULT_2P4G_REPORT_INVERVAL_MS 1 +#endif + +/* Default report interval value */ +#ifndef RETPORT_RETRY_COUNT +# define RETPORT_RETRY_COUNT 30 +#endif + +enum { + REPORT_TYPE_NONE, + REPORT_TYPE_KB, + REPORT_TYPE_NKRO, + REPORT_TYPE_CONSUMER, +}; + +typedef struct { + uint8_t type; + union { + report_keyboard_t keyboard; + report_nkro_t nkro; + uint16_t consumer; + }; +} report_buffer_t; + +void report_buffer_init(void); +bool report_buffer_enqueue(report_buffer_t *report); +bool report_buffer_dequeue(report_buffer_t *report); +bool report_buffer_is_empty(void); +void report_buffer_update_timer(void); +bool report_buffer_next_inverval(void); +void report_buffer_set_inverval(uint8_t interval); +uint8_t report_buffer_get_retry(void); +void report_buffer_set_retry(uint8_t times); +void report_buffer_task(void); diff --git a/keyboards/keychron/common/wireless/rtc_timer.c b/keyboards/keychron/common/wireless/rtc_timer.c new file mode 100644 index 0000000000..9a35b9bddb --- /dev/null +++ b/keyboards/keychron/common/wireless/rtc_timer.c @@ -0,0 +1,43 @@ +/* Copyright 2023 @ lokher (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 . + */ + +#include "hal.h" + +#if (HAL_USE_RTC) + +# include "rtc_timer.h" + +void rtc_timer_init(void) { + rtc_timer_clear(); +} + +void rtc_timer_clear(void) { + RTCDateTime tm = {0, 0, 0, 0, 0, 0}; + rtcSetTime(&RTCD1, &tm); +} + +uint32_t rtc_timer_read_ms(void) { + RTCDateTime tm; + rtcGetTime(&RTCD1, &tm); + + return tm.millisecond; +} + +uint32_t rtc_timer_elapsed_ms(uint32_t last) { + return TIMER_DIFF_32(rtc_timer_read_ms(), last); +} + +#endif diff --git a/keyboards/keychron/common/wireless/rtc_timer.h b/keyboards/keychron/common/wireless/rtc_timer.h new file mode 100644 index 0000000000..cf6dfb5720 --- /dev/null +++ b/keyboards/keychron/common/wireless/rtc_timer.h @@ -0,0 +1,35 @@ +/* Copyright 2023 @ lokher (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 . + */ + +#pragma once + +#include "timer.h" +#include + +#define RTC_MAX_TIME (24 * 3600 * 1000) // Set to 1 day + +#ifdef __cplusplus +extern "C" { +#endif + +void rtc_timer_init(void); +void rtc_timer_clear(void); +uint32_t rtc_timer_read_ms(void); +uint32_t rtc_timer_elapsed_ms(uint32_t last); + +#ifdef __cplusplus +} +#endif diff --git a/keyboards/keychron/common/wireless/transport.c b/keyboards/keychron/common/wireless/transport.c new file mode 100644 index 0000000000..d452d1d6c8 --- /dev/null +++ b/keyboards/keychron/common/wireless/transport.c @@ -0,0 +1,259 @@ +/* Copyright 2022~2023 @ lokher (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 . + */ + +#include "quantum.h" +#include "wireless.h" +#include "indicator.h" +#include "lpm.h" +#include "mousekey.h" +#if defined(PROTOCOL_CHIBIOS) +# include +#endif +#include "transport.h" +#include "lkbt51.h" + +#ifndef REINIT_LED_DRIVER +# define REINIT_LED_DRIVER 0 +#endif + +#if defined(PROTOCOL_CHIBIOS) +extern host_driver_t chibios_driver; +#endif +extern host_driver_t wireless_driver; +extern keymap_config_t keymap_config; +extern wt_func_t wireless_transport; + +static transport_t transport = TRANSPORT_NONE; + +#ifdef NKRO_ENABLE +nkro_t nkro = {false, false}; +#endif + +static void transport_changed(transport_t new_transport); + +__attribute__((weak)) void bt_transport_enable(bool enable) { + if (enable) { + // if (host_get_driver() != &wireless_driver) { + host_set_driver(&wireless_driver); + + /* Disconnect and reconnect to sync the wireless state + * TODO: query wireless state to sync + */ + wireless_disconnect(); + + uint32_t t = timer_read32(); + while (timer_elapsed32(t) < 50) { + wireless_transport.task(); + } + // wireless_connect(); + wireless_connect_ex(30, 0); + // TODO: Clear USB report + //} + } else { + indicator_stop(); + + if (wireless_get_state() == WT_CONNECTED && transport == TRANSPORT_BLUETOOTH) { + report_keyboard_t empty_report = {0}; + wireless_driver.send_keyboard(&empty_report); + } + } +} + +__attribute__((weak)) void p24g_transport_enable(bool enable) { + if (enable) { + // if (host_get_driver() != &wireless_driver) { + host_set_driver(&wireless_driver); + + /* Disconnect and reconnect to sync the wireless state + * TODO: query bluetooth state to sync + */ + wireless_disconnect(); + + uint32_t t = timer_read32(); + while (timer_elapsed32(t) < 50) { + wireless_transport.task(); + } + wireless_connect_ex(P24G_INDEX, 0); + // wireless_connect(); + // TODO: Clear USB report + //} + } else { + indicator_stop(); + + if (wireless_get_state() == WT_CONNECTED && transport == TRANSPORT_P2P4) { + report_keyboard_t empty_report = {0}; + wireless_driver.send_keyboard(&empty_report); + } + } +} + +__attribute__((weak)) void usb_power_connect(void) {} +__attribute__((weak)) void usb_power_disconnect(void) {} + +__attribute__((weak)) void usb_transport_enable(bool enable) { + if (enable) { + if (host_get_driver() != &chibios_driver) { +#if !defined(KEEP_USB_CONNECTION_IN_WIRELESS_MODE) + usb_power_connect(); + usb_start(&USBD1); +#endif + host_set_driver(&chibios_driver); + } + } else { + if (USB_DRIVER.state == USB_ACTIVE) { + report_keyboard_t empty_report = {0}; + chibios_driver.send_keyboard(&empty_report); + } + +#if !defined(KEEP_USB_CONNECTION_IN_WIRELESS_MODE) + usbStop(&USBD1); + usbDisconnectBus(&USBD1); + usb_power_disconnect(); +#endif + } +} + +void set_transport(transport_t new_transport) { + if (transport != new_transport) { + if (transport == TRANSPORT_USB || ((transport != TRANSPORT_USB) && wireless_get_state() == WT_CONNECTED)) clear_keyboard(); + + transport = new_transport; + + switch (transport) { + case TRANSPORT_USB: + usb_transport_enable(true); + bt_transport_enable(false); + wait_ms(5); + p24g_transport_enable(false); + wireless_disconnect(); + lpm_timer_stop(); + break; + + case TRANSPORT_BLUETOOTH: + p24g_transport_enable(false); + wait_ms(1); + bt_transport_enable(true); + usb_transport_enable(false); + lpm_timer_reset(); + break; + + case TRANSPORT_P2P4: + bt_transport_enable(false); + wait_ms(1); + p24g_transport_enable(true); + usb_transport_enable(false); + lpm_timer_reset(); + break; + + default: + break; + } + + transport_changed(transport); + } +} + +transport_t get_transport(void) { + return transport; +} + +#if (REINIT_LED_DRIVER) +/* Changing transport may cause bronw-out reset of led driver + * withoug MCU reset, which lead backlight to not work, + * reinit the led driver workgound this issue */ +static void reinit_led_drvier(void) { + /* Wait circuit to discharge for a while */ + systime_t start = chVTGetSystemTime(); + while (chTimeI2MS(chVTTimeElapsedSinceX(start)) < 100) { + }; + +# ifdef LED_MATRIX_ENABLE + led_matrix_init(); +# endif +# ifdef RGB_MATRIX_ENABLE + rgb_matrix_init(); +# endif +} +#endif + +void transport_changed(transport_t new_transport) { + kc_printf("transport_changed %d\n\r", new_transport); + indicator_init(); + +#if (REINIT_LED_DRIVER) + reinit_led_drvier(); +#endif + +#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_TIMEOUT) +# if (RGB_MATRIX_TIMEOUT > 0) + rgb_matrix_disable_timeout_set(RGB_MATRIX_TIMEOUT_INFINITE); + rgb_matrix_disable_time_reset(); +# endif +#endif +#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_TIMEOUT) +# if (LED_MATRIX_TIMEOUT > 0) + led_matrix_disable_timeout_set(LED_MATRIX_TIMEOUT_INFINITE); + led_matrix_disable_time_reset(); +# endif +#endif +} + +void usb_remote_wakeup(void) { + if (USB_DRIVER.state == USB_SUSPENDED) { + while (USB_DRIVER.state == USB_SUSPENDED) { + wireless_pre_task(); + if (get_transport() != TRANSPORT_USB) { + suspend_wakeup_init_quantum(); + return; + } + /* Do this in the suspended state */ + suspend_power_down(); // on AVR this deep sleeps for 15ms + /* Remote wakeup */ + if (suspend_wakeup_condition() +#ifdef ENCODER_ENABLE + || encoder_read() +#endif + ) { + usbWakeupHost(&USB_DRIVER); + wait_ms(300); +#ifdef MOUSEKEY_ENABLE + // Wiggle to wakeup + mousekey_on(KC_MS_LEFT); + mousekey_send(); + wait_ms(10); + mousekey_on(KC_MS_RIGHT); + mousekey_send(); + wait_ms(10); + mousekey_off((KC_MS_RIGHT)); + mousekey_send(); +#else + set_mods(0x02); + send_keyboard_report(); + wait_ms(10); + del_mods(0x02); + send_keyboard_report(); +#endif + } + } + /* Woken up */ + // variables has been already cleared by the wakeup hook + send_keyboard_report(); +#ifdef MOUSEKEY_ENABLE + mousekey_send(); +#endif /* MOUSEKEY_ENABLE */ + usb_event_queue_task(); + } +} diff --git a/keyboards/keychron/common/wireless/transport.h b/keyboards/keychron/common/wireless/transport.h new file mode 100644 index 0000000000..b9796078ce --- /dev/null +++ b/keyboards/keychron/common/wireless/transport.h @@ -0,0 +1,42 @@ +/* Copyright 2022~2023 @ lokher (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 . + */ + +#pragma once + +typedef enum { + TRANSPORT_NONE, + TRANSPORT_USB = 0x01 << 0, + TRANSPORT_BLUETOOTH = 0x01 << 1, + TRANSPORT_P2P4 = 0x01 << 2, + TRANSPORT_MAX, +} transport_t; + +#ifdef NKRO_ENABLE +typedef struct { + bool usb : 1; + bool bluetooth : 1; +} nkro_t; +#endif + +#define TRANSPORT_WIRELESS (TRANSPORT_BLUETOOTH | TRANSPORT_P2P4) + +void set_transport(transport_t new_transport); +transport_t get_transport(void); + +void usb_power_connect(void); +void usb_power_disconnect(void); +void usb_transport_enable(bool enable); +void usb_remote_wakeup(void); diff --git a/keyboards/keychron/common/wireless/wireless.c b/keyboards/keychron/common/wireless/wireless.c new file mode 100644 index 0000000000..24e9b18fdb --- /dev/null +++ b/keyboards/keychron/common/wireless/wireless.c @@ -0,0 +1,657 @@ +/* Copyright 2023 @ lokher (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 . + */ + +#include "quantum.h" +#include "wireless.h" +#include "report_buffer.h" +#include "lpm.h" +#include "battery.h" +#include "indicator.h" +#include "transport.h" +#include "rtc_timer.h" +#include "keychron_wireless_common.h" +#include "keychron_task.h" +#include "wireless_config.h" +#include "keychron_raw_hid.h" + +extern uint8_t pairing_indication; +extern host_driver_t chibios_driver; +extern report_buffer_t kb_rpt; +extern uint32_t retry_time_buffer; +extern uint8_t retry; + +static uint8_t host_index = 0; +static uint8_t led_state = 0; + +extern wt_func_t wireless_transport; +static wt_state_t wireless_state = WT_RESET; +static bool pincodeEntry = false; +uint8_t wireless_report_protocol = true; + +uint16_t backlit_disable_time = CONNECTED_BACKLIGHT_DISABLE_TIMEOUT; +uint16_t connected_idle_time = CONNECTED_IDLE_TIME; + +/* declarations */ +uint8_t wreless_keyboard_leds(void); +void wireless_send_keyboard(report_keyboard_t *report); +void wireless_send_nkro(report_nkro_t *report); +void wireless_send_mouse(report_mouse_t *report); +void wireless_send_extra(report_extra_t *report); +bool process_record_wireless(uint16_t keycode, keyrecord_t *record); + +/* host struct */ +host_driver_t wireless_driver = {wreless_keyboard_leds, wireless_send_keyboard, wireless_send_nkro, wireless_send_mouse, wireless_send_extra}; + +#define WT_EVENT_QUEUE_SIZE 16 +wireless_event_t wireless_event_queue[WT_EVENT_QUEUE_SIZE]; +uint8_t wireless_event_queue_head; +uint8_t wireless_event_queue_tail; + +bool wireless_lpm_set(uint8_t *data); + +void wireless_event_queue_init(void) { + // Initialise the event queue + memset(&wireless_event_queue, 0, sizeof(wireless_event_queue)); + wireless_event_queue_head = 0; + wireless_event_queue_tail = 0; +} + +bool wireless_event_enqueue(wireless_event_t event) { + uint8_t next = (wireless_event_queue_head + 1) % WT_EVENT_QUEUE_SIZE; + if (next == wireless_event_queue_tail) { + /* Override the first report */ + wireless_event_queue_tail = (wireless_event_queue_tail + 1) % WT_EVENT_QUEUE_SIZE; + } + wireless_event_queue[wireless_event_queue_head] = event; + wireless_event_queue_head = next; + return true; +} + +static inline bool wireless_event_dequeue(wireless_event_t *event) { + if (wireless_event_queue_head == wireless_event_queue_tail) { + return false; + } + *event = wireless_event_queue[wireless_event_queue_tail]; + wireless_event_queue_tail = (wireless_event_queue_tail + 1) % WT_EVENT_QUEUE_SIZE; + return true; +} + +#if defined(EECONFIG_BASE_WIRELESS_CONFIG) +void wireless_config_reset(void) { + uint8_t data[4] = { 0 }; + + uint16_t backlit_disable_time = CONNECTED_BACKLIGHT_DISABLE_TIMEOUT; + uint16_t connected_idle_time = CONNECTED_IDLE_TIME; + + memcpy(&data[0], &backlit_disable_time, sizeof(backlit_disable_time)); + memcpy(&data[2], &connected_idle_time, sizeof(connected_idle_time)); + wireless_lpm_set(data); +} + +void wireless_config_load(void) { + uint8_t offset = 0; + eeprom_read_block(&backlit_disable_time, (uint8_t *)(EECONFIG_BASE_WIRELESS_CONFIG+offset), sizeof(backlit_disable_time)); + offset += sizeof(backlit_disable_time); + eeprom_read_block(&connected_idle_time, (uint8_t *)(EECONFIG_BASE_WIRELESS_CONFIG+offset), sizeof(connected_idle_time)); + + if (backlit_disable_time == 0) + backlit_disable_time = CONNECTED_BACKLIGHT_DISABLE_TIMEOUT; + else if (backlit_disable_time < 5 ) backlit_disable_time = 5; + + if (connected_idle_time == 0) + connected_idle_time = CONNECTED_IDLE_TIME; + else if (connected_idle_time < 30 ) connected_idle_time = 30; +} + +void wireless_config_save(void) { + uint8_t offset = 0; + eeprom_update_block(&backlit_disable_time, (uint8_t *)(EECONFIG_BASE_WIRELESS_CONFIG+offset), sizeof(backlit_disable_time)); + offset += sizeof(backlit_disable_time); + eeprom_update_block(&connected_idle_time, (uint8_t *)(EECONFIG_BASE_WIRELESS_CONFIG+offset), sizeof(connected_idle_time)); +} +#endif + +/* + * Bluetooth init. + */ +void wireless_init(void) { + wireless_state = WT_INITIALIZED; + + wireless_event_queue_init(); +#ifndef DISABLE_REPORT_BUFFER + report_buffer_init(); +#endif + indicator_init(); +#ifdef BLUETOOTH_INT_INPUT_PIN + setPinInputHigh(BLUETOOTH_INT_INPUT_PIN); +#endif + + battery_init(); + lpm_init(); +#if HAL_USE_RTC + rtc_timer_init(); +#endif + +#if defined(EECONFIG_BASE_WIRELESS_CONFIG) + wireless_config_load(); +#endif +} + +/* + * Bluetooth trasponrt init. Bluetooth module driver shall use this function to register a callback + * to its implementation. + */ +void wireless_set_transport(wt_func_t *transport) { + if (transport) memcpy(&wireless_transport, transport, sizeof(wt_func_t)); +} + +/* + * Enter pairing with current host index + */ +void wireless_pairing(void) { + if (battery_is_critical_low()) return; + + wireless_pairing_ex(0, NULL); + wireless_state = WT_PARING; +} + +/* + * Enter pairing with specified host index and param + */ +void wireless_pairing_ex(uint8_t host_idx, void *param) { + kc_printf("wireless_pairing_ex %d\n\r", host_idx); + if (battery_is_critical_low()) return; + + if (wireless_transport.pairing_ex) wireless_transport.pairing_ex(host_idx, param); + wireless_state = WT_PARING; + + host_index = host_idx; +} + +/* + * Initiate connection request to paired host + */ +void wireless_connect(void) { + /* Work around empty report after wakeup, which leads to reconneect/disconnected loop */ + if (battery_is_critical_low() || timer_read32() == 0) return; + + if (wireless_state == WT_RECONNECTING && !indicator_is_running()) { + indicator_set(wireless_state, host_index); + } + wireless_transport.connect_ex(0, 0); + wireless_state = WT_RECONNECTING; +} + +/* + * Initiate connection request to paired host with argument + */ +void wireless_connect_ex(uint8_t host_idx, uint16_t timeout) { + kc_printf("wireless_connect_ex %d\n\r", host_idx); + if (battery_is_critical_low()) return; + + if (host_idx != 0) { + /* Do nothing when trying to connect to current connected host*/ + if (host_index == host_idx && wireless_state == WT_CONNECTED) return; + + host_index = host_idx; + led_state = 0; + } + wireless_transport.connect_ex(host_idx, timeout); + wireless_state = WT_RECONNECTING; +} + +/* Initiate a disconnection */ +void wireless_disconnect(void) { + kc_printf("wireless_disconnect\n\r"); + if (wireless_transport.disconnect) wireless_transport.disconnect(); +} + +/* Called when the BT device is reset. */ +static void wireless_enter_reset(uint8_t reason) { + kc_printf("wireless_enter_reset\n\r"); + wireless_state = WT_RESET; + wireless_enter_reset_kb(reason); +} + +/* Enters discoverable state. Upon entering this state we perform the following actions: + * - change state to WT_PARING + * - set pairing indication + */ +static void wireless_enter_discoverable(uint8_t host_idx) { + kc_printf("wireless_enter_discoverable: %d\n\r", host_idx); + host_index = host_idx; + + wireless_state = WT_PARING; + indicator_set(wireless_state, host_idx); + wireless_enter_discoverable_kb(host_idx); +} + +/* + * Enters reconnecting state. Upon entering this state we perform the following actions: + * - change state to RECONNECTING + * - set reconnect indication + */ +static void wireless_enter_reconnecting(uint8_t host_idx) { + host_index = host_idx; + + kc_printf("wireless_reconnecting %d\n\r", host_idx); + wireless_state = WT_RECONNECTING; + indicator_set(wireless_state, host_idx); + wireless_enter_reconnecting_kb(host_idx); +} + +/* Enters connected state. Upon entering this state we perform the following actions: + * - change state to CONNECTED + * - set connected indication + * - enable NKRO if it is support + */ +static void wireless_enter_connected(uint8_t host_idx) { + kc_printf("wireless_connected %d\n\r", host_idx); + + wireless_state = WT_CONNECTED; + indicator_set(wireless_state, host_idx); + host_index = host_idx; + + clear_keyboard(); + + /* Enable NKRO since it may be disabled in pin code entry */ +#if defined(NKRO_ENABLE) && !defined(WIRELESS_NKRO_ENABLE) + keymap_config.nkro = false; +#endif + + wireless_enter_connected_kb(host_idx); + if (battery_is_empty()) { + indicator_battery_low_enable(true); + } + if (wireless_transport.update_bat_level) wireless_transport.update_bat_level(battery_get_percentage()); + lpm_timer_reset(); +} + +/* Enters disconnected state. Upon entering this state we perform the following actions: + * - change state to DISCONNECTED + * - set disconnected indication + */ +static void wireless_enter_disconnected(uint8_t host_idx, uint8_t reason) { + kc_printf("wireless_disconnected %d, %d\n\r", host_idx, reason); + + uint8_t previous_state = wireless_state; + led_state = 0; + if (get_transport() & TRANSPORT_WIRELESS) + led_update_kb((led_t)led_state); + + wireless_state = WT_DISCONNECTED; + + if (previous_state == WT_CONNECTED) { + lpm_timer_reset(); + indicator_set(WT_SUSPEND, host_idx); + } else { + indicator_set(wireless_state, host_idx); +#if defined(RGB_MATRIX_ENABLE) || defined(LED_MATRIX_ENABLE) + if (reason && (get_transport() & TRANSPORT_WIRELESS)) { + indicator_set_backlit_timeout(DISCONNECTED_BACKLIGHT_DISABLE_TIMEOUT*1000); + } +#endif + } + +#ifndef DISABLE_REPORT_BUFFER + report_buffer_init(); +#endif + retry = 0; + wireless_enter_disconnected_kb(host_idx, reason); + + indicator_battery_low_enable(false); +} + +/* Enter pin code entry state. */ +static void wireless_enter_bluetooth_pin_code_entry(void) { +#if defined(NKRO_ENABLE) + keymap_config.nkro = FALSE; +#endif + pincodeEntry = true; + wireless_enter_bluetooth_pin_code_entry_kb(); +} + +/* Exit pin code entry state. */ +static void wireless_exit_bluetooth_pin_code_entry(void) { +#if defined(NKRO_ENABLE) || defined(WIRELESS_NKRO_ENABLE) + keymap_config.raw = eeconfig_read_keymap(); +#endif + pincodeEntry = false; + wireless_exit_bluetooth_pin_code_entry_kb(); +} + +/* Enters disconnected state. Upon entering this state we perform the following actions: + * - change state to DISCONNECTED + * - set disconnected indication + */ +static void wireless_enter_sleep(void) { + kc_printf("wireless_enter_sleep %d\n\r", wireless_state); + + led_state = 0; + + if (wireless_state == WT_CONNECTED || wireless_state == WT_PARING) { + wireless_state = WT_SUSPEND; + kc_printf("WT_SUSPEND\n\r"); + lpm_timer_reset(); + + wireless_enter_sleep_kb(); + indicator_set(wireless_state, 0); + indicator_battery_low_enable(false); + } +} + +__attribute__((weak)) void wireless_enter_reset_kb(uint8_t reason) {} +__attribute__((weak)) void wireless_enter_discoverable_kb(uint8_t host_idx) {} +__attribute__((weak)) void wireless_enter_reconnecting_kb(uint8_t host_idx) {} +__attribute__((weak)) void wireless_enter_connected_kb(uint8_t host_idx) {} +__attribute__((weak)) void wireless_enter_disconnected_kb(uint8_t host_idx, uint8_t reason) {} +__attribute__((weak)) void wireless_enter_bluetooth_pin_code_entry_kb(void) {} +__attribute__((weak)) void wireless_exit_bluetooth_pin_code_entry_kb(void) {} +__attribute__((weak)) void wireless_enter_sleep_kb(void) {} + +/* */ +static void wireless_hid_set_protocol(bool report_protocol) { + wireless_report_protocol = false; +} + +uint8_t wreless_keyboard_leds(void) { + if (wireless_state == WT_CONNECTED) { + return led_state; + } + + return 0; +} + +extern keymap_config_t keymap_config; + +void wireless_send_keyboard(report_keyboard_t *report) { + if (battery_is_critical_low()) return; + + if (wireless_state == WT_PARING && !pincodeEntry) return; + + if (wireless_state == WT_CONNECTED || (wireless_state == WT_PARING && pincodeEntry)) { + if (wireless_transport.send_keyboard) { +#ifndef DISABLE_REPORT_BUFFER + bool empty = report_buffer_is_empty(); + + report_buffer_t report_buffer; + report_buffer.type = REPORT_TYPE_KB; + memcpy(&report_buffer.keyboard, report, sizeof(report_keyboard_t)); + report_buffer_enqueue(&report_buffer); + + if (empty) + report_buffer_task(); +#else + wireless_transport.send_keyboard(&report->mods); +#endif + } + } else if (wireless_state != WT_RESET) { + wireless_connect(); + } +} + +void wireless_send_nkro(report_nkro_t *report) { + if (battery_is_critical_low()) return; + + if (wireless_state == WT_PARING && !pincodeEntry) return; + + if (wireless_state == WT_CONNECTED || (wireless_state == WT_PARING && pincodeEntry)) { + if (wireless_transport.send_nkro) { +#ifndef DISABLE_REPORT_BUFFER + bool empty = report_buffer_is_empty(); + + report_buffer_t report_buffer; + report_buffer.type = REPORT_TYPE_NKRO; + memcpy(&report_buffer.nkro, report, sizeof(report_nkro_t)); + report_buffer_enqueue(&report_buffer); + + if (empty) + report_buffer_task(); +#else + wireless_transport.send_nkro(&report->mods); +#endif + } + } else if (wireless_state != WT_RESET) { + wireless_connect(); + } +} + +void wireless_send_mouse(report_mouse_t *report) { + if (battery_is_critical_low()) return; + + if (wireless_state == WT_CONNECTED) { + if (wireless_transport.send_mouse) wireless_transport.send_mouse((uint8_t *)report); + } else if (wireless_state != WT_RESET) { + wireless_connect(); + } +} + +void wireless_send_system(uint16_t data) { + if (wireless_state == WT_CONNECTED) { + if (wireless_transport.send_system) wireless_transport.send_system(data); + } else if (wireless_state != WT_RESET) { + wireless_connect(); + } +} + +void wireless_send_consumer(uint16_t data) { + if (wireless_state == WT_CONNECTED) { +#ifndef DISABLE_REPORT_BUFFER + if (report_buffer_is_empty() && report_buffer_next_inverval()) { + if (wireless_transport.send_consumer) wireless_transport.send_consumer(data); + report_buffer_update_timer(); + } else { + report_buffer_t report_buffer; + report_buffer.type = REPORT_TYPE_CONSUMER; + report_buffer.consumer = data; + report_buffer_enqueue(&report_buffer); + } +#else + if (wireless_transport.send_consumer) wireless_transport.send_consumer(data); +#endif + } else if (wireless_state != WT_RESET) { + wireless_connect(); + } +} + +void wireless_send_extra(report_extra_t *report) { + if (battery_is_critical_low()) return; + + if (report->report_id == REPORT_ID_SYSTEM) { + wireless_send_system(report->usage); + } else if (report->report_id == REPORT_ID_CONSUMER) { + wireless_send_consumer(report->usage); + } +} + +void wireless_low_battery_shutdown(void) { + indicator_battery_low_enable(false); + + + report_buffer_init(); + clear_keyboard(); // + wait_ms(50); // wait a while for bt module to free buffer by sending report + + // Release all keys by sending empty reports + if (keymap_config.nkro) { + report_nkro_t empty_nkro_report; + memset(&empty_nkro_report, 0, sizeof(empty_nkro_report)); + wireless_transport.send_nkro(&empty_nkro_report.mods); + } else { + report_keyboard_t empty_report; + memset(&empty_report, 0, sizeof(empty_report)); + wireless_transport.send_keyboard(&empty_report.mods); + } + wait_ms(10); + wireless_transport.send_consumer(0); + wait_ms(10); + report_mouse_t empty_mouse_report; + memset(&empty_mouse_report, 0, sizeof(empty_mouse_report)); + wireless_transport.send_mouse((uint8_t *)&empty_mouse_report); + wait_ms(300); // Wait for bt module to send all buffered report + + wireless_disconnect(); +} + +void wireless_event_task(void) { + wireless_event_t event; + while (wireless_event_dequeue(&event)) { + switch (event.evt_type) { + case EVT_RESET: + wireless_enter_reset(event.params.reason); + break; + case EVT_CONNECTED: + wireless_enter_connected(event.params.hostIndex); + break; + case EVT_DISCOVERABLE: + wireless_enter_discoverable(event.params.hostIndex); + break; + case EVT_RECONNECTING: + wireless_enter_reconnecting(event.params.hostIndex); + break; + case EVT_DISCONNECTED: + wireless_enter_disconnected(event.params.hostIndex, event.data); + break; + case EVT_BT_PINCODE_ENTRY: + wireless_enter_bluetooth_pin_code_entry(); + break; + case EVT_EXIT_BT_PINCODE_ENTRY: + wireless_exit_bluetooth_pin_code_entry(); + break; + case EVT_SLEEP: + wireless_enter_sleep(); + break; + case EVT_HID_INDICATOR: + led_state = event.params.led; + break; + case EVT_HID_SET_PROTOCOL: + wireless_hid_set_protocol(event.params.protocol); + break; + case EVT_CONECTION_INTERVAL: + report_buffer_set_inverval(event.params.interval); + break; + default: + break; + } + } +} + +void wireless_task(void) { + wireless_transport.task(); + wireless_event_task(); +#ifndef DISABLE_REPORT_BUFFER + report_buffer_task(); +#endif + indicator_task(); + keychron_wireless_common_task(); + battery_task(); + lpm_task(); +} + +void send_string_task(void) { + if ((get_transport() & TRANSPORT_WIRELESS) && wireless_get_state() == WT_CONNECTED) { + wireless_transport.task(); +#ifndef DISABLE_REPORT_BUFFER + report_buffer_task(); +#endif + } +} +wt_state_t wireless_get_state(void) { + return wireless_state; +}; + +bool process_record_wireless(uint16_t keycode, keyrecord_t *record) { + if (get_transport() & TRANSPORT_WIRELESS) { + lpm_timer_reset(); + + if (battery_is_empty() && wireless_get_state() == WT_CONNECTED && record->event.pressed) { + indicator_battery_low_enable(true); + } + } + + if (!process_record_keychron_wireless(keycode, record)) return false; + + return true; +} + +#if defined(EECONFIG_BASE_WIRELESS_CONFIG) +bool wireless_lpm_get(uint8_t *data) { + uint8_t index = 1; + memcpy(&data[index], &backlit_disable_time, sizeof(backlit_disable_time)); + index += sizeof(backlit_disable_time); + memcpy(&data[index], &connected_idle_time, sizeof(connected_idle_time)); + + return true; +} + +bool wireless_lpm_set(uint8_t *data) { + uint8_t index = 0; + + memcpy(&backlit_disable_time, &data[index], sizeof(backlit_disable_time)); + index += sizeof(backlit_disable_time); + memcpy(&connected_idle_time, &data[index], sizeof(connected_idle_time)); + + if (backlit_disable_time < 5 || connected_idle_time < 60) { + wireless_config_load(); + return false; + } + + wireless_config_save(); + + // Reset backlight timeout + if ((get_transport() & TRANSPORT_WIRELESS) && wireless_state == WT_CONNECTED) + { + indicator_set_backlit_timeout(backlit_disable_time*1000); + indicator_reset_backlit_time(); + + // Wiggle mouse to reset bluetooth module timer + mousekey_on(KC_MS_LEFT); + mousekey_send(); + wait_ms(10); + mousekey_on(KC_MS_RIGHT); + mousekey_send(); + wait_ms(10); + mousekey_off((KC_MS_RIGHT)); + mousekey_send(); + wait_ms(10); + } + + // Update bluetooth module param + lkbt51_param_init(); + return true; +} + +void wireless_raw_hid_rx(uint8_t *data, uint8_t length) { + uint8_t cmd = data[1]; + bool success = true; + + switch (cmd) { + case WIRELESS_LPM_GET: + success = wireless_lpm_get(&data[2]); + break; + + case WIRELESS_LPM_SET: + success = wireless_lpm_set(&data[2]); + break; + + default: + data[0] = 0xFF; + break; + } + + data[2] = success ? 0 : 1; +} +#endif diff --git a/keyboards/keychron/common/wireless/wireless.h b/keyboards/keychron/common/wireless/wireless.h new file mode 100644 index 0000000000..0ead527d47 --- /dev/null +++ b/keyboards/keychron/common/wireless/wireless.h @@ -0,0 +1,106 @@ +/* Copyright 2023~2025 @ lokher (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 . + */ + +#pragma once + +#include "wireless_event_type.h" +#include "action.h" + +#ifdef KC_DEBUG +# define kc_printf dprintf +#else +# define kc_printf(format, ...) +#endif + +/* Low power mode */ +#ifndef LOW_POWER_MODE +# define LOW_POWER_MODE PM_STOP +#endif + +/* Wake pin used for blueooth module/controller to wake up MCU in low power mode*/ +#ifndef BLUETOOTH_INT_INPUT_PIN +# define WAKE_PIN A5 +#endif + +// clang-format off +/* Type of an enumeration of the possible wireless transport state.*/ +typedef enum { + WT_RESET, + WT_INITIALIZED, // 1 + WT_DISCONNECTED, // 2 + WT_CONNECTED, // 3 + WT_PARING, // 4 + WT_RECONNECTING, // 5 + WT_SUSPEND +} wt_state_t; + +//extern event_listener_t wireless_driver; + +typedef struct { + void (*init)(bool); + void (*connect_ex)(uint8_t, uint16_t); + void (*pairing_ex)(uint8_t, void *); + void (*disconnect)(void); + void (*send_keyboard)(uint8_t *); + void (*send_nkro)(uint8_t *); + void (*send_consumer)(uint16_t); + void (*send_system)(uint16_t); + void (*send_mouse)(uint8_t *); + void (*update_bat_level)(uint8_t); + void (*task)(void); +} wt_func_t; +// clang-format on + +extern void register_wt_tasks(void); + +void wireless_init(void); +void wireless_config_reset(void); + +void wireless_set_transport(wt_func_t *transport); +void wireless(void); + +bool wireless_event_enqueue(wireless_event_t event); + +void wireless_connect(void); +void wireless_connect_ex(uint8_t host_idx, uint16_t timeout); +void wireless_disconnect(void); + +void wireless_pairing(void); +void wireless_pairing_ex(uint8_t host_idx, void *param); +// bool bluetooth_is_activated(void); + +void wireless_enter_reset_kb(uint8_t reason); +void wireless_enter_discoverable_kb(uint8_t host_idx); +void wireless_enter_reconnecting_kb(uint8_t host_idx); +void wireless_enter_connected_kb(uint8_t host_idx); +void wireless_enter_disconnected_kb(uint8_t host_idx, uint8_t reason); +void wireless_enter_bluetooth_pin_code_entry_kb(void); +void wireless_exit_bluetooth_pin_code_entry_kb(void); +void wireless_enter_sleep_kb(void); + +void wireless_task(void); +void wireless_pre_task(void); +void wireless_post_task(void); +void send_string_task(void); + +wt_state_t wireless_get_state(void); + +void wireless_low_battery_shutdown(void); + +bool process_record_wireless(uint16_t keycode, keyrecord_t *record); + +void wireless_raw_hid_rx(uint8_t *data, uint8_t length); + diff --git a/keyboards/keychron/common/wireless/wireless.mk b/keyboards/keychron/common/wireless/wireless.mk new file mode 100644 index 0000000000..b575624b06 --- /dev/null +++ b/keyboards/keychron/common/wireless/wireless.mk @@ -0,0 +1,21 @@ +OPT_DEFS += -DLK_WIRELESS_ENABLE -DWIRELESS_CONFIG_ENABLE +OPT_DEFS += -DNO_USB_STARTUP_CHECK +OPT_DEFS += -DCORTEX_ENABLE_WFI_IDLE=TRUE + +WIRELESS_DIR = common/wireless +SRC += \ + $(WIRELESS_DIR)/wireless.c \ + $(WIRELESS_DIR)/report_buffer.c \ + $(WIRELESS_DIR)/lkbt51.c \ + $(WIRELESS_DIR)/indicator.c \ + $(WIRELESS_DIR)/wireless_main.c \ + $(WIRELESS_DIR)/transport.c \ + $(WIRELESS_DIR)/lpm.c \ + $(WIRELESS_DIR)/lpm_stm32f401.c \ + $(WIRELESS_DIR)/battery.c \ + $(WIRELESS_DIR)/bat_level_animation.c \ + $(WIRELESS_DIR)/rtc_timer.c \ + $(WIRELESS_DIR)/keychron_wireless_common.c + +VPATH += $(TOP_DIR)/keyboards/keychron/$(WIRELESS_DIR) + diff --git a/keyboards/keychron/common/wireless/wireless_config.h b/keyboards/keychron/common/wireless/wireless_config.h new file mode 100644 index 0000000000..f1305f3fd1 --- /dev/null +++ b/keyboards/keychron/common/wireless/wireless_config.h @@ -0,0 +1,31 @@ +/* Copyright 2023~2025 @ lokher (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 . + */ + +#pragma once + +#include "config.h" + +// +#ifndef BT_HOST_DEVICES_COUNT +# define BT_HOST_DEVICES_COUNT 3 +#endif + +#define P2P4G_HOST_DEVICES_COUNT 1 + +// Uint: Second, the timer restarts on key activities. +#ifndef CONNECTED_IDLE_TIME +# define CONNECTED_IDLE_TIME 7200 +#endif diff --git a/keyboards/keychron/common/wireless/wireless_event_type.h b/keyboards/keychron/common/wireless/wireless_event_type.h new file mode 100644 index 0000000000..430ace916f --- /dev/null +++ b/keyboards/keychron/common/wireless/wireless_event_type.h @@ -0,0 +1,45 @@ +/* Copyright 2023~2025 @ lokher (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 . + */ + +#pragma once + +/* Type of an enumeration of the possible wireless events.*/ +typedef enum { + EVT_NONE = 0, + EVT_RESET, + EVT_DISCOVERABLE, + EVT_RECONNECTING, + EVT_CONNECTED, + EVT_DISCONNECTED, + EVT_BT_PINCODE_ENTRY, + EVT_EXIT_BT_PINCODE_ENTRY, + EVT_SLEEP, + EVT_HID_SET_PROTOCOL, + EVT_HID_INDICATOR, + EVT_CONECTION_INTERVAL, +} event_type_t; + +typedef struct { + event_type_t evt_type; /*The type of the event. */ + union { + uint8_t reason; /* Parameters to WT_RESET event */ + uint8_t hostIndex; /* Parameters to connection event from EVT_DISCOVERABLE to EVT_DISCONECTED */ + uint8_t led; /* Parameters to EVT_HID_INDICATOR event */ + uint8_t protocol; /* Parameters to EVT_HID_SET_PROTOCOL event */ + uint8_t interval; /* Parameters to EVT_CONECTION_INTERVAL event */ + } params; + uint8_t data; +} wireless_event_t; diff --git a/keyboards/keychron/common/wireless/wireless_main.c b/keyboards/keychron/common/wireless/wireless_main.c new file mode 100644 index 0000000000..e37a218a35 --- /dev/null +++ b/keyboards/keychron/common/wireless/wireless_main.c @@ -0,0 +1,36 @@ +/* Copyright 2023 @ lokher (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 . + */ + +#include "quantum.h" +#include "wireless.h" +#include "transport.h" +#include "factory_test.h" +#include "keychron_task.h" + +__attribute__((weak)) void wireless_pre_task(void) {} +__attribute__((weak)) void wireless_post_task(void) {} + +bool wireless_tasks(void) { + wireless_pre_task(); + wireless_task(); + wireless_post_task(); + + /* usb_remote_wakeup() should be invoked last so that we have chance + * to switch to wireless after start-up when usb is not connected + */ + if (get_transport() == TRANSPORT_USB) usb_remote_wakeup(); + return true; +} diff --git a/keyboards/keychron/k5_max/ansi/rgb/config.h b/keyboards/keychron/k5_max/ansi/rgb/config.h new file mode 100644 index 0000000000..85e913346a --- /dev/null +++ b/keyboards/keychron/k5_max/ansi/rgb/config.h @@ -0,0 +1,55 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once + +#ifdef RGB_MATRIX_ENABLE +/* RGB Matrix driver configuration */ +# define DRIVER_COUNT 2 +# define RGB_MATRIX_LED_COUNT 108 + +# define SPI_SCK_PIN A5 +# define SPI_MISO_PIN A6 +# define SPI_MOSI_PIN A7 + +# define DRIVER_CS_PINS \ + { B8, B9 } +# define SNLED23751_SPI_DIVISOR 16 +# define SPI_DRIVER SPID1 + +/* Scan phase of led driver set as MSKPHASE_9CHANNEL(defined as 0x03 in snled27351.h) */ +# define PHASE_CHANNEL MSKPHASE_12CHANNEL + +/* Set LED driver current */ +# define SNLED27351_CURRENT_TUNE \ + { 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12 } + +/* Set to infinit, which is use in USB mode by default */ +# define RGB_MATRIX_TIMEOUT RGB_MATRIX_TIMEOUT_INFINITE + +/* Allow shutdown of led driver to save power */ +# define RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE +/* Turn off backlight on low brightness to save power */ +# define RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL 48 + +/* Indications */ +# define LOW_BAT_IND_INDEX \ + { 98 } + +# define RGB_MATRIX_KEYPRESSES +# define RGB_MATRIX_FRAMEBUFFER_EFFECTS + +#endif diff --git a/keyboards/keychron/k5_max/ansi/rgb/info.json b/keyboards/keychron/k5_max/ansi/rgb/info.json new file mode 100644 index 0000000000..36d2b441f2 --- /dev/null +++ b/keyboards/keychron/k5_max/ansi/rgb/info.json @@ -0,0 +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 + } + } +} diff --git a/keyboards/keychron/k5_max/ansi/rgb/keymaps/default/keymap.c b/keyboards/keychron/k5_max/ansi/rgb/keymaps/default/keymap.c new file mode 100644 index 0000000000..d14b8b1c6d --- /dev/null +++ b/keyboards/keychron/k5_max/ansi/rgb/keymaps/default/keymap.c @@ -0,0 +1,68 @@ +/* Copyright 2024 @ 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 . + */ + +#include QMK_KEYBOARD_H +#include "keychron_common.h" + +enum layers { + MAC_BASE, + MAC_FN, + WIN_BASE, + WIN_FN, +}; + +// clang-format off +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [MAC_BASE] = LAYOUT_108_ansi( + KC_ESC, KC_BRID, KC_BRIU, KC_MCTRL, KC_LNPAD, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, KC_SNAP, KC_SIRI, RGB_MOD, KC_F13, KC_F14, KC_F15, KC_F16, + 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_LOPTN, KC_LCMMD, KC_SPC, KC_RCMMD, KC_ROPTN,MO(MAC_FN),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT, KC_PENT), + + [MAC_FN] = LAYOUT_108_ansi( + _______, 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, _______, _______, _______, _______, + _______, BT_HST1, BT_HST2, BT_HST3, P2P4G, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______), + + [WIN_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_CTANA, RGB_MOD, _______, _______, _______, _______, + 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_LWIN, KC_LALT, KC_SPC, KC_RALT, KC_RWIN, MO(WIN_FN),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT, KC_PENT), + + [WIN_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, _______, _______, RGB_TOG, _______, _______, _______, _______, + _______, BT_HST1, BT_HST2, BT_HST3, P2P4G, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______), +}; + +// clang-format on +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + if (!process_record_keychron_common(keycode, record)) { + return false; + } + return 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/ansi/rgb/keymaps/via/keymap.c b/keyboards/keychron/k5_max/ansi/rgb/keymaps/via/keymap.c new file mode 100644 index 0000000000..d14b8b1c6d --- /dev/null +++ b/keyboards/keychron/k5_max/ansi/rgb/keymaps/via/keymap.c @@ -0,0 +1,68 @@ +/* Copyright 2024 @ 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 . + */ + +#include QMK_KEYBOARD_H +#include "keychron_common.h" + +enum layers { + MAC_BASE, + MAC_FN, + WIN_BASE, + WIN_FN, +}; + +// clang-format off +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [MAC_BASE] = LAYOUT_108_ansi( + KC_ESC, KC_BRID, KC_BRIU, KC_MCTRL, KC_LNPAD, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, KC_SNAP, KC_SIRI, RGB_MOD, KC_F13, KC_F14, KC_F15, KC_F16, + 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_LOPTN, KC_LCMMD, KC_SPC, KC_RCMMD, KC_ROPTN,MO(MAC_FN),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT, KC_PENT), + + [MAC_FN] = LAYOUT_108_ansi( + _______, 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, _______, _______, _______, _______, + _______, BT_HST1, BT_HST2, BT_HST3, P2P4G, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______), + + [WIN_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_CTANA, RGB_MOD, _______, _______, _______, _______, + 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_LWIN, KC_LALT, KC_SPC, KC_RALT, KC_RWIN, MO(WIN_FN),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT, KC_PENT), + + [WIN_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, _______, _______, RGB_TOG, _______, _______, _______, _______, + _______, BT_HST1, BT_HST2, BT_HST3, P2P4G, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______), +}; + +// clang-format on +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + if (!process_record_keychron_common(keycode, record)) { + return false; + } + return true; +} diff --git a/keyboards/keychron/k5_max/ansi/rgb/keymaps/via/rules.mk b/keyboards/keychron/k5_max/ansi/rgb/keymaps/via/rules.mk new file mode 100644 index 0000000000..1e5b99807c --- /dev/null +++ b/keyboards/keychron/k5_max/ansi/rgb/keymaps/via/rules.mk @@ -0,0 +1 @@ +VIA_ENABLE = yes diff --git a/keyboards/keychron/k5_max/ansi/rgb/rgb.c b/keyboards/keychron/k5_max/ansi/rgb/rgb.c new file mode 100644 index 0000000000..5d95d6ec86 --- /dev/null +++ b/keyboards/keychron/k5_max/ansi/rgb/rgb.c @@ -0,0 +1,174 @@ +/* Copyright 2024 @ 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 . + */ + +#include "quantum.h" + +// clang-format off +#ifdef RGB_MATRIX_ENABLE +const snled27351_led_t g_snled27351_leds[RGB_MATRIX_LED_COUNT] = { +/* Refer to SNLED27351 manual for these locations + * driver + * | R location + * | | G location + * | | | B location + * | | | | */ + {0, G_1, I_1, H_1}, + {0, G_2, I_2, H_2}, + {0, G_3, I_3, H_3}, + {0, G_4, I_4, H_4}, + {0, G_5, I_5, H_5}, + {0, G_6, I_6, H_6}, + {0, G_7, I_7, H_7}, + {0, G_8, I_8, H_8}, + {0, G_9, I_9, H_9}, + {0, G_10, I_10, H_10}, + {0, G_11, I_11, H_11}, + {0, G_12, I_12, H_12}, + {0, G_13, I_13, H_13}, + {0, G_15, I_15, H_15}, + {0, G_16, I_16, H_16}, + {0, G_14, I_14, H_14}, + {1, G_13, I_13, H_13}, + {1, G_15, I_15, H_15}, + {1, G_16, I_16, H_16}, + {1, A_15, C_15, B_15}, + + {0, D_1, F_1, E_1}, + {0, D_2, F_2, E_2}, + {0, D_3, F_3, E_3}, + {0, D_4, F_4, E_4}, + {0, D_5, F_5, E_5}, + {0, D_6, F_6, E_6}, + {0, D_7, F_7, E_7}, + {0, D_8, F_8, E_8}, + {0, D_9, F_9, E_9}, + {0, D_10, F_10, E_10}, + {0, D_11, F_11, E_11}, + {0, D_12, F_12, E_12}, + {0, D_13, F_13, E_13}, + {0, D_14, F_14, E_14}, + {0, D_15, F_15, E_15}, + {0, D_16, F_16, E_16}, + {0, J_7, L_7, K_7}, + {0, J_8, L_8, K_8}, + {0, J_9, L_9, K_9}, + {0, J_10, L_10, K_10}, + {0, J_11, L_11, K_11}, + + {0, C_1, A_1, B_1}, + {0, C_2, A_2, B_2}, + {0, C_3, A_3, B_3}, + {0, C_4, A_4, B_4}, + {0, C_5, A_5, B_5}, + {0, C_6, A_6, B_6}, + {0, C_7, A_7, B_7}, + {0, C_8, A_8, B_8}, + {0, C_9, A_9, B_9}, + {0, C_10, A_10, B_10}, + {0, C_11, A_11, B_11}, + {0, C_12, A_12, B_12}, + {0, C_13, A_13, B_13}, + {0, C_14, A_14, B_14}, + {0, C_15, A_15, B_15}, + {0, C_16, A_16, B_16}, + {0, J_12, L_12, K_12}, + {0, J_13, L_13, K_13}, + {0, J_14, L_14, K_14}, + {0, J_15, L_15, K_15}, + {0, J_16, L_16, K_16}, + + {1, G_1, I_1, H_1}, + {1, G_2, I_2, H_2}, + {1, G_3, I_3, H_3}, + {1, G_4, I_4, H_4}, + {1, G_5, I_5, H_5}, + {1, G_6, I_6, H_6}, + {1, G_7, I_7, H_7}, + {1, G_8, I_8, H_8}, + {1, G_9, I_9, H_9}, + {1, G_10, I_10, H_10}, + {1, G_11, I_11, H_11}, + {1, G_12, I_12, H_12}, + {1, G_14, I_14, H_14}, + {1, J_7, L_7, K_7}, + {1, J_8, L_8, K_8}, + {1, J_9, L_9, K_9}, + + {1, A_1, C_1, B_1}, + {1, A_3, C_3, B_3}, + {1, A_4, C_4, B_4}, + {1, A_5, C_5, B_5}, + {1, A_6, C_6, B_6}, + {1, A_7, C_7, B_7}, + {1, A_8, C_8, B_8}, + {1, A_9, C_9, B_9}, + {1, A_10, C_10, B_10}, + {1, A_11, C_11, B_11}, + {1, A_12, C_12, B_12}, + {1, A_14, C_14, B_14}, + {1, A_16, C_16, B_16}, + {1, J_10, L_10, K_10}, + {1, J_11, L_11, K_11}, + {1, J_12, L_12, K_12}, + {1, J_13, L_13, K_13}, + + {1, D_1, F_1, E_1}, + {1, D_2, F_2, E_2}, + {1, D_3, F_3, E_3}, + {1, D_7, F_7, E_7}, + {1, D_11, F_11, E_11}, + {1, D_12, F_12, E_12}, + {1, D_13, F_13, E_13}, + {1, D_14, F_14, E_14}, + {1, D_15, F_15, E_15}, + {1, D_16, F_16, E_16}, + {1, J_14, L_14, K_14}, + {1, J_15, L_15, K_15}, + {1, J_16, L_16, K_16}, +}; + +#define __ NO_LED + +led_config_t g_led_config = { + { + // Key Matrix to LED Index + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, __, 13, 14, 15, 16, 17, 18, 19 }, + { 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 }, + { 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61 }, + { 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, __, 74, __, __, __, 75, 76, 77, __ }, + { 78, __, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, __, 89, __, 90, __, 91, 92, 93, 94 }, + { 95, 96, 97, __, __, __, 98, __, __, __, 99, 100, 101, 102, 103, 104, 105, 106, __, 107, __ }, + }, + { + // LED Index to Physical Position + {0, 0}, {21, 0}, {32, 0}, {42, 0}, {53, 0}, {69, 0}, {79, 0}, {90, 0}, {100, 0}, {116, 0}, {127, 0}, {137, 0}, {148, 0}, {160, 0}, {170, 0}, {181, 0}, {192, 0}, {203, 0}, {213, 0}, {224, 0}, + {0,14}, {11,14}, {21,14}, {32,14}, {42,14}, {53,14}, {63,14}, {74,14}, { 84,14}, { 95,14}, {106,14}, {116,14}, {127,14}, {143,14}, {160,14}, {170,14}, {181,14}, {192,14}, {203,14}, {213,14}, {224,14}, + {3,26}, {16,26}, {26,26}, {37,26}, {48,26}, {58,26}, {69,26}, {79,26}, { 90,26}, {100,26}, {111,26}, {121,26}, {132,26}, {145,26}, {160,26}, {170,26}, {181,26}, {192,26}, {203,26}, {213,26}, {224,33}, + {4,39}, {19,39}, {29,39}, {40,39}, {50,39}, {61,39}, {71,39}, {82,39}, { 92,39}, {103,39}, {114,39}, {124,39}, {141,39}, {192,39}, {203,39}, {213,39}, + {7,51}, {24,51}, {34,51}, {45,51}, {55,51}, {66,51}, {77,51}, { 87,51}, { 98,51}, {108,51}, {119,51}, {139,51}, {170,51}, {192,51}, {203,51}, {213,51}, {224,58}, + {1,64}, {15,64}, {28,64}, {67,64}, {107,64}, {120,64}, {133,64}, {147,64}, {160,64}, {170,64}, {181,64}, {198,64}, {213,64}, + }, + { + // RGB LED Index to Flag + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + } +}; +#endif diff --git a/keyboards/keychron/k5_max/ansi/rgb/rules.mk b/keyboards/keychron/k5_max/ansi/rgb/rules.mk new file mode 100644 index 0000000000..6e7633bfe0 --- /dev/null +++ b/keyboards/keychron/k5_max/ansi/rgb/rules.mk @@ -0,0 +1 @@ +# This file intentionally left blank diff --git a/keyboards/keychron/k5_max/ansi/white/config.h b/keyboards/keychron/k5_max/ansi/white/config.h new file mode 100644 index 0000000000..e40f43ff89 --- /dev/null +++ b/keyboards/keychron/k5_max/ansi/white/config.h @@ -0,0 +1,52 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once + +#ifdef LED_MATRIX_ENABLE +/* LED matrix driver configuration */ +# define DRIVER_COUNT 1 +# define LED_MATRIX_LED_COUNT 108 + +# define SPI_SCK_PIN A5 +# define SPI_MISO_PIN A6 +# define SPI_MOSI_PIN A7 + +# define DRIVER_CS_PINS \ + { B9 } +# define SNLED23751_SPI_DIVISOR 16 +# define SPI_DRIVER SPID1 + +/* Use first 6 channels of LED driver */ +# define SNLED27351_PHASE_CHANNEL MSKPHASE_8CHANNEL + +/* Set LED driver current */ +# define SNLED27351_CURRENT_TUNE \ + { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 } + +/* Set to infinit, which is use in USB mode by default */ +# define LED_MATRIX_TIMEOUT LED_MATRIX_TIMEOUT_INFINITE +/* Allow shutdown of led driver to save power */ +# define LED_MATRIX_DRIVER_SHUTDOWN_ENABLE +/* Turn off backlight on low brightness to save power */ +# define LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL 48 + +/* Indications */ +# define LOW_BAT_IND_INDEX \ + { 98 } + +# define LED_MATRIX_KEYPRESSES +#endif diff --git a/keyboards/keychron/k5_max/ansi/white/info.json b/keyboards/keychron/k5_max/ansi/white/info.json new file mode 100644 index 0000000000..e031f22b73 --- /dev/null +++ b/keyboards/keychron/k5_max/ansi/white/info.json @@ -0,0 +1,30 @@ +{ + "usb": { + "pid": "0x0A53", + "device_version": "1.0.0" + }, + "features": { + "led_matrix": true + }, + "led_matrix": { + "driver": "snled27351_spi", + "sleep": true, + "animations": { + "none": true, + "solid": true, + "breathing": true, + "band_pinwheel": true, + "band_spiral": true, + "cycle_left_right": true, + "cycle_up_down": true, + "cycle_out_in": true, + "dual_beacon": true, + "solid_reactive_simple": true, + "solid_reactive_multiwide": true, + "solid_reactive_multinexus": true, + "solid_splash": true, + "wave_left_right": true, + "wave_up_down": true + } + } +} diff --git a/keyboards/keychron/k5_max/ansi/white/keymaps/default/keymap.c b/keyboards/keychron/k5_max/ansi/white/keymaps/default/keymap.c new file mode 100644 index 0000000000..2ea0c3daef --- /dev/null +++ b/keyboards/keychron/k5_max/ansi/white/keymaps/default/keymap.c @@ -0,0 +1,68 @@ +/* Copyright 2024 @ 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 . + */ + +#include QMK_KEYBOARD_H +#include "keychron_common.h" + +enum layers { + MAC_BASE, + MAC_FN, + WIN_BASE, + WIN_FN, +}; + +// clang-format off +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [MAC_BASE] = LAYOUT_108_ansi( + KC_ESC, KC_BRID, KC_BRIU, KC_MCTRL, KC_LNPAD, BL_DOWN, BL_UP, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, KC_SNAP, KC_SIRI, BL_STEP, KC_F13, KC_F14, KC_F15, KC_F16, + 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_LOPTN, KC_LCMMD, KC_SPC, KC_RCMMD, KC_ROPTN,MO(MAC_FN),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT, KC_PENT), + + [MAC_FN] = LAYOUT_108_ansi( + _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, BL_TOGG, _______, _______, _______, _______, + _______, BT_HST1, BT_HST2, BT_HST3, P2P4G, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + BL_TOGG, BL_STEP, BL_UP, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, BL_DOWN, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______), + + [WIN_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_CTANA, BL_STEP, _______, _______, _______, _______, + 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_LWIN, KC_LALT, KC_SPC, KC_RALT, KC_RWIN, MO(WIN_FN),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT, KC_PENT), + + [WIN_FN] = LAYOUT_108_ansi( + _______, KC_BRID, KC_BRIU, KC_TASK, KC_FILE, BL_DOWN, BL_UP, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, _______, _______, BL_TOGG, _______, _______, _______, _______, + _______, BT_HST1, BT_HST2, BT_HST3, P2P4G, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + BL_TOGG, BL_STEP, BL_UP, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, BL_DOWN, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______), +}; + +// clang-format on +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + if (!process_record_keychron_common(keycode, record)) { + return false; + } + return true; +} diff --git a/keyboards/keychron/k5_max/ansi/white/keymaps/via/keymap.c b/keyboards/keychron/k5_max/ansi/white/keymaps/via/keymap.c new file mode 100644 index 0000000000..2ea0c3daef --- /dev/null +++ b/keyboards/keychron/k5_max/ansi/white/keymaps/via/keymap.c @@ -0,0 +1,68 @@ +/* Copyright 2024 @ 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 . + */ + +#include QMK_KEYBOARD_H +#include "keychron_common.h" + +enum layers { + MAC_BASE, + MAC_FN, + WIN_BASE, + WIN_FN, +}; + +// clang-format off +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [MAC_BASE] = LAYOUT_108_ansi( + KC_ESC, KC_BRID, KC_BRIU, KC_MCTRL, KC_LNPAD, BL_DOWN, BL_UP, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, KC_SNAP, KC_SIRI, BL_STEP, KC_F13, KC_F14, KC_F15, KC_F16, + 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_LOPTN, KC_LCMMD, KC_SPC, KC_RCMMD, KC_ROPTN,MO(MAC_FN),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT, KC_PENT), + + [MAC_FN] = LAYOUT_108_ansi( + _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, BL_TOGG, _______, _______, _______, _______, + _______, BT_HST1, BT_HST2, BT_HST3, P2P4G, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + BL_TOGG, BL_STEP, BL_UP, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, BL_DOWN, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______), + + [WIN_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_CTANA, BL_STEP, _______, _______, _______, _______, + 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_LWIN, KC_LALT, KC_SPC, KC_RALT, KC_RWIN, MO(WIN_FN),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT, KC_PENT), + + [WIN_FN] = LAYOUT_108_ansi( + _______, KC_BRID, KC_BRIU, KC_TASK, KC_FILE, BL_DOWN, BL_UP, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, _______, _______, BL_TOGG, _______, _______, _______, _______, + _______, BT_HST1, BT_HST2, BT_HST3, P2P4G, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + BL_TOGG, BL_STEP, BL_UP, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, BL_DOWN, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______), +}; + +// clang-format on +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + if (!process_record_keychron_common(keycode, record)) { + return false; + } + return true; +} diff --git a/keyboards/keychron/k5_max/ansi/white/keymaps/via/rules.mk b/keyboards/keychron/k5_max/ansi/white/keymaps/via/rules.mk new file mode 100644 index 0000000000..1e5b99807c --- /dev/null +++ b/keyboards/keychron/k5_max/ansi/white/keymaps/via/rules.mk @@ -0,0 +1 @@ +VIA_ENABLE = yes diff --git a/keyboards/keychron/k5_max/ansi/white/rules.mk b/keyboards/keychron/k5_max/ansi/white/rules.mk new file mode 100644 index 0000000000..6e7633bfe0 --- /dev/null +++ b/keyboards/keychron/k5_max/ansi/white/rules.mk @@ -0,0 +1 @@ +# This file intentionally left blank diff --git a/keyboards/keychron/k5_max/ansi/white/white.c b/keyboards/keychron/k5_max/ansi/white/white.c new file mode 100644 index 0000000000..b3bf4e2c25 --- /dev/null +++ b/keyboards/keychron/k5_max/ansi/white/white.c @@ -0,0 +1,172 @@ +/* Copyright 2024 @ 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 . + */ + +#include "quantum.h" + +// clang-format off +#ifdef LED_MATRIX_ENABLE +const snled27351_led_t g_snled27351_leds[LED_MATRIX_LED_COUNT] = { +/* Refer to SNLED27351 manual for these locations + * driver + * | LED address + * | | */ + {0, F_1}, + {0, F_2}, + {0, F_3}, + {0, F_4}, + {0, F_5}, + {0, F_6}, + {0, F_7}, + {0, F_8}, + {0, F_9}, + {0, F_10}, + {0, F_11}, + {0, F_12}, + {0, F_13}, + {0, F_15}, + {0, F_16}, + {0, F_14}, + {0, H_7}, + {0, H_8}, + {0, H_9}, + {0, H_10}, + + {0, E_1}, + {0, E_2}, + {0, E_3}, + {0, E_4}, + {0, E_5}, + {0, E_6}, + {0, E_7}, + {0, E_8}, + {0, E_9}, + {0, E_10}, + {0, E_11}, + {0, E_12}, + {0, E_13}, + {0, E_14}, + {0, E_15}, + {0, E_16}, + {0, G_7}, + {0, G_8}, + {0, G_9}, + {0, G_10}, + {0, G_11}, + + {0, D_1}, + {0, D_2}, + {0, D_3}, + {0, D_4}, + {0, D_5}, + {0, D_6}, + {0, D_7}, + {0, D_8}, + {0, D_9}, + {0, D_10}, + {0, D_11}, + {0, D_12}, + {0, D_13}, + {0, D_14}, + {0, D_15}, + {0, D_16}, + {0, G_12}, + {0, G_13}, + {0, G_14}, + {0, G_15}, + {0, G_16}, + + {0, C_1}, + {0, C_2}, + {0, C_3}, + {0, C_4}, + {0, C_5}, + {0, C_6}, + {0, C_7}, + {0, C_8}, + {0, C_9}, + {0, C_10}, + {0, C_11}, + {0, C_12}, + {0, C_14}, + {0, C_13}, + {0, C_15}, + {0, C_16}, + + {0, B_1}, + {0, B_3}, + {0, B_4}, + {0, B_5}, + {0, B_6}, + {0, B_7}, + {0, B_8}, + {0, B_9}, + {0, B_10}, + {0, B_11}, + {0, B_12}, + {0, B_14}, + {0, B_16}, + {0, B_13}, + {0, H_11}, + {0, H_12}, + {0, H_13}, + + {0, A_1}, + {0, A_2}, + {0, A_3}, + {0, A_7}, + {0, A_11}, + {0, A_12}, + {0, A_13}, + {0, A_14}, + {0, A_15}, + {0, A_16}, + {0, H_14}, + {0, H_15}, + {0, H_16}, +}; + +#define __ NO_LED + +led_config_t g_led_config = { + { + // Key Matrix to LED Index + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, __, 13, 14, 15, 16, 17, 18, 19 }, + { 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 }, + { 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61 }, + { 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, __, 74, __, __, __, 75, 76, 77, __ }, + { 78, __, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, __, 89, __, 90, __, 91, 92, 93, 94 }, + { 95, 96, 97, __, __, __, 98, __, __, __, 99, 100, 101, 102, 103, 104, 105, 106, __, 107, __ }, + }, + { + // LED Index to Physical Position + {0, 0}, {21, 0}, {32, 0}, {42, 0}, {53, 0}, {69, 0}, {79, 0}, {90, 0}, {100, 0}, {116, 0}, {127, 0}, {137, 0}, {148, 0}, {160, 0}, {170, 0}, {181, 0}, {192, 0}, {203, 0}, {213, 0}, {224, 0}, + {0,14}, {11,14}, {21,14}, {32,14}, {42,14}, {53,14}, {63,14}, {74,14}, { 84,14}, { 95,14}, {106,14}, {116,14}, {127,14}, {143,14}, {160,14}, {170,14}, {181,14}, {192,14}, {203,14}, {213,14}, {224,14}, + {3,26}, {16,26}, {26,26}, {37,26}, {48,26}, {58,26}, {69,26}, {79,26}, { 90,26}, {100,26}, {111,26}, {121,26}, {132,26}, {145,26}, {160,26}, {170,26}, {181,26}, {192,26}, {203,26}, {213,26}, {224,33}, + {4,39}, {19,39}, {29,39}, {40,39}, {50,39}, {61,39}, {71,39}, {82,39}, { 92,39}, {103,39}, {114,39}, {124,39}, {141,39}, {192,39}, {203,39}, {213,39}, + {7,51}, {24,51}, {34,51}, {45,51}, {55,51}, {66,51}, {77,51}, { 87,51}, { 98,51}, {108,51}, {119,51}, {139,51}, {170,51}, {192,51}, {203,51}, {213,51}, {224,58}, + {1,64}, {15,64}, {28,64}, {67,64}, {107,64}, {120,64}, {133,64}, {147,64}, {160,64}, {170,64}, {181,64}, {198,64}, {213,64}, + }, + { + // RGB LED Index to Flag + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + } +}; +#endif diff --git a/keyboards/keychron/k5_max/board.h b/keyboards/keychron/k5_max/board.h new file mode 100644 index 0000000000..b200f82d61 --- /dev/null +++ b/keyboards/keychron/k5_max/board.h @@ -0,0 +1,226 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once + +#include_next + +// clang-format off + +/* Set GPIOA_SWDIO to INPUT and NOT FLOATING */ +#undef VAL_GPIOA_MODER +#define VAL_GPIOA_MODER (PIN_MODE_INPUT(GPIOA_BUTTON) | \ + PIN_MODE_INPUT(GPIOA_PIN1) | \ + PIN_MODE_INPUT(GPIOA_PIN2) | \ + PIN_MODE_INPUT(GPIOA_PIN3) | \ + PIN_MODE_ALTERNATE(GPIOA_CS43L22_LRCK) |\ + PIN_MODE_ALTERNATE(GPIOA_L3GD20_SCL) | \ + PIN_MODE_ALTERNATE(GPIOA_L3GD20_SD0) | \ + PIN_MODE_ALTERNATE(GPIOA_L3GD20_SDI) | \ + PIN_MODE_INPUT(GPIOA_PIN8) | \ + PIN_MODE_INPUT(GPIOA_VBUS_FS) | \ + PIN_MODE_ALTERNATE(GPIOA_OTG_FS_ID) | \ + PIN_MODE_ALTERNATE(GPIOA_OTG_FS_DM) | \ + PIN_MODE_ALTERNATE(GPIOA_OTG_FS_DP) | \ + PIN_MODE_INPUT(GPIOA_SWDIO) | \ + PIN_MODE_INPUT(GPIOA_SWCLK) | \ + PIN_MODE_INPUT(GPIOA_PIN15)) + +#undef VAL_GPIOA_PUPDR +#define VAL_GPIOA_PUPDR (PIN_PUPDR_FLOATING(GPIOA_BUTTON) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN3) | \ + PIN_PUPDR_FLOATING(GPIOA_CS43L22_LRCK) |\ + PIN_PUPDR_FLOATING(GPIOA_L3GD20_SCL) | \ + PIN_PUPDR_PULLUP(GPIOA_L3GD20_SD0) | \ + PIN_PUPDR_PULLUP(GPIOA_L3GD20_SDI) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN8) | \ + PIN_PUPDR_FLOATING(GPIOA_VBUS_FS) | \ + PIN_PUPDR_FLOATING(GPIOA_OTG_FS_ID) | \ + PIN_PUPDR_FLOATING(GPIOA_OTG_FS_DM) | \ + PIN_PUPDR_FLOATING(GPIOA_OTG_FS_DP) | \ + PIN_PUPDR_PULLDOWN(GPIOA_SWDIO) | \ + PIN_PUPDR_PULLUP(GPIOA_SWCLK) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN15)) + +#undef VAL_GPIOB_MODER +#define VAL_GPIOB_MODER (PIN_MODE_INPUT(GPIOB_PIN0) | \ + PIN_MODE_INPUT(GPIOB_PIN1) | \ + PIN_MODE_INPUT(GPIOB_PIN2) | \ + PIN_MODE_INPUT(GPIOB_SWO) | \ + PIN_MODE_INPUT(GPIOB_PIN4) | \ + PIN_MODE_INPUT(GPIOB_PIN5) | \ + PIN_MODE_INPUT(GPIOB_LSM303DLHC_SCL) | \ + PIN_MODE_INPUT(GPIOB_PIN7) | \ + PIN_MODE_INPUT(GPIOB_PIN8) | \ + PIN_MODE_INPUT(GPIOB_LSM303DLHC_SDA) | \ + PIN_MODE_INPUT(GPIOB_MP45DT02_CLK_IN) |\ + PIN_MODE_INPUT(GPIOB_PIN11) | \ + PIN_MODE_INPUT(GPIOB_PIN12) | \ + PIN_MODE_INPUT(GPIOB_PIN13) | \ + PIN_MODE_INPUT(GPIOB_PIN14) | \ + PIN_MODE_INPUT(GPIOB_PIN15)) + +#undef VAL_GPIOB_PUPDR +#define VAL_GPIOB_PUPDR (PIN_PUPDR_PULLDOWN(GPIOB_PIN0) | \ + PIN_PUPDR_PULLDOWN(GPIOB_PIN1) | \ + PIN_PUPDR_PULLDOWN(GPIOB_PIN2) | \ + PIN_PUPDR_PULLDOWN(GPIOB_SWO) | \ + PIN_PUPDR_PULLDOWN(GPIOB_PIN4) | \ + PIN_PUPDR_PULLDOWN(GPIOB_PIN5) | \ + PIN_PUPDR_PULLDOWN(GPIOB_LSM303DLHC_SCL) |\ + PIN_PUPDR_PULLDOWN(GPIOB_PIN7) | \ + PIN_PUPDR_PULLDOWN(GPIOB_PIN8) | \ + PIN_PUPDR_PULLDOWN(GPIOB_LSM303DLHC_SDA) |\ + PIN_PUPDR_PULLDOWN(GPIOB_MP45DT02_CLK_IN) |\ + PIN_PUPDR_PULLDOWN(GPIOB_PIN11) | \ + PIN_PUPDR_PULLDOWN(GPIOB_PIN12) | \ + PIN_PUPDR_PULLDOWN(GPIOB_PIN13) | \ + PIN_PUPDR_PULLDOWN(GPIOB_PIN14) | \ + PIN_PUPDR_PULLDOWN(GPIOB_PIN15)) + +#undef VAL_GPIOB_AFRL +#define VAL_GPIOB_AFRL (PIN_AFIO_AF(GPIOB_PIN0, 0U) | \ + PIN_AFIO_AF(GPIOB_PIN1, 0U) | \ + PIN_AFIO_AF(GPIOB_PIN2, 0U) | \ + PIN_AFIO_AF(GPIOB_SWO, 0U) | \ + PIN_AFIO_AF(GPIOB_PIN4, 0U) | \ + PIN_AFIO_AF(GPIOB_PIN5, 0U) | \ + PIN_AFIO_AF(GPIOB_LSM303DLHC_SCL, 0) | \ + PIN_AFIO_AF(GPIOB_PIN7, 0U)) + +#undef VAL_GPIOB_AFRH +#define VAL_GPIOB_AFRH (PIN_AFIO_AF(GPIOB_PIN8, 0U) | \ + PIN_AFIO_AF(GPIOB_LSM303DLHC_SDA, 0) | \ + PIN_AFIO_AF(GPIOB_MP45DT02_CLK_IN, 0U) |\ + PIN_AFIO_AF(GPIOB_PIN11, 0U) | \ + PIN_AFIO_AF(GPIOB_PIN12, 0U) | \ + PIN_AFIO_AF(GPIOB_PIN13, 0U) | \ + PIN_AFIO_AF(GPIOB_PIN14, 0U) | \ + PIN_AFIO_AF(GPIOB_PIN15, 0U)) + +/* C5 Need to be pulldown */ +#undef VAL_GPIOC_MODER +#define VAL_GPIOC_MODER (PIN_MODE_INPUT(GPIOC_OTG_FS_POWER_ON) |\ + PIN_MODE_INPUT(GPIOC_PIN1) | \ + PIN_MODE_INPUT(GPIOC_PIN2) | \ + PIN_MODE_INPUT(GPIOC_CS43L22_AIN4x) | \ + PIN_MODE_INPUT(GPIOC_PIN4) | \ + PIN_MODE_INPUT(GPIOC_PIN5) | \ + PIN_MODE_INPUT(GPIOC_PIN6) | \ + PIN_MODE_INPUT(GPIOC_CS43L22_MCLK) | \ + PIN_MODE_INPUT(GPIOC_PIN8) | \ + PIN_MODE_INPUT(GPIOC_PIN9) | \ + PIN_MODE_INPUT(GPIOC_CS43L22_SCLK) | \ + PIN_MODE_INPUT(GPIOC_PIN11) | \ + PIN_MODE_INPUT(GPIOC_CS43L22_SDIN) | \ + PIN_MODE_INPUT(GPIOC_PIN13) | \ + PIN_MODE_INPUT(GPIOC_OSC32_IN) | \ + PIN_MODE_INPUT(GPIOC_OSC32_OUT)) + +#undef VAL_GPIOC_PUPDR +#define VAL_GPIOC_PUPDR (PIN_PUPDR_PULLUP(GPIOC_OTG_FS_POWER_ON) |\ + PIN_PUPDR_PULLUP(GPIOC_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOC_CS43L22_AIN4x) |\ + PIN_PUPDR_PULLUP(GPIOC_PIN4) | \ + PIN_PUPDR_PULLDOWN(GPIOC_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOC_CS43L22_MCLK) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOC_CS43L22_SCLK) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOC_CS43L22_SDIN) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN13) | \ + PIN_PUPDR_PULLUP(GPIOC_OSC32_IN) | \ + PIN_PUPDR_PULLUP(GPIOC_OSC32_OUT)) + +/* Set all GPIOD pins to INPUT & PULLUP to avoid FLOATING */ +#undef VAL_GPIOD_MODER +#define VAL_GPIOD_MODER (PIN_MODE_INPUT(GPIOD_PIN0) | \ + PIN_MODE_INPUT(GPIOD_PIN1) | \ + PIN_MODE_INPUT(GPIOD_PIN2) | \ + PIN_MODE_INPUT(GPIOD_PIN3) | \ + PIN_MODE_INPUT(GPIOD_CS43L22_RESET) | \ + PIN_MODE_INPUT(GPIOD_OverCurrent) | \ + PIN_MODE_INPUT(GPIOD_PIN6) | \ + PIN_MODE_INPUT(GPIOD_PIN7) | \ + PIN_MODE_INPUT(GPIOD_PIN8) | \ + PIN_MODE_INPUT(GPIOD_PIN9) | \ + PIN_MODE_INPUT(GPIOD_PIN10) | \ + PIN_MODE_INPUT(GPIOD_PIN11) | \ + PIN_MODE_INPUT(GPIOD_LED4) | \ + PIN_MODE_INPUT(GPIOD_LED3) | \ + PIN_MODE_INPUT(GPIOD_LED5) | \ + PIN_MODE_INPUT(GPIOD_LED6)) + +#undef VAL_GPIOD_PUPDR +#define VAL_GPIOD_PUPDR (PIN_PUPDR_PULLUP(GPIOD_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOD_CS43L22_RESET) |\ + PIN_PUPDR_PULLUP(GPIOD_OverCurrent) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOD_LED4) | \ + PIN_PUPDR_PULLUP(GPIOD_LED3) | \ + PIN_PUPDR_PULLUP(GPIOD_LED5) | \ + PIN_PUPDR_PULLUP(GPIOD_LED6)) + +/* Set all GPIOE pins to INPUT & PULLUP to avoid FLOATING */ +#undef VAL_GPIOE_MODER +#define VAL_GPIOE_MODER (PIN_MODE_INPUT(GPIOE_L3GD20_INT1) | \ + PIN_MODE_INPUT(GPIOE_L3GD20_INT2) | \ + PIN_MODE_INPUT(GPIOE_LSM303DLHC_DRDY) |\ + PIN_MODE_INPUT(GPIOE_L3GD20_CS) | \ + PIN_MODE_INPUT(GPIOE_LSM303DLHC_INT1) |\ + PIN_MODE_INPUT(GPIOE_LSM303DLHC_INT2) |\ + PIN_MODE_INPUT(GPIOE_PIN6) | \ + PIN_MODE_INPUT(GPIOE_PIN7) | \ + PIN_MODE_INPUT(GPIOE_PIN8) | \ + PIN_MODE_INPUT(GPIOE_PIN9) | \ + PIN_MODE_INPUT(GPIOE_PIN10) | \ + PIN_MODE_INPUT(GPIOE_PIN11) | \ + PIN_MODE_INPUT(GPIOE_PIN12) | \ + PIN_MODE_INPUT(GPIOE_PIN13) | \ + PIN_MODE_INPUT(GPIOE_PIN14) | \ + PIN_MODE_INPUT(GPIOE_PIN15)) + +#undef VAL_GPIOE_PUPDR +#define VAL_GPIOE_PUPDR (PIN_PUPDR_PULLUP(GPIOE_L3GD20_INT1) | \ + PIN_PUPDR_PULLUP(GPIOE_L3GD20_INT2) | \ + PIN_PUPDR_PULLUP(GPIOE_LSM303DLHC_DRDY) |\ + PIN_PUPDR_PULLUP(GPIOE_L3GD20_CS) | \ + PIN_PUPDR_PULLUP(GPIOE_LSM303DLHC_INT1) |\ + PIN_PUPDR_PULLUP(GPIOE_LSM303DLHC_INT2) |\ + PIN_PUPDR_PULLUP(GPIOE_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN13) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN14) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN15)) + diff --git a/keyboards/keychron/k5_max/config.h b/keyboards/keychron/k5_max/config.h new file mode 100644 index 0000000000..ffabc3b3bc --- /dev/null +++ b/keyboards/keychron/k5_max/config.h @@ -0,0 +1,93 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once + +/* Caps lock LED */ +#define LED_CAPS_LOCK_PIN A13 +#define LED_PIN_ON_STATE 1 + +#ifdef LK_WIRELESS_ENABLE +/* Hardware configuration */ +# define P2P4_MODE_SELECT_PIN A10 +# define BT_MODE_SELECT_PIN A9 + +# define LKBT51_RESET_PIN C4 +# define LKBT51_INT_INPUT_PIN B1 +# define BLUETOOTH_INT_OUTPUT_PIN A4 + +# define USB_POWER_SENSE_PIN B0 +# define USB_POWER_CONNECTED_LEVEL 0 + +# define BAT_CHARGING_PIN B13 +# define BAT_CHARGING_LEVEL 0 + +# define BAT_LOW_LED_PIN B12 +# define BAT_LOW_LED_PIN_ON_STATE 1 + +# define BT_HOST_DEVICES_COUNT 3 + +# define BT_HOST_LED_PIN_LIST \ + { C9, C9, C9 } +# define HOST_LED_PIN_ON_STATE 0 + +# define P24G_HOST_DEVICES_COUNT 1 + +# define P24G_HOST_LED_PIN_LIST \ + { A8 } + +# if defined(RGB_MATRIX_ENABLE) || defined(LED_MATRIX_ENABLE) + +# define LED_DRIVER_SHUTDOWN_PIN B7 + +# define BT_HOST_LED_MATRIX_LIST \ + { 21, 22, 23 } + +# define P2P4G_HOST_LED_MATRIX_LIST \ + { 24 } + +# define BAT_LEVEL_LED_LIST \ + { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 } + +/* Backlit disable timeout when keyboard is disconnected(unit: second) */ +# define DISCONNECTED_BACKLIGHT_DISABLE_TIMEOUT 40 + +/* Backlit disable timeout when keyboard is connected(unit: second) */ +# define CONNECTED_BACKLIGHT_DISABLE_TIMEOUT 600 + +/* Reinit LED driver on tranport changed */ +# define REINIT_LED_DRIVER 1 + +# endif + +/* Keep USB connection in blueooth mode */ +# define KEEP_USB_CONNECTION_IN_WIRELESS_MODE + +/* Enable bluetooth NKRO */ +# define WIRELESS_NKRO_ENABLE + +/* Raw hid command for factory test and bluetooth DFU */ +# define RAW_HID_CMD 0xAA ... 0xAB +#else +/* Raw hid command for factory test */ +# define RAW_HID_CMD 0xAB +#endif + +/* Factory test keys */ +#define FN_KEY_1 MO(1) +#define FN_KEY_2 MO(3) + +#define MATRIX_IO_DELAY 10 diff --git a/keyboards/keychron/k5_max/firmware/keychron_k5_max_ansi_rgb_via.bin b/keyboards/keychron/k5_max/firmware/keychron_k5_max_ansi_rgb_via.bin new file mode 100644 index 0000000000000000000000000000000000000000..bb550195a0837c35a357a7f67e8e2ed49bafaa1a GIT binary patch literal 95948 zcmeFadwkQ?{Xc%*mn83`X&ZWhwiHN{f}!COC~6hdkkofeQz%}?M{pKVS7e)E`q?Ml z{ET3A*4spJ8-h#}-3LWy6Re|Z4T?^kIupcwT5-Yz4Yuk|X(8_>ZQj4*xE| z@1K;%$@|l}zktW!1;Y1;q6l~!>7G~d~^oU|Qoyq>pbbJ74@=^Rd4 z47V2U?P|oqO#Z>0T` zcF)XHaW?u2_n&Z&!Mz7}X8M`_RyQY|M0&+JoU|0~%(VZ%{3QFAg+LYpSqNkykcB`N z0$B)TA&`YY76MraWFe4+Ko$a72xK9Ug+LYpSqNkykcB`N0$B)TA&`YY76MraWFe4+ zKo$a72xK9Ug+LYpSqNkykcB`N0$B)TA&`YY76MraWFe4+Ko$a72xK9Ug+LYpSqNky zkcB`N0$B)TA&`YY76MraWFe4+Ko$a72xK9Ug+LYpSqNkykcB`N0$B)TA&`YY76Mra zWFe4+Ko$a72xK9Ug+LYpSqNkykcB`N0$B)TA&`YY76MraWFe4+Ko$a72xK9Ug+LYp zSqNkykcB`N0$B)TA&`YY76MraWFe4+Ko$a72xK9Ug+LYpSqNkykcB`N0$B)TA&`YY z76MraWFhc>g1`@6IJZ7HD7Bx1Un73cSt2#NPZ07h+_F;(*8kxI;iTrsVAK7P!JF=9 zDf>=Pq_ki1&6Fle$e+Kqn3kPdG*(7$4GtEy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ynn%omea~N;Ci*!taTiefJ_*QQC_)GBTV3RD zd~6UDsC&Q+C7TqK$QBCeaxR9_P94^?fe(Qbz-a)^y~-~sNUt}oUmY=ghq&kE8<-w*0D~WtGvPS!UjUb}cs$p9 c@BASV-@vcO6aLvo1+gm2EZsN%y>#;b039aiy8r+H literal 0 HcmV?d00001 diff --git a/keyboards/keychron/k5_max/firmware/keychron_k5_max_ansi_white_via.bin b/keyboards/keychron/k5_max/firmware/keychron_k5_max_ansi_white_via.bin new file mode 100644 index 0000000000000000000000000000000000000000..ed6cd28b1c67650d0eb3fd25f9cc2c66dea33fc5 GIT binary patch literal 87200 zcmeFaeSB2K^*=uMVIQ)2T9N=E39#7>xMV>B!5Rg1*^M_L8wjFSDpZ4L8>Fpkwe3=E zS&Y_LYXzY#g0?8M9~7M1xg3r@0pC*{UiSRRo zE`$#dF0Viw!ovuEKMp>Hiu3?th8+NhM7vr#jDL2cq!S5041+OWm5D6&|U zvxnnTmlU7#Rf4oq-ww~Ekt>kuK~Uq&R{VuLX8z8InfHtoHBMamlt+5=Dpf9Rs~d{T z{ClYhjRjwbGxI+lWHPg{90bP9=1UBip{3$xzAwd&r{auV+1b#^ zW|Lwo5V}k)~+hq6W*UxxjAXAuI-g-S<;mFA3e7$ zvwp2Q$Ss@x2f0m~Zmbn++`UHk`=xB=)X?j0=J>A8tLv&Toj_?-5_S%fn6$1@A6d12_cRFBLZDL=<_Ky&V@jwRfmrtkTUN3O?4C zBcLaB=tD}FY0C*E69cAX;RJWDusAO%@ivbceGvqyU#k(1w4v6&2E9ra`hlF>l(bH$ z?Gu;Kn`yt>K5QCk?3HqC!=^!D z*f>z;9U@FFVR#QEhg4e*L6Vg$)*&z_^8kT3Y&?~%Lt*aME)MdxU>k6BPjGL)XkJsB zhGmFnrD0jjl6k40>aYj`aJt|dM}B(w%{^kxnp$_S*}W?%ZhNdRPk7ApXXQ7_mtVUw z`qj|>KC`$6al)`EVFw)j?&)6O>Q**0jaQ7l)a|B`FCUf$w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02}Sz;($KO{d1(0x;7KCXc!nzAA`lO)1`x;uc^>x35}e!1L0PyR=jHp^qijFU z$Bpa=JI-3@v>6u@H#*K3mlro9?z*_LxEtes7*`c{d)&sjhvW9gJr~y)cO>q3TuWSg zoM6x!42CR&#c++G#IV3n4x(9&VS{0-VTWPA;W=oHR%3h!S>NGUKCOfI;(z*ca5!S@R)3f2_dRq#N;a|K5V zju*5Pv|qznl5cbKs}0C5^z!~0AJ_~OSH ztSu=Xo@DGu#ap@L=nQV5E=M3_2w868IAA`|9RT+j+!Jt!mVevm&YO<8 a4|f+_D3tK&7MRPs$x*Do^Dp0P`Tqd;L{a?! literal 0 HcmV?d00001 diff --git a/keyboards/keychron/k5_max/firmware/keychron_k5_max_iso_rgb_via.bin b/keyboards/keychron/k5_max/firmware/keychron_k5_max_iso_rgb_via.bin new file mode 100644 index 0000000000000000000000000000000000000000..e363a3a96c86a1eb2cbc0ee9debe5ea39bfe642f GIT binary patch literal 95956 zcmeFae|(eG**|{nA4%?{X&d?j+fpD+3WkOsfudGH4N1LQnnLmCc!bR&>WXeNOrJgJ z<}-rTS#?enw^fjdqI*zuHo-b7mZ0d=xy=N1Pb*G3L8Gm@Q(DN~q|N<(pF1tX{d_)u zeg8>$o!sa5kLz6LI@h_b>l}zktkX9WY3BdIl~!>7G~YS3oU{XOvYt2RancZ6>3mLF z2Dbt3&1%HKO<&AO%i;bLZU@|(aFgZE{62s(XNH;o`UQU<_qTb@44*_D@14=FucZBx zcF)XHaSr+l_n&Z&!TlcY%=9z;t!_>_iS&wdIcWvlnQ8xj`APOK3xO;IvJl8ZAPa#k z1hNpwLLdu)ECjL;$U-0sfh+{F5XeFx3xO;IvJl8ZAPa#k1hNpwLLdu)ECjL;$U-0s zfh+{F5XeFx3xO;IvJl8ZAPa#k1hNpwLLdu)ECjL;$U-0sfh+{F5XeFx3xO;IvJl8Z zAPa#k1hNpwLLdu)ECjL;$U-0sfh+{F5XeFx3xO;IvJl8ZAPa#k1hNpwLLdu)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<8s*%E+w}ty1c{C0ehFdPAb) z)VcZ^gb9F!qI8K?X=Yj_S|2v6QljI+Z)pOp1&Fk_Zk1?NL}|A~>vd&sNOWAJji5GU zFrh4)36}vY3auVvTMl08o1kxkZp91F+tLNI#Z?YZeOohX+rDmpLF2RNTe^@{28NsW zRM5UKxC|(6w-4%jLs3|ByNYEM6@I&gWG59bnSk=!RlqJ%G8xy$?5@*saJz-vUx=Nn z-P1~Sp89$sQBvt#NiXC2R{hl~*!@Ban$Pwtsk;u<0}hJ)O6tW!b#5I9(ysoRSiZ(sPO2iCIoFuySS&>=F|g0i&&w}bnLiy8MgH`HJWFm%vop8BwXWV%EomT~xh<_V+^E^n zP&3s@kU@eXh@;vG31hX}QwtfRp|R;F%`L5MYuB}}e}J;ZRc#Hm^%MyjL1vY}n}9%&WnuQWl9?5lc97!dI**?i)_hA6nD2Wc*qE>eiIfYZetGl< z#8KZowD0oy3w&HCUCgD@dn=dus(j0RD57poI>nYu#V9lCkCrMi{6T3xGdqi&n7TenZwqwCY1 z&<*N_baI282St+41F+pSxyPg%RI`>Z|I-&zN)p?6Sus+^v1p25O z4j{w>=ix73aWlb*A)da* zoedadiz5IxF4YHgPX8Qq8Rr9V02Sb8J+M85FYfNgD4s$6h-XsN59c8&*i9=b-(HIe zl!X`)(#-^`#khcn$;*?6^^rK9U$2Mc9jtChU7OCaii1#YHk}N9c{+JmTlq9>P>INE ziM~-iG@WG=m=MDL4X2Z*kLM@nPs-0XLehCUSSN2ZjX%cywdt7~!r=QQIBysDZ-C2L fJf5rmd;XY+ujAL}i~4l4f>?#ERNsFf;l=*}!>sHg literal 0 HcmV?d00001 diff --git a/keyboards/keychron/k5_max/firmware/keychron_k5_max_iso_white_via.bin b/keyboards/keychron/k5_max/firmware/keychron_k5_max_iso_white_via.bin new file mode 100644 index 0000000000000000000000000000000000000000..d1768dbf99f54bbc4bd7dd2133ad6f90eb222481 GIT binary patch literal 87208 zcmeFae|*!`^*?@JKk}pLuh0}IZGki?7#f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>EEe#3h+~^linxQ^)?aOLcbSA!7d#4-}Nu==V$=`yZz+QIQ5h2s(~&`$_#Hcv87AJf9iW&$iH<{FgiVzfj=v{uGRQzYAt!?!(;$7YxRI SvJGbQZgLbEzR9h+>wf^(Az>T< literal 0 HcmV?d00001 diff --git a/keyboards/keychron/k5_max/halconf.h b/keyboards/keychron/k5_max/halconf.h new file mode 100644 index 0000000000..37bcc7c47b --- /dev/null +++ b/keyboards/keychron/k5_max/halconf.h @@ -0,0 +1,31 @@ +/* Copyright 2024 @ 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 + +#define _CHIBIOS_HAL_CONF_VER_8_0_ + +#define HAL_USE_SPI TRUE + +#ifdef LK_WIRELESS_ENABLE +# define HAL_USE_RTC TRUE +#endif + +#if defined(LK_WIRELESS_ENABLE) || defined(ENCODER_ENABLE) +# define PAL_USE_CALLBACKS TRUE +#endif + +#include_next diff --git a/keyboards/keychron/k5_max/info.json b/keyboards/keychron/k5_max/info.json new file mode 100644 index 0000000000..0b331454a3 --- /dev/null +++ b/keyboards/keychron/k5_max/info.json @@ -0,0 +1,272 @@ +{ + "keyboard_name": "Keychron K5 Max", + "manufacturer": "Keychron", + "url": "https://github.com/Keychron", + "maintainer": "lokher", + "processor": "STM32F401", + "bootloader": "stm32-dfu", + "usb": { + "vid": "0x3434" + }, + "features": { + "bootmagic": true, + "extrakey": true, + "mousekey": true, + "dip_switch": true, + "nkro": true, + "raw": true, + "send_string": true + }, + "matrix_pins": { + "cols": ["C6", "C7", "C8", "A14", "A15", "C10", "C11", "C13", "C14", "C15", "C0", "C1", "C2", "C3", "A0", "A1", "A2", "A3", "C5", "B10", "B15"], + "rows": ["C12", "D2", "B3", "B4", "B5", "B6"] + }, + "diode_direction": "ROW2COL", + "dip_switch": { + "pins": ["B14"] + }, + "eeprom": { + "wear_leveling": { + "driver": "embedded_flash", + "logical_size": 2048, + "backing_size": 4096 + } + }, + "layouts": { + "LAYOUT_108_ansi": { + "layout": [ + {"matrix":[0,0], "x":0, "y":0}, + {"matrix":[0,1], "x":2, "y":0}, + {"matrix":[0,2], "x":3, "y":0}, + {"matrix":[0,3], "x":4, "y":0}, + {"matrix":[0,4], "x":5, "y":0}, + {"matrix":[0,5], "x":6.5, "y":0}, + {"matrix":[0,6], "x":7.5, "y":0}, + {"matrix":[0,7], "x":8.5, "y":0}, + {"matrix":[0,8], "x":9.5, "y":0}, + {"matrix":[0,9], "x":11, "y":0}, + {"matrix":[0,10], "x":12, "y":0}, + {"matrix":[0,11], "x":13, "y":0}, + {"matrix":[0,12], "x":14, "y":0}, + {"matrix":[0,14], "x":15.25, "y":0}, + {"matrix":[0,15], "x":16.25, "y":0}, + {"matrix":[0,16], "x":17.25, "y":0}, + {"matrix":[0,17], "x":18.5, "y":0}, + {"matrix":[0,18], "x":19.5, "y":0}, + {"matrix":[0,19], "x":20.5, "y":0}, + {"matrix":[0,20], "x":21.5, "y":0}, + + {"matrix":[1,0], "x":0, "y":1.25}, + {"matrix":[1,1], "x":1, "y":1.25}, + {"matrix":[1,2], "x":2, "y":1.25}, + {"matrix":[1,3], "x":3, "y":1.25}, + {"matrix":[1,4], "x":4, "y":1.25}, + {"matrix":[1,5], "x":5, "y":1.25}, + {"matrix":[1,6], "x":6, "y":1.25}, + {"matrix":[1,7], "x":7, "y":1.25}, + {"matrix":[1,8], "x":8, "y":1.25}, + {"matrix":[1,9], "x":9, "y":1.25}, + {"matrix":[1,10], "x":10, "y":1.25}, + {"matrix":[1,11], "x":11, "y":1.25}, + {"matrix":[1,12], "x":12, "y":1.25}, + {"matrix":[1,13], "x":13, "y":1.25, "w":2}, + {"matrix":[1,14], "x":15.25, "y":1.25}, + {"matrix":[1,15], "x":16.25, "y":1.25}, + {"matrix":[1,16], "x":17.25, "y":1.25}, + {"matrix":[1,17], "x":18.5, "y":1.25}, + {"matrix":[1,18], "x":19.5, "y":1.25}, + {"matrix":[1,19], "x":20.5, "y":1.25}, + {"matrix":[1,20], "x":21.5, "y":1.25}, + + {"matrix":[2,0], "x":0, "y":2.25, "w":1.5}, + {"matrix":[2,1], "x":1.5, "y":2.25}, + {"matrix":[2,2], "x":2.5, "y":2.25}, + {"matrix":[2,3], "x":3.5, "y":2.25}, + {"matrix":[2,4], "x":4.5, "y":2.25}, + {"matrix":[2,5], "x":5.5, "y":2.25}, + {"matrix":[2,6], "x":6.5, "y":2.25}, + {"matrix":[2,7], "x":7.5, "y":2.25}, + {"matrix":[2,8], "x":8.5, "y":2.25}, + {"matrix":[2,9], "x":9.5, "y":2.25}, + {"matrix":[2,10], "x":10.5, "y":2.25}, + {"matrix":[2,11], "x":11.5, "y":2.25}, + {"matrix":[2,12], "x":12.5, "y":2.25}, + {"matrix":[2,13], "x":13.5, "y":2.25, "w":1.5}, + {"matrix":[2,14], "x":15.25, "y":2.25}, + {"matrix":[2,15], "x":16.25, "y":2.25}, + {"matrix":[2,16], "x":17.25, "y":2.25}, + {"matrix":[2,17], "x":18.5, "y":2.25}, + {"matrix":[2,18], "x":19.5, "y":2.25}, + {"matrix":[2,19], "x":20.5, "y":2.25}, + + {"matrix":[3,0], "x":0, "y":3.25, "w":1.75}, + {"matrix":[3,1], "x":1.75, "y":3.25}, + {"matrix":[3,2], "x":2.75, "y":3.25}, + {"matrix":[3,3], "x":3.75, "y":3.25}, + {"matrix":[3,4], "x":4.75, "y":3.25}, + {"matrix":[3,5], "x":5.75, "y":3.25}, + {"matrix":[3,6], "x":6.75, "y":3.25}, + {"matrix":[3,7], "x":7.75, "y":3.25}, + {"matrix":[3,8], "x":8.75, "y":3.25}, + {"matrix":[3,9], "x":9.75, "y":3.25}, + {"matrix":[3,10], "x":10.75, "y":3.25}, + {"matrix":[3,11], "x":11.75, "y":3.25}, + {"matrix":[3,13], "x":12.75, "y":3.25, "w":2.25}, + {"matrix":[3,17], "x":18.5, "y":3.25}, + {"matrix":[3,18], "x":19.5, "y":3.25}, + {"matrix":[3,19], "x":20.5, "y":3.25}, + {"matrix":[2,20], "x":21.5, "y":2.25, "h":2}, + + {"matrix":[4,0], "x":0, "y":4.25, "w":2.25}, + {"matrix":[4,2], "x":2.25, "y":4.25}, + {"matrix":[4,3], "x":3.25, "y":4.25}, + {"matrix":[4,4], "x":4.25, "y":4.25}, + {"matrix":[4,5], "x":5.25, "y":4.25}, + {"matrix":[4,6], "x":6.25, "y":4.25}, + {"matrix":[4,7], "x":7.25, "y":4.25}, + {"matrix":[4,8], "x":8.25, "y":4.25}, + {"matrix":[4,9], "x":9.25, "y":4.25}, + {"matrix":[4,10], "x":10.25, "y":4.25}, + {"matrix":[4,11], "x":11.25, "y":4.25}, + {"matrix":[4,13], "x":12.25, "y":4.25, "w":2.75}, + {"matrix":[4,15], "x":16.25, "y":4.25}, + {"matrix":[4,17], "x":18.5, "y":4.25}, + {"matrix":[4,18], "x":19.5, "y":4.25}, + {"matrix":[4,19], "x":20.5, "y":4.25}, + + {"matrix":[5,0], "x":0, "y":5.25, "w":1.25}, + {"matrix":[5,1], "x":1.25, "y":5.25, "w":1.25}, + {"matrix":[5,2], "x":2.5, "y":5.25, "w":1.25}, + {"matrix":[5,6], "x":3.75, "y":5.25, "w":6.25}, + {"matrix":[5,10], "x":10, "y":5.25, "w":1.25}, + {"matrix":[5,11], "x":11.25, "y":5.25, "w":1.25}, + {"matrix":[5,12], "x":12.5, "y":5.25, "w":1.25}, + {"matrix":[5,13], "x":13.75, "y":5.25, "w":1.25}, + {"matrix":[5,14], "x":15.25, "y":5.25}, + {"matrix":[5,15], "x":16.25, "y":5.25}, + {"matrix":[5,16], "x":17.25, "y":5.25}, + {"matrix":[5,17], "x":18.5, "y":5.25, "w":2}, + {"matrix":[5,19], "x":20.5, "y":5.25} + {"matrix":[4,20], "x":21.5, "y":4.25, "h":2}, + ] + }, + "LAYOUT_109_iso": { + "layout": [ + {"matrix":[0,0], "x":0, "y":0}, + {"matrix":[0,1], "x":2, "y":0}, + {"matrix":[0,2], "x":3, "y":0}, + {"matrix":[0,3], "x":4, "y":0}, + {"matrix":[0,4], "x":5, "y":0}, + {"matrix":[0,5], "x":6.5, "y":0}, + {"matrix":[0,6], "x":7.5, "y":0}, + {"matrix":[0,7], "x":8.5, "y":0}, + {"matrix":[0,8], "x":9.5, "y":0}, + {"matrix":[0,9], "x":11, "y":0}, + {"matrix":[0,10], "x":12, "y":0}, + {"matrix":[0,11], "x":13, "y":0}, + {"matrix":[0,12], "x":14, "y":0}, + {"matrix":[0,14], "x":15.25, "y":0}, + {"matrix":[0,15], "x":16.25, "y":0}, + {"matrix":[0,16], "x":17.25, "y":0}, + {"matrix":[0,17], "x":18.5, "y":0}, + {"matrix":[0,18], "x":19.5, "y":0}, + {"matrix":[0,19], "x":20.5, "y":0}, + {"matrix":[0,20], "x":21.5, "y":0}, + + {"matrix":[1,0], "x":0, "y":1.25}, + {"matrix":[1,1], "x":1, "y":1.25}, + {"matrix":[1,2], "x":2, "y":1.25}, + {"matrix":[1,3], "x":3, "y":1.25}, + {"matrix":[1,4], "x":4, "y":1.25}, + {"matrix":[1,5], "x":5, "y":1.25}, + {"matrix":[1,6], "x":6, "y":1.25}, + {"matrix":[1,7], "x":7, "y":1.25}, + {"matrix":[1,8], "x":8, "y":1.25}, + {"matrix":[1,9], "x":9, "y":1.25}, + {"matrix":[1,10], "x":10, "y":1.25}, + {"matrix":[1,11], "x":11, "y":1.25}, + {"matrix":[1,12], "x":12, "y":1.25}, + {"matrix":[1,13], "x":13, "y":1.25, "w":2}, + {"matrix":[1,14], "x":15.25, "y":1.25}, + {"matrix":[1,15], "x":16.25, "y":1.25}, + {"matrix":[1,16], "x":17.25, "y":1.25}, + {"matrix":[1,17], "x":18.5, "y":1.25}, + {"matrix":[1,18], "x":19.5, "y":1.25}, + {"matrix":[1,19], "x":20.5, "y":1.25}, + {"matrix":[1,20], "x":21.5, "y":1.25}, + + {"matrix":[2,0], "x":0, "y":2.25, "w":1.5}, + {"matrix":[2,1], "x":1.5, "y":2.25}, + {"matrix":[2,2], "x":2.5, "y":2.25}, + {"matrix":[2,3], "x":3.5, "y":2.25}, + {"matrix":[2,4], "x":4.5, "y":2.25}, + {"matrix":[2,5], "x":5.5, "y":2.25}, + {"matrix":[2,6], "x":6.5, "y":2.25}, + {"matrix":[2,7], "x":7.5, "y":2.25}, + {"matrix":[2,8], "x":8.5, "y":2.25}, + {"matrix":[2,9], "x":9.5, "y":2.25}, + {"matrix":[2,10], "x":10.5, "y":2.25}, + {"matrix":[2,11], "x":11.5, "y":2.25}, + {"matrix":[2,12], "x":12.5, "y":2.25}, + {"matrix":[2,14], "x":15.25, "y":2.25}, + {"matrix":[2,15], "x":16.25, "y":2.25}, + {"matrix":[2,16], "x":17.25, "y":2.25}, + {"matrix":[2,17], "x":18.5, "y":2.25}, + {"matrix":[2,18], "x":19.5, "y":2.25}, + {"matrix":[2,19], "x":20.5, "y":2.25}, + + {"matrix":[3,0], "x":0, "y":3.25, "w":1.75}, + {"matrix":[3,1], "x":1.75, "y":3.25}, + {"matrix":[3,2], "x":2.75, "y":3.25}, + {"matrix":[3,3], "x":3.75, "y":3.25}, + {"matrix":[3,4], "x":4.75, "y":3.25}, + {"matrix":[3,5], "x":5.75, "y":3.25}, + {"matrix":[3,6], "x":6.75, "y":3.25}, + {"matrix":[3,7], "x":7.75, "y":3.25}, + {"matrix":[3,8], "x":8.75, "y":3.25}, + {"matrix":[3,9], "x":9.75, "y":3.25}, + {"matrix":[3,10], "x":10.75, "y":3.25}, + {"matrix":[3,11], "x":11.75, "y":3.25}, + {"matrix":[3,13], "x":12.75, "y":3.25}, + {"matrix":[2,13], "x":13.75, "y":2.25, "w":1.25, "h":2}, + {"matrix":[3,17], "x":18.5, "y":3.25}, + {"matrix":[3,18], "x":19.5, "y":3.25}, + {"matrix":[3,19], "x":20.5, "y":3.25}, + {"matrix":[2,20], "x":21.5, "y":2.25, "h":2}, + + {"matrix":[4,0], "x":0, "y":4.25, "w":1.25}, + {"matrix":[4,1], "x":1.25, "y":4.25}, + {"matrix":[4,2], "x":2.25, "y":4.25}, + {"matrix":[4,3], "x":3.25, "y":4.25}, + {"matrix":[4,4], "x":4.25, "y":4.25}, + {"matrix":[4,5], "x":5.25, "y":4.25}, + {"matrix":[4,6], "x":6.25, "y":4.25}, + {"matrix":[4,7], "x":7.25, "y":4.25}, + {"matrix":[4,8], "x":8.25, "y":4.25}, + {"matrix":[4,9], "x":9.25, "y":4.25}, + {"matrix":[4,10], "x":10.25, "y":4.25}, + {"matrix":[4,11], "x":11.25, "y":4.25}, + {"matrix":[4,13], "x":12.25, "y":4.25, "w":2.75}, + {"matrix":[4,15], "x":16.25, "y":4.25}, + {"matrix":[4,17], "x":18.5, "y":4.25}, + {"matrix":[4,18], "x":19.5, "y":4.25}, + {"matrix":[4,19], "x":20.5, "y":4.25}, + + {"matrix":[5,0], "x":0, "y":5.25, "w":1.25}, + {"matrix":[5,1], "x":1.25, "y":5.25, "w":1.25}, + {"matrix":[5,2], "x":2.5, "y":5.25, "w":1.25}, + {"matrix":[5,6], "x":3.75, "y":5.25, "w":6.25}, + {"matrix":[5,10], "x":10, "y":5.25, "w":1.25}, + {"matrix":[5,11], "x":11.25, "y":5.25, "w":1.25}, + {"matrix":[5,12], "x":12.5, "y":5.25, "w":1.25}, + {"matrix":[5,13], "x":13.75, "y":5.25, "w":1.25}, + {"matrix":[5,14], "x":15.25, "y":5.25}, + {"matrix":[5,15], "x":16.25, "y":5.25}, + {"matrix":[5,16], "x":17.25, "y":5.25}, + {"matrix":[5,17], "x":18.5, "y":5.25, "w":2}, + {"matrix":[5,19], "x":20.5, "y":5.25}, + {"matrix":[4,20], "x":21.5, "y":4.25, "h":2} + ] + } + } +} diff --git a/keyboards/keychron/k5_max/iso/rgb/config.h b/keyboards/keychron/k5_max/iso/rgb/config.h new file mode 100644 index 0000000000..9e495ebabd --- /dev/null +++ b/keyboards/keychron/k5_max/iso/rgb/config.h @@ -0,0 +1,55 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once + +#ifdef RGB_MATRIX_ENABLE +/* RGB Matrix driver configuration */ +# define DRIVER_COUNT 2 +# define RGB_MATRIX_LED_COUNT 109 + +# define SPI_SCK_PIN A5 +# define SPI_MISO_PIN A6 +# define SPI_MOSI_PIN A7 + +# define DRIVER_CS_PINS \ + { B8, B9 } +# define SNLED23751_SPI_DIVISOR 16 +# define SPI_DRIVER SPID1 + +/* Scan phase of led driver set as MSKPHASE_12CHANNEL(defined as 0x03 in snled27351.h) */ +# define SNLED27351_PHASE_CHANNEL MSKPHASE_12CHANNEL + +/* Set LED driver current */ +# define SNLED27351_CURRENT_TUNE \ + { 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12 } + +/* Set to infinit, which is use in USB mode by default */ +# define RGB_MATRIX_TIMEOUT RGB_MATRIX_TIMEOUT_INFINITE + +/* Allow shutdown of led driver to save power */ +# define RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE +/* Turn off backlight on low brightness to save power */ +# define RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL 48 + +/* Indications */ +# define LOW_BAT_IND_INDEX \ + { 99 } + +# define RGB_MATRIX_KEYPRESSES +# define RGB_MATRIX_FRAMEBUFFER_EFFECTS + +#endif diff --git a/keyboards/keychron/k5_max/iso/rgb/info.json b/keyboards/keychron/k5_max/iso/rgb/info.json new file mode 100644 index 0000000000..5be8112bad --- /dev/null +++ b/keyboards/keychron/k5_max/iso/rgb/info.json @@ -0,0 +1,36 @@ +{ + "usb": { + "pid": "0x0A51", + "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/iso/rgb/keymaps/default/keymap.c b/keyboards/keychron/k5_max/iso/rgb/keymaps/default/keymap.c new file mode 100644 index 0000000000..9972f8a49d --- /dev/null +++ b/keyboards/keychron/k5_max/iso/rgb/keymaps/default/keymap.c @@ -0,0 +1,68 @@ +/* Copyright 2024 @ 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 . + */ + +#include QMK_KEYBOARD_H +#include "keychron_common.h" + +enum layers { + MAC_BASE, + MAC_FN, + WIN_BASE, + WIN_FN, +}; + +// clang-format off +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [MAC_BASE] = LAYOUT_109_iso( + KC_ESC, KC_BRID, KC_BRIU, KC_MCTRL, KC_LNPAD, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, KC_SNAP, KC_SIRI, RGB_MOD, KC_F13, KC_F14, KC_F15, KC_F16, + 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_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_NUHS, KC_ENT, KC_P4, KC_P5, KC_P6, KC_PPLS, + KC_LSFT, KC_NUBS, 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_LOPTN, KC_LCMMD, KC_SPC, KC_RCMMD, KC_ROPTN,MO(MAC_FN),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT, KC_PENT), + + [MAC_FN] = LAYOUT_109_iso( + _______, 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, _______, _______, _______, _______, + _______, BT_HST1, BT_HST2, BT_HST3, P2P4G, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______), + + [WIN_BASE] = LAYOUT_109_iso( + 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_CTANA, RGB_MOD, _______, _______, _______, _______, + 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_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_NUHS, KC_ENT, KC_P4, KC_P5, KC_P6, KC_PPLS, + KC_LSFT, KC_NUBS, 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_LWIN, KC_LALT, KC_SPC, KC_RALT, KC_RWIN, MO(WIN_FN),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT, KC_PENT), + + [WIN_FN] = LAYOUT_109_iso( + _______, KC_BRID, KC_BRIU, KC_TASK, KC_FILE, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, _______, _______, RGB_TOG, _______, _______, _______, _______, + _______, BT_HST1, BT_HST2, BT_HST3, P2P4G, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______), +}; + +// clang-format on +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + if (!process_record_keychron_common(keycode, record)) { + return false; + } + return true; +} diff --git a/keyboards/keychron/k5_max/iso/rgb/keymaps/via/keymap.c b/keyboards/keychron/k5_max/iso/rgb/keymaps/via/keymap.c new file mode 100644 index 0000000000..9972f8a49d --- /dev/null +++ b/keyboards/keychron/k5_max/iso/rgb/keymaps/via/keymap.c @@ -0,0 +1,68 @@ +/* Copyright 2024 @ 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 . + */ + +#include QMK_KEYBOARD_H +#include "keychron_common.h" + +enum layers { + MAC_BASE, + MAC_FN, + WIN_BASE, + WIN_FN, +}; + +// clang-format off +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [MAC_BASE] = LAYOUT_109_iso( + KC_ESC, KC_BRID, KC_BRIU, KC_MCTRL, KC_LNPAD, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, KC_SNAP, KC_SIRI, RGB_MOD, KC_F13, KC_F14, KC_F15, KC_F16, + 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_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_NUHS, KC_ENT, KC_P4, KC_P5, KC_P6, KC_PPLS, + KC_LSFT, KC_NUBS, 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_LOPTN, KC_LCMMD, KC_SPC, KC_RCMMD, KC_ROPTN,MO(MAC_FN),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT, KC_PENT), + + [MAC_FN] = LAYOUT_109_iso( + _______, 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, _______, _______, _______, _______, + _______, BT_HST1, BT_HST2, BT_HST3, P2P4G, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______), + + [WIN_BASE] = LAYOUT_109_iso( + 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_CTANA, RGB_MOD, _______, _______, _______, _______, + 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_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_NUHS, KC_ENT, KC_P4, KC_P5, KC_P6, KC_PPLS, + KC_LSFT, KC_NUBS, 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_LWIN, KC_LALT, KC_SPC, KC_RALT, KC_RWIN, MO(WIN_FN),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT, KC_PENT), + + [WIN_FN] = LAYOUT_109_iso( + _______, KC_BRID, KC_BRIU, KC_TASK, KC_FILE, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, _______, _______, RGB_TOG, _______, _______, _______, _______, + _______, BT_HST1, BT_HST2, BT_HST3, P2P4G, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______), +}; + +// clang-format on +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + if (!process_record_keychron_common(keycode, record)) { + return false; + } + return true; +} diff --git a/keyboards/keychron/k5_max/iso/rgb/keymaps/via/rules.mk b/keyboards/keychron/k5_max/iso/rgb/keymaps/via/rules.mk new file mode 100644 index 0000000000..1e5b99807c --- /dev/null +++ b/keyboards/keychron/k5_max/iso/rgb/keymaps/via/rules.mk @@ -0,0 +1 @@ +VIA_ENABLE = yes diff --git a/keyboards/keychron/k5_max/iso/rgb/rgb.c b/keyboards/keychron/k5_max/iso/rgb/rgb.c new file mode 100644 index 0000000000..7a88b55d75 --- /dev/null +++ b/keyboards/keychron/k5_max/iso/rgb/rgb.c @@ -0,0 +1,175 @@ +/* Copyright 2024 @ 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 . + */ + +#include "quantum.h" + +// clang-format off +#ifdef RGB_MATRIX_ENABLE +const snled27351_led_t g_snled27351_leds[RGB_MATRIX_LED_COUNT] = { +/* Refer to SNLED27351 manual for these locations + * driver + * | R location + * | | G location + * | | | B location + * | | | | */ + {0, G_1, I_1, H_1}, + {0, G_2, I_2, H_2}, + {0, G_3, I_3, H_3}, + {0, G_4, I_4, H_4}, + {0, G_5, I_5, H_5}, + {0, G_6, I_6, H_6}, + {0, G_7, I_7, H_7}, + {0, G_8, I_8, H_8}, + {0, G_9, I_9, H_9}, + {0, G_10, I_10, H_10}, + {0, G_11, I_11, H_11}, + {0, G_12, I_12, H_12}, + {0, G_13, I_13, H_13}, + {0, G_15, I_15, H_15}, + {0, G_16, I_16, H_16}, + {0, G_14, I_14, H_14}, + {1, G_13, I_13, H_13}, + {1, G_15, I_15, H_15}, + {1, G_16, I_16, H_16}, + {1, A_15, C_15, B_15}, + + {0, D_1, F_1, E_1}, + {0, D_2, F_2, E_2}, + {0, D_3, F_3, E_3}, + {0, D_4, F_4, E_4}, + {0, D_5, F_5, E_5}, + {0, D_6, F_6, E_6}, + {0, D_7, F_7, E_7}, + {0, D_8, F_8, E_8}, + {0, D_9, F_9, E_9}, + {0, D_10, F_10, E_10}, + {0, D_11, F_11, E_11}, + {0, D_12, F_12, E_12}, + {0, D_13, F_13, E_13}, + {0, D_14, F_14, E_14}, + {0, D_15, F_15, E_15}, + {0, D_16, F_16, E_16}, + {0, J_7, L_7, K_7}, + {0, J_8, L_8, K_8}, + {0, J_9, L_9, K_9}, + {0, J_10, L_10, K_10}, + {0, J_11, L_11, K_11}, + + {0, C_1, A_1, B_1}, + {0, C_2, A_2, B_2}, + {0, C_3, A_3, B_3}, + {0, C_4, A_4, B_4}, + {0, C_5, A_5, B_5}, + {0, C_6, A_6, B_6}, + {0, C_7, A_7, B_7}, + {0, C_8, A_8, B_8}, + {0, C_9, A_9, B_9}, + {0, C_10, A_10, B_10}, + {0, C_11, A_11, B_11}, + {0, C_12, A_12, B_12}, + {0, C_13, A_13, B_13}, + {0, C_14, A_14, B_14}, + {0, C_15, A_15, B_15}, + {0, C_16, A_16, B_16}, + {0, J_12, L_12, K_12}, + {0, J_13, L_13, K_13}, + {0, J_14, L_14, K_14}, + {0, J_15, L_15, K_15}, + {0, J_16, L_16, K_16}, + + {1, G_1, I_1, H_1}, + {1, G_2, I_2, H_2}, + {1, G_3, I_3, H_3}, + {1, G_4, I_4, H_4}, + {1, G_5, I_5, H_5}, + {1, G_6, I_6, H_6}, + {1, G_7, I_7, H_7}, + {1, G_8, I_8, H_8}, + {1, G_9, I_9, H_9}, + {1, G_10, I_10, H_10}, + {1, G_11, I_11, H_11}, + {1, G_12, I_12, H_12}, + {1, G_14, I_14, H_14}, + {1, J_7, L_7, K_7}, + {1, J_8, L_8, K_8}, + {1, J_9, L_9, K_9}, + + {1, A_1, C_1, B_1}, + {1, A_2, C_2, B_2}, + {1, A_3, C_3, B_3}, + {1, A_4, C_4, B_4}, + {1, A_5, C_5, B_5}, + {1, A_6, C_6, B_6}, + {1, A_7, C_7, B_7}, + {1, A_8, C_8, B_8}, + {1, A_9, C_9, B_9}, + {1, A_10, C_10, B_10}, + {1, A_11, C_11, B_11}, + {1, A_12, C_12, B_12}, + {1, A_14, C_14, B_14}, + {1, A_16, C_16, B_16}, + {1, J_10, L_10, K_10}, + {1, J_11, L_11, K_11}, + {1, J_12, L_12, K_12}, + {1, J_13, L_13, K_13}, + + {1, D_1, F_1, E_1}, + {1, D_2, F_2, E_2}, + {1, D_3, F_3, E_3}, + {1, D_7, F_7, E_7}, + {1, D_11, F_11, E_11}, + {1, D_12, F_12, E_12}, + {1, D_13, F_13, E_13}, + {1, D_14, F_14, E_14}, + {1, D_15, F_15, E_15}, + {1, D_16, F_16, E_16}, + {1, J_14, L_14, K_14}, + {1, J_15, L_15, K_15}, + {1, J_16, L_16, K_16}, +}; + +#define __ NO_LED + +led_config_t g_led_config = { + { + // Key Matrix to LED Index + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, __, 13, 14, 15, 16, 17, 18, 19 }, + { 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 }, + { 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61 }, + { 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, __, 74, __, __, __, 75, 76, 77, __ }, + { 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, __, 90, __, 91, __, 92, 93, 94, 95 }, + { 96, 97, 98, __, __, __, 99, __, __, __, 100, 101, 102, 103, 104, 105, 106, 107, __, 108, __ }, + }, + { + // LED Index to Physical Position + {0, 0}, {21, 0}, {32, 0}, {42, 0}, {53, 0}, {69, 0}, {79, 0}, {90, 0}, {100, 0}, {116, 0}, {127, 0}, {137, 0}, {148, 0}, {160, 0}, {170, 0}, {181, 0}, {192, 0}, {203, 0}, {213, 0}, {224, 0}, + {0,14}, {11,14}, {21,14}, {32,14}, {42,14}, {53,14}, {63,14}, {74,14}, { 84,14}, { 95,14}, {106,14}, {116,14}, {127,14}, {143,14}, {160,14}, {170,14}, {181,14}, {192,14}, {203,14}, {213,14}, {224,14}, + {3,26}, {16,26}, {26,26}, {37,26}, {48,26}, {58,26}, {69,26}, {79,26}, { 90,26}, {100,26}, {111,26}, {121,26}, {132,26}, {145,32}, {160,26}, {170,26}, {181,26}, {192,26}, {203,26}, {213,26}, {224,33}, + {4,39}, {19,39}, {29,39}, {40,39}, {50,39}, {61,39}, {71,39}, {82,39}, { 92,39}, {103,39}, {114,39}, {124,39}, {134,39}, {192,39}, {203,39}, {213,39}, + {4,51}, {12,39}, {24,51}, {34,51}, {45,51}, {55,51}, {66,51}, {77,51}, { 87,51}, { 98,51}, {108,51}, {119,51}, {139,51}, {170,51}, {192,51}, {203,51}, {213,51}, {224,58}, + {1,64}, {15,64}, {28,64}, {67,64}, {107,64}, {120,64}, {133,64}, {147,64}, {160,64}, {170,64}, {181,64}, {198,64}, {213,64}, + }, + { + // RGB LED Index to Flag + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + } +}; +#endif diff --git a/keyboards/keychron/k5_max/iso/rgb/rules.mk b/keyboards/keychron/k5_max/iso/rgb/rules.mk new file mode 100644 index 0000000000..6e7633bfe0 --- /dev/null +++ b/keyboards/keychron/k5_max/iso/rgb/rules.mk @@ -0,0 +1 @@ +# This file intentionally left blank diff --git a/keyboards/keychron/k5_max/iso/white/config.h b/keyboards/keychron/k5_max/iso/white/config.h new file mode 100644 index 0000000000..6ebcc770b7 --- /dev/null +++ b/keyboards/keychron/k5_max/iso/white/config.h @@ -0,0 +1,52 @@ +/* Copyright 2024 @ 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 . + */ + +#pragma once + +#ifdef LED_MATRIX_ENABLE +/* LED matrix driver configuration */ +# define DRIVER_COUNT 1 +# define LED_MATRIX_LED_COUNT 109 + +# define SPI_SCK_PIN A5 +# define SPI_MISO_PIN A6 +# define SPI_MOSI_PIN A7 + +# define DRIVER_CS_PINS \ + { B9 } +# define SNLED23751_SPI_DIVISOR 16 +# define SPI_DRIVER SPID1 + +/* Use first 8 channels of LED driver */ +# define SNLED27351_PHASE_CHANNEL MSKPHASE_8CHANNEL + +/* Set LED driver current */ +# define SNLED27351_CURRENT_TUNE \ + { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 } + +/* Set to infinit, which is use in USB mode by default */ +# define LED_MATRIX_TIMEOUT LED_MATRIX_TIMEOUT_INFINITE +/* Allow shutdown of led driver to save power */ +# define LED_MATRIX_DRIVER_SHUTDOWN_ENABLE +/* Turn off backlight on low brightness to save power */ +# define LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL 48 + +/* Indications */ +# define LOW_BAT_IND_INDEX \ + { 99 } + +# define LED_MATRIX_KEYPRESSES +#endif diff --git a/keyboards/keychron/k5_max/iso/white/info.json b/keyboards/keychron/k5_max/iso/white/info.json new file mode 100644 index 0000000000..ec3b99c11e --- /dev/null +++ b/keyboards/keychron/k5_max/iso/white/info.json @@ -0,0 +1,30 @@ +{ + "usb": { + "pid": "0x0A54", + "device_version": "1.0.0" + }, + "features": { + "led_matrix": true + }, + "led_matrix": { + "driver": "snled27351_spi", + "sleep": true, + "animations": { + "none": true, + "solid": true, + "breathing": true, + "band_pinwheel": true, + "band_spiral": true, + "cycle_left_right": true, + "cycle_up_down": true, + "cycle_out_in": true, + "dual_beacon": true, + "solid_reactive_simple": true, + "solid_reactive_multiwide": true, + "solid_reactive_multinexus": true, + "solid_splash": true, + "wave_left_right": true, + "wave_up_down": true + } + } +} diff --git a/keyboards/keychron/k5_max/iso/white/keymaps/default/keymap.c b/keyboards/keychron/k5_max/iso/white/keymaps/default/keymap.c new file mode 100644 index 0000000000..2ea0c3daef --- /dev/null +++ b/keyboards/keychron/k5_max/iso/white/keymaps/default/keymap.c @@ -0,0 +1,68 @@ +/* Copyright 2024 @ 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 . + */ + +#include QMK_KEYBOARD_H +#include "keychron_common.h" + +enum layers { + MAC_BASE, + MAC_FN, + WIN_BASE, + WIN_FN, +}; + +// clang-format off +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [MAC_BASE] = LAYOUT_108_ansi( + KC_ESC, KC_BRID, KC_BRIU, KC_MCTRL, KC_LNPAD, BL_DOWN, BL_UP, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, KC_SNAP, KC_SIRI, BL_STEP, KC_F13, KC_F14, KC_F15, KC_F16, + 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_LOPTN, KC_LCMMD, KC_SPC, KC_RCMMD, KC_ROPTN,MO(MAC_FN),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT, KC_PENT), + + [MAC_FN] = LAYOUT_108_ansi( + _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, BL_TOGG, _______, _______, _______, _______, + _______, BT_HST1, BT_HST2, BT_HST3, P2P4G, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + BL_TOGG, BL_STEP, BL_UP, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, BL_DOWN, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______), + + [WIN_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_CTANA, BL_STEP, _______, _______, _______, _______, + 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_LWIN, KC_LALT, KC_SPC, KC_RALT, KC_RWIN, MO(WIN_FN),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT, KC_PENT), + + [WIN_FN] = LAYOUT_108_ansi( + _______, KC_BRID, KC_BRIU, KC_TASK, KC_FILE, BL_DOWN, BL_UP, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, _______, _______, BL_TOGG, _______, _______, _______, _______, + _______, BT_HST1, BT_HST2, BT_HST3, P2P4G, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + BL_TOGG, BL_STEP, BL_UP, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, BL_DOWN, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______), +}; + +// clang-format on +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + if (!process_record_keychron_common(keycode, record)) { + return false; + } + return true; +} diff --git a/keyboards/keychron/k5_max/iso/white/keymaps/via/keymap.c b/keyboards/keychron/k5_max/iso/white/keymaps/via/keymap.c new file mode 100644 index 0000000000..2ea0c3daef --- /dev/null +++ b/keyboards/keychron/k5_max/iso/white/keymaps/via/keymap.c @@ -0,0 +1,68 @@ +/* Copyright 2024 @ 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 . + */ + +#include QMK_KEYBOARD_H +#include "keychron_common.h" + +enum layers { + MAC_BASE, + MAC_FN, + WIN_BASE, + WIN_FN, +}; + +// clang-format off +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [MAC_BASE] = LAYOUT_108_ansi( + KC_ESC, KC_BRID, KC_BRIU, KC_MCTRL, KC_LNPAD, BL_DOWN, BL_UP, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, KC_SNAP, KC_SIRI, BL_STEP, KC_F13, KC_F14, KC_F15, KC_F16, + 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_LOPTN, KC_LCMMD, KC_SPC, KC_RCMMD, KC_ROPTN,MO(MAC_FN),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT, KC_PENT), + + [MAC_FN] = LAYOUT_108_ansi( + _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, BL_TOGG, _______, _______, _______, _______, + _______, BT_HST1, BT_HST2, BT_HST3, P2P4G, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + BL_TOGG, BL_STEP, BL_UP, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, BL_DOWN, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______), + + [WIN_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_CTANA, BL_STEP, _______, _______, _______, _______, + 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_LWIN, KC_LALT, KC_SPC, KC_RALT, KC_RWIN, MO(WIN_FN),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT, KC_PENT), + + [WIN_FN] = LAYOUT_108_ansi( + _______, KC_BRID, KC_BRIU, KC_TASK, KC_FILE, BL_DOWN, BL_UP, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, _______, _______, BL_TOGG, _______, _______, _______, _______, + _______, BT_HST1, BT_HST2, BT_HST3, P2P4G, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + BL_TOGG, BL_STEP, BL_UP, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, BL_DOWN, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______), +}; + +// clang-format on +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + if (!process_record_keychron_common(keycode, record)) { + return false; + } + return true; +} diff --git a/keyboards/keychron/k5_max/iso/white/keymaps/via/rules.mk b/keyboards/keychron/k5_max/iso/white/keymaps/via/rules.mk new file mode 100644 index 0000000000..1e5b99807c --- /dev/null +++ b/keyboards/keychron/k5_max/iso/white/keymaps/via/rules.mk @@ -0,0 +1 @@ +VIA_ENABLE = yes diff --git a/keyboards/keychron/k5_max/iso/white/rules.mk b/keyboards/keychron/k5_max/iso/white/rules.mk new file mode 100644 index 0000000000..6e7633bfe0 --- /dev/null +++ b/keyboards/keychron/k5_max/iso/white/rules.mk @@ -0,0 +1 @@ +# This file intentionally left blank diff --git a/keyboards/keychron/k5_max/iso/white/white.c b/keyboards/keychron/k5_max/iso/white/white.c new file mode 100644 index 0000000000..0499b14fc1 --- /dev/null +++ b/keyboards/keychron/k5_max/iso/white/white.c @@ -0,0 +1,173 @@ +/* Copyright 2024 @ 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 . + */ + +#include "quantum.h" + +// clang-format off +#ifdef LED_MATRIX_ENABLE +const snled27351_led_t g_snled27351_leds[LED_MATRIX_LED_COUNT] = { +/* Refer to SNLED27351 manual for these locations + * driver + * | LED address + * | | */ + {0, F_1}, + {0, F_2}, + {0, F_3}, + {0, F_4}, + {0, F_5}, + {0, F_6}, + {0, F_7}, + {0, F_8}, + {0, F_9}, + {0, F_10}, + {0, F_11}, + {0, F_12}, + {0, F_13}, + {0, F_15}, + {0, F_16}, + {0, F_14}, + {0, H_7}, + {0, H_8}, + {0, H_9}, + {0, H_10}, + + {0, E_1}, + {0, E_2}, + {0, E_3}, + {0, E_4}, + {0, E_5}, + {0, E_6}, + {0, E_7}, + {0, E_8}, + {0, E_9}, + {0, E_10}, + {0, E_11}, + {0, E_12}, + {0, E_13}, + {0, E_14}, + {0, E_15}, + {0, E_16}, + {0, G_7}, + {0, G_8}, + {0, G_9}, + {0, G_10}, + {0, G_11}, + + {0, D_1}, + {0, D_2}, + {0, D_3}, + {0, D_4}, + {0, D_5}, + {0, D_6}, + {0, D_7}, + {0, D_8}, + {0, D_9}, + {0, D_10}, + {0, D_11}, + {0, D_12}, + {0, D_13}, + {0, D_14}, + {0, D_15}, + {0, D_16}, + {0, G_12}, + {0, G_13}, + {0, G_14}, + {0, G_15}, + {0, G_16}, + + {0, C_1}, + {0, C_2}, + {0, C_3}, + {0, C_4}, + {0, C_5}, + {0, C_6}, + {0, C_7}, + {0, C_8}, + {0, C_9}, + {0, C_10}, + {0, C_11}, + {0, C_12}, + {0, C_14}, + {0, C_13}, + {0, C_15}, + {0, C_16}, + + {0, B_1}, + {0, B_2}, + {0, B_3}, + {0, B_4}, + {0, B_5}, + {0, B_6}, + {0, B_7}, + {0, B_8}, + {0, B_9}, + {0, B_10}, + {0, B_11}, + {0, B_12}, + {0, B_14}, + {0, B_16}, + {0, B_13}, + {0, H_11}, + {0, H_12}, + {0, H_13}, + + {0, A_1}, + {0, A_2}, + {0, A_3}, + {0, A_7}, + {0, A_11}, + {0, A_12}, + {0, A_13}, + {0, A_14}, + {0, A_15}, + {0, A_16}, + {0, H_14}, + {0, H_15}, + {0, H_16}, +}; + +#define __ NO_LED + +led_config_t g_led_config = { + { + // Key Matrix to LED Index + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, __, 13, 14, 15, 16, 17, 18, 19 }, + { 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 }, + { 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61 }, + { 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, __, 74, __, __, __, 75, 76, 77, __ }, + { 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, __, 90, __, 91, __, 92, 93, 94, 95 }, + { 96, 97, 98, __, __, __, 99, __, __, __, 100, 101, 102, 103, 104, 105, 106, 107, __, 108, __ }, + }, + { + // LED Index to Physical Position + {0, 0}, {21, 0}, {32, 0}, {42, 0}, {53, 0}, {69, 0}, {79, 0}, {90, 0}, {100, 0}, {116, 0}, {127, 0}, {137, 0}, {148, 0}, {160, 0}, {170, 0}, {181, 0}, {192, 0}, {203, 0}, {213, 0}, {224, 0}, + {0,14}, {11,14}, {21,14}, {32,14}, {42,14}, {53,14}, {63,14}, {74,14}, { 84,14}, { 95,14}, {106,14}, {116,14}, {127,14}, {143,14}, {160,14}, {170,14}, {181,14}, {192,14}, {203,14}, {213,14}, {224,14}, + {3,26}, {16,26}, {26,26}, {37,26}, {48,26}, {58,26}, {69,26}, {79,26}, { 90,26}, {100,26}, {111,26}, {121,26}, {132,26}, {145,32}, {160,26}, {170,26}, {181,26}, {192,26}, {203,26}, {213,26}, {224,33}, + {4,39}, {19,39}, {29,39}, {40,39}, {50,39}, {61,39}, {71,39}, {82,39}, { 92,39}, {103,39}, {114,39}, {124,39}, {134,39}, {192,39}, {203,39}, {213,39}, + {4,51}, {12,39}, {24,51}, {34,51}, {45,51}, {55,51}, {66,51}, {77,51}, { 87,51}, { 98,51}, {108,51}, {119,51}, {139,51}, {170,51}, {192,51}, {203,51}, {213,51}, {224,58}, + {1,64}, {15,64}, {28,64}, {67,64}, {107,64}, {120,64}, {133,64}, {147,64}, {160,64}, {170,64}, {181,64}, {198,64}, {213,64}, + }, + { + // LED Index to Flag + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + } +}; +#endif diff --git a/keyboards/keychron/k5_max/k5_max.c b/keyboards/keychron/k5_max/k5_max.c new file mode 100644 index 0000000000..f0ab1c6105 --- /dev/null +++ b/keyboards/keychron/k5_max/k5_max.c @@ -0,0 +1,97 @@ +/* Copyright 2024 @ 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 . + */ + +#include "quantum.h" +#include "keychron_task.h" +#ifdef FACTORY_TEST_ENABLE +# include "factory_test.h" +# include "keychron_common.h" +#endif +#ifdef LK_WIRELESS_ENABLE +# include "lkbt51.h" +# include "wireless.h" +# include "transport.h" +# include "keychron_wireless_common.h" +# include "battery.h" +#endif + +#define POWER_ON_LED_DURATION 3000 +static uint32_t power_on_indicator_timer; + +#ifdef LK_WIRELESS_ENABLE +pin_t bt_led_pins[] = BT_HOST_LED_PIN_LIST; +pin_t p24g_led_pins[] = P24G_HOST_LED_PIN_LIST; +#endif + +bool dip_switch_update_kb(uint8_t index, bool active) { + dip_switch_update_user(index, active); + + return true; +} + +void keyboard_post_init_kb(void) { +#ifdef LK_WIRELESS_ENABLE + palSetLineMode(P2P4_MODE_SELECT_PIN, PAL_MODE_INPUT); + palSetLineMode(BT_MODE_SELECT_PIN, PAL_MODE_INPUT); + + writePin(BAT_LOW_LED_PIN, BAT_LOW_LED_PIN_ON_STATE); + lkbt51_init(false); + wireless_init(); +#endif + + power_on_indicator_timer = timer_read32(); +#ifdef ENCODER_ENABLE + encoder_cb_init(); +#endif + + keyboard_post_init_user(); +} + +bool keychron_task_kb(void) { + if (power_on_indicator_timer) { + if (timer_elapsed32(power_on_indicator_timer) > POWER_ON_LED_DURATION) { + power_on_indicator_timer = 0; + + if (!host_keyboard_led_state().caps_lock) writePin(LED_CAPS_LOCK_PIN, !LED_PIN_ON_STATE); +#ifdef LK_WIRELESS_ENABLE + writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE); + for (uint8_t i = 0; i < sizeof(bt_led_pins) / sizeof(pin_t); i++) + writePin(bt_led_pins[i], 1); + for (uint8_t i = 0; i < sizeof(p24g_led_pins) / sizeof(pin_t); i++) + writePin(p24g_led_pins[i], 1); +#endif + + } else { + writePin(LED_CAPS_LOCK_PIN, LED_PIN_ON_STATE); +#ifdef LK_WIRELESS_ENABLE + writePin(BAT_LOW_LED_PIN, BAT_LOW_LED_PIN_ON_STATE); + if (get_transport() != TRANSPORT_P2P4) + for (uint8_t i = 0; i < sizeof(bt_led_pins) / sizeof(pin_t); i++) + writePin(bt_led_pins[i], 0); + if (get_transport() != TRANSPORT_BLUETOOTH) + for (uint8_t i = 0; i < sizeof(p24g_led_pins) / sizeof(pin_t); i++) + writePin(p24g_led_pins[i], 0); +#endif + } + } + return true; +} + +#ifdef LK_WIRELESS_ENABLE +bool lpm_is_kb_idle(void) { + return power_on_indicator_timer == 0 && !factory_reset_indicating(); +} +#endif diff --git a/keyboards/keychron/k5_max/mcuconf.h b/keyboards/keychron/k5_max/mcuconf.h new file mode 100644 index 0000000000..89294ee64b --- /dev/null +++ b/keyboards/keychron/k5_max/mcuconf.h @@ -0,0 +1,37 @@ +/* Copyright 2024 @ 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 + +#include_next + +#undef STM32_HSECLK +#define STM32_HSECLK 16000000 + +#undef STM32_PLLM_VALUE +#define STM32_PLLM_VALUE 8 + +#undef STM32_PLLN_VALUE +#define STM32_PLLN_VALUE 96 + +#undef STM32_PLLP_VALUE +#define STM32_PLLP_VALUE 4 + +#undef STM32_PLLQ_VALUE +#define STM32_PLLQ_VALUE 4 + +#undef STM32_SPI_USE_SPI1 +#define STM32_SPI_USE_SPI1 TRUE diff --git a/keyboards/keychron/k5_max/readme.md b/keyboards/keychron/k5_max/readme.md new file mode 100644 index 0000000000..b5918289a0 --- /dev/null +++ b/keyboards/keychron/k5_max/readme.md @@ -0,0 +1,23 @@ +# Keychron K5 Max + +![Keychron K5 Max](https://cdn.shopify.com/s/files/1/0059/0630/1017/files/K5-Max-page13.jpg?v=1705308494) + +A customizable 84 keys 100% fullsize keyboard. + +* Keyboard Maintainer: [Keychron](https://github.com/keychron) +* Hardware Supported: Keychron K5 Max +* Hardware Availability: [Keychron K5 Max QMK/VIA Wireless Custom Mechanical Keyboard](https://www.keychron.com/products/keychron-k5-max-qmk-via-wireless-custom-mechanical-keyboard) + +Make example for this keyboard (after setting up your build environment): + + make keychron/k5_max/ansi/rgb:default + make keychron/k5_max/ansi/white:default + +Flashing example for this keyboard: + + make keychron/k5_max/ansi/rgb:default:flash + make keychron/k5_max/ansi/white:default:flash + +**Reset Key**: Disconnect the USB cable, toggle mode switch to "Cable", hold down the *Esc* key or reset button underneath space bar, then connect the USB cable. + +See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs). diff --git a/keyboards/keychron/k5_max/rules.mk b/keyboards/keychron/k5_max/rules.mk new file mode 100644 index 0000000000..4eaf6820bc --- /dev/null +++ b/keyboards/keychron/k5_max/rules.mk @@ -0,0 +1,4 @@ +include keyboards/keychron/common/wireless/wireless.mk +include keyboards/keychron/common/keychron_common.mk + +VPATH += $(TOP_DIR)/keyboards/keychron diff --git a/keyboards/keychron/k5_max/via_json/k5_max_ansi_rgb.json b/keyboards/keychron/k5_max/via_json/k5_max_ansi_rgb.json new file mode 100644 index 0000000000..ea914fbd76 --- /dev/null +++ b/keyboards/keychron/k5_max/via_json/k5_max_ansi_rgb.json @@ -0,0 +1,342 @@ +{ + "name": "Keychron K5 Max ANSI RGB", + "vendorId": "0x3434", + "productId": "0x0A50", + "keycodes": ["qmk_lighting"], + "menus": [ + { + "label": "Lighting", + "content": [ + { + "label": "Backlight", + "content": [ + { + "label": "Brightness", + "type": "range", + "options": [0, 255], + "content": ["id_qmk_rgb_matrix_brightness", 3, 1] + }, + { + "label": "Effect", + "type": "dropdown", + "content": ["id_qmk_rgb_matrix_effect", 3, 2], + "options": [ + ["None", 0], + ["Solid Color", 1], + ["Breathing", 2], + ["Band Spiral Val", 3], + ["Cycle All", 4], + ["Cycle Left Right", 5], + ["Cycle Up Down", 6], + ["Rainbow Moving Chevron", 7], + ["Cycle Out In", 8], + ["Cycle Out In Dual", 9], + ["Cycle Pinwheel", 10], + ["Cycle Spiral", 11], + ["Dual Beacon", 12], + ["Rainbow Beacon", 13], + ["Jellybean Raindrops", 14], + ["Pixel Rain", 15], + ["Typing Heatmap", 16], + ["Digital Rain", 17], + ["Reactive Simple", 18], + ["Reactive Multiwide", 19], + ["Reactive Multinexus", 20], + ["Splash", 21], + ["Solid Splash", 22] + ] + }, + { + "showIf": "{id_qmk_rgb_matrix_effect} > 1", + "label": "Effect Speed", + "type": "range", + "options": [0, 255], + "content": ["id_qmk_rgb_matrix_effect_speed", 3, 3] + }, + { + "showIf": "{id_qmk_rgb_matrix_effect} != 0 && ( {id_qmk_rgb_matrix_effect} < 4 || {id_qmk_rgb_matrix_effect} == 18 || ({id_qmk_rgb_matrix_effect} > 17 && {id_qmk_rgb_matrix_effect} != 21) ) ", + "label": "Color", + "type": "color", + "content": ["id_qmk_rgb_matrix_color", 3, 4] + } + ] + } + ] + } + ], + "customKeycodes": [ + {"name": "Left Option", "title": "Left Option", "shortName": "LOpt"}, + {"name": "Right Option", "title": "Right Option", "shortName": "ROpt"}, + {"name": "Left Cmd", "title": "Left Command", "shortName": "LCmd"}, + {"name": "Right Cmd", "title": "Right Command", "shortName": "RCmd"}, + {"name": "Misson Control", "title": "Misson Control in Mac", "shortName": "MCtl"}, + {"name": "Lanuch Pad", "title": "Lanuch Pad in Windows", "shortName": "LPad"}, + {"name": "Task View", "title": "Task View in Windows", "shortName": "Task"}, + {"name": "File Explorer", "title": "File Explorer in Windows", "shortName": "File"}, + {"name": "Screen shot", "title": "Screenshot in macOS", "shortName": "SShot"}, + {"name": "Cortana", "title": "Cortana in Windows", "shortName": "Cortana"}, + {"name": "Siri", "title": "Siri in macOS", "shortName": "Siri"}, + {"name": "Bluetooth Host 1", "title": "Bluetooth Host 1", "shortName": "BTH1"}, + {"name": "Bluetooth Host 2", "title": "Bluetooth Host 2", "shortName": "BTH2"}, + {"name": "Bluetooth Host 3", "title": "Bluetooth Host 3", "shortName": "BTH3"}, + {"name": "2.4G", "title": "2.4G", "shortName": "2.4G"}, + {"name": "Battery Level", "title": "Show battery level", "shortName": "Batt"} + ], + "matrix": {"rows": 6, "cols" : 21}, + "layouts": { + "keymap": [ + [ + { + "c": "#777777" + }, + "0, 0", + { + "x": 1, + "c": "#cccccc" + }, + "0, 1", + "0, 2", + "0, 3", + "0, 4", + { + "x": 0.5, + "c": "#aaaaaa" + }, + "0, 5", + "0, 6", + "0, 7", + "0, 8", + { + "x": 0.5, + "c": "#cccccc" + }, + "0, 9", + "0, 10", + "0, 11", + "0, 12", + { + "x": 0.25, + "c": "#aaaaaa" + }, + "0, 14", + "0, 15", + "0, 16", + { + "x": 0.25, + "c": "#cccccc" + }, + "0, 17", + "0, 18", + "0, 19", + "0, 20" + ], + [ + { + "c": "#aaaaaa" + }, + "1, 0", + { + "c": "#cccccc" + }, + "1, 1", + "1, 2", + "1, 3", + "1, 4", + "1, 5", + "1, 6", + "1, 7", + "1, 8", + "1, 9", + "1, 10", + "1, 11", + "1, 12", + { + "w": 2, + "c": "#aaaaaa" + }, + "1, 13", + { + "x": 0.25 + }, + "1, 14", + "1, 15", + "1, 16", + { + "x": 0.25, + "c": "#cccccc" + }, + "1, 17", + "1, 18", + "1, 19", + "1, 20" + ], + [ + { + "w": 1.5, + "c": "#aaaaaa" + }, + "2, 0", + { + "c": "#cccccc" + }, + "2, 1", + "2, 2", + "2, 3", + "2, 4", + "2, 5", + "2, 6", + "2, 7", + "2, 8", + "2, 9", + "2, 10", + "2, 11", + "2, 12", + { + "w": 1.5, + "c": "#aaaaaa" + }, + "2, 13", + { + "x": 0.25 + }, + "2, 14", + "2, 15", + "2, 16", + { + "x": 0.25, + "c": "#cccccc" + }, + "2, 17", + "2, 18", + "2, 19", + { + "h": 2 + }, + "2, 20" + ], + [ + { + "w": 1.75, + "c": "#aaaaaa" + }, + "3, 0", + { + "c": "#cccccc" + }, + "3, 1", + "3, 2", + "3, 3", + "3, 4", + "3, 5", + "3, 6", + "3, 7", + "3, 8", + "3, 9", + "3, 10", + "3, 11", + { + "w": 2.25, + "c": "#777777" + }, + "3, 13", + { + "x": 3.5, + "c": "#cccccc" + }, + "3, 17", + "3, 18", + "3, 19" + ], + [ + { + "w": 2.25, + "c": "#aaaaaa" + }, + "4, 0", + { + "c": "#cccccc" + }, + "4, 2", + "4, 3", + "4, 4", + "4, 5", + "4, 6", + "4, 7", + "4, 8", + "4, 9", + "4, 10", + "4, 11", + { + "w": 2.75, + "c": "#aaaaaa" + }, + "4, 13", + { + "x": 1.25, + "c": "#cccccc" + }, + "4, 15", + { + "x": 1.25 + }, + "4, 17", + "4, 18", + "4, 19", + { + "h": 2 + }, + "4, 20" + ], + [ + { + "w": 1.25, + "c": "#aaaaaa" + }, + "5, 0", + { + "w": 1.25 + }, + "5, 1", + { + "w": 1.25 + }, + "5, 2", + { + "w": 6.25, + "c": "#cccccc" + }, + "5, 6", + { + "w": 1.25, + "c": "#aaaaaa" + }, + "5, 10", + { + "w": 1.25 + }, + "5, 11", + { + "w": 1.25 + }, + "5, 12", + { + "w": 1.25 + }, + "5, 13", + { + "x": 0.25, + "c": "#cccccc" + }, + "5, 14", + "5, 15", + "5, 16", + { + "x": 0.25, + "w": 2 + }, + "5, 17", + "5, 19" + ] + ] + } + } diff --git a/keyboards/keychron/k5_max/via_json/k5_max_ansi_white.json b/keyboards/keychron/k5_max/via_json/k5_max_ansi_white.json new file mode 100644 index 0000000000..e1f8f410f7 --- /dev/null +++ b/keyboards/keychron/k5_max/via_json/k5_max_ansi_white.json @@ -0,0 +1,281 @@ +{ + "name": "Keychron K5 Max ANSI White", + "vendorId": "0x3434", + "productId": "0x0A53", + "keycodes": ["qmk_lighting"], + "customKeycodes": [ + {"name": "Left Option", "title": "Left Option", "shortName": "LOpt"}, + {"name": "Right Option", "title": "Right Option", "shortName": "ROpt"}, + {"name": "Left Cmd", "title": "Left Command", "shortName": "LCmd"}, + {"name": "Right Cmd", "title": "Right Command", "shortName": "RCmd"}, + {"name": "Misson Control", "title": "Misson Control in Mac", "shortName": "MCtl"}, + {"name": "Lanuch Pad", "title": "Lanuch Pad in Windows", "shortName": "LPad"}, + {"name": "Task View", "title": "Task View in Windows", "shortName": "Task"}, + {"name": "File Explorer", "title": "File Explorer in Windows", "shortName": "File"}, + {"name": "Screen shot", "title": "Screenshot in macOS", "shortName": "SShot"}, + {"name": "Cortana", "title": "Cortana in Windows", "shortName": "Cortana"}, + {"name": "Siri", "title": "Siri in macOS", "shortName": "Siri"}, + {"name": "Bluetooth Host 1", "title": "Bluetooth Host 1", "shortName": "BTH1"}, + {"name": "Bluetooth Host 2", "title": "Bluetooth Host 2", "shortName": "BTH2"}, + {"name": "Bluetooth Host 3", "title": "Bluetooth Host 3", "shortName": "BTH3"}, + {"name": "2.4G", "title": "2.4G", "shortName": "2.4G"}, + {"name": "Battery Level", "title": "Show battery level", "shortName": "Batt"} + ], + "matrix": {"rows": 6, "cols" : 21}, + "layouts": { + "keymap": [ + [ + { + "c": "#777777" + }, + "0, 0", + { + "x": 1, + "c": "#cccccc" + }, + "0, 1", + "0, 2", + "0, 3", + "0, 4", + { + "x": 0.5, + "c": "#aaaaaa" + }, + "0, 5", + "0, 6", + "0, 7", + "0, 8", + { + "x": 0.5, + "c": "#cccccc" + }, + "0, 9", + "0, 10", + "0, 11", + "0, 12", + { + "x": 0.25, + "c": "#aaaaaa" + }, + "0, 14", + "0, 15", + "0, 16", + { + "x": 0.25, + "c": "#cccccc" + }, + "0, 17", + "0, 18", + "0, 19", + "0, 20" + ], + [ + { + "c": "#aaaaaa" + }, + "1, 0", + { + "c": "#cccccc" + }, + "1, 1", + "1, 2", + "1, 3", + "1, 4", + "1, 5", + "1, 6", + "1, 7", + "1, 8", + "1, 9", + "1, 10", + "1, 11", + "1, 12", + { + "w": 2, + "c": "#aaaaaa" + }, + "1, 13", + { + "x": 0.25 + }, + "1, 14", + "1, 15", + "1, 16", + { + "x": 0.25, + "c": "#cccccc" + }, + "1, 17", + "1, 18", + "1, 19", + "1, 20" + ], + [ + { + "w": 1.5, + "c": "#aaaaaa" + }, + "2, 0", + { + "c": "#cccccc" + }, + "2, 1", + "2, 2", + "2, 3", + "2, 4", + "2, 5", + "2, 6", + "2, 7", + "2, 8", + "2, 9", + "2, 10", + "2, 11", + "2, 12", + { + "w": 1.5, + "c": "#aaaaaa" + }, + "2, 13", + { + "x": 0.25 + }, + "2, 14", + "2, 15", + "2, 16", + { + "x": 0.25, + "c": "#cccccc" + }, + "2, 17", + "2, 18", + "2, 19", + { + "h": 2 + }, + "2, 20" + ], + [ + { + "w": 1.75, + "c": "#aaaaaa" + }, + "3, 0", + { + "c": "#cccccc" + }, + "3, 1", + "3, 2", + "3, 3", + "3, 4", + "3, 5", + "3, 6", + "3, 7", + "3, 8", + "3, 9", + "3, 10", + "3, 11", + { + "w": 2.25, + "c": "#777777" + }, + "3, 13", + { + "x": 3.5, + "c": "#cccccc" + }, + "3, 17", + "3, 18", + "3, 19" + ], + [ + { + "w": 2.25, + "c": "#aaaaaa" + }, + "4, 0", + { + "c": "#cccccc" + }, + "4, 2", + "4, 3", + "4, 4", + "4, 5", + "4, 6", + "4, 7", + "4, 8", + "4, 9", + "4, 10", + "4, 11", + { + "w": 2.75, + "c": "#aaaaaa" + }, + "4, 13", + { + "x": 1.25, + "c": "#cccccc" + }, + "4, 15", + { + "x": 1.25 + }, + "4, 17", + "4, 18", + "4, 19", + { + "h": 2 + }, + "4, 20" + ], + [ + { + "w": 1.25, + "c": "#aaaaaa" + }, + "5, 0", + { + "w": 1.25 + }, + "5, 1", + { + "w": 1.25 + }, + "5, 2", + { + "w": 6.25, + "c": "#cccccc" + }, + "5, 6", + { + "w": 1.25, + "c": "#aaaaaa" + }, + "5, 10", + { + "w": 1.25 + }, + "5, 11", + { + "w": 1.25 + }, + "5, 12", + { + "w": 1.25 + }, + "5, 13", + { + "x": 0.25, + "c": "#cccccc" + }, + "5, 14", + "5, 15", + "5, 16", + { + "x": 0.25, + "w": 2 + }, + "5, 17", + "5, 19" + ] + ] + } + } \ No newline at end of file