ESPHome 2025.12.0-dev
Loading...
Searching...
No Matches
tinyusb_component.cpp
Go to the documentation of this file.
1#if defined(USE_ESP32_VARIANT_ESP32P4) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
2#include "tinyusb_component.h"
4#include "esphome/core/log.h"
5
6namespace esphome::tinyusb {
7
8static const char *TAG = "tinyusb";
9
11 // Use the device's MAC address as its serial number if no serial number is defined
12 if (this->string_descriptor_[SERIAL_NUMBER] == nullptr) {
13 static char mac_addr_buf[13];
14 get_mac_address_into_buffer(mac_addr_buf);
15 this->string_descriptor_[SERIAL_NUMBER] = mac_addr_buf;
16 }
17
18 this->tusb_cfg_ = {
19 .descriptor = &this->usb_descriptor_,
20 .string_descriptor = this->string_descriptor_,
21 .string_descriptor_count = SIZE,
22 .external_phy = false,
23 };
24
25 esp_err_t result = tinyusb_driver_install(&this->tusb_cfg_);
26 if (result != ESP_OK) {
27 this->mark_failed();
28 }
29}
30
32 ESP_LOGCONFIG(TAG,
33 "TinyUSB:\n"
34 " Product ID: 0x%04X\n"
35 " Vendor ID: 0x%04X\n"
36 " Manufacturer: '%s'\n"
37 " Product: '%s'\n"
38 " Serial: '%s'\n",
39 this->usb_descriptor_.idProduct, this->usb_descriptor_.idVendor, this->string_descriptor_[MANUFACTURER],
40 this->string_descriptor_[PRODUCT], this->string_descriptor_[SERIAL_NUMBER]);
41}
42
43} // namespace esphome::tinyusb
44#endif
virtual void mark_failed()
Mark this component as failed.
const char * string_descriptor_[SIZE]
tusb_desc_device_t usb_descriptor_
void get_mac_address_into_buffer(std::span< char, 13 > buf)
Get the device MAC address into the given buffer, in lowercase hex notation.
Definition helpers.cpp:646