From d88bad6997968d3a7c47ca5e15c8356224ca9012 Mon Sep 17 00:00:00 2001 From: Joel Spadin Date: Sun, 26 Nov 2023 12:28:27 -0600 Subject: [PATCH] feat(shields): Make settings_reset shield reset all settings Added a new CONFIG_ZMK_SETTINGS_RESET_ON_START option which enables init code to call zmk_settings_erase(), and changed the settings_reset shield to use it instead of CONFIG_ZMK_BLE_CLEAR_BONDS_ON_START, so it now resets all settings instead of just clearing BLE bonds. CONFIG_ZMK_BLE_CLEAR_BONDS_ON_START is left in place for now in case someone still needs it. It will likely be replaced in the future once we find a better way to repair a broken split connection without deleting all settings. --- app/Kconfig | 5 +++++ .../settings_reset/settings_reset.conf | 4 +++- app/src/settings/CMakeLists.txt | 2 ++ app/src/settings/reset_settings_on_start.c | 19 +++++++++++++++++++ docs/docs/config/system.md | 13 +++++++------ 5 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 app/src/settings/reset_settings_on_start.c diff --git a/app/Kconfig b/app/Kconfig index a5fa54f614be..641a34b1343c 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -560,6 +560,11 @@ endif #Logging endmenu +config ZMK_SETTINGS_RESET_ON_START + bool "Delete all persistent settings when the keyboard boots" + default n + select SETTINGS + if SETTINGS config ZMK_SETTINGS_SAVE_DEBOUNCE diff --git a/app/boards/shields/settings_reset/settings_reset.conf b/app/boards/shields/settings_reset/settings_reset.conf index 8052a6cf2583..8259c33aa622 100644 --- a/app/boards/shields/settings_reset/settings_reset.conf +++ b/app/boards/shields/settings_reset/settings_reset.conf @@ -1 +1,3 @@ -CONFIG_ZMK_BLE_CLEAR_BONDS_ON_START=y +CONFIG_ZMK_SETTINGS_RESET_ON_START=y +# Disable BLE so splits don't try to re-pair until normal firmware is flashed. +CONFIG_ZMK_BLE=n diff --git a/app/src/settings/CMakeLists.txt b/app/src/settings/CMakeLists.txt index 63bcd7f95225..28664a4ef138 100644 --- a/app/src/settings/CMakeLists.txt +++ b/app/src/settings/CMakeLists.txt @@ -5,3 +5,5 @@ target_sources_ifdef(CONFIG_SETTINGS_NONE app PRIVATE reset_settings_none.c) target_sources_ifdef(CONFIG_SETTINGS_FCB app PRIVATE reset_settings_fcb.c) target_sources_ifdef(CONFIG_SETTINGS_FILE app PRIVATE reset_settings_file.c) target_sources_ifdef(CONFIG_SETTINGS_NVS app PRIVATE reset_settings_nvs.c) + +target_sources_ifdef(CONFIG_ZMK_SETTINGS_RESET_ON_START app PRIVATE reset_settings_on_start.c) diff --git a/app/src/settings/reset_settings_on_start.c b/app/src/settings/reset_settings_on_start.c new file mode 100644 index 000000000000..3b3890f469ba --- /dev/null +++ b/app/src/settings/reset_settings_on_start.c @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include + +#include + +static int reset_settings_init(const struct device *dev) { + ARG_UNUSED(dev); + return zmk_settings_erase(); +} + +// Reset after the kernel is initialized but before any application code to +// ensure settings are cleared before anything tries to use them. +SYS_INIT(reset_settings_init, POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY); diff --git a/docs/docs/config/system.md b/docs/docs/config/system.md index 4629ea0f790e..8e4d8da93ac5 100644 --- a/docs/docs/config/system.md +++ b/docs/docs/config/system.md @@ -13,12 +13,13 @@ Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/ ### General -| Config | Type | Description | Default | -| ----------------------------------- | ------ | ----------------------------------------------------------------------------- | ------- | -| `CONFIG_ZMK_KEYBOARD_NAME` | string | The name of the keyboard (max 16 characters) | | -| `CONFIG_ZMK_SETTINGS_SAVE_DEBOUNCE` | int | Milliseconds to wait after a setting change before writing it to flash memory | 60000 | -| `CONFIG_ZMK_WPM` | bool | Enable calculating words per minute | n | -| `CONFIG_HEAP_MEM_POOL_SIZE` | int | Size of the heap memory pool | 8192 | +| Config | Type | Description | Default | +| ------------------------------------ | ------ | ----------------------------------------------------------------------------- | ------- | +| `CONFIG_ZMK_KEYBOARD_NAME` | string | The name of the keyboard (max 16 characters) | | +| `CONFIG_ZMK_SETTINGS_RESET_ON_START` | bool | Clears all persistent settings from the keyboard at startup | n | +| `CONFIG_ZMK_SETTINGS_SAVE_DEBOUNCE` | int | Milliseconds to wait after a setting change before writing it to flash memory | 60000 | +| `CONFIG_ZMK_WPM` | bool | Enable calculating words per minute | n | +| `CONFIG_HEAP_MEM_POOL_SIZE` | int | Size of the heap memory pool | 8192 | ### HID