diff --git a/app/src/split/serial/CMakeLists.txt b/app/src/split/serial/CMakeLists.txt index 230d423565aa..cec576ccbdcf 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 000000000000..696f28e6e68f --- /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 fa1345972ef9..d239451332d8 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_POLLING static void serial_tx_work_handler(struct k_work *work) { diff --git a/app/src/split/service.c b/app/src/split/service.c index d0b610a17e86..9a87f4e94e50 100644 --- a/app/src/split/service.c +++ b/app/src/split/service.c @@ -38,6 +38,7 @@ void send_position_state_callback(struct k_work *work) { K_WORK_DEFINE(service_position_notify_work, send_position_state_callback); int send_position_state() { + LOG_INF("TODO TODO TODO sending"); int err = k_msgq_put(&position_state_msgq, position_state, K_MSEC(100)); if (err) { switch (err) {