Skip to content

Commit 8832412

Browse files
authored
Allows setting only one pin (rx or tx) in the first begin() (espressif#6394)
1 parent 9b00d4a commit 8832412

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

cores/esp32/HardwareSerial.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,25 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
261261
if (!uartIsDriverInstalled(_uart)) {
262262
switch (_uart_nr) {
263263
case UART_NUM_0:
264-
rxPin = rxPin < 0 ? SOC_RX0 : rxPin;
265-
txPin = txPin < 0 ? SOC_TX0 : txPin;
264+
if (rxPin < 0 && txPin < 0) {
265+
rxPin = SOC_RX0;
266+
txPin = SOC_TX0;
267+
}
266268
break;
267269
#if SOC_UART_NUM > 1 // may save some flash bytes...
268270
case UART_NUM_1:
269-
rxPin = rxPin < 0 ? RX1 : rxPin;
270-
txPin = txPin < 0 ? TX1 : txPin;
271+
if (rxPin < 0 && txPin < 0) {
272+
rxPin = RX1;
273+
txPin = TX1;
274+
}
271275
break;
272276
#endif
273277
#if SOC_UART_NUM > 2 // may save some flash bytes...
274278
case UART_NUM_2:
275-
rxPin = rxPin < 0 ? RX2 : rxPin;
276-
txPin = txPin < 0 ? TX2 : txPin;
279+
if (rxPin < 0 && txPin < 0) {
280+
rxPin = RX2;
281+
txPin = TX2;
282+
}
277283
break;
278284
#endif
279285
default:

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