Skip to content

Commit 8aecb33

Browse files
committed
feat(usb_device_uac): support integration into other tinyusb projects
1 parent ea46beb commit 8aecb33

File tree

15 files changed

+94
-58
lines changed

15 files changed

+94
-58
lines changed

components/usb/usb_device_uac/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# ChangeLog
22

3+
## v1.2.0 (2025-3-31)
4+
5+
* Supports integration into other TinyUSB projects.
6+
37
## v1.1.0 (2025-1-15)
48

59
* Use espressif/tinyusb: 0.17.2

components/usb/usb_device_uac/CMakeLists.txt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ idf_component_register(SRCS usb_device_uac.c
22
INCLUDE_DIRS "include"
33
PRIV_REQUIRES usb esp_timer)
44

5+
if(NOT CONFIG_USB_DEVICE_UAC_AS_PART)
6+
# Determine whether tinyusb is fetched from component registry or from local path
7+
idf_build_get_property(build_components BUILD_COMPONENTS)
8+
if(tinyusb IN_LIST build_components)
9+
set(tinyusb_name tinyusb) # Local component
10+
else()
11+
set(tinyusb_name espressif__tinyusb) # Managed component
12+
endif()
513

6-
# Determine whether tinyusb is fetched from component registry or from local path
7-
idf_build_get_property(build_components BUILD_COMPONENTS)
8-
if(tinyusb IN_LIST build_components)
9-
set(tinyusb_name tinyusb) # Local component
10-
else()
11-
set(tinyusb_name espressif__tinyusb) # Managed component
14+
idf_component_get_property(tusb_lib ${tinyusb_name} COMPONENT_LIB)
15+
target_include_directories(${tusb_lib} PUBLIC "${COMPONENT_DIR}/tusb" "${COMPONENT_DIR}/tusb_uac")
16+
target_sources(${tusb_lib} PUBLIC "${COMPONENT_DIR}/tusb/usb_descriptors.c")
1217
endif()
1318

14-
idf_component_get_property(tusb_lib ${tinyusb_name} COMPONENT_LIB)
15-
target_include_directories(${tusb_lib} PUBLIC "${COMPONENT_DIR}/tusb")
16-
target_sources(${tusb_lib} PUBLIC "${COMPONENT_DIR}/tusb/usb_descriptors.c")
17-
1819
include(package_manager)
1920
cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR})

components/usb/usb_device_uac/Kconfig

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
menu "USB Device UAC Configuration"
22

3-
config TUSB_VID
4-
hex "USB Device VID"
5-
default 0x303A
6-
7-
config TUSB_PID
8-
hex "USB Device PID"
9-
default 0x8000
10-
11-
config TUSB_MANUFACTURER
12-
string "USB Device Manufacture"
13-
default "Espressif"
14-
15-
config TUSB_PRODUCT
16-
string "Product Name"
17-
default "ESP UAC Device"
18-
19-
config TUSB_SERIAL_NUM
20-
string "Product ID"
21-
default "12345678"
22-
23-
choice TINYUSB_RHPORT
24-
prompt "TinyUSB Root Port"
25-
default TINYUSB_RHPORT_HS if IDF_TARGET_ESP32P4
26-
default TINYUSB_RHPORT_FS
27-
help
28-
Allows set the USB PHY Controller for TinyUSB: HS (USB OTG2.0 PHY for HighSpeed)
29-
30-
config TINYUSB_RHPORT_HS
31-
depends on IDF_TARGET_ESP32P4
32-
bool "High Speed"
33-
34-
config TINYUSB_RHPORT_FS
35-
bool "Full Speed"
36-
endchoice
3+
if !USB_DEVICE_UAC_AS_PART
4+
config UAC_TUSB_VID
5+
hex "USB Device VID"
6+
default 0x303A
7+
8+
config UAC_TUSB_PID
9+
hex "USB Device PID"
10+
default 0x8000
11+
12+
config UAC_TUSB_MANUFACTURER
13+
string "USB Device Manufacture"
14+
default "Espressif"
15+
16+
config UAC_TUSB_PRODUCT
17+
string "Product Name"
18+
default "ESP UAC Device"
19+
20+
config UAC_TUSB_SERIAL_NUM
21+
string "Product ID"
22+
default "12345678"
23+
24+
choice TINYUSB_RHPORT
25+
prompt "TinyUSB Root Port"
26+
default TINYUSB_RHPORT_HS if IDF_TARGET_ESP32P4
27+
default TINYUSB_RHPORT_FS
28+
help
29+
Allows set the USB PHY Controller for TinyUSB: HS (USB OTG2.0 PHY for HighSpeed)
30+
31+
config TINYUSB_RHPORT_HS
32+
depends on IDF_TARGET_ESP32P4
33+
bool "High Speed"
34+
35+
config TINYUSB_RHPORT_FS
36+
bool "Full Speed"
37+
endchoice
38+
endif
3739

