Skip to content

Commit f65bb21

Browse files
committed
change(usb_hid_device, usb_surface_dial): Added possibility to use local tinyusb component
1 parent cf4f5a6 commit f65bb21

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

examples/usb/device/usb_hid_device/main/CMakeLists.txt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
idf_component_register(
22
SRCS "../hid_device/usb_descriptors.c" "tinyusb_hid.c" "usb_hid_device_main.c"
3-
INCLUDE_DIRS "../hid_device"
3+
INCLUDE_DIRS "."
4+
PRIV_INCLUDE_DIRS "../hid_device"
45
)
56

6-
if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0")
7-
idf_component_get_property(tusb_lib espressif__tinyusb COMPONENT_LIB)
7+
# Determine whether tinyusb is fetched from component registry or from local path
8+
idf_build_get_property(build_components BUILD_COMPONENTS)
9+
if(tinyusb IN_LIST build_components)
10+
set(tinyusb_name tinyusb) # Local component
811
else()
9-
idf_component_get_property(tusb_lib leeebo__tinyusb_src COMPONENT_LIB)
12+
if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0")
13+
set(tinyusb_name espressif__tinyusb) # Managed component
14+
else ()
15+
set(tinyusb_name leeebo__tinyusb_src) # Managed component
16+
endif()
1017
endif()
1118

19+
# Pass tusb_config.h to the example
20+
idf_component_get_property(tusb_lib ${tinyusb_name} COMPONENT_LIB)
21+
target_include_directories(${tusb_lib} INTERFACE "../hid_device")
22+
target_link_libraries(${tusb_lib} INTERFACE ${COMPONENT_LIB})
23+
1224
cmake_policy(SET CMP0079 NEW)
13-
target_link_libraries(${tusb_lib} PRIVATE ${COMPONENT_LIB})

examples/usb/device/usb_surface_dial/main/CMakeLists.txt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
idf_component_register(
22
SRCS "main.c" "usb_descriptors.c"
33
INCLUDE_DIRS "."
4+
PRIV_INCLUDE_DIRS "."
45
)
56

6-
idf_component_get_property(tusb_lib leeebo__tinyusb_src COMPONENT_LIB)
7+
# Determine whether tinyusb is fetched from component registry or from local path
8+
idf_build_get_property(build_components BUILD_COMPONENTS)
9+
if(tinyusb IN_LIST build_components)
10+
set(tinyusb_name tinyusb) # Local component
11+
else()
12+
if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0")
13+
set(tinyusb_name espressif__tinyusb) # Managed component
14+
else ()
15+
set(tinyusb_name leeebo__tinyusb_src) # Managed component
16+
endif()
17+
endif()
18+
19+
# Pass tusb_config.h to the example
20+
idf_component_get_property(tusb_lib ${tinyusb_name} COMPONENT_LIB)
21+
target_include_directories(${tusb_lib} INTERFACE ".")
22+
target_link_libraries(${tusb_lib} INTERFACE ${COMPONENT_LIB})
23+
724
cmake_policy(SET CMP0079 NEW)
8-
target_link_libraries(${tusb_lib} PRIVATE ${COMPONENT_LIB})

0 commit comments

Comments
 (0)