From f357aeddc8c1f716c00621fe74a6d08883c183f1 Mon Sep 17 00:00:00 2001 From: Megamind <68985133+megamind4089@users.noreply.github.com> Date: Sun, 6 Feb 2022 16:14:36 +0800 Subject: [PATCH] Address comments --- app/Kconfig | 29 +++++++++------------- app/boards/shields/a_dux/Kconfig.defconfig | 2 -- app/src/split/serial/central.c | 19 ++++++-------- app/src/split/serial/service.c | 12 ++++----- 4 files changed, 25 insertions(+), 37 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index 81c08b31..d406864e 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -238,26 +238,21 @@ menuconfig ZMK_SPLIT_SERIAL_ROLE_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 +config ZMK_SPLIT_SERIAL_THREAD_STACK_SIZE + int "Serial split thread stack size" + default 128 + +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 diff --git a/app/boards/shields/a_dux/Kconfig.defconfig b/app/boards/shields/a_dux/Kconfig.defconfig index 9e42da22..63612e56 100644 --- a/app/boards/shields/a_dux/Kconfig.defconfig +++ b/app/boards/shields/a_dux/Kconfig.defconfig @@ -3,10 +3,8 @@ 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 diff --git a/app/src/split/serial/central.c b/app/src/split/serial/central.c index 80186614..54e8dd2b 100644 --- a/app/src/split/serial/central.c +++ b/app/src/split/serial/central.c @@ -19,28 +19,25 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include #include -#if DT_HAS_CHOSEN(zmk_split_serial) +#if !DT_HAS_CHOSEN(zmk_split_serial) + #error "No zmk-split-serial node is chosen" +#endif #define UART_NODE1 DT_CHOSEN(zmk_split_serial) const struct device *serial_dev = DEVICE_DT_GET(UART_NODE1); static int uart_ready = 0; -#define CONFIG_ZMK_SPLIT_SERIAL_CENTRAL_POSITION_QUEUE_SIZE 5 - -#define CONFIG_SERIAL_THREAD_STACK_SIZE 128 -#define CONFIG_SERIAL_THREAD_PRIORITY 5 - static void split_serial_receive_thread(void *unused, void *unused1, void *unused2); K_MEM_SLAB_DEFINE(split_memory_slab, sizeof(split_data_t), \ - CONFIG_ZMK_SPLIT_SERIAL_CENTRAL_POSITION_QUEUE_SIZE, 4); + CONFIG_ZMK_SPLIT_SERIAL_THREAD_QUEUE_SIZE, 4); K_MSGQ_DEFINE(peripheral_event_msgq, sizeof(struct zmk_position_state_changed), \ - CONFIG_ZMK_SPLIT_SERIAL_CENTRAL_POSITION_QUEUE_SIZE, 4); + CONFIG_ZMK_SPLIT_SERIAL_THREAD_QUEUE_SIZE, 4); -K_THREAD_DEFINE(split_central, CONFIG_SERIAL_THREAD_STACK_SIZE, +K_THREAD_DEFINE(split_central, CONFIG_ZMK_SPLIT_SERIAL_THREAD_STACK_SIZE, split_serial_receive_thread, NULL, NULL, NULL, - K_PRIO_PREEMPT(CONFIG_SERIAL_THREAD_PRIORITY), 0, 0); + K_PRIO_PREEMPT(CONFIG_ZMK_SPLIT_SERIAL_THREAD_PRIORITY), 0, 0); static void peripheral_event_work_callback(struct k_work *work) { @@ -186,5 +183,3 @@ static void split_serial_receive_thread(void *unused, void *unused1, void *unuse }; } -#endif /* DT_HAS_CHOSEN(zmk_matrix_transform) */ - diff --git a/app/src/split/serial/service.c b/app/src/split/serial/service.c index d3b7e325..a0559967 100644 --- a/app/src/split/serial/service.c +++ b/app/src/split/serial/service.c @@ -18,7 +18,9 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include -#if DT_HAS_CHOSEN(zmk_split_serial) +#if !DT_HAS_CHOSEN(zmk_split_serial) + #error "No zmk-split-serial node is chosen" +#endif #define UART_NODE1 DT_CHOSEN(zmk_split_serial) const struct device *serial_dev = DEVICE_DT_GET(UART_NODE1); @@ -26,12 +28,12 @@ static int uart_ready = 0; static uint8_t position_state[SPLIT_DATA_LEN]; -K_THREAD_STACK_DEFINE(service_q_stack, CONFIG_ZMK_SPLIT_SERIAL_PERIPHERAL_STACK_SIZE); +K_THREAD_STACK_DEFINE(service_q_stack, CONFIG_ZMK_SPLIT_SERIAL_THREAD_STACK_SIZE); struct k_work_q service_work_q; K_MSGQ_DEFINE(position_state_msgq, sizeof(char[SPLIT_DATA_LEN]), - CONFIG_ZMK_SPLIT_SERIAL_PERIPHERAL_POSITION_QUEUE_SIZE, 4); + CONFIG_ZMK_SPLIT_SERIAL_THREAD_QUEUE_SIZE, 4); void send_data_via_uart(const struct device *dev, char *data, size_t len) { @@ -95,12 +97,10 @@ int service_init(const struct device *_arg) { uart_ready = 1; LOG_INF("UART device:%s ready", serial_dev->name); k_work_q_start(&service_work_q, service_q_stack, K_THREAD_STACK_SIZEOF(service_q_stack), - CONFIG_ZMK_SPLIT_SERIAL_PERIPHERAL_PRIORITY); + CONFIG_ZMK_SPLIT_SERIAL_THREAD_PRIORITY); return 0; } SYS_INIT(service_init, APPLICATION, CONFIG_ZMK_USB_INIT_PRIORITY); -#endif /* DT_HAS_CHOSEN(zmk_matrix_transform) */ -