mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
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>
This commit is contained in:
@@ -668,19 +668,18 @@ static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TickType_t time_to_wait;
|
TickType_t time_to_wait = self->timeout > 0 ? pdMS_TO_TICKS(self->timeout) : 0;
|
||||||
if (self->timeout == 0) {
|
|
||||||
time_to_wait = 0;
|
|
||||||
} else {
|
|
||||||
time_to_wait = pdMS_TO_TICKS(self->timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool release_gil = time_to_wait > 0;
|
bool release_gil = (self->timeout + self->timeout_char) > 0;
|
||||||
if (release_gil) {
|
if (release_gil) {
|
||||||
MP_THREAD_GIL_EXIT();
|
MP_THREAD_GIL_EXIT();
|
||||||
}
|
}
|
||||||
|
|
||||||
int bytes_read = uart_read_bytes(self->uart_num, buf_in, size, time_to_wait);
|
int bytes_read = uart_read_bytes(self->uart_num, buf_in, 1, time_to_wait);
|
||||||
|
if (size > 1 && bytes_read != 0) {
|
||||||
|
time_to_wait = self->timeout_char > 0 ? pdMS_TO_TICKS(self->timeout_char) : 0;
|
||||||
|
bytes_read += uart_read_bytes(self->uart_num, buf_in + 1, size - 1, time_to_wait);
|
||||||
|
}
|
||||||
|
|
||||||
if (release_gil) {
|
if (release_gil) {
|
||||||
MP_THREAD_GIL_ENTER();
|
MP_THREAD_GIL_ENTER();
|
||||||
|
|||||||
Reference in New Issue
Block a user