Skip to content

Commit

Permalink
Always clear RX buffer on CTRL-C
Browse files Browse the repository at this point in the history
Some serial sources clear their RX buffers and others didn't. This
cause CP to skip into the REPL based on characters typed before the
CTRL-C. The serial file transfer code looks for "press any key"
which is skipped in this case.

Fixes circuitpython/web-editor#238
  • Loading branch information
tannewt committed Sep 12, 2024
1 parent 30d57b1 commit b5517cb
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions ports/espressif/common-hal/_bleio/CharacteristicBuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void bleio_characteristic_buffer_extend(bleio_characteristic_buffer_obj_t *self,
for (uint16_t i = 0; i < len; i++) {
if (data[i] == mp_interrupt_char) {
mp_sched_keyboard_interrupt();
ringbuf_clear(&self->ringbuf);
} else {
ringbuf_put(&self->ringbuf, data[i]);
}
Expand Down
1 change: 1 addition & 0 deletions ports/espressif/supervisor/usb_serial_jtag.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static void _copy_out_of_fifo(void) {
for (size_t i = 0; i < len; ++i) {
if (rx_buf[i] == mp_interrupt_char) {
mp_sched_keyboard_interrupt();
ringbuf_clear(&ringbuf);
} else {
ringbuf_put(&ringbuf, rx_buf[i]);
}
Expand Down
1 change: 1 addition & 0 deletions ports/nordic/common-hal/_bleio/CharacteristicBuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ static void write_to_ringbuf(bleio_characteristic_buffer_obj_t *self, uint8_t *d
for (uint16_t i = 0; i < len; i++) {
if (data[i] == mp_interrupt_char) {
mp_sched_keyboard_interrupt();
ringbuf_clear(&self->ringbuf);
} else {
ringbuf_put(&self->ringbuf, data[i]);
}
Expand Down
3 changes: 2 additions & 1 deletion supervisor/shared/usb/host_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ static void send_bufn_core(const char *buf, size_t n) {
for (; n--; buf++) {
int code = *buf;
if (code == mp_interrupt_char) {
ringbuf_clear(&_incoming_ringbuf);
mp_sched_keyboard_interrupt();
return;
continue;
}
if (ringbuf_num_empty(&_incoming_ringbuf) == 0) {
// Drop on the floor
Expand Down
1 change: 1 addition & 0 deletions supervisor/shared/web_workflow/websocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ void websocket_background(void) {
while (ringbuf_num_empty(&_incoming_ringbuf) > 0 &&
_read_next_payload_byte(&c)) {
if (c == mp_interrupt_char) {
ringbuf_clear(&_incoming_ringbuf);
mp_sched_keyboard_interrupt();
continue;
}
Expand Down

0 comments on commit b5517cb

Please sign in to comment.