diff options
author | lalalademaxiya1 <2831039915@qq.com> | 2023-03-02 17:31:35 +0800 |
---|---|---|
committer | lalalademaxiya1 <2831039915@qq.com> | 2023-03-02 17:31:35 +0800 |
commit | 09c270ab0db52ad8564cc35952a243551860ea21 (patch) | |
tree | 1c6b6517651f460b9b612e3492a56c2392134d69 /keyboards/keychron/bluetooth | |
parent | 77f3d1738b6c9cba7aa7aae840200317a2bad73e (diff) |
Add some new boards
Added k1_pro, k5_pro, k9_pro, k13_pro, q2_pro and q3_pro.
Diffstat (limited to 'keyboards/keychron/bluetooth')
-rwxr-xr-x[-rw-r--r--] | keyboards/keychron/bluetooth/battery.c | 6 | ||||
-rwxr-xr-x[-rw-r--r--] | keyboards/keychron/bluetooth/bluetooth.c | 54 | ||||
-rw-r--r-- | keyboards/keychron/bluetooth/factory_test.c | 10 | ||||
-rw-r--r-- | keyboards/keychron/bluetooth/indicator.c | 32 | ||||
-rw-r--r-- | keyboards/keychron/bluetooth/indicator.h | 2 |
5 files changed, 63 insertions, 41 deletions
diff --git a/keyboards/keychron/bluetooth/battery.c b/keyboards/keychron/bluetooth/battery.c index bc463f9336..8c6438d4c5 100644..100755 --- a/keyboards/keychron/bluetooth/battery.c +++ b/keyboards/keychron/bluetooth/battery.c @@ -34,7 +34,7 @@ static uint8_t bat_state; static uint8_t power_on_sample = 0; void battery_init(void) { - bat_state = BAT_NOT_CHARGING; + bat_state = BAT_NOT_CHARGING; } __attribute__((weak)) void battery_measure(void) { ckbt51_read_state_reg(0x05, 0x02); @@ -76,7 +76,7 @@ void battery_check_empty(void) { if (voltage < EMPTY_VOLTAGE_VALUE) { if (bat_empty <= BATTERY_EMPTY_COUNT) { if (++bat_empty > BATTERY_EMPTY_COUNT) { -#ifdef BAT_LOW_LED_PIN +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) indicator_battery_low_enable(true); #endif #if defined(LOW_BAT_IND_INDEX) @@ -130,7 +130,7 @@ void battery_task(void) { if ((bat_empty || critical_low) && usb_power_connected()) { bat_empty = false; critical_low = false; -#ifdef BAT_LOW_LED_PIN +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) indicator_battery_low_enable(false); #endif #if defined(LOW_BAT_IND_INDEX) diff --git a/keyboards/keychron/bluetooth/bluetooth.c b/keyboards/keychron/bluetooth/bluetooth.c index ad133bc9b0..3220fbc77f 100644..100755 --- a/keyboards/keychron/bluetooth/bluetooth.c +++ b/keyboards/keychron/bluetooth/bluetooth.c @@ -14,6 +14,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "action.h" #include "quantum.h" #include "bluetooth.h" #include "report_buffer.h" @@ -37,15 +38,15 @@ static uint8_t host_index = 0; static uint8_t led_state = 0; extern bluetooth_transport_t bluetooth_transport; -static bluetooth_state_t bt_state = BLUETOOTH_RESET; -static bool pincodeEntry = false; -uint8_t bluetooth_report_protocol = true; +static bluetooth_state_t bt_state = BLUETOOTH_RESET; +static bool pincodeEntry = false; +uint8_t bluetooth_report_protocol = true; /* declarations */ 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_extra(report_extra_t *report); /* host struct */ host_driver_t bluetooth_driver = {bluetooth_keyboard_leds, bluetooth_send_keyboard, bluetooth_send_mouse, bluetooth_send_extra}; @@ -102,7 +103,7 @@ void bluetooth_init(void) { #ifdef BLUETOOTH_NKRO_ENABLE keymap_config.raw = eeconfig_read_keymap(); - nkro.bluetooth = keymap_config.nkro; + nkro.bluetooth = keymap_config.nkro; #endif } @@ -167,7 +168,6 @@ void bluetooth_disconnect(void) { if (bluetooth_transport.disconnect) bluetooth_transport.disconnect(); } - /* Called when the BT device is reset. */ static void bluetooth_enter_reset(uint8_t reason) { bt_state = BLUETOOTH_RESET; @@ -215,7 +215,7 @@ static void bluetooth_enter_connected(uint8_t host_idx) { #endif bluetooth_enter_connected_kb(host_idx); -#ifdef BAT_LOW_LED_PIN +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) if (battery_is_empty()) { indicator_battery_low_enable(true); } @@ -241,7 +241,7 @@ static void bluetooth_enter_disconnected(uint8_t host_idx) { #endif retry = 0; bluetooth_enter_disconnected_kb(host_idx); -#ifdef BAT_LOW_LED_PIN +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) indicator_battery_low_enable(false); #endif #if defined(LOW_BAT_IND_INDEX) @@ -261,9 +261,9 @@ static void bluetooth_enter_pin_code_entry(void) { /* Exit pin code entry state. */ static void bluetooth_exit_pin_code_entry(void) { #if defined(NKRO_ENABLE) - keymap_config.nkro = true; + keymap_config.nkro = true; #endif - pincodeEntry = false; + pincodeEntry = false; bluetooth_exit_pin_code_entry_kb(); } @@ -294,10 +294,10 @@ void bluetooth_send_keyboard(report_keyboard_t *report) { if (bt_state == BLUETOOTH_PARING && !pincodeEntry) return; if (bt_state == BLUETOOTH_CONNECTED || (bt_state == BLUETOOTH_PARING && pincodeEntry)) { -# if defined(NKRO_ENABLE) +#if defined(NKRO_ENABLE) if (bluetooth_report_protocol && keymap_config.nkro) { if (bluetooth_transport.send_nkro) { -# ifndef DISABLE_REPORT_BUFFER +# ifndef DISABLE_REPORT_BUFFER bool firstBuffer = false; if (report_buffer_is_empty() && report_buffer_next_inverval() && report_buffer_get_retry() == 0) { firstBuffer = true; @@ -312,16 +312,16 @@ void bluetooth_send_keyboard(report_keyboard_t *report) { report_buffer_set_retry(0); report_buffer_task(); } -# else +# else bluetooth_transport.send_nkro(&report->nkro.mods); -# endif +# endif } } else -# endif +#endif { - //#ifdef KEYBOARD_SHARED_EP + // #ifdef KEYBOARD_SHARED_EP if (bluetooth_transport.send_keyboard) { -# ifndef DISABLE_REPORT_BUFFER +#ifndef DISABLE_REPORT_BUFFER if (report_buffer_is_empty() && report_buffer_next_inverval()) { bluetooth_transport.send_keyboard(&report->mods); report_buffer_update_timer(); @@ -331,11 +331,11 @@ void bluetooth_send_keyboard(report_keyboard_t *report) { memcpy(&report_buffer.keyboard, report, sizeof(report_keyboard_t)); report_buffer_enqueue(&report_buffer); } -# else +#else bluetooth_transport.send_keyboard(&report->mods); -# endif +#endif } - //#endif + // #endif } } else if (bt_state != BLUETOOTH_RESET) { @@ -379,17 +379,16 @@ void bluetooth_send_consumer(uint16_t data) { } } -void bluetooth_send_extra(report_extra_t *report) { +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) { + } else if (report->report_id == REPORT_ID_CONSUMER) { bluetooth_send_consumer(report->usage); } } void bluetooth_low_battery_shutdown(void) { -#ifdef BAT_LOW_LED_PIN +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) indicator_battery_low_enable(false); #endif #if defined(LOW_BAT_IND_INDEX) @@ -440,7 +439,6 @@ void bluetooth_event_queue_task(void) { } void bluetooth_task(void) { - bluetooth_transport.task(); bluetooth_event_queue_task(); #ifndef DISABLE_REPORT_BUFFER @@ -455,7 +453,9 @@ bluetooth_state_t bluetooth_get_state(void) { return bt_state; }; -__attribute__((weak)) bool process_record_kb_bt(uint16_t keycode, keyrecord_t *record) { return true;}; +__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)) { @@ -467,7 +467,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { #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) +# if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) indicator_battery_low_enable(true); # endif # if defined(LOW_BAT_IND_INDEX) diff --git a/keyboards/keychron/bluetooth/factory_test.c b/keyboards/keychron/bluetooth/factory_test.c index b42d2bde36..9de130a26b 100644 --- a/keyboards/keychron/bluetooth/factory_test.c +++ b/keyboards/keychron/bluetooth/factory_test.c @@ -69,7 +69,7 @@ static uint8_t factory_reset_ind_state = 0; static bool report_os_sw_state = false; void factory_timer_start(void) { - factory_reset_timer = sync_timer_read32() | 1; + factory_reset_timer = sync_timer_read32() == 0 ? 1 : sync_timer_read32(); } static inline void factory_timer_check(void) { @@ -77,7 +77,7 @@ static inline void factory_timer_check(void) { factory_reset_timer = 0; if (factory_reset_state == KEY_PRESS_FACTORY_RESET) { - factory_reset_ind_timer = sync_timer_read32() | 1; + factory_reset_ind_timer = sync_timer_read32() == 0 ? 1 : sync_timer_read32(); factory_reset_ind_state++; layer_state_t default_layer_tmp = default_layer_state; @@ -114,7 +114,7 @@ static inline void factory_reset_ind_timer_check(void) { if (factory_reset_ind_state++ > 6) { factory_reset_ind_timer = factory_reset_ind_state = 0; } else { - factory_reset_ind_timer = sync_timer_read32() | 1; + factory_reset_ind_timer = sync_timer_read32() == 0 ? 1 : sync_timer_read32(); } } } @@ -187,7 +187,7 @@ bool led_matrix_indicators_user(void) { led_matrix_set_value_all(factory_reset_ind_state % 2 ? 0 : 255); } - return false; + return true; } #endif @@ -213,7 +213,7 @@ bool rgb_matrix_indicators_user(void) { } } - return false; + return true; } #endif diff --git a/keyboards/keychron/bluetooth/indicator.c b/keyboards/keychron/bluetooth/indicator.c index e4e4f2eccf..fa111817dd 100644 --- a/keyboards/keychron/bluetooth/indicator.c +++ b/keyboards/keychron/bluetooth/indicator.c @@ -61,9 +61,12 @@ static uint16_t next_period; static indicator_type_t type; static uint32_t indicator_timer_buffer = 0; -#if defined(BAT_LOW_LED_PIN) +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) static uint32_t bat_low_pin_indicator = 0; static uint32_t bat_low_blink_duration = 0; +# ifdef BAT_LOW_LED_PIN_STATE +bool bat_low_led_pin_state = false; +# endif #endif #if defined(LOW_BAT_IND_INDEX) @@ -85,6 +88,7 @@ static pin_t host_led_pin_list[HOST_DEVICES_COUNT] = HOST_LED_PIN_LIST; #ifdef LED_MATRIX_ENABLE # define LED_DRIVER led_matrix_driver # define LED_INDICATORS_KB led_matrix_indicators_kb +# define LED_INDICATORS_USER led_matrix_indicators_user # define LED_NONE_INDICATORS_KB led_matrix_none_indicators_kb # define SET_ALL_LED_OFF() led_matrix_set_value_all(0) # define SET_LED_OFF(idx) led_matrix_set_value(idx, 0) @@ -107,6 +111,7 @@ static pin_t host_led_pin_list[HOST_DEVICES_COUNT] = HOST_LED_PIN_LIST; #ifdef RGB_MATRIX_ENABLE # define LED_DRIVER rgb_matrix_driver # define LED_INDICATORS_KB rgb_matrix_indicators_kb +# define LED_INDICATORS_USER rgb_matrix_indicators_user # define LED_NONE_INDICATORS_KB rgb_matrix_none_indicators_kb # define SET_ALL_LED_OFF() rgb_matrix_set_color_all(0, 0, 0) # define SET_LED_OFF(idx) rgb_matrix_set_color(idx, 0, 0, 0) @@ -172,7 +177,7 @@ void indicator_eeconfig_reload(void) { bool indicator_is_running(void) { return -#if defined(BAT_LOW_LED_PIN) +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) bat_low_blink_duration || #endif #if defined(LOW_BAT_IND_INDEX) @@ -367,15 +372,20 @@ void indicator_stop(void) { } } -#ifdef BAT_LOW_LED_PIN +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) void indicator_battery_low_enable(bool enable) { if (enable) { if (bat_low_blink_duration == 0) { bat_low_blink_duration = bat_low_pin_indicator = sync_timer_read32() | 1; } else bat_low_blink_duration = sync_timer_read32() | 1; - } else + } else { +# if defined(BAT_LOW_LED_PIN) writePin(BAT_LOW_LED_PIN, !BAT_LOW_LED_PIN_ON_STATE); +# else + bat_low_led_pin_state = false; +# endif + } } #endif @@ -410,12 +420,20 @@ void indicator_battery_low_backlit_enable(bool enable) { #endif void indicator_battery_low(void) { -#ifdef BAT_LOW_LED_PIN +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) if (bat_low_pin_indicator && sync_timer_elapsed32(bat_low_pin_indicator) > (LOW_BAT_LED_BLINK_PERIOD)) { +# if defined(BAT_LOW_LED_PIN) togglePin(BAT_LOW_LED_PIN); +# else + bat_low_led_pin_state = !bat_low_led_pin_state; +# endif bat_low_pin_indicator = sync_timer_read32() | 1; // Turn off low battery indication if we reach the duration +# if defined(BAT_LOW_LED_PIN) if (sync_timer_elapsed32(bat_low_blink_duration) > LOW_BAT_LED_BLINK_DURATION && palReadLine(BAT_LOW_LED_PIN) != BAT_LOW_LED_PIN_ON_STATE) { +# elif defined(BAT_LOW_LED_PIN_STATE) + if (sync_timer_elapsed32(bat_low_blink_duration) > LOW_BAT_LED_BLINK_DURATION) { +# endif bat_low_blink_duration = bat_low_pin_indicator = 0; } } @@ -491,6 +509,10 @@ static void os_state_indicate(void) { } bool LED_INDICATORS_KB(void) { + if (!LED_INDICATORS_USER()) { + return false; + } + if (get_transport() == TRANSPORT_BLUETOOTH) { /* Prevent backlight flash caused by key activities */ if (battery_is_critical_low()) { diff --git a/keyboards/keychron/bluetooth/indicator.h b/keyboards/keychron/bluetooth/indicator.h index bf408a0c1c..d1345d2235 100644 --- a/keyboards/keychron/bluetooth/indicator.h +++ b/keyboards/keychron/bluetooth/indicator.h @@ -49,7 +49,7 @@ # define CONNECTED_BACKLIGHT_OFF_DELAY_TIME 600 #endif -#ifdef BAT_LOW_LED_PIN +#if defined(BAT_LOW_LED_PIN) || defined(BAT_LOW_LED_PIN_STATE) /* Uint: ms */ # ifndef LOW_BAT_LED_BLINK_PERIOD # define LOW_BAT_LED_BLINK_PERIOD 1000 |