Skip to content

Commit 688d103

Browse files
committed
esp32/machine_uart: Handle properly the timeout_char argument.
Before, it was ignored. Tested with ESP32, ESP32S3, ESP32C6. Signed-off-by: robert-hh <robert@hammelrath.com>
1 parent e73ed39 commit 688d103

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

ports/esp32/machine_uart.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -628,19 +628,18 @@ static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t
628628
return 0;
629629
}
630630

631-
TickType_t time_to_wait;
632-
if (self->timeout == 0) {
633-
time_to_wait = 0;
634-
} else {
635-
time_to_wait = pdMS_TO_TICKS(self->timeout);
636-
}
631+
TickType_t time_to_wait = self->timeout > 0 ? pdMS_TO_TICKS(self->timeout) : 0;
637632

638-
bool release_gil = time_to_wait > 0;
633+
bool release_gil = (self->timeout + self->timeout_char) > 0;
639634
if (release_gil) {
640635
MP_THREAD_GIL_EXIT();
641636
}
642637

643-
int bytes_read = uart_read_bytes(self->uart_num, buf_in, size, time_to_wait);
638+
int bytes_read = uart_read_bytes(self->uart_num, buf_in, 1, time_to_wait);
639+
if (size > 1 && bytes_read != 0) {
640+
time_to_wait = self->timeout_char > 0 ? pdMS_TO_TICKS(self->timeout_char) : 0;
641+
bytes_read += uart_read_bytes(self->uart_num, buf_in + 1, size - 1, time_to_wait);
642+
}
644643

645644
if (release_gil) {
646645
MP_THREAD_GIL_ENTER();

0 commit comments

Comments
 (0)