summaryrefslogtreecommitdiffstats
path: root/keyboards/keychron/bluetooth/ckbt51.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/keychron/bluetooth/ckbt51.c')
-rw-r--r--keyboards/keychron/bluetooth/ckbt51.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/keyboards/keychron/bluetooth/ckbt51.c b/keyboards/keychron/bluetooth/ckbt51.c
index f60101d8bf..2be217c091 100644
--- a/keyboards/keychron/bluetooth/ckbt51.c
+++ b/keyboards/keychron/bluetooth/ckbt51.c
@@ -39,8 +39,8 @@ enum {
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_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,
@@ -51,14 +51,14 @@ enum {
/* 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,
+ /* 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,
@@ -69,10 +69,11 @@ enum {
/* 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,
+ CKBT51_EVT_OTA_RSP = 0xA3,
+ CKBT51_CONNECTION_EVT_ACK = 0xA4,
};
enum {
@@ -139,11 +140,14 @@ void ckbt51_init(bool wakeup_from_low_power_mode) {
}
void ckbt51_send_cmd(uint8_t* payload, uint8_t len, bool ack_enable, bool retry) {
- static uint8_t sn = 1;
+ 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++) {
@@ -161,15 +165,13 @@ void ckbt51_send_cmd(uint8_t* payload, uint8_t len, bool ack_enable, bool retry)
pkt[i++] = ack_enable ? 0x56 : 0x55;
pkt[i++] = len + 2;
pkt[i++] = ~(len + 2) & 0xFF;
- pkt[i++] = sn++;
+ pkt[i++] = sn;
memcpy(pkt + i, payload, len);
i += len;
pkt[i++] = checksum & 0xFF;
pkt[i++] = (checksum >> 8) & 0xFF;
sdWrite(&BT_DRIVER, pkt, i);
-
- if (sn == 0) sn = 1;
}
void ckbt51_send_keyboard(uint8_t* report) {
@@ -352,7 +354,7 @@ void ckbt51_set_local_name(const char* name) {
ckbt51_send_cmd(payload, i, false, false);
}
-void ckbt51_get_local_name(char* name) {
+void ckbt51_get_local_name(void) {
uint8_t i = 0;
memset(payload, 0, PACKET_MAX_LEN);
@@ -379,6 +381,16 @@ void ckbt51_int_pin_test(bool 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};