From 6539b3ae25926ab0b4671b116ea3045795119723 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 23 May 2022 03:11:45 +0000 Subject: [PATCH] refactor(split): Clean up Kconfig organization. * Seperated configs for split role (central/peripheral) and transport (BLE only for now). * Split the configs to align on structure. --- app/CMakeLists.txt | 6 +- app/Kconfig | 103 +------------------------- app/include/zmk/ble.h | 6 +- app/src/ble.c | 12 +-- app/src/display/widgets/Kconfig | 12 +-- app/src/split/Kconfig | 26 +++++++ app/src/split/bluetooth/Kconfig | 95 ++++++++++++++++++++++++ docs/docs/development/new-behavior.md | 10 +-- docs/docs/development/new-shield.md | 2 +- 9 files changed, 146 insertions(+), 126 deletions(-) create mode 100644 app/src/split/Kconfig create mode 100644 app/src/split/bluetooth/Kconfig diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 734a1e59..1afca568 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -37,7 +37,7 @@ target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/events/wpm_state_changed.c) target_sources_ifdef(CONFIG_USB_DEVICE_STACK app PRIVATE src/events/usb_conn_state_changed.c) target_sources(app PRIVATE src/behaviors/behavior_reset.c) target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/behaviors/behavior_ext_power.c) -if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) +if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL) target_sources(app PRIVATE src/hid.c) target_sources(app PRIVATE src/behaviors/behavior_key_press.c) target_sources(app PRIVATE src/behaviors/behavior_hold_tap.c) @@ -80,13 +80,13 @@ target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/events/battery_state_changed target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/battery.c) if (CONFIG_ZMK_SPLIT_BLE) - if (NOT CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) + if (NOT CONFIG_ZMK_SPLIT_ROLE_CENTRAL) target_sources(app PRIVATE src/split_listener.c) target_sources(app PRIVATE src/split/bluetooth/service.c) target_sources(app PRIVATE src/split/bluetooth/peripheral.c) target_sources(app PRIVATE src/events/split_peripheral_status_changed.c) endif() - if (CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) + if (CONFIG_ZMK_SPLIT_ROLE_CENTRAL) target_sources(app PRIVATE src/split/bluetooth/central.c) endif() endif() diff --git a/app/Kconfig b/app/Kconfig index 0879e5dc..95c4295e 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -166,108 +166,7 @@ endmenu # HID endmenu -menu "Split Support" - -config ZMK_SPLIT - bool "Split keyboard support" - -if ZMK_SPLIT - -menuconfig ZMK_SPLIT_BLE - bool "Split keyboard support via BLE transport" - depends on ZMK_BLE - default y - select BT_USER_PHY_UPDATE - select BT_AUTO_PHY_UPDATE - -if ZMK_SPLIT_BLE - -menuconfig ZMK_SPLIT_BLE_ROLE_CENTRAL - bool "Central" - select BT_CENTRAL - select BT_GATT_CLIENT - select BT_GATT_AUTO_DISCOVER_CCC - -if ZMK_SPLIT_BLE_ROLE_CENTRAL - -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_BLE_SPLIT_CENTRAL_SPLIT_RUN_STACK_SIZE - int "BLE split central write thread stack size" - default 512 - -config ZMK_BLE_SPLIT_CENTRAL_SPLIT_RUN_QUEUE_SIZE - int "Max number of behavior run events to queue to send to the peripheral(s)" - default 5 - -endif - -if !ZMK_SPLIT_BLE_ROLE_CENTRAL - -config ZMK_SPLIT_BLE_PERIPHERAL_STACK_SIZE - int "BLE split peripheral notify thread stack size" - default 650 - -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 ZMK_USB - default n - -config BT_MAX_PAIRED - default 1 - -config BT_MAX_CONN - default 1 - -config BT_PERIPHERAL_PREF_MAX_INT - default 6 - -#!ZMK_SPLIT_BLE_ROLE_CENTRAL -endif - -#ZMK_SPLIT_BLE -endif - -#ZMK_SPLIT -endif - -if ZMK_BLE - -if ZMK_SPLIT_BLE && ZMK_SPLIT_BLE_ROLE_CENTRAL - -config BT_MAX_CONN - default 6 - -config BT_MAX_PAIRED - default 6 - -#ZMK_SPLIT_BLE && ZMK_SPLIT_BLE_ROLE_CENTRAL -endif - -if !ZMK_SPLIT_BLE - -config BT_MAX_CONN - default 5 - -config BT_MAX_PAIRED - default 5 - -#!ZMK_SPLIT_BLE -endif - -#ZMK_BLE -endif - -#Split Support -endmenu +rsource "src/split/Kconfig" #Basic Keyboard Setup endmenu diff --git a/app/include/zmk/ble.h b/app/include/zmk/ble.h index f813ddc8..4380a33a 100644 --- a/app/include/zmk/ble.h +++ b/app/include/zmk/ble.h @@ -11,7 +11,7 @@ #define ZMK_BLE_IS_CENTRAL \ (IS_ENABLED(CONFIG_ZMK_SPLIT) && IS_ENABLED(CONFIG_ZMK_BLE) && \ - IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL)) + IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL)) #if ZMK_BLE_IS_CENTRAL #define ZMK_BLE_PROFILE_COUNT (CONFIG_BT_MAX_PAIRED - 1) @@ -33,6 +33,6 @@ char *zmk_ble_active_profile_name(); int zmk_ble_unpair_all(); -#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) +#if IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) void zmk_ble_set_peripheral_addr(bt_addr_le_t *addr); -#endif /* IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) */ +#endif /* IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) */ diff --git a/app/src/ble.c b/app/src/ble.c index 131b39b4..b10aa20b 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -47,7 +47,7 @@ static uint8_t passkey_digit = 0; #endif /* IS_ENABLED(CONFIG_ZMK_BLE_PASSKEY_ENTRY) */ -#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) +#if IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) #define PROFILE_COUNT (CONFIG_BT_MAX_PAIRED - 1) #else #define PROFILE_COUNT CONFIG_BT_MAX_PAIRED @@ -82,11 +82,11 @@ static const struct bt_data zmk_ble_ad[] = { ), }; -#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) +#if IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) static bt_addr_le_t peripheral_addr; -#endif /* IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) */ +#endif /* IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) */ static void raise_profile_changed_event() { ZMK_EVENT_RAISE(new_zmk_ble_active_profile_changed((struct zmk_ble_active_profile_changed){ @@ -278,14 +278,14 @@ bt_addr_le_t *zmk_ble_active_profile_addr() { return &profiles[active_profile].p char *zmk_ble_active_profile_name() { return profiles[active_profile].name; } -#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) +#if IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) void zmk_ble_set_peripheral_addr(bt_addr_le_t *addr) { memcpy(&peripheral_addr, addr, sizeof(bt_addr_le_t)); settings_save_one("ble/peripheral_address", addr, sizeof(bt_addr_le_t)); } -#endif /* IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) */ +#endif /* IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) */ #if IS_ENABLED(CONFIG_SETTINGS) @@ -336,7 +336,7 @@ static int ble_profiles_handle_set(const char *name, size_t len, settings_read_c return err; } } -#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) +#if IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) else if (settings_name_steq(name, "peripheral_address", &next) && !next) { if (len != sizeof(bt_addr_le_t)) { return -EINVAL; diff --git a/app/src/display/widgets/Kconfig b/app/src/display/widgets/Kconfig index 7357663f..96e7e16d 100644 --- a/app/src/display/widgets/Kconfig +++ b/app/src/display/widgets/Kconfig @@ -6,7 +6,7 @@ menu "ZMK Display Widgets" config ZMK_WIDGET_LAYER_STATUS bool "Widget for highest, active layer using small icons" default y - depends on !ZMK_SPLIT || ZMK_SPLIT_BLE_ROLE_CENTRAL + depends on !ZMK_SPLIT || ZMK_SPLIT_ROLE_CENTRAL select LVGL_USE_LABEL config ZMK_WIDGET_BATTERY_STATUS @@ -17,19 +17,19 @@ config ZMK_WIDGET_BATTERY_STATUS config ZMK_WIDGET_OUTPUT_STATUS bool "Widget for keyboard output status icons" - depends on BT && (!ZMK_SPLIT_BLE || ZMK_SPLIT_BLE_ROLE_CENTRAL) - default y if BT && (!ZMK_SPLIT_BLE || ZMK_SPLIT_BLE_ROLE_CENTRAL) + depends on BT && (!ZMK_SPLIT_BLE || ZMK_SPLIT_ROLE_CENTRAL) + default y if BT && (!ZMK_SPLIT_BLE || ZMK_SPLIT_ROLE_CENTRAL) select LVGL_USE_LABEL config ZMK_WIDGET_PERIPHERAL_STATUS bool "Widget for split peripheral status icons" - depends on BT && ZMK_SPLIT_BLE && !ZMK_SPLIT_BLE_ROLE_CENTRAL - default y if BT && ZMK_SPLIT_BLE && !ZMK_SPLIT_BLE_ROLE_CENTRAL + depends on BT && ZMK_SPLIT_BLE && !ZMK_SPLIT_ROLE_CENTRAL + default y if BT && ZMK_SPLIT_BLE && !ZMK_SPLIT_ROLE_CENTRAL select LVGL_USE_LABEL config ZMK_WIDGET_WPM_STATUS bool "Widget for displaying typed words per minute" - depends on !ZMK_SPLIT || ZMK_SPLIT_BLE_ROLE_CENTRAL + depends on !ZMK_SPLIT || ZMK_SPLIT_ROLE_CENTRAL select LVGL_USE_LABEL select ZMK_WPM diff --git a/app/src/split/Kconfig b/app/src/split/Kconfig new file mode 100644 index 00000000..42cb411c --- /dev/null +++ b/app/src/split/Kconfig @@ -0,0 +1,26 @@ +# Copyright (c) 2022 The ZMK Contributors +# SPDX-License-Identifier: MIT + +menuconfig ZMK_SPLIT + bool "Split keyboard support" + +if ZMK_SPLIT + +config ZMK_SPLIT_ROLE_CENTRAL + bool "Split central device" + +choice ZMK_SPLIT_TRANSPORT + prompt "Split transport" + +config ZMK_SPLIT_BLE + bool "BLE" + depends on ZMK_BLE + select BT_USER_PHY_UPDATE + select BT_AUTO_PHY_UPDATE + +endchoice + +#ZMK_SPLIT +endif + +rsource "bluetooth/Kconfig" diff --git a/app/src/split/bluetooth/Kconfig b/app/src/split/bluetooth/Kconfig new file mode 100644 index 00000000..f6976cff --- /dev/null +++ b/app/src/split/bluetooth/Kconfig @@ -0,0 +1,95 @@ +# Copyright (c) 2022 The ZMK Contributors +# SPDX-License-Identifier: MIT + +if ZMK_SPLIT && ZMK_SPLIT_BLE + +menu "BLE Transport" + +# Added for backwards compatibility. New shields/board should set `ZMK_SPLIT_ROLE_CENTRAL` only. +config ZMK_SPLIT_BLE_ROLE_CENTRAL + bool + select ZMK_SPLIT_ROLE_CENTRAL + +config ZMK_SPLIT_ROLE_CENTRAL + select BT_CENTRAL + select BT_GATT_CLIENT + select BT_GATT_AUTO_DISCOVER_CCC + +if ZMK_SPLIT_ROLE_CENTRAL + +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_BLE_SPLIT_CENTRAL_SPLIT_RUN_STACK_SIZE + int "BLE split central write thread stack size" + default 512 + +config ZMK_BLE_SPLIT_CENTRAL_SPLIT_RUN_QUEUE_SIZE + int "Max number of behavior run events to queue to send to the peripheral(s)" + default 5 + +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 650 + +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 ZMK_USB + default n + +config BT_MAX_PAIRED + default 1 + +config BT_MAX_CONN + default 1 + +config BT_PERIPHERAL_PREF_MAX_INT + default 6 + +#!ZMK_SPLIT_ROLE_CENTRAL +endif + +endmenu + +#ZMK_SPLIT_BLE +endif + + +if ZMK_BLE + +if ZMK_SPLIT_BLE && ZMK_SPLIT_ROLE_CENTRAL + +config BT_MAX_CONN + default 6 + +config BT_MAX_PAIRED + default 6 + +#ZMK_SPLIT_BLE && ZMK_SPLIT_ROLE_CENTRAL +endif + +if !ZMK_SPLIT_BLE + +config BT_MAX_CONN + default 5 + +config BT_MAX_PAIRED + default 5 + +#!ZMK_SPLIT_BLE +endif + +#ZMK_BLE +endif + diff --git a/docs/docs/development/new-behavior.md b/docs/docs/development/new-behavior.md index 3af80365..782dc010 100644 --- a/docs/docs/development/new-behavior.md +++ b/docs/docs/development/new-behavior.md @@ -320,10 +320,10 @@ Remember that `.c` files should be formatted according to `clang-format` to ensu ### Updating `app/CmakeLists.txt` to include the new driver -Most behavior drivers' are invoked according to the central half's [locality](#api-structure), and are therefore stored after the line `if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL)` in the form, `target_sources(app PRIVATE src/behaviors/.c)`, as shown below. +Most behavior drivers' are invoked according to the central half's [locality](#api-structure), and are therefore stored after the line `if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL)` in the form, `target_sources(app PRIVATE src/behaviors/.c)`, as shown below. ```txt title="app/CmakeLists.txt" -if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL) +if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL) target_sources(app PRIVATE src/behaviors/behavior_key_press.c) target_sources(app PRIVATE src/behaviors/behavior_hold_tap.c) target_sources(app PRIVATE src/behaviors/behavior_sticky_key.c) @@ -346,9 +346,9 @@ endif() For behaviors that do not require central locality, the following options for updating `app/CmakeLists.txt` also exist: -- Behavior applies to unibody, or central or peripheral half of keyboard: place `target_sources(app PRIVATE .c)` line _before_ `if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL)` -- Behavior applies to _only_ central half of split keyboard: place `target_sources(app PRIVATE .c)` after `if (CONFIG_ZMK_SPLIT_BLE AND CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL)` -- Behavior applies to _only_ peripheral half of split keyboard: place `target_sources(app PRIVATE .c)` after `if (CONFIG_ZMK_SPLIT_BLE AND (NOT CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL))` +- Behavior applies to unibody, or central or peripheral half of keyboard: place `target_sources(app PRIVATE .c)` line _before_ `if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL)` +- Behavior applies to _only_ central half of split keyboard: place `target_sources(app PRIVATE .c)` after `if (CONFIG_ZMK_SPLIT_BLE AND CONFIG_ZMK_SPLIT_ROLE_CENTRAL)` +- Behavior applies to _only_ peripheral half of split keyboard: place `target_sources(app PRIVATE .c)` after `if (CONFIG_ZMK_SPLIT_BLE AND (NOT CONFIG_ZMK_SPLIT_ROLE_CENTRAL))` - Behavior requires certain condition in a keyboard's `.conf` file to be met: use `target_sources_ifdef(CONFIG_ app PRIVATE .c)` instead of `target_sources(.c)` ### Defining common use-cases for the behavior (`.dtsi`) (Optional) diff --git a/docs/docs/development/new-shield.md b/docs/docs/development/new-shield.md index dc4db850..b46c319d 100644 --- a/docs/docs/development/new-shield.md +++ b/docs/docs/development/new-shield.md @@ -100,7 +100,7 @@ if SHIELD_MY_BOARD_LEFT config ZMK_KEYBOARD_NAME default "My Board" -config ZMK_SPLIT_BLE_ROLE_CENTRAL +config ZMK_SPLIT_ROLE_CENTRAL default y endif