Skip to content

Allow UART constructors in both PinName and pin number #240

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
Jun 14, 2021
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
15 changes: 15 additions & 0 deletions cores/arduino/Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ struct _mbed_serial {
mbed::UnbufferedSerial* obj;
};

UART::UART(int tx, int rx, int rts, int cts) {
_tx = digitalPinToPinName(tx);
_rx = digitalPinToPinName(rx);
if (rts >= 0) {
_rts = digitalPinToPinName(rts);
} else {
_rts = NC;
}
if (cts >= 0) {
_cts = digitalPinToPinName(cts);
} else {
_cts = NC;
}
}

void UART::begin(unsigned long baudrate, uint16_t config) {

#if defined(SERIAL_CDC)
Expand Down
3 changes: 2 additions & 1 deletion cores/arduino/Serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ namespace arduino {

class UART : public HardwareSerial {
public:
UART(int tx, int rx, int rts, int cts) : _tx((PinName)tx), _rx((PinName)rx), _rts((PinName)rts), _cts((PinName)cts) {}
UART(int tx, int rx, int rts = -1, int cts = -1);
UART(PinName tx, PinName rx, PinName rts = NC, PinName cts = NC) : _tx(tx), _rx(rx), _rts(rts), _cts(cts) {}
UART() {
is_usb = true;
}
Expand Down