From 1dfcfc7d3f074e538900a6df684cc99e92c60a21 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 may be replaced in the future once we find a better way to repair a broken split connection. --- app/Kconfig | 3 +++ .../settings_reset/settings_reset.conf | 5 ++++- app/src/settings/CMakeLists.txt | 2 ++ app/src/settings/reset_settings_on_start.c | 19 +++++++++++++++++++ docs/docs/config/system.md | 13 +++++++------ 5 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 app/src/settings/reset_settings_on_start.c diff --git a/app/Kconfig b/app/Kconfig index bb6997a4..3f797abd 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -565,6 +565,9 @@ endmenu if SETTINGS +config ZMK_SETTINGS_RESET_ON_START + bool "Delete all persistent settings when the keyboard boots" + config ZMK_SETTINGS_SAVE_DEBOUNCE int "Milliseconds to debounce settings saves" default 60000 diff --git a/app/boards/shields/settings_reset/settings_reset.conf b/app/boards/shields/settings_reset/settings_reset.conf index 8052a6cf..4ed84df8 100644 --- a/app/boards/shields/settings_reset/settings_reset.conf +++ b/app/boards/shields/settings_reset/settings_reset.conf @@ -1 +1,4 @@ -CONFIG_ZMK_BLE_CLEAR_BONDS_ON_START=y +CONFIG_SETTINGS=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 63bcd7f9..28664a4e 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 00000000..3b3890f4 --- /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 83f2f065..d60fa24e 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