summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobert-hh <robert@hammelrath.com>2022-06-19 08:44:13 +0200
committerDamien George <damien@micropython.org>2022-06-23 17:13:41 +1000
commit5f4539b0ca5c3d832122b3a44c5a075d4ceb6203 (patch)
tree9a2283f87fc6682029b2632ca7df12eb75d44272
parent425d8fc0d652a58f1a6e81d953281beb5784e18b (diff)
esp32/machine_uart: Implement the functionality of timeout_char arg.
Using it for the rx-timeout. The value is given as ms, which is then converted to character times. A value of less than a character time will cause the rx call to return immediately after 1 character, which may be inefficient at high transmission rates. Addresses #8778.
-rw-r--r--ports/esp32/machine_uart.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/ports/esp32/machine_uart.c b/ports/esp32/machine_uart.c
index c0eedb80b..49ce78b1b 100644
--- a/ports/esp32/machine_uart.c
+++ b/ports/esp32/machine_uart.c
@@ -267,12 +267,18 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
}
// set timeout_char
- // make sure it is at least as long as a whole character (13 bits to be safe)
+ // make sure it is at least as long as a whole character (12 bits here)
if (args[ARG_timeout_char].u_int != -1) {
self->timeout_char = args[ARG_timeout_char].u_int;
- uint32_t min_timeout_char = 13000 / baudrate + 1;
- if (self->timeout_char < min_timeout_char) {
- self->timeout_char = min_timeout_char;
+ uint32_t char_time_ms = 12000 / baudrate + 1;
+ uint32_t rx_timeout = self->timeout_char / char_time_ms;
+ if (rx_timeout < 1) {
+ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 1, 0)
+ uart_set_rx_full_threshold(self->uart_num, 1);
+ #endif
+ uart_set_rx_timeout(self->uart_num, 1);
+ } else {
+ uart_set_rx_timeout(self->uart_num, rx_timeout);
}
}