Skip to content

[HardwareSerial] Fix ambiguous call of overloaded function #893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cores/arduino/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion cores/arduino/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down