summaryrefslogtreecommitdiffstats
path: root/keyboards/keychron/k5_pro/k5_pro.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/keychron/k5_pro/k5_pro.c')
-rw-r--r--keyboards/keychron/k5_pro/k5_pro.c52
1 files changed, 43 insertions, 9 deletions
diff --git a/keyboards/keychron/k5_pro/k5_pro.c b/keyboards/keychron/k5_pro/k5_pro.c
index f86f054944..a213c19e61 100644
--- a/keyboards/keychron/k5_pro/k5_pro.c
+++ b/keyboards/keychron/k5_pro/k5_pro.c
@@ -15,6 +15,7 @@
*/
#include "k5_pro.h"
+#include <stdbool.h>
#ifdef KC_BLUETOOTH_ENABLE
# include "ckbt51.h"
# include "bluetooth.h"
@@ -29,7 +30,8 @@
# include "factory_test.h"
#endif
-#ifndef POWER_ON_LED_DURATION
+#ifdef BAT_LOW_LED_PIN
+static uint32_t power_on_indicator_timer_buffer;
# define POWER_ON_LED_DURATION 3000
#endif
@@ -38,9 +40,9 @@ typedef struct PACKED {
uint8_t keycode[3];
} key_combination_t;
-static uint32_t power_on_indicator_timer_buffer;
-static uint32_t siri_timer_buffer = 0;
-static uint8_t mac_keycode[4] = {KC_LOPT, KC_ROPT, KC_LCMD, KC_RCMD};
+static uint32_t factory_timer_buffer = 0;
+static uint32_t siri_timer_buffer = 0;
+static uint8_t mac_keycode[4] = {KC_LOPT, KC_ROPT, KC_LCMD, KC_RCMD};
key_combination_t key_comb_list[4] = {
{2, {KC_LWIN, KC_TAB}}, // Task (win)
@@ -63,9 +65,9 @@ static void pairing_key_timer_cb(void *arg) {
bool dip_switch_update_kb(uint8_t index, bool active) {
if (index == 0) {
#ifdef INVERT_OS_SWITCH_STATTE
- default_layer_set(1UL << (!active ? 2 : 0));
+ default_layer_set(1UL << (!active ? 0 : 2));
#else
- default_layer_set(1UL << (active ? 2 : 0));
+ default_layer_set(1UL << (active ? 0 : 2));
#endif
}
dip_switch_update_user(index, active);
@@ -81,6 +83,20 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
static uint8_t host_idx = 0;
switch (keycode) {
+ case KC_MICT:
+ if (record->event.pressed) {
+ register_code(KC_MISSION_CONTROL);
+ } else {
+ unregister_code(KC_MISSION_CONTROL);
+ }
+ return false; // Skip all further processing of this key
+ case KC_LAPA:
+ if (record->event.pressed) {
+ register_code(KC_LAUNCHPAD);
+ } else {
+ unregister_code(KC_LAUNCHPAD);
+ }
+ return false; // Skip all further processing of this key
case KC_LOPTN:
case KC_ROPTN:
case KC_LCMMD:
@@ -143,7 +159,8 @@ void keyboard_post_init_kb(void) {
#ifdef KC_BLUETOOTH_ENABLE
/* Currently we don't use this reset pin */
- 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
* as there is an external pull-down resistor.
@@ -165,6 +182,16 @@ void keyboard_post_init_kb(void) {
}
void matrix_scan_kb(void) {
+ if (factory_timer_buffer && timer_elapsed32(factory_timer_buffer) > 2000) {
+ factory_timer_buffer = 0;
+ if (bt_factory_reset) {
+ bt_factory_reset = false;
+ palWriteLine(CKBT51_RESET_PIN, PAL_LOW);
+ wait_ms(5);
+ palWriteLine(CKBT51_RESET_PIN, PAL_HIGH);
+ }
+ }
+
if (power_on_indicator_timer_buffer) {
if (sync_timer_elapsed32(power_on_indicator_timer_buffer) > POWER_ON_LED_DURATION) {
power_on_indicator_timer_buffer = 0;
@@ -193,8 +220,8 @@ void matrix_scan_kb(void) {
#ifdef KC_BLUETOOTH_ENABLE
static void ckbt51_param_init(void) {
/* Set bluetooth device name */
- // ckbt51_set_local_name(STR(PRODUCT));
ckbt51_set_local_name(PRODUCT);
+ wait_ms(10);
/* Set bluetooth parameters */
module_param_t param = {.event_mode = 0x02,
.connected_idle_timeout = 7200,
@@ -206,6 +233,7 @@ static void ckbt51_param_init(void) {
.verndor_id = 0, // Must be 0x3434
.product_id = PRODUCT_ID};
ckbt51_set_param(&param);
+ wait_ms(10);
}
void ckbt51_default_ack_handler(uint8_t *data, uint8_t len) {
@@ -225,8 +253,8 @@ void ckbt51_default_ack_handler(uint8_t *data, uint8_t len) {
void bluetooth_enter_disconnected_kb(uint8_t host_idx) {
if (bt_factory_reset) {
- bt_factory_reset = false;
ckbt51_param_init();
+ factory_timer_buffer = timer_read32();
}
/* CKBT51 bluetooth module boot time is slower, it enters disconnected after boot,
so we place initialization here. */
@@ -306,3 +334,9 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
}
}
#endif
+
+void suspend_wakeup_init_kb(void) {
+ // code will run on keyboard wakeup
+ clear_keyboard();
+ send_keyboard_report();
+}