summaryrefslogtreecommitdiffstats
path: root/keyboards/keychron/bluetooth
diff options
context:
space:
mode:
authorlalalademaxiya1 <2831039915@qq.com>2023-03-15 16:51:53 +0800
committerlalalademaxiya1 <2831039915@qq.com>2023-03-15 16:51:53 +0800
commitc6243da12f6643747a24a7aa761e103cc4a848c2 (patch)
tree82d29a9567d09c2d3845654c7e5b16b284b2bc30 /keyboards/keychron/bluetooth
parentee715fc26ade41e56f47e60527f17d5cbdfb584b (diff)
Update Keychron K Pro series keyboards
Diffstat (limited to 'keyboards/keychron/bluetooth')
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/bat_level_animation.c0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/bat_level_animation.h0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/battery.h0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/bluetooth.h12
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/bluetooth.mk0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/bluetooth_config.h0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/bluetooth_event_type.h0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/bluetooth_main.c0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/ckbt51.c63
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/ckbt51.h0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/factory_test.c0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/factory_test.h0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/indicator.c4
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/indicator.h0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/lpm.c0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/lpm.h0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/lpm_stm32l432.c11
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/lpm_stm32l432.h0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/report_buffer.c0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/report_buffer.h0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/rtc_timer.c0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/rtc_timer.h0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/transport.c0
-rwxr-xr-x[-rw-r--r--]keyboards/keychron/bluetooth/transport.h0
24 files changed, 47 insertions, 43 deletions
diff --git a/keyboards/keychron/bluetooth/bat_level_animation.c b/keyboards/keychron/bluetooth/bat_level_animation.c
index e63735bcff..e63735bcff 100644..100755
--- a/keyboards/keychron/bluetooth/bat_level_animation.c
+++ b/keyboards/keychron/bluetooth/bat_level_animation.c
diff --git a/keyboards/keychron/bluetooth/bat_level_animation.h b/keyboards/keychron/bluetooth/bat_level_animation.h
index 716e924103..716e924103 100644..100755
--- a/keyboards/keychron/bluetooth/bat_level_animation.h
+++ b/keyboards/keychron/bluetooth/bat_level_animation.h
diff --git a/keyboards/keychron/bluetooth/battery.h b/keyboards/keychron/bluetooth/battery.h
index 45de2bc23a..45de2bc23a 100644..100755
--- a/keyboards/keychron/bluetooth/battery.h
+++ b/keyboards/keychron/bluetooth/battery.h
diff --git a/keyboards/keychron/bluetooth/bluetooth.h b/keyboards/keychron/bluetooth/bluetooth.h
index 99d406223d..0ef14e0d06 100644..100755
--- 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
index 70db522586..70db522586 100644..100755
--- a/keyboards/keychron/bluetooth/bluetooth.mk
+++ b/keyboards/keychron/bluetooth/bluetooth.mk
diff --git a/keyboards/keychron/bluetooth/bluetooth_config.h b/keyboards/keychron/bluetooth/bluetooth_config.h
index 26dbc81f6c..26dbc81f6c 100644..100755
--- a/keyboards/keychron/bluetooth/bluetooth_config.h
+++ b/keyboards/keychron/bluetooth/bluetooth_config.h
diff --git a/keyboards/keychron/bluetooth/bluetooth_event_type.h b/keyboards/keychron/bluetooth/bluetooth_event_type.h
index 8ce55d7616..8ce55d7616 100644..100755
--- a/keyboards/keychron/bluetooth/bluetooth_event_type.h
+++ b/keyboards/keychron/bluetooth/bluetooth_event_type.h
diff --git a/keyboards/keychron/bluetooth/bluetooth_main.c b/keyboards/keychron/bluetooth/bluetooth_main.c
index eabcc83826..eabcc83826 100644..100755
--- a/keyboards/keychron/bluetooth/bluetooth_main.c
+++ b/keyboards/keychron/bluetooth/bluetooth_main.c
diff --git a/keyboards/keychron/bluetooth/ckbt51.c b/keyboards/keychron/bluetooth/ckbt51.c
index 2be217c091..4653825839 100644..100755
--- a/keyboards/keychron/bluetooth/ckbt51.c
+++ b/keyboards/keychron/bluetooth/ckbt51.c
@@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <stdbool.h>
#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
index f0bc08a98f..f0bc08a98f 100644..100755
--- a/keyboards/keychron/bluetooth/ckbt51.h
+++ b/keyboards/keychron/bluetooth/ckbt51.h
diff --git a/keyboards/keychron/bluetooth/factory_test.c b/keyboards/keychron/bluetooth/factory_test.c
index 9de130a26b..9de130a26b 100644..100755
--- a/keyboards/keychron/bluetooth/factory_test.c
+++ b/keyboards/keychron/bluetooth/factory_test.c
diff --git a/keyboards/keychron/bluetooth/factory_test.h b/keyboards/keychron/bluetooth/factory_test.h
index d5ef301512..d5ef301512 100644..100755
--- a/keyboards/keychron/bluetooth/factory_test.h
+++ b/keyboards/keychron/bluetooth/factory_test.h
diff --git a/keyboards/keychron/bluetooth/indicator.c b/keyboards/keychron/bluetooth/indicator.c
index fa111817dd..d4644dbd0c 100644..100755
--- 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
index d1345d2235..d1345d2235 100644..100755
--- a/keyboards/keychron/bluetooth/indicator.h
+++ b/keyboards/keychron/bluetooth/indicator.h
diff --git a/keyboards/keychron/bluetooth/lpm.c b/keyboards/keychron/bluetooth/lpm.c
index 187c6d75c0..187c6d75c0 100644..100755
--- a/keyboards/keychron/bluetooth/lpm.c
+++ b/keyboards/keychron/bluetooth/lpm.c
diff --git a/keyboards/keychron/bluetooth/lpm.h b/keyboards/keychron/bluetooth/lpm.h
index bacc82a716..bacc82a716 100644..100755
--- a/keyboards/keychron/bluetooth/lpm.h
+++ b/keyboards/keychron/bluetooth/lpm.h
diff --git a/keyboards/keychron/bluetooth/lpm_stm32l432.c b/keyboards/keychron/bluetooth/lpm_stm32l432.c
index 8e9f2fa77f..69db4fc30d 100644..100755
--- 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
index 065bf96b47..065bf96b47 100644..100755
--- a/keyboards/keychron/bluetooth/lpm_stm32l432.h
+++ b/keyboards/keychron/bluetooth/lpm_stm32l432.h
diff --git a/keyboards/keychron/bluetooth/report_buffer.c b/keyboards/keychron/bluetooth/report_buffer.c
index 51225888c9..51225888c9 100644..100755
--- a/keyboards/keychron/bluetooth/report_buffer.c
+++ b/keyboards/keychron/bluetooth/report_buffer.c
diff --git a/keyboards/keychron/bluetooth/report_buffer.h b/keyboards/keychron/bluetooth/report_buffer.h
index ef53b6fc5a..ef53b6fc5a 100644..100755
--- a/keyboards/keychron/bluetooth/report_buffer.h
+++ b/keyboards/keychron/bluetooth/report_buffer.h
diff --git a/keyboards/keychron/bluetooth/rtc_timer.c b/keyboards/keychron/bluetooth/rtc_timer.c
index 04ebd43995..04ebd43995 100644..100755
--- a/keyboards/keychron/bluetooth/rtc_timer.c
+++ b/keyboards/keychron/bluetooth/rtc_timer.c
diff --git a/keyboards/keychron/bluetooth/rtc_timer.h b/keyboards/keychron/bluetooth/rtc_timer.h
index aa73a31c8a..aa73a31c8a 100644..100755
--- a/keyboards/keychron/bluetooth/rtc_timer.h
+++ b/keyboards/keychron/bluetooth/rtc_timer.h
diff --git a/keyboards/keychron/bluetooth/transport.c b/keyboards/keychron/bluetooth/transport.c
index e5986de11b..e5986de11b 100644..100755
--- a/keyboards/keychron/bluetooth/transport.c
+++ b/keyboards/keychron/bluetooth/transport.c
diff --git a/keyboards/keychron/bluetooth/transport.h b/keyboards/keychron/bluetooth/transport.h
index 29722cd265..29722cd265 100644..100755
--- a/keyboards/keychron/bluetooth/transport.h
+++ b/keyboards/keychron/bluetooth/transport.h