feat(behaviors): Add &bootloader
behavior.
* Allow reset behavior to have a type property. * Add `bootloader` node that triggers DFU UF2 bootloader mode using the AdaFruit nrf52 bootloader.
This commit is contained in:
parent
1ff13676f7
commit
805ea77005
6 changed files with 87 additions and 12 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
#include <dt-bindings/zmk/reset.h>
|
||||||
|
|
||||||
/ {
|
/ {
|
||||||
behaviors {
|
behaviors {
|
||||||
reset: behavior_reset {
|
reset: behavior_reset {
|
||||||
|
@ -5,5 +7,12 @@
|
||||||
label = "RESET";
|
label = "RESET";
|
||||||
#binding-cells = <0>;
|
#binding-cells = <0>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bootloader: behavior_reset_dfu {
|
||||||
|
compatible = "zmk,behavior-reset";
|
||||||
|
label = "BOOTLOADER_RESET";
|
||||||
|
type = <RST_UF2>;
|
||||||
|
#binding-cells = <0>;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,3 +6,8 @@ description: Keyboard Reset Behavior
|
||||||
compatible: "zmk,behavior-reset"
|
compatible: "zmk,behavior-reset"
|
||||||
|
|
||||||
include: zero_param.yaml
|
include: zero_param.yaml
|
||||||
|
|
||||||
|
properties:
|
||||||
|
type:
|
||||||
|
type: int
|
||||||
|
default: 0
|
||||||
|
|
12
app/include/dt-bindings/zmk/reset.h
Normal file
12
app/include/dt-bindings/zmk/reset.h
Normal file
|
@ -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
|
|
@ -13,8 +13,9 @@
|
||||||
|
|
||||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||||
|
|
||||||
struct behavior_reset_config { };
|
struct behavior_reset_config {
|
||||||
struct behavior_reset_data { };
|
int type;
|
||||||
|
};
|
||||||
|
|
||||||
static int behavior_reset_init(struct device *dev)
|
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)
|
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?
|
// TODO: Correct magic code for going into DFU?
|
||||||
// See https://github.com/adafruit/Adafruit_nRF52_Bootloader/blob/d6b28e66053eea467166f44875e3c7ec741cb471/src/main.c#L107
|
// See https://github.com/adafruit/Adafruit_nRF52_Bootloader/blob/d6b28e66053eea467166f44875e3c7ec741cb471/src/main.c#L107
|
||||||
sys_reboot(0);
|
sys_reboot(cfg->type);
|
||||||
return 0;
|
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 = {};
|
#define RST_INST(n) \
|
||||||
|
static const struct behavior_reset_config behavior_reset_config_##n = { \
|
||||||
static struct behavior_reset_data behavior_reset_data;
|
.type = DT_INST_PROP(n, type) \
|
||||||
|
}; \
|
||||||
DEVICE_AND_API_INIT(behavior_reset, DT_INST_LABEL(0), behavior_reset_init,
|
DEVICE_AND_API_INIT(behavior_reset_##n, DT_INST_LABEL(n), behavior_reset_init, \
|
||||||
&behavior_reset_data,
|
NULL, \
|
||||||
&behavior_reset_config,
|
&behavior_reset_config_##n, \
|
||||||
APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
|
APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
|
||||||
&behavior_reset_driver_api);
|
&behavior_reset_driver_api);
|
||||||
|
|
||||||
|
DT_INST_FOREACH_STATUS_OKAY(RST_INST)
|
43
docs/docs/behavior/reset.md
Normal file
43
docs/docs/behavior/reset.md
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
---
|
||||||
|
title: Reset Behaviors
|
||||||
|
sidebar_label: Reset
|
||||||
|
---
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
There are two available behaviors that can be used to trigger a reset of the keyboard.
|
||||||
|
The first is a soft reset, that will simply reset and re-run the currently flashed
|
||||||
|
firmware; the second when triggered will reset into the bootloader, allowing you to
|
||||||
|
flash a new firmware to the keyboard.
|
||||||
|
|
||||||
|
## Reset
|
||||||
|
|
||||||
|
The basic reset behavior will reset the keyboard and re-run the firmware flashed
|
||||||
|
to the device
|
||||||
|
|
||||||
|
### Behavior Binding
|
||||||
|
|
||||||
|
- Reference: `&reset`
|
||||||
|
- Parameters: None
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```
|
||||||
|
&reset
|
||||||
|
```
|
||||||
|
|
||||||
|
## Bootloader Reset
|
||||||
|
|
||||||
|
The bootloader reset behavior will reset the keyboard and put it into bootloader mode, allowing
|
||||||
|
you to flash a new firmware.
|
||||||
|
|
||||||
|
### Behavior Binding
|
||||||
|
|
||||||
|
- Reference: `&bootloader`
|
||||||
|
- Parameters: None
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```
|
||||||
|
&bootloader
|
||||||
|
```
|
|
@ -12,6 +12,7 @@ module.exports = {
|
||||||
"behavior/layers",
|
"behavior/layers",
|
||||||
"behavior/misc",
|
"behavior/misc",
|
||||||
"behavior/mod-tap",
|
"behavior/mod-tap",
|
||||||
|
"behavior/reset",
|
||||||
"behavior/lighting",
|
"behavior/lighting",
|
||||||
],
|
],
|
||||||
Development: [
|
Development: [
|
||||||
|
|
Loading…
Reference in a new issue