Skip to content

Commit 406e46f

Browse files
committed
Allow serial "break" to trigger KeyboardInterrupt
When the USB serial buffer is full, the Ctrl-C code to send KeyboardInterrupt can't be sent, which creates a problem if you've pasted code or otherwise filled the buffer and need to recover. A similar problem affects advanced UIs that interact with CircuitPython and may send characters when they're unexpected, such as mu when it tries to move the cursor based on the user clicking on the screen. The main way forward seems to be to use some kind of message that can still reach CircuitPython when its internal serial recieve buffer is full. RS232 defines a "break" signal, in which the transmitting device holds its data line in the "space" state for many entire character times. This still exists in the world of USB serial. This does work, sort of, except that your host computer software will need to properly handle blocking serial writes; tio can send a break with the **ctrl-c b** sequence, but this only works if it hasn't yet written too much data, so it doesn't actually help in most situations :-/
1 parent ef34378 commit 406e46f

File tree

1 file changed

+6
-0
lines changed
  • supervisor/shared/usb

1 file changed

+6
-0
lines changed

supervisor/shared/usb/usb.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,10 @@ void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char) {
359359
}
360360
}
361361

362+
void tud_cdc_send_break_cb(uint8_t itf, uint16_t duration_ms) {
363+
if (usb_cdc_console_enabled() && mp_interrupt_char != -1 && itf == 0 && duration_ms > 0) {
364+
mp_sched_keyboard_interrupt();
365+
}
366+
}
367+
362368
#endif

0 commit comments

Comments
 (0)