feat: Add double tap to enter bootloader functionality

Add ability to enter the bootloader if double tapping reset within the
specified window.
This commit is contained in:
Peter Johanson 2025-03-23 23:32:27 -06:00
parent bf323bf577
commit 15fcf92a63
5 changed files with 60 additions and 3 deletions

View File

@ -110,4 +110,5 @@ config ZMK_BATTERY_REPORT_INTERVAL
default 60
# Imports
rsource "src/boot/Kconfig.defaults"
rsource "src/split/Kconfig.defaults"

View File

@ -1,2 +1,3 @@
target_sources_ifdef(CONFIG_ZMK_BOOTMODE_TO_MAGIC_VALUE_MAPPER app PRIVATE bootmode_to_magic_mapper.c)
target_sources_ifdef(CONFIG_ZMK_BOOTMODE_TO_MAGIC_VALUE_MAPPER app PRIVATE bootmode_to_magic_mapper.c)
target_sources_ifdef(CONFIG_ZMK_DBL_TAP_BOOTLOADER app PRIVATE dbl_tap_bootloader.c)

View File

@ -1,4 +1,18 @@
config ZMK_DBL_TAP_BOOTLOADER
bool "Double Tap To Enter Bootloader"
depends on RETENTION_BOOT_MODE
if ZMK_DBL_TAP_BOOTLOADER
config ZMK_DBL_TAP_BOOTLOADER_TIMEOUT_MS
int "Double Tap Timeout (ms)"
config ZMK_DBL_TAP_BOOTLOADER_INIT_PRIORITY
int "Double Tap Init Priority"
endif
config ZMK_BOOTMODE_TO_MAGIC_VALUE_MAPPER
bool "Magic Value Mapper"
default y
@ -25,7 +39,5 @@ endchoice
config ZMK_BOOTMODE_BOOTLOADER_MAGIC_VALUE
hex
default 0xf01669ef if ZMK_BOOTMODE_MAGIC_VALUE_BOOTLOADER_TYPE_TINYUF2 || ZMK_BOOTMODE_MAGIC_VALUE_BOOTLOADER_TYPE_ADAFRUIT_BOSSA || BOOTLOADER_BOSSA_ADAFRUIT_UF2
default 0x57 if ZMK_BOOTMODE_MAGIC_VALUE_BOOTLOADER_TYPE_ADAFRUIT_NRF52
endif

View File

@ -0,0 +1,27 @@
config ZMK_DBL_TAP_BOOTLOADER
default y if STM32_BOOTLOADER || RPI_PICO_ROM_BOOTLOADER
depends on RETENTION_BOOT_MODE
if ZMK_DBL_TAP_BOOTLOADER
config ZMK_DBL_TAP_BOOTLOADER_TIMEOUT_MS
default 500
config ZMK_DBL_TAP_BOOTLOADER_INIT_PRIORITY
default 20
endif
if ZMK_BOOTMODE_TO_MAGIC_VALUE_MAPPER
choice ZMK_BOOTMODE_MAGIC_VALUE_BOOTLOADER_TYPE
default ZMK_BOOTMODE_MAGIC_VALUE_BOOTLOADER_TYPE_ADAFRUIT_NRF52 if SOC_NRF52840
endchoice
config ZMK_BOOTMODE_BOOTLOADER_MAGIC_VALUE
default 0xf01669ef if ZMK_BOOTMODE_MAGIC_VALUE_BOOTLOADER_TYPE_TINYUF2 || ZMK_BOOTMODE_MAGIC_VALUE_BOOTLOADER_TYPE_ADAFRUIT_BOSSA || BOOTLOADER_BOSSA_ADAFRUIT_UF2
default 0x57 if ZMK_BOOTMODE_MAGIC_VALUE_BOOTLOADER_TYPE_ADAFRUIT_NRF52
endif

View File

@ -0,0 +1,16 @@
#include <soc.h>
#include <zephyr/init.h>
#include <zephyr/retention/retention.h>
#include <zephyr/retention/bootmode.h>
static int dbl_tap_boot_mode_init(void) {
bootmode_set(BOOT_MODE_TYPE_BOOTLOADER);
k_busy_wait(CONFIG_ZMK_DBL_TAP_BOOTLOADER_TIMEOUT_MS * 1000);
bootmode_clear();
return 0;
}
SYS_INIT(dbl_tap_boot_mode_init, POST_KERNEL, CONFIG_ZMK_DBL_TAP_BOOTLOADER_INIT_PRIORITY);