Browse Source

Lots of cleanup of old events/behavior mash.

xmkb
Pete Johanson 4 years ago
parent
commit
57e061ac91
  1. 3
      app/CMakeLists.txt
  2. 1
      app/dts/behaviors.dtsi
  3. 9
      app/dts/behaviors/hid.dtsi
  4. 9
      app/include/zmk/events.h
  5. 1
      app/src/behaviors/behavior_mod_tap.c
  6. 1
      app/src/behaviors/behavior_momentary_layer.c
  7. 83
      app/src/events.c
  8. 53
      app/src/hid_listener.c

3
app/CMakeLists.txt

@ -29,14 +29,13 @@ zephyr_linker_sources(RODATA include/linker/zmk-events.ld)
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/matrix_transform.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/keymap.c)
target_sources(app PRIVATE src/hid_listener.c)
target_sources(app PRIVATE src/hid.c) target_sources(app PRIVATE src/hid.c)
target_sources(app PRIVATE src/event_manager.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/position_state_changed.c)
target_sources(app PRIVATE src/events/keycode_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/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_key_press.c)
target_sources(app PRIVATE src/behaviors/behavior_reset.c) target_sources(app PRIVATE src/behaviors/behavior_reset.c)
target_sources(app PRIVATE src/behaviors/behavior_mod_tap.c) target_sources(app PRIVATE src/behaviors/behavior_mod_tap.c)

1
app/dts/behaviors.dtsi

@ -3,4 +3,3 @@
#include <behaviors/mod_tap.dtsi> #include <behaviors/mod_tap.dtsi>
#include <behaviors/momentary_layer.dtsi> #include <behaviors/momentary_layer.dtsi>
#include <behaviors/reset.dtsi> #include <behaviors/reset.dtsi>
#include <behaviors/hid.dtsi>

9
app/dts/behaviors/hid.dtsi

@ -1,9 +0,0 @@
/ {
behaviors {
hid_behavior: behavior_hid {
compatible = "zmk,behavior-hid", "zmk,behavior-global";
label = "HID";
#binding-cells = <0>;
};
};
};

9
app/include/zmk/events.h

@ -1,9 +0,0 @@
#pragma once
#include <zmk/keys.h>
int zmk_events_modifiers_pressed(zmk_mod_flags modifiers);
int zmk_events_modifiers_released(zmk_mod_flags modifiers);
// TODO: Encoders?
// TODO: Sensors?

1
app/src/behaviors/behavior_mod_tap.c

@ -13,7 +13,6 @@
#include <zmk/event-manager.h> #include <zmk/event-manager.h>
#include <zmk/events/keycode-state-changed.h> #include <zmk/events/keycode-state-changed.h>
#include <zmk/events/modifiers-state-changed.h> #include <zmk/events/modifiers-state-changed.h>
#include <zmk/events.h>
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

1
app/src/behaviors/behavior_momentary_layer.c

@ -10,7 +10,6 @@
#include <drivers/behavior.h> #include <drivers/behavior.h>
#include <logging/log.h> #include <logging/log.h>
#include <zmk/events.h>
#include <zmk/keymap.h> #include <zmk/keymap.h>
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

83
app/src/events.c

@ -1,83 +0,0 @@
#include <zephyr.h>
#include <drivers/behavior.h>
#include <zmk/behavior.h>
#include <zmk/events.h>
#include <sys/util.h>
#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;
};

53
app/src/behaviors/behavior_hid.c → app/src/hid_listener.c

@ -4,10 +4,6 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#define DT_DRV_COMPAT zmk_behavior_hid
#include <device.h>
#include <power/reboot.h>
#include <drivers/behavior.h> #include <drivers/behavior.h>
#include <logging/log.h> #include <logging/log.h>
@ -19,14 +15,11 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/hid.h> #include <zmk/hid.h>
#include <zmk/endpoints.h> #include <zmk/endpoints.h>
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; int err;
LOG_DBG("keycode %d", keycode); LOG_DBG("usage_page 0x%02X keycode 0x%02X", usage_page, keycode);
switch (usage_page) { switch (usage_page) {
case USAGE_KEYPAD: 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); 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; int err;
LOG_DBG("keycode %d", keycode); LOG_DBG("usage_page 0x%02X keycode 0x%02X", usage_page, keycode);
switch (usage_page) { switch (usage_page) {
case USAGE_KEYPAD: 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); 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); 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); 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); 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); 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)) { if (is_keycode_state_changed(eh)) {
const struct keycode_state_changed *ev = cast_keycode_state_changed(eh); const struct keycode_state_changed *ev = cast_keycode_state_changed(eh);
if (ev->state) { if (ev->state) {
behaviour_hid_keycode_pressed(ev->usage_page, ev->keycode); hid_listener_keycode_pressed(ev->usage_page, ev->keycode);
} else { } 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)) { } else if (is_modifiers_state_changed(eh)) {
const struct modifiers_state_changed *ev = cast_modifiers_state_changed(eh); const struct modifiers_state_changed *ev = cast_modifiers_state_changed(eh);
if (ev->state) { if (ev->state) {
behavior_hid_modifiers_pressed(ev->modifiers); hid_listener_modifiers_pressed(ev->modifiers);
} else { } else {
behavior_hid_modifiers_released(ev->modifiers); hid_listener_modifiers_released(ev->modifiers);
} }
} }
return 0; return 0;
} }
ZMK_LISTENER(behavior_hid, behavior_hid_listener); ZMK_LISTENER(hid_listener, hid_listener);
ZMK_SUBSCRIPTION(behavior_hid, keycode_state_changed); ZMK_SUBSCRIPTION(hid_listener, keycode_state_changed);
ZMK_SUBSCRIPTION(behavior_hid, modifiers_state_changed); ZMK_SUBSCRIPTION(hid_listener, 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);
Loading…
Cancel
Save