Modifier event, tweaks for linker script.
This commit is contained in:
parent
9a991bf019
commit
96ec16da92
8 changed files with 73 additions and 41 deletions
|
@ -33,8 +33,9 @@ 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.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/keycode_state_changed.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/modifiers_state_changed.c)
|
||||||
target_sources(app PRIVATE src/behaviors/behavior_hid.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)
|
||||||
|
|
|
@ -1,16 +1,10 @@
|
||||||
#include <linker/linker-defs.h>
|
#include <linker/linker-defs.h>
|
||||||
|
|
||||||
SECTION_PROLOGUE(event_types,,)
|
|
||||||
{
|
|
||||||
__event_type_start = .; \
|
__event_type_start = .; \
|
||||||
KEEP(*(".event_type")); \
|
KEEP(*(".event_type")); \
|
||||||
__event_type_end = .; \
|
__event_type_end = .; \
|
||||||
} GROUP_LINK_IN(ROMABLE_REGION)
|
|
||||||
|
|
||||||
SECTION_PROLOGUE(event_subscriptions,,)
|
|
||||||
{
|
|
||||||
__event_subscriptions_start = .; \
|
__event_subscriptions_start = .; \
|
||||||
KEEP(*(".event_subscription")); \
|
KEEP(*(".event_subscription")); \
|
||||||
__event_subscriptions_end = .; \
|
__event_subscriptions_end = .; \
|
||||||
} GROUP_LINK_IN(ROMABLE_REGION)
|
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,8 @@
|
||||||
|
|
||||||
#include <zmk/keys.h>
|
#include <zmk/keys.h>
|
||||||
|
|
||||||
int zmk_events_position_pressed(u32_t position);
|
|
||||||
int zmk_events_position_released(u32_t position);
|
|
||||||
int zmk_events_keycode_pressed(u8_t usage_page, u32_t keycode);
|
|
||||||
int zmk_events_keycode_released(u8_t usage_page, u32_t keycode);
|
|
||||||
int zmk_events_modifiers_pressed(zmk_mod_flags modifiers);
|
int zmk_events_modifiers_pressed(zmk_mod_flags modifiers);
|
||||||
int zmk_events_modifiers_released(zmk_mod_flags modifiers);
|
int zmk_events_modifiers_released(zmk_mod_flags modifiers);
|
||||||
int zmk_events_consumer_key_pressed(u32_t usage);
|
|
||||||
int zmk_events_consumer_key_released(u32_t usage);
|
|
||||||
|
|
||||||
// TODO: Encoders?
|
// TODO: Encoders?
|
||||||
// TODO: Sensors?
|
// TODO: Sensors?
|
|
@ -11,3 +11,13 @@ struct keycode_state_changed {
|
||||||
};
|
};
|
||||||
|
|
||||||
ZMK_EVENT_DECLARE(keycode_state_changed);
|
ZMK_EVENT_DECLARE(keycode_state_changed);
|
||||||
|
|
||||||
|
inline struct keycode_state_changed* create_keycode_state_changed(u8_t usage_page, u32_t keycode, bool state)
|
||||||
|
{
|
||||||
|
struct keycode_state_changed* ev = new_keycode_state_changed();
|
||||||
|
ev->usage_page = usage_page;
|
||||||
|
ev->keycode = keycode;
|
||||||
|
ev->state = state;
|
||||||
|
|
||||||
|
return ev;
|
||||||
|
}
|
22
app/include/zmk/events/modifiers-state-changed.h
Normal file
22
app/include/zmk/events/modifiers-state-changed.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <zephyr.h>
|
||||||
|
#include <zmk/keys.h>
|
||||||
|
#include <zmk/event-manager.h>
|
||||||
|
|
||||||
|
struct modifiers_state_changed {
|
||||||
|
struct zmk_event_header header;
|
||||||
|
zmk_mod_flags modifiers;
|
||||||
|
bool state;
|
||||||
|
};
|
||||||
|
|
||||||
|
ZMK_EVENT_DECLARE(modifiers_state_changed);
|
||||||
|
|
||||||
|
inline struct modifiers_state_changed* create_modifiers_state_changed(zmk_mod_flags modifiers, bool state)
|
||||||
|
{
|
||||||
|
struct modifiers_state_changed* ev = new_modifiers_state_changed();
|
||||||
|
ev->modifiers = modifiers;
|
||||||
|
ev->state = state;
|
||||||
|
|
||||||
|
return ev;
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||||
|
|
||||||
#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/hid.h>
|
#include <zmk/hid.h>
|
||||||
#include <zmk/endpoints.h>
|
#include <zmk/endpoints.h>
|
||||||
|
|
||||||
|
@ -56,14 +57,14 @@ static int behaviour_hid_keycode_released(u8_t usage_page, u32_t keycode)
|
||||||
case USAGE_KEYPAD:
|
case USAGE_KEYPAD:
|
||||||
err = zmk_hid_keypad_release(keycode);
|
err = zmk_hid_keypad_release(keycode);
|
||||||
if (err) {
|
if (err) {
|
||||||
LOG_ERR("Unable to press keycode");
|
LOG_ERR("Unable to release keycode");
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case USAGE_CONSUMER:
|
case USAGE_CONSUMER:
|
||||||
err = zmk_hid_consumer_release(keycode);
|
err = zmk_hid_consumer_release(keycode);
|
||||||
if (err) {
|
if (err) {
|
||||||
LOG_ERR("Unable to press keycode");
|
LOG_ERR("Unable to release keycode");
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -71,6 +72,21 @@ 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)
|
||||||
|
{
|
||||||
|
LOG_DBG("modifiers %d", modifiers);
|
||||||
|
|
||||||
|
zmk_hid_register_mods(modifiers);
|
||||||
|
return zmk_endpoints_send_report(USAGE_KEYPAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int behavior_hid_modifiers_released(zmk_mod_flags modifiers)
|
||||||
|
{
|
||||||
|
LOG_DBG("modifiers %d", modifiers);
|
||||||
|
|
||||||
|
zmk_hid_unregister_mods(modifiers);
|
||||||
|
return zmk_endpoints_send_report(USAGE_KEYPAD);
|
||||||
|
}
|
||||||
|
|
||||||
int behavior_hid_listener(const struct zmk_event_header *eh)
|
int behavior_hid_listener(const struct zmk_event_header *eh)
|
||||||
{
|
{
|
||||||
|
@ -81,37 +97,27 @@ int behavior_hid_listener(const struct zmk_event_header *eh)
|
||||||
} else {
|
} else {
|
||||||
behaviour_hid_keycode_released(ev->usage_page, ev->keycode);
|
behaviour_hid_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);
|
||||||
|
} else {
|
||||||
|
behavior_hid_modifiers_released(ev->modifiers);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZMK_LISTENER(behavior_hid, behavior_hid_listener);
|
ZMK_LISTENER(behavior_hid, behavior_hid_listener);
|
||||||
ZMK_SUBSCRIPTION(behavior_hid, keycode_state_changed);
|
ZMK_SUBSCRIPTION(behavior_hid, keycode_state_changed);
|
||||||
|
ZMK_SUBSCRIPTION(behavior_hid, modifiers_state_changed);
|
||||||
|
|
||||||
static int behavior_hid_init(struct device *dev)
|
static int behavior_hid_init(struct device *dev)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int on_modifiers_pressed(struct device *dev, zmk_mod_flags modifiers)
|
|
||||||
{
|
|
||||||
LOG_DBG("modifiers %d", modifiers);
|
|
||||||
|
|
||||||
zmk_hid_register_mods(modifiers);
|
|
||||||
return zmk_endpoints_send_report(USAGE_KEYPAD);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int on_modifiers_released(struct device *dev, zmk_mod_flags modifiers)
|
|
||||||
{
|
|
||||||
LOG_DBG("modifiers %d", modifiers);
|
|
||||||
|
|
||||||
zmk_hid_unregister_mods(modifiers);
|
|
||||||
return zmk_endpoints_send_report(USAGE_KEYPAD);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct behavior_driver_api behavior_hid_driver_api = {
|
static const struct behavior_driver_api behavior_hid_driver_api = {
|
||||||
.modifiers_pressed = on_modifiers_pressed,
|
|
||||||
.modifiers_released = on_modifiers_released
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct behavior_hid_config behavior_hid_config = {};
|
static const struct behavior_hid_config behavior_hid_config = {};
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#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.h>
|
#include <zmk/events.h>
|
||||||
|
|
||||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||||
|
@ -48,21 +49,20 @@ static int on_keymap_binding_pressed(struct device *dev, u32_t position, u32_t m
|
||||||
struct behavior_mod_tap_data *data = dev->driver_data;
|
struct behavior_mod_tap_data *data = dev->driver_data;
|
||||||
LOG_DBG("mods: %d, keycode: %d", mods, keycode);
|
LOG_DBG("mods: %d, keycode: %d", mods, keycode);
|
||||||
WRITE_BIT(data->pending_press_positions, position, true);
|
WRITE_BIT(data->pending_press_positions, position, true);
|
||||||
return zmk_events_modifiers_pressed(mods);
|
return ZMK_EVENT_RAISE(create_modifiers_state_changed(mods, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// They keycode is passed by the "keymap" based on the parameter created as part of the assignment.
|
|
||||||
static int on_keymap_binding_released(struct device *dev, u32_t position, u32_t mods, u32_t keycode)
|
static int on_keymap_binding_released(struct device *dev, u32_t position, u32_t mods, u32_t keycode)
|
||||||
{
|
{
|
||||||
struct behavior_mod_tap_data *data = dev->driver_data;
|
struct behavior_mod_tap_data *data = dev->driver_data;
|
||||||
LOG_DBG("mods: %d, keycode: %d", mods, keycode);
|
LOG_DBG("mods: %d, keycode: %d", mods, keycode);
|
||||||
|
|
||||||
zmk_events_modifiers_released(mods);
|
ZMK_EVENT_RAISE(create_modifiers_state_changed(mods, false));
|
||||||
|
k_msleep(10); // TODO: Better approach than k_msleep to avoid USB send failures? Retries in the USB endpoint layer?
|
||||||
if (data->pending_press_positions & BIT(position)) {
|
if (data->pending_press_positions & BIT(position)) {
|
||||||
zmk_events_keycode_pressed(USAGE_KEYPAD, keycode);
|
ZMK_EVENT_RAISE(create_keycode_state_changed(USAGE_KEYPAD, keycode, true));
|
||||||
k_msleep(10);
|
k_msleep(10);
|
||||||
zmk_events_keycode_released(USAGE_KEYPAD, keycode);
|
ZMK_EVENT_RAISE(create_keycode_state_changed(USAGE_KEYPAD, keycode, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -73,7 +73,6 @@ static const struct behavior_driver_api behavior_mod_tap_driver_api = {
|
||||||
.binding_released = on_keymap_binding_released,
|
.binding_released = on_keymap_binding_released,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static const struct behavior_mod_tap_config behavior_mod_tap_config = {};
|
static const struct behavior_mod_tap_config behavior_mod_tap_config = {};
|
||||||
|
|
||||||
static struct behavior_mod_tap_data behavior_mod_tap_data;
|
static struct behavior_mod_tap_data behavior_mod_tap_data;
|
||||||
|
|
6
app/src/events/modifiers_state_changed.c
Normal file
6
app/src/events/modifiers_state_changed.c
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
#include <kernel.h>
|
||||||
|
#include <zmk/events/modifiers-state-changed.h>
|
||||||
|
|
||||||
|
ZMK_EVENT_IMPL(modifiers_state_changed);
|
Loading…
Add table
Reference in a new issue