mirror of
https://github.com/esphome/esphome.git
synced 2026-05-18 01:32:27 +08:00
[usb_uart] Derive TX output chunk count from buffer_size config (#15909)
This commit is contained in:
committed by
Jesse Hills
parent
2a3bd8bc85
commit
76eb8f697f
@@ -116,12 +116,23 @@ CONFIG_SCHEMA = cv.ensure_list(
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
# The output chunk pool/queue are compile-time-sized templates shared by all
|
||||
# USBUartChannel instances, so use the largest buffer_size across every channel
|
||||
# of every device. Each chunk is 64 bytes (USB FS MPS); add one extra slot
|
||||
# because LockFreeQueue<T,N> is a ring buffer that wastes one entry.
|
||||
max_buffer_size = max(
|
||||
channel[CONF_BUFFER_SIZE]
|
||||
for device in config
|
||||
for channel in device[CONF_CHANNELS]
|
||||
)
|
||||
output_chunk_count = max_buffer_size // 64 + 1
|
||||
cg.add_define("USB_UART_OUTPUT_CHUNK_COUNT", output_chunk_count)
|
||||
|
||||
for device in config:
|
||||
var = await register_usb_client(device)
|
||||
for index, channel in enumerate(device[CONF_CHANNELS]):
|
||||
chvar = cg.new_Pvariable(channel[CONF_ID], index, channel[CONF_BUFFER_SIZE])
|
||||
await cg.register_parented(chvar, var)
|
||||
cg.add(chvar.set_rx_buffer_size(channel[CONF_BUFFER_SIZE]))
|
||||
cg.add(chvar.set_stop_bits(channel[CONF_STOP_BITS]))
|
||||
cg.add(chvar.set_data_bits(channel[CONF_DATA_BITS]))
|
||||
cg.add(chvar.set_parity(channel[CONF_PARITY]))
|
||||
|
||||
@@ -132,8 +132,9 @@ class USBUartChannel : public uart::UARTComponent, public Parented<USBUartCompon
|
||||
friend class USBUartTypeCH34X;
|
||||
|
||||
public:
|
||||
// Number of output chunk slots per channel (8 × 64 bytes = 512 bytes peak, lazily allocated)
|
||||
static constexpr uint8_t USB_OUTPUT_CHUNK_COUNT = 8;
|
||||
// Number of output chunk slots per channel, derived from buffer_size config.
|
||||
// Computed as ceil(buffer_size / 64) + 1 in Python codegen; defaults to 5 (256 / 64 + 1).
|
||||
static constexpr uint8_t USB_OUTPUT_CHUNK_COUNT = USB_UART_OUTPUT_CHUNK_COUNT;
|
||||
|
||||
USBUartChannel(uint8_t index, uint16_t buffer_size) : index_(index), input_buffer_(RingBuffer(buffer_size)) {}
|
||||
void write_array(const uint8_t *data, size_t len) override;
|
||||
|
||||
@@ -284,6 +284,7 @@
|
||||
#define ESPHOME_WIFI_POWER_SAVE_LISTENERS 2
|
||||
#define USE_WIFI_RUNTIME_POWER_SAVE
|
||||
#define USB_HOST_MAX_REQUESTS 16
|
||||
#define USB_UART_OUTPUT_CHUNK_COUNT 5
|
||||
|
||||
#ifdef USE_ARDUINO
|
||||
#define USE_ARDUINO_VERSION_CODE VERSION_CODE(3, 3, 7)
|
||||
|
||||
Reference in New Issue
Block a user