mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
Implement invert for HardwareSerial (#6816)
* Simple i/f to turn on inverted logic on UART0. * Refactor invert from HardwareSerial to uart * Final refactoring of invert bits into config bitmap. * Overload instead of default arg for subclassing. * Prevent unwanted effects if setting invert on other than UART0 - only that has these flags defined and documented.
This commit is contained in:
parent
b478429fe4
commit
007e495e0d
@ -36,10 +36,10 @@ HardwareSerial::HardwareSerial(int uart_nr)
|
||||
: _uart_nr(uart_nr), _rx_size(256)
|
||||
{}
|
||||
|
||||
void HardwareSerial::begin(unsigned long baud, SerialConfig config, SerialMode mode, uint8_t tx_pin)
|
||||
void HardwareSerial::begin(unsigned long baud, SerialConfig config, SerialMode mode, uint8_t tx_pin, bool invert)
|
||||
{
|
||||
end();
|
||||
_uart = uart_init(_uart_nr, baud, (int) config, (int) mode, tx_pin, _rx_size);
|
||||
_uart = uart_init(_uart_nr, baud, (int) config, (int) mode, tx_pin, _rx_size, invert);
|
||||
#if defined(DEBUG_ESP_PORT) && !defined(NDEBUG)
|
||||
if (static_cast<void*>(this) == static_cast<void*>(&DEBUG_ESP_PORT))
|
||||
{
|
||||
|
@ -73,18 +73,23 @@ public:
|
||||
|
||||
void begin(unsigned long baud)
|
||||
{
|
||||
begin(baud, SERIAL_8N1, SERIAL_FULL, 1);
|
||||
begin(baud, SERIAL_8N1, SERIAL_FULL, 1, false);
|
||||
}
|
||||
void begin(unsigned long baud, SerialConfig config)
|
||||
{
|
||||
begin(baud, config, SERIAL_FULL, 1);
|
||||
begin(baud, config, SERIAL_FULL, 1, false);
|
||||
}
|
||||
void begin(unsigned long baud, SerialConfig config, SerialMode mode)
|
||||
{
|
||||
begin(baud, config, mode, 1);
|
||||
begin(baud, config, mode, 1, false);
|
||||
}
|
||||
|
||||
void begin(unsigned long baud, SerialConfig config, SerialMode mode, uint8_t tx_pin);
|
||||
void begin(unsigned long baud, SerialConfig config, SerialMode mode, uint8_t tx_pin)
|
||||
{
|
||||
begin(baud, config, mode, tx_pin, false);
|
||||
}
|
||||
|
||||
void begin(unsigned long baud, SerialConfig config, SerialMode mode, uint8_t tx_pin, bool invert);
|
||||
|
||||
void end();
|
||||
|
||||
|
@ -577,7 +577,7 @@ uart_get_baudrate(uart_t* uart)
|
||||
}
|
||||
|
||||
uart_t*
|
||||
uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx_size)
|
||||
uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx_size, bool invert)
|
||||
{
|
||||
uart_t* uart = (uart_t*) malloc(sizeof(uart_t));
|
||||
if(uart == NULL)
|
||||
@ -657,6 +657,10 @@ uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx
|
||||
}
|
||||
|
||||
uart_set_baudrate(uart, baudrate);
|
||||
if(uart->uart_nr == UART0 && invert)
|
||||
{
|
||||
config |= BIT(UCDTRI) | BIT(UCRTSI) | BIT(UCTXI) | BIT(UCDSRI) | BIT(UCCTSI) | BIT(UCRXI);
|
||||
}
|
||||
USC0(uart->uart_nr) = config;
|
||||
|
||||
if(!gdbstub_has_uart_isr_control() || uart->uart_nr != UART0) {
|
||||
|
@ -113,7 +113,7 @@ extern "C" {
|
||||
struct uart_;
|
||||
typedef struct uart_ uart_t;
|
||||
|
||||
uart_t* uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx_size);
|
||||
uart_t* uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx_size, bool invert);
|
||||
void uart_uninit(uart_t* uart);
|
||||
|
||||
void uart_swap(uart_t* uart, int tx_pin);
|
||||
|
@ -323,10 +323,11 @@ uart_get_bit_length(const int uart_nr)
|
||||
}
|
||||
|
||||
uart_t*
|
||||
uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx_size)
|
||||
uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx_size, bool invert)
|
||||
{
|
||||
(void) config;
|
||||
(void) tx_pin;
|
||||
(void) invert;
|
||||
uart_t* uart = (uart_t*) malloc(sizeof(uart_t));
|
||||
if(uart == NULL)
|
||||
return NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user