Implement raise/lower for default keymap.

* Properly allow includes for keymaps to allow defining
  custom keycodes, and then adding them to the
  keymap.overlay file.
* Fix keymap.c loading after build refactor.
* Fix for deactivating a layer working properly.
* Fix default keymap to put transparent in proper spots to
  make raise/lower keycodes work as expected.
* Add custom raise/lower keycode handling to default
  keymap.
This commit is contained in:
Pete Johanson 2020-05-18 13:42:41 -04:00
parent c1905745b3
commit f478438f01
8 changed files with 69 additions and 22 deletions

View file

@ -9,9 +9,9 @@ include(cmake/keymap.cmake)
find_package(Zephyr)
project(zmk)
if(EXISTS ${KEYMAP_DIR}/${KEYMAP}/keymap.c)
if(EXISTS ${KEYMAP_DIR}/keymap.c)
message(STATUS "ADDING THE KEYMAP SOURCE")
target_sources(app PRIVATE ${KEYMAP_DIR}/${KEYMAP}/keymap.c)
target_sources(app PRIVATE ${KEYMAP_DIR}/keymap.c)
endif()

View file

@ -0,0 +1,5 @@
#include <dt-bindings/zmk/keys.h>
#define CC_RAIS ZC_CSTM(1)
#define CC_LOWR ZC_CSTM(2)

View file

@ -1,7 +1,34 @@
#include <zmk/keys.h>
#include <zmk/keymap.h>
#include <keymap.h>
bool zmk_handle_key_user(struct zmk_key_event *key_event)
{
switch (key_event->key)
{
case CC_LOWR:
if (key_event->pressed)
{
zmk_keymap_layer_activate(1);
}
else
{
zmk_keymap_layer_deactivate(1);
}
return false;
case CC_RAIS:
if (key_event->pressed)
{
zmk_keymap_layer_activate(2);
}
else
{
zmk_keymap_layer_deactivate(2);
}
return false;
}
return true;
};

View file

@ -1,4 +1,5 @@
#include <dt-bindings/zmk/keys.h>
#include <keymap.h>
/ {
chosen {
@ -14,22 +15,22 @@
compatible = "zmk,layers";
default: layer_0 {
label = "Default";
label = "DEFAULT";
keys =
<
KC_A KC_B
KC_C ZC_CSTM(1)
CC_RAIS CC_LOWR
>;
};
lower: layer_1 {
label = "Lower";
keys = <KC_D KC_C KC_B KC_A>;
label = "LOWER";
keys = <KC_D KC_C ZC_TRNS ZC_TRNS>;
};
raise: layer_2 {
label = "Raise";
keys = <KC_C KC_D KC_A KC_B>;
label = "RAISE";
keys = <KC_C KC_D ZC_TRNS ZC_TRNS>;
};
};
};

View file

@ -76,13 +76,19 @@ foreach(root ${BOARD_ROOT})
endif()
endforeach()
find_path(KEYMAP_DIR
find_path(BASE_KEYMAPS_DIR
NAMES ${KEYMAP}/keymap.overlay
PATHS ${KEYMAP_DIRS}
NO_DEFAULT_PATH
)
if (KEYMAP_DIR)
message(STATUS "Using keymap directory: ${KEYMAP_DIR}/${KEYMAP}/")
set(DTC_OVERLAY_FILE ${KEYMAP_DIR}/${KEYMAP}/keymap.overlay)
if (BASE_KEYMAPS_DIR)
set(KEYMAP_DIR "${BASE_KEYMAPS_DIR}/${KEYMAP}" CACHE STRING "Selected keymap directory")
message(STATUS "Using keymap directory: ${KEYMAP_DIR}/")
# Used to let local imports of custom keycodes work as expected
list(APPEND DTS_ROOT ${KEYMAP_DIR})
if (EXISTS "${KEYMAP_DIR}/include")
include_directories("${KEYMAP_DIR}/include")
endif()
set(DTC_OVERLAY_FILE ${KEYMAP_DIR}/keymap.overlay)
endif()

View file

@ -66,9 +66,7 @@
#define KC_ALT 0x02
#define KC_CTRL 0x03
#define ZC_RAIS 0xF0
#define ZC_LOWR 0xF1
#define ZC_TRNS 0xF2
#define ZC_NOOP 0xF3
#define ZC_TRNS 0xF0
#define ZC_NOOP 0xF1
#define ZC_CSTM(n) (0xFF + n)

View file

@ -11,6 +11,16 @@
#define ZMK_KEYMAP_NODE DT_CHOSEN(zmk_keymap)
#define ZMK_KEYMAP_LAYERS_LEN DT_PROP_LEN(ZMK_KEYMAP_NODE, layers)
#define _ZMK_LAYER_ENUM_ITEM(label) DT_CAT(label, _layer)
#define _ZMK_KEYMAP_GENERATE_LAYER_CONST(node_id) \
_ZMK_LAYER_ENUM_ITEM(DT_NODELABEL(node_id)),
enum zmk_keymap_layer
{
DT_FOREACH_CHILD(DT_INST(0, zmk_layers), _ZMK_KEYMAP_GENERATE_LAYER_CONST)
};
bool zmk_keymap_layer_activate(u8_t layer);
bool zmk_keymap_layer_deactivate(u8_t layer);

View file

@ -36,7 +36,7 @@ static zmk_key zmk_keymap[ZMK_KEYMAP_LAYERS_LEN][ZMK_MATRIX_ROWS * ZMK_MATRIX_CO
{ \
return false; \
} \
WRITE_BIT(zmk_keymap_layer_state, layer, true); \
WRITE_BIT(zmk_keymap_layer_state, layer, state); \
return true;
bool zmk_keymap_layer_activate(u8_t layer)