Skip to content

Commit 474edd3

Browse files
authored
feat(uart): Refactor UART signal inversion handling
1 parent 268f282 commit 474edd3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

cores/esp32/esp32-hal-uart.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,15 +712,17 @@ uart_t *uartBegin(
712712
if (retCode) {
713713
if (inverted) {
714714
// invert signal for both Rx and Tx
715-
retCode &= ESP_OK == uart_set_line_inverse(uart_nr, UART_SIGNAL_TXD_INV | UART_SIGNAL_RXD_INV);
715+
uint32_t _inv_mask = inv_mask;
716+
_inv_mask |= UART_SIGNAL_TXD_INV | UART_SIGNAL_RXD_INV;
717+
retCode &= ESP_OK == uart_set_line_inverse(uart_nr, _inv_mask);
716718
if (retCode) {
717-
inv_mask |= UART_SIGNAL_TXD_INV | UART_SIGNAL_RXD_INV;
719+
inv_mask = _inv_mask;
718720
}
719721
} else {
720722
// disable invert signal for both Rx and Tx
721723
retCode &= ESP_OK == uart_set_line_inverse(uart_nr, UART_SIGNAL_INV_DISABLE);
722724
if (retCode) {
723-
inv_mask &= ~(UART_SIGNAL_TXD_INV | UART_SIGNAL_RXD_INV);
725+
inv_mask = UART_SIGNAL_INV_DISABLE;
724726
}
725727
}
726728
}
@@ -833,7 +835,7 @@ void uartEnd(uint8_t uart_num) {
833835
// Helper generic function that takes a uart_sigenl_inv_t mask to be properly applied to the designated uart pin
834836
// invMask can be UART_SIGNAL_RXD_INV, UART_SIGNAL_TXD_INV, UART_SIGNAL_RTS_INV, UART_SIGNAL_CTS_INV
835837
// returns the operation success status
836-
bool _uartPinSignalInversion(uart_t *uart, uint32_t invMask, bool inverted) {
838+
bool uartPinSignalInversion(uart_t *uart, uint32_t invMask, bool inverted) {
837839
if (uart == NULL) {
838840
return;
839841
}

0 commit comments

Comments
 (0)