Skip to content

Commit

Permalink
[release/2.x] fix(uart): Set back Pin signal polarity (#9952)
Browse files Browse the repository at this point in the history
* fix(uart): Set back Pin signal polarity

Fixes a problem related to inverting signal polarity back to normal after a previous inversion.

This shall set the correct polarity in Serial.begin().

* fix(uart): Remove commentary

Removes a commentary with a question about the inversing polarity function.

* fix(uart): Update comment

Co-authored-by: Jan Procházka <[email protected]>

---------

Co-authored-by: Me No Dev <[email protected]>
Co-authored-by: Jan Procházka <[email protected]>
  • Loading branch information
3 people authored Jul 1, 2024
1 parent b25c1b2 commit 33c9552
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cores/esp32/esp32-hal-uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,16 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx

if (retCode) retCode &= ESP_OK == uart_param_config(uart_nr, &uart_config);

// Is it right or the idea is to swap rx and tx pins?
if (retCode && inverted) {
if (retCode) {
if (inverted) {
// invert signal for both Rx and Tx
retCode &= ESP_OK == uart_set_line_inverse(uart_nr, UART_SIGNAL_TXD_INV | UART_SIGNAL_RXD_INV);
retCode &= ESP_OK == uart_set_line_inverse(uart_nr, UART_SIGNAL_TXD_INV | UART_SIGNAL_RXD_INV);
} else {
// disable invert signal for both Rx and Tx
retCode &= ESP_OK == uart_set_line_inverse(uart_nr, UART_SIGNAL_INV_DISABLE);
}
}

// if all fine, set internal parameters
if (retCode) {
uart->_baudrate = baudrate;
uart->_config = config;
Expand Down

0 comments on commit 33c9552

Please sign in to comment.