15 static const char *
const TAG =
"uart.arduino_esp8266";
16 bool 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,
"UART Bus:");
105 if (this->
rx_pin_ !=
nullptr) {
108 ESP_LOGCONFIG(TAG,
" Baud Rate: %u baud", this->
baud_rate_);
109 ESP_LOGCONFIG(TAG,
" Data Bits: %u", this->
data_bits_);
111 ESP_LOGCONFIG(TAG,
" Stop bits: %u", this->
stop_bits_);
113 ESP_LOGCONFIG(TAG,
" Using hardware serial interface.");
115 ESP_LOGCONFIG(TAG,
" Using software serial");
127 ESP_LOGW(TAG,
" You're using the same serial port for logging and the UART component. Please " 128 "disable logging over the serial port by setting logger->baud_rate to 0.");
137 for (
size_t i = 0; i <
len; i++)
140 #ifdef USE_UART_DEBUGGER 141 for (
size_t i = 0; i <
len; i++) {
162 for (
size_t i = 0; i <
len; i++)
165 #ifdef USE_UART_DEBUGGER 166 for (
size_t i = 0; i <
len; i++) {
180 ESP_LOGVV(TAG,
" Flushing...");
189 size_t rx_buffer_size) {
190 this->bit_time_ = F_CPU / baud_rate;
195 if (tx_pin !=
nullptr) {
196 gpio_tx_pin_ = tx_pin;
197 gpio_tx_pin_->
setup();
201 if (rx_pin !=
nullptr) {
202 gpio_rx_pin_ = rx_pin;
203 gpio_rx_pin_->
setup();
215 rec |= arg->
read_bit_(&wait, start) << i;
223 arg->
wait_(&wait, start);
225 arg->
wait_(&wait, start);
233 if (this->gpio_tx_pin_ ==
nullptr) {
234 ESP_LOGE(TAG,
"UART doesn't have TX pins set!");
237 bool parity_bit =
false;
238 bool need_parity_bit =
true;
244 need_parity_bit =
false;
249 uint32_t wait = this->bit_time_;
252 this->write_bit_(
false, &wait, start);
254 bool bit = data & (1 << i);
255 this->write_bit_(bit, &wait, start);
260 this->write_bit_(parity_bit, &wait, start);
262 this->write_bit_(
true, &wait, start);
264 this->wait_(&wait, start);
270 *wait += this->bit_time_;
273 this->wait_(wait, start);
278 this->wait_(wait, start);
281 if (this->rx_in_pos_ == this->rx_out_pos_)
283 uint8_t data = this->rx_buffer_[this->rx_out_pos_];
288 if (this->rx_in_pos_ == this->rx_out_pos_)
290 return this->rx_buffer_[this->rx_out_pos_];
296 int avail = int(this->rx_in_pos_) - int(this->rx_out_pos_);
304 #endif // USE_ESP8266 virtual void digital_write(bool value)=0
void write_bit_(bool bit, uint32_t *wait, const uint32_t &start)
volatile size_t rx_in_pos_
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)
uint32_t get_baud_rate() const
bool read_array(uint8_t *data, size_t len) override
ESP8266SoftwareSerial * sw_serial_
void check_logger_conflict() override
InternalGPIOPin * tx_pin_
UARTParityOptions parity_
void write_array(const uint8_t *data, size_t len) override
bool read_bit_(uint32_t *wait, const uint32_t &start)
HardwareSerial * hw_serial_
void write_byte(uint8_t data)
bool peek_byte(uint8_t *data) override
UARTParityOptions parity_
void dump_config() override
virtual uint8_t get_pin() const =0
InternalGPIOPin * rx_pin_
UARTSelection get_uart() const
Get the UART used by the logger.
ISRInternalGPIOPin rx_pin_
static void gpio_intr(ESP8266SoftwareSerial *arg)
virtual bool digital_read()=0
virtual ISRInternalGPIOPin to_isr() const =0
Helper class to disable interrupts.
void wait_(uint32_t *wait, const uint32_t &start)
bool check_read_timeout_(size_t len=1)
CallbackManager< void(UARTDirection, uint8_t)> debug_callback_
uint32_t arch_get_cpu_cycle_count()
const LogString * parity_to_str(UARTParityOptions parity)
virtual bool is_inverted() const =0