From a4c0819f1305da4490837683beebc2f9c7b4af6c Mon Sep 17 00:00:00 2001 From: jiaxin96 <572673807@qq.com> Date: Mon, 28 Jun 2021 23:54:21 +0800 Subject: [PATCH] v-alpha1 --- .../tmk_core/protocol/chibios/biu_nrf52.cpp | 21 +++++++++++++++---- .../tmk_core/protocol/chibios/outputselect.c | 2 +- .../tmk_core/protocol/chibios/outputselect.h | 2 +- .../yandrstudio/m60ble/keymaps/ble/keymap.c | 1 + 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/keyboards/yandrstudio/biu_nrf52_ble_lib/tmk_core/protocol/chibios/biu_nrf52.cpp b/keyboards/yandrstudio/biu_nrf52_ble_lib/tmk_core/protocol/chibios/biu_nrf52.cpp index f7989327f785..559567be25e3 100644 --- a/keyboards/yandrstudio/biu_nrf52_ble_lib/tmk_core/protocol/chibios/biu_nrf52.cpp +++ b/keyboards/yandrstudio/biu_nrf52_ble_lib/tmk_core/protocol/chibios/biu_nrf52.cpp @@ -65,10 +65,11 @@ #define BiuNrf52MsgShortTimeout 10 /* milliseconds */ #define BiuNrf52MsgRecvTimeout 2000 /* microseconds */ -#define BiuNrf52ResetTimeout 10000 /* microseconds */ +#define BiuNrf52ResetTimeout 25000 /* microseconds */ #define BiuNrf52InitTimeout 3000 /* microseconds */ +// #define BiuNrf52SystemOffTimeout 300000 /* milliseconds */ #define BiuNrf52SystemOffTimeout 30000 /* milliseconds */ -#define BatteryUpdateInterval 300000 /* milliseconds */ +#define BatteryUpdateInterval 60000 /* milliseconds */ @@ -202,6 +203,7 @@ static struct { uint32_t vbat; #endif uint16_t last_connection_update; + uint16_t last_success_conn_update; uint16_t last_reset_update; bool has_send_ask; } state; @@ -277,6 +279,7 @@ static void process_nrf_ack_msg(struct biunrf52_msg * msg) { state.initialized = true; state.configured = true; state.is_connected = true; + state.last_success_conn_update = timer_read(); break; case NRF_DISCONNECT: case NRF_ADVING: @@ -684,6 +687,7 @@ bool bluetooth_init_pre(void) { state.has_send_ask = false; state.last_connection_update = timer_read(); state.last_battery_update = timer_read(); + state.last_success_conn_update = timer_read(); // start the uart data trans uart_init(BIUNRF52UartBaud); @@ -824,6 +828,7 @@ void inline biu_ble_system_off() { state.has_send_ask = false; state.last_battery_update = 0; state.last_connection_update = 0; + state.last_success_conn_update = 0; struct queue_item item; @@ -836,8 +841,16 @@ void inline biu_ble_system_off() { } void inline check_ble_system_off_timer(void) { - if (TIMER_DIFF_16(timer_read(), state.last_connection_update) > BiuNrf52SystemOffTimeout) { - biu_ble_system_off(); + if (state.is_connected) { + if (TIMER_DIFF_16(timer_read(), state.last_connection_update) > BiuNrf52SystemOffTimeout) { + biu_ble_system_off(); + } + } else { + if (0 == state.last_success_conn_update) { // avoid died after last sysoff + state.last_success_conn_update = timer_read(); + } else if (TIMER_DIFF_16(timer_read(), state.last_success_conn_update) > BiuNrf52SystemOffTimeout) { + biu_ble_system_off(); + } } } diff --git a/keyboards/yandrstudio/biu_nrf52_ble_lib/tmk_core/protocol/chibios/outputselect.c b/keyboards/yandrstudio/biu_nrf52_ble_lib/tmk_core/protocol/chibios/outputselect.c index 4f3efd28b57d..c9c8be25e860 100644 --- a/keyboards/yandrstudio/biu_nrf52_ble_lib/tmk_core/protocol/chibios/outputselect.c +++ b/keyboards/yandrstudio/biu_nrf52_ble_lib/tmk_core/protocol/chibios/outputselect.c @@ -35,8 +35,8 @@ uint8_t desired_output = OUTPUT_DEFAULT; * FIXME: Needs doc */ void set_output(uint8_t output) { - set_output_user(output); desired_output = output; + set_output_user(output); } /** \brief Set Output User diff --git a/keyboards/yandrstudio/biu_nrf52_ble_lib/tmk_core/protocol/chibios/outputselect.h b/keyboards/yandrstudio/biu_nrf52_ble_lib/tmk_core/protocol/chibios/outputselect.h index 85c65aac1d53..2ae74e46e497 100644 --- a/keyboards/yandrstudio/biu_nrf52_ble_lib/tmk_core/protocol/chibios/outputselect.h +++ b/keyboards/yandrstudio/biu_nrf52_ble_lib/tmk_core/protocol/chibios/outputselect.h @@ -24,7 +24,7 @@ enum outputs { }; #ifndef OUTPUT_DEFAULT -# define OUTPUT_DEFAULT OUTPUT_BLUETOOTH +# define OUTPUT_DEFAULT OUTPUT_AUTO #endif diff --git a/keyboards/yandrstudio/m60ble/keymaps/ble/keymap.c b/keyboards/yandrstudio/m60ble/keymaps/ble/keymap.c index f98a008c75f2..c8f3b49dbcec 100644 --- a/keyboards/yandrstudio/m60ble/keymaps/ble/keymap.c +++ b/keyboards/yandrstudio/m60ble/keymaps/ble/keymap.c @@ -96,6 +96,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { case BL_SW_2: case BL_SW_3: if (record->event.pressed) { + set_output(OUTPUT_BLUETOOTH); bluetooth_switch_one(keycode - BL_SW_0); } return false;