diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 9bfc8d6a..5be628b7 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -29,14 +29,13 @@ zephyr_linker_sources(RODATA include/linker/zmk-events.ld) target_include_directories(app PRIVATE include) target_sources(app PRIVATE src/kscan.c) target_sources(app PRIVATE src/matrix_transform.c) -target_sources(app PRIVATE src/events.c) target_sources(app PRIVATE src/keymap.c) +target_sources(app PRIVATE src/hid_listener.c) target_sources(app PRIVATE src/hid.c) target_sources(app PRIVATE src/event_manager.c) target_sources(app PRIVATE src/events/position_state_changed.c) target_sources(app PRIVATE src/events/keycode_state_changed.c) target_sources(app PRIVATE src/events/modifiers_state_changed.c) -target_sources(app PRIVATE src/behaviors/behavior_hid.c) target_sources(app PRIVATE src/behaviors/behavior_key_press.c) target_sources(app PRIVATE src/behaviors/behavior_reset.c) target_sources(app PRIVATE src/behaviors/behavior_mod_tap.c) diff --git a/app/dts/behaviors.dtsi b/app/dts/behaviors.dtsi index 7a4f8fbc..86cd7b72 100644 --- a/app/dts/behaviors.dtsi +++ b/app/dts/behaviors.dtsi @@ -2,5 +2,4 @@ #include #include #include -#include -#include \ No newline at end of file +#include \ No newline at end of file diff --git a/app/dts/behaviors/hid.dtsi b/app/dts/behaviors/hid.dtsi deleted file mode 100644 index 30ebb090..00000000 --- a/app/dts/behaviors/hid.dtsi +++ /dev/null @@ -1,9 +0,0 @@ -/ { - behaviors { - hid_behavior: behavior_hid { - compatible = "zmk,behavior-hid", "zmk,behavior-global"; - label = "HID"; - #binding-cells = <0>; - }; - }; -}; diff --git a/app/include/zmk/events.h b/app/include/zmk/events.h deleted file mode 100644 index 178686c4..00000000 --- a/app/include/zmk/events.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include - -int zmk_events_modifiers_pressed(zmk_mod_flags modifiers); -int zmk_events_modifiers_released(zmk_mod_flags modifiers); - -// TODO: Encoders? -// TODO: Sensors? \ No newline at end of file diff --git a/app/src/behaviors/behavior_mod_tap.c b/app/src/behaviors/behavior_mod_tap.c index 37461834..62604eba 100644 --- a/app/src/behaviors/behavior_mod_tap.c +++ b/app/src/behaviors/behavior_mod_tap.c @@ -13,7 +13,6 @@ #include #include #include -#include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); diff --git a/app/src/behaviors/behavior_momentary_layer.c b/app/src/behaviors/behavior_momentary_layer.c index 904051e4..8a8584a9 100644 --- a/app/src/behaviors/behavior_momentary_layer.c +++ b/app/src/behaviors/behavior_momentary_layer.c @@ -10,7 +10,6 @@ #include #include -#include #include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); diff --git a/app/src/events.c b/app/src/events.c deleted file mode 100644 index fabb93e1..00000000 --- a/app/src/events.c +++ /dev/null @@ -1,83 +0,0 @@ - -#include -#include -#include -#include -#include - -#define DT_DRV_COMPAT zmk_behavior_global -#define GLOBAL_BEHAVIOR_LEN DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) - -#define LABEL_ENTRY(i) DT_INST_LABEL(i), -static const char *global_behaviors[] = { - DT_INST_FOREACH_STATUS_OKAY(LABEL_ENTRY) -}; - -int zmk_events_position_pressed(u32_t position) -{ - for (int i = 0; i < GLOBAL_BEHAVIOR_LEN; i++) { - const char* label = global_behaviors[i]; - struct device *dev = device_get_binding(label); - behavior_position_pressed(dev, position); - } - return 0; -}; - -int zmk_events_position_released(u32_t position) -{ - for (int i = 0; i < GLOBAL_BEHAVIOR_LEN; i++) { - const char* label = global_behaviors[i]; - struct device *dev = device_get_binding(label); - behavior_position_released(dev, position); - } - return 0; -}; - -int zmk_events_keycode_pressed(u8_t usage_page, u32_t keycode) -{ - for (int i = 0; i < GLOBAL_BEHAVIOR_LEN; i++) { - const char* label = global_behaviors[i]; - struct device *dev = device_get_binding(label); - behavior_keycode_pressed(dev, usage_page, keycode); - } - return 0; -}; - -int zmk_events_keycode_released(u8_t usage_page, u32_t keycode) -{ - for (int i = 0; i < GLOBAL_BEHAVIOR_LEN; i++) { - const char* label = global_behaviors[i]; - struct device *dev = device_get_binding(label); - behavior_keycode_released(dev, usage_page, keycode); - } - return 0; -}; - -int zmk_events_modifiers_pressed(zmk_mod_flags modifiers) -{ - for (int i = 0; i < GLOBAL_BEHAVIOR_LEN; i++) { - const char* label = global_behaviors[i]; - struct device *dev = device_get_binding(label); - behavior_modifiers_pressed(dev, modifiers); - } - return 0; -}; - -int zmk_events_modifiers_released(zmk_mod_flags modifiers) -{ - for (int i = 0; i < GLOBAL_BEHAVIOR_LEN; i++) { - const char* label = global_behaviors[i]; - struct device *dev = device_get_binding(label); - behavior_modifiers_released(dev, modifiers); - } - return 0; -}; - -int zmk_events_consumer_key_pressed(u32_t usage) -{ - return 0; -}; -int zmk_events_consumer_key_released(u32_t usage) -{ - return 0; -}; diff --git a/app/src/behaviors/behavior_hid.c b/app/src/hid_listener.c similarity index 55% rename from app/src/behaviors/behavior_hid.c rename to app/src/hid_listener.c index 9e1fb6bf..69aa23e7 100644 --- a/app/src/behaviors/behavior_hid.c +++ b/app/src/hid_listener.c @@ -4,10 +4,6 @@ * SPDX-License-Identifier: MIT */ -#define DT_DRV_COMPAT zmk_behavior_hid - -#include -#include #include #include @@ -19,14 +15,11 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include #include -struct behavior_hid_config { }; -struct behavior_hid_data { }; - -static int behaviour_hid_keycode_pressed(u8_t usage_page, u32_t keycode) +static int hid_listener_keycode_pressed(u8_t usage_page, u32_t keycode) { int err; - LOG_DBG("keycode %d", keycode); + LOG_DBG("usage_page 0x%02X keycode 0x%02X", usage_page, keycode); switch (usage_page) { case USAGE_KEYPAD: @@ -48,10 +41,10 @@ static int behaviour_hid_keycode_pressed(u8_t usage_page, u32_t keycode) return zmk_endpoints_send_report(usage_page); } -static int behaviour_hid_keycode_released(u8_t usage_page, u32_t keycode) +static int hid_listener_keycode_released(u8_t usage_page, u32_t keycode) { int err; - LOG_DBG("keycode %d", keycode); + LOG_DBG("usage_page 0x%02X keycode 0x%02X", usage_page, keycode); switch (usage_page) { case USAGE_KEYPAD: @@ -72,7 +65,7 @@ static int behaviour_hid_keycode_released(u8_t usage_page, u32_t keycode) return zmk_endpoints_send_report(usage_page); } -static int behavior_hid_modifiers_pressed(zmk_mod_flags modifiers) +static int hid_listener_modifiers_pressed(zmk_mod_flags modifiers) { LOG_DBG("modifiers %d", modifiers); @@ -80,7 +73,7 @@ static int behavior_hid_modifiers_pressed(zmk_mod_flags modifiers) return zmk_endpoints_send_report(USAGE_KEYPAD); } -static int behavior_hid_modifiers_released(zmk_mod_flags modifiers) +static int hid_listener_modifiers_released(zmk_mod_flags modifiers) { LOG_DBG("modifiers %d", modifiers); @@ -88,44 +81,26 @@ static int behavior_hid_modifiers_released(zmk_mod_flags modifiers) return zmk_endpoints_send_report(USAGE_KEYPAD); } -int behavior_hid_listener(const struct zmk_event_header *eh) +int hid_listener(const struct zmk_event_header *eh) { if (is_keycode_state_changed(eh)) { const struct keycode_state_changed *ev = cast_keycode_state_changed(eh); if (ev->state) { - behaviour_hid_keycode_pressed(ev->usage_page, ev->keycode); + hid_listener_keycode_pressed(ev->usage_page, ev->keycode); } else { - behaviour_hid_keycode_released(ev->usage_page, ev->keycode); + hid_listener_keycode_released(ev->usage_page, ev->keycode); } } else if (is_modifiers_state_changed(eh)) { const struct modifiers_state_changed *ev = cast_modifiers_state_changed(eh); if (ev->state) { - behavior_hid_modifiers_pressed(ev->modifiers); + hid_listener_modifiers_pressed(ev->modifiers); } else { - behavior_hid_modifiers_released(ev->modifiers); + hid_listener_modifiers_released(ev->modifiers); } } return 0; } -ZMK_LISTENER(behavior_hid, behavior_hid_listener); -ZMK_SUBSCRIPTION(behavior_hid, keycode_state_changed); -ZMK_SUBSCRIPTION(behavior_hid, modifiers_state_changed); - -static int behavior_hid_init(struct device *dev) -{ - return 0; -}; - -static const struct behavior_driver_api behavior_hid_driver_api = { -}; - -static const struct behavior_hid_config behavior_hid_config = {}; - -static struct behavior_hid_data behavior_hid_data; - -DEVICE_AND_API_INIT(behavior_hid, DT_INST_LABEL(0), behavior_hid_init, - &behavior_hid_data, - &behavior_hid_config, - APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, - &behavior_hid_driver_api); \ No newline at end of file +ZMK_LISTENER(hid_listener, hid_listener); +ZMK_SUBSCRIPTION(hid_listener, keycode_state_changed); +ZMK_SUBSCRIPTION(hid_listener, modifiers_state_changed); \ No newline at end of file