You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.1 KiB
75 lines
2.1 KiB
5 years ago
|
|
||
5 years ago
|
#include <logging/log.h>
|
||
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||
5 years ago
|
#include <zmk/keymap.h>
|
||
5 years ago
|
|
||
5 years ago
|
static u32_t zmk_keymap_layer_state = 0;
|
||
5 years ago
|
static u8_t zmk_keymap_layer_default = 0;
|
||
5 years ago
|
|
||
|
static zmk_key zmk_keymap[ZMK_KEYMAP_LAYERS_LEN][ZMK_MATRIX_ROWS * ZMK_MATRIX_COLS] = {
|
||
|
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 0)
|
||
|
DT_PROP_BY_PHANDLE_IDX(ZMK_KEYMAP_NODE, layers, 0, keys),
|
||
5 years ago
|
#endif
|
||
5 years ago
|
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 1)
|
||
|
DT_PROP_BY_PHANDLE_IDX(ZMK_KEYMAP_NODE, layers, 1, keys),
|
||
5 years ago
|
#endif
|
||
5 years ago
|
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 2)
|
||
|
DT_PROP_BY_PHANDLE_IDX(ZMK_KEYMAP_NODE, layers, 2, keys),
|
||
5 years ago
|
#endif
|
||
5 years ago
|
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 3)
|
||
|
DT_PROP_BY_PHANDLE_IDX(ZMK_KEYMAP_NODE, layers, 3, keys),
|
||
5 years ago
|
#endif
|
||
5 years ago
|
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 4)
|
||
|
DT_PROP_BY_PHANDLE_IDX(ZMK_KEYMAP_NODE, layers, 4, keys),
|
||
5 years ago
|
#endif
|
||
5 years ago
|
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 5)
|
||
|
DT_PROP_BY_PHANDLE_IDX(ZMK_KEYMAP_NODE, layers, 5, keys),
|
||
5 years ago
|
#endif
|
||
5 years ago
|
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 6)
|
||
|
DT_PROP_BY_PHANDLE_IDX(ZMK_KEYMAP_NODE, layers, 6, keys),
|
||
5 years ago
|
#endif
|
||
5 years ago
|
#if DT_PROP_HAS_IDX(ZMK_KEYMAP_NODE, layers, 7)
|
||
|
DT_PROP_BY_PHANDLE_IDX(ZMK_KEYMAP_NODE, layers, 7, keys),
|
||
5 years ago
|
#endif
|
||
|
};
|
||
|
|
||
5 years ago
|
#define SET_LAYER_STATE(layer, state) \
|
||
|
if (layer >= 32) \
|
||
|
{ \
|
||
|
return false; \
|
||
|
} \
|
||
|
WRITE_BIT(zmk_keymap_layer_state, layer, state); \
|
||
5 years ago
|
return true;
|
||
|
|
||
|
bool zmk_keymap_layer_activate(u8_t layer)
|
||
|
{
|
||
|
SET_LAYER_STATE(layer, true);
|
||
|
};
|
||
|
|
||
|
bool zmk_keymap_layer_deactivate(u8_t layer)
|
||
5 years ago
|
{
|
||
5 years ago
|
SET_LAYER_STATE(layer, false);
|
||
|
};
|
||
|
|
||
|
zmk_key zmk_keymap_keycode_from_position(u32_t row, u32_t column)
|
||
|
{
|
||
|
for (int layer = ZMK_KEYMAP_LAYERS_LEN - 1; layer >= zmk_keymap_layer_default; layer--)
|
||
|
{
|
||
5 years ago
|
if ((zmk_keymap_layer_state & BIT(layer)) == BIT(layer) || layer == zmk_keymap_layer_default)
|
||
5 years ago
|
{
|
||
5 years ago
|
u8_t key_index = (row * ZMK_MATRIX_COLS) + column;
|
||
|
LOG_DBG("Getting key at index %d", key_index);
|
||
|
|
||
|
zmk_key key = zmk_keymap[layer][key_index];
|
||
5 years ago
|
if (key == ZC_TRNS)
|
||
|
{
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
return key;
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
return ZC_NO;
|
||
5 years ago
|
}
|