@@ -107,6 +107,12 @@ bool SoftwareSerial::hasRxGPIOPullUp(int8_t pin) {
107107#endif
108108}
109109
110+ void SoftwareSerial::setRxGPIOPullUp () {
111+ if (m_rxValid) {
112+ pinMode (m_rxPin, hasRxGPIOPullUp (m_rxPin) && m_rxGPIOPullupEnabled ? INPUT_PULLUP : INPUT);
113+ }
114+ }
115+
110116void SoftwareSerial::begin (uint32_t baud, SoftwareSerialConfig config,
111117 int8_t rxPin, int8_t txPin,
112118 bool invert, int bufCapacity, int isrBufCapacity) {
@@ -120,6 +126,7 @@ void SoftwareSerial::begin(uint32_t baud, SoftwareSerialConfig config,
120126 m_pduBits = m_dataBits + static_cast <bool >(m_parityMode) + m_stopBits;
121127 m_bitCycles = (ESP.getCpuFreqMHz () * 1000000UL + baud / 2 ) / baud;
122128 m_intTxEnabled = true ;
129+ m_rxGPIOPullupEnabled = true ;
123130 if (isValidRxGPIOpin (m_rxPin)) {
124131 m_buffer.reset (new circular_queue<uint8_t >((bufCapacity > 0 ) ? bufCapacity : 64 ));
125132 if (m_parityMode)
@@ -131,7 +138,7 @@ void SoftwareSerial::begin(uint32_t baud, SoftwareSerialConfig config,
131138 isrBufCapacity : m_buffer->capacity () * (2 + m_dataBits + static_cast <bool >(m_parityMode))));
132139 if (m_buffer && (!m_parityMode || m_parityBuffer) && m_isrBuffer) {
133140 m_rxValid = true ;
134- pinMode (m_rxPin, hasRxGPIOPullUp (m_rxPin) ? INPUT_PULLUP : INPUT );
141+ setRxGPIOPullUp ( );
135142 }
136143 }
137144 if (isValidTxGPIOpin (m_txPin)) {
@@ -177,6 +184,11 @@ void SoftwareSerial::enableIntTx(bool on) {
177184 m_intTxEnabled = on;
178185}
179186
187+ void SoftwareSerial::enableRxGPIOPullup (bool on) {
188+ m_rxGPIOPullupEnabled = on;
189+ setRxGPIOPullUp ();
190+ }
191+
180192void SoftwareSerial::enableTx (bool on) {
181193 if (m_txValid && m_oneWire) {
182194 if (on) {
@@ -185,7 +197,7 @@ void SoftwareSerial::enableTx(bool on) {
185197 digitalWrite (m_txPin, !m_invert);
186198 }
187199 else {
188- pinMode (m_rxPin, hasRxGPIOPullUp (m_rxPin) ? INPUT_PULLUP : INPUT );
200+ setRxGPIOPullUp ( );
189201 enableRx (true );
190202 }
191203 }
0 commit comments