From 8fcc91485364b334c51447686bc168e9160d093f Mon Sep 17 00:00:00 2001 From: brian-r-calder Date: Thu, 1 Oct 2020 06:58:48 -0400 Subject: [PATCH] Added facility to invert the polarity of input UART bits. (#4200) --- cores/esp32/HardwareSerial.cpp | 5 +++++ cores/esp32/HardwareSerial.h | 2 ++ cores/esp32/esp32-hal-uart.c | 11 +++++++++++ cores/esp32/esp32-hal-uart.h | 2 ++ 4 files changed, 20 insertions(+) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index a6c36293..b06e0735 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -184,3 +184,8 @@ HardwareSerial::operator bool() const { return true; } + +void HardwareSerial::setRxInvert(bool invert) +{ + uartSetRxInvert(_uart, invert); +} diff --git a/cores/esp32/HardwareSerial.h b/cores/esp32/HardwareSerial.h index f6fab2a9..e776e939 100644 --- a/cores/esp32/HardwareSerial.h +++ b/cores/esp32/HardwareSerial.h @@ -100,6 +100,8 @@ public: size_t setRxBufferSize(size_t); void setDebugOutput(bool); + + void setRxInvert(bool); protected: int _uart_nr; diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index bc4a676b..cad5a1d4 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -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) { diff --git a/cores/esp32/esp32-hal-uart.h b/cores/esp32/esp32-hal-uart.h index ffec2a45..e35f05d4 100644 --- a/cores/esp32/esp32-hal-uart.h +++ b/cores/esp32/esp32-hal-uart.h @@ -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();