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.
This commit is contained in:
Pete Johanson 2020-05-18 09:11:46 -04:00
parent b3babe2505
commit c1905745b3
26 changed files with 109 additions and 64 deletions

28
.vscode/tasks.json vendored Normal file
View File

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

View File

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

View File

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

View File

@ -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 Normal file
View File

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

View File

@ -1,6 +1,6 @@
#pragma once
#include "keys.h"
#include <zmk/keys.h>
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);

View File

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

View File

@ -5,7 +5,7 @@
#include <dt-bindings/zmk/keys.h>
#include "keys.h"
#include <zmk/keys.h>
#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();
struct zmk_hid_report *zmk_hid_get_report();

9
include/zmk/hog.h Normal file
View File

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

View File

@ -3,10 +3,10 @@
#include <devicetree.h>
#include <usb/usb_device.h>
#include <usb/class/usb_hid.h>
#include "dt-bindings/zmk/keys.h"
#include <dt-bindings/zmk/keys.h>
#include "zmk.h"
#include "keys.h"
#include <zmk/matrix.h>
#include <zmk/keys.h>
#define ZMK_KEYMAP_NODE DT_CHOSEN(zmk_keymap)
#define ZMK_KEYMAP_LAYERS_LEN DT_PROP_LEN(ZMK_KEYMAP_NODE, layers)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,8 +1,8 @@
#include "endpoints.h"
#include "hid.h"
#include "usb_hid.h"
#include "hog.h"
#include <zmk/endpoints.h>
#include <zmk/hid.h>
#include <zmk/usb_hid.h>
#include <zmk/hog.h>
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;
}
}

View File

@ -1,8 +1,7 @@
#include "handlers.h"
#include "ble.h"
#include "endpoints.h"
#include <zmk/ble.h>
#include <zmk/handlers.h>
#include <zmk/endpoints.h>
__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);
};

View File

@ -1,4 +1,4 @@
#include "hid.h"
#include <zmk/hid.h>
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;
}
}

View File

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

View File

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

View File

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

View File

@ -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 <zmk/keymap.h>
#include <zmk/handlers.h>
#define ZMK_KSCAN_EVENT_STATE_PRESSED 0
#define ZMK_KSCAN_EVENT_STATE_RELEASED 1

View File

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

View File

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