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,
"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) {
206 this->bit_time_ = F_CPU / baud_rate;
211 if (tx_pin !=
nullptr) {
212 gpio_tx_pin_ = tx_pin;
213 gpio_tx_pin_->
setup();
217 if (rx_pin !=
nullptr) {
218 gpio_rx_pin_ = rx_pin;
219 gpio_rx_pin_->
setup();
231 rec |= arg->
read_bit_(&wait, start) << i;
239 arg->
wait_(&wait, start);
241 arg->
wait_(&wait, start);
249 if (this->gpio_tx_pin_ ==
nullptr) {
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;
265 uint32_t wait = this->bit_time_;
268 this->write_bit_(
false, &wait, start);
270 bool bit = data & (1 << i);
271 this->write_bit_(bit, &wait, start);
276 this->write_bit_(parity_bit, &wait, start);
278 this->write_bit_(
true, &wait, start);
280 this->wait_(&wait, start);
286 *wait += this->bit_time_;
289 this->wait_(wait, start);
294 this->wait_(wait, start);
297 if (this->rx_in_pos_ == this->rx_out_pos_)
299 uint8_t data = this->rx_buffer_[this->rx_out_pos_];
304 if (this->rx_in_pos_ == this->rx_out_pos_)
306 return this->rx_buffer_[this->rx_out_pos_];
312 int avail = int(this->rx_in_pos_) - int(this->rx_out_pos_);
320 #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 load_settings() override
Implementation of SPI Controller mode.
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