From ff2f0d943b88037160327bef6da4006089d887ae Mon Sep 17 00:00:00 2001 From: zvecr Date: Wed, 23 Nov 2022 17:43:55 +0000 Subject: [PATCH] ChibiOS - Non blocking xap_send_base --- keyboards/zvecr/zv48/keymaps/xap/keymap.c | 11 +++++++++++ tmk_core/protocol/chibios/usb_main.c | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/keyboards/zvecr/zv48/keymaps/xap/keymap.c b/keyboards/zvecr/zv48/keymaps/xap/keymap.c index c45e573bd93..36828f54e46 100644 --- a/keyboards/zvecr/zv48/keymaps/xap/keymap.c +++ b/keyboards/zvecr/zv48/keymaps/xap/keymap.c @@ -100,3 +100,14 @@ const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = { [_ADJUST] = { ENCODER_CCW_CW(RGB_RMOD, RGB_MOD), ENCODER_CCW_CW(KC_RIGHT, KC_LEFT) }, }; #endif + +void housekeeping_task_user(void) { + static uint32_t timer = 0; + static uint8_t count = 0; + if (timer_elapsed32(timer) > 1000) { + timer = timer_read32(); + count++; + + xap_broadcast(0x03, &count, 1); + } +} diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index ae8386c1b00..ef9dbf8edc9 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -1138,7 +1138,13 @@ void xap_send_base(uint8_t *data, uint8_t length) { if (length != XAP_EPSIZE) { return; } - chnWrite(&drivers.xap_driver.driver, data, length); + + // see console sendchar for timeout details + static bool timed_out = false; + + const sysinterval_t timeout = timed_out ? TIME_IMMEDIATE : TIME_MS2I(5); + const size_t result = chnWriteTimeout(&drivers.xap_driver.driver, data, length, timeout); + timed_out = (result == 0); } void xap_send(xap_token_t token, xap_response_flags_t response_flags, const void *data, size_t length) {