summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Johanson <peter@peterjohanson.com>2020-06-17 09:40:28 -0400
committerGitHub <noreply@github.com>2020-06-17 09:40:28 -0400
commit6e111f4676de8260023942a855c079d463d52bde (patch)
treedb4f298be18a6a6295086bb3915499f90bcc26a9
parentc9b22e55fdf2b25b1b4c15e613c193eec917fb42 (diff)
parent583839afce4b8117e3ae7bd644954b03d0ed3ddf (diff)
Merge pull request #29 from petejohanson/build/zmk-config-initial-work
Initial refactor to have a shield/board have one default keymap.
-rw-r--r--app/CMakeLists.txt4
-rw-r--r--app/boards/shields/petejohanson_handwire/keymap/include/keymap.h (renamed from app/boards/shields/petejohanson_handwire/keymaps/default/include/keymap.h)0
-rw-r--r--app/boards/shields/petejohanson_handwire/keymap/keymap.c (renamed from app/boards/shields/petejohanson_handwire/keymaps/default/keymap.c)0
-rw-r--r--app/boards/shields/petejohanson_handwire/keymap/keymap.overlay (renamed from app/boards/shields/petejohanson_handwire/keymaps/default/keymap.overlay)0
-rw-r--r--app/boards/shields/petejohanson_proton_handwire/keymap/include/keymap.h9
-rw-r--r--app/boards/shields/petejohanson_proton_handwire/keymap/keymap.c (renamed from app/boards/shields/petejohanson_proton_handwire/keymaps/default/keymap.c)8
-rw-r--r--app/boards/shields/petejohanson_proton_handwire/keymap/keymap.overlay (renamed from app/boards/shields/petejohanson_proton_handwire/keymaps/default/keymap.overlay)0
-rw-r--r--app/boards/shields/petejohanson_proton_handwire/keymaps/default/include/keymap.h5
-rw-r--r--app/cmake/keymap.cmake94
-rw-r--r--app/cmake/zmk_config.cmake132
10 files changed, 147 insertions, 105 deletions
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt
index c5868ee..ed2c28c 100644
--- a/app/CMakeLists.txt
+++ b/app/CMakeLists.txt
@@ -12,9 +12,9 @@ list(APPEND ZEPHYR_EXTRA_MODULES
)
list(APPEND SYSCALL_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/drivers/zephyr)
-include(cmake/keymap.cmake)
+include(cmake/zmk_config.cmake)
-find_package(Zephyr)
+find_package(Zephyr REQUIRED HINTS ../zephyr)
project(zmk)
diff --git a/app/boards/shields/petejohanson_handwire/keymaps/default/include/keymap.h b/app/boards/shields/petejohanson_handwire/keymap/include/keymap.h
index 01cd9e5..01cd9e5 100644
--- a/app/boards/shields/petejohanson_handwire/keymaps/default/include/keymap.h
+++ b/app/boards/shields/petejohanson_handwire/keymap/include/keymap.h
diff --git a/app/boards/shields/petejohanson_handwire/keymaps/default/keymap.c b/app/boards/shields/petejohanson_handwire/keymap/keymap.c
index 067cd08..067cd08 100644
--- a/app/boards/shields/petejohanson_handwire/keymaps/default/keymap.c
+++ b/app/boards/shields/petejohanson_handwire/keymap/keymap.c
diff --git a/app/boards/shields/petejohanson_handwire/keymaps/default/keymap.overlay b/app/boards/shields/petejohanson_handwire/keymap/keymap.overlay
index d87363f..d87363f 100644
--- a/app/boards/shields/petejohanson_handwire/keymaps/default/keymap.overlay
+++ b/app/boards/shields/petejohanson_handwire/keymap/keymap.overlay
diff --git a/app/boards/shields/petejohanson_proton_handwire/keymap/include/keymap.h b/app/boards/shields/petejohanson_proton_handwire/keymap/include/keymap.h
new file mode 100644
index 0000000..0fd2f9f
--- /dev/null
+++ b/app/boards/shields/petejohanson_proton_handwire/keymap/include/keymap.h
@@ -0,0 +1,9 @@
+
+#include <dt-bindings/zmk/keys.h>
+
+#define DEFAULT 0
+#define RAISE 1
+#define LOWER 2
+
+#define CC_RAIS ZC_CSTM(RAISE)
+#define CC_LOWR ZC_CSTM(LOWER)
diff --git a/app/boards/shields/petejohanson_proton_handwire/keymaps/default/keymap.c b/app/boards/shields/petejohanson_proton_handwire/keymap/keymap.c
index 067cd08..bde15ac 100644
--- a/app/boards/shields/petejohanson_proton_handwire/keymaps/default/keymap.c
+++ b/app/boards/shields/petejohanson_proton_handwire/keymap/keymap.c
@@ -10,22 +10,22 @@ bool zmk_handle_key_user(struct zmk_key_event *key_event)
case CC_LOWR:
if (key_event->pressed)
{
- zmk_keymap_layer_activate(1);
+ zmk_keymap_layer_activate(LOWER);
}
else
{
- zmk_keymap_layer_deactivate(1);
+ zmk_keymap_layer_deactivate(LOWER);
}
return false;
case CC_RAIS:
if (key_event->pressed)
{
- zmk_keymap_layer_activate(2);
+ zmk_keymap_layer_activate(RAISE);
}
else
{
- zmk_keymap_layer_deactivate(2);
+ zmk_keymap_layer_deactivate(RAISE);
}
return false;
}
diff --git a/app/boards/shields/petejohanson_proton_handwire/keymaps/default/keymap.overlay b/app/boards/shields/petejohanson_proton_handwire/keymap/keymap.overlay
index c1bd542..c1bd542 100644
--- a/app/boards/shields/petejohanson_proton_handwire/keymaps/default/keymap.overlay
+++ b/app/boards/shields/petejohanson_proton_handwire/keymap/keymap.overlay
diff --git a/app/boards/shields/petejohanson_proton_handwire/keymaps/default/include/keymap.h b/app/boards/shields/petejohanson_proton_handwire/keymaps/default/include/keymap.h
deleted file mode 100644
index 01cd9e5..0000000
--- a/app/boards/shields/petejohanson_proton_handwire/keymaps/default/include/keymap.h
+++ /dev/null
@@ -1,5 +0,0 @@
-
-#include <dt-bindings/zmk/keys.h>
-
-#define CC_RAIS ZC_CSTM(1)
-#define CC_LOWR ZC_CSTM(2) \ No newline at end of file
diff --git a/app/cmake/keymap.cmake b/app/cmake/keymap.cmake
deleted file mode 100644
index 2d3c629..0000000
--- a/app/cmake/keymap.cmake
+++ /dev/null
@@ -1,94 +0,0 @@
-
-get_property(cached_keymap_value CACHE KEYMAP PROPERTY VALUE)
-
-# There are actually 4 sources, the three user input sources, and the
-# previously used value (CACHED_KEYMAP). The previously used value has
-# precedence, and if we detect that the user is trying to change the
-# value we give him a warning about needing to clean the build
-# directory to be able to change keymaps.
-
-set(keymap_cli_argument ${cached_keymap_value}) # Either new or old
-if(keymap_cli_argument STREQUAL CACHED_KEYMAP)
- # We already have a CACHED_KEYMAP so there is no new input on the CLI
- unset(keymap_cli_argument)
-endif()
-
-set(keymap_app_cmake_lists ${KEYMAP})
-if(cached_keymap_value STREQUAL KEYMAP)
- # The app build scripts did not set a default, The KEYMAP we are
- # reading is the cached value from the CLI
- unset(keymap_app_cmake_lists)
-endif()
-
-if(CACHED_KEYMAP)
- # Warn the user if it looks like he is trying to change the keymap
- # without cleaning first
- if(keymap_cli_argument)
- if(NOT (CACHED_KEYMAP STREQUAL keymap_cli_argument))
- message(WARNING "The build directory must be cleaned pristinely when changing keymaps")
- # TODO: Support changing keymaps without requiring a clean build
- endif()
- endif()
-
- set(KEYMAP ${CACHED_KEYMAP})
-elseif(keymap_cli_argument)
- set(KEYMAP ${keymap_cli_argument})
-
-elseif(DEFINED ENV{KEYMAP})
- set(KEYMAP $ENV{KEYMAP})
-
-elseif(keymap_app_cmake_lists)
- set(KEYMAP ${keymap_app_cmake_lists})
-
-else()
- set(KEYMAP default)
- message(STATUS "KEYMAP defaulted to 'default'")
-endif()
-
-message(STATUS "Keymap: ${KEYMAP}")
-
-# Store the selected keymap in the cache
-set(CACHED_KEYMAP ${KEYMAP} CACHE STRING "Selected keymap")
-
-set(ZMK_APP_DIR ${CMAKE_CURRENT_SOURCE_DIR})
-
-list(APPEND KEYMAP_DIRS ${ZMK_APP_DIR}/keymaps)
-
-foreach(root ${BOARD_ROOT})
- find_path(BOARD_DIR
- NAMES ${BOARD}_defconfig
- PATHS ${root}/boards/*/*
- NO_DEFAULT_PATH
- )
- if(BOARD_DIR)
- list(APPEND KEYMAP_DIRS ${BOARD_DIR}/keymaps)
- endif()
-
- if(DEFINED SHIELD)
- find_path(shields_refs_list
- NAMES ${SHIELD}.overlay
- PATHS ${root}/boards/shields/*
- NO_DEFAULT_PATH
- )
- foreach(shield_path ${shields_refs_list})
- list(APPEND KEYMAP_DIRS ${shield_path}/keymaps)
- endforeach()
- endif()
-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 "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()
diff --git a/app/cmake/zmk_config.cmake b/app/cmake/zmk_config.cmake
new file mode 100644
index 0000000..89c141a
--- /dev/null
+++ b/app/cmake/zmk_config.cmake
@@ -0,0 +1,132 @@
+# TODO: Check for env or command line "ZMK_CONFIG" setting.
+# * That directory should load
+# * defconfigs,
+# * .conf file,
+# * single overlay,
+# * or per board/shield.
+
+get_property(cached_user_config_value CACHE ZMK_CONFIG PROPERTY VALUE)
+
+set(user_config_cli_argument ${cached_user_config_value}) # Either new or old
+if(user_config_cli_argument STREQUAL CACHED_ZMK_CONFIG)
+ # We already have a CACHED_ZMK_CONFIG so there is no new input on the CLI
+ unset(user_config_cli_argument)
+endif()
+
+set(user_config_app_cmake_lists ${ZMK_CONFIG})
+if(cached_user_config_value STREQUAL ZMK_CONFIG)
+ # The app build scripts did not set a default, The ZMK_CONFIG we are
+ # reading is the cached value from the CLI
+ unset(user_config_app_cmake_lists)
+endif()
+
+if(CACHED_ZMK_CONFIG)
+ # Warn the user if it looks like he is trying to change the user_config
+ # without cleaning first
+ if(user_config_cli_argument)
+ if(NOT (CACHED_ZMK_CONFIG STREQUAL user_config_cli_argument))
+ message(WARNING "The build directory must be cleaned pristinely when changing user ZMK config")
+ endif()
+ endif()
+
+ set(ZMK_CONFIG ${CACHED_ZMK_CONFIG})
+elseif(user_config_cli_argument)
+ set(ZMK_CONFIG ${user_config_cli_argument})
+
+elseif(DEFINED ENV{ZMK_CONFIG})
+ set(ZMK_CONFIG $ENV{ZMK_CONFIG})
+
+elseif(user_config_app_cmake_lists)
+ set(ZMK_CONFIG ${user_config_app_cmake_lists})
+endif()
+
+# Store the selected user_config in the cache
+set(CACHED_ZMK_CONFIG ${ZMK_CONFIG} CACHE STRING "Selected user ZMK config")
+
+foreach(root ${BOARD_ROOT})
+ find_path(BOARD_DIR
+ NAMES ${BOARD}_defconfig
+ PATHS ${root}/boards/*/*
+ NO_DEFAULT_PATH
+ )
+ if(BOARD_DIR)
+ if (EXISTS "${BOARD_DIR}/keymap")
+ list(APPEND KEYMAP_DIRS ${BOARD_DIR}/keymap)
+ endif()
+ endif()
+
+ if(DEFINED SHIELD)
+ find_path(shields_refs_list
+ NAMES ${SHIELD}.overlay
+ PATHS ${root}/boards/shields/*
+ NO_DEFAULT_PATH
+ )
+ foreach(shield_path ${shields_refs_list})
+ if (EXISTS "${shield_path}/keymap")
+ list(APPEND KEYMAP_DIRS ${shield_path}/keymap)
+ endif()
+ endforeach()
+ endif()
+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 (EXISTS "${ZMK_CONFIG}")
+ message(STATUS "ZMK Config directory: ${ZMK_CONFIG}")
+ list(APPEND DTS_ROOT ${ZMK_CONFIG})
+ if (EXISTS "${ZMK_CONFIG}/include")
+ include_directories("${ZMK_CONFIG}/include")
+ endif()
+
+ if (SHIELD)
+ list(APPEND overlay_candidates "${ZMK_CONFIG}/${SHIELD}_${BOARD}.overlay")
+ list(APPEND overlay_candidates "${ZMK_CONFIG}/${SHIELD}.overlay")
+ list(APPEND config_candidates "${ZMK_CONFIG}/${SHIELD}_${BOARD}.conf")
+ list(APPEND config_candidates "${ZMK_CONFIG}/${SHIELD}.conf")
+ endif()
+
+ # TODO: Board revisions?
+ list(APPEND overlay_candidates "${ZMK_CONFIG}/${BOARD}.overlay")
+ list(APPEND overlay_candidates "${ZMK_CONFIG}/default.overlay")
+ list(APPEND config_candidates "${ZMK_CONFIG}/${BOARD}.conf")
+ list(APPEND config_candidates "${ZMK_CONFIG}/default.conf")
+
+ foreach(overlay ${overlay_candidates})
+ if (EXISTS "${overlay}")
+ message(STATUS "ZMK Config devicetree overlay: ${overlay}")
+ list(APPEND ZMK_DTC_FILES "${overlay}")
+ break()
+ endif()
+ endforeach()
+
+ foreach(conf ${config_candidates})
+ if (EXISTS "${conf}")
+ message(STATUS "ZMK Config Kconfig: ${overlay}")
+ set(CONF_FILE "${conf}")
+ break()
+ endif()
+ endforeach()
+ else()
+ message(WARNING "Unable to locate ZMK config at: ${ZMK_CONFIG}")
+ endif()
+endif()
+
+if (ZMK_DTC_FILES)
+ string(REPLACE ";" " " DTC_OVERLAY_FILE "${ZMK_DTC_FILES}")
+endif()