Skip to content

Added facility to invert the polarity of input UART bits. #4200

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
Oct 1, 2020
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
5 changes: 5 additions & 0 deletions cores/esp32/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,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 @@ -265,6 +265,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