ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
uart_component_zephyr.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ZEPHYR
4
5#include <zephyr/device.h>
6#include <zephyr/sys/ring_buffer.h>
7
9#include "uart_component.h"
10
11namespace esphome::uart {
12
13class ZephyrUARTComponent final : public UARTComponent, public Component {
14 public:
15 void setup() override;
16 void dump_config() override;
17 float get_setup_priority() const override { return setup_priority::BUS; }
18
19 void write_array(const uint8_t *data, size_t len) override;
20
21 bool peek_byte(uint8_t *data) override;
22 bool read_array(uint8_t *data, size_t len) override;
23
24 size_t available() override;
25 UARTFlushResult flush() override;
26
27 void set_device(const struct device *device) { this->device_ = device; }
28
29 void load_settings(bool dump_config) override;
31
32 protected:
33 void check_logger_conflict() override {}
34 bool configure_();
35 static void rx_isr(const struct device *device, void *user_data);
36
37 const struct device *device_{nullptr};
38 struct ring_buf rx_ring_{};
39 uint8_t *rx_storage_{nullptr};
40 // Bytes dropped because the RX buffer was full; written in the ISR, reported from loop()
43 // When the last byte written started; flush() waits for it to finish
45 uint8_t peek_buffer_{0};
46 bool has_peek_{false};
47 bool tx_pending_{false};
48};
49
50} // namespace esphome::uart
51
52#endif // USE_ZEPHYR
void load_settings()
Load the UART settings.
void set_device(const struct device *device)
void write_array(const uint8_t *data, size_t len) override
void load_settings()
Load the UART settings.
static void rx_isr(const struct device *device, void *user_data)
bool read_array(uint8_t *data, size_t len) override
constexpr float BUS
For communication buses like i2c/spi.
Definition component.h:40
UARTFlushResult
Result of a flush() call.
const void size_t len
Definition hal.h:68
static void uint32_t