diff --git a/app/include/zmk/split/central.h b/app/include/zmk/split/central.h new file mode 100644 index 00000000000..da4ff7f3a9f --- /dev/null +++ b/app/include/zmk/split/central.h @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include + +void zmk_position_state_change_handle(struct zmk_position_state_changed *ev); diff --git a/app/src/split/CMakeLists.txt b/app/src/split/CMakeLists.txt index 1205c026f78..b59533d4d89 100644 --- a/app/src/split/CMakeLists.txt +++ b/app/src/split/CMakeLists.txt @@ -6,6 +6,10 @@ if (CONFIG_ZMK_SPLIT_BLE AND (NOT CONFIG_ZMK_SPLIT_ROLE_CENTRAL)) target_sources(app PRIVATE service.c) endif() +if (CONFIG_ZMK_SPLIT_BLE AND CONFIG_ZMK_SPLIT_ROLE_CENTRAL) + target_sources(app PRIVATE central.c) +endif() + if (CONFIG_ZMK_SPLIT_BLE) add_subdirectory(bluetooth) endif() diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index c22d64e7496..1394b4f3ea2 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -24,6 +24,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include #include #include +#include #include #include #include @@ -134,19 +135,6 @@ static bool is_scanning = false; static const struct bt_uuid_128 split_service_uuid = BT_UUID_INIT_128(ZMK_SPLIT_BT_SERVICE_UUID); -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 ev; - while (k_msgq_get(&peripheral_event_msgq, &ev, K_NO_WAIT) == 0) { - LOG_DBG("Trigger key position state change for %d", ev.position); - raise_zmk_position_state_changed(ev); - } -} - -K_WORK_DEFINE(peripheral_event_work, peripheral_event_work_callback); - int peripheral_slot_index_for_conn(struct bt_conn *conn) { for (int i = 0; i < ZMK_SPLIT_BLE_PERIPHERAL_COUNT; i++) { if (peripherals[i].conn == conn) { @@ -194,9 +182,7 @@ int release_peripheral_slot(int index) { .position = position, .state = false, .timestamp = k_uptime_get()}; - - k_msgq_put(&peripheral_event_msgq, &ev, K_NO_WAIT); - k_work_submit(&peripheral_event_work); + zmk_position_state_change_handle(&ev); } } } @@ -389,9 +375,7 @@ static uint8_t split_central_notify_func(struct bt_conn *conn, .position = position, .state = pressed, .timestamp = k_uptime_get()}; - - k_msgq_put(&peripheral_event_msgq, &ev, K_NO_WAIT); - k_work_submit(&peripheral_event_work); + zmk_position_state_change_handle(&ev); } } } diff --git a/app/src/split/central.c b/app/src/split/central.c new file mode 100644 index 00000000000..d51c3e6c572 --- /dev/null +++ b/app/src/split/central.c @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include + +#include +#include +#include + +#include +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +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 ev; + while (k_msgq_get(&peripheral_event_msgq, &ev, K_NO_WAIT) == 0) { + LOG_DBG("Trigger key position state change for %d", ev.position); + raise_zmk_position_state_changed(ev); + } +} + +K_WORK_DEFINE(peripheral_event_work, peripheral_event_work_callback); + +void zmk_position_state_change_handle(struct zmk_position_state_changed *ev) { + k_msgq_put(&peripheral_event_msgq, ev, K_NO_WAIT); + k_work_submit(&peripheral_event_work); +}