Skip to content

Commit 419d354

Browse files
committed
esp32/machine_uart: Don't save baudrate but compute it instead.
1 parent 6c62e70 commit 419d354

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

esp32/machine_uart.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ typedef struct _machine_uart_obj_t {
4242
uint8_t bits;
4343
uint8_t parity;
4444
uint8_t stop;
45-
uint32_t baudrate;
4645
int8_t tx;
4746
int8_t rx;
4847
int8_t rts;
@@ -60,8 +59,10 @@ QueueHandle_t UART_QUEUE[UART_NUM_MAX] = {};
6059

6160
STATIC void machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
6261
machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
62+
uint32_t baudrate;
63+
uart_get_baudrate(self->uart_num, &baudrate);
6364
mp_printf(print, "UART(%u, baudrate=%u, bits=%u, parity=%s, stop=%u, tx=%d, rx=%d, rts=%d, cts=%d, timeout=%u, timeout_char=%u)",
64-
self->uart_num, self->baudrate, self->bits, _parity_name[self->parity],
65+
self->uart_num, baudrate, self->bits, _parity_name[self->parity],
6566
self->stop, self->tx, self->rx, self->rts, self->cts, self->timeout, self->timeout_char);
6667
}
6768

@@ -86,9 +87,10 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
8687
uart_wait_tx_done(self->uart_num, pdMS_TO_TICKS(1000));
8788

8889
// set baudrate
90+
uint32_t baudrate = 115200;
8991
if (args[ARG_baudrate].u_int > 0) {
90-
self->baudrate = args[ARG_baudrate].u_int;
91-
uart_set_baudrate(self->uart_num, self->baudrate);
92+
uart_set_baudrate(self->uart_num, args[ARG_baudrate].u_int);
93+
uart_get_baudrate(self->uart_num, &baudrate);
9294
}
9395

9496
uart_set_pin(self->uart_num, args[ARG_tx].u_int, args[ARG_rx].u_int, args[ARG_rts].u_int, args[ARG_cts].u_int);
@@ -174,7 +176,7 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
174176
// set timeout_char
175177
// make sure it is at least as long as a whole character (13 bits to be safe)
176178
self->timeout_char = args[ARG_timeout_char].u_int;
177-
uint32_t min_timeout_char = 13000 / self->baudrate + 1;
179+
uint32_t min_timeout_char = 13000 / baudrate + 1;
178180
if (self->timeout_char < min_timeout_char) {
179181
self->timeout_char = min_timeout_char;
180182
}
@@ -209,7 +211,6 @@ STATIC mp_obj_t machine_uart_make_new(const mp_obj_type_t *type, size_t n_args,
209211
machine_uart_obj_t *self = m_new_obj(machine_uart_obj_t);
210212
self->base.type = &machine_uart_type;
211213
self->uart_num = uart_num;
212-
self->baudrate = 115200;
213214
self->bits = 8;
214215
self->parity = 0;
215216
self->stop = 1;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy