diff options
Diffstat (limited to 'keyboards/keychron/bluetooth')
-rw-r--r-- | keyboards/keychron/bluetooth/bluetooth.c | 15 | ||||
-rw-r--r-- | keyboards/keychron/bluetooth/bluetooth_config.h | 9 | ||||
-rw-r--r-- | keyboards/keychron/bluetooth/ckbt51.c | 47 | ||||
-rw-r--r-- | keyboards/keychron/bluetooth/ckbt51.h | 2 | ||||
-rw-r--r-- | keyboards/keychron/bluetooth/factory_test.c | 4 |
5 files changed, 47 insertions, 30 deletions
diff --git a/keyboards/keychron/bluetooth/bluetooth.c b/keyboards/keychron/bluetooth/bluetooth.c index c026a72d4c..690ddde716 100644 --- a/keyboards/keychron/bluetooth/bluetooth.c +++ b/keyboards/keychron/bluetooth/bluetooth.c @@ -50,9 +50,6 @@ uint8_t bluetooth_keyboard_leds(void); void bluetooth_send_keyboard(report_keyboard_t *report); void bluetooth_send_mouse(report_mouse_t *report); void bluetooth_send_extra(report_extra_t *report); -void bluetooth_send_system(uint16_t data); -void bluetooth_send_consumer(uint16_t data); - /* host struct */ host_driver_t bluetooth_driver = {bluetooth_keyboard_leds, bluetooth_send_keyboard, bluetooth_send_mouse, bluetooth_send_extra}; @@ -345,9 +342,6 @@ void bluetooth_send_mouse(report_mouse_t *report) { } } -void bluetooth_send_extra(report_extra_t *report) { -} - void bluetooth_send_system(uint16_t data) { if (bt_state == BLUETOOTH_CONNECTED) { if (bluetooth_transport.send_system) bluetooth_transport.send_system(data); @@ -376,6 +370,15 @@ void bluetooth_send_consumer(uint16_t data) { } } +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) { indicator_battery_low_enable(false); bluetooth_disconnect(); diff --git a/keyboards/keychron/bluetooth/bluetooth_config.h b/keyboards/keychron/bluetooth/bluetooth_config.h index 5135cee624..26dbc81f6c 100644 --- a/keyboards/keychron/bluetooth/bluetooth_config.h +++ b/keyboards/keychron/bluetooth/bluetooth_config.h @@ -19,14 +19,19 @@ #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 +# 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 +# define CONNECTED_BACKLIGHT_OFF_DELAY_TIME 600 #endif #endif diff --git a/keyboards/keychron/bluetooth/ckbt51.c b/keyboards/keychron/bluetooth/ckbt51.c index d89ec9a9d3..7286fe40e1 100644 --- a/keyboards/keychron/bluetooth/ckbt51.c +++ b/keyboards/keychron/bluetooth/ckbt51.c @@ -138,7 +138,7 @@ void ckbt51_init(bool wakeup_from_low_power_mode) { writePinHigh(CKBT51_INT_INPUT_PIN); } -void ckbt51_send_cmd(uint8_t* payload, uint8_t len, bool ack_enable) { +void ckbt51_send_cmd(uint8_t* payload, uint8_t len, bool ack_enable, bool retry) { static uint8_t sn = 1; uint8_t i; uint8_t pkt[PACKET_MAX_LEN] = {0}; @@ -180,7 +180,7 @@ void ckbt51_send_keyboard(uint8_t* report) { memcpy(payload + i, report, 8); i += 8; - ckbt51_send_cmd(payload, i, true); + ckbt51_send_cmd(payload, i, true, false); } void ckbt51_send_nkro(uint8_t* report) { @@ -191,7 +191,7 @@ void ckbt51_send_nkro(uint8_t* report) { memcpy(payload + i, report, 20); // NKRO report lenght is limited to 20 bytes i += 20; - ckbt51_send_cmd(payload, i, true); + ckbt51_send_cmd(payload, i, true, false); } void ckbt51_send_consumer(uint16_t report) { @@ -203,7 +203,7 @@ void ckbt51_send_consumer(uint16_t report) { 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); + ckbt51_send_cmd(payload, i, true, false); } void ckbt51_send_system(uint16_t report) { @@ -213,7 +213,7 @@ void ckbt51_send_system(uint16_t report) { payload[i++] = CKBT51_CMD_SEND_SYSTEM; payload[i++] = report & 0xFF; - ckbt51_send_cmd(payload, i, true); + ckbt51_send_cmd(payload, i, true, false); } void ckbt51_send_mouse(uint8_t* report) { @@ -229,7 +229,7 @@ void ckbt51_send_mouse(uint8_t* report) { payload[i++] = report[4]; // V wheel payload[i++] = report[5]; // H wheel - ckbt51_send_cmd(payload, i, false); + ckbt51_send_cmd(payload, i, false, false); } /* Send ack to connection event, bluetooth module will retry 2 times if no ack received */ @@ -239,7 +239,7 @@ void ckbt51_send_conn_evt_ack(void) { payload[i++] = CKBT51_CONNECTION_EVT_ACK; - ckbt51_send_cmd(payload, i, false); + ckbt51_send_cmd(payload, i, false, false); } void ckbt51_become_discoverable(uint8_t host_idx, void* param) { @@ -265,7 +265,7 @@ void ckbt51_become_discoverable(uint8_t host_idx, void* param) { i += strlen(p->leName); } - ckbt51_send_cmd(payload, i, true); + ckbt51_send_cmd(payload, i, true, false); } /* Timeout : 2 ~ 255 seconds */ @@ -278,7 +278,7 @@ void ckbt51_connect(uint8_t hostIndex, uint16_t timeout) { payload[i++] = timeout & 0xFF; // Timeout payload[i++] = (timeout >> 8) & 0xFF; - ckbt51_send_cmd(payload, i, true); + ckbt51_send_cmd(payload, i, true, false); } void ckbt51_disconnect(void) { @@ -288,7 +288,7 @@ void ckbt51_disconnect(void) { payload[i++] = CKBT51_CMD_DISCONNECT; payload[i++] = 0; // Sleep mode - ckbt51_send_cmd(payload, i, true); + ckbt51_send_cmd(payload, i, true, false); } void ckbt51_switch_host(uint8_t hostIndex) { @@ -298,7 +298,7 @@ void ckbt51_switch_host(uint8_t hostIndex) { payload[i++] = CKBT51_CMD_SWITCH_HOST; payload[i++] = hostIndex; - ckbt51_send_cmd(payload, i, true); + ckbt51_send_cmd(payload, i, true, false); } void ckbt51_read_state_reg(uint8_t reg, uint8_t len) { @@ -310,7 +310,7 @@ void ckbt51_read_state_reg(uint8_t reg, uint8_t len) { payload[i++] = len; // TODO - ckbt51_send_cmd(payload, i, false); + ckbt51_send_cmd(payload, i, false, false); } void ckbt51_get_info(module_info_t* info) { @@ -318,7 +318,7 @@ void ckbt51_get_info(module_info_t* info) { memset(payload, 0, PACKET_MAX_LEN); payload[i++] = CKBT51_CMD_GET_MODULE_INFO; - ckbt51_send_cmd(payload, i, false); + ckbt51_send_cmd(payload, i, false, false); } void ckbt51_set_param(module_param_t* param) { @@ -329,7 +329,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); + ckbt51_send_cmd(payload, i, false, false); } void ckbt51_get_param(module_param_t* param) { @@ -338,7 +338,7 @@ void ckbt51_get_param(module_param_t* param) { payload[i++] = CKBT51_CMD_GET_CONFIG; - ckbt51_send_cmd(payload, i, false); + ckbt51_send_cmd(payload, i, false, false); } void ckbt51_set_local_name(const char* name) { @@ -349,7 +349,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); + ckbt51_send_cmd(payload, i, false, false); } void ckbt51_get_local_name(char* name) { @@ -358,7 +358,7 @@ void ckbt51_get_local_name(char* name) { payload[i++] = CKBT51_CMD_GET_NAME; - ckbt51_send_cmd(payload, i, false); + ckbt51_send_cmd(payload, i, false, false); } void ckbt51_factory_reset(void) { @@ -367,7 +367,7 @@ void ckbt51_factory_reset(void) { payload[i++] = CKBT51_CMD_FACTORY_RESET; - ckbt51_send_cmd(payload, i, false); + ckbt51_send_cmd(payload, i, false, false); } void ckbt51_int_pin_test(bool enable) { @@ -376,7 +376,7 @@ void ckbt51_int_pin_test(bool enable) { payload[i++] = CKBT51_CMD_INT_PIN_TEST; payload[i++] = enable; - ckbt51_send_cmd(payload, i, false); + ckbt51_send_cmd(payload, i, false, false); } void ckbt51_dfu_tx(uint8_t rsp, uint8_t* data, uint8_t len, uint8_t sn) { @@ -424,9 +424,16 @@ void ckbt51_dfu_rx(uint8_t* data, uint8_t length) { /* 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); + ckbt51_send_cmd(payload, payload_len - 2, data[1] == 0x56, retry); } } } diff --git a/keyboards/keychron/bluetooth/ckbt51.h b/keyboards/keychron/bluetooth/ckbt51.h index 0992aea01f..ff6da33a07 100644 --- a/keyboards/keychron/bluetooth/ckbt51.h +++ b/keyboards/keychron/bluetooth/ckbt51.h @@ -128,7 +128,7 @@ typedef struct { } __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); +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); diff --git a/keyboards/keychron/bluetooth/factory_test.c b/keyboards/keychron/bluetooth/factory_test.c index 16cce079d8..e2915dd013 100644 --- a/keyboards/keychron/bluetooth/factory_test.c +++ b/keyboards/keychron/bluetooth/factory_test.c @@ -179,10 +179,12 @@ void process_record_factory_reset(uint16_t keycode, keyrecord_t *record) { } #ifdef LED_MATRIX_ENABLE -void led_matrix_indicators_user(void) { +bool led_matrix_indicators_user(void) { if (factory_reset_ind_state) { led_matrix_set_value_all(factory_reset_ind_state % 2 ? 0 : 255); } + + return false; } #endif |