13#if LT_ARD_HAS_SOFTSERIAL
14#include <SoftwareSerial.h>
19static const char *
const TAG =
"uart.lt";
21static const char *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;
53 auto shouldFallbackToSoftwareSerial = [&]() ->
bool {
59#if LT_ARD_HAS_SOFTSERIAL
60 ESP_LOGI(TAG,
"Pins has flags set. Using Software Serial");
63 ESP_LOGW(TAG,
"Pin flags are set but not supported for hardware serial. Ignoring");
72 else if ((tx_pin == -1 || tx_pin == PIN_SERIAL0_TX) && (rx_pin == -1 || rx_pin == PIN_SERIAL0_RX) &&
73 !shouldFallbackToSoftwareSerial()) {
79 else if ((tx_pin == -1 || tx_pin == PIN_SERIAL1_TX) && (rx_pin == -1 || rx_pin == PIN_SERIAL1_RX) &&
80 !shouldFallbackToSoftwareSerial()) {
86 else if ((tx_pin == -1 || tx_pin == PIN_SERIAL2_TX) && (rx_pin == -1 || rx_pin == PIN_SERIAL2_RX) &&
87 !shouldFallbackToSoftwareSerial()) {
93#if LT_ARD_HAS_SOFTSERIAL
100 this->
serial_ =
new SoftwareSerial(rx_pin, tx_pin, rx_inverted || tx_inverted);
103 ESP_LOGE(TAG,
" SoftwareSerial is not implemented for this chip. Only hardware pins are supported:");
105 ESP_LOGE(TAG,
" TX=%u, RX=%u", PIN_SERIAL0_TX, PIN_SERIAL0_RX);
108 ESP_LOGE(TAG,
" TX=%u, RX=%u", PIN_SERIAL1_TX, PIN_SERIAL1_RX);
111 ESP_LOGE(TAG,
" TX=%u, RX=%u", PIN_SERIAL2_TX, PIN_SERIAL2_RX);
126 UART_TYPE[is_software]);
132 if (this->
rx_pin_ !=
nullptr) {
136 " Baud Rate: %u baud\n"
146#ifdef USE_UART_DEBUGGER
147 for (
size_t i = 0; i <
len; i++) {
164#ifdef USE_UART_DEBUGGER
165 for (
size_t i = 0; i <
len; i++) {
174 ESP_LOGVV(TAG,
" Flushing");
185 ESP_LOGW(TAG,
" You're using the same serial port for logging and the UART component. Please "
186 "disable logging over the serial port by setting logger->baud_rate to 0.");
virtual 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
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