Skip to content

Commit

Permalink
slicemk: implement &sys_off (EXPERIMENTAL 2023-06-14)
Browse files Browse the repository at this point in the history
  • Loading branch information
xudongzheng committed Nov 18, 2023
1 parent 1d4e651 commit 0f49f22
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
9 changes: 8 additions & 1 deletion app/dts/behaviors/reset.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,12 @@
type = <RST_UF2>;
#binding-cells = <0>;
};
};

sys_off: behavior_reset_sysoff {
compatible = "zmk,behavior-reset";
label = "SYSOFF";
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
12 changes: 12 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 @@ -50,3 +51,14 @@ 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(const struct device *dev) {
uint32_t const gpregret = NRF_POWER->GPREGRET;
if (gpregret == RST_SYSOFF) {
NRF_POWER->GPREGRET = 0;
NRF_POWER->SYSTEMOFF = 1;
}
return 0;
}

SYS_INIT(sysoff_init_prekernel, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);

0 comments on commit 0f49f22

Please sign in to comment.