Skip to content
This repository has been archived by the owner on Apr 16, 2021. It is now read-only.

Commit

Permalink
Allow Serial with flow control
Browse files Browse the repository at this point in the history
  • Loading branch information
facchinm committed Oct 7, 2019
1 parent a89067f commit 87a622f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
27 changes: 24 additions & 3 deletions cores/arduino/Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ void UART::begin(unsigned long baudrate) {
if (_serial == NULL) {
_serial = new mbed::RawSerial(tx, rx, baudrate);
}
if (rts != NC) {
_serial->set_flow_control(mbed::SerialBase::Flow::RTSCTS, rts, cts);
}
_serial->attach(mbed::callback(this, &UART::on_rx), mbed::SerialBase::RxIrq);
}

Expand Down Expand Up @@ -84,11 +87,29 @@ UART::operator bool() {
}

#if SERIAL_HOWMANY > 0
UART UART1(SERIAL1_TX, SERIAL1_RX);

#ifdef SERIAL1_RTS
UART UART1(SERIAL1_TX, SERIAL1_RX, SERIAL1_RTS, SERIAL1_CTS);
#else
UART UART1(SERIAL1_TX, SERIAL1_RX, NC, NC);
#endif

#if SERIAL_HOWMANY > 1
UART UART2(SERIAL2_TX, SERIAL2_RX);

#ifdef SERIAL2_RTS
UART UART2(SERIAL2_TX, SERIAL2_RX, SERIAL2_RTS, SERIAL2_CTS);
#else
UART UART2(SERIAL2_TX, SERIAL2_RX, NC, NC);
#endif

#if SERIAL_HOWMANY > 2
UART UART3(SERIAL3_TX, SERIAL3_RX);

#ifdef SERIAL3_RTS
UART UART1(SERIAL3_TX, SERIAL3_RX, SERIAL3_RTS, SERIAL3_CTS);
#else
UART UART1(SERIAL3_TX, SERIAL3_RX, NC, NC);
#endif

#endif
#endif
#endif
4 changes: 2 additions & 2 deletions cores/arduino/Serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace arduino {

class UART : public HardwareSerial {
public:
UART(int _tx, int _rx) : tx((PinName)_tx), rx((PinName)_rx) {};
UART(int _tx, int _rx, int _rts, int _cts) : tx((PinName)_tx), rx((PinName)_rx), rts((PinName)_rts), cts((PinName)_cts) {};
void begin(unsigned long);
void begin(unsigned long baudrate, uint16_t config);
void end();
Expand All @@ -48,7 +48,7 @@ class UART : public HardwareSerial {
private:
void on_rx();
mbed::RawSerial* _serial = NULL;
PinName tx, rx;
PinName tx, rx, rts, cts;
RingBufferN<256> rx_buffer;
uint8_t intermediate_buf[4];
};
Expand Down

0 comments on commit 87a622f

Please sign in to comment.