Skip to content

Commit

Permalink
slicemk: implement &sys_off (experimental 2024-02-14)
Browse files Browse the repository at this point in the history
  • Loading branch information
xudongzheng committed Jan 22, 2025
1 parent 2d0f593 commit a4002a6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/dts/behaviors/reset.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@
#binding-cells = <0>;
display-name = "Bootloader";
};

sys_off: behavior_reset_sysoff {
compatible = "zmk,behavior-reset";
type = <RST_SYSOFF>;
#binding-cells = <0>;
};
};
};
5 changes: 4 additions & 1 deletion app/include/dt-bindings/zmk/reset.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
#define RST_WARM 0x00
#define RST_COLD 0x01

// Custom SliceMK magic token for SYSOFF.
#define RST_SYSOFF 0x56

// AdaFruit nrf52 Bootloader Specific. See
// https://github.com/adafruit/Adafruit_nRF52_Bootloader/blob/d6b28e66053eea467166f44875e3c7ec741cb471/src/main.c#L107

#define RST_UF2 0x57
#define RST_UF2 0x57
14 changes: 14 additions & 0 deletions app/src/behaviors/behavior_reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <drivers/behavior.h>

#include <zmk/behavior.h>
#include <dt-bindings/zmk/reset.h>

LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

Expand Down Expand Up @@ -53,3 +54,16 @@ static const struct behavior_driver_api behavior_reset_driver_api = {
DT_INST_FOREACH_STATUS_OKAY(RST_INST)

#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */

static int sysoff_init_prekernel(void) {
#ifdef CONFIG_SOC_SERIES_NRF52X
uint32_t const gpregret = NRF_POWER->GPREGRET;
if (gpregret == RST_SYSOFF) {
NRF_POWER->GPREGRET = 0;
NRF_POWER->SYSTEMOFF = 1;
}
#endif
return 0;
}

SYS_INIT(sysoff_init_prekernel, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);

0 comments on commit a4002a6

Please sign in to comment.