ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
usb_host_client.cpp
Go to the documentation of this file.
1// Should not be needed, but it's required to pass CI clang-tidy checks
2#if defined(USE_ESP32_VARIANT_ESP32P4) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
3#include "usb_host.h"
4#include "esphome/core/log.h"
5#include "esphome/core/hal.h"
8
9#include <cinttypes>
10#include <cstring>
11#include <atomic>
12#include <span>
13namespace esphome::usb_host {
14
15#pragma GCC diagnostic ignored "-Wparentheses"
16
17using namespace bytebuffer;
18
19#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
20static void print_ep_desc(const usb_ep_desc_t *ep_desc) {
21 const char *ep_type_str;
22 int type = ep_desc->bmAttributes & USB_BM_ATTRIBUTES_XFERTYPE_MASK;
23
24 switch (type) {
25 case USB_BM_ATTRIBUTES_XFER_CONTROL:
26 ep_type_str = "CTRL";
27 break;
28 case USB_BM_ATTRIBUTES_XFER_ISOC:
29 ep_type_str = "ISOC";
30 break;
31 case USB_BM_ATTRIBUTES_XFER_BULK:
32 ep_type_str = "BULK";
33 break;
34 case USB_BM_ATTRIBUTES_XFER_INT:
35 ep_type_str = "INT";
36 break;
37 default:
38 ep_type_str = NULL;
39 break;
40 }
41
42 ESP_LOGV(TAG,
43 "\t\t*** Endpoint descriptor ***\n"
44 "\t\tbLength %d\n"
45 "\t\tbDescriptorType %d\n"
46 "\t\tbEndpointAddress 0x%x\tEP %d %s\n"
47 "\t\tbmAttributes 0x%x\t%s\n"
48 "\t\twMaxPacketSize %d\n"
49 "\t\tbInterval %d",
50 ep_desc->bLength, ep_desc->bDescriptorType, ep_desc->bEndpointAddress, USB_EP_DESC_GET_EP_NUM(ep_desc),
51 USB_EP_DESC_GET_EP_DIR(ep_desc) ? "IN" : "OUT", ep_desc->bmAttributes, ep_type_str, ep_desc->wMaxPacketSize,
52 ep_desc->bInterval);
53}
54
55static void usbh_print_intf_desc(const usb_intf_desc_t *intf_desc) {
56 ESP_LOGV(TAG,
57 "\t*** Interface descriptor ***\n"
58 "\tbLength %d\n"
59 "\tbDescriptorType %d\n"
60 "\tbInterfaceNumber %d\n"
61 "\tbAlternateSetting %d\n"
62 "\tbNumEndpoints %d\n"
63 "\tbInterfaceClass 0x%x\n"
64 "\tiInterface %d",
65 intf_desc->bLength, intf_desc->bDescriptorType, intf_desc->bInterfaceNumber, intf_desc->bAlternateSetting,
66 intf_desc->bNumEndpoints, intf_desc->bInterfaceProtocol, intf_desc->iInterface);
67}
68
69static void usbh_print_cfg_desc(const usb_config_desc_t *cfg_desc) {
70 ESP_LOGV(TAG,
71 "*** Configuration descriptor ***\n"
72 " bLength %d\n"
73 " bDescriptorType %d\n"
74 " wTotalLength %d\n"
75 " bNumInterfaces %d\n"
76 " bConfigurationValue %d\n"
77 " iConfiguration %d\n"
78 " bmAttributes 0x%x\n"
79 " bMaxPower %dmA",
80 cfg_desc->bLength, cfg_desc->bDescriptorType, cfg_desc->wTotalLength, cfg_desc->bNumInterfaces,
81 cfg_desc->bConfigurationValue, cfg_desc->iConfiguration, cfg_desc->bmAttributes, cfg_desc->bMaxPower * 2);
82}
83
84static void usb_client_print_device_descriptor(const usb_device_desc_t *devc_desc) {
85 if (devc_desc == NULL) {
86 return;
87 }
88
89 ESP_LOGV(TAG,
90 "*** Device descriptor ***\n"
91 " bLength %d\n"
92 " bDescriptorType %d\n"
93 " bcdUSB %d.%d0\n"
94 " bDeviceClass 0x%x\n"
95 " bDeviceSubClass 0x%x\n"
96 " bDeviceProtocol 0x%x\n"
97 " bMaxPacketSize0 %d\n"
98 " idVendor 0x%x\n"
99 " idProduct 0x%x\n"
100 " bcdDevice %d.%d0\n"
101 " iManufacturer %d\n"
102 " iProduct %d\n"
103 " iSerialNumber %d\n"
104 " bNumConfigurations %d",
105 devc_desc->bLength, devc_desc->bDescriptorType, ((devc_desc->bcdUSB >> 8) & 0xF),
106 ((devc_desc->bcdUSB >> 4) & 0xF), devc_desc->bDeviceClass, devc_desc->bDeviceSubClass,
107 devc_desc->bDeviceProtocol, devc_desc->bMaxPacketSize0, devc_desc->idVendor, devc_desc->idProduct,
108 ((devc_desc->bcdDevice >> 8) & 0xF), ((devc_desc->bcdDevice >> 4) & 0xF), devc_desc->iManufacturer,
109 devc_desc->iProduct, devc_desc->iSerialNumber, devc_desc->bNumConfigurations);
110}
111
112static void usb_client_print_config_descriptor(const usb_config_desc_t *cfg_desc,
113 print_class_descriptor_cb class_specific_cb) {
114 if (cfg_desc == nullptr) {
115 return;
116 }
117
118 int offset = 0;
119 uint16_t w_total_length = cfg_desc->wTotalLength;
120 const usb_standard_desc_t *next_desc = (const usb_standard_desc_t *) cfg_desc;
121
122 do {
123 switch (next_desc->bDescriptorType) {
124 case USB_W_VALUE_DT_CONFIG:
125 usbh_print_cfg_desc((const usb_config_desc_t *) next_desc);
126 break;
127 case USB_W_VALUE_DT_INTERFACE:
128 usbh_print_intf_desc((const usb_intf_desc_t *) next_desc);
129 break;
130 case USB_W_VALUE_DT_ENDPOINT:
131 print_ep_desc((const usb_ep_desc_t *) next_desc);
132 break;
133 default:
134 if (class_specific_cb) {
135 class_specific_cb(next_desc);
136 }
137 break;
138 }
139
140 next_desc = usb_parse_next_descriptor(next_desc, w_total_length, &offset);
141
142 } while (next_desc != NULL);
143}
144#endif
145// USB string descriptors: bLength (uint8_t, max 255) includes the 2-byte header (bLength and bDescriptorType).
146// Character count = (bLength - 2) / 2, max 126 chars + null terminator.
147static constexpr size_t DESC_STRING_BUF_SIZE = 128;
148
149static const char *get_descriptor_string(const usb_str_desc_t *desc, std::span<char, DESC_STRING_BUF_SIZE> buffer) {
150 if (desc == nullptr || desc->bLength < 2)
151 return "(unspecified)";
152 int char_count = (desc->bLength - 2) / 2;
153 char *p = buffer.data();
154 char *end = p + buffer.size() - 1;
155 for (int i = 0; i != char_count && p < end; i++) {
156 auto c = desc->wData[i];
157 if (c < 0x100)
158 *p++ = static_cast<char>(c);
159 }
160 *p = '\0';
161 return buffer.data();
162}
163
164// CALLBACK CONTEXT: USB task (called from usb_host_client_handle_events in USB task)
165static void client_event_cb(const usb_host_client_event_msg_t *event_msg, void *ptr) {
166 auto *client = static_cast<USBClient *>(ptr);
167
168 // Allocate event from pool
169 UsbEvent *event = client->event_pool.allocate();
170 if (event == nullptr) {
171 // No events available - increment counter for periodic logging
172 client->event_queue.increment_dropped_count();
173 return;
174 }
175
176 // Queue events to be processed in main loop
177 switch (event_msg->event) {
178 case USB_HOST_CLIENT_EVENT_NEW_DEV: {
179 ESP_LOGD(TAG, "New device %d", event_msg->new_dev.address);
180 event->type = EVENT_DEVICE_NEW;
181 event->data.device_new.address = event_msg->new_dev.address;
182 break;
183 }
184 case USB_HOST_CLIENT_EVENT_DEV_GONE: {
185 ESP_LOGD(TAG, "Device gone");
186 event->type = EVENT_DEVICE_GONE;
187 event->data.device_gone.handle = event_msg->dev_gone.dev_hdl;
188 break;
189 }
190 default:
191 ESP_LOGD(TAG, "Unknown event %d", event_msg->event);
192 client->event_pool.release(event);
193 return;
194 }
195
196 // Push always succeeds: pool is sized to queue capacity (SIZE-1), so if
197 // allocate() returned non-null, the queue cannot be full.
198 client->event_queue.push(event);
199
200 // Re-enable component loop to process the queued event
201 client->enable_loop_soon_any_context();
202
203 // Wake main loop immediately to process USB event
205}
207 usb_host_client_config_t config{.is_synchronous = false,
208 .max_num_event_msg = 5,
209 .async = {.client_event_callback = client_event_cb, .callback_arg = this}};
210 auto err = usb_host_client_register(&config, &this->handle_);
211 if (err != ESP_OK) {
212 ESP_LOGE(TAG, "client register failed: %s", esp_err_to_name(err));
213 this->status_set_error(LOG_STR("Client register failed"));
214 this->mark_failed();
215 return;
216 }
217 // Pre-allocate USB transfer buffers for all slots at startup
218 // This avoids any dynamic allocation during runtime
219 for (auto &request : this->requests_) {
220 usb_host_transfer_alloc(64, 0, &request.transfer);
221 request.client = this; // Set once, never changes
222 }
223
224 // Create and start USB task
225 xTaskCreate(usb_task_fn, "usb_task",
226 USB_TASK_STACK_SIZE, // Stack size
227 this, // Task parameter
228 USB_TASK_PRIORITY, // Priority (higher than main loop)
229 &this->usb_task_handle_);
230
231 if (this->usb_task_handle_ == nullptr) {
232 ESP_LOGE(TAG, "Failed to create USB task");
233 this->mark_failed();
234 }
235}
236
237void USBClient::usb_task_fn(void *arg) {
238 auto *client = static_cast<USBClient *>(arg);
239 client->usb_task_loop();
240}
242 while (true) {
243 usb_host_client_handle_events(this->handle_, portMAX_DELAY);
244 }
245}
246
248 bool had_work = false;
249
250 // Process any events from the USB task
251 UsbEvent *event;
252 while ((event = this->event_queue.pop()) != nullptr) {
253 had_work = true;
254 switch (event->type) {
255 case EVENT_DEVICE_NEW:
256 this->on_opened(event->data.device_new.address);
257 break;
259 this->on_removed(event->data.device_gone.handle);
260 break;
261 }
262 // Return event to pool for reuse
263 this->event_pool.release(event);
264 }
265
266 // Log dropped events periodically
267 uint16_t dropped = this->event_queue.get_and_reset_dropped_count();
268 if (dropped > 0) {
269 ESP_LOGW(TAG, "Dropped %u USB events due to queue overflow", dropped);
270 }
271
272 if (this->state_ == USB_CLIENT_OPEN) {
273 had_work = true;
274 this->handle_open_state_();
275 }
276
277 return had_work;
278}
279
281 if (!this->process_usb_events_()) {
282 this->disable_loop();
283 }
284}
285
287 int err;
288 ESP_LOGD(TAG, "Open device %d", this->device_addr_);
289 err = usb_host_device_open(this->handle_, this->device_addr_, &this->device_handle_);
290 if (err != ESP_OK) {
291 ESP_LOGW(TAG, "Device open failed: %s", esp_err_to_name(err));
292 this->state_ = USB_CLIENT_INIT;
293 return;
294 }
295 ESP_LOGD(TAG, "Get descriptor device %d", this->device_addr_);
296 const usb_device_desc_t *desc;
297 err = usb_host_get_device_descriptor(this->device_handle_, &desc);
298 if (err != ESP_OK) {
299 ESP_LOGW(TAG, "Device get_desc failed: %s", esp_err_to_name(err));
300 this->disconnect();
301 return;
302 }
303 ESP_LOGD(TAG, "Device descriptor: vid %X pid %X", desc->idVendor, desc->idProduct);
304 if (desc->idVendor != this->vid_ || desc->idProduct != this->pid_) {
305 if (this->vid_ != 0 || this->pid_ != 0) {
306 ESP_LOGD(TAG, "Not our device, closing");
307 this->disconnect();
308 return;
309 }
310 }
311 usb_device_info_t dev_info;
312 err = usb_host_device_info(this->device_handle_, &dev_info);
313 if (err != ESP_OK) {
314 ESP_LOGW(TAG, "Device info failed: %s", esp_err_to_name(err));
315 this->disconnect();
316 return;
317 }
319 char buf_manuf[DESC_STRING_BUF_SIZE];
320 char buf_product[DESC_STRING_BUF_SIZE];
321 char buf_serial[DESC_STRING_BUF_SIZE];
322 ESP_LOGD(TAG, "Device connected: Manuf: %s; Prod: %s; Serial: %s",
323 get_descriptor_string(dev_info.str_desc_manufacturer, buf_manuf),
324 get_descriptor_string(dev_info.str_desc_product, buf_product),
325 get_descriptor_string(dev_info.str_desc_serial_num, buf_serial));
326
327#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
328 const usb_device_desc_t *device_desc;
329 err = usb_host_get_device_descriptor(this->device_handle_, &device_desc);
330 if (err == ESP_OK)
331 usb_client_print_device_descriptor(device_desc);
332 const usb_config_desc_t *config_desc;
333 err = usb_host_get_active_config_descriptor(this->device_handle_, &config_desc);
334 if (err == ESP_OK)
335 usb_client_print_config_descriptor(config_desc, nullptr);
336#endif
337 this->on_connected();
338}
339
340void USBClient::on_opened(uint8_t addr) {
341 if (this->state_ == USB_CLIENT_INIT) {
342 this->device_addr_ = addr;
343 this->state_ = USB_CLIENT_OPEN;
344 }
345}
346void USBClient::on_removed(usb_device_handle_t handle) {
347 if (this->device_handle_ == handle) {
348 this->disconnect();
349 }
350}
351
352// CALLBACK CONTEXT: USB task (called from usb_host_client_handle_events in USB task)
353static void control_callback(const usb_transfer_t *xfer) {
354 auto *trq = static_cast<TransferRequest *>(xfer->context);
355 trq->status.error_code = xfer->status;
356 trq->status.success = xfer->status == USB_TRANSFER_STATUS_COMPLETED;
357 trq->status.endpoint = xfer->bEndpointAddress;
358 trq->status.data = xfer->data_buffer;
359 trq->status.data_len = xfer->actual_num_bytes;
360
361 // Execute callback in USB task context
362 if (trq->callback != nullptr) {
363 trq->callback(trq->status);
364 }
365
366 // Release transfer slot immediately in USB task
367 // The release_trq() uses thread-safe atomic operations
368 trq->client->release_trq(trq);
369}
370
371// THREAD CONTEXT: Called from both USB task and main loop threads (multi-consumer)
372// - USB task: USB UART input callbacks restart transfers for immediate data reception
373// - Main loop: Output transfers and flow-controlled input restarts after consuming data
374//
375// THREAD SAFETY: Lock-free using atomic compare-and-swap on bitmask
376// This multi-threaded access is intentional for performance - USB task can
377// immediately restart transfers without waiting for main loop scheduling.
379 trq_bitmask_t mask = this->trq_in_use_.load(std::memory_order_acquire);
380
381 // Find first available slot (bit = 0) and try to claim it atomically
382 // We use a while loop to allow retrying the same slot after CAS failure
383 for (;;) {
384 if (mask == ALL_REQUESTS_IN_USE) {
385 ESP_LOGE(TAG, "All %zu transfer slots in use", MAX_REQUESTS);
386 return nullptr;
387 }
388 // find the least significant zero bit
389 trq_bitmask_t lsb = ~mask & (mask + 1);
390
391 // Slot i appears available, try to claim it atomically
392 trq_bitmask_t desired = mask | lsb;
393
394 if (this->trq_in_use_.compare_exchange_weak(mask, desired, std::memory_order::acquire)) {
395 auto i = __builtin_ctz(lsb); // count trailing zeroes
396 // Successfully claimed slot i - prepare the TransferRequest
397 auto *trq = &this->requests_[i];
398 trq->transfer->context = trq;
399 trq->transfer->device_handle = this->device_handle_;
400 return trq;
401 }
402 // CAS failed - another thread modified the bitmask
403 // mask was already updated by compare_exchange_weak with the current value
404 }
405}
406
408 this->on_disconnected();
409 auto err = usb_host_device_close(this->handle_, this->device_handle_);
410 if (err != ESP_OK) {
411 ESP_LOGE(TAG, "Device close failed: %s", esp_err_to_name(err));
412 }
413 this->state_ = USB_CLIENT_INIT;
414 this->device_handle_ = nullptr;
415 this->device_addr_ = -1;
416}
417
418// THREAD CONTEXT: Called from main loop thread only
419// - Used for device configuration and control operations
420bool USBClient::control_transfer(uint8_t type, uint8_t request, uint16_t value, uint16_t index,
421 const transfer_cb_t &callback, const std::vector<uint8_t> &data) {
422 auto *trq = this->get_trq_();
423 if (trq == nullptr)
424 return false;
425 auto length = data.size();
426 if (length > trq->transfer->data_buffer_size - SETUP_PACKET_SIZE) {
427 ESP_LOGE(TAG, "Control transfer data size too large: %u > %u", length,
428 trq->transfer->data_buffer_size - SETUP_PACKET_SIZE);
429 this->release_trq(trq);
430 return false;
431 }
432 auto control_packet = ByteBuffer(SETUP_PACKET_SIZE, LITTLE);
433 control_packet.put_uint8(type);
434 control_packet.put_uint8(request);
435 control_packet.put_uint16(value);
436 control_packet.put_uint16(index);
437 control_packet.put_uint16(length);
438 memcpy(trq->transfer->data_buffer, control_packet.get_data().data(), SETUP_PACKET_SIZE);
439 if (length != 0 && !(type & USB_DIR_IN)) {
440 memcpy(trq->transfer->data_buffer + SETUP_PACKET_SIZE, data.data(), length);
441 }
442 trq->callback = callback;
443 trq->transfer->bEndpointAddress = type & USB_DIR_MASK;
444 trq->transfer->num_bytes = static_cast<int>(length + SETUP_PACKET_SIZE);
445 trq->transfer->callback = reinterpret_cast<usb_transfer_cb_t>(control_callback);
446 auto err = usb_host_transfer_submit_control(this->handle_, trq->transfer);
447 if (err != ESP_OK) {
448 ESP_LOGE(TAG, "Failed to submit control transfer, err=%s", esp_err_to_name(err));
449 this->release_trq(trq);
450 return false;
451 }
452 return true;
453}
454
455// CALLBACK CONTEXT: USB task (called from usb_host_client_handle_events in USB task)
456static void transfer_callback(usb_transfer_t *xfer) {
457 auto *trq = static_cast<TransferRequest *>(xfer->context);
458 trq->status.error_code = xfer->status;
459 trq->status.success = xfer->status == USB_TRANSFER_STATUS_COMPLETED;
460 trq->status.endpoint = xfer->bEndpointAddress;
461 trq->status.data = xfer->data_buffer;
462 trq->status.data_len = xfer->actual_num_bytes;
463
464 // Always execute callback in USB task context
465 // Callbacks should be fast and non-blocking (e.g., copy data to queue)
466 if (trq->callback != nullptr) {
467 trq->callback(trq->status);
468 }
469
470 // Release transfer slot AFTER callback completes to prevent slot exhaustion
471 // This is critical for high-throughput transfers (e.g., USB UART at 115200 baud)
472 // The callback has finished accessing xfer->data_buffer, so it's safe to release
473 // The release_trq() uses thread-safe atomic operations
474 trq->client->release_trq(trq);
475}
488bool USBClient::transfer_in(uint8_t ep_address, const transfer_cb_t &callback, uint16_t length) {
489 auto *trq = this->get_trq_();
490 if (trq == nullptr) {
491 ESP_LOGE(TAG, "Too many requests queued");
492 return false;
493 }
494 if (length > trq->transfer->data_buffer_size) {
495 ESP_LOGE(TAG, "transfer_in: data length %u exceeds buffer size %u", length, trq->transfer->data_buffer_size);
496 this->release_trq(trq);
497 return false;
498 }
499 trq->callback = callback;
500 trq->transfer->callback = transfer_callback;
501 trq->transfer->bEndpointAddress = ep_address | USB_DIR_IN;
502 trq->transfer->num_bytes = length;
503 auto err = usb_host_transfer_submit(trq->transfer);
504 if (err != ESP_OK) {
505 ESP_LOGE(TAG, "Failed to submit transfer, address=%x, length=%d, err=%x", ep_address, length, err);
506 this->release_trq(trq);
507 return false;
508 }
509 return true;
510}
511
529bool USBClient::transfer_out(uint8_t ep_address, const transfer_cb_t &callback, const uint8_t *data, uint16_t length) {
530 auto *trq = this->get_trq_();
531 if (trq == nullptr) {
532 ESP_LOGE(TAG, "Too many requests queued");
533 return false;
534 }
535 if (length > trq->transfer->data_buffer_size) {
536 ESP_LOGE(TAG, "transfer_out: data length %u exceeds buffer size %u", length, trq->transfer->data_buffer_size);
537 this->release_trq(trq);
538 return false;
539 }
540 trq->callback = callback;
541 trq->transfer->callback = transfer_callback;
542 trq->transfer->bEndpointAddress = ep_address | USB_DIR_OUT;
543 trq->transfer->num_bytes = length;
544 memcpy(trq->transfer->data_buffer, data, length);
545 auto err = usb_host_transfer_submit(trq->transfer);
546 if (err != ESP_OK) {
547 ESP_LOGE(TAG, "Failed to submit transfer, address=%x, length=%d, err=%x", ep_address, length, err);
548 this->release_trq(trq);
549 return false;
550 }
551 return true;
552}
554 ESP_LOGCONFIG(TAG,
555 "USBClient\n"
556 " Vendor id %04X\n"
557 " Product id %04X",
558 this->vid_, this->pid_);
559}
560// THREAD CONTEXT: Called from both USB task and main loop threads
561// - USB task: Immediately after transfer callback completes
562// - Main loop: When transfer submission fails
563//
564// THREAD SAFETY: Lock-free using atomic AND to clear bit
565// Thread-safe atomic operation allows multithreaded deallocation
567 if (trq == nullptr)
568 return;
569
570 // Calculate index from pointer arithmetic
571 size_t index = trq - this->requests_;
572 if (index >= MAX_REQUESTS) {
573 ESP_LOGE(TAG, "Invalid TransferRequest pointer");
574 return;
575 }
576
577 // Atomically clear the bit to mark slot as available
578 // fetch_and with inverted bitmask clears the bit atomically
579 trq_bitmask_t mask = ~(static_cast<trq_bitmask_t>(1) << index);
580 this->trq_in_use_.fetch_and(mask, std::memory_order_release);
581}
582
583} // namespace esphome::usb_host
584#endif // USE_ESP32_VARIANT_ESP32P4 || USE_ESP32_VARIANT_ESP32S2 || USE_ESP32_VARIANT_ESP32S3
void wake_loop_threadsafe()
Wake the main event loop from another thread or callback.
void mark_failed()
Mark this component as failed.
void disable_loop()
Disable this component's loop.
A class modelled on the Java ByteBuffer class.
Definition bytebuffer.h:38
usb_host_client_handle_t handle_
Definition usb_host.h:173
TransferRequest requests_[MAX_REQUESTS]
Definition usb_host.h:171
bool transfer_out(uint8_t ep_address, const transfer_cb_t &callback, const uint8_t *data, uint16_t length)
Performs an output transfer operation.
void release_trq(TransferRequest *trq)
static void usb_task_fn(void *arg)
virtual void on_connected()
Definition usb_host.h:160
EventPool< UsbEvent, USB_EVENT_QUEUE_SIZE - 1 > event_pool
Definition usb_host.h:150
TaskHandle_t usb_task_handle_
Definition usb_host.h:172
virtual void on_disconnected()
Definition usb_host.h:161
bool control_transfer(uint8_t type, uint8_t request, uint16_t value, uint16_t index, const transfer_cb_t &callback, const std::vector< uint8_t > &data={})
bool transfer_in(uint8_t ep_address, const transfer_cb_t &callback, uint16_t length)
Performs a transfer input operation.
void on_removed(usb_device_handle_t handle)
usb_device_handle_t device_handle_
Definition usb_host.h:174
std::atomic< trq_bitmask_t > trq_in_use_
Definition usb_host.h:180
LockFreeQueue< UsbEvent, USB_EVENT_QUEUE_SIZE > event_queue
Definition usb_host.h:146
uint16_t type
std::conditional<(MAX_REQUESTS<=16), uint16_t, uint32_t >::type trq_bitmask_t
Definition usb_host.h:66
std::function< void(const TransferStatus &)> transfer_cb_t
Definition usb_host.h:83
Application App
Global storage of Application pointer - only one Application can exist.
struct esphome::usb_host::UsbEvent::@177::@179 device_gone
usb_device_handle_t handle
Definition usb_host.h:107
union esphome::usb_host::UsbEvent::@177 data
struct esphome::usb_host::UsbEvent::@177::@178 device_new
uint8_t end[39]
Definition sun_gtil2.cpp:17
uint16_t length
Definition tt21100.cpp:0