From 8d626fbca4c656c59e04186c451d8322e3a2451a Mon Sep 17 00:00:00 2001 From: Tokazio Date: Tue, 17 Jan 2023 19:05:04 +0100 Subject: [PATCH] slicemk: ZMK PR 1630 (WIP 2024-01-15) --- app/include/zmk/split/bluetooth/central.h | 5 ++++- app/src/behavior_queue.c | 5 +++-- app/src/keymap.c | 27 ++++++++++++++--------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app/include/zmk/split/bluetooth/central.h b/app/include/zmk/split/bluetooth/central.h index 973a4e8b23ba..60d532082ecb 100644 --- a/app/include/zmk/split/bluetooth/central.h +++ b/app/include/zmk/split/bluetooth/central.h @@ -11,6 +11,9 @@ int zmk_split_invoke_behavior(uint8_t source, struct zmk_behavior_binding *binding, struct zmk_behavior_binding_event event, bool state); +int zmk_run_behavior(struct zmk_behavior_binding *binding, struct zmk_behavior_binding_event event, + uint8_t source, bool pressed); + #if IS_ENABLED(CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS) int zmk_split_bt_update_hid_indicator(zmk_hid_indicators_t indicators); @@ -21,4 +24,4 @@ int zmk_split_bt_update_hid_indicator(zmk_hid_indicators_t indicators); int zmk_split_get_peripheral_battery_level(uint8_t source, uint8_t *level); -#endif // IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_FETCHING) \ No newline at end of file +#endif // IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_FETCHING) diff --git a/app/src/behavior_queue.c b/app/src/behavior_queue.c index 1511e755d4f0..08d62d52513e 100644 --- a/app/src/behavior_queue.c +++ b/app/src/behavior_queue.c @@ -9,6 +9,7 @@ #include #include #include +#include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); @@ -35,9 +36,9 @@ static void behavior_queue_process_next(struct k_work *work) { .timestamp = k_uptime_get()}; if (item.press) { - behavior_keymap_binding_pressed(&item.binding, event); + zmk_run_behavior(&item.binding, event, 0, true); } else { - behavior_keymap_binding_released(&item.binding, event); + zmk_run_behavior(&item.binding, event, 0, false); } LOG_DBG("Processing next queued behavior in %dms", item.wait); diff --git a/app/src/keymap.c b/app/src/keymap.c index e7e752120cdf..64ff7b501163 100644 --- a/app/src/keymap.c +++ b/app/src/keymap.c @@ -177,23 +177,28 @@ int zmk_keymap_apply_position_state(uint8_t source, int layer, uint32_t position // We want to make a copy of this, since it may be converted from // relative to absolute before being invoked struct zmk_behavior_binding binding = zmk_keymap[layer][position]; - const struct device *behavior; struct zmk_behavior_binding_event event = { .layer = layer, .position = position, .timestamp = timestamp, }; - LOG_DBG("layer: %d position: %d, binding name: %s", layer, position, binding.behavior_dev); + return zmk_run_behavior(&binding, event, source, pressed); +} + +int zmk_run_behavior(struct zmk_behavior_binding *binding, struct zmk_behavior_binding_event event, + uint8_t source, bool pressed) { + LOG_DBG("layer: %d position: %d, binding name: %s", event.layer, event.position, + binding->behavior_dev); - behavior = zmk_behavior_get_binding(binding.behavior_dev); + const struct device *behavior = zmk_behavior_get_binding(binding->behavior_dev); if (!behavior) { - LOG_WRN("No behavior assigned to %d on layer %d", position, layer); + LOG_WRN("No behavior assigned to %d on layer %d", event.position, event.layer); return 1; } - int err = behavior_keymap_binding_convert_central_state_dependent_params(&binding, event); + int err = behavior_keymap_binding_convert_central_state_dependent_params(binding, event); if (err) { LOG_ERR("Failed to convert relative to absolute behavior binding (err %d)", err); return err; @@ -208,24 +213,24 @@ int zmk_keymap_apply_position_state(uint8_t source, int layer, uint32_t position switch (locality) { case BEHAVIOR_LOCALITY_CENTRAL: - return invoke_locally(&binding, event, pressed); + return invoke_locally(binding, event, pressed); case BEHAVIOR_LOCALITY_EVENT_SOURCE: #if ZMK_BLE_IS_CENTRAL if (source == ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL) { - return invoke_locally(&binding, event, pressed); + return invoke_locally(binding, event, pressed); } else { - return zmk_split_invoke_behavior(source, &binding, event, pressed); + return zmk_split_invoke_behavior(source, binding, event, pressed); } #else - return invoke_locally(&binding, event, pressed); + return invoke_locally(binding, event, pressed); #endif case BEHAVIOR_LOCALITY_GLOBAL: #if ZMK_BLE_IS_CENTRAL for (int i = 0; i < ZMK_SPLIT_BLE_PERIPHERAL_COUNT; i++) { - zmk_split_invoke_behavior(i, &binding, event, pressed); + zmk_split_invoke_behavior(i, binding, event, pressed); } #endif - return invoke_locally(&binding, event, pressed); + return invoke_locally(binding, event, pressed); } return -ENOTSUP;