Skip to content

Commit

Permalink
Add wired split support using UART communication
Browse files Browse the repository at this point in the history
  • Loading branch information
megamind4089 committed Feb 4, 2022
1 parent edbbbc7 commit 9072f10
Show file tree
Hide file tree
Showing 12 changed files with 457 additions and 20 deletions.
9 changes: 8 additions & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/events/battery_state_changed
target_sources_ifdef(CONFIG_USB 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_BLE_ROLE_CENTRAL OR CONFIG_ZMK_SPLIT_SERIAL_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)
Expand Down Expand Up @@ -74,6 +74,13 @@ endif()
if (CONFIG_ZMK_SPLIT_BLE AND CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL)
target_sources(app PRIVATE src/split/bluetooth/central.c)
endif()
if (CONFIG_ZMK_SPLIT_SERIAL AND (NOT CONFIG_ZMK_SPLIT_SERIAL_ROLE_CENTRAL))
target_sources(app PRIVATE src/split_listener.c)
target_sources(app PRIVATE src/split/serial/service.c)
endif()
if (CONFIG_ZMK_SPLIT_SERIAL AND CONFIG_ZMK_SPLIT_SERIAL_ROLE_CENTRAL)
target_sources(app PRIVATE src/split/serial/central.c)
endif()
target_sources_ifdef(CONFIG_USB app PRIVATE src/usb.c)
target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/hog.c)
target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/rgb_underglow.c)
Expand Down
59 changes: 55 additions & 4 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,14 @@ config ZMK_SPLIT

if ZMK_SPLIT

choice ZMK_SPLIT_TYPE
prompt "ZMK split type"

if ZMK_BLE

menuconfig ZMK_SPLIT_BLE
bool "Split keyboard support via BLE transport"
depends on ZMK_BLE
default y
select BT_USER_PHY_UPDATE

if ZMK_SPLIT_BLE
Expand Down Expand Up @@ -199,9 +203,6 @@ 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

Expand All @@ -217,6 +218,56 @@ endif
#ZMK_SPLIT_BLE
endif

# ZMK_BLE
endif

if ZMK_USB

menuconfig ZMK_SPLIT_SERIAL
bool "Split keyboard support via Serial transport"
depends on ZMK_USB

if ZMK_SPLIT_SERIAL

choice ZMK_SPLIT_SERIAL_ROLE
prompt "ZMK split serial role"

menuconfig ZMK_SPLIT_SERIAL_ROLE_CENTRAL
bool "Central"

menuconfig ZMK_SPLIT_SERIAL_ROLE_PERIPHERAL
bool "Peripheral"

if ZMK_SPLIT_SERIAL_ROLE_PERIPHERAL

config ZMK_SPLIT_SERIAL_PERIPHERAL_STACK_SIZE
int "Serial split peripheral notify thread stack size"
default 512

config ZMK_SPLIT_SERIAL_PERIPHERAL_PRIORITY
int "Serial split peripheral notify thread priority"
default 5

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

# ZMK_SPLIT_SERIAL_ROLE_PERIPHERAL
endif

# ZMK_SPLIT_SERIAL_ROLE
endchoice

# ZMK_SPLIT_SERIAL
endif

# ZMK_USB
endif

# ZMK_SPLIT_TYPE
endchoice


#ZMK_SPLIT
endif

Expand Down
28 changes: 25 additions & 3 deletions app/boards/shields/a_dux/Kconfig.defconfig
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
# Copyright (c) 2021 The ZMK Contributors
# SPDX-License-Identifier: MIT

if SHIELD_A_DUX_LEFT || SHIELD_A_DUX_RIGHT

if ZMK_BLE || ZMK_USB
config ZMK_SPLIT
default y
endif

if SHIELD_A_DUX_LEFT

config ZMK_KEYBOARD_NAME
default "A. Dux"

if ZMK_BLE
config ZMK_SPLIT_BLE_ROLE_CENTRAL
default y
endif

if ZMK_USB
choice ZMK_SPLIT_SERIAL_ROLE
default ZMK_SPLIT_SERIAL_ROLE_CENTRAL
endchoice
endif

if SHIELD_A_DUX_LEFT || SHIELD_A_DUX_RIGHT
# SHIELD_A_DUX_LEFT
endif

config ZMK_SPLIT
default y
if SHIELD_A_DUX_RIGHT

if ZMK_USB
choice ZMK_SPLIT_SERIAL_ROLE
default ZMK_SPLIT_SERIAL_ROLE_PERIPHERAL
endchoice
endif

# SHIELD_A_DUX_RIGHT
endif

endif
37 changes: 37 additions & 0 deletions app/boards/shields/a_dux/boards/stemcell.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2022 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

/ {
chosen {
zmk,split-serial = &usart1;
};
};

&usart1 {
status = "okay";
};

&kscan0 {
input-gpios =
<&pro_micro_d 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_d 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_a 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_d 16 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_a 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_d 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_d 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>, /* Changed since swapped pins */
<&pro_micro_a 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_d 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_a 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_d 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_d 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_d 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>, /* TODO: Use 0 if Console is needed */
<&pro_micro_d 15 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_d 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_d 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>,
<&pro_micro_d 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>
;
};
2 changes: 1 addition & 1 deletion app/include/zmk/split/bluetooth/central.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
#include <zmk/behavior.h>

int zmk_split_bt_invoke_behavior(uint8_t source, struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event, bool state);
struct zmk_behavior_binding_event event, bool state);
3 changes: 0 additions & 3 deletions app/include/zmk/split/bluetooth/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,3 @@ struct zmk_split_run_behavior_payload {
struct zmk_split_run_behavior_data data;
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);
24 changes: 24 additions & 0 deletions app/include/zmk/split/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2022 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

#pragma once

#include <zephyr/types.h>

#define SPLIT_DATA_LEN 16

#define SPLIT_TYPE_KEYPOSITION 0

typedef struct _split_data_t {
uint16_t type;
uint8_t data[SPLIT_DATA_LEN];
uint16_t crc;
} split_data_t;

int zmk_split_position_pressed(uint8_t position);

int zmk_split_position_released(uint8_t position);

5 changes: 3 additions & 2 deletions app/src/split/bluetooth/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/behavior.h>
#include <zmk/matrix.h>
#include <zmk/split/bluetooth/uuid.h>
#include <zmk/split/common.h>
#include <zmk/split/bluetooth/service.h>

#define POS_STATE_LEN 16
Expand Down Expand Up @@ -141,12 +142,12 @@ int send_position_state() {
return 0;
}

int zmk_split_bt_position_pressed(uint8_t position) {
int zmk_split_position_pressed(uint8_t position) {
WRITE_BIT(position_state[position / 8], position % 8, true);
return send_position_state();
}

int zmk_split_bt_position_released(uint8_t position) {
int zmk_split_position_released(uint8_t position) {
WRITE_BIT(position_state[position / 8], position % 8, false);
return send_position_state();
}
Expand Down
Loading

0 comments on commit 9072f10

Please sign in to comment.