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

This commit is contained in:
brian-r-calder 2020-10-01 06:58:48 -04:00 committed by GitHub
parent d03f8f1277
commit 8fcc914853
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 0 deletions

View File

@ -184,3 +184,8 @@ HardwareSerial::operator bool() const
{ {
return true; return true;
} }
void HardwareSerial::setRxInvert(bool invert)
{
uartSetRxInvert(_uart, invert);
}

View File

@ -100,6 +100,8 @@ public:
size_t setRxBufferSize(size_t); size_t setRxBufferSize(size_t);
void setDebugOutput(bool); void setDebugOutput(bool);
void setRxInvert(bool);
protected: protected:
int _uart_nr; int _uart_nr;

View File

@ -266,6 +266,17 @@ size_t uartResizeRxBuffer(uart_t * uart, size_t new_size) {
return 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) uint32_t uartAvailable(uart_t* uart)
{ {
if(uart == NULL || uart->queue == NULL) { if(uart == NULL || uart->queue == NULL) {

View File

@ -70,6 +70,8 @@ uint32_t uartGetBaudRate(uart_t* uart);
size_t uartResizeRxBuffer(uart_t* uart, size_t new_size); size_t uartResizeRxBuffer(uart_t* uart, size_t new_size);
void uartSetRxInvert(uart_t* uart, bool invert);
void uartSetDebug(uart_t* uart); void uartSetDebug(uart_t* uart);
int uartGetDebug(); int uartGetDebug();