From 777cd7a3d57a467e09a501101e09639b58bb69a6 Mon Sep 17 00:00:00 2001 From: lalalademaxiya1 <66767061+lalalademaxiya1@users.noreply.github.com> Date: Mon, 16 Jan 2023 17:37:06 +0800 Subject: [PATCH] Update K2 Pro --- keyboards/keychron/bluetooth/bluetooth.c | 25 ++++++++-------- keyboards/keychron/bluetooth/rtc_timer.c | 1 + keyboards/keychron/bluetooth/transport.c | 37 +++++++++++++++++------- keyboards/keychron/bluetooth/transport.h | 7 +++++ keyboards/keychron/k2_pro/rules.mk | 2 +- 5 files changed, 47 insertions(+), 25 deletions(-) diff --git a/keyboards/keychron/bluetooth/bluetooth.c b/keyboards/keychron/bluetooth/bluetooth.c index 1580138ab0..1ba8051f3a 100644 --- a/keyboards/keychron/bluetooth/bluetooth.c +++ b/keyboards/keychron/bluetooth/bluetooth.c @@ -30,11 +30,6 @@ extern uint32_t retry_time_buffer; extern uint8_t retry; #ifdef NKRO_ENABLE -typedef struct { - bool usb : 1; - bool bluetooth : 1; -} nkro_t; - extern nkro_t nkro; #endif @@ -101,7 +96,7 @@ void bluetooth_init(void) { #ifdef BLUETOOTH_INT_INPUT_PIN setPinInputHigh(BLUETOOTH_INT_INPUT_PIN); #endif - + lpm_init(); rtc_timer_init(); } @@ -207,7 +202,7 @@ static void bluetooth_enter_connected(uint8_t host_idx) { clear_keyboard(); - /* Enable NKRO since it may be disabled in pin code entry */ + /* 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 @@ -229,7 +224,7 @@ static void bluetooth_enter_connected(uint8_t host_idx) { 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); @@ -276,8 +271,8 @@ __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; +static void bluetooth_hid_set_protocol(bool report_protocol) { + bluetooth_report_protocol = false; } uint8_t bluetooth_keyboard_leds(void) { @@ -338,7 +333,7 @@ void bluetooth_send_keyboard(report_keyboard_t *report) { //#endif } - } else if (bt_state != BLUETOOTH_RESET) { + } else if (bt_state != BLUETOOTH_RESET) { bluetooth_connect(); } } @@ -458,6 +453,10 @@ bluetooth_state_t bluetooth_get_state(void) { __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(); @@ -472,6 +471,6 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { } #endif } - process_record_kb_bt(keycode, record); - return process_record_user(keycode, record); + return process_record_kb_bt(keycode, record); + // return process_record_user(keycode, record); } diff --git a/keyboards/keychron/bluetooth/rtc_timer.c b/keyboards/keychron/bluetooth/rtc_timer.c index eb8ca6fc28..04ebd43995 100644 --- a/keyboards/keychron/bluetooth/rtc_timer.c +++ b/keyboards/keychron/bluetooth/rtc_timer.c @@ -13,6 +13,7 @@ * 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) diff --git a/keyboards/keychron/bluetooth/transport.c b/keyboards/keychron/bluetooth/transport.c index 65d053abe0..2cf69016fe 100644 --- a/keyboards/keychron/bluetooth/transport.c +++ b/keyboards/keychron/bluetooth/transport.c @@ -1,3 +1,18 @@ +/* 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" @@ -12,13 +27,6 @@ # define REINIT_LED_DRIVER 1 #endif -#ifdef NKRO_ENABLE -typedef struct { - bool usb : 1; - bool bluetooth : 1; -} nkro_t; -#endif - #if defined(PROTOCOL_CHIBIOS) extern host_driver_t chibios_driver; #endif @@ -37,8 +45,8 @@ __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 + + /* Disconnect and reconnect to sync the bluetooth state * TODO: query bluetooth state to sync */ bluetooth_disconnect(); @@ -55,8 +63,8 @@ __attribute__((weak)) void bt_transport_enable(bool enable) { } } -/* There is no dedicated pin for USB power on chip such as STM32L432, but USB power - * can be connected and disconnected via registers. +/* 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) {} @@ -180,3 +188,10 @@ void usb_remote_wakeup(void) { send_keyboard_report(); } } + +#ifdef BLUETOOTH_NKRO_ENABLE +void keyboard_post_init_user(void) { + keymap_config.raw = eeconfig_read_keymap(); + nkro.bluetooth = keymap_config.nkro; +} +#endif diff --git a/keyboards/keychron/bluetooth/transport.h b/keyboards/keychron/bluetooth/transport.h index 32fbf0b218..29722cd265 100644 --- a/keyboards/keychron/bluetooth/transport.h +++ b/keyboards/keychron/bluetooth/transport.h @@ -22,6 +22,13 @@ typedef enum { 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); diff --git a/keyboards/keychron/k2_pro/rules.mk b/keyboards/keychron/k2_pro/rules.mk index 7244d12fd2..a747da42ca 100644 --- a/keyboards/keychron/k2_pro/rules.mk +++ b/keyboards/keychron/k2_pro/rules.mk @@ -1,6 +1,6 @@ # MCU name MCU = STM32L432 - + # Bootloader selection BOOTLOADER = stm32-dfu