mirror of
https://github.com/zmkfirmware/zmk.git
synced 2026-03-20 13:05:20 -05:00
fix: Improve startup time with proper settings loading.
* Avoid doing duplicate calls to setings_load_subtree, which iterates NVS fully each time under the hood, and instead use on settings_load later in the lifecycle.
This commit is contained in:
committed by
Pete Johanson
parent
f18974e8c4
commit
80173f8ea3
@@ -12,6 +12,7 @@
|
||||
#include <zephyr/bluetooth/uuid.h>
|
||||
#include <zephyr/bluetooth/gatt.h>
|
||||
#include <zephyr/bluetooth/hci.h>
|
||||
#include <zephyr/settings/settings.h>
|
||||
#include <zephyr/sys/byteorder.h>
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
@@ -865,13 +866,34 @@ int zmk_split_bt_update_hid_indicator(zmk_hid_indicators_t indicators) {
|
||||
|
||||
#endif // IS_ENABLED(CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS)
|
||||
|
||||
static int finish_init() {
|
||||
return IS_ENABLED(CONFIG_ZMK_BLE_CLEAR_BONDS_ON_START) ? 0 : start_scanning();
|
||||
}
|
||||
|
||||
#if IS_ENABLED(CONFIG_SETTINGS)
|
||||
|
||||
static int central_ble_handle_set(const char *name, size_t len, settings_read_cb read_cb,
|
||||
void *cb_arg) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct settings_handler ble_central_settings_handler = {
|
||||
.name = "ble_central", .h_set = central_ble_handle_set, .h_commit = finish_init};
|
||||
|
||||
#endif // IS_ENABLED(CONFIG_SETTINGS)
|
||||
|
||||
static int zmk_split_bt_central_init(void) {
|
||||
k_work_queue_start(&split_central_split_run_q, split_central_split_run_q_stack,
|
||||
K_THREAD_STACK_SIZEOF(split_central_split_run_q_stack),
|
||||
CONFIG_ZMK_BLE_THREAD_PRIORITY, NULL);
|
||||
bt_conn_cb_register(&conn_callbacks);
|
||||
|
||||
return IS_ENABLED(CONFIG_ZMK_BLE_CLEAR_BONDS_ON_START) ? 0 : start_scanning();
|
||||
#if IS_ENABLED(CONFIG_SETTINGS)
|
||||
settings_register(&ble_central_settings_handler);
|
||||
return 0;
|
||||
#else
|
||||
return finish_init();
|
||||
#endif // IS_ENABLED(CONFIG_SETTINGS)
|
||||
}
|
||||
|
||||
SYS_INIT(zmk_split_bt_central_init, APPLICATION, CONFIG_ZMK_BLE_INIT_PRIORITY);
|
||||
|
||||
@@ -146,21 +146,7 @@ bool zmk_split_bt_peripheral_is_connected(void) { return is_connected; }
|
||||
|
||||
bool zmk_split_bt_peripheral_is_bonded(void) { return is_bonded; }
|
||||
|
||||
static int zmk_peripheral_ble_init(void) {
|
||||
int err = bt_enable(NULL);
|
||||
|
||||
if (err) {
|
||||
LOG_ERR("BLUETOOTH FAILED (%d)", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
#if IS_ENABLED(CONFIG_SETTINGS)
|
||||
settings_subsys_init();
|
||||
|
||||
settings_load_subtree("ble");
|
||||
settings_load_subtree("bt");
|
||||
#endif
|
||||
|
||||
static int zmk_peripheral_ble_complete_startup(void) {
|
||||
#if IS_ENABLED(CONFIG_ZMK_BLE_CLEAR_BONDS_ON_START)
|
||||
LOG_WRN("Clearing all existing BLE bond information from the keyboard");
|
||||
|
||||
@@ -176,4 +162,35 @@ static int zmk_peripheral_ble_init(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if IS_ENABLED(CONFIG_SETTINGS)
|
||||
|
||||
static int peripheral_ble_handle_set(const char *name, size_t len, settings_read_cb read_cb,
|
||||
void *cb_arg) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct settings_handler ble_peripheral_settings_handler = {
|
||||
.name = "ble_peripheral",
|
||||
.h_set = peripheral_ble_handle_set,
|
||||
.h_commit = zmk_peripheral_ble_complete_startup};
|
||||
|
||||
#endif // IS_ENABLED(CONFIG_SETTINGS)
|
||||
|
||||
static int zmk_peripheral_ble_init(void) {
|
||||
int err = bt_enable(NULL);
|
||||
|
||||
if (err) {
|
||||
LOG_ERR("BLUETOOTH FAILED (%d)", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
#if IS_ENABLED(CONFIG_SETTINGS)
|
||||
settings_register(&ble_peripheral_settings_handler);
|
||||
#else
|
||||
zmk_peripheral_ble_complete_startup();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SYS_INIT(zmk_peripheral_ble_init, APPLICATION, CONFIG_ZMK_BLE_INIT_PRIORITY);
|
||||
|
||||
Reference in New Issue
Block a user