3840
# Insert UAC config
3941
orsource "./Kconfig.uac"

components/usb/usb_device_uac/Kconfig.uac

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
menu "USB Device UAC"
22

3+
config USB_DEVICE_UAC_AS_PART
4+
bool "Using customer tinyusb configs and descriptors"
5+
default n
6+
help
7+
If enable this feature, will need to write the `tusb_config.h` and `usb_descriptors.c` files in the project.
8+
39
config UAC_SPEAKER_CHANNEL_NUM
410
int "UAC Speaker channel number"
511
range 0 8

components/usb/usb_device_uac/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "1.1.0"
1+
version: "1.2.0"
22
targets:
33
- esp32s2
44
- esp32s3

components/usb/usb_device_uac/include/usb_device_uac.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ typedef struct {
3030
uac_set_mute_cb_t set_mute_cb; /*!< callback function for set mute, if NULL, the set mute request will be ignored */
3131
uac_set_volume_cb_t set_volume_cb; /*!< callback function for set volume, if NULL, the set volume request will be ignored */
3232
void *cb_ctx; /*!< callback context, for user specific usage */
33+
#if CONFIG_USB_DEVICE_UAC_AS_PART
34+
int spk_itf_num; /*!< If CONFIG_USB_DEVICE_UAC_AS_PART is enabled, you need to provide the speaker interface number */
35+
int mic_itf_num; /*!< If CONFIG_USB_DEVICE_UAC_AS_PART is enabled, you need to provide the mic interface number */
36+
#endif
3337
} uac_device_config_t;
3438

3539
/**

components/usb/usb_device_uac/tusb/usb_descriptors.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ tusb_desc_device_t const desc_device = {
4242
.bDeviceProtocol = MISC_PROTOCOL_IAD,
4343
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
4444

45-
.idVendor = CONFIG_TUSB_VID,
46-
.idProduct = CONFIG_TUSB_PID,
45+
.idVendor = CONFIG_UAC_TUSB_VID,
46+
.idProduct = CONFIG_UAC_TUSB_PID,
4747
.bcdDevice = 0x0100,
4848

4949
.iManufacturer = 0x01,
@@ -91,9 +91,9 @@ uint8_t const *tud_descriptor_configuration_cb(uint8_t index)
9191
// array of pointer to string descriptors
9292
char const *string_desc_arr [] = {
9393
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
94-
CONFIG_TUSB_MANUFACTURER, // 1: Manufacturer
95-
CONFIG_TUSB_PRODUCT, // 2: Product
96-
CONFIG_TUSB_SERIAL_NUM, // 3: Serials, should use chip ID
94+
CONFIG_UAC_TUSB_MANUFACTURER, // 1: Manufacturer
95+
CONFIG_UAC_TUSB_PRODUCT, // 2: Product
96+
CONFIG_UAC_TUSB_SERIAL_NUM, // 3: Serials, should use chip ID
9797
"usb uac", // 4: UAC control Interface
9898
#if SPEAK_CHANNEL_NUM
9999
"speaker", // 5: Speak Interface

components/usb/usb_device_uac/tusb/uac_descriptors.h renamed to components/usb/usb_device_uac/tusb_uac/uac_descriptors.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ extern "C" {
3030
#endif
3131

3232
#include "uac_config.h"
33+
#include "sdkconfig.h"
3334

35+
#if !CONFIG_USB_DEVICE_UAC_AS_PART
3436
enum {
3537
ITF_NUM_AUDIO_CONTROL = 0,
3638
#if SPEAK_CHANNEL_NUM
@@ -41,6 +43,7 @@ enum {
4143
#endif // MIC_CHANNEL_NUM
4244
ITF_NUM_TOTAL
4345
};
46+
#endif
4447

4548
// Unit numbers are arbitrary selected
4649
#define UAC2_ENTITY_CLOCK 0x04

0 commit comments

Comments
 (0)