diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp index 1b1d8fd634..57975975b9 100644 --- a/cores/arduino/HardwareSerial.cpp +++ b/cores/arduino/HardwareSerial.cpp @@ -116,7 +116,7 @@ HardwareSerial::HardwareSerial(PinName _rx, PinName _tx) init(_rx, _tx); } -HardwareSerial::HardwareSerial(void *peripheral, bool halfDuplex) +HardwareSerial::HardwareSerial(void *peripheral, HalfDuplexMode_t halfDuplex) { // If PIN_SERIALy_RX is not defined assume half-duplex _serial.pin_rx = NC; @@ -247,7 +247,7 @@ HardwareSerial::HardwareSerial(void *peripheral, bool halfDuplex) _serial.pin_rx = pinmap_pin(peripheral, PinMap_UART_RX); _serial.pin_tx = pinmap_pin(peripheral, PinMap_UART_TX); } - if (halfDuplex) { + if (halfDuplex == HALF_DUPLEX_ENABLED) { _serial.pin_rx = NC; } init(_serial.pin_rx, _serial.pin_tx); diff --git a/cores/arduino/HardwareSerial.h b/cores/arduino/HardwareSerial.h index a2a5644776..b9325858f5 100644 --- a/cores/arduino/HardwareSerial.h +++ b/cores/arduino/HardwareSerial.h @@ -57,6 +57,15 @@ typedef uint16_t rx_buffer_index_t; typedef uint8_t rx_buffer_index_t; #endif +// A bool should be enough for this +// But it brings an build error due to ambiguous +// call of overloaded HardwareSerial(int, int) +// So defining a dedicated type +typedef enum { + HALF_DUPLEX_DISABLED, + HALF_DUPLEX_ENABLED +} HalfDuplexMode_t; + // Define config for Serial.begin(baud, config); // below configs are not supported by STM32 //#define SERIAL_5N1 0x00 @@ -103,7 +112,7 @@ class HardwareSerial : public Stream { public: HardwareSerial(uint32_t _rx, uint32_t _tx); HardwareSerial(PinName _rx, PinName _tx); - HardwareSerial(void *peripheral, bool halfDuplex = false); + HardwareSerial(void *peripheral, HalfDuplexMode_t halfDuplex = HALF_DUPLEX_DISABLED); HardwareSerial(uint32_t _rxtx); HardwareSerial(PinName _rxtx); void begin(unsigned long baud) diff --git a/keywords.txt b/keywords.txt index 46f16f7a21..019b437912 100644 --- a/keywords.txt +++ b/keywords.txt @@ -270,6 +270,8 @@ PIN_WIRE_SCL LITERAL1 HardwareSerial KEYWORD2 setRx KEYWORD2 setTx KEYWORD2 +HALF_DUPLEX_DISABLED LITERAL1 +HALF_DUPLEX_ENABLED LITERAL1 setHalfDuplex KEYWORD2 isHalfDuplex KEYWORD2 enableHalfDuplexRx KEYWORD2