diff options
Diffstat (limited to 'keyboards/keychron/bluetooth/bluetooth.c')
-rw-r--r-- | keyboards/keychron/bluetooth/bluetooth.c | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/keyboards/keychron/bluetooth/bluetooth.c b/keyboards/keychron/bluetooth/bluetooth.c index 690ddde716..ad133bc9b0 100644 --- a/keyboards/keychron/bluetooth/bluetooth.c +++ b/keyboards/keychron/bluetooth/bluetooth.c @@ -21,6 +21,7 @@ #include "battery.h" #include "indicator.h" #include "transport.h" +#include "rtc_timer.h" extern uint8_t pairing_indication; extern host_driver_t chibios_driver; @@ -29,11 +30,6 @@ extern uint32_t retry_time_buffer; extern uint8_t retry; #ifdef NKRO_ENABLE -typedef struct { - bool usb : 1; - bool bluetooth : 1; -} nkro_t; - extern nkro_t nkro; #endif @@ -100,8 +96,14 @@ void bluetooth_init(void) { #ifdef BLUETOOTH_INT_INPUT_PIN setPinInputHigh(BLUETOOTH_INT_INPUT_PIN); #endif - + lpm_init(); + rtc_timer_init(); + +#ifdef BLUETOOTH_NKRO_ENABLE + keymap_config.raw = eeconfig_read_keymap(); + nkro.bluetooth = keymap_config.nkro; +#endif } /* @@ -205,7 +207,7 @@ static void bluetooth_enter_connected(uint8_t host_idx) { clear_keyboard(); - /* Enable NKRO since it may be disabled in pin code entry */ + /* Enable NKRO since it may be disabled in pin code entry */ #if defined(NKRO_ENABLE) && defined(BLUETOOTH_NKRO_ENABLE) keymap_config.nkro = nkro.bluetooth; #else @@ -213,8 +215,11 @@ static void bluetooth_enter_connected(uint8_t host_idx) { #endif bluetooth_enter_connected_kb(host_idx); - - if (battery_is_empty()) indicator_battery_low_enable(true); +#ifdef BAT_LOW_LED_PIN + if (battery_is_empty()) { + indicator_battery_low_enable(true); + } +#endif } /* Enters disconnected state. Upon entering this state we perform the following actions: @@ -224,7 +229,7 @@ static void bluetooth_enter_connected(uint8_t host_idx) { static void bluetooth_enter_disconnected(uint8_t host_idx) { uint8_t previous_state = bt_state; bt_state = BLUETOOTH_DISCONNECTED; - + if (previous_state == BLUETOOTH_CONNECTED) { lpm_timer_reset(); indicator_set(BLUETOOTH_SUSPEND, host_idx); @@ -236,10 +241,14 @@ static void bluetooth_enter_disconnected(uint8_t host_idx) { #endif retry = 0; bluetooth_enter_disconnected_kb(host_idx); +#ifdef BAT_LOW_LED_PIN indicator_battery_low_enable(false); +#endif +#if defined(LOW_BAT_IND_INDEX) + indicator_battery_low_backlit_enable(false); +#endif } - /* Enter pin code entry state. */ static void bluetooth_enter_pin_code_entry(void) { #if defined(NKRO_ENABLE) @@ -267,8 +276,8 @@ __attribute__((weak)) void bluetooth_enter_pin_code_entry_kb(void) {} __attribute__((weak)) void bluetooth_exit_pin_code_entry_kb(void){}; /* */ -static void bluetooth_hid_set_protocol(bool report_protocol) { - bluetooth_report_protocol = false; +static void bluetooth_hid_set_protocol(bool report_protocol) { + bluetooth_report_protocol = false; } uint8_t bluetooth_keyboard_leds(void) { @@ -329,7 +338,7 @@ void bluetooth_send_keyboard(report_keyboard_t *report) { //#endif } - } else if (bt_state != BLUETOOTH_RESET) { + } else if (bt_state != BLUETOOTH_RESET) { bluetooth_connect(); } } @@ -380,7 +389,12 @@ void bluetooth_send_extra(report_extra_t *report) { } void bluetooth_low_battery_shutdown(void) { +#ifdef BAT_LOW_LED_PIN indicator_battery_low_enable(false); +#endif +#if defined(LOW_BAT_IND_INDEX) + indicator_battery_low_backlit_enable(false); +#endif bluetooth_disconnect(); } @@ -444,9 +458,24 @@ bluetooth_state_t bluetooth_get_state(void) { __attribute__((weak)) bool process_record_kb_bt(uint16_t keycode, keyrecord_t *record) { return true;}; bool process_record_kb(uint16_t keycode, keyrecord_t *record) { + if (!process_record_user(keycode, record)) { + return false; + } + if (get_transport() == TRANSPORT_BLUETOOTH) { lpm_timer_reset(); + +#if defined(BAT_LOW_LED_PIN) || defined(LOW_BAT_IND_INDEX) + if (battery_is_empty() && bluetooth_get_state() == BLUETOOTH_CONNECTED && record->event.pressed) { +# if defined(BAT_LOW_LED_PIN) + indicator_battery_low_enable(true); +# endif +# if defined(LOW_BAT_IND_INDEX) + indicator_battery_low_backlit_enable(true); +# endif + } +#endif } - process_record_kb_bt(keycode, record); - return process_record_user(keycode, record); + return process_record_kb_bt(keycode, record); + // return process_record_user(keycode, record); } |