13#if LT_ARD_HAS_SOFTSERIAL
14#include <SoftwareSerial.h>
20static const char *
const TAG =
"uart.lt";
22static const char *UART_TYPE[] = {
32 config |= SERIAL_PARITY_NONE;
35 config |= SERIAL_PARITY_EVEN;
38 config |= SERIAL_PARITY_ODD;
43 config |= 0x10 + (this->
stop_bits_ - 1) * 0x20;
49 ESP_LOGCONFIG(TAG,
"Setting up UART...");
59 else if ((tx_pin == -1 || tx_pin == PIN_SERIAL0_TX) && (rx_pin == -1 || rx_pin == PIN_SERIAL0_RX)) {
65 else if ((tx_pin == -1 || tx_pin == PIN_SERIAL1_TX) && (rx_pin == -1 || rx_pin == PIN_SERIAL1_RX)) {
71 else if ((tx_pin == -1 || tx_pin == PIN_SERIAL2_TX) && (rx_pin == -1 || rx_pin == PIN_SERIAL2_RX)) {
77#if LT_ARD_HAS_SOFTSERIAL
78 this->
serial_ =
new SoftwareSerial(rx_pin, tx_pin, rx_inverted || tx_inverted);
81 ESP_LOGE(TAG,
" SoftwareSerial is not implemented for this chip. Only hardware pins are supported:");
83 ESP_LOGE(TAG,
" TX=%u, RX=%u", PIN_SERIAL0_TX, PIN_SERIAL0_RX);
86 ESP_LOGE(TAG,
" TX=%u, RX=%u", PIN_SERIAL1_TX, PIN_SERIAL1_RX);
89 ESP_LOGE(TAG,
" TX=%u, RX=%u", PIN_SERIAL2_TX, PIN_SERIAL2_RX);
101 ESP_LOGCONFIG(TAG,
"UART Bus:");
102 ESP_LOGCONFIG(TAG,
" Type: %s", UART_TYPE[is_software]);
108 if (this->
rx_pin_ !=
nullptr) {
111 ESP_LOGCONFIG(TAG,
" Baud Rate: %u baud", this->
baud_rate_);
112 ESP_LOGCONFIG(TAG,
" Data Bits: %u", this->
data_bits_);
114 ESP_LOGCONFIG(TAG,
" Stop bits: %u", this->
stop_bits_);
120#ifdef USE_UART_DEBUGGER
121 for (
size_t i = 0; i <
len; i++) {
138#ifdef USE_UART_DEBUGGER
139 for (
size_t i = 0; i <
len; i++) {
148 ESP_LOGVV(TAG,
" Flushing...");
159 ESP_LOGW(TAG,
" You're using the same serial port for logging and the UART component. Please "
160 "disable logging over the serial port by setting logger->baud_rate to 0.");
virtual void mark_failed()
Mark this component as failed.
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
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
Providing packet encoding functions for exchanging data with a remote host.