Skip to content

Commit d88bad6

Browse files
committed
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.
1 parent d6f6fe7 commit d88bad6

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

app/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,11 @@ endif
560560
#Logging
561561
endmenu
562562

563+
config ZMK_SETTINGS_RESET_ON_START
564+
bool "Delete all persistent settings when the keyboard boots"
565+
default n
566+
select SETTINGS
567+
563568
if SETTINGS
564569

565570
config ZMK_SETTINGS_SAVE_DEBOUNCE
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
CONFIG_ZMK_BLE_CLEAR_BONDS_ON_START=y
1+
CONFIG_ZMK_SETTINGS_RESET_ON_START=y
2+
# Disable BLE so splits don't try to re-pair until normal firmware is flashed.
3+
CONFIG_ZMK_BLE=n

app/src/settings/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ target_sources_ifdef(CONFIG_SETTINGS_NONE app PRIVATE reset_settings_none.c)
55
target_sources_ifdef(CONFIG_SETTINGS_FCB app PRIVATE reset_settings_fcb.c)
66
target_sources_ifdef(CONFIG_SETTINGS_FILE app PRIVATE reset_settings_file.c)
77
target_sources_ifdef(CONFIG_SETTINGS_NVS app PRIVATE reset_settings_nvs.c)
8+
9+
target_sources_ifdef(CONFIG_ZMK_SETTINGS_RESET_ON_START app PRIVATE reset_settings_on_start.c)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2023 The ZMK Contributors
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
7+
#include <zephyr/device.h>
8+
#include <zephyr/init.h>
9+
10+
#include <zmk/settings.h>
11+
12+
static int reset_settings_init(const struct device *dev) {
13+
ARG_UNUSED(dev);
14+
return zmk_settings_erase();
15+
}
16+
17+
// Reset after the kernel is initialized but before any application code to
18+
// ensure settings are cleared before anything tries to use them.
19+
SYS_INIT(reset_settings_init, POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY);

docs/docs/config/system.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/
1313

1414
### General
1515

16-
| Config | Type | Description | Default |
17-
| ----------------------------------- | ------ | ----------------------------------------------------------------------------- | ------- |
18-
| `CONFIG_ZMK_KEYBOARD_NAME` | string | The name of the keyboard (max 16 characters) | |
19-
| `CONFIG_ZMK_SETTINGS_SAVE_DEBOUNCE` | int | Milliseconds to wait after a setting change before writing it to flash memory | 60000 |
20-
| `CONFIG_ZMK_WPM` | bool | Enable calculating words per minute | n |
21-
| `CONFIG_HEAP_MEM_POOL_SIZE` | int | Size of the heap memory pool | 8192 |
16+
| Config | Type | Description | Default |
17+
| ------------------------------------ | ------ | ----------------------------------------------------------------------------- | ------- |
18+
| `CONFIG_ZMK_KEYBOARD_NAME` | string | The name of the keyboard (max 16 characters) | |
19+
| `CONFIG_ZMK_SETTINGS_RESET_ON_START` | bool | Clears all persistent settings from the keyboard at startup | n |
20+
| `CONFIG_ZMK_SETTINGS_SAVE_DEBOUNCE` | int | Milliseconds to wait after a setting change before writing it to flash memory | 60000 |
21+
| `CONFIG_ZMK_WPM` | bool | Enable calculating words per minute | n |
22+
| `CONFIG_HEAP_MEM_POOL_SIZE` | int | Size of the heap memory pool | 8192 |
2223

2324
### HID
2425

0 commit comments

Comments
 (0)