4#include <zephyr/drivers/uart.h>
17 this->
mark_failed(LOG_STR(
"UART device not ready"));
21 this->
mark_failed(LOG_STR(
"UART configuration not supported"));
28 uart_irq_rx_enable(this->
device_);
33 struct uart_config config{};
37 config.parity = UART_CFG_PARITY_NONE;
40 config.parity = UART_CFG_PARITY_EVEN;
46 config.stop_bits = this->
stop_bits_ == 2 ? UART_CFG_STOP_BITS_2 : UART_CFG_STOP_BITS_1;
47 config.data_bits =
static_cast<uint8_t
>(UART_CFG_DATA_BITS_5 + (this->
data_bits_ - 5));
48 config.flow_ctrl = UART_CFG_FLOW_CTRL_NONE;
49 int err = uart_configure(this->
device_, &config);
51 ESP_LOGE(TAG,
"uart_configure() failed for %" PRIu32
" baud, %u data bits, parity %s, %u stop bits: %d",
62 ESP_LOGCONFIG(TAG,
"UART bus was reloaded.");
69 bool received =
false;
70 while (uart_irq_update(device) > 0 && uart_irq_rx_ready(device) > 0) {
72 uint32_t claimed = ring_buf_put_claim(&self->rx_ring_, &space, self->rx_buffer_size_);
76 int dropped = uart_fifo_read(device, discard,
sizeof(discard));
79 self->rx_overflow_ = self->rx_overflow_ + dropped;
82 int got = uart_fifo_read(device, space, claimed);
83 ring_buf_put_finish(&self->rx_ring_, got > 0 ? got : 0);
93 ESP_LOGCONFIG(TAG,
"UART Bus:");
94 ESP_LOGCONFIG(TAG,
" Device: %s", this->
device_ !=
nullptr ? this->
device_->name :
"none");
95 LOG_PIN(
" TX Pin: ", this->
tx_pin_);
96 LOG_PIN(
" RX Pin: ", this->
rx_pin_);
98 ESP_LOGCONFIG(TAG,
" RX Buffer Size: %u", (
unsigned) this->
rx_buffer_size_);
101 " Baud Rate: %" PRIu32
" baud\n"
113 for (
size_t i = 0; i <
len; i++) {
114 uart_poll_out(this->
device_, data[i]);
119#ifdef USE_UART_DEBUGGER
121 for (
size_t i = 0; i <
len; i++) {
151 ring_buf_get(&this->
rx_ring_, data + offset,
len - offset);
152#ifdef USE_UART_DEBUGGER
153 for (
size_t i = 0; i <
len; i++) {
181 if (elapsed < frame_us)
void feed_wdt()
Feed the task watchdog.
void mark_failed()
Mark this component as failed.
UARTParityOptions parity_
bool check_read_timeout_(size_t len=1)
InternalGPIOPin * tx_pin_
CallbackManager< void(UARTDirection, uint8_t)> debug_callback_
InternalGPIOPin * rx_pin_
void check_logger_conflict() override
const struct device * device_
uint32_t rx_overflow_reported_
void write_array(const uint8_t *data, size_t len) override
void dump_config() override
volatile uint32_t rx_overflow_
void load_settings()
Load the UART settings.
UARTFlushResult flush() override
bool peek_byte(uint8_t *data) override
static void rx_isr(const struct device *device, void *user_data)
uint32_t last_tx_start_us_
bool read_array(uint8_t *data, size_t len) override
size_t available() override
ESPHOME_LOG_TAG(TAG, "uart.binary_sensor")
const LogString * parity_to_str(UARTParityOptions parity)
UARTFlushResult
Result of a flush() call.
@ UART_FLUSH_RESULT_ASSUMED_SUCCESS
Platform cannot report result; success is assumed.
@ UART_FLUSH_RESULT_SUCCESS
Confirmed: all bytes left the TX FIFO.
@ UART_CONFIG_PARITY_EVEN
@ UART_CONFIG_PARITY_NONE
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
uint32_t IRAM_ATTR HOT micros()
Application App
Global storage of Application pointer - only one Application can exist.
void IRAM_ATTR wake_loop_any_context()
IRAM_ATTR entry point for ISR callers — defined in wake_esp8266.cpp.
Platform-specific main loop wake primitives.