15static const char *
const TAG =
"uart.arduino_esp8266";
16bool ESP8266UartComponent::serial0_in_use =
false;
22 config |= UART_PARITY_NONE;
24 config |= UART_PARITY_EVEN;
26 config |= UART_PARITY_ODD;
31 config |= UART_NB_BIT_5;
34 config |= UART_NB_BIT_6;
37 config |= UART_NB_BIT_7;
40 config |= UART_NB_BIT_8;
45 config |= UART_NB_STOP_BIT_1;
47 config |= UART_NB_STOP_BIT_2;
59 ESP_LOGCONFIG(TAG,
"Setting up UART bus...");
63 SerialConfig config =
static_cast<SerialConfig
>(
get_config());
76 ESP8266UartComponent::serial0_in_use =
true;
77 }
else if (!ESP8266UartComponent::serial0_in_use && (
tx_pin_ ==
nullptr ||
tx_pin_->
get_pin() == 15) &&
89 ESP8266UartComponent::serial0_in_use =
true;
102 ESP_LOGCONFIG(TAG,
"Loading UART bus settings...");
104 SerialConfig config =
static_cast<SerialConfig
>(
get_config());
112 ESP_LOGCONFIG(TAG,
"UART bus was reloaded.");
118 ESP_LOGCONFIG(TAG,
"UART Bus:");
119 LOG_PIN(
" TX Pin: ", this->
tx_pin_);
120 LOG_PIN(
" RX Pin: ", this->
rx_pin_);
121 if (this->
rx_pin_ !=
nullptr) {
124 ESP_LOGCONFIG(TAG,
" Baud Rate: %u baud", this->
baud_rate_);
125 ESP_LOGCONFIG(TAG,
" Data Bits: %u", this->
data_bits_);
127 ESP_LOGCONFIG(TAG,
" Stop bits: %u", this->
stop_bits_);
129 ESP_LOGCONFIG(TAG,
" Using hardware serial interface.");
131 ESP_LOGCONFIG(TAG,
" Using software serial");
143 ESP_LOGW(TAG,
" You're using the same serial port for logging and the UART component. Please "
144 "disable logging over the serial port by setting logger->baud_rate to 0.");
153 for (
size_t i = 0; i <
len; i++)
156#ifdef USE_UART_DEBUGGER
157 for (
size_t i = 0; i <
len; i++) {
178 for (
size_t i = 0; i <
len; i++)
181#ifdef USE_UART_DEBUGGER
182 for (
size_t i = 0; i <
len; i++) {
196 ESP_LOGVV(TAG,
" Flushing...");
205 size_t rx_buffer_size) {
211 if (tx_pin !=
nullptr) {
217 if (rx_pin !=
nullptr) {
231 rec |= arg->
read_bit_(&wait, start) << i;
239 arg->
wait_(&wait, start);
241 arg->
wait_(&wait, start);
250 ESP_LOGE(TAG,
"UART doesn't have TX pins set!");
253 bool parity_bit =
false;
254 bool need_parity_bit =
true;
260 need_parity_bit =
false;
270 bool bit = data & (1 << i);
280 this->
wait_(&wait, start);
289 this->
wait_(wait, start);
294 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_
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_
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
Providing packet encoding functions for exchanging data with a remote host.
uint32_t arch_get_cpu_cycle_count()