Refactor to simpler keymaps.
This commit is contained in:
parent
fd3ce4ba1c
commit
0460631729
7 changed files with 76 additions and 167 deletions
|
@ -1,23 +1,11 @@
|
|||
#include <behaviors.dtsi>
|
||||
#include <dt-bindings/zmk/keys.h>
|
||||
#include <dt-bindings/zmk/matrix-transform.h>
|
||||
|
||||
/ {
|
||||
chosen {
|
||||
zmk,keymap = &keymap0;
|
||||
};
|
||||
|
||||
keymap0: keymap {
|
||||
keymap {
|
||||
compatible = "zmk,keymap";
|
||||
label ="Default Planck Keymap";
|
||||
layers = <&default>;
|
||||
};
|
||||
|
||||
layers {
|
||||
compatible = "zmk,layers";
|
||||
|
||||
default: layer_0 {
|
||||
label = "DEFAULT";
|
||||
default_layer {
|
||||
// -----------------------------------------------------------------------------------------
|
||||
// | TAB | Q | W | E | R | T | Y | U | I | O | P | BSPC |
|
||||
// | ESC | A | S | D | F | G | H | J | K | L | ; | ' |
|
||||
|
|
|
@ -1,23 +1,11 @@
|
|||
#include <dt-bindings/zmk/keys.h>
|
||||
#include <dt-bindings/zmk/matrix-transform.h>
|
||||
#include <behaviors.dtsi>
|
||||
#include <dt-bindings/zmk/keys.h>
|
||||
|
||||
/ {
|
||||
chosen {
|
||||
zmk,keymap = &keymap0;
|
||||
};
|
||||
|
||||
keymap0: keymap {
|
||||
compatible = "zmk,keymap";
|
||||
label ="Default Kyria Keymap";
|
||||
layers = <&default>;
|
||||
};
|
||||
|
||||
layers {
|
||||
compatible = "zmk,layers";
|
||||
|
||||
default: layer_0 {
|
||||
label = "DEFAULT";
|
||||
default_layer {
|
||||
bindings = <
|
||||
&kp NUM_9 &kp NUM_8
|
||||
&kp NUM_7 &kp NUM_6
|
||||
|
|
|
@ -2,34 +2,55 @@
|
|||
#include <dt-bindings/zmk/keys.h>
|
||||
|
||||
/ {
|
||||
chosen {
|
||||
zmk,keymap = &keymap0;
|
||||
};
|
||||
|
||||
keymap0: keymap {
|
||||
keymap {
|
||||
compatible = "zmk,keymap";
|
||||
label ="Default Kyria Keymap";
|
||||
layers = <&default>;
|
||||
};
|
||||
|
||||
layers {
|
||||
compatible = "zmk,layers";
|
||||
|
||||
default: layer_0 {
|
||||
label = "DEFAULT";
|
||||
default_layer {
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// | ESC | Q | W | E | R | T | | Y | U | I | O | P | \ |
|
||||
// | TAB | A | S | D | F | G | | H | J | K | L | ; | ' |
|
||||
// | SHIFT | Z | X | C | V | B | L SHIFT | L SHIFT | | L SHIFT | L SHIFT | N | M | , | . | / | CTRL |
|
||||
// | GUI | DEL | RET | SPACE | ESC | | RET | SPACE | TAB | BSPC | R-ALT |
|
||||
bindings = <
|
||||
&kp ESC &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P &kp BSLH
|
||||
&kp TAB &kp A &kp S &kp D &kp F &kp G &kp H &kp J &kp K &kp L &kp SCLN &kp QUOT
|
||||
&kp LSFT &kp Z &kp X &kp C &kp V &kp B &kp LSFT &kp LSFT &kp LSFT &kp LSFT &kp N &kp M &kp CMMA &kp DOT &kp FSLH &kp RCTL
|
||||
&kp LGUI &kp DEL &kp RET &kp SPC &kp ESC &kp RET &kp SPC &kp TAB &kp BKSP &kp RALT
|
||||
&kp ESC &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P &kp BSLH
|
||||
&kp TAB &kp A &kp S &mt MOD_LCTL D &mt MOD_LSFT F &kp G &kp H &mt MOD_LSFT J &mt MOD_LCTL K &kp L &kp SCLN &kp QUOT
|
||||
&kp LSFT &kp Z &kp X &kp C &kp V &kp B &kp LSFT &kp LSFT &kp LSFT &kp LSFT &kp N &kp M &kp CMMA &kp DOT &kp FSLH &kp RCTL
|
||||
&kp LGUI &kp DEL &kp RET &kp SPC &mo 1 &mo 2 &kp SPC &kp RET &kp BKSP &kp RALT
|
||||
>;
|
||||
|
||||
sensor-bindings = <&inc_dec_cp M_VOLU M_VOLD &inc_dec_kp PGUP PGDN>;
|
||||
};
|
||||
|
||||
lower_layer {
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// | ESC | Q | W | E | R | T | | Y | U | I | O | P | \ |
|
||||
// | TAB | A | S | D | F | G | | H | J | K | L | ; | ' |
|
||||
// | SHIFT | Z | X | C | V | B | L SHIFT | L SHIFT | | L SHIFT | L SHIFT | N | M | , | . | / | CTRL |
|
||||
// | GUI | DEL | RET | SPACE | ESC | | RET | SPACE | TAB | BSPC | R-ALT |
|
||||
bindings = <
|
||||
&kp ESC &kp NUM_1 &kp NUM_2 &kp NUM_3 &kp NUM_4 &kp NUM_5 &kp NUM_6 &kp NUM_7 &kp NUM_8 &kp NUM_9 &kp NUM_0 &kp BSLH
|
||||
&kp TAB &kp A &kp S &mt MOD_LCTL D &mt MOD_LSFT F &kp G &kp H &mt MOD_LSFT J &mt MOD_LCTL K &kp L &kp SCLN &kp QUOT
|
||||
&kp LSFT &kp Z &kp X &kp C &kp V &kp B &kp LSFT &kp LSFT &kp LSFT &kp LSFT &kp N &kp M &kp CMMA &kp DOT &kp FSLH &kp RCTL
|
||||
&kp LGUI &kp DEL &kp RET &kp SPC &trans &kp RET &kp SPC &kp SPC &kp BKSP &kp RALT
|
||||
>;
|
||||
|
||||
// sensor-bindings = <&inc_dec_cp M_VOLU M_VOLD &inc_dec_kp PGUP PGDN>;
|
||||
};
|
||||
|
||||
raise_layer {
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// | ESC | Q | W | E | R | T | | Y | U | I | O | P | \ |
|
||||
// | TAB | A | S | D | F | G | | H | J | K | L | ; | ' |
|
||||
// | SHIFT | Z | X | C | V | B | L SHIFT | L SHIFT | | L SHIFT | L SHIFT | N | M | , | . | / | CTRL |
|
||||
// | GUI | DEL | RET | SPACE | ESC | | RET | SPACE | TAB | BSPC | R-ALT |
|
||||
bindings = <
|
||||
&kp ESC &kp Q &kp W &kp E &kp R &kp T &kp Y &kp U &kp I &kp O &kp P &kp BSLH
|
||||
&kp TAB &kp A &kp S &mt MOD_LCTL D &mt MOD_LSFT F &kp G &kp H &mt MOD_LSFT J &mt MOD_LCTL K &kp L &kp SCLN &kp QUOT
|
||||
&kp LSFT &kp Z &kp X &kp C &kp V &kp B &kp LSFT &kp LSFT &kp LSFT &kp LSFT &kp N &kp M &kp CMMA &kp DOT &kp FSLH &kp RCTL
|
||||
&kp LGUI &kp DEL &kp RET &kp SPC &kp RET &trans &kp SPC &kp SPC &kp BKSP &kp RALT
|
||||
>;
|
||||
|
||||
// sensor-bindings = <&inc_dec_cp M_VOLU M_VOLD &inc_dec_kp PGUP PGDN>;
|
||||
};
|
||||
};
|
||||
};
|
|
@ -1,23 +1,11 @@
|
|||
#include <behaviors.dtsi>
|
||||
#include <dt-bindings/zmk/keys.h>
|
||||
#include <dt-bindings/zmk/matrix-transform.h>
|
||||
|
||||
/ {
|
||||
chosen {
|
||||
zmk,keymap = &keymap0;
|
||||
};
|
||||
|
||||
keymap0: keymap {
|
||||
keymap {
|
||||
compatible = "zmk,keymap";
|
||||
label ="Default Lily58 Keymap";
|
||||
layers = <&default &lower &raise>;
|
||||
};
|
||||
|
||||
layers {
|
||||
compatible = "zmk,layers";
|
||||
|
||||
default: layer_0 {
|
||||
label = "DEFAULT";
|
||||
default_layer {
|
||||
// ------------------------------------------------------------------------------------------------------------
|
||||
// | ESC | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | ` |
|
||||
// | TAB | Q | W | E | R | T | | Y | U | I | O | P | - |
|
||||
|
@ -33,8 +21,7 @@
|
|||
>;
|
||||
};
|
||||
|
||||
lower: layer_1 {
|
||||
label = "LOWER";
|
||||
lower_layer {
|
||||
// ------------------------------------------------------------------------------------------------------------
|
||||
// | | | | | | | | | | | | | |
|
||||
// | F1 | F2 | F3 | F4 | F5 | F6 | | F7 | F8 | F9 | F10 | F11 | F12 |
|
||||
|
@ -50,8 +37,7 @@
|
|||
>;
|
||||
};
|
||||
|
||||
raise: layer_3 {
|
||||
label = "RAISE";
|
||||
raise_layer {
|
||||
// ------------------------------------------------------------------------------------------------------------
|
||||
// | | | | | | | | | | | | | |
|
||||
// | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | |
|
||||
|
|
|
@ -3,15 +3,13 @@ description: |
|
|||
|
||||
compatible: "zmk,keymap"
|
||||
|
||||
properties:
|
||||
transform:
|
||||
type: phandle
|
||||
required: false
|
||||
child-binding:
|
||||
description: "A layer to be used in a keymap"
|
||||
|
||||
label:
|
||||
type: string
|
||||
required: true
|
||||
|
||||
layers:
|
||||
type: phandles
|
||||
required: true
|
||||
properties:
|
||||
bindings:
|
||||
type: phandle-array
|
||||
required: true
|
||||
sensor-bindings:
|
||||
type: phandle-array
|
||||
required: false
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
description: |
|
||||
Allows defining the various keymap layers for use.
|
||||
|
||||
compatible: "zmk,layers"
|
||||
|
||||
child-binding:
|
||||
description: "A layer to be used in a keymap"
|
||||
|
||||
properties:
|
||||
label:
|
||||
type: string
|
||||
required: true
|
||||
bindings:
|
||||
type: phandle-array
|
||||
required: true
|
||||
sensor-bindings:
|
||||
type: phandle-array
|
||||
required: false
|
|
@ -17,96 +17,41 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
|||
static u32_t zmk_keymap_layer_state = 0;
|
||||
static u8_t zmk_keymap_layer_default = 0;
|
||||
|
||||
#define ZMK_KEYMAP_NODE DT_CHOSEN(zmk_keymap)
|
||||
#define ZMK_KEYMAP_LAYERS_LEN DT_PROP_LEN(ZMK_KEYMAP_NODE, layers)
|
||||
#define DT_DRV_COMPAT zmk_keymap
|
||||
|
||||
#define LAYER_CHILD_LEN(node) 1+
|
||||
#define ZMK_KEYMAP_NODE DT_DRV_INST(0)
|
||||
#define ZMK_KEYMAP_LAYERS_LEN (DT_INST_FOREACH_CHILD(0, LAYER_CHILD_LEN) 0)
|
||||
|
||||
#define LAYER_NODE(l) DT_PHANDLE_BY_IDX(ZMK_KEYMAP_NODE, layers, l)
|
||||
|
||||
#define _TRANSFORM_ENTRY(idx, layer) \
|
||||
{ .behavior_dev = DT_LABEL(DT_PHANDLE_BY_IDX(DT_PHANDLE_BY_IDX(ZMK_KEYMAP_NODE, layers, layer), bindings, idx)), \
|
||||
.param1 = COND_CODE_0(DT_PHA_HAS_CELL_AT_IDX(LAYER_NODE(layer), bindings, idx, param1), (0), (DT_PHA_BY_IDX(LAYER_NODE(layer), bindings, idx, param1))), \
|
||||
.param2 = COND_CODE_0(DT_PHA_HAS_CELL_AT_IDX(LAYER_NODE(layer), bindings, idx, param2), (0), (DT_PHA_BY_IDX(LAYER_NODE(layer), bindings, idx, param2))), \
|
||||
{ .behavior_dev = DT_LABEL(DT_PHANDLE_BY_IDX(layer, bindings, idx)), \
|
||||
.param1 = COND_CODE_0(DT_PHA_HAS_CELL_AT_IDX(layer, bindings, idx, param1), (0), (DT_PHA_BY_IDX(layer, bindings, idx, param1))), \
|
||||
.param2 = COND_CODE_0(DT_PHA_HAS_CELL_AT_IDX(layer, bindings, idx, param2), (0), (DT_PHA_BY_IDX(layer, bindings, idx, param2))), \
|
||||
},
|
||||
|
||||
#define TRANSFORMED_LAYER(idx) \
|
||||
{ UTIL_LISTIFY(DT_PROP_LEN(DT_PHANDLE_BY_IDX(ZMK_KEYMAP_NODE, layers, idx), bindings), _TRANSFORM_ENTRY, idx) }
|
||||
#define TRANSFORMED_LAYER(node) \
|
||||
{ UTIL_LISTIFY(DT_PROP_LEN(node, bindings), _TRANSFORM_ENTRY, node) },
|
||||
|
||||
static struct zmk_behavior_binding zmk_keymap[ZMK_KEYMAP_LAYERS_LEN][ZMK_KEYMAP_LEN] = {
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 0)
|
||||
TRANSFORMED_LAYER(0),
|
||||
#endif
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 1)
|
||||
TRANSFORMED_LAYER(1),
|
||||
#endif
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 2)
|
||||
TRANSFORMED_LAYER(2),
|
||||
#endif
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 3)
|
||||
TRANSFORMED_LAYER(3),
|
||||
#endif
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 4)
|
||||
TRANSFORMED_LAYER(4),
|
||||
#endif
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 5)
|
||||
TRANSFORMED_LAYER(5),
|
||||
#endif
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 6)
|
||||
TRANSFORMED_LAYER(6),
|
||||
#endif
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 7)
|
||||
TRANSFORMED_LAYER(7),
|
||||
#endif
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 8)
|
||||
TRANSFORMED_LAYER(8),
|
||||
#endif
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 9)
|
||||
TRANSFORMED_LAYER(9),
|
||||
#endif
|
||||
DT_INST_FOREACH_CHILD(0, TRANSFORMED_LAYER)
|
||||
};
|
||||
|
||||
#if ZMK_KEYMAP_HAS_SENSORS
|
||||
#define _TRANSFORM_SENSOR_ENTRY(idx, layer) \
|
||||
{ .behavior_dev = DT_LABEL(DT_PHANDLE_BY_IDX(DT_PHANDLE_BY_IDX(ZMK_KEYMAP_NODE, layers, layer), sensor_bindings, idx)), \
|
||||
.param1 = COND_CODE_0(DT_PHA_HAS_CELL_AT_IDX(LAYER_NODE(layer), sensor_bindings, idx, param1), (0), (DT_PHA_BY_IDX(LAYER_NODE(layer), sensor_bindings, idx, param1))), \
|
||||
.param2 = COND_CODE_0(DT_PHA_HAS_CELL_AT_IDX(LAYER_NODE(layer), sensor_bindings, idx, param2), (0), (DT_PHA_BY_IDX(LAYER_NODE(layer), sensor_bindings, idx, param2))), \
|
||||
{ .behavior_dev = DT_LABEL(DT_PHANDLE_BY_IDX(layer, sensor_bindings, idx)), \
|
||||
.param1 = COND_CODE_0(DT_PHA_HAS_CELL_AT_IDX(layer, sensor_bindings, idx, param1), (0), (DT_PHA_BY_IDX(layer, sensor_bindings, idx, param1))), \
|
||||
.param2 = COND_CODE_0(DT_PHA_HAS_CELL_AT_IDX(layer, sensor_bindings, idx, param2), (0), (DT_PHA_BY_IDX(layer, sensor_bindings, idx, param2))), \
|
||||
},
|
||||
|
||||
#define SENSOR_LAYER(idx) \
|
||||
COND_CODE_1(DT_NODE_HAS_PROP(DT_PHANDLE_BY_IDX(ZMK_KEYMAP_NODE, layers, idx), sensor_bindings), \
|
||||
({ UTIL_LISTIFY(DT_PROP_LEN(DT_PHANDLE_BY_IDX(ZMK_KEYMAP_NODE, layers, idx), sensor_bindings), _TRANSFORM_SENSOR_ENTRY, idx) }), \
|
||||
(NULL))
|
||||
#define SENSOR_LAYER(node) \
|
||||
COND_CODE_1(DT_NODE_HAS_PROP(node, sensor_bindings), \
|
||||
({ UTIL_LISTIFY(DT_PROP_LEN(node, sensor_bindings), _TRANSFORM_SENSOR_ENTRY, node) }), \
|
||||
({})),
|
||||
|
||||
static struct zmk_behavior_binding zmk_sensor_keymap[ZMK_KEYMAP_LAYERS_LEN][ZMK_KEYMAP_SENSORS_LEN] = {
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 0)
|
||||
SENSOR_LAYER(0),
|
||||
#endif
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 1)
|
||||
SENSOR_LAYER(1),
|
||||
#endif
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 2)
|
||||
SENSOR_LAYER(2),
|
||||
#endif
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 3)
|
||||
SENSOR_LAYER(3),
|
||||
#endif
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 4)
|
||||
SENSOR_LAYER(4),
|
||||
#endif
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 5)
|
||||
SENSOR_LAYER(5),
|
||||
#endif
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 6)
|
||||
SENSOR_LAYER(6),
|
||||
#endif
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 7)
|
||||
SENSOR_LAYER(7),
|
||||
#endif
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 8)
|
||||
SENSOR_LAYER(8),
|
||||
#endif
|
||||
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 9)
|
||||
SENSOR_LAYER(9),
|
||||
#endif
|
||||
DT_INST_FOREACH_CHILD(0, SENSOR_LAYER)
|
||||
};
|
||||
|
||||
#endif /* ZMK_KEYMAP_HAS_SENSORS */
|
||||
|
@ -131,6 +76,7 @@ int zmk_keymap_layer_deactivate(u8_t layer)
|
|||
|
||||
int zmk_keymap_position_state_changed(u32_t position, bool pressed)
|
||||
{
|
||||
LOG_DBG("Searching %d layers for a binding", ZMK_KEYMAP_LAYERS_LEN);
|
||||
for (int layer = ZMK_KEYMAP_LAYERS_LEN - 1; layer >= zmk_keymap_layer_default; layer--)
|
||||
{
|
||||
if ((zmk_keymap_layer_state & BIT(layer)) == BIT(layer) || layer == zmk_keymap_layer_default)
|
||||
|
|
Loading…
Reference in a new issue