8000 When UART timeout of zero is given, make read() return data already a… · flummer/circuitpython@02b3f62 · GitHub
[go: up one dir, main page]

Skip to content

Commit 02b3f62

Browse files
PaulKiersteaddhalbert
authored andcommitted
When UART timeout of zero is given, make read() return data already available
1 parent 2cb7039 commit 02b3f62

File tree

1 file changed

+5
-1
lines changed
  • ports/atmel-samd/common-hal/busio

1 file changed

+5
-1
lines changed

ports/atmel-samd/common-hal/busio/UART.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
254254
uint64_t start_ticks = ticks_ms;
255255

256256
// Busy-wait until timeout or until we've read enough chars.
257-
while (ticks_ms - start_ticks < self->timeout_ms) {
257+
while (ticks_ms - start_ticks <= self->timeout_ms) {
258258
// Read as many chars as we can right now, up to len.
259259
size_t num_read = io_read(io, data, len);
260260

@@ -273,6 +273,10 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
273273
#ifdef MICROPY_VM_HOOK_LOOP
274274
MICROPY_VM_HOOK_LOOP
275275
#endif
276+
// If we are zero timeout, make sure we don't loop again (in the event
277+
// we read in under 1ms)
278+
if (self->timeout_ms == 0)
279+
break;
276280
}
277281

278282
if (total_read == 0) {

0 commit comments

Comments
 (0)
0