Skip to content

Commit

Permalink
feat(split): Add full-duplex wired split support
Browse files Browse the repository at this point in the history
* Depends on full-duplex hardware UART for communication.
* Supports all existing central commands/peripheral events, including
  sensors/inputs from peripherals.
* Only one wired split peripheral supported (for now)
* Relies on chosen `zmk,split-uart` referencing the UART device.
  • Loading branch information
petejohanson committed Feb 3, 2025
1 parent fd2a15b commit 6e7d12e
Show file tree
Hide file tree
Showing 12 changed files with 1,031 additions and 5 deletions.
5 changes: 5 additions & 0 deletions app/boards/shields/zmk_uno/zmk_uno_split.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ left_encoder: &encoder {
status = "disabled";
};

&arduino_serial {
status = "okay";
};

/ {
chosen {
zmk,split-uart = &arduino_serial;
zmk,physical-layout = &split_matrix_physical_layout;
};

Expand Down
20 changes: 20 additions & 0 deletions app/dts/bindings/zmk,wired-split.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) 2024 The ZMK Contributors
# SPDX-License-Identifier: MIT

description: |
Complete specification of wired split connetion
compatible: "zmk,wired-split"

properties:
device:
type: phandle
required: true
description: The UART device for wired split communication

half-duplex:
type: boolean
description: Enable half-duplex protocol mode.

dir-gpios:
type: phandle-array
4 changes: 4 additions & 0 deletions app/src/split/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ if (CONFIG_ZMK_SPLIT_BLE)
add_subdirectory(bluetooth)
endif()

if (CONFIG_ZMK_SPLIT_WIRED)
add_subdirectory(wired)
endif()

if (CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
target_sources(app PRIVATE central.c)
zephyr_linker_sources(SECTIONS ../../include/linker/zmk-split-transport-central.ld)
Expand Down
16 changes: 11 additions & 5 deletions app/src/split/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ 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"
bool "BLE Split"
default y
depends on ZMK_BLE
select BT_USER_PHY_UPDATE
select BT_AUTO_PHY_UPDATE

endchoice
DT_CHOSEN_ZMK_SPLIT_UART := zmk,split-uart

config ZMK_SPLIT_WIRED
bool "Wired Split"
default $(dt_chosen_enabled,$(DT_CHOSEN_ZMK_SPLIT_UART)) if !ZMK_SPLIT_BLE
select SERIAL
select RING_BUFFER
select CRC

config ZMK_SPLIT_PERIPHERAL_HID_INDICATORS
bool "Peripheral HID Indicators"
Expand All @@ -29,3 +34,4 @@ config ZMK_SPLIT_PERIPHERAL_HID_INDICATORS
endif # ZMK_SPLIT

rsource "bluetooth/Kconfig"
rsource "wired/Kconfig"
2 changes: 2 additions & 0 deletions app/src/split/Kconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
# SPDX-License-Identifier: MIT

rsource "bluetooth/Kconfig.defaults"
rsource "wired/Kconfig.defaults"

3 changes: 3 additions & 0 deletions app/src/split/wired/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target_sources(app PRIVATE wired.c)
target_sources_ifdef(CONFIG_ZMK_SPLIT_ROLE_CENTRAL app PRIVATE central.c)
target_sources_ifndef(CONFIG_ZMK_SPLIT_ROLE_CENTRAL app PRIVATE peripheral.c)
44 changes: 44 additions & 0 deletions app/src/split/wired/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
if ZMK_SPLIT_WIRED

choice ZMK_SPLIT_WIRED_UART_MODE_DEFAULT
prompt "Default UART Mode"

config ZMK_SPLIT_WIRED_UART_MODE_DEFAULT_ASYNC
bool "Async (DMA) Mode"
depends on SERIAL_SUPPORT_ASYNC
select UART_ASYNC_API

config ZMK_SPLIT_WIRED_UART_MODE_DEFAULT_INTERRUPT
bool "Interrupt Mode"
depends on SERIAL_SUPPORT_INTERRUPT
select UART_INTERRUPT_DRIVEN

config ZMK_SPLIT_WIRED_UART_MODE_DEFAULT_POLLING
bool "Polling Mode"

endchoice

if ZMK_SPLIT_WIRED_UART_MODE_DEFAULT_POLLING

config ZMK_SPLIT_WIRED_POLLING_RX_PERIOD
int "Ticks between RX polls"

endif

if ZMK_SPLIT_WIRED_UART_MODE_DEFAULT_ASYNC

config ZMK_SPLIT_WIRED_ASYNC_RX_TIMEOUT
int "RX Timeout (in microseconds) before reporting received data"

endif

config ZMK_SPLIT_WIRED_CMD_BUFFER_ITEMS
int "Number of central commands to buffer for TX/RX"

config ZMK_SPLIT_WIRED_EVENT_BUFFER_ITEMS
int "Number of peripheral events to buffer for TX/RX"

config ZMK_SPLIT_WIRED_HALF_DUPLEX_RX_TIMEOUT
int "RX timeout (in ticks) when polling peripheral(s)"

endif
28 changes: 28 additions & 0 deletions app/src/split/wired/Kconfig.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
if ZMK_SPLIT_WIRED

config ZMK_SPLIT_WIRED_CMD_BUFFER_ITEMS
default 4

config ZMK_SPLIT_WIRED_EVENT_BUFFER_ITEMS
default 16


if ZMK_SPLIT_WIRED_UART_MODE_DEFAULT_POLLING

config ZMK_SPLIT_WIRED_POLLING_RX_PERIOD
default 10

endif


if ZMK_SPLIT_WIRED_UART_MODE_DEFAULT_ASYNC

config ZMK_SPLIT_WIRED_ASYNC_RX_TIMEOUT
default 100

endif

config ZMK_SPLIT_WIRED_HALF_DUPLEX_RX_TIMEOUT
default 50

endif
Loading

0 comments on commit 6e7d12e

Please sign in to comment.