From 2e214843db7a81308e931169504a8a60d07d34bc Mon Sep 17 00:00:00 2001 From: "Dirk O. Kaar" Date: Wed, 31 Mar 2021 15:24:29 +0200 Subject: [PATCH 1/2] Minor code cleanup. --- cores/esp8266/uart.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/cores/esp8266/uart.cpp b/cores/esp8266/uart.cpp index 7ad926cb9..4b7c189dd 100644 --- a/cores/esp8266/uart.cpp +++ b/cores/esp8266/uart.cpp @@ -775,17 +775,14 @@ uart_swap(uart_t* uart, int tx_pin) { pinMode(uart->tx_pin, INPUT); uart->tx_pin = 15; + pinMode(uart->tx_pin, FUNCTION_4); } if(uart->rx_enabled) //RX { pinMode(uart->rx_pin, INPUT); uart->rx_pin = 13; + pinMode(uart->rx_pin, FUNCTION_4); } - if(uart->tx_enabled) - pinMode(uart->tx_pin, FUNCTION_4); //TX - - if(uart->rx_enabled) - pinMode(uart->rx_pin, FUNCTION_4); //RX IOSWAP |= (1 << IOSWAPU0); return true; @@ -796,17 +793,14 @@ uart_swap(uart_t* uart, int tx_pin) { pinMode(uart->tx_pin, INPUT); uart->tx_pin = (tx_pin == 2)?2:1; + pinMode(uart->tx_pin, (tx_pin == 2)?FUNCTION_4:SPECIAL); } if(uart->rx_enabled) //RX { pinMode(uart->rx_pin, INPUT); uart->rx_pin = 3; + pinMode(3, SPECIAL); } - if(uart->tx_enabled) - pinMode(uart->tx_pin, (tx_pin == 2)?FUNCTION_4:SPECIAL); //TX - - if(uart->rx_enabled) - pinMode(3, SPECIAL); //RX IOSWAP &= ~(1 << IOSWAPU0); return true; @@ -832,14 +826,18 @@ uart_set_tx(uart_t* uart, int tx_pin) case UART0: if(uart->tx_enabled) { - if (uart->tx_pin == 1 && tx_pin == 2) + if (uart->tx_pin == tx_pin) + { + return true; + } + else if (tx_pin == 2) { pinMode(uart->tx_pin, INPUT); - uart->tx_pin = 2; + uart->tx_pin = tx_pin; pinMode(uart->tx_pin, FUNCTION_4); return true; } - else if (uart->tx_pin == 2 && tx_pin != 2) + else if (tx_pin != 2) { pinMode(uart->tx_pin, INPUT); uart->tx_pin = 1; From cd7d137774c885135d958834d4dee878bf8b935f Mon Sep 17 00:00:00 2001 From: "Dirk O. Kaar" Date: Sun, 4 Apr 2021 19:26:24 +0200 Subject: [PATCH 2/2] Per review. --- cores/esp8266/uart.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/cores/esp8266/uart.cpp b/cores/esp8266/uart.cpp index 4b7c189dd..de574d0be 100644 --- a/cores/esp8266/uart.cpp +++ b/cores/esp8266/uart.cpp @@ -830,18 +830,11 @@ uart_set_tx(uart_t* uart, int tx_pin) { return true; } - else if (tx_pin == 2) + else if (tx_pin == 1 || tx_pin == 2) { pinMode(uart->tx_pin, INPUT); uart->tx_pin = tx_pin; - pinMode(uart->tx_pin, FUNCTION_4); - return true; - } - else if (tx_pin != 2) - { - pinMode(uart->tx_pin, INPUT); - uart->tx_pin = 1; - pinMode(uart->tx_pin, SPECIAL); + pinMode(uart->tx_pin, tx_pin == 1 ? SPECIAL : FUNCTION_4); return true; } }