From c6243da12f6643747a24a7aa761e103cc4a848c2 Mon Sep 17 00:00:00 2001
From: lalalademaxiya1 <2831039915@qq.com>
Date: Wed, 15 Mar 2023 16:51:53 +0800
Subject: Update Keychron K Pro series keyboards
---
keyboards/keychron/bluetooth/bat_level_animation.c | 0
keyboards/keychron/bluetooth/bat_level_animation.h | 0
keyboards/keychron/bluetooth/battery.h | 0
keyboards/keychron/bluetooth/bluetooth.h | 12 ++---
keyboards/keychron/bluetooth/bluetooth.mk | 0
keyboards/keychron/bluetooth/bluetooth_config.h | 0
.../keychron/bluetooth/bluetooth_event_type.h | 0
keyboards/keychron/bluetooth/bluetooth_main.c | 0
keyboards/keychron/bluetooth/ckbt51.c | 63 ++++++++++++----------
keyboards/keychron/bluetooth/ckbt51.h | 0
keyboards/keychron/bluetooth/factory_test.c | 0
keyboards/keychron/bluetooth/factory_test.h | 0
keyboards/keychron/bluetooth/indicator.c | 4 +-
keyboards/keychron/bluetooth/indicator.h | 0
keyboards/keychron/bluetooth/lpm.c | 0
keyboards/keychron/bluetooth/lpm.h | 0
keyboards/keychron/bluetooth/lpm_stm32l432.c | 11 ++--
keyboards/keychron/bluetooth/lpm_stm32l432.h | 0
keyboards/keychron/bluetooth/report_buffer.c | 0
keyboards/keychron/bluetooth/report_buffer.h | 0
keyboards/keychron/bluetooth/rtc_timer.c | 0
keyboards/keychron/bluetooth/rtc_timer.h | 0
keyboards/keychron/bluetooth/transport.c | 0
keyboards/keychron/bluetooth/transport.h | 0
24 files changed, 47 insertions(+), 43 deletions(-)
mode change 100644 => 100755 keyboards/keychron/bluetooth/bat_level_animation.c
mode change 100644 => 100755 keyboards/keychron/bluetooth/bat_level_animation.h
mode change 100644 => 100755 keyboards/keychron/bluetooth/battery.h
mode change 100644 => 100755 keyboards/keychron/bluetooth/bluetooth.h
mode change 100644 => 100755 keyboards/keychron/bluetooth/bluetooth.mk
mode change 100644 => 100755 keyboards/keychron/bluetooth/bluetooth_config.h
mode change 100644 => 100755 keyboards/keychron/bluetooth/bluetooth_event_type.h
mode change 100644 => 100755 keyboards/keychron/bluetooth/bluetooth_main.c
mode change 100644 => 100755 keyboards/keychron/bluetooth/ckbt51.c
mode change 100644 => 100755 keyboards/keychron/bluetooth/ckbt51.h
mode change 100644 => 100755 keyboards/keychron/bluetooth/factory_test.c
mode change 100644 => 100755 keyboards/keychron/bluetooth/factory_test.h
mode change 100644 => 100755 keyboards/keychron/bluetooth/indicator.c
mode change 100644 => 100755 keyboards/keychron/bluetooth/indicator.h
mode change 100644 => 100755 keyboards/keychron/bluetooth/lpm.c
mode change 100644 => 100755 keyboards/keychron/bluetooth/lpm.h
mode change 100644 => 100755 keyboards/keychron/bluetooth/lpm_stm32l432.c
mode change 100644 => 100755 keyboards/keychron/bluetooth/lpm_stm32l432.h
mode change 100644 => 100755 keyboards/keychron/bluetooth/report_buffer.c
mode change 100644 => 100755 keyboards/keychron/bluetooth/report_buffer.h
mode change 100644 => 100755 keyboards/keychron/bluetooth/rtc_timer.c
mode change 100644 => 100755 keyboards/keychron/bluetooth/rtc_timer.h
mode change 100644 => 100755 keyboards/keychron/bluetooth/transport.c
mode change 100644 => 100755 keyboards/keychron/bluetooth/transport.h
(limited to 'keyboards/keychron/bluetooth')
diff --git a/keyboards/keychron/bluetooth/bat_level_animation.c b/keyboards/keychron/bluetooth/bat_level_animation.c
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/bat_level_animation.h b/keyboards/keychron/bluetooth/bat_level_animation.h
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/battery.h b/keyboards/keychron/bluetooth/battery.h
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/bluetooth.h b/keyboards/keychron/bluetooth/bluetooth.h
old mode 100644
new mode 100755
index 99d406223d..0ef14e0d06
--- a/keyboards/keychron/bluetooth/bluetooth.h
+++ b/keyboards/keychron/bluetooth/bluetooth.h
@@ -32,11 +32,11 @@
/* 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_INITIALIZED, // 1
+ BLUETOOTH_DISCONNECTED, // 2
+ BLUETOOTH_CONNECTED, // 3
+ BLUETOOTH_PARING, // 4
+ BLUETOOTH_RECONNECTING, // 5
BLUETOOTH_SUSPEND
} bluetooth_state_t;
@@ -85,5 +85,3 @@ 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
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/bluetooth_config.h b/keyboards/keychron/bluetooth/bluetooth_config.h
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/bluetooth_event_type.h b/keyboards/keychron/bluetooth/bluetooth_event_type.h
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/bluetooth_main.c b/keyboards/keychron/bluetooth/bluetooth_main.c
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/ckbt51.c b/keyboards/keychron/bluetooth/ckbt51.c
old mode 100644
new mode 100755
index 2be217c091..4653825839
--- a/keyboards/keychron/bluetooth/ckbt51.c
+++ b/keyboards/keychron/bluetooth/ckbt51.c
@@ -14,6 +14,7 @@
* along with this program. If not, see .
*/
+#include
#include "quantum.h"
#include "ckbt51.h"
#include "bluetooth.h"
@@ -31,7 +32,7 @@
/* 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
+#define CKBT51_WAKE_WAIT_TIME 3000 // us
enum {
/* HID Report */
@@ -150,15 +151,17 @@ void ckbt51_send_cmd(uint8_t* payload, uint8_t len, bool ack_enable, bool retry)
systime_t start = 0;
- for (i=0; i< 3; i++) {
+ for (i = 0; i < 3; i++) {
writePin(CKBT51_INT_INPUT_PIN, i % 2);
start = chVTGetSystemTime();
- while (chTimeI2US(chVTTimeElapsedSinceX(start)) < CKBT51_WAKE_WAIT_TIME / 3) {};
+ 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];
+ for (i = 0; i < len; i++)
+ checksum += payload[i];
i = 0;
pkt[i++] = 0xAA;
@@ -190,7 +193,7 @@ void ckbt51_send_nkro(uint8_t* report) {
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
+ memcpy(payload + i, report, 20); // NKRO report lenght is limited to 20 bytes
i += 20;
ckbt51_send_cmd(payload, i, true, false);
@@ -203,7 +206,7 @@ void ckbt51_send_consumer(uint16_t report) {
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
+ i += 4; // QMK doesn't send multiple consumer reports, just skip 2nd and 3rd consumer reports
ckbt51_send_cmd(payload, i, true, false);
}
@@ -222,14 +225,14 @@ 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++] = 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]; // 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
+ payload[i++] = report[4]; // V wheel
+ payload[i++] = report[5]; // H wheel
ckbt51_send_cmd(payload, i, false, false);
}
@@ -255,13 +258,13 @@ void ckbt51_become_discoverable(uint8_t host_idx, void* 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++] = 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
+ 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);
@@ -276,8 +279,8 @@ void ckbt51_connect(uint8_t hostIndex, uint16_t timeout) {
memset(payload, 0, PACKET_MAX_LEN);
payload[i++] = CKBT51_CMD_CONNECT;
- payload[i++] = hostIndex; // Host index
- payload[i++] = timeout & 0xFF; // Timeout
+ payload[i++] = hostIndex; // Host index
+ payload[i++] = timeout & 0xFF; // Timeout
payload[i++] = (timeout >> 8) & 0xFF;
ckbt51_send_cmd(payload, i, true, false);
@@ -288,7 +291,7 @@ void ckbt51_disconnect(void) {
memset(payload, 0, PACKET_MAX_LEN);
payload[i++] = CKBT51_CMD_DISCONNECT;
- payload[i++] = 0; // Sleep mode
+ payload[i++] = 0; // Sleep mode
ckbt51_send_cmd(payload, i, true, false);
}
@@ -331,7 +334,7 @@ void ckbt51_set_param(module_param_t* param) {
memcpy(payload + i, param, sizeof(module_param_t));
i += sizeof(module_param_t);
- ckbt51_send_cmd(payload, i, false, false);
+ ckbt51_send_cmd(payload, i, true, false);
}
void ckbt51_get_param(module_param_t* param) {
@@ -351,7 +354,7 @@ void ckbt51_set_local_name(const char* name) {
payload[i++] = CKBT51_CMD_SET_NAME;
memcpy(payload + i, name, len);
i += len;
- ckbt51_send_cmd(payload, i, false, false);
+ ckbt51_send_cmd(payload, i, true, false);
}
void ckbt51_get_local_name(void) {
@@ -406,7 +409,8 @@ void ckbt51_dfu_tx(uint8_t rsp, uint8_t* data, uint8_t len, uint8_t sn) {
memcpy(&buf[i], data, len);
i += len;
- for (uint8_t k = 0; k < i; k++) checksum += buf[i];
+ for (uint8_t k = 0; k < i; k++)
+ checksum += buf[i];
raw_hid_send(buf, RAW_EPSIZE);
@@ -440,7 +444,7 @@ void ckbt51_dfu_rx(uint8_t* data, uint8_t length) {
bool retry = true;
if (sn != data[4]) {
- sn = data[4];
+ sn = data[4];
retry = false;
}
@@ -450,6 +454,8 @@ void ckbt51_dfu_rx(uint8_t* data, uint8_t length) {
}
}
+__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:
@@ -471,12 +477,13 @@ static void ack_handler(uint8_t* data, uint8_t len) {
break;
}
break;
- default: 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]) {
@@ -593,13 +600,13 @@ void ckbt51_task(void) {
for (uint8_t i = 0; i < len; i++) {
buf[i] = sdGetTimeout(&BT_DRIVER, TIME_IMMEDIATE);
-
}
wait_for_new_pkt = true;
uint16_t checksum = 0;
- for (int i = 0; i < len - 2; i++) checksum += buf[i];
+ 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);
diff --git a/keyboards/keychron/bluetooth/ckbt51.h b/keyboards/keychron/bluetooth/ckbt51.h
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/factory_test.c b/keyboards/keychron/bluetooth/factory_test.c
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/factory_test.h b/keyboards/keychron/bluetooth/factory_test.h
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/indicator.c b/keyboards/keychron/bluetooth/indicator.c
old mode 100644
new mode 100755
index fa111817dd..d4644dbd0c
--- a/keyboards/keychron/bluetooth/indicator.c
+++ b/keyboards/keychron/bluetooth/indicator.c
@@ -403,7 +403,7 @@ void indicator_battery_low_backlit_enable(bool enable) {
}
/* 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() | 1) : 0;
+ bat_low_backlit_indicator = enable ? (timer_read32() == 0 ? 1 : timer_read32()) : 0;
rtc_time = rtc_timer_read_ms();
bat_low_ind_state = 1;
@@ -448,7 +448,7 @@ void indicator_battery_low(void) {
bat_low_ind_state |= 0x80;
}
- bat_low_backlit_indicator = sync_timer_read32() | 1;
+ 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)) {
diff --git a/keyboards/keychron/bluetooth/indicator.h b/keyboards/keychron/bluetooth/indicator.h
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/lpm.c b/keyboards/keychron/bluetooth/lpm.c
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/lpm.h b/keyboards/keychron/bluetooth/lpm.h
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/lpm_stm32l432.c b/keyboards/keychron/bluetooth/lpm_stm32l432.c
old mode 100644
new mode 100755
index 8e9f2fa77f..69db4fc30d
--- a/keyboards/keychron/bluetooth/lpm_stm32l432.c
+++ b/keyboards/keychron/bluetooth/lpm_stm32l432.c
@@ -140,7 +140,6 @@ bool lpm_set(pm_t mode) {
}
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);
@@ -204,15 +203,15 @@ static inline void lpm_wakeup(void) {
#ifdef USB_POWER_SENSE_PIN
palDisableLineEvent(USB_POWER_SENSE_PIN);
-#if defined(KEEP_USB_CONNECTION_IN_BLUETOOTH_MODE)
+# 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. */
+ // PWR->CR2 |= PWR_CR2_USV; /* PWR_CR2_USV is available on STM32L4x2xx and STM32L4x3xx devices only. */
usb_power_connect();
usb_start(&USBD1);
}
-#endif
+# endif
#endif
@@ -277,7 +276,7 @@ void stm32_clock_fast_init(void) {
pll_init();
pllsai1_init();
pllsai2_init();
-/* clang-format off */
+ /* clang-format off */
/* Other clock-related settings (dividers, MCO etc).*/
RCC->CFGR = STM32_MCOPRE | STM32_MCOSEL | STM32_STOPWUCK |
STM32_PPRE2 | STM32_PPRE1 | STM32_HPRE;
@@ -289,7 +288,7 @@ void stm32_clock_fast_init(void) {
STM32_I2C3SEL | STM32_I2C2SEL | STM32_I2C1SEL |
STM32_UART5SEL | STM32_UART4SEL | STM32_USART3SEL |
STM32_USART2SEL | STM32_USART1SEL | STM32_LPUART1SEL;
-/* clang-format on */
+/* clang-format on */
# if STM32_SAI2SEL != STM32_SAI2SEL_OFF
ccipr |= STM32_SAI2SEL;
# endif
diff --git a/keyboards/keychron/bluetooth/lpm_stm32l432.h b/keyboards/keychron/bluetooth/lpm_stm32l432.h
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/report_buffer.c b/keyboards/keychron/bluetooth/report_buffer.c
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/report_buffer.h b/keyboards/keychron/bluetooth/report_buffer.h
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/rtc_timer.c b/keyboards/keychron/bluetooth/rtc_timer.c
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/rtc_timer.h b/keyboards/keychron/bluetooth/rtc_timer.h
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/transport.c b/keyboards/keychron/bluetooth/transport.c
old mode 100644
new mode 100755
diff --git a/keyboards/keychron/bluetooth/transport.h b/keyboards/keychron/bluetooth/transport.h
old mode 100644
new mode 100755
--
cgit v1.2.3