Update q6_pro.c

This commit is contained in:
lalalademaxiya1 2023-06-05 15:48:12 +08:00
parent c7b9295b75
commit ef737f8529

View file

@ -36,6 +36,7 @@ typedef struct PACKED {
uint8_t keycode[3]; uint8_t keycode[3];
} key_combination_t; } key_combination_t;
static uint32_t factory_timer_buffer = 0;
static uint32_t power_on_indicator_timer_buffer; static uint32_t power_on_indicator_timer_buffer;
static uint32_t siri_timer_buffer = 0; static uint32_t siri_timer_buffer = 0;
static uint8_t mac_keycode[4] = {KC_LOPT, KC_ROPT, KC_LCMD, KC_RCMD}; static uint8_t mac_keycode[4] = {KC_LOPT, KC_ROPT, KC_LCMD, KC_RCMD};
@ -143,7 +144,9 @@ void keyboard_post_init_kb(void) {
#ifdef KC_BLUETOOTH_ENABLE #ifdef KC_BLUETOOTH_ENABLE
/* Currently we don't use this reset pin */ /* Currently we don't use this reset pin */
palSetLineMode(CKBT51_RESET_PIN, PAL_MODE_UNCONNECTED); // palSetLineMode(CKBT51_RESET_PIN, PAL_MODE_UNCONNECTED);
palSetLineMode(CKBT51_RESET_PIN, PAL_MODE_OUTPUT_PUSHPULL);
palWriteLine(CKBT51_RESET_PIN, PAL_HIGH);
/* IMPORTANT: DO NOT enable internal pull-up resistor /* IMPORTANT: DO NOT enable internal pull-up resistor
* as there is an external pull-down resistor. * as there is an external pull-down resistor.
@ -171,7 +174,20 @@ void keyboard_post_init_kb(void) {
keyboard_post_init_user(); keyboard_post_init_user();
} }
static void ckbt51_param_init(void);
void matrix_scan_kb(void) { void matrix_scan_kb(void) {
if (factory_timer_buffer && timer_elapsed32(factory_timer_buffer) > 20000) {
factory_timer_buffer = 0;
if (bt_factory_reset) {
bt_factory_reset = false;
ckbt51_param_init();
palWriteLine(CKBT51_RESET_PIN, PAL_LOW);
wait_ms(5);
palWriteLine(CKBT51_RESET_PIN, PAL_HIGH);
}
}
if (power_on_indicator_timer_buffer) { if (power_on_indicator_timer_buffer) {
if (sync_timer_elapsed32(power_on_indicator_timer_buffer) > POWER_ON_LED_DURATION) { if (sync_timer_elapsed32(power_on_indicator_timer_buffer) > POWER_ON_LED_DURATION) {
power_on_indicator_timer_buffer = 0; power_on_indicator_timer_buffer = 0;
@ -198,6 +214,7 @@ static void ckbt51_param_init(void) {
/* Set bluetooth device name */ /* Set bluetooth device name */
// ckbt51_set_local_name(STR(PRODUCT)); // ckbt51_set_local_name(STR(PRODUCT));
ckbt51_set_local_name(PRODUCT); ckbt51_set_local_name(PRODUCT);
wait_ms(10);
/* Set bluetooth parameters */ /* Set bluetooth parameters */
module_param_t param = {.event_mode = 0x02, module_param_t param = {.event_mode = 0x02,
.connected_idle_timeout = 7200, .connected_idle_timeout = 7200,
@ -213,9 +230,9 @@ static void ckbt51_param_init(void) {
void bluetooth_enter_disconnected_kb(uint8_t host_idx) { void bluetooth_enter_disconnected_kb(uint8_t host_idx) {
if (bt_factory_reset) { if (bt_factory_reset) {
bt_factory_reset = false; factory_timer_buffer = timer_read32();
ckbt51_param_init();
} }
/* CKBT51 bluetooth module boot time is slower, it enters disconnected after boot, /* CKBT51 bluetooth module boot time is slower, it enters disconnected after boot,
so we place initialization here. */ so we place initialization here. */
if (firstDisconnect && sync_timer_read32() < 1000 && get_transport() == TRANSPORT_BLUETOOTH) { if (firstDisconnect && sync_timer_read32() < 1000 && get_transport() == TRANSPORT_BLUETOOTH) {
@ -226,18 +243,18 @@ void bluetooth_enter_disconnected_kb(uint8_t host_idx) {
} }
void ckbt51_default_ack_handler(uint8_t *data, uint8_t len) { void ckbt51_default_ack_handler(uint8_t *data, uint8_t len) {
if (data[1] == 0x45) { // if (data[1] == 0x45) {
module_param_t param = {.event_mode = 0x02, // module_param_t param = {.event_mode = 0x02,
.connected_idle_timeout = 7200, // .connected_idle_timeout = 7200,
.pairing_timeout = 180, // .pairing_timeout = 180,
.pairing_mode = 0, // .pairing_mode = 0,
.reconnect_timeout = 5, // .reconnect_timeout = 5,
.report_rate = 90, // .report_rate = 90,
.vendor_id_source = 1, // .vendor_id_source = 1,
.verndor_id = 0, // Must be 0x3434 // .verndor_id = 0, // Must be 0x3434
.product_id = PRODUCT_ID}; // .product_id = PRODUCT_ID};
ckbt51_set_param(&param); // ckbt51_set_param(&param);
} // }
} }
void bluetooth_pre_task(void) { void bluetooth_pre_task(void) {