refactor(core): Move to stack allocated events.
* Move to local/stack allocated event API that doesn't require dynamic allocation/freeing. * Disable heap, we no longer use alloc/free unless using LVGL. * Tons of refactors all over to account for the new event approach.
This commit is contained in:
parent
50e473276f
commit
33209dee1d
24 changed files with 172 additions and 147 deletions
|
@ -595,7 +595,7 @@ endmenu
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
config HEAP_MEM_POOL_SIZE
|
config HEAP_MEM_POOL_SIZE
|
||||||
default 8192
|
default 8192 if ZMK_DISPLAY
|
||||||
|
|
||||||
config KERNEL_BIN_NAME
|
config KERNEL_BIN_NAME
|
||||||
default "zmk"
|
default "zmk"
|
||||||
|
|
|
@ -38,7 +38,8 @@ struct zmk_event_subscription {
|
||||||
zmk_event_t header; \
|
zmk_event_t header; \
|
||||||
struct event_type data; \
|
struct event_type data; \
|
||||||
}; \
|
}; \
|
||||||
struct event_type##_event *new_##event_type(struct event_type); \
|
struct event_type##_event copy_raised_##event_type(const struct event_type *ev); \
|
||||||
|
int raise_##event_type(struct event_type); \
|
||||||
struct event_type *as_##event_type(const zmk_event_t *eh); \
|
struct event_type *as_##event_type(const zmk_event_t *eh); \
|
||||||
extern const struct zmk_event_type zmk_event_##event_type;
|
extern const struct zmk_event_type zmk_event_##event_type;
|
||||||
|
|
||||||
|
@ -46,12 +47,14 @@ struct zmk_event_subscription {
|
||||||
const struct zmk_event_type zmk_event_##event_type = {.name = STRINGIFY(event_type)}; \
|
const struct zmk_event_type zmk_event_##event_type = {.name = STRINGIFY(event_type)}; \
|
||||||
const struct zmk_event_type *zmk_event_ref_##event_type __used \
|
const struct zmk_event_type *zmk_event_ref_##event_type __used \
|
||||||
__attribute__((__section__(".event_type"))) = &zmk_event_##event_type; \
|
__attribute__((__section__(".event_type"))) = &zmk_event_##event_type; \
|
||||||
struct event_type##_event *new_##event_type(struct event_type data) { \
|
struct event_type##_event copy_raised_##event_type(const struct event_type *ev) { \
|
||||||
struct event_type##_event *ev = \
|
struct event_type##_event *outer = CONTAINER_OF(ev, struct event_type##_event, data); \
|
||||||
(struct event_type##_event *)k_malloc(sizeof(struct event_type##_event)); \
|
return *outer; \
|
||||||
ev->header.event = &zmk_event_##event_type; \
|
}; \
|
||||||
ev->data = data; \
|
int raise_##event_type(struct event_type data) { \
|
||||||
return ev; \
|
struct event_type##_event ev = {.data = data}; \
|
||||||
|
ev.header.event = &zmk_event_##event_type; \
|
||||||
|
return ZMK_EVENT_RAISE(ev); \
|
||||||
}; \
|
}; \
|
||||||
struct event_type *as_##event_type(const zmk_event_t *eh) { \
|
struct event_type *as_##event_type(const zmk_event_t *eh) { \
|
||||||
return (eh->event == &zmk_event_##event_type) ? &((struct event_type##_event *)eh)->data \
|
return (eh->event == &zmk_event_##event_type) ? &((struct event_type##_event *)eh)->data \
|
||||||
|
@ -68,17 +71,15 @@ struct zmk_event_subscription {
|
||||||
.listener = &zmk_listener_##mod, \
|
.listener = &zmk_listener_##mod, \
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ZMK_EVENT_RAISE(ev) zmk_event_manager_raise((zmk_event_t *)ev);
|
#define ZMK_EVENT_RAISE(ev) zmk_event_manager_raise((zmk_event_t *)&ev);
|
||||||
|
|
||||||
#define ZMK_EVENT_RAISE_AFTER(ev, mod) \
|
#define ZMK_EVENT_RAISE_AFTER(ev, mod) \
|
||||||
zmk_event_manager_raise_after((zmk_event_t *)ev, &zmk_listener_##mod);
|
zmk_event_manager_raise_after((zmk_event_t *)&ev, &zmk_listener_##mod);
|
||||||
|
|
||||||
#define ZMK_EVENT_RAISE_AT(ev, mod) \
|
#define ZMK_EVENT_RAISE_AT(ev, mod) \
|
||||||
zmk_event_manager_raise_at((zmk_event_t *)ev, &zmk_listener_##mod);
|
zmk_event_manager_raise_at((zmk_event_t *)&ev, &zmk_listener_##mod);
|
||||||
|
|
||||||
#define ZMK_EVENT_RELEASE(ev) zmk_event_manager_release((zmk_event_t *)ev);
|
#define ZMK_EVENT_RELEASE(ev) zmk_event_manager_release((zmk_event_t *)&ev);
|
||||||
|
|
||||||
#define ZMK_EVENT_FREE(ev) k_free((void *)ev);
|
|
||||||
|
|
||||||
int zmk_event_manager_raise(zmk_event_t *event);
|
int zmk_event_manager_raise(zmk_event_t *event);
|
||||||
int zmk_event_manager_raise_after(zmk_event_t *event, const struct zmk_listener *listener);
|
int zmk_event_manager_raise_after(zmk_event_t *event, const struct zmk_listener *listener);
|
||||||
|
|
|
@ -21,7 +21,7 @@ struct zmk_keycode_state_changed {
|
||||||
|
|
||||||
ZMK_EVENT_DECLARE(zmk_keycode_state_changed);
|
ZMK_EVENT_DECLARE(zmk_keycode_state_changed);
|
||||||
|
|
||||||
static inline struct zmk_keycode_state_changed_event *
|
static inline struct zmk_keycode_state_changed
|
||||||
zmk_keycode_state_changed_from_encoded(uint32_t encoded, bool pressed, int64_t timestamp) {
|
zmk_keycode_state_changed_from_encoded(uint32_t encoded, bool pressed, int64_t timestamp) {
|
||||||
uint16_t page = ZMK_HID_USAGE_PAGE(encoded);
|
uint16_t page = ZMK_HID_USAGE_PAGE(encoded);
|
||||||
uint16_t id = ZMK_HID_USAGE_ID(encoded);
|
uint16_t id = ZMK_HID_USAGE_ID(encoded);
|
||||||
|
@ -38,11 +38,10 @@ zmk_keycode_state_changed_from_encoded(uint32_t encoded, bool pressed, int64_t t
|
||||||
implicit_modifiers = SELECT_MODS(encoded);
|
implicit_modifiers = SELECT_MODS(encoded);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new_zmk_keycode_state_changed(
|
return (struct zmk_keycode_state_changed){.usage_page = page,
|
||||||
(struct zmk_keycode_state_changed){.usage_page = page,
|
.keycode = id,
|
||||||
.keycode = id,
|
.implicit_modifiers = implicit_modifiers,
|
||||||
.implicit_modifiers = implicit_modifiers,
|
.explicit_modifiers = explicit_modifiers,
|
||||||
.explicit_modifiers = explicit_modifiers,
|
.state = pressed,
|
||||||
.state = pressed,
|
.timestamp = timestamp};
|
||||||
.timestamp = timestamp});
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,7 @@ struct zmk_layer_state_changed {
|
||||||
|
|
||||||
ZMK_EVENT_DECLARE(zmk_layer_state_changed);
|
ZMK_EVENT_DECLARE(zmk_layer_state_changed);
|
||||||
|
|
||||||
static inline struct zmk_layer_state_changed_event *create_layer_state_changed(uint8_t layer,
|
static inline int raise_layer_state_changed(uint8_t layer, bool state) {
|
||||||
bool state) {
|
return raise_zmk_layer_state_changed((struct zmk_layer_state_changed){
|
||||||
return new_zmk_layer_state_changed((struct zmk_layer_state_changed){
|
|
||||||
.layer = layer, .state = state, .timestamp = k_uptime_get()});
|
.layer = layer, .state = state, .timestamp = k_uptime_get()});
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@ struct zmk_mouse_button_state_changed {
|
||||||
|
|
||||||
ZMK_EVENT_DECLARE(zmk_mouse_button_state_changed);
|
ZMK_EVENT_DECLARE(zmk_mouse_button_state_changed);
|
||||||
|
|
||||||
static inline struct zmk_mouse_button_state_changed_event *
|
static inline int raise_zmk_mouse_button_state_changed_from_encoded(uint32_t encoded, bool pressed,
|
||||||
zmk_mouse_button_state_changed_from_encoded(uint32_t encoded, bool pressed, int64_t timestamp) {
|
int64_t timestamp) {
|
||||||
return new_zmk_mouse_button_state_changed((struct zmk_mouse_button_state_changed){
|
return raise_zmk_mouse_button_state_changed((struct zmk_mouse_button_state_changed){
|
||||||
.buttons = ZMK_HID_USAGE_ID(encoded), .state = pressed, .timestamp = timestamp});
|
.buttons = ZMK_HID_USAGE_ID(encoded), .state = pressed, .timestamp = timestamp});
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,8 +43,8 @@ static uint32_t activity_last_uptime;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int raise_event(void) {
|
int raise_event(void) {
|
||||||
return ZMK_EVENT_RAISE(new_zmk_activity_state_changed(
|
return raise_zmk_activity_state_changed(
|
||||||
(struct zmk_activity_state_changed){.state = activity_state}));
|
(struct zmk_activity_state_changed){.state = activity_state});
|
||||||
}
|
}
|
||||||
|
|
||||||
int set_state(enum zmk_activity_state state) {
|
int set_state(enum zmk_activity_state state) {
|
||||||
|
|
|
@ -63,8 +63,8 @@ static int zmk_battery_update(const struct device *battery) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
rc = ZMK_EVENT_RAISE(new_zmk_battery_state_changed(
|
rc = raise_zmk_battery_state_changed(
|
||||||
(struct zmk_battery_state_changed){.state_of_charge = last_state_of_charge}));
|
(struct zmk_battery_state_changed){.state_of_charge = last_state_of_charge});
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
|
|
@ -88,7 +88,24 @@ struct active_hold_tap {
|
||||||
struct active_hold_tap *undecided_hold_tap = NULL;
|
struct active_hold_tap *undecided_hold_tap = NULL;
|
||||||
struct active_hold_tap active_hold_taps[ZMK_BHV_HOLD_TAP_MAX_HELD] = {};
|
struct active_hold_tap active_hold_taps[ZMK_BHV_HOLD_TAP_MAX_HELD] = {};
|
||||||
// We capture most position_state_changed events and some modifiers_state_changed events.
|
// We capture most position_state_changed events and some modifiers_state_changed events.
|
||||||
const zmk_event_t *captured_events[ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS] = {};
|
|
||||||
|
enum captured_event_tag {
|
||||||
|
ET_NONE,
|
||||||
|
ET_POS_CHANGED,
|
||||||
|
ET_CODE_CHANGED,
|
||||||
|
};
|
||||||
|
|
||||||
|
union captured_event_data {
|
||||||
|
struct zmk_position_state_changed_event position;
|
||||||
|
struct zmk_keycode_state_changed_event keycode;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct captured_event {
|
||||||
|
enum captured_event_tag tag;
|
||||||
|
union captured_event_data data;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct captured_event captured_events[ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS] = {};
|
||||||
|
|
||||||
// Keep track of which key was tapped most recently for the standard, if it is a hold-tap
|
// Keep track of which key was tapped most recently for the standard, if it is a hold-tap
|
||||||
// a position, will be given, if not it will just be INT32_MIN
|
// a position, will be given, if not it will just be INT32_MIN
|
||||||
|
@ -122,33 +139,32 @@ static bool is_quick_tap(struct active_hold_tap *hold_tap) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int capture_event(const zmk_event_t *event) {
|
static int capture_event(struct captured_event *data) {
|
||||||
for (int i = 0; i < ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS; i++) {
|
for (int i = 0; i < ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS; i++) {
|
||||||
if (captured_events[i] == NULL) {
|
if (captured_events[i].tag == ET_NONE) {
|
||||||
captured_events[i] = event;
|
captured_events[i] = *data;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct zmk_position_state_changed *find_captured_keydown_event(uint32_t position) {
|
static bool have_captured_keydown_event(uint32_t position) {
|
||||||
struct zmk_position_state_changed *last_match = NULL;
|
|
||||||
for (int i = 0; i < ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS; i++) {
|
for (int i = 0; i < ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS; i++) {
|
||||||
const zmk_event_t *eh = captured_events[i];
|
struct captured_event *ev = &captured_events[i];
|
||||||
if (eh == NULL) {
|
if (ev->tag == ET_NONE) {
|
||||||
return last_match;
|
return false;
|
||||||
}
|
}
|
||||||
struct zmk_position_state_changed *position_event = as_zmk_position_state_changed(eh);
|
|
||||||
if (position_event == NULL) {
|
if (ev->tag != ET_POS_CHANGED) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (position_event->position == position && position_event->state) {
|
if (ev->data.position.data.position == position && ev->data.position.data.state) {
|
||||||
last_match = position_event;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return last_match;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct zmk_listener zmk_listener_behavior_hold_tap;
|
const struct zmk_listener zmk_listener_behavior_hold_tap;
|
||||||
|
@ -184,25 +200,35 @@ static void release_captured_events() {
|
||||||
// [k1_down, k1_up, null, null, null, ...]
|
// [k1_down, k1_up, null, null, null, ...]
|
||||||
// now mt2 will start releasing it's own captured positions.
|
// now mt2 will start releasing it's own captured positions.
|
||||||
for (int i = 0; i < ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS; i++) {
|
for (int i = 0; i < ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS; i++) {
|
||||||
const zmk_event_t *captured_event = captured_events[i];
|
struct captured_event *captured_event = &captured_events[i];
|
||||||
if (captured_event == NULL) {
|
enum captured_event_tag tag = captured_event->tag;
|
||||||
|
|
||||||
|
if (tag == ET_NONE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
captured_events[i] = NULL;
|
|
||||||
|
captured_events[i].tag = ET_NONE;
|
||||||
if (undecided_hold_tap != NULL) {
|
if (undecided_hold_tap != NULL) {
|
||||||
k_msleep(10);
|
k_msleep(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct zmk_position_state_changed *position_event;
|
switch (tag) {
|
||||||
struct zmk_keycode_state_changed *modifier_event;
|
case ET_CODE_CHANGED:
|
||||||
if ((position_event = as_zmk_position_state_changed(captured_event)) != NULL) {
|
LOG_DBG("Releasing mods changed event 0x%02X %s",
|
||||||
LOG_DBG("Releasing key position event for position %d %s", position_event->position,
|
captured_event->data.keycode.data.keycode,
|
||||||
(position_event->state ? "pressed" : "released"));
|
(captured_event->data.keycode.data.state ? "pressed" : "released"));
|
||||||
} else if ((modifier_event = as_zmk_keycode_state_changed(captured_event)) != NULL) {
|
ZMK_EVENT_RAISE_AT(captured_event->data.keycode, behavior_hold_tap);
|
||||||
LOG_DBG("Releasing mods changed event 0x%02X %s", modifier_event->keycode,
|
break;
|
||||||
(modifier_event->state ? "pressed" : "released"));
|
case ET_POS_CHANGED:
|
||||||
|
LOG_DBG("Releasing key position event for position %d %s",
|
||||||
|
captured_event->data.position.data.position,
|
||||||
|
(captured_event->data.position.data.state ? "pressed" : "released"));
|
||||||
|
ZMK_EVENT_RAISE_AT(captured_event->data.position, behavior_hold_tap);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
LOG_ERR("Unhandled captured event type");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
ZMK_EVENT_RAISE_AT(captured_event, behavior_hold_tap);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -622,7 +648,7 @@ static int position_state_changed_listener(const zmk_event_t *eh) {
|
||||||
return ZMK_EV_EVENT_BUBBLE;
|
return ZMK_EV_EVENT_BUBBLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ev->state && find_captured_keydown_event(ev->position) == NULL) {
|
if (!ev->state && !have_captured_keydown_event(ev->position)) {
|
||||||
// no keydown event has been captured, let it bubble.
|
// no keydown event has been captured, let it bubble.
|
||||||
// we'll catch modifiers later in modifier_state_changed_listener
|
// we'll catch modifiers later in modifier_state_changed_listener
|
||||||
LOG_DBG("%d bubbling %d %s event", undecided_hold_tap->position, ev->position,
|
LOG_DBG("%d bubbling %d %s event", undecided_hold_tap->position, ev->position,
|
||||||
|
@ -632,7 +658,11 @@ static int position_state_changed_listener(const zmk_event_t *eh) {
|
||||||
|
|
||||||
LOG_DBG("%d capturing %d %s event", undecided_hold_tap->position, ev->position,
|
LOG_DBG("%d capturing %d %s event", undecided_hold_tap->position, ev->position,
|
||||||
ev->state ? "down" : "up");
|
ev->state ? "down" : "up");
|
||||||
capture_event(eh);
|
struct captured_event capture = {
|
||||||
|
.tag = ET_POS_CHANGED,
|
||||||
|
.data = {.position = copy_raised_zmk_position_state_changed(ev)},
|
||||||
|
};
|
||||||
|
capture_event(&capture);
|
||||||
decide_hold_tap(undecided_hold_tap, ev->state ? HT_OTHER_KEY_DOWN : HT_OTHER_KEY_UP);
|
decide_hold_tap(undecided_hold_tap, ev->state ? HT_OTHER_KEY_DOWN : HT_OTHER_KEY_UP);
|
||||||
return ZMK_EV_EVENT_CAPTURED;
|
return ZMK_EV_EVENT_CAPTURED;
|
||||||
}
|
}
|
||||||
|
@ -659,7 +689,9 @@ static int keycode_state_changed_listener(const zmk_event_t *eh) {
|
||||||
// if a undecided_hold_tap is active.
|
// if a undecided_hold_tap is active.
|
||||||
LOG_DBG("%d capturing 0x%02X %s event", undecided_hold_tap->position, ev->keycode,
|
LOG_DBG("%d capturing 0x%02X %s event", undecided_hold_tap->position, ev->keycode,
|
||||||
ev->state ? "down" : "up");
|
ev->state ? "down" : "up");
|
||||||
capture_event(eh);
|
struct captured_event capture = {
|
||||||
|
.tag = ET_CODE_CHANGED, .data = {.keycode = copy_raised_zmk_keycode_state_changed(ev)}};
|
||||||
|
capture_event(&capture);
|
||||||
return ZMK_EV_EVENT_CAPTURED;
|
return ZMK_EV_EVENT_CAPTURED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,14 +21,14 @@ static int behavior_key_press_init(const struct device *dev) { return 0; };
|
||||||
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
|
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
|
||||||
struct zmk_behavior_binding_event event) {
|
struct zmk_behavior_binding_event event) {
|
||||||
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
|
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
|
||||||
return ZMK_EVENT_RAISE(
|
return raise_zmk_keycode_state_changed(
|
||||||
zmk_keycode_state_changed_from_encoded(binding->param1, true, event.timestamp));
|
zmk_keycode_state_changed_from_encoded(binding->param1, true, event.timestamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
|
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
|
||||||
struct zmk_behavior_binding_event event) {
|
struct zmk_behavior_binding_event event) {
|
||||||
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
|
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
|
||||||
return ZMK_EVENT_RAISE(
|
return raise_zmk_keycode_state_changed(
|
||||||
zmk_keycode_state_changed_from_encoded(binding->param1, false, event.timestamp));
|
zmk_keycode_state_changed_from_encoded(binding->param1, false, event.timestamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ static int on_key_repeat_binding_pressed(struct zmk_behavior_binding *binding,
|
||||||
sizeof(struct zmk_keycode_state_changed));
|
sizeof(struct zmk_keycode_state_changed));
|
||||||
data->current_keycode_pressed.timestamp = k_uptime_get();
|
data->current_keycode_pressed.timestamp = k_uptime_get();
|
||||||
|
|
||||||
ZMK_EVENT_RAISE(new_zmk_keycode_state_changed(data->current_keycode_pressed));
|
raise_zmk_keycode_state_changed(data->current_keycode_pressed);
|
||||||
|
|
||||||
return ZMK_BEHAVIOR_OPAQUE;
|
return ZMK_BEHAVIOR_OPAQUE;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ static int on_key_repeat_binding_released(struct zmk_behavior_binding *binding,
|
||||||
data->current_keycode_pressed.timestamp = k_uptime_get();
|
data->current_keycode_pressed.timestamp = k_uptime_get();
|
||||||
data->current_keycode_pressed.state = false;
|
data->current_keycode_pressed.state = false;
|
||||||
|
|
||||||
ZMK_EVENT_RAISE(new_zmk_keycode_state_changed(data->current_keycode_pressed));
|
raise_zmk_keycode_state_changed(data->current_keycode_pressed);
|
||||||
return ZMK_BEHAVIOR_OPAQUE;
|
return ZMK_BEHAVIOR_OPAQUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
|
||||||
struct zmk_behavior_binding_event event) {
|
struct zmk_behavior_binding_event event) {
|
||||||
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
|
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
|
||||||
bool pressed = zmk_hid_is_pressed(binding->param1);
|
bool pressed = zmk_hid_is_pressed(binding->param1);
|
||||||
return ZMK_EVENT_RAISE(
|
return raise_zmk_keycode_state_changed(
|
||||||
zmk_keycode_state_changed_from_encoded(binding->param1, !pressed, event.timestamp));
|
zmk_keycode_state_changed_from_encoded(binding->param1, !pressed, event.timestamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,15 +24,15 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
|
||||||
struct zmk_behavior_binding_event event) {
|
struct zmk_behavior_binding_event event) {
|
||||||
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
|
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
|
||||||
|
|
||||||
return ZMK_EVENT_RAISE(
|
return raise_zmk_mouse_button_state_changed_from_encoded(binding->param1, true,
|
||||||
zmk_mouse_button_state_changed_from_encoded(binding->param1, true, event.timestamp));
|
event.timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
|
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
|
||||||
struct zmk_behavior_binding_event event) {
|
struct zmk_behavior_binding_event event) {
|
||||||
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
|
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
|
||||||
return ZMK_EVENT_RAISE(
|
return raise_zmk_mouse_button_state_changed_from_encoded(binding->param1, false,
|
||||||
zmk_mouse_button_state_changed_from_encoded(binding->param1, false, event.timestamp));
|
event.timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct behavior_driver_api behavior_mouse_key_press_driver_api = {
|
static const struct behavior_driver_api behavior_mouse_key_press_driver_api = {
|
||||||
|
|
|
@ -236,7 +236,9 @@ static int sticky_key_keycode_state_changed_listener(const zmk_event_t *eh) {
|
||||||
if (sticky_key->config->quick_release) {
|
if (sticky_key->config->quick_release) {
|
||||||
// immediately release the sticky key after the key press is handled.
|
// immediately release the sticky key after the key press is handled.
|
||||||
if (!event_reraised) {
|
if (!event_reraised) {
|
||||||
ZMK_EVENT_RAISE_AFTER(eh, behavior_sticky_key);
|
struct zmk_keycode_state_changed_event dupe_ev;
|
||||||
|
memcpy(&dupe_ev, eh, sizeof(struct zmk_keycode_state_changed_event));
|
||||||
|
ZMK_EVENT_RAISE_AFTER(dupe_ev, behavior_sticky_key);
|
||||||
event_reraised = true;
|
event_reraised = true;
|
||||||
}
|
}
|
||||||
release_sticky_key_behavior(sticky_key, ev_copy.timestamp);
|
release_sticky_key_behavior(sticky_key, ev_copy.timestamp);
|
||||||
|
|
|
@ -83,8 +83,8 @@ static bt_addr_le_t peripheral_addrs[ZMK_SPLIT_BLE_PERIPHERAL_COUNT];
|
||||||
#endif /* IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) */
|
#endif /* IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) */
|
||||||
|
|
||||||
static void raise_profile_changed_event(void) {
|
static void raise_profile_changed_event(void) {
|
||||||
ZMK_EVENT_RAISE(new_zmk_ble_active_profile_changed((struct zmk_ble_active_profile_changed){
|
raise_zmk_ble_active_profile_changed((struct zmk_ble_active_profile_changed){
|
||||||
.index = active_profile, .profile = &profiles[active_profile]}));
|
.index = active_profile, .profile = &profiles[active_profile]});
|
||||||
}
|
}
|
||||||
|
|
||||||
static void raise_profile_changed_event_callback(struct k_work *work) {
|
static void raise_profile_changed_event_callback(struct k_work *work) {
|
||||||
|
|
|
@ -47,7 +47,9 @@ struct active_combo {
|
||||||
// key_positions_pressed is filled with key_positions when the combo is pressed.
|
// key_positions_pressed is filled with key_positions when the combo is pressed.
|
||||||
// The keys are removed from this array when they are released.
|
// The keys are removed from this array when they are released.
|
||||||
// Once this array is empty, the behavior is released.
|
// Once this array is empty, the behavior is released.
|
||||||
const zmk_event_t *key_positions_pressed[CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO];
|
uint32_t key_positions_pressed_count;
|
||||||
|
struct zmk_position_state_changed_event
|
||||||
|
key_positions_pressed[CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct combo_candidate {
|
struct combo_candidate {
|
||||||
|
@ -58,8 +60,9 @@ struct combo_candidate {
|
||||||
int64_t timeout_at;
|
int64_t timeout_at;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uint32_t pressed_keys_count = 0;
|
||||||
// set of keys pressed
|
// set of keys pressed
|
||||||
const zmk_event_t *pressed_keys[CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO] = {NULL};
|
struct zmk_position_state_changed_event pressed_keys[CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO] = {};
|
||||||
// the set of candidate combos based on the currently pressed_keys
|
// the set of candidate combos based on the currently pressed_keys
|
||||||
struct combo_candidate candidates[CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY];
|
struct combo_candidate candidates[CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY];
|
||||||
// the last candidate that was completely pressed
|
// the last candidate that was completely pressed
|
||||||
|
@ -210,12 +213,7 @@ static inline bool candidate_is_completely_pressed(struct combo_cfg *candidate)
|
||||||
// since events may have been reraised after clearing one or more slots at
|
// since events may have been reraised after clearing one or more slots at
|
||||||
// the start of pressed_keys (see: release_pressed_keys), we have to check
|
// the start of pressed_keys (see: release_pressed_keys), we have to check
|
||||||
// that each key needed to trigger the combo was pressed, not just the last.
|
// that each key needed to trigger the combo was pressed, not just the last.
|
||||||
for (int i = 0; i < candidate->key_position_len; i++) {
|
return candidate->key_position_len == pressed_keys_count;
|
||||||
if (pressed_keys[i] == NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cleanup();
|
static int cleanup();
|
||||||
|
@ -261,38 +259,33 @@ static int clear_candidates() {
|
||||||
return CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY;
|
return CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int capture_pressed_key(const zmk_event_t *ev) {
|
static int capture_pressed_key(const struct zmk_position_state_changed *ev) {
|
||||||
for (int i = 0; i < CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO; i++) {
|
if (pressed_keys_count == CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY) {
|
||||||
if (pressed_keys[i] != NULL) {
|
return ZMK_EV_EVENT_BUBBLE;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
pressed_keys[i] = ev;
|
|
||||||
return ZMK_EV_EVENT_CAPTURED;
|
|
||||||
}
|
}
|
||||||
return ZMK_EV_EVENT_BUBBLE;
|
|
||||||
|
pressed_keys[pressed_keys_count++] = copy_raised_zmk_position_state_changed(ev);
|
||||||
|
return ZMK_EV_EVENT_CAPTURED;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct zmk_listener zmk_listener_combo;
|
const struct zmk_listener zmk_listener_combo;
|
||||||
|
|
||||||
static int release_pressed_keys() {
|
static int release_pressed_keys() {
|
||||||
for (int i = 0; i < CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO; i++) {
|
uint32_t count = pressed_keys_count;
|
||||||
const zmk_event_t *captured_event = pressed_keys[i];
|
pressed_keys_count = 0;
|
||||||
if (pressed_keys[i] == NULL) {
|
for (int i = 0; i < count; i++) {
|
||||||
return i;
|
struct zmk_position_state_changed_event ev = pressed_keys[i];
|
||||||
}
|
|
||||||
pressed_keys[i] = NULL;
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
LOG_DBG("combo: releasing position event %d",
|
LOG_DBG("combo: releasing position event %d", ev.data.position);
|
||||||
as_zmk_position_state_changed(captured_event)->position);
|
ZMK_EVENT_RELEASE(ev)
|
||||||
ZMK_EVENT_RELEASE(captured_event)
|
|
||||||
} else {
|
} else {
|
||||||
// reprocess events (see tests/combo/fully-overlapping-combos-3 for why this is needed)
|
// reprocess events (see tests/combo/fully-overlapping-combos-3 for why this is needed)
|
||||||
LOG_DBG("combo: reraising position event %d",
|
LOG_DBG("combo: reraising position event %d", ev.data.position);
|
||||||
as_zmk_position_state_changed(captured_event)->position);
|
ZMK_EVENT_RAISE(ev);
|
||||||
ZMK_EVENT_RAISE(captured_event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO;
|
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int press_combo_behavior(struct combo_cfg *combo, int32_t timestamp) {
|
static inline int press_combo_behavior(struct combo_cfg *combo, int32_t timestamp) {
|
||||||
|
@ -316,19 +309,19 @@ static inline int release_combo_behavior(struct combo_cfg *combo, int32_t timest
|
||||||
}
|
}
|
||||||
|
|
||||||
static void move_pressed_keys_to_active_combo(struct active_combo *active_combo) {
|
static void move_pressed_keys_to_active_combo(struct active_combo *active_combo) {
|
||||||
int combo_length = active_combo->combo->key_position_len;
|
|
||||||
|
int combo_length = MIN(pressed_keys_count, active_combo->combo->key_position_len);
|
||||||
for (int i = 0; i < combo_length; i++) {
|
for (int i = 0; i < combo_length; i++) {
|
||||||
active_combo->key_positions_pressed[i] = pressed_keys[i];
|
active_combo->key_positions_pressed[i] = pressed_keys[i];
|
||||||
pressed_keys[i] = NULL;
|
|
||||||
}
|
}
|
||||||
|
active_combo->key_positions_pressed_count = combo_length;
|
||||||
|
|
||||||
// move any other pressed keys up
|
// move any other pressed keys up
|
||||||
for (int i = 0; i + combo_length < CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO; i++) {
|
for (int i = 0; i + combo_length < pressed_keys_count; i++) {
|
||||||
if (pressed_keys[i + combo_length] == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pressed_keys[i] = pressed_keys[i + combo_length];
|
pressed_keys[i] = pressed_keys[i + combo_length];
|
||||||
pressed_keys[i + combo_length] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pressed_keys_count -= combo_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct active_combo *store_active_combo(struct combo_cfg *combo) {
|
static struct active_combo *store_active_combo(struct combo_cfg *combo) {
|
||||||
|
@ -353,8 +346,7 @@ static void activate_combo(struct combo_cfg *combo) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
move_pressed_keys_to_active_combo(active_combo);
|
move_pressed_keys_to_active_combo(active_combo);
|
||||||
press_combo_behavior(
|
press_combo_behavior(combo, active_combo->key_positions_pressed[0].data.timestamp);
|
||||||
combo, as_zmk_position_state_changed(active_combo->key_positions_pressed[0])->timestamp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void deactivate_combo(int active_combo_index) {
|
static void deactivate_combo(int active_combo_index) {
|
||||||
|
@ -373,22 +365,22 @@ static bool release_combo_key(int32_t position, int64_t timestamp) {
|
||||||
struct active_combo *active_combo = &active_combos[combo_idx];
|
struct active_combo *active_combo = &active_combos[combo_idx];
|
||||||
|
|
||||||
bool key_released = false;
|
bool key_released = false;
|
||||||
bool all_keys_pressed = true;
|
bool all_keys_pressed =
|
||||||
|
active_combo->key_positions_pressed_count == active_combo->combo->key_position_len;
|
||||||
bool all_keys_released = true;
|
bool all_keys_released = true;
|
||||||
for (int i = 0; i < active_combo->combo->key_position_len; i++) {
|
for (int i = 0; i < active_combo->key_positions_pressed_count; i++) {
|
||||||
if (active_combo->key_positions_pressed[i] == NULL) {
|
if (key_released) {
|
||||||
all_keys_pressed = false;
|
active_combo->key_positions_pressed[i - 1] = active_combo->key_positions_pressed[i];
|
||||||
} else if (as_zmk_position_state_changed(active_combo->key_positions_pressed[i])
|
|
||||||
->position != position) {
|
|
||||||
all_keys_released = false;
|
all_keys_released = false;
|
||||||
} else { // not null and position matches
|
} else if (active_combo->key_positions_pressed[i].data.position != position) {
|
||||||
ZMK_EVENT_FREE(active_combo->key_positions_pressed[i]);
|
all_keys_released = false;
|
||||||
active_combo->key_positions_pressed[i] = NULL;
|
} else { // position matches
|
||||||
key_released = true;
|
key_released = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key_released) {
|
if (key_released) {
|
||||||
|
active_combo->key_positions_pressed_count--;
|
||||||
if ((active_combo->combo->slow_release && all_keys_released) ||
|
if ((active_combo->combo->slow_release && all_keys_released) ||
|
||||||
(!active_combo->combo->slow_release && all_keys_pressed)) {
|
(!active_combo->combo->slow_release && all_keys_pressed)) {
|
||||||
release_combo_behavior(active_combo->combo, timestamp);
|
release_combo_behavior(active_combo->combo, timestamp);
|
||||||
|
@ -442,7 +434,7 @@ static int position_state_down(const zmk_event_t *ev, struct zmk_position_state_
|
||||||
|
|
||||||
struct combo_cfg *candidate_combo = candidates[0].combo;
|
struct combo_cfg *candidate_combo = candidates[0].combo;
|
||||||
LOG_DBG("combo: capturing position event %d", data->position);
|
LOG_DBG("combo: capturing position event %d", data->position);
|
||||||
int ret = capture_pressed_key(ev);
|
int ret = capture_pressed_key(data);
|
||||||
switch (num_candidates) {
|
switch (num_candidates) {
|
||||||
case 0:
|
case 0:
|
||||||
cleanup();
|
cleanup();
|
||||||
|
@ -469,7 +461,9 @@ static int position_state_up(const zmk_event_t *ev, struct zmk_position_state_ch
|
||||||
if (released_keys > 1) {
|
if (released_keys > 1) {
|
||||||
// The second and further key down events are re-raised. To preserve
|
// The second and further key down events are re-raised. To preserve
|
||||||
// correct order for e.g. hold-taps, reraise the key up event too.
|
// correct order for e.g. hold-taps, reraise the key up event too.
|
||||||
ZMK_EVENT_RAISE(ev);
|
struct zmk_position_state_changed_event dupe_ev =
|
||||||
|
copy_raised_zmk_position_state_changed(data);
|
||||||
|
ZMK_EVENT_RAISE(dupe_ev);
|
||||||
return ZMK_EV_EVENT_CAPTURED;
|
return ZMK_EV_EVENT_CAPTURED;
|
||||||
}
|
}
|
||||||
return ZMK_EV_EVENT_BUBBLE;
|
return ZMK_EV_EVENT_BUBBLE;
|
||||||
|
|
|
@ -346,8 +346,7 @@ static void update_current_endpoint(void) {
|
||||||
zmk_endpoint_instance_to_str(current_instance, endpoint_str, sizeof(endpoint_str));
|
zmk_endpoint_instance_to_str(current_instance, endpoint_str, sizeof(endpoint_str));
|
||||||
LOG_INF("Endpoint changed: %s", endpoint_str);
|
LOG_INF("Endpoint changed: %s", endpoint_str);
|
||||||
|
|
||||||
ZMK_EVENT_RAISE(
|
raise_zmk_endpoint_changed((struct zmk_endpoint_changed){.endpoint = current_instance});
|
||||||
new_zmk_endpoint_changed((struct zmk_endpoint_changed){.endpoint = current_instance}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,21 +32,17 @@ int zmk_event_manager_handle_from(zmk_event_t *event, uint8_t start_index) {
|
||||||
continue;
|
continue;
|
||||||
case ZMK_EV_EVENT_HANDLED:
|
case ZMK_EV_EVENT_HANDLED:
|
||||||
LOG_DBG("Listener handled the event");
|
LOG_DBG("Listener handled the event");
|
||||||
ret = 0;
|
return 0;
|
||||||
goto release;
|
|
||||||
case ZMK_EV_EVENT_CAPTURED:
|
case ZMK_EV_EVENT_CAPTURED:
|
||||||
LOG_DBG("Listener captured the event");
|
LOG_DBG("Listener captured the event");
|
||||||
// Listeners are expected to free events they capture
|
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
LOG_DBG("Listener returned an error: %d", ret);
|
LOG_DBG("Listener returned an error: %d", ret);
|
||||||
goto release;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
release:
|
return 0;
|
||||||
k_free(event);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmk_event_manager_raise(zmk_event_t *event) { return zmk_event_manager_handle_from(event, 0); }
|
int zmk_event_manager_raise(zmk_event_t *event) { return zmk_event_manager_handle_from(event, 0); }
|
||||||
|
|
|
@ -76,6 +76,7 @@ static struct zmk_behavior_binding
|
||||||
#endif /* ZMK_KEYMAP_HAS_SENSORS */
|
#endif /* ZMK_KEYMAP_HAS_SENSORS */
|
||||||
|
|
||||||
static inline int set_layer_state(uint8_t layer, bool state) {
|
static inline int set_layer_state(uint8_t layer, bool state) {
|
||||||
|
int ret = 0;
|
||||||
if (layer >= ZMK_KEYMAP_LAYERS_LEN) {
|
if (layer >= ZMK_KEYMAP_LAYERS_LEN) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -90,10 +91,13 @@ static inline int set_layer_state(uint8_t layer, bool state) {
|
||||||
// Don't send state changes unless there was an actual change
|
// Don't send state changes unless there was an actual change
|
||||||
if (old_state != _zmk_keymap_layer_state) {
|
if (old_state != _zmk_keymap_layer_state) {
|
||||||
LOG_DBG("layer_changed: layer %d state %d", layer, state);
|
LOG_DBG("layer_changed: layer %d state %d", layer, state);
|
||||||
ZMK_EVENT_RAISE(create_layer_state_changed(layer, state));
|
ret = raise_layer_state_changed(layer, state);
|
||||||
|
if (ret < 0) {
|
||||||
|
LOG_WRN("Failed to raise layer state changed (%d)", ret);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t zmk_keymap_layer_default(void) { return _zmk_keymap_layer_default; }
|
uint8_t zmk_keymap_layer_default(void) { return _zmk_keymap_layer_default; }
|
||||||
|
|
|
@ -57,11 +57,11 @@ void zmk_kscan_process_msgq(struct k_work *item) {
|
||||||
|
|
||||||
LOG_DBG("Row: %d, col: %d, position: %d, pressed: %s", ev.row, ev.column, position,
|
LOG_DBG("Row: %d, col: %d, position: %d, pressed: %s", ev.row, ev.column, position,
|
||||||
(pressed ? "true" : "false"));
|
(pressed ? "true" : "false"));
|
||||||
ZMK_EVENT_RAISE(new_zmk_position_state_changed(
|
raise_zmk_position_state_changed(
|
||||||
(struct zmk_position_state_changed){.source = ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL,
|
(struct zmk_position_state_changed){.source = ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL,
|
||||||
.state = pressed,
|
.state = pressed,
|
||||||
.position = position,
|
.position = position,
|
||||||
.timestamp = k_uptime_get()}));
|
.timestamp = k_uptime_get()});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,12 +87,12 @@ static void trigger_sensor_data_for_position(uint32_t sensor_index) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZMK_EVENT_RAISE(new_zmk_sensor_event(
|
raise_zmk_sensor_event(
|
||||||
(struct zmk_sensor_event){.sensor_index = item->sensor_index,
|
(struct zmk_sensor_event){.sensor_index = item->sensor_index,
|
||||||
.channel_data_size = 1,
|
.channel_data_size = 1,
|
||||||
.channel_data = {(struct zmk_sensor_channel_data){
|
.channel_data = {(struct zmk_sensor_channel_data){
|
||||||
.value = value, .channel = item->trigger.chan}},
|
.value = value, .channel = item->trigger.chan}},
|
||||||
.timestamp = k_uptime_get()}));
|
.timestamp = k_uptime_get()});
|
||||||
}
|
}
|
||||||
|
|
||||||
static void run_sensors_data_trigger(struct k_work *work) {
|
static void run_sensors_data_trigger(struct k_work *work) {
|
||||||
|
|
|
@ -72,7 +72,7 @@ void peripheral_event_work_callback(struct k_work *work) {
|
||||||
struct zmk_position_state_changed ev;
|
struct zmk_position_state_changed ev;
|
||||||
while (k_msgq_get(&peripheral_event_msgq, &ev, K_NO_WAIT) == 0) {
|
while (k_msgq_get(&peripheral_event_msgq, &ev, K_NO_WAIT) == 0) {
|
||||||
LOG_DBG("Trigger key position state change for %d", ev.position);
|
LOG_DBG("Trigger key position state change for %d", ev.position);
|
||||||
ZMK_EVENT_RAISE(new_zmk_position_state_changed(ev));
|
raise_zmk_position_state_changed(ev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ void peripheral_sensor_event_work_callback(struct k_work *work) {
|
||||||
struct zmk_sensor_event ev;
|
struct zmk_sensor_event ev;
|
||||||
while (k_msgq_get(&peripheral_sensor_event_msgq, &ev, K_NO_WAIT) == 0) {
|
while (k_msgq_get(&peripheral_sensor_event_msgq, &ev, K_NO_WAIT) == 0) {
|
||||||
LOG_DBG("Trigger sensor change for %d", ev.sensor_index);
|
LOG_DBG("Trigger sensor change for %d", ev.sensor_index);
|
||||||
ZMK_EVENT_RAISE(new_zmk_sensor_event(ev));
|
raise_zmk_sensor_event(ev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,8 +83,8 @@ K_WORK_DEFINE(advertising_work, advertising_cb);
|
||||||
static void connected(struct bt_conn *conn, uint8_t err) {
|
static void connected(struct bt_conn *conn, uint8_t err) {
|
||||||
is_connected = (err == 0);
|
is_connected = (err == 0);
|
||||||
|
|
||||||
ZMK_EVENT_RAISE(new_zmk_split_peripheral_status_changed(
|
raise_zmk_split_peripheral_status_changed(
|
||||||
(struct zmk_split_peripheral_status_changed){.connected = is_connected}));
|
(struct zmk_split_peripheral_status_changed){.connected = is_connected});
|
||||||
|
|
||||||
if (err == BT_HCI_ERR_ADV_TIMEOUT) {
|
if (err == BT_HCI_ERR_ADV_TIMEOUT) {
|
||||||
low_duty_advertising = true;
|
low_duty_advertising = true;
|
||||||
|
@ -101,8 +101,8 @@ static void disconnected(struct bt_conn *conn, uint8_t reason) {
|
||||||
|
|
||||||
is_connected = false;
|
is_connected = false;
|
||||||
|
|
||||||
ZMK_EVENT_RAISE(new_zmk_split_peripheral_status_changed(
|
raise_zmk_split_peripheral_status_changed(
|
||||||
(struct zmk_split_peripheral_status_changed){.connected = is_connected}));
|
(struct zmk_split_peripheral_status_changed){.connected = is_connected});
|
||||||
|
|
||||||
low_duty_advertising = false;
|
low_duty_advertising = false;
|
||||||
k_work_submit(&advertising_work);
|
k_work_submit(&advertising_work);
|
||||||
|
|
|
@ -22,8 +22,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||||
static enum usb_dc_status_code usb_status = USB_DC_UNKNOWN;
|
static enum usb_dc_status_code usb_status = USB_DC_UNKNOWN;
|
||||||
|
|
||||||
static void raise_usb_status_changed_event(struct k_work *_work) {
|
static void raise_usb_status_changed_event(struct k_work *_work) {
|
||||||
ZMK_EVENT_RAISE(new_zmk_usb_conn_state_changed(
|
raise_zmk_usb_conn_state_changed(
|
||||||
(struct zmk_usb_conn_state_changed){.conn_state = zmk_usb_get_conn_state()}));
|
(struct zmk_usb_conn_state_changed){.conn_state = zmk_usb_get_conn_state()});
|
||||||
}
|
}
|
||||||
|
|
||||||
K_WORK_DEFINE(usb_status_notifier_work, raise_usb_status_changed_event);
|
K_WORK_DEFINE(usb_status_notifier_work, raise_usb_status_changed_event);
|
||||||
|
|
|
@ -54,8 +54,7 @@ void wpm_work_handler(struct k_work *work) {
|
||||||
if (last_wpm_state != wpm_state) {
|
if (last_wpm_state != wpm_state) {
|
||||||
LOG_DBG("Raised WPM state changed %d wpm_update_counter %d", wpm_state, wpm_update_counter);
|
LOG_DBG("Raised WPM state changed %d wpm_update_counter %d", wpm_state, wpm_update_counter);
|
||||||
|
|
||||||
ZMK_EVENT_RAISE(
|
raise_zmk_wpm_state_changed((struct zmk_wpm_state_changed){.state = wpm_state});
|
||||||
new_zmk_wpm_state_changed((struct zmk_wpm_state_changed){.state = wpm_state}));
|
|
||||||
|
|
||||||
last_wpm_state = wpm_state;
|
last_wpm_state = wpm_state;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue