10000 esp32/machine_uart: Always configure timeout_char setting in init(). · mancausoft/micropython@20f85fb · GitHub
[go: up one dir, main page]

Skip to content

Commit 20f85fb

Browse files
DvdGiessendpgeorge
authored andcommitted
esp32/machine_uart: Always configure timeout_char setting in init().
If the `timeout_char` parameter is not given, we should still configure the UART to ensure the UART is always initialized consistently. So the default of 0 gets applied correctly, or if, for example, the baudrate was changed the char timeout isn't still based on the old baudrate causing weird behaviour, etc. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
1 parent cdfc6c1 commit 20f85fb

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

ports/esp32/machine_uart.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,17 +277,17 @@ static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args,
277277
}
278278

279279
// set timeout_char
280-
// make sure it is at least as long as a whole character (12 bits here)
281280
if (args[ARG_timeout_char].u_int != -1) {
282281
self->timeout_char = args[ARG_timeout_char].u_int;
283-
uint32_t char_time_ms = 12000 / baudrate + 1;
284-
uint32_t rx_timeout = self->timeout_char / char_time_ms;
285-
if (rx_timeout < 1) {
286-
check_esp_err(uart_set_rx_full_threshold(self->uart_num, 1));
287-
check_esp_err(uart_set_rx_timeout(self->uart_num, 1));
288-
} else {
289-
check_esp_err(uart_set_rx_timeout(self->uart_num, rx_timeout));
290-
}
282+
}
283+
// make sure it is at least as long as a whole character (12 bits here)
284+
uint32_t char_time_ms = 12000 / baudrate + 1;
285+
uint32_t rx_timeout = self->timeout_char / char_time_ms;
286+
if (rx_timeout < 1) {
287+
check_esp_err(uart_set_rx_full_threshold(self->uart_num, 1));
288+
check_esp_err(uart_set_rx_timeout(self->uart_num, 1));
289+
} else {
290+
check_esp_err(uart_set_rx_timeout(self->uart_num, rx_timeout));
291 45DE 291
}
292292

293293
// set line inversion

0 commit comments

Comments
 (0)
0