|
|
@ -4,42 +4,22 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
|
|
|
#include <zmk/keymap.h> |
|
|
|
#include <zmk/keymap.h> |
|
|
|
#include <dt-bindings/zmk/matrix-transform.h> |
|
|
|
#include <dt-bindings/zmk/matrix-transform.h> |
|
|
|
#include <drivers/behavior.h> |
|
|
|
#include <drivers/behavior.h> |
|
|
|
|
|
|
|
#include <zmk/behavior.h> |
|
|
|
#include <sys/util.h> |
|
|
|
#include <sys/util.h> |
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
struct zmk_behavior_binding { |
|
|
|
|
|
|
|
char *behavior_dev; |
|
|
|
|
|
|
|
u32_t param1; |
|
|
|
|
|
|
|
u32_t param2; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ZMK_KEYMAP_NODE DT_CHOSEN(zmk_keymap) |
|
|
|
#define ZMK_KEYMAP_NODE DT_CHOSEN(zmk_keymap) |
|
|
|
#define ZMK_KEYMAP_LAYERS_LEN DT_PROP_LEN(ZMK_KEYMAP_NODE, layers) |
|
|
|
#define ZMK_KEYMAP_LAYERS_LEN DT_PROP_LEN(ZMK_KEYMAP_NODE, layers) |
|
|
|
|
|
|
|
|
|
|
|
#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 BINDING_FOR_IDX(layer,idx) \ |
|
|
|
#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(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))), \
|
|
|
|
.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))), \
|
|
|
|
.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))), \
|
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
#if DT_NODE_HAS_PROP(ZMK_KEYMAP_NODE, transform) |
|
|
|
|
|
|
|
#define ZMK_KEYMAP_TRANSFORM_NODE DT_PHANDLE(ZMK_KEYMAP_NODE, transform) |
|
|
|
|
|
|
|
#define ZMK_KEYMAP_LEN DT_PROP_LEN(ZMK_KEYMAP_TRANSFORM_NODE, map) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define _TRANSFORM_ENTRY(i, l) \ |
|
|
|
|
|
|
|
[(KT_ROW(DT_PROP_BY_IDX(ZMK_KEYMAP_TRANSFORM_NODE, map, i)) * ZMK_MATRIX_COLS) + KT_COL(DT_PROP_BY_IDX(ZMK_KEYMAP_TRANSFORM_NODE, map, i))] = BINDING_FOR_IDX(l,i), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ZMK_KEYMAP_LEN DT_PROP_LEN(ZMK_KEYMAP_NODE, bindings) |
|
|
|
|
|
|
|
#define _TRANSFORM_ENTRY(i, l) \ |
|
|
|
|
|
|
|
BINDING_FOR_IDX(l,i), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define TRANSFORMED_LAYER(idx) \ |
|
|
|
#define TRANSFORMED_LAYER(idx) \ |
|
|
|
{ UTIL_LISTIFY(DT_PROP_LEN(DT_PHANDLE_BY_IDX(ZMK_KEYMAP_NODE, layers, idx), bindings), _TRANSFORM_ENTRY, idx) } |
|
|
|
{ UTIL_LISTIFY(DT_PROP_LEN(DT_PHANDLE_BY_IDX(ZMK_KEYMAP_NODE, layers, idx), bindings), _TRANSFORM_ENTRY, idx) } |
|
|
@ -77,8 +57,6 @@ static struct zmk_behavior_binding zmk_keymap[ZMK_KEYMAP_LAYERS_LEN][ZMK_MATRIX_ |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// #else
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define SET_LAYER_STATE(layer, state) \ |
|
|
|
#define SET_LAYER_STATE(layer, state) \ |
|
|
|
if (layer >= 32) \
|
|
|
|
if (layer >= 32) \
|
|
|
|
{ \
|
|
|
|
{ \
|
|
|
@ -97,18 +75,17 @@ bool zmk_keymap_layer_deactivate(u8_t layer) |
|
|
|
SET_LAYER_STATE(layer, false); |
|
|
|
SET_LAYER_STATE(layer, false); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
int zmk_keymap_position_state_changed(u32_t row, u32_t column, bool pressed) |
|
|
|
int zmk_keymap_position_state_changed(u32_t position, bool pressed) |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (int layer = ZMK_KEYMAP_LAYERS_LEN - 1; layer >= zmk_keymap_layer_default; layer--) |
|
|
|
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) |
|
|
|
if ((zmk_keymap_layer_state & BIT(layer)) == BIT(layer) || layer == zmk_keymap_layer_default) |
|
|
|
{ |
|
|
|
{ |
|
|
|
u8_t key_index = (row * ZMK_MATRIX_COLS) + column; |
|
|
|
struct zmk_behavior_binding *binding = &zmk_keymap[layer][position]; |
|
|
|
struct zmk_behavior_binding *binding = &zmk_keymap[layer][key_index]; |
|
|
|
|
|
|
|
struct device *behavior; |
|
|
|
struct device *behavior; |
|
|
|
int ret; |
|
|
|
int ret; |
|
|
|
|
|
|
|
|
|
|
|
LOG_DBG("key index: %d, binding name: %s", key_index, binding->behavior_dev); |
|
|
|
LOG_DBG("position: %d, binding name: %s", position, binding->behavior_dev); |
|
|
|
|
|
|
|
|
|
|
|
behavior = device_get_binding(binding->behavior_dev); |
|
|
|
behavior = device_get_binding(binding->behavior_dev); |
|
|
|
if (pressed) { |
|
|
|
if (pressed) { |
|
|
|