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:
Peter Johanson
2024-07-03 02:33:26 -06:00
committed by Pete Johanson
parent f18974e8c4
commit 80173f8ea3
11 changed files with 129 additions and 102 deletions

View File

@@ -263,7 +263,8 @@ static int endpoints_handle_set(const char *name, size_t len, settings_read_cb r
return 0;
}
struct settings_handler endpoints_handler = {.name = "endpoints", .h_set = endpoints_handle_set};
SETTINGS_STATIC_HANDLER_DEFINE(endpoints, "endpoints", NULL, endpoints_handle_set, NULL, NULL);
#endif /* IS_ENABLED(CONFIG_SETTINGS) */
static bool is_usb_ready(void) {
@@ -322,17 +323,7 @@ static struct zmk_endpoint_instance get_selected_instance(void) {
static int zmk_endpoints_init(void) {
#if IS_ENABLED(CONFIG_SETTINGS)
settings_subsys_init();
int err = settings_register(&endpoints_handler);
if (err) {
LOG_ERR("Failed to register the endpoints settings handler (err %d)", err);
return err;
}
k_work_init_delayable(&endpoints_save_work, endpoints_save_preferred_work);
settings_load_subtree("endpoints");
#endif
current_instance = get_selected_instance();