ESPHome  2024.12.2
uart_component_esp8266.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifdef USE_ESP8266
4 
5 #include <HardwareSerial.h>
6 #include <vector>
8 #include "esphome/core/hal.h"
9 #include "esphome/core/log.h"
10 #include "uart_component.h"
11 
12 namespace esphome {
13 namespace uart {
14 
16  public:
17  void setup(InternalGPIOPin *tx_pin, InternalGPIOPin *rx_pin, uint32_t baud_rate, uint8_t stop_bits,
18  uint32_t data_bits, UARTParityOptions parity, size_t rx_buffer_size);
19 
20  uint8_t read_byte();
21  uint8_t peek_byte();
22 
23  void flush();
24 
25  void write_byte(uint8_t data);
26 
27  int available();
28 
29  protected:
30  static void gpio_intr(ESP8266SoftwareSerial *arg);
31 
32  void wait_(uint32_t *wait, const uint32_t &start);
33  bool read_bit_(uint32_t *wait, const uint32_t &start);
34  void write_bit_(bool bit, uint32_t *wait, const uint32_t &start);
35 
36  uint32_t bit_time_{0};
37  uint8_t *rx_buffer_{nullptr};
39  volatile size_t rx_in_pos_{0};
40  size_t rx_out_pos_{0};
41  uint8_t stop_bits_;
42  uint8_t data_bits_;
48 };
49 
51  public:
52  void setup() override;
53  void dump_config() override;
54  float get_setup_priority() const override { return setup_priority::BUS; }
55 
56  void write_array(const uint8_t *data, size_t len) override;
57 
58  bool peek_byte(uint8_t *data) override;
59  bool read_array(uint8_t *data, size_t len) override;
60 
61  int available() override;
62  void flush() override;
63 
64  uint32_t get_config();
65 
78  void load_settings(bool dump_config) override;
79  void load_settings() override { this->load_settings(true); }
80 
81  protected:
82  void check_logger_conflict() override;
83 
84  HardwareSerial *hw_serial_{nullptr};
85  ESP8266SoftwareSerial *sw_serial_{nullptr};
86 
87  private:
88  static bool serial0_in_use; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
89 };
90 
91 } // namespace uart
92 } // namespace esphome
93 
94 #endif // USE_ESP8266
void write_bit_(bool bit, 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)
Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
Definition: gpio.h:66
bool read_bit_(uint32_t *wait, const uint32_t &start)
const float BUS
For communication buses like i2c/spi.
Definition: component.cpp:16
static void gpio_intr(ESP8266SoftwareSerial *arg)
std::string size_t len
Definition: helpers.h:293
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void wait_(uint32_t *wait, const uint32_t &start)