Browse Source

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.
xmkb
Pete Johanson 5 years ago
parent
commit
c1905745b3
  1. 28
      .vscode/tasks.json
  2. 10
      CMakeLists.txt
  3. 8
      Kconfig
  4. 7
      boards/shields/petejohanson_handwire/keymaps/default/keymap.c
  5. 7
      include/zmk/ble.h
  6. 4
      include/zmk/endpoints.h
  7. 4
      include/zmk/handlers.h
  8. 4
      include/zmk/hid.h
  9. 9
      include/zmk/hog.h
  10. 6
      include/zmk/keymap.h
  11. 0
      include/zmk/keys.h
  12. 0
      include/zmk/kscan.h
  13. 4
      include/zmk/matrix.h
  14. 4
      include/zmk/usb_hid.h
  15. 11
      prj.conf
  16. 2
      src/ble.c
  17. 5
      src/ble.h
  18. 15
      src/endpoints.c
  19. 9
      src/handlers.c
  20. 4
      src/hid.c
  21. 6
      src/hog.c
  22. 9
      src/hog.h
  23. 2
      src/keymap.c
  24. 5
      src/kscan.c
  25. 6
      src/main.c
  26. 4
      src/usb_hid.c

28
.vscode/tasks.json vendored

@ -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"
}
]
}

10
CMakeLists.txt

@ -9,15 +9,21 @@ include(cmake/keymap.cmake)
find_package(Zephyr) find_package(Zephyr)
project(zmk) 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 # Add your source file to the "app" target. This must come after
# find_package(Zephyr) which defines the target. # find_package(Zephyr) which defines the target.
target_include_directories(app PRIVATE include) target_include_directories(app PRIVATE include)
target_sources(app PRIVATE src/kscan.c) target_sources(app PRIVATE src/kscan.c)
target_sources(app PRIVATE src/keymap.c) target_sources(app PRIVATE src/keymap.c)
target_sources(app PRIVATE src/hid.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/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/endpoints.c)
target_sources(app PRIVATE src/main.c) target_sources(app PRIVATE src/main.c)
target_sources(app PRIVATE src/handlers.c) target_sources(app PRIVATE src/handlers.c)

8
Kconfig

@ -4,6 +4,14 @@ config ZMK_KSCAN_EVENT_QUEUE_SIZE
int "Size of the event queue for KSCAN events to buffer events" int "Size of the event queue for KSCAN events to buffer events"
default 4 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 = ZMK_KSCAN
module-str = zmk_kscan module-str = zmk_kscan

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

@ -0,0 +1,7 @@
#include <zmk/keys.h>
bool zmk_handle_key_user(struct zmk_key_event *key_event)
{
return true;
};

7
include/zmk/ble.h

@ -0,0 +1,7 @@
#pragma once
#include <zmk/keys.h>
int zmk_ble_init();
bool zmk_ble_handle_key_user(struct zmk_key_event *key_event);

4
src/endpoints.h → include/zmk/endpoints.h

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "keys.h" #include <zmk/keys.h>
int zmk_endpoints_init(); int zmk_endpoints_init();
int zmk_endpoints_send_key_event(struct zmk_key_event key_event); int zmk_endpoints_send_key_event(struct zmk_key_event key_event);

4
src/handlers.h → include/zmk/handlers.h

@ -2,7 +2,7 @@
#include <dt-bindings/zmk/keys.h> #include <dt-bindings/zmk/keys.h>
#include "keymap.h" #include <zmk/keymap.h>
#include "keys.h" #include <zmk/keys.h>
void zmk_handle_key(struct zmk_key_event key_event); void zmk_handle_key(struct zmk_key_event key_event);

4
src/hid.h → include/zmk/hid.h

@ -5,7 +5,7 @@
#include <dt-bindings/zmk/keys.h> #include <dt-bindings/zmk/keys.h>
#include "keys.h" #include <zmk/keys.h>
#define ZMK_HID_MAX_KEYCODE KC_APP #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_press_key(zmk_key key);
int zmk_hid_release_key(zmk_key key); int zmk_hid_release_key(zmk_key key);
struct zmk_hid_report *zmk_hid_get_report(); struct zmk_hid_report *zmk_hid_get_report();

9
include/zmk/hog.h

@ -0,0 +1,9 @@
#pragma once
#include <zmk/keys.h>
#include <zmk/hid.h>
int zmk_hog_init();
int zmk_hog_send_report(struct zmk_hid_report *report);

6
src/keymap.h → include/zmk/keymap.h

