diff options
| author | Dan Halbert <halbert@halwitz.org> | 2020-04-21 17:37:22 -0400 |
|---|---|---|
| committer | Dan Halbert <halbert@halwitz.org> | 2020-04-21 17:38:20 -0400 |
| commit | 38ec3bc57476c6fde45cd7d722370a5408fd8e10 (patch) | |
| tree | bea75dc24a3f94c14e564cb885af3fde87f9c033 /ports/stm/common-hal/busio/UART.c | |
| parent | 1a71c8c51577cc7014d5db1c05084778c0b977e9 (diff) | |
further ringbuf cleanup
Diffstat (limited to 'ports/stm/common-hal/busio/UART.c')
| -rw-r--r-- | ports/stm/common-hal/busio/UART.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/ports/stm/common-hal/busio/UART.c b/ports/stm/common-hal/busio/UART.c index cb5460c68..d1ee146f1 100644 --- a/ports/stm/common-hal/busio/UART.c +++ b/ports/stm/common-hal/busio/UART.c @@ -262,7 +262,7 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t uint64_t start_ticks = supervisor_ticks_ms64(); // Wait for all bytes received or timeout, same as nrf - while ( (ringbuf_count(&self->rbuf) < len) && (supervisor_ticks_ms64() - start_ticks < self->timeout_ms) ) { + while ( (ringbuf_avail(&self->rbuf) < len) && (supervisor_ticks_ms64() - start_ticks < self->timeout_ms) ) { RUN_BACKGROUND_TASKS; //restart if it failed in the callback if (errflag != HAL_OK) { @@ -276,12 +276,8 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t // Halt reception HAL_NVIC_DisableIRQ(self->irq); - // copy received data - rx_bytes = ringbuf_count(&self->rbuf); - rx_bytes = MIN(rx_bytes, len); - for (uint16_t i = 0; i < rx_bytes; i++) { - data[i] = ringbuf_get(&self->rbuf); - } + // Copy as much received data as available, up to len bytes. + size_t rx_bytes = ringbuf_get_n(&self->rbuf, data, len); HAL_NVIC_EnableIRQ(self->irq); if (rx_bytes == 0) { @@ -380,7 +376,7 @@ void common_hal_busio_uart_set_timeout(busio_uart_obj_t *self, mp_float_t timeou } uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) { - return ringbuf_count(&self->rbuf); + return ringbuf_avail(&self->rbuf); } void common_hal_busio_uart_clear_rx_buffer(busio_uart_obj_t *self) { |
