Skip to content

Commit

Permalink
fixup! feat(split): Add full-duplex wired split support
Browse files Browse the repository at this point in the history
  • Loading branch information
petejohanson committed Mar 2, 2025
1 parent c05f327 commit f15acf1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
11 changes: 9 additions & 2 deletions app/src/split/wired/central.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ static inline int can_tx(void) { return 0; }

#endif

#if IS_ENABLED(CONFIG_ZMK_SPLIT_WIRED_UART_MODE_POLLING)

static void send_pending_tx_work_cb(struct k_work *work);

static K_WORK_DEFINE(wired_central_tx_work, send_pending_tx_work_cb);

#endif

static void begin_tx(void) {
#if IS_ENABLED(CONFIG_ZMK_SPLIT_WIRED_UART_MODE_INTERRUPT)
uart_irq_tx_enable(uart);
Expand Down Expand Up @@ -233,11 +241,10 @@ static void send_pending_tx_work_cb(struct k_work *work) {
}

static void read_timer_cb(struct k_timer *_timer) {
zmk_split_wired_poll_in(&rx_buf, uart, &publish_events, sizeof(struct event_envelope));
zmk_split_wired_poll_in(&rx_buf, uart, &publish_events, NULL);
// Check if we found any bytes, read some, or read all the bytes in the RX
}

static K_WORK_DEFINE(wired_central_tx_work, send_pending_tx_work_cb);
static K_TIMER_DEFINE(wired_central_read_timer, read_timer_cb, NULL);

#endif
Expand Down
3 changes: 1 addition & 2 deletions app/src/split/wired/peripheral.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ static void send_pending_tx_work_cb(struct k_work *work) {
static K_WORK_DEFINE(send_pending_tx, send_pending_tx_work_cb);

static void wired_peripheral_read_tick_cb(struct k_timer *timer) {
zmk_split_wired_poll_in(&chosen_rx_buf, uart, &publish_commands,
sizeof(struct command_envelope));
zmk_split_wired_poll_in(&chosen_rx_buf, uart, NULL, process_tx_cb);
}

static K_TIMER_DEFINE(wired_peripheral_read_timer, wired_peripheral_read_tick_cb, NULL);
Expand Down
5 changes: 2 additions & 3 deletions app/src/split/wired/wired.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ void zmk_split_wired_poll_out(struct ring_buf *tx_buf, const struct device *uart

int zmk_split_wired_poll_in(struct ring_buf *rx_buf, const struct device *uart,
struct k_work *process_data_work,
zmk_split_wired_process_tx_callback_t process_data_cb,
size_t envelope_size) {
zmk_split_wired_process_tx_callback_t process_data_cb) {
uint8_t *buf;
uint32_t read = 0;
uint32_t claim_len = ring_buf_put_claim(rx_buf, &buf, ring_buf_space_get(rx_buf));
Expand All @@ -52,7 +51,7 @@ int zmk_split_wired_poll_in(struct ring_buf *rx_buf, const struct device *uart,

ring_buf_put_finish(rx_buf, read);

if (ring_buf_size_get(rx_buf) >= envelope_size) {
if (ring_buf_size_get(rx_buf) >= 0) {
if (process_data_work) {
k_work_submit(process_data_work);
} else if (process_data_cb) {
Expand Down
3 changes: 1 addition & 2 deletions app/src/split/wired/wired.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ void zmk_split_wired_poll_out(struct ring_buf *tx_buf, const struct device *uart

int zmk_split_wired_poll_in(struct ring_buf *rx_buf, const struct device *uart,
struct k_work *process_data_work,
zmk_split_wired_process_tx_callback_t process_data_cb,
size_t envelope_size);
zmk_split_wired_process_tx_callback_t process_data_cb);

#endif

Expand Down

0 comments on commit f15acf1

Please sign in to comment.