Skip to content

Commit 907b441

Browse files
committed
Add .baudrate support to ESP8266.
busio.UART on ESP8266 provides a TX-only UART on GPIO2. Fixed some bugs in the implementation.
1 parent 6daf4bd commit 907b441

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

ports/esp8266/common-hal/busio/UART.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
4040
const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate,
4141
uint8_t bits, uart_parity_t parity, uint8_t stop, uint32_t timeout,
4242
uint8_t receiver_buffer_size) {
43-
if (rx != NULL || tx != &pin_GPIO2) {
43+
if (rx != mp_const_none || tx != &pin_GPIO2) {
4444
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Only tx supported on UART1 (GPIO2)."));
4545
}
46+
4647
// set baudrate
4748
UartDev.baut_rate = baudrate;
49+
self->baudrate = baudrate;
4850

4951
// set data bits
5052
switch (bits) {
@@ -90,6 +92,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
9092
}
9193

9294
uart_setup(UART1);
95+
self->deinited = false;
9396
}
9497

9598
bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) {
@@ -100,7 +103,8 @@ void common_hal_busio_uart_deinit(busio_uart_obj_t *self) {
100103
if (common_hal_busio_uart_deinited(self)) {
101104
return;
102105
}
103-
PIN_FUNC_SELECT(FUNC_U1TXD_BK, 0);
106+
// Switch GPIO2 back to a GPIO pin.
107+
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
104108
self->deinited = true;
105109
}
106110

@@ -119,6 +123,16 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data,
119123
return len;
120124
}
121125

126+
uint32_t common_hal_busio_uart_get_baudrate(busio_uart_obj_t *self) {
127+
return self->baudrate;
128+
}
129+
130+
void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrate) {
131+
UartDev.baut_rate = baudrate;
132+
uart_setup(UART1);
133+
self->baudrate = baudrate;
134+
}
135+
122136
uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) {
123137
return 0;
124138
}

ports/esp8266/common-hal/busio/UART.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
typedef struct {
3535
mp_obj_base_t base;
36+
uint32_t baudrate;
3637
bool deinited;
3738
} busio_uart_obj_t;
3839

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