From bd097de27787baaa3ec073d2247b8cb6638474b0 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 12 May 2023 16:49:11 -0700 Subject: [PATCH] Check usb/jtag for incoming chars too --- ports/espressif/supervisor/usb_serial_jtag.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ports/espressif/supervisor/usb_serial_jtag.c b/ports/espressif/supervisor/usb_serial_jtag.c index 646d2c3a5e..9350d1bf97 100644 --- a/ports/espressif/supervisor/usb_serial_jtag.c +++ b/ports/espressif/supervisor/usb_serial_jtag.c @@ -101,21 +101,28 @@ bool usb_serial_jtag_connected(void) { } char usb_serial_jtag_read_char(void) { - if (ringbuf_num_filled(&ringbuf) == 0) { + if (ringbuf_num_filled(&ringbuf) == 0 && !usb_serial_jtag_ll_rxfifo_data_available()) { return -1; } - char c = ringbuf_get(&ringbuf); + char c = -1; + if (ringbuf_num_filled(&ringbuf) > 0) { + c = ringbuf_get(&ringbuf); + } // Maybe re-enable the recv interrupt if we've emptied the ringbuf. if (ringbuf_num_filled(&ringbuf) == 0) { usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT); _copy_out_of_fifo(); usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT); + // May have only been ctrl-c. + if (c == -1 && ringbuf_num_filled(&ringbuf) > 0) { + c = ringbuf_get(&ringbuf); + } } return c; } bool usb_serial_jtag_bytes_available(void) { - return ringbuf_num_filled(&ringbuf) > 0; + return ringbuf_num_filled(&ringbuf) > 0 || usb_serial_jtag_ll_rxfifo_data_available(); } void usb_serial_jtag_write(const char *text, uint32_t length) {