Skip to content

Commit

Permalink
feat(split): wired split over serial TX support (WIP 2024-05-26)
Browse files Browse the repository at this point in the history
  • Loading branch information
xudongzheng committed Jun 27, 2024
1 parent 2aa03ea commit 2f19b18
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/src/split/serial/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Copyright (c) 2023 The ZMK Contributors
# SPDX-License-Identifier: MIT

if (NOT CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
target_sources(app PRIVATE peripheral.c)
endif()

if (CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
target_sources(app PRIVATE central.c)
endif()
Expand Down
24 changes: 24 additions & 0 deletions app/src/split/serial/peripheral.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2023 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

#include <zephyr/kernel.h>

#include <zmk/split/serial/serial.h>

// TODO TODO TODO
#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(slicemk);

// TODO TODO TODO these two should be in a header somewhere

// TODO TODO TODO implement central to peripheral data transfer
void serial_handle_rx(uint32_t cmd, uint8_t *data, uint8_t len) {
LOG_HEXDUMP_ERR(data, len, "central to peripheral");
}

void send_position_state_impl(uint8_t *state, int len) {
serial_write_uart(0x73627400, state, len);
}
9 changes: 8 additions & 1 deletion app/src/split/serial/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static void serial_callback(const struct device *dev, void *data) {
}
}

void serial_write(struct serial_device *sd, uint32_t cmd, uint8_t *data, uint8_t len) {
static void serial_write(struct serial_device *sd, uint32_t cmd, uint8_t *data, uint8_t len) {
// TODO TODO TODO use buf with size SERIAL_BUF_SIZE. do single
// ring_buf_put() to avoid potential race
uint8_t header[13] = SERIAL_MSG_PREFIX;
Expand All @@ -138,6 +138,13 @@ void serial_write(struct serial_device *sd, uint32_t cmd, uint8_t *data, uint8_t
uart_irq_tx_enable(sd->dev);
}

// TODO TODO TODO this should be abstracted a bit differently
#ifdef CONFIG_ZMK_SPLIT_SERIAL_UART
void serial_write_uart(uint32_t cmd, uint8_t *data, uint8_t len) {
serial_write(&serial_devs[0], cmd, data, len);
}
#endif

#ifdef CONFIG_ZMK_SPLIT_SERIAL_UART_POLL

static void serial_tx_work_handler(struct k_work *work) {
Expand Down

0 comments on commit 2f19b18

Please sign in to comment.