Skip to content

Commit

Permalink
nrf/drivers/usb: Probe for interrupt char in USB CDC task.
Browse files Browse the repository at this point in the history
And ensure that the input queue is empty when scheduling the interrupt.
  • Loading branch information
robert-hh authored and dpgeorge committed Jul 16, 2022
1 parent 30c7f17 commit 60539ea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ports/nrf/drivers/bluetooth/ble_uart.c
Expand Up @@ -193,9 +193,9 @@ STATIC void gatts_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t at
for (uint16_t i = 0; i < length; i++) {
#if MICROPY_KBD_EXCEPTION
if (data[i] == mp_interrupt_char) {
mp_sched_keyboard_interrupt();
m_rx_ring_buffer.start = 0;
m_rx_ring_buffer.end = 0;
mp_sched_keyboard_interrupt();
} else
#endif
{
Expand Down
10 changes: 9 additions & 1 deletion ports/nrf/drivers/usb/usb_cdc.c
Expand Up @@ -35,6 +35,8 @@
#include "nrfx_uart.h"
#include "py/ringbuf.h"
#include "py/stream.h"
#include "py/runtime.h"
#include "shared/runtime/interrupt_char.h"

#ifdef BLUETOOTH_SD
#include "nrf_sdm.h"
Expand Down Expand Up @@ -127,7 +129,13 @@ static void cdc_task(void)
int c;
uint32_t count = tud_cdc_read(&c, 1);
(void)count;
ringbuf_put((ringbuf_t*)&rx_ringbuf, c);
if (c == mp_interrupt_char) {
rx_ringbuf.iget = 0;
rx_ringbuf.iput = 0;
mp_sched_keyboard_interrupt();
} else {
ringbuf_put((ringbuf_t*)&rx_ringbuf, c);
}
}

int chars = 0;
Expand Down
2 changes: 2 additions & 0 deletions ports/nrf/modules/machine/uart.c
Expand Up @@ -128,6 +128,8 @@ STATIC void uart_event_handler(nrfx_uart_event_t const *p_event, void *p_context
nrfx_uart_rx(self->p_uart, &self->buf->rx_buf[0], 1);
#if !MICROPY_PY_BLE_NUS && MICROPY_KBD_EXCEPTION
if (chr == mp_interrupt_char) {
self->buf->rx_ringbuf.iget = 0;
self->buf->rx_ringbuf.iput = 0;
mp_sched_keyboard_interrupt();
} else
#endif
Expand Down

0 comments on commit 60539ea

Please sign in to comment.