From 04fe57d3a30c0bb37022e8b019293dbb1fc56197 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 12 May 2020 14:15:33 -0400 Subject: [PATCH] Some refactoring to prep for BLE support. --- CMakeLists.txt | 1 + src/endpoints.c | 17 +++++++++++++++++ src/endpoints.h | 5 +++++ src/handlers.c | 11 ++--------- src/handlers.h | 8 ++------ src/keymap.h | 3 +-- src/keys.h | 11 +++++++++++ src/usb_hid.h | 6 ++++-- 8 files changed, 43 insertions(+), 19 deletions(-) create mode 100644 src/endpoints.c create mode 100644 src/endpoints.h create mode 100644 src/keys.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b09b3a6..12b44c14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ 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/usb_hid.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/src/endpoints.c b/src/endpoints.c new file mode 100644 index 00000000..c4cd4165 --- /dev/null +++ b/src/endpoints.c @@ -0,0 +1,17 @@ + +#include "endpoints.h" +#include "usb_hid.h" + +int zmk_endpoints_send_key_event(struct zmk_key_event key_event) +{ + if (key_event.pressed) + { + zmk_usb_hid_press_key(key_event.key); + } + else + { + zmk_usb_hid_release_key(key_event.key); + } + + return 0; +} \ No newline at end of file diff --git a/src/endpoints.h b/src/endpoints.h new file mode 100644 index 00000000..1a72c322 --- /dev/null +++ b/src/endpoints.h @@ -0,0 +1,5 @@ +#pragma once + +#include "keys.h" + +int zmk_endpoints_send_key_event(struct zmk_key_event key_event); \ No newline at end of file diff --git a/src/handlers.c b/src/handlers.c index 7c329c50..9383e758 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -1,7 +1,7 @@ #include "handlers.h" -#include "usb_hid.h" +#include "endpoints.h" __attribute__((weak)) bool zmk_handle_key_user(struct zmk_key_event *key_event) { @@ -15,12 +15,5 @@ void zmk_handle_key(struct zmk_key_event key_event) return; } - if (key_event.pressed) - { - zmk_usb_hid_press_key(key_event.key); - } - else - { - zmk_usb_hid_release_key(key_event.key); - } + zmk_endpoints_send_key_event(key_event); }; diff --git a/src/handlers.h b/src/handlers.h index 3a935721..382f3b84 100644 --- a/src/handlers.h +++ b/src/handlers.h @@ -1,12 +1,8 @@ #pragma once -#include "keymap.h" #include -struct zmk_key_event -{ - zmk_key key; - bool pressed; -}; +#include "keymap.h" +#include "keys.h" void zmk_handle_key(struct zmk_key_event key_event); diff --git a/src/keymap.h b/src/keymap.h index bb758d81..20bd4833 100644 --- a/src/keymap.h +++ b/src/keymap.h @@ -6,12 +6,11 @@ #include "dt-bindings/zmk/keys.h" #include "zmk.h" +#include "keys.h" #define ZMK_KEYMAP_NODE DT_CHOSEN(zmk_keymap) #define ZMK_KEYMAP_LAYERS_LEN DT_PROP_LEN(ZMK_KEYMAP_NODE, layers) -typedef u64_t zmk_key; - bool zmk_keymap_layer_activate(u8_t layer); bool zmk_keymap_layer_deactivate(u8_t layer); diff --git a/src/keys.h b/src/keys.h new file mode 100644 index 00000000..bfe8dd9a --- /dev/null +++ b/src/keys.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +typedef u64_t zmk_key; + +struct zmk_key_event +{ + zmk_key key; + bool pressed; +}; \ No newline at end of file diff --git a/src/usb_hid.h b/src/usb_hid.h index 5bcd8bf8..1f331cde 100644 --- a/src/usb_hid.h +++ b/src/usb_hid.h @@ -4,11 +4,13 @@ #include #include +#include "keys.h" + int zmk_usb_hid_init(); // TODO: Modifiers! -int zmk_usb_hid_press_key(enum hid_kbd_code code); -int zmk_usb_hid_release_key(enum hid_kbd_code code); +int zmk_usb_hid_press_key(zmk_key key); +int zmk_usb_hid_release_key(zmk_key key); #endif