From c49da513b4c9f0df3763a0b7c8f5efd6b64ce422 Mon Sep 17 00:00:00 2001 From: ReFil Date: Tue, 11 Oct 2022 11:35:40 +0100 Subject: [PATCH] feat(bluetooth): bootloader after settings reset --- app/Kconfig | 5 +++++ app/boards/shields/settings_reset/settings_reset.conf | 1 + app/src/ble.c | 9 +++++++++ app/src/split/bluetooth/peripheral.c | 4 ++++ 4 files changed, 19 insertions(+) diff --git a/app/Kconfig b/app/Kconfig index 9902046d..4063cc51 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -143,6 +143,11 @@ config ZMK_BLE_CLEAR_BONDS_ON_START bool "Configuration that clears all bond information from the keyboard on startup." default n +config ZMK_BOOTLOADER_BLE_CLEAR_BONDS + bool "Configuration that resets to bootloader after clearing all bond information" + depends on ZMK_BLE_CLEAR_BONDS_ON_START + default n + # HID GATT notifications sent this way are *not* picked up by Linux, and possibly others. config BT_GATT_NOTIFY_MULTIPLE default n diff --git a/app/boards/shields/settings_reset/settings_reset.conf b/app/boards/shields/settings_reset/settings_reset.conf index 8052a6cf..c0d578c0 100644 --- a/app/boards/shields/settings_reset/settings_reset.conf +++ b/app/boards/shields/settings_reset/settings_reset.conf @@ -1 +1,2 @@ CONFIG_ZMK_BLE_CLEAR_BONDS_ON_START=y +CONFIG_ZMK_BOOTLOADER_BLE_CLEAR_BONDS=y diff --git a/app/src/ble.c b/app/src/ble.c index b10aa20b..c656c5a7 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -47,6 +47,10 @@ static uint8_t passkey_digit = 0; #endif /* IS_ENABLED(CONFIG_ZMK_BLE_PASSKEY_ENTRY) */ +#if IS_ENABLED(CONFIG_ZMK_BOOTLOADER_BLE_CLEAR_BONDS) +#include +#endif + #if IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) #define PROFILE_COUNT (CONFIG_BT_MAX_PAIRED - 1) #else @@ -585,6 +589,11 @@ static int zmk_ble_init(const struct device *_arg) { LOG_ERR("Failed to delete setting: %d", err); } } +#if IS_ENABLED(CONFIG_ZMK_BOOTLOADER_BLE_CLEAR_BONDS) + LOG_WRN("Clearing completed, rebooting to bootloader"); + sys_reboot(0x57); +#endif + #endif bt_conn_cb_register(&conn_callbacks); diff --git a/app/src/split/bluetooth/peripheral.c b/app/src/split/bluetooth/peripheral.c index aa690ab2..77693878 100644 --- a/app/src/split/bluetooth/peripheral.c +++ b/app/src/split/bluetooth/peripheral.c @@ -116,6 +116,10 @@ static int zmk_peripheral_ble_init(const struct device *_arg) { LOG_WRN("Clearing all existing BLE bond information from the keyboard"); bt_unpair(BT_ID_DEFAULT, NULL); +#if IS_ENABLED(CONFIG_ZMK_BOOTLOADER_BLE_CLEAR_BONDS) + LOG_WRN("Clearing completed, rebooting to bootloader"); + sys_reboot(0x57); +#endif #endif bt_conn_cb_register(&conn_callbacks);