ESPHome
2026.5.0-dev
Loading...
Searching...
No Matches
esphome
components
tinyusb
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
"
3
#include "
esphome/core/helpers.h
"
4
#include "
esphome/core/log.h
"
5
#include "tinyusb_default_config.h"
6
7
namespace
esphome::tinyusb
{
8
9
static
const
char
*TAG =
"tinyusb"
;
10
11
void
TinyUSB::setup
() {
12
// Use the device's MAC address as its serial number if no serial number is defined
13
if
(this->
string_descriptor_
[
SERIAL_NUMBER
] ==
nullptr
) {
14
static
char
mac_addr_buf[13];
15
get_mac_address_into_buffer
(mac_addr_buf);
16
this->
string_descriptor_
[
SERIAL_NUMBER
] = mac_addr_buf;
17
}
18
19
// Start from esp_tinyusb defaults to keep required task settings valid across esp_tinyusb updates.
20
this->
tusb_cfg_
= TINYUSB_DEFAULT_CONFIG();
21
this->
tusb_cfg_
.port = TINYUSB_PORT_FULL_SPEED_0;
22
this->
tusb_cfg_
.phy.skip_setup =
false
;
23
this->
tusb_cfg_
.descriptor = {
24
.device = &this->
usb_descriptor_
,
25
.string = this->
string_descriptor_
,
26
.string_count =
SIZE
,
27
};
28
29
esp_err_t result = tinyusb_driver_install(&this->
tusb_cfg_
);
30
if
(result != ESP_OK) {
31
ESP_LOGE(TAG,
"tinyusb_driver_install failed: %s"
, esp_err_to_name(result));
32
this->
mark_failed
();
33
}
34
}
35
36
void
TinyUSB::dump_config
() {
37
ESP_LOGCONFIG(TAG,
38
"TinyUSB:\n"
39
" Product ID: 0x%04X\n"
40
" Vendor ID: 0x%04X\n"
41
" Manufacturer: '%s'\n"
42
" Product: '%s'\n"
43
" Serial: '%s'\n"
,
44
this->
usb_descriptor_
.idProduct, this->usb_descriptor_.idVendor, this->string_descriptor_[
MANUFACTURER
],
45
this->string_descriptor_[
PRODUCT
], this->string_descriptor_[
SERIAL_NUMBER
]);
46
}
47
48
}
// namespace esphome::tinyusb
49
#endif
// USE_ESP32_VARIANT_ESP32P4 || USE_ESP32_VARIANT_ESP32S2 || USE_ESP32_VARIANT_ESP32S3
esphome::Component::mark_failed
void mark_failed()
Mark this component as failed.
Definition
component.cpp:283
esphome::tinyusb::TinyUSB::tusb_cfg_
tinyusb_config_t tusb_cfg_
Definition
tinyusb_component.h:52
esphome::tinyusb::TinyUSB::string_descriptor_
const char * string_descriptor_[SIZE]
Definition
tinyusb_component.h:43
esphome::tinyusb::TinyUSB::usb_descriptor_
tusb_desc_device_t usb_descriptor_
Definition
tinyusb_component.h:53
esphome::tinyusb::TinyUSB::setup
void setup() override
Definition
tinyusb_component.cpp:11
esphome::tinyusb::TinyUSB::dump_config
void dump_config() override
Definition
tinyusb_component.cpp:36
helpers.h
log.h
esphome::tinyusb
Definition
tinyusb_component.cpp:7
esphome::tinyusb::MANUFACTURER
@ MANUFACTURER
Definition
tinyusb_component.h:12
esphome::tinyusb::PRODUCT
@ PRODUCT
Definition
tinyusb_component.h:13
esphome::tinyusb::SIZE
@ SIZE
Definition
tinyusb_component.h:17
esphome::tinyusb::SERIAL_NUMBER
@ SERIAL_NUMBER
Definition
tinyusb_component.h:14
esphome::get_mac_address_into_buffer
void get_mac_address_into_buffer(std::span< char, MAC_ADDRESS_BUFFER_SIZE > buf)
Get the device MAC address into the given buffer, in lowercase hex notation.
Definition
helpers.cpp:867
tinyusb_component.h
Generated by
1.12.0