Skip to content

Commit

Permalink
Merge pull request #1159 from PaulKierstead/master
Browse files Browse the repository at this point in the history
When UART timeout of zero is given, make read() return data already a…
  • Loading branch information
dhalbert committed Sep 4, 2018
2 parents 9b98ad7 + 2d3f1a1 commit ba6e1b6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ports/atmel-samd/common-hal/busio/UART.c
Expand Up @@ -249,7 +249,7 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
uint64_t start_ticks = ticks_ms;

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

Expand All @@ -268,6 +268,10 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
#ifdef MICROPY_VM_HOOK_LOOP
MICROPY_VM_HOOK_LOOP
#endif
// If we are zero timeout, make sure we don't loop again (in the event
// we read in under 1ms)
if (self->timeout_ms == 0)
break;
}

if (total_read == 0) {
Expand Down

0 comments on commit ba6e1b6

Please sign in to comment.