ESPHome 2026.3.0
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 instead of waiting for select() timeout
204#if defined(USE_SOCKET_SELECT_SUPPORT) && defined(USE_WAKE_LOOP_THREADSAFE)
206#endif
207}
209 usb_host_client_config_t config{.is_synchronous = false,
210 .max_num_event_msg = 5,
211 .async = {.client_event_callback = client_event_cb, .callback_arg = this}};
212 auto err = usb_host_client_register(&config, &this->handle_);
213 if (err != ESP_OK) {
214 ESP_LOGE(TAG, "client register failed: %s", esp_err_to_name(err));
215 this->status_set_error(LOG_STR("Client register failed"));
216 this->mark_failed();
217 return;
218 }
219 // Pre-allocate USB transfer buffers for all slots at startup
220 // This avoids any dynamic allocation during runtime
221 for (auto &request : this->requests_) {
222 usb_host_transfer_alloc(64, 0, &request.transfer);
223 request.client = this; // Set once, never changes
224 }
225
226 // Create and start USB task
227 xTaskCreate(usb_task_fn, "usb_task",
228 USB_TASK_STACK_SIZE, // Stack size
229 this, // Task parameter
230 USB_TASK_PRIORITY, // Priority (higher than main loop)
231 &this->usb_task_handle_);
232
233 if (this->usb_task_handle_ == nullptr) {
234 ESP_LOGE(TAG, "Failed to create USB task");
235 this->mark_failed();
236 }
237}
238
239void USBClient::usb_task_fn(void *arg) {
240 auto *client = static_cast<USBClient *>(arg);
241 client->usb_task_loop();
242}
244 while (true) {
245 usb_host_client_handle_events(this->handle_, portMAX_DELAY);
246 }
247}
248
250 bool had_work = false;
251
252 // Process any events from the USB task
253 UsbEvent *event;
254 while ((event = this->event_queue.pop()) != nullptr) {
255 had_work = true;
256 switch (event->type) {
257 case EVENT_DEVICE_NEW:
258 this->on_opened(event->data.device_new.address);
259 break;
261 this->on_removed(event->data.device_gone.handle);
262 break;
263 }
264 // Return event to pool for reuse
265 this->event_pool.release(event);
266 }
267
268 // Log dropped events periodically
269 uint16_t dropped = this->event_queue.get_and_reset_dropped_count();
270 if (dropped > 0) {
271 ESP_LOGW(TAG, "Dropped %u USB events due to queue overflow", dropped);
272 }
273
274 if (this->state_ == USB_CLIENT_OPEN) {
275 had_work = true;
276 this->handle_open_state_();
277 }
278
279 return had_work;
280}
281
283 if (!this->process_usb_events_()) {
284 this->disable_loop();
285 }
286}
287
289 int err;
290 ESP_LOGD(TAG, "Open device %d", this->device_addr_);
291 err = usb_host_device_open(this->handle_, this->device_addr_, &this->device_handle_);
292 if (err != ESP_OK) {
293 ESP_LOGW(TAG, "Device open failed: %s", esp_err_to_name(err));
294 this->state_ = USB_CLIENT_INIT;
295 return;
296 }
297 ESP_LOGD(TAG, "Get descriptor device %d", this->device_addr_);
298 const usb_device_desc_t *desc;
299 err = usb_host_get_device_descriptor(this->device_handle_, &desc);
300 if (err != ESP_OK) {
301 ESP_LOGW(TAG, "Device get_desc failed: %s", esp_err_to_name(err));
302 this->disconnect();
303 return;
304 }
305 ESP_LOGD(TAG, "Device descriptor: vid %X pid %X", desc->idVendor, desc->idProduct);
306 if (desc->idVendor != this->vid_ || desc->idProduct != this->pid_) {
307 if (this->vid_ != 0 || this->pid_ != 0) {
308 ESP_LOGD(TAG, "Not our device, closing");
309 this->disconnect();
310 return;
311 }
312 }
313 usb_device_info_t dev_info;
314 err = usb_host_device_info(this->device_handle_, &dev_info);
315 if (err != ESP_OK) {
316 ESP_LOGW(TAG, "Device info failed: %s", esp_err_to_name(err));
317 this->disconnect();
318 return;
319 }
321 char buf_manuf[DESC_STRING_BUF_SIZE];
322 char buf_product[DESC_STRING_BUF_SIZE];
323 char buf_serial[DESC_STRING_BUF_SIZE];
324 ESP_LOGD(TAG, "Device connected: Manuf: %s; Prod: %s; Serial: %s",
325 get_descriptor_string(dev_info.str_desc_manufacturer, buf_manuf),
326 get_descriptor_string(dev_info.str_desc_product, buf_product),
327 get_descriptor_string(dev_info.str_desc_serial_num, buf_serial));
328
329#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
330 const usb_device_desc_t *device_desc;
331 err = usb_host_get_device_descriptor(this->device_handle_, &device_desc);
332 if (err == ESP_OK)
333 usb_client_print_device_descriptor(device_desc);
334 const usb_config_desc_t *config_desc;
335 err = usb_host_get_active_config_descriptor(this->device_handle_, &config_desc);
336 if (err == ESP_OK)
337 usb_client_print_config_descriptor(config_desc, nullptr);
338#endif
339 this->on_connected();
340}
341
342void USBClient::on_opened(uint8_t addr) {
343 if (this->state_ == USB_CLIENT_INIT) {
344 this->device_addr_ = addr;
345 this->state_ = USB_CLIENT_OPEN;
346 }
347}
348void USBClient::on_removed(usb_device_handle_t handle) {
349 if (this->device_handle_ == handle) {
350 this->disconnect();
351 }
352}
353
354// CALLBACK CONTEXT: USB task (called from usb_host_client_handle_events in USB task)
355static void control_callback(const usb_transfer_t *xfer) {
356 auto *trq = static_cast<TransferRequest *>(xfer->context);
357 trq->status.error_code = xfer->status;
358 trq->status.success = xfer->status == USB_TRANSFER_STATUS_COMPLETED;
359 trq->status.endpoint = xfer->bEndpointAddress;
360 trq->status.data = xfer->data_buffer;
361 trq->status.data_len = xfer->actual_num_bytes;
362
363 // Execute callback in USB task context
364 if (trq->callback != nullptr) {
365 trq->callback(trq->status);
366 }
367
368 // Release transfer slot immediately in USB task
369 // The release_trq() uses thread-safe atomic operations
370 trq->client->release_trq(trq);
371}
372
373// THREAD CONTEXT: Called from both USB task and main loop threads (multi-consumer)
374// - USB task: USB UART input callbacks restart transfers for immediate data reception
375// - Main loop: Output transfers and flow-controlled input restarts after consuming data
376//
377// THREAD SAFETY: Lock-free using atomic compare-and-swap on bitmask
378// This multi-threaded access is intentional for performance - USB task can
379// immediately restart transfers without waiting for main loop scheduling.
381 trq_bitmask_t mask = this->trq_in_use_.load(std::memory_order_acquire);
382
383 // Find first available slot (bit = 0) and try to claim it atomically
384 // We use a while loop to allow retrying the same slot after CAS failure
385 for (;;) {
386 if (mask == ALL_REQUESTS_IN_USE) {
387 ESP_LOGE(TAG, "All %zu transfer slots in use", MAX_REQUESTS);
388 return nullptr;
389 }
390 // find the least significant zero bit
391 trq_bitmask_t lsb = ~mask & (mask + 1);
392
393 // Slot i appears available, try to claim it atomically
394 trq_bitmask_t desired = mask | lsb;
395
396 if (this->trq_in_use_.compare_exchange_weak(mask, desired, std::memory_order::acquire)) {
397 auto i = __builtin_ctz(lsb); // count trailing zeroes
398 // Successfully claimed slot i - prepare the TransferRequest
399 auto *trq = &this->requests_[i];
400 trq->transfer->context = trq;
401 trq->transfer->device_handle = this->device_handle_;
402 return trq;
403 }
404 // CAS failed - another thread modified the bitmask
405 // mask was already updated by compare_exchange_weak with the current value
406 }
407}
408
410 this->on_disconnected();
411 auto err = usb_host_device_close(this->handle_, this->device_handle_);
412 if (err != ESP_OK) {
413 ESP_LOGE(TAG, "Device close failed: %s", esp_err_to_name(err));
414 }
415 this->state_ = USB_CLIENT_INIT;
416 this->device_handle_ = nullptr;
417 this->device_addr_ = -1;
418}
419
420// THREAD CONTEXT: Called from main loop thread only
421// - Used for device configuration and control operations
422bool USBClient::control_transfer(uint8_t type, uint8_t request, uint16_t value, uint16_t index,
423 const transfer_cb_t &callback, const std::vector<uint8_t> &data) {
424 auto *trq = this->get_trq_();
425 if (trq == nullptr)
426 return false;
427 auto length = data.size();
428 if (length > trq->transfer->data_buffer_size - SETUP_PACKET_SIZE) {
429 ESP_LOGE(TAG, "Control transfer data size too large: %u > %u", length,
430 trq->transfer->data_buffer_size - SETUP_PACKET_SIZE);
431 this->release_trq(trq);
432 return false;
433 }
434 auto control_packet = ByteBuffer(SETUP_PACKET_SIZE, LITTLE);
435 control_packet.put_uint8(type);
436 control_packet.put_uint8(request);
437 control_packet.put_uint16(value);
438 control_packet.put_uint16(index);
439 control_packet.put_uint16(length);
440 memcpy(trq->transfer->data_buffer, control_packet.get_data().data(), SETUP_PACKET_SIZE);
441 if (length != 0 && !(type & USB_DIR_IN)) {
442 memcpy(trq->transfer->data_buffer + SETUP_PACKET_SIZE, data.data(), length);
443 }
444 trq->callback = callback;
445 trq->transfer->bEndpointAddress = type & USB_DIR_MASK;
446 trq->transfer->num_bytes = static_cast<int>(length + SETUP_PACKET_SIZE);
447 trq->transfer->callback = reinterpret_cast<usb_transfer_cb_t>(control_callback);
448 auto err = usb_host_transfer_submit_control(this->handle_, trq->transfer);
449 if (err != ESP_OK) {
450 ESP_LOGE(TAG, "Failed to submit control transfer, err=%s", esp_err_to_name(err));
451 this->release_trq(trq);
452 return false;
453 }
454 return true;
455}
456
457// CALLBACK CONTEXT: USB task (called from usb_host_client_handle_events in USB task)
458static void transfer_callback(usb_transfer_t *xfer) {
459 auto *trq = static_cast<TransferRequest *>(xfer->context);
460 trq->status.error_code = xfer->status;
461 trq->status.success = xfer->status == USB_TRANSFER_STATUS_COMPLETED;
462 trq->status.endpoint = xfer->bEndpointAddress;
463 trq->status.data = xfer->data_buffer;
464 trq->status.data_len = xfer->actual_num_bytes;
465
466 // Always execute callback in USB task context
467 // Callbacks should be fast and non-blocking (e.g., copy data to queue)
468 if (trq->callback != nullptr) {
469 trq->callback(trq->status);
470 }
471
472 // Release transfer slot AFTER callback completes to prevent slot exhaustion
473 // This is critical for high-throughput transfers (e.g., USB UART at 115200 baud)
474 // The callback has finished accessing xfer->data_buffer, so it's safe to release
475 // The release_trq() uses thread-safe atomic operations
476 trq->client->release_trq(trq);
477}
490bool USBClient::transfer_in(uint8_t ep_address, const transfer_cb_t &callback, uint16_t length) {
491 auto *trq = this->get_trq_();
492 if (trq == nullptr) {
493 ESP_LOGE(TAG, "Too many requests queued");
494 return false;
495 }
496 if (length > trq->transfer->data_buffer_size) {
497 ESP_LOGE(TAG, "transfer_in: data length %u exceeds buffer size %u", length, trq->transfer->data_buffer_size);
498 this->release_trq(trq);
499 return false;
500 }
501 trq->callback = callback;
502 trq->transfer->callback = transfer_callback;
503 trq->transfer->bEndpointAddress = ep_address | USB_DIR_IN;
504 trq->transfer->num_bytes = length;
505 auto err = usb_host_transfer_submit(trq->transfer);
506 if (err != ESP_OK) {
507 ESP_LOGE(TAG, "Failed to submit transfer, address=%x, length=%d, err=%x", ep_address, length, err);
508 this->release_trq(trq);
509 return false;
510 }
511 return true;
512}
513
531bool USBClient::transfer_out(uint8_t ep_address, const transfer_cb_t &callback, const uint8_t *data, uint16_t length) {
532 auto *trq = this->get_trq_();
533 if (trq == nullptr) {
534 ESP_LOGE(TAG, "Too many requests queued");
535 return false;
536 }
537 if (length > trq->transfer->data_buffer_size) {
538 ESP_LOGE(TAG, "transfer_out: data length %u exceeds buffer size %u", length, trq->transfer->data_buffer_size);
539 this->release_trq(trq);
540 return false;
541 }
542 trq->callback = callback;
543 trq->transfer->callback = transfer_callback;
544 trq->transfer->bEndpointAddress = ep_address | USB_DIR_OUT;
545 trq->transfer->num_bytes = length;
546 memcpy(trq->transfer->data_buffer, data, length);
547 auto err = usb_host_transfer_submit(trq->transfer);
548 if (err != ESP_OK) {
549 ESP_LOGE(TAG, "Failed to submit transfer, address=%x, length=%d, err=%x", ep_address, length, err);
550 this->release_trq(trq);
551 return false;
552 }
553 return true;
554}
556 ESP_LOGCONFIG(TAG,
557 "USBClient\n"
558 " Vendor id %04X\n"
559 " Product id %04X",
560 this->vid_, this->pid_);
561}
562// THREAD CONTEXT: Called from both USB task and main loop threads
563// - USB task: Immediately after transfer callback completes
564// - Main loop: When transfer submission fails
565//
566// THREAD SAFETY: Lock-free using atomic AND to clear bit
567// Thread-safe atomic operation allows multithreaded deallocation
569 if (trq == nullptr)
570 return;
571
572 // Calculate index from pointer arithmetic
573 size_t index = trq - this->requests_;
574 if (index >= MAX_REQUESTS) {
575 ESP_LOGE(TAG, "Invalid TransferRequest pointer");
576 return;
577 }
578
579 // Atomically clear the bit to mark slot as available
580 // fetch_and with inverted bitmask clears the bit atomically
581 trq_bitmask_t mask = ~(static_cast<trq_bitmask_t>(1) << index);
582 this->trq_in_use_.fetch_and(mask, std::memory_order_release);
583}
584
585} // namespace esphome::usb_host
586#endif // USE_ESP32_VARIANT_ESP32P4 || USE_ESP32_VARIANT_ESP32S2 || USE_ESP32_VARIANT_ESP32S3
void wake_loop_threadsafe()
Wake the main event loop from another FreeRTOS task.
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::@163::@164 device_new
struct esphome::usb_host::UsbEvent::@163::@165 device_gone
usb_device_handle_t handle
Definition usb_host.h:107
union esphome::usb_host::UsbEvent::@163 data
uint8_t end[39]
Definition sun_gtil2.cpp:17
uint16_t length
Definition tt21100.cpp:0