summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/dts/behaviors/reset.dtsi9
-rw-r--r--app/dts/bindings/behaviors/zmk,behavior-reset.yaml5
-rw-r--r--app/include/dt-bindings/zmk/reset.h12
-rw-r--r--app/src/behaviors/behavior_reset.c29
4 files changed, 43 insertions, 12 deletions
diff --git a/app/dts/behaviors/reset.dtsi b/app/dts/behaviors/reset.dtsi
index 4e3b444..fc4fa14 100644
--- a/app/dts/behaviors/reset.dtsi
+++ b/app/dts/behaviors/reset.dtsi
@@ -1,3 +1,5 @@
+#include <dt-bindings/zmk/reset.h>
+
/ {
behaviors {
reset: behavior_reset {
@@ -5,5 +7,12 @@
label = "RESET";
#binding-cells = <0>;
};
+
+ bootloader: behavior_reset_dfu {
+ compatible = "zmk,behavior-reset";
+ label = "BOOTLOADER_RESET";
+ type = <RST_UF2>;
+ #binding-cells = <0>;
+ };
};
};
diff --git a/app/dts/bindings/behaviors/zmk,behavior-reset.yaml b/app/dts/bindings/behaviors/zmk,behavior-reset.yaml
index c8e5e6f..061b15e 100644
--- a/app/dts/bindings/behaviors/zmk,behavior-reset.yaml
+++ b/app/dts/bindings/behaviors/zmk,behavior-reset.yaml
@@ -6,3 +6,8 @@ description: Keyboard Reset Behavior
compatible: "zmk,behavior-reset"
include: zero_param.yaml
+
+properties:
+ type:
+ type: int
+ default: 0
diff --git a/app/include/dt-bindings/zmk/reset.h b/app/include/dt-bindings/zmk/reset.h
new file mode 100644
index 0000000..b513649
--- /dev/null
+++ b/app/include/dt-bindings/zmk/reset.h
@@ -0,0 +1,12 @@
+/*
+ * Copyright (c) 2020 Peter Johanson <peter@peterjohanson.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#define RST_WARM 0x00
+#define RST_COLD 0x01
+
+// AdaFruit nrf52 Bootloader Specific. See https://github.com/adafruit/Adafruit_nRF52_Bootloader/blob/d6b28e66053eea467166f44875e3c7ec741cb471/src/main.c#L107
+
+#define RST_UF2 0x57 \ No newline at end of file
diff --git a/app/src/behaviors/behavior_reset.c b/app/src/behaviors/behavior_reset.c
index 44cbc21..30a96ea 100644
--- a/app/src/behaviors/behavior_reset.c
+++ b/app/src/behaviors/behavior_reset.c
@@ -13,8 +13,9 @@
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
-struct behavior_reset_config { };
-struct behavior_reset_data { };
+struct behavior_reset_config {
+ int type;
+};
static int behavior_reset_init(struct device *dev)
{
@@ -23,9 +24,11 @@ static int behavior_reset_init(struct device *dev)
static int on_keymap_binding_pressed(struct device *dev, u32_t position, u32_t _param1, u32_t _param2)
{
+ const struct behavior_reset_config *cfg = dev->config_info;
+
// TODO: Correct magic code for going into DFU?
// See https://github.com/adafruit/Adafruit_nRF52_Bootloader/blob/d6b28e66053eea467166f44875e3c7ec741cb471/src/main.c#L107
- sys_reboot(0);
+ sys_reboot(cfg->type);
return 0;
}
@@ -34,12 +37,14 @@ static const struct behavior_driver_api behavior_reset_driver_api = {
};
-static const struct behavior_reset_config behavior_reset_config = {};
-
-static struct behavior_reset_data behavior_reset_data;
-
-DEVICE_AND_API_INIT(behavior_reset, DT_INST_LABEL(0), behavior_reset_init,
- &behavior_reset_data,
- &behavior_reset_config,
- APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
- &behavior_reset_driver_api); \ No newline at end of file
+#define RST_INST(n) \
+ static const struct behavior_reset_config behavior_reset_config_##n = { \
+ .type = DT_INST_PROP(n, type) \
+ }; \
+ DEVICE_AND_API_INIT(behavior_reset_##n, DT_INST_LABEL(n), behavior_reset_init, \
+ NULL, \
+ &behavior_reset_config_##n, \
+ APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
+ &behavior_reset_driver_api);
+
+DT_INST_FOREACH_STATUS_OKAY(RST_INST) \ No newline at end of file