Refactor to using .keymap files
* Still just devicetree keymaps. * Filename can now use `<board>.keymap` or `<shield>.keymap` convention, including overrides for revisions, etc.
This commit is contained in:
parent
9233ab60cd
commit
f83ec5ce2b
16 changed files with 25 additions and 212 deletions
|
@ -18,10 +18,6 @@ include(cmake/zmk_config.cmake)
|
||||||
find_package(Zephyr REQUIRED HINTS ../zephyr)
|
find_package(Zephyr REQUIRED HINTS ../zephyr)
|
||||||
project(zmk)
|
project(zmk)
|
||||||
|
|
||||||
if(EXISTS ${KEYMAP_DIR}/keymap.c)
|
|
||||||
target_sources(app PRIVATE ${KEYMAP_DIR}/keymap.c)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
zephyr_linker_sources(RODATA include/linker/zmk-events.ld)
|
zephyr_linker_sources(RODATA include/linker/zmk-events.ld)
|
||||||
|
|
||||||
# Add your source file to the "app" target. This must come after
|
# Add your source file to the "app" target. This must come after
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
|
|
||||||
if SHIELD_PETEJOHANSON_HANDWIRE
|
|
||||||
|
|
||||||
config ZMK_KEYBOARD_NAME
|
|
||||||
default "Pete's Handwire Breadboard"
|
|
||||||
|
|
||||||
config ZMK_BLE
|
|
||||||
default y
|
|
||||||
|
|
||||||
config ZMK_ACTION_MOD_TAP
|
|
||||||
default y
|
|
||||||
|
|
||||||
endif
|
|
|
@ -1,5 +0,0 @@
|
||||||
# Copyright (c) 2019 Linaro Limited
|
|
||||||
# SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
config SHIELD_PETEJOHANSON_HANDWIRE
|
|
||||||
def_bool $(shields_list_contains,petejohanson_handwire)
|
|
|
@ -1,40 +0,0 @@
|
||||||
#include <dt-bindings/zmk/keys.h>
|
|
||||||
#include <behaviors.dtsi>
|
|
||||||
|
|
||||||
/ {
|
|
||||||
chosen {
|
|
||||||
zmk,keymap = &keymap0;
|
|
||||||
};
|
|
||||||
|
|
||||||
keymap0: keymap {
|
|
||||||
compatible = "zmk,keymap";
|
|
||||||
label ="Default keymap";
|
|
||||||
layers = <&default &lower &raise>;
|
|
||||||
};
|
|
||||||
|
|
||||||
layers {
|
|
||||||
compatible = "zmk,layers";
|
|
||||||
|
|
||||||
default: layer_0 {
|
|
||||||
label = "DEFAULT";
|
|
||||||
bindings = <
|
|
||||||
&cp M_NEXT &mt MOD_LSFT B &trans &trans
|
|
||||||
&mo 1 &mo 2 &trans &trans>;
|
|
||||||
};
|
|
||||||
|
|
||||||
lower: layer_1 {
|
|
||||||
label = "LOWER";
|
|
||||||
|
|
||||||
bindings = <
|
|
||||||
&cp M_PLAY &cp M_NEXT &trans &trans
|
|
||||||
&trans &trans &trans &trans>;
|
|
||||||
};
|
|
||||||
|
|
||||||
raise: layer_2 {
|
|
||||||
label = "RAISE";
|
|
||||||
bindings = <
|
|
||||||
&kp C &kp D &trans &trans
|
|
||||||
&trans &kp E &trans &trans>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -1 +0,0 @@
|
||||||
CONFIG_ZMK_KSCAN_COMPOSITE_DRIVER=y
|
|
|
@ -1,44 +0,0 @@
|
||||||
|
|
||||||
/ {
|
|
||||||
chosen {
|
|
||||||
zmk,kscan = &kscan0;
|
|
||||||
};
|
|
||||||
|
|
||||||
kscan0: kscan_0 {
|
|
||||||
compatible = "zmk,kscan-composite";
|
|
||||||
label = "KSCAN_COMP";
|
|
||||||
rows = <2>;
|
|
||||||
columns = <4>;
|
|
||||||
|
|
||||||
left {
|
|
||||||
kscan = <&left_hand>;
|
|
||||||
};
|
|
||||||
|
|
||||||
right {
|
|
||||||
kscan = <&right_hand>;
|
|
||||||
column-offset = <2>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
left_hand: kscan_1 {
|
|
||||||
compatible = "zmk,kscan-gpio-matrix";
|
|
||||||
label = "KSCAN_LEFT";
|
|
||||||
|
|
||||||
diode-direction = "row2col";
|
|
||||||
row-gpios = <&arduino_header 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
|
|
||||||
<&arduino_header 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
|
|
||||||
col-gpios = <&arduino_header 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
|
|
||||||
<&arduino_header 11 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
|
|
||||||
};
|
|
||||||
|
|
||||||
right_hand: kscan_2 {
|
|
||||||
compatible = "zmk,kscan-gpio-matrix";
|
|
||||||
label = "KSCAN_RIGHT";
|
|
||||||
|
|
||||||
diode-direction = "row2col";
|
|
||||||
row-gpios = <&arduino_header 12 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
|
|
||||||
<&arduino_header 13 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
|
|
||||||
col-gpios = <&arduino_header 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
|
|
||||||
<&arduino_header 15 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -1,13 +0,0 @@
|
||||||
|
|
||||||
if SHIELD_PETEJOHANSON_PRO_MICRO_HANDWIRE
|
|
||||||
|
|
||||||
config ZMK_KEYBOARD_NAME
|
|
||||||
default "Pete's ProMicro Compat Handwire"
|
|
||||||
|
|
||||||
config ZMK_USB
|
|
||||||
default y
|
|
||||||
|
|
||||||
config ZMK_ACTION_MOD_TAP
|
|
||||||
default y
|
|
||||||
|
|
||||||
endif
|
|
|
@ -1,5 +0,0 @@
|
||||||
# Copyright (c) 2020 Pete Johanson
|
|
||||||
# SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
config SHIELD_PETEJOHANSON_PRO_MICRO_HANDWIRE
|
|
||||||
def_bool $(shields_list_contains,petejohanson_pro_micro_handwire)
|
|
|
@ -1,41 +0,0 @@
|
||||||
#include <behaviors.dtsi>
|
|
||||||
#include <dt-bindings/zmk/keys.h>
|
|
||||||
|
|
||||||
/ {
|
|
||||||
chosen {
|
|
||||||
zmk,keymap = &keymap0;
|
|
||||||
};
|
|
||||||
keymap0: keymap {
|
|
||||||
compatible = "zmk,keymap";
|
|
||||||
label ="Default keymap";
|
|
||||||
layers = <&default &lower &raise>;
|
|
||||||
};
|
|
||||||
|
|
||||||
layers {
|
|
||||||
compatible = "zmk,layers";
|
|
||||||
|
|
||||||
default: layer_0 {
|
|
||||||
label = "DEFAULT";
|
|
||||||
|
|
||||||
bindings = <
|
|
||||||
&mo 1 &kp A
|
|
||||||
&mo 2 &kp C>;
|
|
||||||
};
|
|
||||||
|
|
||||||
lower: layer_1 {
|
|
||||||
label = "LOWER";
|
|
||||||
|
|
||||||
bindings = <
|
|
||||||
&trans &kp D
|
|
||||||
&trans &kp E>;
|
|
||||||
};
|
|
||||||
|
|
||||||
raise: layer_2 {
|
|
||||||
label = "RAISE";
|
|
||||||
|
|
||||||
bindings = <
|
|
||||||
&trans &kp I
|
|
||||||
&trans &kp H>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -1,17 +0,0 @@
|
||||||
|
|
||||||
/ {
|
|
||||||
chosen {
|
|
||||||
zmk,kscan = &kscan0;
|
|
||||||
};
|
|
||||||
|
|
||||||
kscan0: kscan {
|
|
||||||
compatible = "zmk,kscan-gpio-matrix";
|
|
||||||
label = "KSCAN";
|
|
||||||
|
|
||||||
diode-direction = "row2col";
|
|
||||||
row-gpios = <&pro_micro_d 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
|
|
||||||
<&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
|
|
||||||
col-gpios = <&pro_micro_d 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
|
|
||||||
<&pro_micro_d 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -62,11 +62,9 @@ foreach(root ${BOARD_ROOT})
|
||||||
NAMES ${BOARD}_defconfig
|
NAMES ${BOARD}_defconfig
|
||||||
PATHS ${root}/boards/*/*
|
PATHS ${root}/boards/*/*
|
||||||
NO_DEFAULT_PATH
|
NO_DEFAULT_PATH
|
||||||
)
|
)
|
||||||
if(BOARD_DIR)
|
if(BOARD_DIR)
|
||||||
if (EXISTS "${BOARD_DIR}/keymap")
|
list(APPEND KEYMAP_DIRS ${BOARD_DIR})
|
||||||
list(APPEND KEYMAP_DIRS ${BOARD_DIR}/keymap)
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(DEFINED SHIELD)
|
if(DEFINED SHIELD)
|
||||||
|
@ -77,37 +75,16 @@ foreach(root ${BOARD_ROOT})
|
||||||
)
|
)
|
||||||
foreach(shield_path ${shields_refs_list})
|
foreach(shield_path ${shields_refs_list})
|
||||||
get_filename_component(SHIELD_DIR ${shield_path} NAME)
|
get_filename_component(SHIELD_DIR ${shield_path} NAME)
|
||||||
if (EXISTS "${shield_path}/keymap")
|
list(APPEND KEYMAP_DIRS ${shield_path})
|
||||||
list(APPEND KEYMAP_DIRS ${shield_path}/keymap)
|
|
||||||
endif()
|
|
||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
find_path(BASE_KEYMAPS_DIR
|
|
||||||
NAMES ${KEYMAP}/keymap.overlay
|
|
||||||
PATHS ${KEYMAP_DIRS}
|
|
||||||
NO_DEFAULT_PATH
|
|
||||||
)
|
|
||||||
|
|
||||||
if (BASE_KEYMAPS_DIR)
|
|
||||||
set(KEYMAP_DIR "${BASE_KEYMAPS_DIR}/${KEYMAP}" CACHE STRING "Selected keymap directory")
|
|
||||||
message(STATUS "Keyboard Base Keymap: ${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()
|
|
||||||
list(APPEND ZMK_DTC_FILES "${KEYMAP_DIR}keymap.overlay")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (ZMK_CONFIG)
|
if (ZMK_CONFIG)
|
||||||
if (EXISTS ${ZMK_CONFIG})
|
if (EXISTS ${ZMK_CONFIG})
|
||||||
message(STATUS "ZMK Config directory: ${ZMK_CONFIG}")
|
message(STATUS "ZMK Config directory: ${ZMK_CONFIG}")
|
||||||
list(APPEND DTS_ROOT ${ZMK_CONFIG})
|
list(APPEND DTS_ROOT ${ZMK_CONFIG})
|
||||||
if (EXISTS "${ZMK_CONFIG}/include")
|
list(PREPEND KEYMAP_DIRS "${ZMK_CONFIG}")
|
||||||
include_directories("${ZMK_CONFIG}/include")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (SHIELD)
|
if (SHIELD)
|
||||||
message(STATUS "Board: ${BOARD}, ${BOARD_DIR}, ${SHIELD}, ${SHIELD_DIR}")
|
message(STATUS "Board: ${BOARD}, ${BOARD_DIR}, ${SHIELD}, ${SHIELD_DIR}")
|
||||||
|
@ -137,7 +114,7 @@ if (ZMK_CONFIG)
|
||||||
|
|
||||||
foreach(conf ${config_candidates})
|
foreach(conf ${config_candidates})
|
||||||
if (EXISTS "${conf}")
|
if (EXISTS "${conf}")
|
||||||
message(STATUS "ZMK Config Kconfig: ${overlay}")
|
message(STATUS "ZMK Config Kconfig: ${conf}")
|
||||||
set(CONF_FILE "${conf}")
|
set(CONF_FILE "${conf}")
|
||||||
break()
|
break()
|
||||||
endif()
|
endif()
|
||||||
|
@ -147,6 +124,25 @@ if (ZMK_CONFIG)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
if(NOT KEYMAP_FILE)
|
||||||
|
foreach(keymap_dir ${KEYMAP_DIRS})
|
||||||
|
foreach(keymap_prefix ${SHIELD} ${SHIELD_DIR} ${BOARD} ${BOARD_DIR})
|
||||||
|
if (EXISTS ${keymap_dir}/${keymap_prefix}.keymap)
|
||||||
|
set(KEYMAP_FILE "${keymap_dir}/${keymap_prefix}.keymap" CACHE STRING "Selected keymap file")
|
||||||
|
message(STATUS "Using keymap file: ${KEYMAP_FILE}")
|
||||||
|
break()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT KEYMAP_FILE)
|
||||||
|
message(FATAL_ERROR "Failed to locate keymap file!")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
list(APPEND ZMK_DTC_FILES ${KEYMAP_FILE})
|
||||||
|
|
||||||
if (ZMK_DTC_FILES)
|
if (ZMK_DTC_FILES)
|
||||||
string(REPLACE ";" " " DTC_OVERLAY_FILE "${ZMK_DTC_FILES}")
|
string(REPLACE ";" " " DTC_OVERLAY_FILE "${ZMK_DTC_FILES}")
|
||||||
endif()
|
endif()
|
||||||
|
|
Loading…
Reference in a new issue