7#ifdef USE_UART_WAKE_LOOP_ON_RX
17static const char *
const TAG =
"uart.arduino_esp8266";
18bool ESP8266UartComponent::serial0_in_use =
false;
24 config |= UART_PARITY_NONE;
26 config |= UART_PARITY_EVEN;
28 config |= UART_PARITY_ODD;
33 config |= UART_NB_BIT_5;
36 config |= UART_NB_BIT_6;
39 config |= UART_NB_BIT_7;
42 config |= UART_NB_BIT_8;
47 config |= UART_NB_STOP_BIT_1;
49 config |= UART_NB_STOP_BIT_2;
71 setup_pin_if_needed(this->
rx_pin_);
73 setup_pin_if_needed(this->
tx_pin_);
79 SerialConfig config =
static_cast<SerialConfig
>(
get_config());
81#ifdef USE_ESP8266_UART_SERIAL
93 ESP8266UartComponent::serial0_in_use =
true;
94 }
else if (!ESP8266UartComponent::serial0_in_use && (
tx_pin_ ==
nullptr ||
tx_pin_->
get_pin() == 15) &&
106 ESP8266UartComponent::serial0_in_use =
true;
109#ifdef USE_ESP8266_UART_SERIAL1
124 ESP_LOGCONFIG(TAG,
"Loading UART bus settings");
126 SerialConfig config =
static_cast<SerialConfig
>(
get_config());
134 ESP_LOGCONFIG(TAG,
"UART bus was reloaded.");
140 ESP_LOGCONFIG(TAG,
"UART Bus:");
141 LOG_PIN(
" TX Pin: ", this->
tx_pin_);
142 LOG_PIN(
" RX Pin: ", this->
rx_pin_);
143 if (this->
rx_pin_ !=
nullptr) {
147 " Baud Rate: %u baud\n"
153 ESP_LOGCONFIG(TAG,
" Using hardware serial interface.");
155 ESP_LOGCONFIG(TAG,
" Using software serial"
156#ifdef USE_UART_WAKE_LOOP_ON_RX
157 "\n Wake on data RX: ENABLED"
171 ESP_LOGW(TAG,
" You're using the same serial port for logging and the UART component. Please "
172 "disable logging over the serial port by setting logger->baud_rate to 0.");
181 for (
size_t i = 0; i <
len; i++)
184#ifdef USE_UART_DEBUGGER
185 for (
size_t i = 0; i <
len; i++) {
206 for (
size_t i = 0; i <
len; i++)
209#ifdef USE_UART_DEBUGGER
210 for (
size_t i = 0; i <
len; i++) {
224 ESP_LOGVV(TAG,
" Flushing");
234 size_t rx_buffer_size) {
240 if (tx_pin !=
nullptr) {
246 if (rx_pin !=
nullptr) {
260 rec |= arg->
read_bit_(&wait, start) << i;
268 arg->
wait_(&wait, start);
270 arg->
wait_(&wait, start);
276#ifdef USE_UART_WAKE_LOOP_ON_RX
285 ESP_LOGE(TAG,
"UART doesn't have TX pins set!");
288 bool parity_bit =
false;
289 bool need_parity_bit =
true;
295 need_parity_bit =
false;
305 bool bit = data & (1 << i);
315 this->
wait_(&wait, start);
324 this->
wait_(wait, start);
329 this->
wait_(wait, start);
void digital_write(bool value)
virtual uint8_t get_pin() const =0
void attach_interrupt(void(*func)(T *), T *arg, gpio::InterruptType type) const
virtual bool is_inverted() const =0
virtual ISRInternalGPIOPin to_isr() const =0
Helper class to disable interrupts.
Stream * get_hw_serial() const
UARTSelection get_uart() const
Get the UART used by the logger.
UARTParityOptions parity_
volatile size_t rx_in_pos_
ISRInternalGPIOPin rx_pin_
void wait_(uint32_t *wait, const uint32_t &start)
void setup(InternalGPIOPin *tx_pin, InternalGPIOPin *rx_pin, uint32_t baud_rate, uint8_t stop_bits, uint32_t data_bits, UARTParityOptions parity, size_t rx_buffer_size)
void write_bit_(bool bit, uint32_t *wait, const uint32_t &start)
InternalGPIOPin * gpio_tx_pin_
InternalGPIOPin * gpio_rx_pin_
bool read_bit_(uint32_t *wait, const uint32_t &start)
static void gpio_intr(ESP8266SoftwareSerial *arg)
void write_byte(uint8_t data)
ISRInternalGPIOPin tx_pin_
size_t available() override
void check_logger_conflict() override
bool peek_byte(uint8_t *data) override
bool read_array(uint8_t *data, size_t len) override
void dump_config() override
HardwareSerial * hw_serial_
UARTFlushResult flush() override
void write_array(const uint8_t *data, size_t len) override
ESP8266SoftwareSerial * sw_serial_
void load_settings() override
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_
@ UART_SELECTION_UART0_SWAP
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.
uint32_t arch_get_cpu_cycle_count()
void ESPHOME_ALWAYS_INLINE wake_loop_isrsafe()
ISR-safe: no task_woken arg because ESP8266 has no FreeRTOS. Caller must be IRAM_ATTR.
Platform-specific main loop wake primitives.