Skip to content

Commit

Permalink
feat(shields): Make settings_reset shield reset all settings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joelspadin committed Dec 17, 2023
1 parent d6f6fe7 commit d88bad6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
5 changes: 5 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion app/boards/shields/settings_reset/settings_reset.conf
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions app/src/settings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
19 changes: 19 additions & 0 deletions app/src/settings/reset_settings_on_start.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2023 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

#include <zephyr/device.h>
#include <zephyr/init.h>

#include <zmk/settings.h>

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);
13 changes: 7 additions & 6 deletions docs/docs/config/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d88bad6

Please sign in to comment.