Skip to content

Commit 3c754c2

Browse files
committed
Refactor invert from HardwareSerial to uart
1 parent efa35a8 commit 3c754c2

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

cores/esp8266/HardwareSerial.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ HardwareSerial::HardwareSerial(int uart_nr)
3939
void HardwareSerial::begin(unsigned long baud, SerialConfig config, SerialMode mode, uint8_t tx_pin, bool invert)
4040
{
4141
end();
42-
_uart = uart_init(_uart_nr, baud, (int) config, (int) mode, tx_pin, _rx_size);
43-
if (0 == _uart_nr && invert)
44-
{
45-
U0C0 |= BIT(UCDTRI) | BIT(UCRTSI) | BIT(UCTXI) | BIT(UCDSRI) | BIT(UCCTSI) | BIT(UCRXI);
46-
}
42+
_uart = uart_init(_uart_nr, baud, (int) config, (int) mode, tx_pin, _rx_size, invert);
4743
#if defined(DEBUG_ESP_PORT) && !defined(NDEBUG)
4844
if (static_cast<void*>(this) == static_cast<void*>(&DEBUG_ESP_PORT))
4945
{

cores/esp8266/uart.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ uart_get_baudrate(uart_t* uart)
577577
}
578578

579579
uart_t*
580-
uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx_size)
580+
uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx_size, bool invert)
581581
{
582582
uart_t* uart = (uart_t*) malloc(sizeof(uart_t));
583583
if(uart == NULL)
@@ -669,6 +669,10 @@ uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx
669669
if(uart->rx_enabled) {
670670
uart_start_isr(uart);
671671
}
672+
if(invert)
673+
{
674+
U0C0 |= BIT(UCDTRI) | BIT(UCRTSI) | BIT(UCTXI) | BIT(UCDSRI) | BIT(UCCTSI) | BIT(UCRXI);
675+
}
672676
if(gdbstub_has_uart_isr_control()) {
673677
ETS_UART_INTR_ENABLE(); // Undo the disable in the switch() above
674678
}

cores/esp8266/uart.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ extern "C" {
113113
struct uart_;
114114
typedef struct uart_ uart_t;
115115

116-
uart_t* uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx_size);
116+
uart_t* uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx_size, bool invert);
117117
void uart_uninit(uart_t* uart);
118118

119119
void uart_swap(uart_t* uart, int tx_pin);

tests/host/common/MockUART.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,11 @@ uart_get_bit_length(const int uart_nr)
323323
}
324324

325325
uart_t*
326-
uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx_size)
326+
uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx_size, bool invert)
327327
{
328328
(void) config;
329329
(void) tx_pin;
330+
(void) invert;
330331
uart_t* uart = (uart_t*) malloc(sizeof(uart_t));
331332
if(uart == NULL)
332333
return NULL;

0 commit comments

Comments
 (0)