Skip to content

Commit 8fcc914

Browse files
Added facility to invert the polarity of input UART bits. (#4200)
1 parent d03f8f1 commit 8fcc914

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

Diff for: cores/esp32/HardwareSerial.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,8 @@ HardwareSerial::operator bool() const
184184
{
185185
return true;
186186
}
187+
188+
void HardwareSerial::setRxInvert(bool invert)
189+
{
190+
uartSetRxInvert(_uart, invert);
191+
}

Diff for: cores/esp32/HardwareSerial.h

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ class HardwareSerial: public Stream
100100

101101
size_t setRxBufferSize(size_t);
102102
void setDebugOutput(bool);
103+
104+
void setRxInvert(bool);
103105

104106
protected:
105107
int _uart_nr;

Diff for: cores/esp32/esp32-hal-uart.c

+11
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,17 @@ size_t uartResizeRxBuffer(uart_t * uart, size_t new_size) {
266266
return new_size;
267267
}
268268

269+
void uartSetRxInvert(uart_t* uart, bool invert)
270+
{
271+
if (uart == NULL)
272+
return;
273+
274+
if (invert)
275+
uart->dev->conf0.rxd_inv = 1;
276+
else
277+
uart->dev->conf0.rxd_inv = 0;
278+
}
279+
269280
uint32_t uartAvailable(uart_t* uart)
270281
{
271282
if(uart == NULL || uart->queue == NULL) {

Diff for: cores/esp32/esp32-hal-uart.h

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ uint32_t uartGetBaudRate(uart_t* uart);
7070

7171
size_t uartResizeRxBuffer(uart_t* uart, size_t new_size);
7272

73+
void uartSetRxInvert(uart_t* uart, bool invert);
74+
7375
void uartSetDebug(uart_t* uart);
7476
int uartGetDebug();
7577

0 commit comments

Comments
 (0)