13#if LT_ARD_HAS_SOFTSERIAL
14#include <SoftwareSerial.h>
19static const char *
const TAG =
"uart.lt";
21static const char *
const UART_TYPE[] = {
31 config |= SERIAL_PARITY_NONE;
34 config |= SERIAL_PARITY_EVEN;
37 config |= SERIAL_PARITY_ODD;
42 config |= 0x10 + (this->
stop_bits_ - 1) * 0x20;
51 auto should_fallback_to_software_serial = [&]() ->
bool {
59#if LT_ARD_HAS_SOFTSERIAL
60 ESP_LOGI(TAG,
"Pins have flags set. Using Software Serial");
63 ESP_LOGW(TAG,
"Pin flags are set but not supported for hardware serial. Ignoring");
73 else if ((tx_pin == -1 || tx_pin == PIN_SERIAL0_TX) && (rx_pin == -1 || rx_pin == PIN_SERIAL0_RX) &&
74 !should_fallback_to_software_serial()) {
80 else if ((tx_pin == -1 || tx_pin == PIN_SERIAL1_TX) && (rx_pin == -1 || rx_pin == PIN_SERIAL1_RX) &&
81 !should_fallback_to_software_serial()) {
87 else if ((tx_pin == -1 || tx_pin == PIN_SERIAL2_TX) && (rx_pin == -1 || rx_pin == PIN_SERIAL2_RX) &&
88 !should_fallback_to_software_serial()) {
94#if LT_ARD_HAS_SOFTSERIAL
103 this->
serial_ =
new SoftwareSerial(rx_pin, tx_pin, rx_inverted || tx_inverted);
106 ESP_LOGE(TAG,
" SoftwareSerial is not implemented for this chip. Only hardware pins are supported:");
108 ESP_LOGE(TAG,
" TX=%u, RX=%u", PIN_SERIAL0_TX, PIN_SERIAL0_RX);
111 ESP_LOGE(TAG,
" TX=%u, RX=%u", PIN_SERIAL1_TX, PIN_SERIAL1_RX);
114 ESP_LOGE(TAG,
" TX=%u, RX=%u", PIN_SERIAL2_TX, PIN_SERIAL2_RX);
116 this->
mark_failed(LOG_STR(
"SoftwareSerial is not implemented for this chip."));
129 UART_TYPE[is_software]);
135 if (this->
rx_pin_ !=
nullptr) {
139 " Baud Rate: %" PRIu32
" baud\n"
149#ifdef USE_UART_DEBUGGER
150 for (
size_t i = 0; i <
len; i++) {
167#ifdef USE_UART_DEBUGGER
168 for (
size_t i = 0; i <
len; i++) {
177 ESP_LOGVV(TAG,
" Flushing");
189 ESP_LOGW(TAG,
" You're using the same serial port for logging and the UART component. Please "
190 "disable logging over the serial port by setting logger->baud_rate to 0.");
void mark_failed()
Mark this component as failed.
virtual gpio::Flags get_flags() const =0
Retrieve GPIO pin flags.
virtual uint8_t get_pin() const =0
virtual bool is_inverted() const =0
void dump_config() override
bool read_array(uint8_t *data, size_t len) override
bool peek_byte(uint8_t *data) override
UARTFlushResult flush() override
void check_logger_conflict() override
size_t available() override
void write_array(const uint8_t *data, size_t len) override
HardwareSerial * get_hw_serial()
UARTParityOptions parity_
bool check_read_timeout_(size_t len=1)
InternalGPIOPin * tx_pin_
uint32_t get_baud_rate() const
CallbackManager< void(UARTDirection, uint8_t)> debug_callback_
InternalGPIOPin * rx_pin_
const LogString * parity_to_str(UARTParityOptions parity)
@ UART_CONFIG_PARITY_EVEN
@ UART_CONFIG_PARITY_NONE
UARTFlushResult
Result of a flush() call.
@ UART_FLUSH_RESULT_ASSUMED_SUCCESS
Platform cannot report result; success is assumed.