-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add wired split support using UART communication #1117
base: main
Are you sure you want to change the base?
Changes from all commits
e92a986
f357aed
ace8cc3
528fc96
8e6b5f5
5a8744f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,10 +155,14 @@ config ZMK_SPLIT | |
|
||
if ZMK_SPLIT | ||
|
||
choice ZMK_SPLIT_TYPE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto on #1314 |
||
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 | ||
|
@@ -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 | ||
|
||
|
@@ -217,6 +218,51 @@ endif | |
#ZMK_SPLIT_BLE | ||
endif | ||
|
||
# ZMK_BLE | ||
endif | ||
|
||
if ZMK_USB | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this really needs to be behind this condition, TBH. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean we can remove this check ? |
||
|
||
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" | ||
|
||
# ZMK_SPLIT_SERIAL_ROLE | ||
endchoice | ||
|
||
config ZMK_SPLIT_SERIAL_THREAD_STACK_SIZE | ||
int "Serial split thread stack size" | ||
default 1024 | ||
|
||
config ZMK_SPLIT_SERIAL_THREAD_PRIORITY | ||
int "Serial split thread priority" | ||
default 5 | ||
|
||
config ZMK_SPLIT_SERIAL_THREAD_QUEUE_SIZE | ||
int "Max number of queue size for split data buffering" | ||
default 5 | ||
|
||
# ZMK_SPLIT_SERIAL | ||
endif | ||
|
||
# ZMK_USB | ||
endif | ||
|
||
# ZMK_SPLIT_TYPE | ||
endchoice | ||
|
||
|
||
#ZMK_SPLIT | ||
endif | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,39 @@ | ||
# Copyright (c) 2021 The ZMK Contributors | ||
# SPDX-License-Identifier: MIT | ||
|
||
if SHIELD_A_DUX_LEFT || SHIELD_A_DUX_RIGHT | ||
|
||
config ZMK_SPLIT | ||
default y | ||
|
||
if SHIELD_A_DUX_LEFT | ||
|
||
config ZMK_KEYBOARD_NAME | ||
default "A. Dux" | ||
|
||
if ZMK_BLE | ||
config ZMK_SPLIT_BLE_ROLE_CENTRAL | ||
default y | ||
endif | ||
Comment on lines
+14
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be easier w/ the agnostic role config in #1314 |
||
|
||
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 |
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would the pins for a kscan device need overriding for just one board? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Existing split keyboards use any one of four ports D0, D1, D2 and D3 for split communication STM32 chips support half duplex UART comm only on TX pins. Other way is to use some KConfig variable to detect and swap pins. So in the meantime, i have just juggling the pins inside the shields directly. |
||
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)> | ||
; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright (c) 2022 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
/ { | ||
chosen { | ||
zmk,split-serial = &usart2; | ||
}; | ||
}; | ||
|
||
&usart2 { | ||
status = "okay"; | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2022 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <zephyr/types.h> | ||
#include <init.h> | ||
|
||
/* Caller does/should not need to free `data` | ||
* Data will be freed immediately after calling this callback */ | ||
typedef int (*rx_complete_t)(const uint8_t *data, size_t length); | ||
|
||
void split_serial_async_init(rx_complete_t complete_fn); | ||
|
||
void split_serial_async_send(uint8_t *data, size_t length); | ||
|
||
uint8_t *alloc_split_serial_buffer(k_timeout_t timeout); | ||
|
||
void free_split_serial_buffer(const uint8_t *data); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It this is common, it shouldn't, IMHO, be duplicated for both, but should really be a reusable common core that then delegates to the transport to send the state. |
||
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(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the refactor in #1314 which will massively simplify things drastically and avoid this change being needed.