13 #if LT_ARD_HAS_SOFTSERIAL 14 #include <SoftwareSerial.h> 20 static const char *
const TAG =
"uart.lt";
22 static 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_);
119 this->
serial_->write(data, len);
120 #ifdef USE_UART_DEBUGGER 121 for (
size_t i = 0; i <
len; i++) {
137 this->
serial_->readBytes(data, len);
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.");
168 #endif // USE_LIBRETINY
uint32_t get_baud_rate() const
InternalGPIOPin * tx_pin_
UARTParityOptions parity_
bool peek_byte(uint8_t *data) override
void write_array(const uint8_t *data, size_t len) override
void dump_config() override
virtual uint8_t get_pin() const =0
InternalGPIOPin * rx_pin_
bool read_array(uint8_t *data, size_t len) override
HardwareSerial * get_hw_serial()
virtual void mark_failed()
Mark this component as failed.
void check_logger_conflict() override
Implementation of SPI Controller mode.
bool check_read_timeout_(size_t len=1)
CallbackManager< void(UARTDirection, uint8_t)> debug_callback_
const LogString * parity_to_str(UARTParityOptions parity)
virtual bool is_inverted() const =0