Update the patched UART component to ESPHome 2026.11.0
ESPHome 2026.11's tuya component calls uart.new_uart_component(), which the 2026.10.2 copy didn't have, so the build failed. Copy the UART component from 2026.11.0, reapply the PA13/PA14 patch, regenerate the patch file and point the refs at v1.0.6. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bcc6b3a42b
commit
1457e25d98
39 files changed
+907
-304
No files matched your search
@@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/hal.h"
|
||||
@@ -25,6 +28,7 @@ class UARTDevice {
|
||||
size_t get_rx_timeout() { return this->parent_->get_rx_timeout(); }
|
||||
|
||||
void write_array(const uint8_t *data, size_t len) { this->parent_->write_array(data, len); }
|
||||
void write_array_progmem(const uint8_t *data, size_t len) { this->parent_->write_array_progmem(data, len); }
|
||||
void write_array(const std::vector<uint8_t> &data) { this->parent_->write_array(data); }
|
||||
template<size_t N> void write_array(const std::array<uint8_t, N> &data) {
|
||||
this->parent_->write_array(data.data(), data.size());
|
||||
@@ -47,6 +51,48 @@ class UARTDevice {
|
||||
|
||||
size_t available() { return this->parent_->available(); }
|
||||
|
||||
/// Pass the bytes available now to on_chunk(data, len) in N byte chunks; returning false stops.
|
||||
/// Returns false only on a read error.
|
||||
template<size_t N = 64, typename F> bool read_available_chunks(F &&on_chunk) {
|
||||
return this->read_available_chunks<N>(on_chunk, this->available());
|
||||
}
|
||||
/// Same, reading exactly count bytes; count must not exceed available().
|
||||
template<size_t N = 64, typename F> bool read_available_chunks(F &&on_chunk, size_t count) {
|
||||
static_assert(N > 0, "read buffer size must be non-zero");
|
||||
uint8_t buf[N];
|
||||
while (count > 0) {
|
||||
const size_t len = std::min(count, N);
|
||||
if (!this->read_array(buf, len)) {
|
||||
return false;
|
||||
}
|
||||
count -= len;
|
||||
if (!continue_after(on_chunk, static_cast<const uint8_t *>(buf), len)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Same as read_available_chunks(), calling on_byte(uint8_t) once per byte.
|
||||
template<size_t N = 64, typename F> bool read_available(F &&on_byte) {
|
||||
return this->read_available<N>(on_byte, this->available());
|
||||
}
|
||||
template<size_t N = 64, typename F> bool read_available(F &&on_byte, size_t count) {
|
||||
return this->read_available_chunks<N>(
|
||||
[&on_byte](const uint8_t *data, size_t len) {
|
||||
for (const uint8_t *p = data; p != data + len; p++) {
|
||||
if (!continue_after(on_byte, *p)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
count);
|
||||
}
|
||||
|
||||
/// Read and drop every byte waiting in the receive buffer.
|
||||
void discard_available();
|
||||
|
||||
UARTFlushResult flush() { return this->parent_->flush(); }
|
||||
|
||||
// Compat APIs
|
||||
@@ -73,6 +119,18 @@ class UARTDevice {
|
||||
UARTParityOptions parity = UART_CONFIG_PARITY_NONE, uint8_t data_bits = 8);
|
||||
|
||||
protected:
|
||||
/// Call f(args...) and return its result; a void callback always continues.
|
||||
template<typename F, typename... A> static bool continue_after(F &f, A... args) {
|
||||
using R = std::invoke_result_t<F &, A...>;
|
||||
if constexpr (std::is_void_v<R>) {
|
||||
f(args...);
|
||||
return true;
|
||||
} else {
|
||||
static_assert(std::is_same_v<std::remove_cvref_t<R>, bool>, "callback must return void or bool");
|
||||
return f(args...);
|
||||
}
|
||||
}
|
||||
|
||||
UARTComponent *parent_{nullptr};
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user