diff --git a/app/src/split/serial/CMakeLists.txt b/app/src/split/serial/CMakeLists.txt index 230d423565a..cec576ccbdc 100644 --- a/app/src/split/serial/CMakeLists.txt +++ b/app/src/split/serial/CMakeLists.txt @@ -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() diff --git a/app/src/split/serial/peripheral.c b/app/src/split/serial/peripheral.c new file mode 100644 index 00000000000..c6299f0884f --- /dev/null +++ b/app/src/split/serial/peripheral.c @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include + +#include + +// TODO TODO TODO +#include +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); +} diff --git a/app/src/split/serial/serial.c b/app/src/split/serial/serial.c index a4876b60822..1775e3a2c33 100644 --- a/app/src/split/serial/serial.c +++ b/app/src/split/serial/serial.c @@ -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; @@ -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) {