Browse Source

Merge pull request #74 from petejohanson/core/keymaps-refactor-simplification

Refactor to simpler keymaps.
xmkb
Pete Johanson 4 years ago committed by GitHub
parent
commit
4b0284f45b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      app/boards/arm/planck/planck_rev6.keymap
  2. 16
      app/boards/shields/clueboard_california/clueboard_california.keymap
  3. 15
      app/boards/shields/kyria/kyria.keymap
  4. 22
      app/boards/shields/lily58/lily58.keymap
  5. 22
      app/dts/bindings/zmk,keymap.yaml
  6. 18
      app/dts/bindings/zmk,layers.yaml
  7. 93
      app/src/keymap.c

16
app/boards/arm/planck/planck_rev6.keymap

@ -1,23 +1,11 @@
#include <behaviors.dtsi> #include <behaviors.dtsi>
#include <dt-bindings/zmk/keys.h> #include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/matrix-transform.h>
/ { / {
chosen { keymap {
zmk,keymap = &keymap0;
};
keymap0: keymap {
compatible = "zmk,keymap"; compatible = "zmk,keymap";
label ="Default Planck Keymap";
layers = <&default>;
};
layers {
compatible = "zmk,layers";
default: layer_0 { default_layer {
label = "DEFAULT";
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
// | TAB | Q | W | E | R | T | Y | U | I | O | P | BSPC | // | TAB | Q | W | E | R | T | Y | U | I | O | P | BSPC |
// | ESC | A | S | D | F | G | H | J | K | L | ; | ' | // | ESC | A | S | D | F | G | H | J | K | L | ; | ' |

16
app/boards/shields/clueboard_california/clueboard_california.keymap

@ -1,23 +1,11 @@
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/matrix-transform.h>
#include <behaviors.dtsi> #include <behaviors.dtsi>
#include <dt-bindings/zmk/keys.h>
/ { / {
chosen {
zmk,keymap = &keymap0;
};
keymap0: keymap { keymap0: keymap {
compatible = "zmk,keymap"; compatible = "zmk,keymap";
label ="Default Kyria Keymap";
layers = <&default>;
};
layers {
compatible = "zmk,layers";
default: layer_0 { default_layer {
label = "DEFAULT";
bindings = < bindings = <
&kp NUM_9 &kp NUM_8 &kp NUM_9 &kp NUM_8
&kp NUM_7 &kp NUM_6 &kp NUM_7 &kp NUM_6

15
app/boards/shields/kyria/kyria.keymap

@ -2,21 +2,10 @@
#include <dt-bindings/zmk/keys.h> #include <dt-bindings/zmk/keys.h>
/ { / {
chosen { keymap {
zmk,keymap = &keymap0;
};
keymap0: keymap {
compatible = "zmk,keymap"; compatible = "zmk,keymap";
label ="Default Kyria Keymap";
layers = <&default>;
};
layers {
compatible = "zmk,layers";
default: layer_0 { default_layer {
label = "DEFAULT";
// --------------------------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------------------------
// | ESC | Q | W | E | R | T | | Y | U | I | O | P | \ | // | ESC | Q | W | E | R | T | | Y | U | I | O | P | \ |
// | TAB | A | S | D | F | G | | H | J | K | L | ; | ' | // | TAB | A | S | D | F | G | | H | J | K | L | ; | ' |

22
app/boards/shields/lily58/lily58.keymap

@ -1,23 +1,11 @@
#include <behaviors.dtsi> #include <behaviors.dtsi>
#include <dt-bindings/zmk/keys.h> #include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/matrix-transform.h>
/ { / {
chosen { keymap {
zmk,keymap = &keymap0;
};
keymap0: keymap {
compatible = "zmk,keymap"; compatible = "zmk,keymap";
label ="Default Lily58 Keymap";
layers = <&default &lower &raise>;
};
layers {
compatible = "zmk,layers";
default: layer_0 { default_layer {
label = "DEFAULT";
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
// | ESC | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | ` | // | ESC | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | ` |
// | TAB | Q | W | E | R | T | | Y | U | I | O | P | - | // | TAB | Q | W | E | R | T | | Y | U | I | O | P | - |
@ -33,8 +21,7 @@
>; >;
}; };
lower: layer_1 { lower_layer {
label = "LOWER";
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
// | | | | | | | | | | | | | | // | | | | | | | | | | | | | |
// | F1 | F2 | F3 | F4 | F5 | F6 | | F7 | F8 | F9 | F10 | F11 | F12 | // | F1 | F2 | F3 | F4 | F5 | F6 | | F7 | F8 | F9 | F10 | F11 | F12 |
@ -50,8 +37,7 @@
>; >;
}; };
raise: layer_3 { raise_layer {
label = "RAISE";
// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
// | | | | | | | | | | | | | | // | | | | | | | | | | | | | |
// | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | | // | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | |

22
app/dts/bindings/zmk,keymap.yaml

@ -3,15 +3,13 @@ description: |
compatible: "zmk,keymap" compatible: "zmk,keymap"
properties: child-binding:
transform: description: "A layer to be used in a keymap"
type: phandle
required: false properties:
bindings:
label: type: phandle-array
type: string required: true
required: true sensor-bindings:
type: phandle-array
layers: required: false
type: phandles
required: true

18
app/dts/bindings/zmk,layers.yaml

@ -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

93
app/src/keymap.c

@ -17,96 +17,41 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
static u32_t zmk_keymap_layer_state = 0; static u32_t zmk_keymap_layer_state = 0;
static u8_t zmk_keymap_layer_default = 0; static u8_t zmk_keymap_layer_default = 0;
#define ZMK_KEYMAP_NODE DT_CHOSEN(zmk_keymap) #define DT_DRV_COMPAT zmk_keymap
#define ZMK_KEYMAP_LAYERS_LEN DT_PROP_LEN(ZMK_KEYMAP_NODE, layers)
#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 LAYER_NODE(l) DT_PHANDLE_BY_IDX(ZMK_KEYMAP_NODE, layers, l)
#define _TRANSFORM_ENTRY(idx, layer) \ #define _TRANSFORM_ENTRY(idx, layer) \
{ .behavior_dev = DT_LABEL(DT_PHANDLE_BY_IDX(DT_PHANDLE_BY_IDX(ZMK_KEYMAP_NODE, layers, layer), bindings, idx)), \ { .behavior_dev = DT_LABEL(DT_PHANDLE_BY_IDX(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))), \ .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_NODE(layer), bindings, idx, param2), (0), (DT_PHA_BY_IDX(LAYER_NODE(layer), bindings, idx, param2))), \ .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) \ #define TRANSFORMED_LAYER(node) \
{ UTIL_LISTIFY(DT_PROP_LEN(DT_PHANDLE_BY_IDX(ZMK_KEYMAP_NODE, layers, idx), bindings), _TRANSFORM_ENTRY, idx) } { UTIL_LISTIFY(DT_PROP_LEN(node, bindings), _TRANSFORM_ENTRY, node) },
static struct zmk_behavior_binding zmk_keymap[ZMK_KEYMAP_LAYERS_LEN][ZMK_KEYMAP_LEN] = { static struct zmk_behavior_binding zmk_keymap[ZMK_KEYMAP_LAYERS_LEN][ZMK_KEYMAP_LEN] = {
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 0) DT_INST_FOREACH_CHILD(0, TRANSFORMED_LAYER)
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
}; };
#if ZMK_KEYMAP_HAS_SENSORS #if ZMK_KEYMAP_HAS_SENSORS
#define _TRANSFORM_SENSOR_ENTRY(idx, layer) \ #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)), \ { .behavior_dev = DT_LABEL(DT_PHANDLE_BY_IDX(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))), \ .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_NODE(layer), sensor_bindings, idx, param2), (0), (DT_PHA_BY_IDX(LAYER_NODE(layer), sensor_bindings, idx, param2))), \ .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) \ #define SENSOR_LAYER(node) \
COND_CODE_1(DT_NODE_HAS_PROP(DT_PHANDLE_BY_IDX(ZMK_KEYMAP_NODE, layers, idx), sensor_bindings), \ COND_CODE_1(DT_NODE_HAS_PROP(node, sensor_bindings), \
({ UTIL_LISTIFY(DT_PROP_LEN(DT_PHANDLE_BY_IDX(ZMK_KEYMAP_NODE, layers, idx), sensor_bindings), _TRANSFORM_SENSOR_ENTRY, idx) }), \ ({ UTIL_LISTIFY(DT_PROP_LEN(node, sensor_bindings), _TRANSFORM_SENSOR_ENTRY, node) }), \
(NULL)) ({})),
static struct zmk_behavior_binding zmk_sensor_keymap[ZMK_KEYMAP_LAYERS_LEN][ZMK_KEYMAP_SENSORS_LEN] = { 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) DT_INST_FOREACH_CHILD(0, SENSOR_LAYER)
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
}; };
#endif /* ZMK_KEYMAP_HAS_SENSORS */ #endif /* ZMK_KEYMAP_HAS_SENSORS */

Loading…
Cancel
Save