From 4699e5683250e550b3f6e16228b9261e35dc0738 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 23 Sep 2025 21:28:14 -0500 Subject: [PATCH] wip --- esphome/components/usb_uart/usb_uart.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/esphome/components/usb_uart/usb_uart.h b/esphome/components/usb_uart/usb_uart.h index c1affe2bc9..91a4329f22 100644 --- a/esphome/components/usb_uart/usb_uart.h +++ b/esphome/components/usb_uart/usb_uart.h @@ -115,17 +115,12 @@ class USBUartChannel : public uart::UARTComponent, public Parenteddata_chunk_pool_[i] = new UsbDataChunk(); this->free_chunks_.push(this->data_chunk_pool_[i]); } } - ~USBUartComponent() { - for (int i = 0; i < MAX_DATA_CHUNKS; i++) { - delete this->data_chunk_pool_[i]; - } - } void setup() override; void loop() override; void dump_config() override; @@ -137,14 +132,17 @@ class USBUartComponent : public usb_host::USBClient { void start_output(USBUartChannel *channel); // Lock-free data transfer from USB task to main loop - LockFreeQueue usb_data_queue_; + static constexpr int USB_DATA_QUEUE_SIZE = 32; + LockFreeQueue usb_data_queue_; protected: std::vector channels_{}; // Pool of pre-allocated data chunks to avoid dynamic allocation - static constexpr int MAX_DATA_CHUNKS = 32; + static constexpr int MAX_DATA_CHUNKS = 40; UsbDataChunk *data_chunk_pool_[MAX_DATA_CHUNKS]; + // IMPORTANT: This is used bidirectionally (USB task pops, main loop pushes) + // which technically violates SPSC, but works in practice because operations are atomic LockFreeQueue free_chunks_; };