From c1905745b3578037d1791bd634a3d1607cafd525 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Mon, 18 May 2020 09:11:46 -0400 Subject: [PATCH] Refactor build/config/keymaps. * Move all headers to `include/zmk` directory. * Update includes to reference them properly. * Add `keymap.c` file from keymap, if found. * Toplevel CONFIG_ZMK_BLE aggregate config setting. --- .vscode/tasks.json | 28 +++++++++++++++++++ CMakeLists.txt | 10 +++++-- Kconfig | 8 ++++++ .../keymaps/default/keymap.c | 7 +++++ include/zmk/ble.h | 7 +++++ {src => include/zmk}/endpoints.h | 4 +-- {src => include/zmk}/handlers.h | 4 +-- {src => include/zmk}/hid.h | 4 +-- include/zmk/hog.h | 9 ++++++ {src => include/zmk}/keymap.h | 6 ++-- {src => include/zmk}/keys.h | 0 {src => include/zmk}/kscan.h | 0 src/zmk.h => include/zmk/matrix.h | 4 +-- {src => include/zmk}/usb_hid.h | 4 +-- prj.conf | 11 +------- src/ble.c | 2 +- src/ble.h | 5 ---- src/endpoints.c | 15 ++++++---- src/handlers.c | 9 +++--- src/hid.c | 4 +-- src/hog.c | 6 ++-- src/hog.h | 9 ------ src/keymap.c | 2 +- src/kscan.c | 5 ++-- src/main.c | 6 ++-- src/usb_hid.c | 4 +-- 26 files changed, 109 insertions(+), 64 deletions(-) create mode 100644 .vscode/tasks.json create mode 100644 boards/shields/petejohanson_handwire/keymaps/default/keymap.c create mode 100644 include/zmk/ble.h rename {src => include/zmk}/endpoints.h (81%) rename {src => include/zmk}/handlers.h (69%) rename {src => include/zmk}/hid.h (97%) create mode 100644 include/zmk/hog.h rename {src => include/zmk}/keymap.h (82%) rename {src => include/zmk}/keys.h (100%) rename {src => include/zmk}/kscan.h (100%) rename src/zmk.h => include/zmk/matrix.h (83%) rename {src => include/zmk}/usb_hid.h (82%) delete mode 100644 src/ble.h delete mode 100644 src/hog.h diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..0902d0ee --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Build", + "type": "shell", + "command": "west build", + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Flash", + "type": "shell", + "command": "west flash", + "group": "test" + }, + { + "label": "Debug", + "type": "shell", + "command": "west debug", + "group": "test" + } + ] +} diff --git a/CMakeLists.txt b/CMakeLists.txt index dc8ccdae..9348b9ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,15 +9,21 @@ include(cmake/keymap.cmake) find_package(Zephyr) project(zmk) +if(EXISTS ${KEYMAP_DIR}/${KEYMAP}/keymap.c) + message(STATUS "ADDING THE KEYMAP SOURCE") + target_sources(app PRIVATE ${KEYMAP_DIR}/${KEYMAP}/keymap.c) +endif() + + # Add your source file to the "app" target. This must come after # find_package(Zephyr) which defines the target. target_include_directories(app PRIVATE include) target_sources(app PRIVATE src/kscan.c) target_sources(app PRIVATE src/keymap.c) target_sources(app PRIVATE src/hid.c) -target_sources(app PRIVATE src/ble.c) +target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/ble.c) target_sources(app PRIVATE src/usb_hid.c) -target_sources(app PRIVATE src/hog.c) +target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/hog.c) target_sources(app PRIVATE src/endpoints.c) target_sources(app PRIVATE src/main.c) target_sources(app PRIVATE src/handlers.c) diff --git a/Kconfig b/Kconfig index d92a1a48..2ab2c6fd 100644 --- a/Kconfig +++ b/Kconfig @@ -4,6 +4,14 @@ config ZMK_KSCAN_EVENT_QUEUE_SIZE int "Size of the event queue for KSCAN events to buffer events" default 4 +config ZMK_BLE + bool "Enable low energy bluetooth support" + select BT + select BT_SMP + select BT_SMP_SC_PAIR_ONLY + select BT_PERIPHERAL + select BT_GATT_DIS + select BT_GATT_BAS module = ZMK_KSCAN module-str = zmk_kscan diff --git a/boards/shields/petejohanson_handwire/keymaps/default/keymap.c b/boards/shields/petejohanson_handwire/keymaps/default/keymap.c new file mode 100644 index 00000000..349d7557 --- /dev/null +++ b/boards/shields/petejohanson_handwire/keymaps/default/keymap.c @@ -0,0 +1,7 @@ + +#include + +bool zmk_handle_key_user(struct zmk_key_event *key_event) +{ + return true; +}; diff --git a/include/zmk/ble.h b/include/zmk/ble.h new file mode 100644 index 00000000..a77237d8 --- /dev/null +++ b/include/zmk/ble.h @@ -0,0 +1,7 @@ + +#pragma once + +#include + +int zmk_ble_init(); +bool zmk_ble_handle_key_user(struct zmk_key_event *key_event); diff --git a/src/endpoints.h b/include/zmk/endpoints.h similarity index 81% rename from src/endpoints.h rename to include/zmk/endpoints.h index cc200f19..42734aac 100644 --- a/src/endpoints.h +++ b/include/zmk/endpoints.h @@ -1,6 +1,6 @@ #pragma once -#include "keys.h" +#include int zmk_endpoints_init(); -int zmk_endpoints_send_key_event(struct zmk_key_event key_event); \ No newline at end of file +int zmk_endpoints_send_key_event(struct zmk_key_event key_event); diff --git a/src/handlers.h b/include/zmk/handlers.h similarity index 69% rename from src/handlers.h rename to include/zmk/handlers.h index 382f3b84..a10851f8 100644 --- a/src/handlers.h +++ b/include/zmk/handlers.h @@ -2,7 +2,7 @@ #include -#include "keymap.h" -#include "keys.h" +#include +#include void zmk_handle_key(struct zmk_key_event key_event); diff --git a/src/hid.h b/include/zmk/hid.h similarity index 97% rename from src/hid.h rename to include/zmk/hid.h index 0f34df23..9f0760ab 100644 --- a/src/hid.h +++ b/include/zmk/hid.h @@ -5,7 +5,7 @@ #include -#include "keys.h" +#include #define ZMK_HID_MAX_KEYCODE KC_APP @@ -104,4 +104,4 @@ struct zmk_hid_report int zmk_hid_press_key(zmk_key key); int zmk_hid_release_key(zmk_key key); -struct zmk_hid_report *zmk_hid_get_report(); \ No newline at end of file +struct zmk_hid_report *zmk_hid_get_report(); diff --git a/include/zmk/hog.h b/include/zmk/hog.h new file mode 100644 index 00000000..a48fa989 --- /dev/null +++ b/include/zmk/hog.h @@ -0,0 +1,9 @@ + +#pragma once + +#include +#include + +int zmk_hog_init(); + +int zmk_hog_send_report(struct zmk_hid_report *report); diff --git a/src/keymap.h b/include/zmk/keymap.h similarity index 82% rename from src/keymap.h rename to include/zmk/keymap.h index 20bd4833..9b58cc0f 100644 --- a/src/keymap.h +++ b/include/zmk/keymap.h @@ -3,10 +3,10 @@ #include #include #include -#include "dt-bindings/zmk/keys.h" +#include -#include "zmk.h" -#include "keys.h" +#include +#include #define ZMK_KEYMAP_NODE DT_CHOSEN(zmk_keymap) #define ZMK_KEYMAP_LAYERS_LEN DT_PROP_LEN(ZMK_KEYMAP_NODE, layers) diff --git a/src/keys.h b/include/zmk/keys.h similarity index 100% rename from src/keys.h rename to include/zmk/keys.h diff --git a/src/kscan.h b/include/zmk/kscan.h similarity index 100% rename from src/kscan.h rename to include/zmk/kscan.h diff --git a/src/zmk.h b/include/zmk/matrix.h similarity index 83% rename from src/zmk.h rename to include/zmk/matrix.h index 82ef3b6b..83a8e2df 100644 --- a/src/zmk.h +++ b/include/zmk/matrix.h @@ -1,8 +1,6 @@ -#ifndef ZMK_H -#define ZMK_H +#pragma once #define ZMK_MATRIX_NODE_ID DT_CHOSEN(zmk_kscan) #define ZMK_MATRIX_ROWS DT_PROP_LEN(ZMK_MATRIX_NODE_ID,row_gpios) #define ZMK_MATRIX_COLS DT_PROP_LEN(ZMK_MATRIX_NODE_ID,col_gpios) -#endif diff --git a/src/usb_hid.h b/include/zmk/usb_hid.h similarity index 82% rename from src/usb_hid.h rename to include/zmk/usb_hid.h index 4b55688e..893e7e48 100644 --- a/src/usb_hid.h +++ b/include/zmk/usb_hid.h @@ -4,8 +4,8 @@ #include #include -#include "keys.h" -#include "hid.h" +#include +#include int zmk_usb_hid_init(); diff --git a/prj.conf b/prj.conf index 949a8281..9250cce2 100644 --- a/prj.conf +++ b/prj.conf @@ -1,22 +1,14 @@ CONFIG_KSCAN=y CONFIG_KSCAN_GPIO=y -# CONFIG_ZMK_KSCAN_LOG_LEVEL_DBG=y -# CONFIG_ZMK_USB_HID_LOG_LEVEL_DBG=y CONFIG_USB=y CONFIG_USB_DEVICE_STACK=y CONFIG_USB_DEVICE_HID=y CONFIG_USB_DEVICE_PRODUCT="ZMK Firmware" -CONFIG_BT=y -CONFIG_BT_SMP=y -CONFIG_BT_SMP_SC_PAIR_ONLY=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_GATT_DIS=y +CONFIG_ZMK_BLE=y # HID GATT notifications sent this way are *not* picked up by Linux, and possibly others. CONFIG_BT_GATT_NOTIFY_MULTIPLE=n -CONFIG_BT_GATT_BAS=y CONFIG_BT_DEVICE_NAME="ZMK Keyboard" CONFIG_BT_DEVICE_APPEARANCE=961 -CONFIG_BT_FIXED_PASSKEY=y # Incresed stack due to settings API usage # CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 @@ -27,4 +19,3 @@ CONFIG_BT_FIXED_PASSKEY=y # CONFIG_FLASH_MAP=y # CONFIG_NVS=y # CONFIG_SETTINGS=y -# CONFIG_SETTINGS_NONE=n diff --git a/src/ble.c b/src/ble.c index 266185fe..18b4fe31 100644 --- a/src/ble.c +++ b/src/ble.c @@ -8,7 +8,7 @@ #include #include -#include "keys.h" +#include static struct bt_conn *auth_passkey_entry_conn; static u8_t passkey_entries[6] = {0, 0, 0, 0, 0, 0}; diff --git a/src/ble.h b/src/ble.h deleted file mode 100644 index 03b34fe9..00000000 --- a/src/ble.h +++ /dev/null @@ -1,5 +0,0 @@ - -#pragma once - -int zmk_ble_init(); -bool zmk_ble_handle_key_user(struct zmk_key_event *key_event); \ No newline at end of file diff --git a/src/endpoints.c b/src/endpoints.c index 1f78cb7b..6854370f 100644 --- a/src/endpoints.c +++ b/src/endpoints.c @@ -1,8 +1,8 @@ -#include "endpoints.h" -#include "hid.h" -#include "usb_hid.h" -#include "hog.h" +#include +#include +#include +#include int zmk_endpoints_init() { @@ -15,6 +15,7 @@ int zmk_endpoints_init() return err; } +#ifdef CONFIG_ZMK_BLE err = zmk_hog_init(); if (err) { @@ -22,6 +23,8 @@ int zmk_endpoints_init() return err; } +#endif /* CONFIG_ZMK_BLE */ + return 0; } @@ -46,12 +49,14 @@ int zmk_endpoints_send_key_event(struct zmk_key_event key_event) // // LOG_DBG("USB Send Failed"); // } +#ifdef CONFIG_ZMK_BLE err = zmk_hog_send_report(report); if (err) { printk("FAILED TO SEND OVER HOG: %d\n", err); // LOG_DBG("HID Over GATTP Send Failed"); } +#endif /* CONFIG_ZMK_BLE */ return 0; -} \ No newline at end of file +} diff --git a/src/handlers.c b/src/handlers.c index 0ab93f69..b73c92cd 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -1,8 +1,7 @@ -#include "handlers.h" - -#include "ble.h" -#include "endpoints.h" +#include +#include +#include __attribute__((weak)) bool zmk_handle_key_user(struct zmk_key_event *key_event) { @@ -16,10 +15,12 @@ void zmk_handle_key(struct zmk_key_event key_event) return; } +#ifdef CONFIG_ZMK_BLE if (!zmk_ble_handle_key_user(&key_event)) { return; } +#endif /* CONFIG_ZMK_BLE */ zmk_endpoints_send_key_event(key_event); }; diff --git a/src/hid.c b/src/hid.c index 8c42df58..faf3cfc5 100644 --- a/src/hid.c +++ b/src/hid.c @@ -1,4 +1,4 @@ -#include "hid.h" +#include static struct zmk_hid_report report = { .modifiers = 0, @@ -53,4 +53,4 @@ int zmk_hid_release_key(zmk_key code) struct zmk_hid_report *zmk_hid_get_report() { return &report; -} \ No newline at end of file +} diff --git a/src/hog.c b/src/hog.c index dcddba6a..67ccf5b6 100644 --- a/src/hog.c +++ b/src/hog.c @@ -3,9 +3,9 @@ #include #include -#include "ble.h" -#include "hog.h" -#include "hid.h" +#include +#include +#include int zmk_hog_init() { diff --git a/src/hog.h b/src/hog.h deleted file mode 100644 index a1e4142e..00000000 --- a/src/hog.h +++ /dev/null @@ -1,9 +0,0 @@ - -#pragma once - -#include "keys.h" -#include "hid.h" - -int zmk_hog_init(); - -int zmk_hog_send_report(struct zmk_hid_report *report); \ No newline at end of file diff --git a/src/keymap.c b/src/keymap.c index 1f55b1f5..b47809b7 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -1,5 +1,5 @@ -#include "keymap.h" +#include static u32_t zmk_keymap_layer_state = 0; static u8_t zmk_keymap_layer_default = 0; diff --git a/src/kscan.c b/src/kscan.c index 25bbbfa2..09ca3872 100644 --- a/src/kscan.c +++ b/src/kscan.c @@ -11,9 +11,8 @@ LOG_MODULE_REGISTER(zmk_kscan, CONFIG_ZMK_KSCAN_LOG_LEVEL); -#include "keymap.h" -#include "usb_hid.h" -#include "handlers.h" +#include +#include #define ZMK_KSCAN_EVENT_STATE_PRESSED 0 #define ZMK_KSCAN_EVENT_STATE_RELEASED 1 diff --git a/src/main.c b/src/main.c index 708f4ff4..00a1cd0d 100644 --- a/src/main.c +++ b/src/main.c @@ -8,9 +8,9 @@ #include #include -#include "zmk.h" -#include "kscan.h" -#include "endpoints.h" +#include +#include +#include #define ZMK_KSCAN_DEV DT_LABEL(ZMK_MATRIX_NODE_ID) diff --git a/src/usb_hid.c b/src/usb_hid.c index 80b21388..ee8ee130 100644 --- a/src/usb_hid.c +++ b/src/usb_hid.c @@ -5,8 +5,8 @@ #include #include -#include "hid.h" -#include "keymap.h" +#include +#include LOG_MODULE_REGISTER(zmk_usb_hid, CONFIG_ZMK_USB_HID_LOG_LEVEL);