Skip to content

Commit

Permalink
Added facility to invert the polarity of input UART bits. (#4200)
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-r-calder committed Oct 1, 2020
1 parent d03f8f1 commit 8fcc914
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cores/esp32/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,8 @@ HardwareSerial::operator bool() const
{
return true;
}

void HardwareSerial::setRxInvert(bool invert)
{
uartSetRxInvert(_uart, invert);
}
2 changes: 2 additions & 0 deletions cores/esp32/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class HardwareSerial: public Stream

size_t setRxBufferSize(size_t);
void setDebugOutput(bool);

void setRxInvert(bool);

protected:
int _uart_nr;
Expand Down
11 changes: 11 additions & 0 deletions cores/esp32/esp32-hal-uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ size_t uartResizeRxBuffer(uart_t * uart, size_t new_size) {
return new_size;
}

void uartSetRxInvert(uart_t* uart, bool invert)
{
if (uart == NULL)
return;

if (invert)
uart->dev->conf0.rxd_inv = 1;
else
uart->dev->conf0.rxd_inv = 0;
}

uint32_t uartAvailable(uart_t* uart)
{
if(uart == NULL || uart->queue == NULL) {
Expand Down
2 changes: 2 additions & 0 deletions cores/esp32/esp32-hal-uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ uint32_t uartGetBaudRate(uart_t* uart);

size_t uartResizeRxBuffer(uart_t* uart, size_t new_size);

void uartSetRxInvert(uart_t* uart, bool invert);

void uartSetDebug(uart_t* uart);
int uartGetDebug();

Expand Down

0 comments on commit 8fcc914

Please sign in to comment.