summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/esp32/machine_uart.c23
1 files changed, 7 insertions, 16 deletions
diff --git a/ports/esp32/machine_uart.c b/ports/esp32/machine_uart.c
index 49ce78b1b..28110e39f 100644
--- a/ports/esp32/machine_uart.c
+++ b/ports/esp32/machine_uart.c
@@ -399,28 +399,19 @@ STATIC mp_obj_t machine_uart_sendbreak(mp_obj_t self_in) {
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
// Save settings
- uart_word_length_t word_length;
- uart_parity_t parity;
- uart_get_word_length(self->uart_num, &word_length);
- uart_get_parity(self->uart_num, &parity);
+ uint32_t baudrate;
+ uart_get_baudrate(self->uart_num, &baudrate);
- // Synthesise the break condition by either a longer word or using even parity
+ // Synthesise the break condition by reducing the baud rate,
+ // and cater for the worst case of 5 data bits, no parity.
uart_wait_tx_done(self->uart_num, pdMS_TO_TICKS(1000));
- if (word_length != UART_DATA_8_BITS) {
- uart_set_word_length(self->uart_num, UART_DATA_8_BITS);
- } else if (parity == UART_PARITY_DISABLE) {
- uart_set_parity(self->uart_num, UART_PARITY_EVEN);
- } else {
- // Cannot synthesise break
- mp_raise_OSError(MP_EPERM);
- }
+ uart_set_baudrate(self->uart_num, baudrate * 6 / 15);
char buf[1] = {0};
uart_write_bytes(self->uart_num, buf, 1);
uart_wait_tx_done(self->uart_num, pdMS_TO_TICKS(1000));
- // Restore original settings
- uart_set_word_length(self->uart_num, word_length);
- uart_set_parity(self->uart_num, parity);
+ // Restore original setting
+ uart_set_baudrate(self->uart_num, baudrate);
return mp_const_none;
}