From 3fe2acc2d191006fa6309191ee99b2e4e249ed08 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Mon, 18 Jan 2021 00:35:56 -0500 Subject: refactor(core): Extra event payloads to own types, refactor API. * Make it easier to use *just* event payloads by defining the data, and then having event manager macros generate "wrapper structs" * Improve is_*/cast_* APIs to hide details of full event struct. * Create `zmk_event_t` typedef to pass to event handlers. * Bring event names inline w/ consistent `zmk_` prefix. --- app/src/activity.c | 11 ++-- app/src/battery.c | 5 +- app/src/behaviors/behavior_hold_tap.c | 73 +++++++++++----------- app/src/behaviors/behavior_key_press.c | 4 +- .../behaviors/behavior_sensor_rotate_key_press.c | 4 +- app/src/behaviors/behavior_sticky_key.c | 8 +-- app/src/ble.c | 7 +-- app/src/combo.c | 40 ++++++------ app/src/display/main.c | 6 +- app/src/display/widgets/battery_status.c | 6 +- app/src/display/widgets/layer_status.c | 4 +- app/src/display/widgets/output_status.c | 6 +- app/src/endpoints.c | 6 +- app/src/event_manager.c | 14 ++--- app/src/events/activity_state_changed.c | 2 +- app/src/events/battery_state_changed.c | 2 +- app/src/events/ble_active_profile_changed.c | 2 +- app/src/events/keycode_state_changed.c | 2 +- app/src/events/layer_state_changed.c | 2 +- app/src/events/modifiers_state_changed.c | 2 +- app/src/events/position_state_changed.c | 2 +- app/src/events/sensor_event.c | 2 +- app/src/events/usb_conn_state_changed.c | 2 +- app/src/hid_listener.c | 8 +-- app/src/keymap.c | 17 +++-- app/src/kscan.c | 7 +-- app/src/sensors.c | 9 +-- app/src/split/bluetooth/central.c | 11 ++-- app/src/split_listener.c | 14 ++--- app/src/usb.c | 6 +- 30 files changed, 133 insertions(+), 151 deletions(-) (limited to 'app/src') diff --git a/app/src/activity.c b/app/src/activity.c index 8fe912a..0661b27 100644 --- a/app/src/activity.c +++ b/app/src/activity.c @@ -29,7 +29,10 @@ static uint32_t activity_last_uptime; #define MAX_SLEEP_MS CONFIG_ZMK_IDLE_SLEEP_TIMEOUT #endif -int raise_event() { return ZMK_EVENT_RAISE(create_activity_state_changed(activity_state)); } +int raise_event() { + return ZMK_EVENT_RAISE(new_zmk_activity_state_changed( + (struct zmk_activity_state_changed){.state = activity_state})); +} int set_state(enum zmk_activity_state state) { if (activity_state == state) @@ -41,7 +44,7 @@ int set_state(enum zmk_activity_state state) { enum zmk_activity_state zmk_activity_get_state() { return activity_state; } -int activity_event_listener(const struct zmk_event_header *eh) { +int activity_event_listener(const zmk_event_t *eh) { activity_last_uptime = k_uptime_get(); return set_state(ZMK_ACTIVITY_ACTIVE); @@ -74,7 +77,7 @@ int activity_init() { } ZMK_LISTENER(activity, activity_event_listener); -ZMK_SUBSCRIPTION(activity, position_state_changed); -ZMK_SUBSCRIPTION(activity, sensor_event); +ZMK_SUBSCRIPTION(activity, zmk_position_state_changed); +ZMK_SUBSCRIPTION(activity, zmk_sensor_event); SYS_INIT(activity_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); diff --git a/app/src/battery.c b/app/src/battery.c index 917af9c..5a7c57b 100644 --- a/app/src/battery.c +++ b/app/src/battery.c @@ -45,9 +45,8 @@ static int zmk_battery_update(const struct device *battery) { return rc; } - struct battery_state_changed *ev = new_battery_state_changed(); - ev->state_of_charge = state_of_charge.val1; - return ZMK_EVENT_RAISE(ev); + return ZMK_EVENT_RAISE(new_zmk_battery_state_changed( + (struct zmk_battery_state_changed){.state_of_charge = state_of_charge.val1})); } static void zmk_battery_work(struct k_work *work) { diff --git a/app/src/behaviors/behavior_hold_tap.c b/app/src/behaviors/behavior_hold_tap.c index 43bf92c..01851e9 100644 --- a/app/src/behaviors/behavior_hold_tap.c +++ b/app/src/behaviors/behavior_hold_tap.c @@ -69,9 +69,9 @@ struct active_hold_tap { struct active_hold_tap *undecided_hold_tap = NULL; 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. -const struct zmk_event_header *captured_events[ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS] = {}; +const zmk_event_t *captured_events[ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS] = {}; -static int capture_event(const struct zmk_event_header *event) { +static int capture_event(const zmk_event_t *event) { for (int i = 0; i < ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS; i++) { if (captured_events[i] == NULL) { captured_events[i] = event; @@ -81,18 +81,18 @@ static int capture_event(const struct zmk_event_header *event) { return -ENOMEM; } -static struct position_state_changed *find_captured_keydown_event(uint32_t position) { - struct position_state_changed *last_match = NULL; +static struct zmk_position_state_changed *find_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++) { - const struct zmk_event_header *eh = captured_events[i]; + const zmk_event_t *eh = captured_events[i]; if (eh == NULL) { return last_match; } - if (!is_position_state_changed(eh)) { + if (!is_zmk_position_state_changed(eh)) { continue; } - struct position_state_changed *position_event = cast_position_state_changed(eh); - if (position_event->data.position == position && position_event->data.state) { + struct zmk_position_state_changed *position_event = cast_zmk_position_state_changed(eh); + if (position_event->position == position && position_event->state) { last_match = position_event; } } @@ -132,7 +132,7 @@ static void release_captured_events() { // [k1_down, k1_up, null, null, null, ...] // now mt2 will start releasing it's own captured positions. for (int i = 0; i < ZMK_BHV_HOLD_TAP_MAX_CAPTURED_EVENTS; i++) { - const struct zmk_event_header *captured_event = captured_events[i]; + const zmk_event_t *captured_event = captured_events[i]; if (captured_event == NULL) { return; } @@ -140,15 +140,14 @@ static void release_captured_events() { if (undecided_hold_tap != NULL) { k_msleep(10); } - if (is_position_state_changed(captured_event)) { - struct position_state_changed *position_event = - cast_position_state_changed(captured_event); - LOG_DBG("Releasing key position event for position %d %s", - position_event->data.position, - (position_event->data.state ? "pressed" : "released")); + if (is_zmk_position_state_changed(captured_event)) { + struct zmk_position_state_changed *position_event = + cast_zmk_position_state_changed(captured_event); + LOG_DBG("Releasing key position event for position %d %s", position_event->position, + (position_event->state ? "pressed" : "released")); } else { - struct keycode_state_changed *modifier_event = - cast_keycode_state_changed(captured_event); + struct zmk_keycode_state_changed *modifier_event = + cast_zmk_keycode_state_changed(captured_event); LOG_DBG("Releasing mods changed event 0x%02X %s", modifier_event->keycode, (modifier_event->state ? "pressed" : "released")); } @@ -388,16 +387,16 @@ static const struct behavior_driver_api behavior_hold_tap_driver_api = { .binding_released = on_hold_tap_binding_released, }; -static int position_state_changed_listener(const struct zmk_event_header *eh) { - struct position_state_changed *ev = cast_position_state_changed(eh); +static int position_state_changed_listener(const zmk_event_t *eh) { + struct zmk_position_state_changed *ev = cast_zmk_position_state_changed(eh); if (undecided_hold_tap == NULL) { - LOG_DBG("%d bubble (no undecided hold_tap active)", ev->data.position); + LOG_DBG("%d bubble (no undecided hold_tap active)", ev->position); return ZMK_EV_EVENT_BUBBLE; } - if (undecided_hold_tap->position == ev->data.position) { - if (ev->data.state) { // keydown + if (undecided_hold_tap->position == ev->position) { + if (ev->state) { // keydown LOG_ERR("hold-tap listener should be called before before most other listeners!"); return ZMK_EV_EVENT_BUBBLE; } else { // keyup @@ -409,34 +408,34 @@ static int position_state_changed_listener(const struct zmk_event_header *eh) { // If these events were queued, the timer event may be queued too late or not at all. // We make a timer decision before the other key events are handled if the timer would // have run out. - if (ev->data.timestamp > + if (ev->timestamp > (undecided_hold_tap->timestamp + undecided_hold_tap->config->tapping_term_ms)) { decide_hold_tap(undecided_hold_tap, HT_TIMER_EVENT); } - if (!ev->data.state && find_captured_keydown_event(ev->data.position) == NULL) { + if (!ev->state && find_captured_keydown_event(ev->position) == NULL) { // no keydown event has been captured, let it bubble. // we'll catch modifiers later in modifier_state_changed_listener - LOG_DBG("%d bubbling %d %s event", undecided_hold_tap->position, ev->data.position, - ev->data.state ? "down" : "up"); + LOG_DBG("%d bubbling %d %s event", undecided_hold_tap->position, ev->position, + ev->state ? "down" : "up"); return ZMK_EV_EVENT_BUBBLE; } - LOG_DBG("%d capturing %d %s event", undecided_hold_tap->position, ev->data.position, - ev->data.state ? "down" : "up"); + LOG_DBG("%d capturing %d %s event", undecided_hold_tap->position, ev->position, + ev->state ? "down" : "up"); capture_event(eh); - decide_hold_tap(undecided_hold_tap, ev->data.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; } -static inline bool only_mods(struct keycode_state_changed *ev) { +static inline bool only_mods(struct zmk_keycode_state_changed *ev) { return ev->usage_page == HID_USAGE_KEY && ev->keycode >= HID_USAGE_KEY_KEYBOARD_LEFTCONTROL && ev->keycode <= HID_USAGE_KEY_KEYBOARD_RIGHT_GUI; } -static int keycode_state_changed_listener(const struct zmk_event_header *eh) { +static int keycode_state_changed_listener(const zmk_event_t *eh) { // we want to catch layer-up events too... how? - struct keycode_state_changed *ev = cast_keycode_state_changed(eh); + struct zmk_keycode_state_changed *ev = cast_zmk_keycode_state_changed(eh); if (undecided_hold_tap == NULL) { // LOG_DBG("0x%02X bubble (no undecided hold_tap active)", ev->keycode); @@ -456,19 +455,19 @@ static int keycode_state_changed_listener(const struct zmk_event_header *eh) { return ZMK_EV_EVENT_CAPTURED; } -int behavior_hold_tap_listener(const struct zmk_event_header *eh) { - if (is_position_state_changed(eh)) { +int behavior_hold_tap_listener(const zmk_event_t *eh) { + if (is_zmk_position_state_changed(eh)) { return position_state_changed_listener(eh); - } else if (is_keycode_state_changed(eh)) { + } else if (is_zmk_keycode_state_changed(eh)) { return keycode_state_changed_listener(eh); } return ZMK_EV_EVENT_BUBBLE; } ZMK_LISTENER(behavior_hold_tap, behavior_hold_tap_listener); -ZMK_SUBSCRIPTION(behavior_hold_tap, position_state_changed); +ZMK_SUBSCRIPTION(behavior_hold_tap, zmk_position_state_changed); // this should be modifiers_state_changed, but unfrotunately that's not implemented yet. -ZMK_SUBSCRIPTION(behavior_hold_tap, keycode_state_changed); +ZMK_SUBSCRIPTION(behavior_hold_tap, zmk_keycode_state_changed); void behavior_hold_tap_timer_work_handler(struct k_work *item) { struct active_hold_tap *hold_tap = CONTAINER_OF(item, struct active_hold_tap, work); diff --git a/app/src/behaviors/behavior_key_press.c b/app/src/behaviors/behavior_key_press.c index df0828a..8282977 100644 --- a/app/src/behaviors/behavior_key_press.c +++ b/app/src/behaviors/behavior_key_press.c @@ -22,14 +22,14 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, struct zmk_behavior_binding_event event) { LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1); return ZMK_EVENT_RAISE( - 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, struct zmk_behavior_binding_event event) { LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1); return ZMK_EVENT_RAISE( - keycode_state_changed_from_encoded(binding->param1, false, event.timestamp)); + zmk_keycode_state_changed_from_encoded(binding->param1, false, event.timestamp)); } static const struct behavior_driver_api behavior_key_press_driver_api = { diff --git a/app/src/behaviors/behavior_sensor_rotate_key_press.c b/app/src/behaviors/behavior_sensor_rotate_key_press.c index 1e659a1..67a2e71 100644 --- a/app/src/behaviors/behavior_sensor_rotate_key_press.c +++ b/app/src/behaviors/behavior_sensor_rotate_key_press.c @@ -45,12 +45,12 @@ static int on_sensor_binding_triggered(struct zmk_behavior_binding *binding, LOG_DBG("SEND %d", keycode); - ZMK_EVENT_RAISE(keycode_state_changed_from_encoded(keycode, true, timestamp)); + ZMK_EVENT_RAISE(zmk_keycode_state_changed_from_encoded(keycode, true, timestamp)); // TODO: Better way to do this? k_msleep(5); - return ZMK_EVENT_RAISE(keycode_state_changed_from_encoded(keycode, false, timestamp)); + return ZMK_EVENT_RAISE(zmk_keycode_state_changed_from_encoded(keycode, false, timestamp)); } static const struct behavior_driver_api behavior_sensor_rotate_key_press_driver_api = { diff --git a/app/src/behaviors/behavior_sticky_key.c b/app/src/behaviors/behavior_sticky_key.c index 15c9e21..ee33d38 100644 --- a/app/src/behaviors/behavior_sticky_key.c +++ b/app/src/behaviors/behavior_sticky_key.c @@ -175,11 +175,11 @@ static const struct behavior_driver_api behavior_sticky_key_driver_api = { .binding_released = on_sticky_key_binding_released, }; -static int sticky_key_keycode_state_changed_listener(const struct zmk_event_header *eh) { - if (!is_keycode_state_changed(eh)) { +static int sticky_key_keycode_state_changed_listener(const zmk_event_t *eh) { + if (!is_zmk_keycode_state_changed(eh)) { return ZMK_EV_EVENT_BUBBLE; } - struct keycode_state_changed *ev = cast_keycode_state_changed(eh); + struct zmk_keycode_state_changed *ev = cast_zmk_keycode_state_changed(eh); for (int i = 0; i < ZMK_BHV_STICKY_KEY_MAX_HELD; i++) { struct active_sticky_key *sticky_key = &active_sticky_keys[i]; if (sticky_key->position == ZMK_BHV_STICKY_KEY_POSITION_FREE) { @@ -226,7 +226,7 @@ static int sticky_key_keycode_state_changed_listener(const struct zmk_event_head } ZMK_LISTENER(behavior_sticky_key, sticky_key_keycode_state_changed_listener); -ZMK_SUBSCRIPTION(behavior_sticky_key, keycode_state_changed); +ZMK_SUBSCRIPTION(behavior_sticky_key, zmk_keycode_state_changed); void behavior_sticky_key_timer_handler(struct k_work *item) { struct active_sticky_key *sticky_key = diff --git a/app/src/ble.c b/app/src/ble.c index 3a115cf..e8d2c42 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -92,11 +92,8 @@ static bt_addr_le_t peripheral_addr; #endif /* IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) */ static void raise_profile_changed_event() { - struct ble_active_profile_changed *ev = new_ble_active_profile_changed(); - ev->index = active_profile; - ev->profile = &profiles[active_profile]; - - ZMK_EVENT_RAISE(ev); + ZMK_EVENT_RAISE(new_zmk_ble_active_profile_changed((struct zmk_ble_active_profile_changed){ + .index = active_profile, .profile = &profiles[active_profile]})); } static void raise_profile_changed_event_callback(struct k_work *work) { diff --git a/app/src/combo.c b/app/src/combo.c index 4963870..a08a2f5 100644 --- a/app/src/combo.c +++ b/app/src/combo.c @@ -40,7 +40,7 @@ struct active_combo { // key_positions_pressed is filled with key_positions when the combo is pressed. // The keys are removed from this array when they are released. // Once this array is empty, the behavior is released. - struct position_state_changed *key_positions_pressed[CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO]; + const zmk_event_t *key_positions_pressed[CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO]; }; struct combo_candidate { @@ -52,7 +52,7 @@ struct combo_candidate { }; // set of keys pressed -struct position_state_changed *pressed_keys[CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO] = {NULL}; +const zmk_event_t *pressed_keys[CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO] = {NULL}; // the set of candidate combos based on the currently pressed_keys struct combo_candidate candidates[CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY]; // the last candidate that was completely pressed @@ -202,7 +202,7 @@ static int clear_candidates() { return CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY; } -static int capture_pressed_key(struct position_state_changed *ev) { +static int capture_pressed_key(const zmk_event_t *ev) { for (int i = 0; i < CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY; i++) { if (pressed_keys[i] != NULL) { continue; @@ -228,7 +228,7 @@ static void release_pressed_keys() { if (pressed_keys[i] == NULL) { return; } - struct position_state_changed *captured_event = pressed_keys[i]; + const zmk_event_t *captured_event = pressed_keys[i]; pressed_keys[i] = NULL; ZMK_EVENT_RAISE(captured_event); } @@ -290,7 +290,8 @@ static void activate_combo(struct combo_cfg *combo) { return; } move_pressed_keys_to_active_combo(active_combo); - press_combo_behavior(combo, active_combo->key_positions_pressed[0]->timestamp); + press_combo_behavior( + combo, cast_zmk_position_state_changed(active_combo->key_positions_pressed[0])->timestamp); } static void deactivate_combo(int active_combo_index) { @@ -314,10 +315,11 @@ static bool release_combo_key(int32_t position, int64_t timestamp) { for (int i = 0; i < active_combo->combo->key_position_len; i++) { if (active_combo->key_positions_pressed[i] == NULL) { all_keys_pressed = false; - } else if (active_combo->key_positions_pressed[i]->position != position) { + } else if (cast_zmk_position_state_changed(active_combo->key_positions_pressed[i]) + ->position != position) { all_keys_released = false; } else { // not null and position matches - k_free(active_combo->key_positions_pressed[i]); + ZMK_EVENT_FREE(active_combo->key_positions_pressed[i]); active_combo->key_positions_pressed[i] = NULL; key_released = true; } @@ -362,16 +364,16 @@ static void update_timeout_task() { } } -static int position_state_down(struct position_state_changed *ev) { +static int position_state_down(const zmk_event_t *ev, struct zmk_position_state_changed *data) { int num_candidates; if (candidates[0].combo == NULL) { - num_candidates = setup_candidates_for_first_keypress(ev->position, ev->timestamp); + num_candidates = setup_candidates_for_first_keypress(data->position, data->timestamp); if (num_candidates == 0) { return 0; } } else { - filter_timed_out_candidates(ev->timestamp); - num_candidates = filter_candidates(ev->position); + filter_timed_out_candidates(data->timestamp); + num_candidates = filter_candidates(data->position); } update_timeout_task(); @@ -395,7 +397,7 @@ static int position_state_down(struct position_state_changed *ev) { } } -static int position_state_up(struct position_state_changed *ev) { +static int position_state_up(struct zmk_position_state_changed *ev) { cleanup(); if (release_combo_key(ev->position, ev->timestamp)) { return ZMK_EV_EVENT_HANDLED; @@ -415,21 +417,21 @@ static void combo_timeout_handler(struct k_work *item) { update_timeout_task(); } -static int position_state_changed_listener(const struct zmk_event_header *eh) { - if (!is_position_state_changed(eh)) { +static int position_state_changed_listener(const zmk_event_t *ev) { + if (!is_zmk_position_state_changed(ev)) { return 0; } - struct position_state_changed *ev = cast_position_state_changed(eh); - if (ev->state) { // keydown - return position_state_down(ev); + struct zmk_position_state_changed *data = cast_zmk_position_state_changed(ev); + if (data->state) { // keydown + return position_state_down(ev, data); } else { // keyup - return position_state_up(ev); + return position_state_up(data); } } ZMK_LISTENER(combo, position_state_changed_listener); -ZMK_SUBSCRIPTION(combo, position_state_changed); +ZMK_SUBSCRIPTION(combo, zmk_position_state_changed); // todo: remove this once #506 is merged and #include #define KEY_BINDING_TO_STRUCT(idx, drv_inst) \ diff --git a/app/src/display/main.c b/app/src/display/main.c index 0bef656..90789f9 100644 --- a/app/src/display/main.c +++ b/app/src/display/main.c @@ -75,8 +75,8 @@ int zmk_display_init() { return 0; } -int display_event_handler(const struct zmk_event_header *eh) { - struct activity_state_changed *ev = cast_activity_state_changed(eh); +int display_event_handler(const zmk_event_t *eh) { + struct zmk_activity_state_changed *ev = cast_zmk_activity_state_changed(eh); switch (ev->state) { case ZMK_ACTIVITY_ACTIVE: start_display_updates(); @@ -93,4 +93,4 @@ int display_event_handler(const struct zmk_event_header *eh) { } ZMK_LISTENER(display, display_event_handler); -ZMK_SUBSCRIPTION(display, activity_state_changed); \ No newline at end of file +ZMK_SUBSCRIPTION(display, zmk_activity_state_changed); \ No newline at end of file diff --git a/app/src/display/widgets/battery_status.c b/app/src/display/widgets/battery_status.c index f1f1c9f..309c3e9 100644 --- a/app/src/display/widgets/battery_status.c +++ b/app/src/display/widgets/battery_status.c @@ -75,14 +75,14 @@ lv_obj_t *zmk_widget_battery_status_obj(struct zmk_widget_battery_status *widget return widget->obj; } -int battery_status_listener(const struct zmk_event_header *eh) { +int battery_status_listener(const zmk_event_t *eh) { struct zmk_widget_battery_status *widget; SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_battery_symbol(widget->obj); } return ZMK_EV_EVENT_BUBBLE; } ZMK_LISTENER(widget_battery_status, battery_status_listener) -ZMK_SUBSCRIPTION(widget_battery_status, battery_state_changed); +ZMK_SUBSCRIPTION(widget_battery_status, zmk_battery_state_changed); #if IS_ENABLED(CONFIG_USB) -ZMK_SUBSCRIPTION(widget_battery_status, usb_conn_state_changed); +ZMK_SUBSCRIPTION(widget_battery_status, zmk_usb_conn_state_changed); #endif /* IS_ENABLED(CONFIG_USB) */ diff --git a/app/src/display/widgets/layer_status.c b/app/src/display/widgets/layer_status.c index 6700bb3..9960f2a 100644 --- a/app/src/display/widgets/layer_status.c +++ b/app/src/display/widgets/layer_status.c @@ -69,11 +69,11 @@ lv_obj_t *zmk_widget_layer_status_obj(struct zmk_widget_layer_status *widget) { return widget->obj; } -int layer_status_listener(const struct zmk_event_header *eh) { +int layer_status_listener(const zmk_event_t *eh) { struct zmk_widget_layer_status *widget; SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_layer_symbol(widget->obj); } return 0; } ZMK_LISTENER(widget_layer_status, layer_status_listener) -ZMK_SUBSCRIPTION(widget_layer_status, layer_state_changed); \ No newline at end of file +ZMK_SUBSCRIPTION(widget_layer_status, zmk_layer_state_changed); \ No newline at end of file diff --git a/app/src/display/widgets/output_status.c b/app/src/display/widgets/output_status.c index 716228b..7e37f90 100644 --- a/app/src/display/widgets/output_status.c +++ b/app/src/display/widgets/output_status.c @@ -79,7 +79,7 @@ lv_obj_t *zmk_widget_output_status_obj(struct zmk_widget_output_status *widget) return widget->obj; } -int output_status_listener(const struct zmk_event_header *eh) { +int output_status_listener(const zmk_event_t *eh) { struct zmk_widget_output_status *widget; SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_status_symbol(widget->obj); } return ZMK_EV_EVENT_BUBBLE; @@ -87,8 +87,8 @@ int output_status_listener(const struct zmk_event_header *eh) { ZMK_LISTENER(widget_output_status, output_status_listener) #if defined(CONFIG_USB) -ZMK_SUBSCRIPTION(widget_output_status, usb_conn_state_changed); +ZMK_SUBSCRIPTION(widget_output_status, zmk_usb_conn_state_changed); #endif #if defined(CONFIG_ZMK_BLE) -ZMK_SUBSCRIPTION(widget_output_status, ble_active_profile_changed); +ZMK_SUBSCRIPTION(widget_output_status, zmk_ble_active_profile_changed); #endif diff --git a/app/src/endpoints.c b/app/src/endpoints.c index feff799..93dfb81 100644 --- a/app/src/endpoints.c +++ b/app/src/endpoints.c @@ -245,17 +245,17 @@ static void update_current_endpoint() { } } -static int endpoint_listener(const struct zmk_event_header *eh) { +static int endpoint_listener(const zmk_event_t *eh) { update_current_endpoint(); return 0; } ZMK_LISTENER(endpoint_listener, endpoint_listener); #if IS_ENABLED(CONFIG_ZMK_USB) -ZMK_SUBSCRIPTION(endpoint_listener, usb_conn_state_changed); +ZMK_SUBSCRIPTION(endpoint_listener, zmk_usb_conn_state_changed); #endif #if IS_ENABLED(CONFIG_ZMK_BLE) -ZMK_SUBSCRIPTION(endpoint_listener, ble_active_profile_changed); +ZMK_SUBSCRIPTION(endpoint_listener, zmk_ble_active_profile_changed); #endif SYS_INIT(zmk_endpoints_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); diff --git a/app/src/event_manager.c b/app/src/event_manager.c index 872f5c8..0399ca8 100644 --- a/app/src/event_manager.c +++ b/app/src/event_manager.c @@ -17,7 +17,7 @@ extern struct zmk_event_type *__event_type_end[]; extern struct zmk_event_subscription __event_subscriptions_start[]; extern struct zmk_event_subscription __event_subscriptions_end[]; -int zmk_event_manager_handle_from(struct zmk_event_header *event, uint8_t start_index) { +int zmk_event_manager_handle_from(zmk_event_t *event, uint8_t start_index) { int ret = 0; uint8_t len = __event_subscriptions_end - __event_subscriptions_start; for (int i = start_index; i < len; i++) { @@ -48,12 +48,9 @@ release: return ret; } -int zmk_event_manager_raise(struct zmk_event_header *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); } -int zmk_event_manager_raise_after(struct zmk_event_header *event, - const struct zmk_listener *listener) { +int zmk_event_manager_raise_after(zmk_event_t *event, const struct zmk_listener *listener) { uint8_t len = __event_subscriptions_end - __event_subscriptions_start; for (int i = 0; i < len; i++) { struct zmk_event_subscription *ev_sub = __event_subscriptions_start + i; @@ -68,8 +65,7 @@ int zmk_event_manager_raise_after(struct zmk_event_header *event, return -EINVAL; } -int zmk_event_manager_raise_at(struct zmk_event_header *event, - const struct zmk_listener *listener) { +int zmk_event_manager_raise_at(zmk_event_t *event, const struct zmk_listener *listener) { uint8_t len = __event_subscriptions_end - __event_subscriptions_start; for (int i = 0; i < len; i++) { struct zmk_event_subscription *ev_sub = __event_subscriptions_start + i; @@ -84,6 +80,6 @@ int zmk_event_manager_raise_at(struct zmk_event_header *event, return -EINVAL; } -int zmk_event_manager_release(struct zmk_event_header *event) { +int zmk_event_manager_release(zmk_event_t *event) { return zmk_event_manager_handle_from(event, event->last_listener_index + 1); } diff --git a/app/src/events/activity_state_changed.c b/app/src/events/activity_state_changed.c index 001e6a1..2c27ce7 100644 --- a/app/src/events/activity_state_changed.c +++ b/app/src/events/activity_state_changed.c @@ -7,4 +7,4 @@ #include #include -ZMK_EVENT_IMPL(activity_state_changed); \ No newline at end of file +ZMK_EVENT_IMPL(zmk_activity_state_changed); \ No newline at end of file diff --git a/app/src/events/battery_state_changed.c b/app/src/events/battery_state_changed.c index ed6147a..435fb24 100644 --- a/app/src/events/battery_state_changed.c +++ b/app/src/events/battery_state_changed.c @@ -7,4 +7,4 @@ #include #include -ZMK_EVENT_IMPL(battery_state_changed); \ No newline at end of file +ZMK_EVENT_IMPL(zmk_battery_state_changed); \ No newline at end of file diff --git a/app/src/events/ble_active_profile_changed.c b/app/src/events/ble_active_profile_changed.c index e2d172f..c4887f7 100644 --- a/app/src/events/ble_active_profile_changed.c +++ b/app/src/events/ble_active_profile_changed.c @@ -7,4 +7,4 @@ #include #include -ZMK_EVENT_IMPL(ble_active_profile_changed); \ No newline at end of file +ZMK_EVENT_IMPL(zmk_ble_active_profile_changed); \ No newline at end of file diff --git a/app/src/events/keycode_state_changed.c b/app/src/events/keycode_state_changed.c index d46126b..c9ef6aa 100644 --- a/app/src/events/keycode_state_changed.c +++ b/app/src/events/keycode_state_changed.c @@ -7,4 +7,4 @@ #include #include -ZMK_EVENT_IMPL(keycode_state_changed); +ZMK_EVENT_IMPL(zmk_keycode_state_changed); diff --git a/app/src/events/layer_state_changed.c b/app/src/events/layer_state_changed.c index e7f8039..bd6234c 100644 --- a/app/src/events/layer_state_changed.c +++ b/app/src/events/layer_state_changed.c @@ -7,4 +7,4 @@ #include #include -ZMK_EVENT_IMPL(layer_state_changed); \ No newline at end of file +ZMK_EVENT_IMPL(zmk_layer_state_changed); \ No newline at end of file diff --git a/app/src/events/modifiers_state_changed.c b/app/src/events/modifiers_state_changed.c index 4143796..3dfea25 100644 --- a/app/src/events/modifiers_state_changed.c +++ b/app/src/events/modifiers_state_changed.c @@ -7,4 +7,4 @@ #include #include -ZMK_EVENT_IMPL(modifiers_state_changed); \ No newline at end of file +ZMK_EVENT_IMPL(zmk_modifiers_state_changed); \ No newline at end of file diff --git a/app/src/events/position_state_changed.c b/app/src/events/position_state_changed.c index b80314b..bb40584 100644 --- a/app/src/events/position_state_changed.c +++ b/app/src/events/position_state_changed.c @@ -7,4 +7,4 @@ #include #include -ZMK_EVENT_IMPL(position_state_changed); \ No newline at end of file +ZMK_EVENT_IMPL(zmk_position_state_changed); \ No newline at end of file diff --git a/app/src/events/sensor_event.c b/app/src/events/sensor_event.c index 6811e7d..94ade94 100644 --- a/app/src/events/sensor_event.c +++ b/app/src/events/sensor_event.c @@ -7,4 +7,4 @@ #include #include -ZMK_EVENT_IMPL(sensor_event); \ No newline at end of file +ZMK_EVENT_IMPL(zmk_sensor_event); \ No newline at end of file diff --git a/app/src/events/usb_conn_state_changed.c b/app/src/events/usb_conn_state_changed.c index c299da7..b355556 100644 --- a/app/src/events/usb_conn_state_changed.c +++ b/app/src/events/usb_conn_state_changed.c @@ -7,4 +7,4 @@ #include #include -ZMK_EVENT_IMPL(usb_conn_state_changed); \ No newline at end of file +ZMK_EVENT_IMPL(zmk_usb_conn_state_changed); \ No newline at end of file diff --git a/app/src/hid_listener.c b/app/src/hid_listener.c index 6537cca..c5143db 100644 --- a/app/src/hid_listener.c +++ b/app/src/hid_listener.c @@ -70,9 +70,9 @@ static int hid_listener_keycode_released(uint16_t usage_page, uint32_t keycode, return zmk_endpoints_send_report(usage_page); } -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); +int hid_listener(const zmk_event_t *eh) { + if (is_zmk_keycode_state_changed(eh)) { + const struct zmk_keycode_state_changed *ev = cast_zmk_keycode_state_changed(eh); if (ev->state) { hid_listener_keycode_pressed(ev->usage_page, ev->keycode, ev->implicit_modifiers); } else { @@ -83,4 +83,4 @@ int hid_listener(const struct zmk_event_header *eh) { } ZMK_LISTENER(hid_listener, hid_listener); -ZMK_SUBSCRIPTION(hid_listener, keycode_state_changed); \ No newline at end of file +ZMK_SUBSCRIPTION(hid_listener, zmk_keycode_state_changed); \ No newline at end of file diff --git a/app/src/keymap.c b/app/src/keymap.c index 0af777d..169cf9c 100644 --- a/app/src/keymap.c +++ b/app/src/keymap.c @@ -246,14 +246,13 @@ int zmk_keymap_sensor_triggered(uint8_t sensor_number, const struct device *sens #endif /* ZMK_KEYMAP_HAS_SENSORS */ -int keymap_listener(const struct zmk_event_header *eh) { - if (is_position_state_changed(eh)) { - const struct position_state_changed *ev = cast_position_state_changed(eh); - return zmk_keymap_position_state_changed(ev->data.position, ev->data.state, - ev->data.timestamp); +int keymap_listener(const zmk_event_t *eh) { + if (is_zmk_position_state_changed(eh)) { + const struct zmk_position_state_changed *ev = cast_zmk_position_state_changed(eh); + return zmk_keymap_position_state_changed(ev->position, ev->state, ev->timestamp); #if ZMK_KEYMAP_HAS_SENSORS - } else if (is_sensor_event(eh)) { - const struct sensor_event *ev = cast_sensor_event(eh); + } else if (is_zmk_sensor_event(eh)) { + const struct zmk_sensor_event *ev = cast_zmk_sensor_event(eh); return zmk_keymap_sensor_triggered(ev->sensor_number, ev->sensor, ev->timestamp); #endif /* ZMK_KEYMAP_HAS_SENSORS */ } @@ -262,8 +261,8 @@ int keymap_listener(const struct zmk_event_header *eh) { } ZMK_LISTENER(keymap, keymap_listener); -ZMK_SUBSCRIPTION(keymap, position_state_changed); +ZMK_SUBSCRIPTION(keymap, zmk_position_state_changed); #if ZMK_KEYMAP_HAS_SENSORS -ZMK_SUBSCRIPTION(keymap, sensor_event); +ZMK_SUBSCRIPTION(keymap, zmk_sensor_event); #endif /* ZMK_KEYMAP_HAS_SENSORS */ diff --git a/app/src/kscan.c b/app/src/kscan.c index 707b439..0c128b2 100644 --- a/app/src/kscan.c +++ b/app/src/kscan.c @@ -47,13 +47,10 @@ void zmk_kscan_process_msgq(struct k_work *item) { while (k_msgq_get(&zmk_kscan_msgq, &ev, K_NO_WAIT) == 0) { bool pressed = (ev.state == ZMK_KSCAN_EVENT_STATE_PRESSED); uint32_t position = zmk_matrix_transform_row_column_to_position(ev.row, ev.column); - struct position_state_changed *pos_ev; LOG_DBG("Row: %d, col: %d, position: %d, pressed: %s\n", ev.row, ev.column, position, (pressed ? "true" : "false")); - pos_ev = new_position_state_changed(); - pos_ev->data = (struct zmk_position_state_changed_data){ - .state = pressed, .position = position, .timestamp = k_uptime_get()}; - ZMK_EVENT_RAISE(pos_ev); + ZMK_EVENT_RAISE(new_zmk_position_state_changed((struct zmk_position_state_changed){ + .state = pressed, .position = position, .timestamp = k_uptime_get()})); } } diff --git a/app/src/sensors.c b/app/src/sensors.c index 5e9ef15..dd5f426 100644 --- a/app/src/sensors.c +++ b/app/src/sensors.c @@ -35,7 +35,6 @@ static struct sensors_data_item sensors[] = {UTIL_LISTIFY(ZMK_KEYMAP_SENSORS_LEN static void zmk_sensors_trigger_handler(const struct device *dev, struct sensor_trigger *trigger) { int err; struct sensors_data_item *item = CONTAINER_OF(trigger, struct sensors_data_item, trigger); - struct sensor_event *event; LOG_DBG("sensor %d", item->sensor_number); @@ -45,12 +44,8 @@ static void zmk_sensors_trigger_handler(const struct device *dev, struct sensor_ return; } - event = new_sensor_event(); - event->sensor_number = item->sensor_number; - event->sensor = dev; - event->timestamp = k_uptime_get(); - - ZMK_EVENT_RAISE(event); + ZMK_EVENT_RAISE(new_zmk_sensor_event((struct zmk_sensor_event){ + .sensor_number = item->sensor_number, .sensor = dev, .timestamp = k_uptime_get()})); } static void zmk_sensors_init_item(const char *node, uint8_t i, uint8_t abs_i) { diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index 6772869..a56b0b8 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -33,17 +33,14 @@ static struct bt_uuid_128 uuid = BT_UUID_INIT_128(ZMK_SPLIT_BT_SERVICE_UUID); static struct bt_gatt_discover_params discover_params; static struct bt_gatt_subscribe_params subscribe_params; -K_MSGQ_DEFINE(peripheral_event_msgq, sizeof(struct zmk_position_state_changed_data), +K_MSGQ_DEFINE(peripheral_event_msgq, sizeof(struct zmk_position_state_changed), CONFIG_ZMK_SPLIT_BLE_CENTRAL_POSITION_QUEUE_SIZE, 4); void peripheral_event_work_callback(struct k_work *work) { - struct zmk_position_state_changed_data ev; + struct zmk_position_state_changed ev; while (k_msgq_get(&peripheral_event_msgq, &ev, K_NO_WAIT) == 0) { - struct position_state_changed *pos_ev = new_position_state_changed(); - pos_ev->data = ev; - LOG_DBG("Trigger key position state change for %d", ev.position); - ZMK_EVENT_RAISE(pos_ev); + ZMK_EVENT_RAISE(new_zmk_position_state_changed(ev)); } } @@ -74,7 +71,7 @@ static uint8_t split_central_notify_func(struct bt_conn *conn, if (changed_positions[i] & BIT(j)) { uint32_t position = (i * 8) + j; bool pressed = position_state[i] & BIT(j); - struct zmk_position_state_changed_data ev = { + struct zmk_position_state_changed ev = { .position = position, .state = pressed, .timestamp = k_uptime_get()}; k_msgq_put(&peripheral_event_msgq, &ev, K_NO_WAIT); diff --git a/app/src/split_listener.c b/app/src/split_listener.c index 6d2ca60..54e893e 100644 --- a/app/src/split_listener.c +++ b/app/src/split_listener.c @@ -19,18 +19,18 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include #include -int split_listener(const struct zmk_event_header *eh) { +int split_listener(const zmk_event_t *eh) { LOG_DBG(""); - if (is_position_state_changed(eh)) { - const struct position_state_changed *ev = cast_position_state_changed(eh); - if (ev->data.state) { - return zmk_split_bt_position_pressed(ev->data.position); + if (is_zmk_position_state_changed(eh)) { + const struct zmk_position_state_changed *ev = cast_zmk_position_state_changed(eh); + if (ev->state) { + return zmk_split_bt_position_pressed(ev->position); } else { - return zmk_split_bt_position_released(ev->data.position); + return zmk_split_bt_position_released(ev->position); } } return ZMK_EV_EVENT_BUBBLE; } ZMK_LISTENER(split_listener, split_listener); -ZMK_SUBSCRIPTION(split_listener, position_state_changed); \ No newline at end of file +ZMK_SUBSCRIPTION(split_listener, zmk_position_state_changed); \ No newline at end of file diff --git a/app/src/usb.c b/app/src/usb.c index 7900ace..c2f61a5 100644 --- a/app/src/usb.c +++ b/app/src/usb.c @@ -55,10 +55,8 @@ int zmk_usb_hid_send_report(const uint8_t *report, size_t len) { #endif /* CONFIG_ZMK_USB */ static void raise_usb_status_changed_event() { - struct usb_conn_state_changed *ev = new_usb_conn_state_changed(); - ev->conn_state = zmk_usb_get_conn_state(); - - ZMK_EVENT_RAISE(ev); + ZMK_EVENT_RAISE(new_zmk_usb_conn_state_changed( + (struct zmk_usb_conn_state_changed){.conn_state = zmk_usb_get_conn_state()})); } enum usb_dc_status_code zmk_usb_get_status() { return usb_status; } -- cgit v1.2.3