Browse Source

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.
xmkb
Pete Johanson 5 years ago
parent
commit
f478438f01
  1. 4
      CMakeLists.txt
  2. 5
      boards/shields/petejohanson_handwire/keymaps/default/include/keymap.h
  3. 27
      boards/shields/petejohanson_handwire/keymaps/default/keymap.c
  4. 13
      boards/shields/petejohanson_handwire/keymaps/default/keymap.overlay
  5. 14
      cmake/keymap.cmake
  6. 6
      include/dt-bindings/zmk/keys.h
  7. 10
      include/zmk/keymap.h
  8. 2
      src/keymap.c

4
CMakeLists.txt

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

5
boards/shields/petejohanson_handwire/keymaps/default/include/keymap.h

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

27
boards/shields/petejohanson_handwire/keymaps/default/keymap.c

@ -1,7 +1,34 @@
#include <zmk/keys.h> #include <zmk/keys.h>
#include <zmk/keymap.h>
#include <keymap.h>
bool zmk_handle_key_user(struct zmk_key_event *key_event) 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; return true;
}; };

13
boards/shields/petejohanson_handwire/keymaps/default/keymap.overlay

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

14
cmake/keymap.cmake

@ -76,13 +76,19 @@ foreach(root ${BOARD_ROOT})
endif() endif()
endforeach() endforeach()
find_path(KEYMAP_DIR find_path(BASE_KEYMAPS_DIR
NAMES ${KEYMAP}/keymap.overlay NAMES ${KEYMAP}/keymap.overlay
PATHS ${KEYMAP_DIRS} PATHS ${KEYMAP_DIRS}
NO_DEFAULT_PATH NO_DEFAULT_PATH
) )
if (KEYMAP_DIR) if (BASE_KEYMAPS_DIR)
message(STATUS "Using keymap directory: ${KEYMAP_DIR}/${KEYMAP}/") set(KEYMAP_DIR "${BASE_KEYMAPS_DIR}/${KEYMAP}" CACHE STRING "Selected keymap directory")
set(DTC_OVERLAY_FILE ${KEYMAP_DIR}/${KEYMAP}/keymap.overlay) 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() endif()

6
include/dt-bindings/zmk/keys.h

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

10
include/zmk/keymap.h

@ -11,6 +11,16 @@
#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 _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_activate(u8_t layer);
bool zmk_keymap_layer_deactivate(u8_t layer); bool zmk_keymap_layer_deactivate(u8_t layer);

2
src/keymap.c

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

Loading…
Cancel
Save