mirror of
https://github.com/esphome/esphome.git
synced 2026-09-26 06:20:21 +00:00
[usb_host][usb_uart] Add configurable max packet size (#14584)
This commit is contained in:
@@ -157,7 +157,7 @@ void USBUartChannel::write_array(const uint8_t *data, size_t len) {
|
||||
ESP_LOGE(TAG, "Output pool full - lost %zu bytes", len);
|
||||
break;
|
||||
}
|
||||
size_t chunk_len = std::min(len, UsbOutputChunk::MAX_CHUNK_SIZE);
|
||||
uint16_t chunk_len = std::min(len, UsbOutputChunk::MAX_CHUNK_SIZE);
|
||||
memcpy(chunk->data, data, chunk_len);
|
||||
chunk->length = static_cast<uint8_t>(chunk_len);
|
||||
// Push always succeeds: pool is sized to queue capacity (SIZE-1), so if
|
||||
@@ -222,7 +222,7 @@ void USBUartComponent::loop() {
|
||||
|
||||
#ifdef USE_UART_DEBUGGER
|
||||
if (channel->debug_) {
|
||||
char buf[4 + format_hex_pretty_size(UsbDataChunk::MAX_CHUNK_SIZE)]; // "<<< " + hex
|
||||
char buf[4 + format_hex_pretty_size(usb_host::USB_MAX_PACKET_SIZE)]; // "<<< " + hex
|
||||
memcpy(buf, "<<< ", 4);
|
||||
format_hex_pretty_to(buf + 4, sizeof(buf) - 4, chunk->data, chunk->length, ',');
|
||||
ESP_LOGD(TAG, "%s%s", channel->debug_prefix_.c_str(), buf);
|
||||
@@ -377,7 +377,7 @@ void USBUartComponent::start_output(USBUartChannel *channel) {
|
||||
this->start_output(channel);
|
||||
};
|
||||
|
||||
const uint8_t len = chunk->length;
|
||||
const auto len = chunk->length;
|
||||
if (!this->transfer_out(ep->bEndpointAddress, callback, chunk->data, len)) {
|
||||
// Transfer submission failed — return chunk and release flag so callers can retry.
|
||||
channel->output_pool_.release(chunk);
|
||||
@@ -394,10 +394,10 @@ void USBUartComponent::start_output(USBUartChannel *channel) {
|
||||
static void fix_mps(const usb_ep_desc_t *ep) {
|
||||
if (ep != nullptr) {
|
||||
auto *ep_mutable = const_cast<usb_ep_desc_t *>(ep);
|
||||
if (ep->wMaxPacketSize > 64) {
|
||||
ESP_LOGW(TAG, "Corrected MPS of EP 0x%02X from %u to 64", static_cast<uint8_t>(ep->bEndpointAddress & 0xFF),
|
||||
ep->wMaxPacketSize);
|
||||
ep_mutable->wMaxPacketSize = 64;
|
||||
if (ep->wMaxPacketSize > usb_host::USB_MAX_PACKET_SIZE) {
|
||||
ESP_LOGW(TAG, "Corrected MPS of EP 0x%02X from %u to %u", static_cast<uint8_t>(ep->bEndpointAddress & 0xFF),
|
||||
ep->wMaxPacketSize, usb_host::USB_MAX_PACKET_SIZE);
|
||||
ep_mutable->wMaxPacketSize = usb_host::USB_MAX_PACKET_SIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user