Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split Refactor Part 1 #2086

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/include/zmk/split/bluetooth/central.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <zmk/hid_indicators_types.h>
#endif // IS_ENABLED(CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS)

int zmk_split_bt_invoke_behavior(uint8_t source, struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event, bool state);
int zmk_split_invoke_behavior(uint8_t source, struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event, bool state);

#if IS_ENABLED(CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS)

Expand Down
19 changes: 19 additions & 0 deletions app/include/zmk/split/central.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2023 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

#pragma once

#include <zmk/events/position_state_changed.h>
#include <zmk/events/sensor_event.h>
#include <zmk/split/service.h>

void zmk_position_state_change_handle(struct zmk_position_state_changed *ev);

#if ZMK_KEYMAP_HAS_SENSORS
void zmk_sensor_event_handle(struct zmk_sensor_event *ev);
#endif

void send_split_run_impl(struct zmk_split_run_behavior_payload_wrapper *payload_wrapper);
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <zmk/sensors.h>

#define ZMK_SPLIT_RUN_BEHAVIOR_DEV_LEN 9
#define ZMK_SPLIT_POS_STATE_LEN 16

struct sensor_event {
uint8_t sensor_index;
Expand All @@ -30,8 +31,18 @@ struct zmk_split_run_behavior_payload {
char behavior_dev[ZMK_SPLIT_RUN_BEHAVIOR_DEV_LEN];
} __packed;

int zmk_split_bt_position_pressed(uint8_t position);
int zmk_split_bt_position_released(uint8_t position);
int zmk_split_bt_sensor_triggered(uint8_t sensor_index,
const struct zmk_sensor_channel_data channel_data[],
size_t channel_data_size);
struct zmk_split_run_behavior_payload_wrapper {
uint8_t source;
struct zmk_split_run_behavior_payload payload;
};

int zmk_split_position_pressed(uint8_t position);
int zmk_split_position_released(uint8_t position);
int zmk_split_sensor_triggered(uint8_t sensor_index,
const struct zmk_sensor_channel_data channel_data[],
size_t channel_data_size);

void send_position_state_impl(uint8_t *state, int len);
#if ZMK_KEYMAP_HAS_SENSORS
void send_sensor_state_impl(struct sensor_event *event, int len);
#endif
4 changes: 2 additions & 2 deletions app/src/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ int zmk_keymap_apply_position_state(uint8_t source, int layer, uint32_t position
if (source == ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL) {
return invoke_locally(&binding, event, pressed);
} else {
return zmk_split_bt_invoke_behavior(source, &binding, event, pressed);
return zmk_split_invoke_behavior(source, &binding, event, pressed);
}
#else
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_bt_invoke_behavior(i, &binding, event, pressed);
zmk_split_invoke_behavior(i, &binding, event, pressed);
}
#endif
return invoke_locally(&binding, event, pressed);
Expand Down
11 changes: 10 additions & 1 deletion app/src/split/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Copyright (c) 2022 The ZMK Contributors
# SPDX-License-Identifier: MIT

if (CONFIG_ZMK_SPLIT_BLE AND (NOT CONFIG_ZMK_SPLIT_ROLE_CENTRAL))
target_sources(app PRIVATE listener.c)
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()
endif()
40 changes: 40 additions & 0 deletions app/src/split/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,49 @@ menuconfig ZMK_SPLIT

if ZMK_SPLIT

config ZMK_SPLIT_INIT_PRIORITY
int "Split Init Priority"
default 50

config ZMK_SPLIT_ROLE_CENTRAL
bool "Split central device"

if ZMK_SPLIT_ROLE_CENTRAL

config ZMK_SPLIT_CENTRAL_POSITION_QUEUE_SIZE
int "Max number of key position state events to queue when received from peripherals"
default 5

config ZMK_SPLIT_CENTRAL_SPLIT_RUN_STACK_SIZE
int "Split central write thread stack size"
default 512

config ZMK_SPLIT_CENTRAL_SPLIT_RUN_QUEUE_SIZE
int "Max number of behavior run events to queue to send to the peripheral(s)"
default 5

config ZMK_SPLIT_CENTRAL_PRIORITY
int "Split central thread priority"
default 5

endif # ZMK_SPLIT_ROLE_CENTRAL

if !ZMK_SPLIT_ROLE_CENTRAL

config ZMK_SPLIT_PERIPHERAL_STACK_SIZE
int "Split peripheral notify thread stack size"
default 756

config ZMK_SPLIT_PERIPHERAL_PRIORITY
int "Split peripheral notify thread priority"
default 5

config ZMK_SPLIT_PERIPHERAL_POSITION_QUEUE_SIZE
int "Max number of key position state events to queue to send to the central"
default 10

endif #!ZMK_SPLIT_ROLE_CENTRAL

choice ZMK_SPLIT_TRANSPORT
prompt "Split transport"

Expand Down
4 changes: 2 additions & 2 deletions app/src/split/bluetooth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# SPDX-License-Identifier: MIT

if (NOT CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
target_sources(app PRIVATE split_listener.c)
target_sources(app PRIVATE service.c)
target_sources(app PRIVATE peripheral.c)
endif()

if (CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
target_sources(app PRIVATE central.c)
endif()

if (CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_PROXY)
target_sources(app PRIVATE central_bas_proxy.c)
endif()
endif()
24 changes: 0 additions & 24 deletions app/src/split/bluetooth/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,6 @@ config ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_PROXY

endif

config ZMK_SPLIT_BLE_CENTRAL_POSITION_QUEUE_SIZE
int "Max number of key position state events to queue when received from peripherals"
default 5

config ZMK_SPLIT_BLE_CENTRAL_SPLIT_RUN_STACK_SIZE
int "BLE split central write thread stack size"
default 512

config ZMK_SPLIT_BLE_CENTRAL_SPLIT_RUN_QUEUE_SIZE
int "Max number of behavior run events to queue to send to the peripheral(s)"
default 5

config ZMK_SPLIT_BLE_PREF_INT
int "Connection interval to use for split central/peripheral connection"
default 6
Expand All @@ -74,18 +62,6 @@ endif # ZMK_SPLIT_ROLE_CENTRAL

if !ZMK_SPLIT_ROLE_CENTRAL

config ZMK_SPLIT_BLE_PERIPHERAL_STACK_SIZE
int "BLE split peripheral notify thread stack size"
default 756

config ZMK_SPLIT_BLE_PERIPHERAL_PRIORITY
int "BLE split peripheral notify thread priority"
default 5

config ZMK_SPLIT_BLE_PERIPHERAL_POSITION_QUEUE_SIZE
int "Max number of key position state events to queue to send to the central"
default 10

config BT_MAX_PAIRED
default 1

Expand Down
Loading