@ -3,10 +3,10 @@
#include <devicetree.h> #include <devicetree.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/class/usb_hid.h> #include <usb/class/usb_hid.h>
#include "dt-bindings/zmk/keys.h" #include <dt-bindings/zmk/keys.h>
#include "zmk.h" #include <zmk/matrix.h>
#include "keys.h" #include <zmk/keys.h>
#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)

0
src/keys.h → include/zmk/keys.h

0
src/kscan.h → include/zmk/kscan.h

4
src/zmk.h → include/zmk/matrix.h

@ -1,8 +1,6 @@
#ifndef ZMK_H #pragma once
#define ZMK_H
#define ZMK_MATRIX_NODE_ID DT_CHOSEN(zmk_kscan) #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_ROWS DT_PROP_LEN(ZMK_MATRIX_NODE_ID,row_gpios)
#define ZMK_MATRIX_COLS DT_PROP_LEN(ZMK_MATRIX_NODE_ID,col_gpios) #define ZMK_MATRIX_COLS DT_PROP_LEN(ZMK_MATRIX_NODE_ID,col_gpios)
#endif

4
src/usb_hid.h → include/zmk/usb_hid.h

@ -4,8 +4,8 @@
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/class/usb_hid.h> #include <usb/class/usb_hid.h>
#include "keys.h" #include <zmk/keys.h>
#include "hid.h" #include <zmk/hid.h>
int zmk_usb_hid_init(); int zmk_usb_hid_init();

11
prj.conf

@ -1,22 +1,14 @@
CONFIG_KSCAN=y CONFIG_KSCAN=y
CONFIG_KSCAN_GPIO=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=y
CONFIG_USB_DEVICE_STACK=y CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_HID=y CONFIG_USB_DEVICE_HID=y
CONFIG_USB_DEVICE_PRODUCT="ZMK Firmware" CONFIG_USB_DEVICE_PRODUCT="ZMK Firmware"
CONFIG_BT=y CONFIG_ZMK_BLE=y
CONFIG_BT_SMP=y
CONFIG_BT_SMP_SC_PAIR_ONLY=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_GATT_DIS=y
# HID GATT notifications sent this way are *not* picked up by Linux, and possibly others. # HID GATT notifications sent this way are *not* picked up by Linux, and possibly others.
CONFIG_BT_GATT_NOTIFY_MULTIPLE=n CONFIG_BT_GATT_NOTIFY_MULTIPLE=n
CONFIG_BT_GATT_BAS=y
CONFIG_BT_DEVICE_NAME="ZMK Keyboard" CONFIG_BT_DEVICE_NAME="ZMK Keyboard"
CONFIG_BT_DEVICE_APPEARANCE=961 CONFIG_BT_DEVICE_APPEARANCE=961
CONFIG_BT_FIXED_PASSKEY=y
# Incresed stack due to settings API usage # Incresed stack due to settings API usage
# CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 # CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
@ -27,4 +19,3 @@ CONFIG_BT_FIXED_PASSKEY=y
# CONFIG_FLASH_MAP=y # CONFIG_FLASH_MAP=y
# CONFIG_NVS=y # CONFIG_NVS=y
# CONFIG_SETTINGS=y # CONFIG_SETTINGS=y
# CONFIG_SETTINGS_NONE=n

2
src/ble.c

@ -8,7 +8,7 @@
#include <bluetooth/uuid.h> #include <bluetooth/uuid.h>
#include <bluetooth/gatt.h> #include <bluetooth/gatt.h>
#include "keys.h" #include <zmk/keys.h>
static struct bt_conn *auth_passkey_entry_conn; static struct bt_conn *auth_passkey_entry_conn;
static u8_t passkey_entries[6] = {0, 0, 0, 0, 0, 0}; static u8_t passkey_entries[6] = {0, 0, 0, 0, 0, 0};

5
src/ble.h

@ -1,5 +0,0 @@
#pragma once
int zmk_ble_init();
bool zmk_ble_handle_key_user(struct zmk_key_event *key_event);

15
src/endpoints.c

@ -1,8 +1,8 @@
#include "endpoints.h" #include <zmk/endpoints.h>
#include "hid.h" #include <zmk/hid.h>
#include "usb_hid.h" #include <zmk/usb_hid.h>
#include "hog.h" #include <zmk/hog.h>
int zmk_endpoints_init() int zmk_endpoints_init()
{ {
@ -15,6 +15,7 @@ int zmk_endpoints_init()
return err; return err;
} }
#ifdef CONFIG_ZMK_BLE
err = zmk_hog_init(); err = zmk_hog_init();
if (err) if (err)
{ {
@ -22,6 +23,8 @@ int zmk_endpoints_init()
return err; return err;
} }
#endif /* CONFIG_ZMK_BLE */
return 0; return 0;
} }
@ -46,12 +49,14 @@ int zmk_endpoints_send_key_event(struct zmk_key_event key_event)
// // LOG_DBG("USB Send Failed"); // // LOG_DBG("USB Send Failed");
// } // }
#ifdef CONFIG_ZMK_BLE
err = zmk_hog_send_report(report); err = zmk_hog_send_report(report);
if (err) if (err)
{ {
printk("FAILED TO SEND OVER HOG: %d\n", err); printk("FAILED TO SEND OVER HOG: %d\n", err);
// LOG_DBG("HID Over GATTP Send Failed"); // LOG_DBG("HID Over GATTP Send Failed");
} }
#endif /* CONFIG_ZMK_BLE */
return 0; return 0;
} }

