1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-31 23:21:54 +00:00
This commit is contained in:
J. Nick Koston
2025-10-25 15:02:56 -07:00
parent 2c6b9d3826
commit 7e31149584
2 changed files with 42 additions and 33 deletions

View File

@@ -184,13 +184,10 @@ void USBUartComponent::restart_input_(USBUartChannel *channel) {
}
}
void USBUartComponent::do_start_input_(USBUartChannel *channel) {
// This function does the actual work of starting input
// Caller must ensure input_started_ is already set to true
const auto *ep = channel->cdc_dev_.in_ep;
// CALLBACK CONTEXT: This lambda is executed in USB task via transfer_callback
auto callback = [this, channel](const usb_host::TransferStatus &status) {
void USBUartComponent::input_transfer_callback_(USBUartChannel *channel, const usb_host::TransferStatus &status) {
// CALLBACK CONTEXT: This function is executed in USB task via transfer_callback
ESP_LOGV(TAG, "Transfer result: length: %u; status %X", status.data_len, status.error_code);
if (!status.success) {
ESP_LOGE(TAG, "Control transfer failed, status=%s", esp_err_to_name(status.error_code));
// Transfer failed, slot already released
@@ -225,7 +222,18 @@ void USBUartComponent::do_start_input_(USBUartChannel *channel) {
channel->input_retry_count_.store(0);
channel->input_started_.store(false);
this->start_input(channel);
}
void USBUartComponent::do_start_input_(USBUartChannel *channel) {
// This function does the actual work of starting input
// Caller must ensure input_started_ is already set to true
const auto *ep = channel->cdc_dev_.in_ep;
// Set up callback using a lambda that captures channel and forwards to the named function
auto callback = [this, channel](const usb_host::TransferStatus &status) {
this->input_transfer_callback_(channel, status);
};
// input_started_ already set to true by caller
auto result = this->transfer_in(ep->bEndpointAddress, callback, ep->wMaxPacketSize);
if (result == usb_host::TRANSFER_ERROR_NO_SLOTS) {

View File

@@ -145,6 +145,7 @@ class USBUartComponent : public usb_host::USBClient {
void reset_input_state_(USBUartChannel *channel);
void restart_input_(USBUartChannel *channel);
void do_start_input_(USBUartChannel *channel);
void input_transfer_callback_(USBUartChannel *channel, const usb_host::TransferStatus &status);
std::vector<USBUartChannel *> channels_{};
};