9
src/handlers.c

@ -1,8 +1,7 @@
#include "handlers.h" #include <zmk/ble.h>
#include <zmk/handlers.h>
#include "ble.h" #include <zmk/endpoints.h>
#include "endpoints.h"
__attribute__((weak)) bool zmk_handle_key_user(struct zmk_key_event *key_event) __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; return;
} }
#ifdef CONFIG_ZMK_BLE
if (!zmk_ble_handle_key_user(&key_event)) if (!zmk_ble_handle_key_user(&key_event))
{ {
return; return;
} }
#endif /* CONFIG_ZMK_BLE */
zmk_endpoints_send_key_event(key_event); zmk_endpoints_send_key_event(key_event);
}; };

4
src/hid.c

@ -1,4 +1,4 @@
#include "hid.h" #include <zmk/hid.h>
static struct zmk_hid_report report = { static struct zmk_hid_report report = {
.modifiers = 0, .modifiers = 0,
@ -53,4 +53,4 @@ int zmk_hid_release_key(zmk_key code)
struct zmk_hid_report *zmk_hid_get_report() struct zmk_hid_report *zmk_hid_get_report()
{ {
return &report; return &report;
} }

6
src/hog.c

@ -3,9 +3,9 @@
#include <bluetooth/bluetooth.h> #include <bluetooth/bluetooth.h>
#include <bluetooth/gatt.h> #include <bluetooth/gatt.h>
#include "ble.h" #include <zmk/ble.h>
#include "hog.h" #include <zmk/hog.h>
#include "hid.h" #include <zmk/hid.h>
int zmk_hog_init() int zmk_hog_init()
{ {

9
src/hog.h

@ -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);

2
src/keymap.c

@ -1,5 +1,5 @@
#include "keymap.h" #include <zmk/keymap.h>
static u32_t zmk_keymap_layer_state = 0; static u32_t zmk_keymap_layer_state = 0;
static u8_t zmk_keymap_layer_default = 0; static u8_t zmk_keymap_layer_default = 0;

5
src/kscan.c

@ -11,9 +11,8 @@
LOG_MODULE_REGISTER(zmk_kscan, CONFIG_ZMK_KSCAN_LOG_LEVEL); LOG_MODULE_REGISTER(zmk_kscan, CONFIG_ZMK_KSCAN_LOG_LEVEL);
#include "keymap.h" #include <zmk/keymap.h>
#include "usb_hid.h" #include <zmk/handlers.h>
#include "handlers.h"
#define ZMK_KSCAN_EVENT_STATE_PRESSED 0 #define ZMK_KSCAN_EVENT_STATE_PRESSED 0
#define ZMK_KSCAN_EVENT_STATE_RELEASED 1 #define ZMK_KSCAN_EVENT_STATE_RELEASED 1

6
src/main.c

@ -8,9 +8,9 @@
#include <device.h> #include <device.h>
#include <devicetree.h> #include <devicetree.h>
#include "zmk.h" #include <zmk/matrix.h>
#include "kscan.h" #include <zmk/kscan.h>
#include "endpoints.h" #include <zmk/endpoints.h>
#define ZMK_KSCAN_DEV DT_LABEL(ZMK_MATRIX_NODE_ID) #define ZMK_KSCAN_DEV DT_LABEL(ZMK_MATRIX_NODE_ID)

4
src/usb_hid.c

@ -5,8 +5,8 @@
#include <usb/class/usb_hid.h> #include <usb/class/usb_hid.h>
#include <dt-bindings/zmk/keys.h> #include <dt-bindings/zmk/keys.h>
#include "hid.h" #include <zmk/hid.h>
#include "keymap.h" #include <zmk/keymap.h>
LOG_MODULE_REGISTER(zmk_usb_hid, CONFIG_ZMK_USB_HID_LOG_LEVEL); LOG_MODULE_REGISTER(zmk_usb_hid, CONFIG_ZMK_USB_HID_LOG_LEVEL);

Loading…
Cancel
Save