Skip to content

Commit c880bff

Browse files
committed
Merge branch 'change/usb_device_local_tinyusb_component_usage' into 'master'
change(usb_device): Added possibility to use local tinyusb component during the build See merge request ae_group/esp-iot-solution!1124
2 parents 884edf3 + d90a900 commit c880bff

File tree

8 files changed

+42
-23
lines changed

8 files changed

+42
-23
lines changed

.gitlab/ci/build.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,6 @@ build_example_usb_device_usb_hid_device:
765765
- .rules:build:example_usb_device_usb_hid_device
766766
parallel:
767767
matrix:
768-
- IMAGE: espressif/idf:release-v4.4
769768
- IMAGE: espressif/idf:release-v5.0
770769
variables:
771770
EXAMPLE_DIR: examples/usb/device/usb_hid_device
@@ -795,7 +794,6 @@ build_example_usb_device_usb_surface_dial:
795794
- .rules:build:example_usb_device_usb_surface_dial
796795
parallel:
797796
matrix:
798-
- IMAGE: espressif/idf:release-v4.4
799797
- IMAGE: espressif/idf:release-v5.0
800798
variables:
801799
EXAMPLE_DIR: examples/usb/device/usb_surface_dial

examples/usb/device/usb_hid_device/hid_device/tusb_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ extern "C" {
5959
#define CFG_TUSB_OS OPT_OS_FREERTOS
6060
#endif
6161

62+
#ifndef ESP_PLATFORM
63+
#define ESP_PLATFORM 1
64+
#endif
65+
6266
// Espressif IDF requires "freertos/" prefix in include path
6367
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
6468
#define CFG_TUSB_OS_INC_PATH freertos/

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
idf_component_register(
2-
SRCS "../hid_device/usb_descriptors.c" "tinyusb_hid.c" "usb_hid_device_main.c"
3-
INCLUDE_DIRS "../hid_device"
2+
SRCS "tinyusb_hid.c" "usb_hid_device_main.c"
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+
set(tinyusb_name espressif__tinyusb) # Managed component
1013
endif()
1114

15+
# Pass tusb_config.h to the example
16+
idf_component_get_property(tusb_lib ${tinyusb_name} COMPONENT_LIB)
17+
target_include_directories(${tusb_lib} PUBLIC "../hid_device")
18+
target_sources(${tusb_lib} PUBLIC "../hid_device/usb_descriptors.c")
19+
1220
cmake_policy(SET CMP0079 NEW)
13-
target_link_libraries(${tusb_lib} PRIVATE ${COMPONENT_LIB})

examples/usb/device/usb_hid_device/main/idf_component.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
dependencies:
2-
idf: ">=4.4"
2+
idf: ">=5.0"
33
espressif/button:
44
version: "~2.5.0"
55
espressif/tinyusb:
66
version: ">=0.15.0~2"
7-
rules:
8-
- if: "idf_version >=5.0"
9-
leeebo/tinyusb_src:
10-
version: ">=0.15.0~6"
11-
rules:
12-
- if: "idf_version >=4.4,<5.0"
137
espressif/esp32_s3_usb_otg:
148
version: "^1.5.1"
159
rules:

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
idf_component_register(
2-
SRCS "main.c" "usb_descriptors.c"
2+
SRCS "main.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+
set(tinyusb_name espressif__tinyusb) # Managed component
13+
endif()
14+
15+
# Pass tusb_config.h to the example
16+
idf_component_get_property(tusb_lib ${tinyusb_name} COMPONENT_LIB)
17+
target_include_directories(${tusb_lib} PUBLIC ".")
18+
target_sources(${tusb_lib} PUBLIC "./usb_descriptors.c")
19+
720
cmake_policy(SET CMP0079 NEW)
8-
target_link_libraries(${tusb_lib} PRIVATE ${COMPONENT_LIB})

examples/usb/device/usb_surface_dial/main/idf_component.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
dependencies:
33
## Required IDF version
44
idf:
5-
version: ">=4.4.0"
5+
version: ">=5.0"
66
espressif/button:
77
version: ">=2.3.0"
88
override_path: "../../../../../components/button"
9-
leeebo/tinyusb_src:
10-
version: ">=0.0.4"
9+
espressif/tinyusb:
10+
version: ">=0.15.0~2"
1111
espressif/knob:
1212
version: ">=0.1.0"
1313
override_path: "../../../../../components/knob"

examples/usb/device/usb_surface_dial/main/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ static void _button_press_up_cb(void *arg, void *data)
7373

7474
static void _knob_right_cb(void *arg, void *data)
7575
{
76-
ESP_LOGI(TAG, "KONB: KONB_RIGHT,count_value:%"PRId32"", iot_knob_get_count_value((button_handle_t)arg));
76+
ESP_LOGI(TAG, "KONB: KONB_RIGHT,count_value:%d", iot_knob_get_count_value((button_handle_t)arg));
7777
surface_dial_report(DIAL_L);
7878
}
7979

8080
static void _knob_left_cb(void *arg, void *data)
8181
{
82-
ESP_LOGI(TAG, "KONB: KONB_LEFT,count_value:%"PRId32"", iot_knob_get_count_value((button_handle_t)arg));
82+
ESP_LOGI(TAG, "KONB: KONB_LEFT,count_value:%d", iot_knob_get_count_value((button_handle_t)arg));
8383
surface_dial_report(DIAL_R);
8484
}
8585

examples/usb/device/usb_surface_dial/main/tusb_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ extern "C" {
5959
#define CFG_TUSB_OS OPT_OS_FREERTOS
6060
#endif
6161

62+
#ifndef ESP_PLATFORM
63+
#define ESP_PLATFORM 1
64+
#endif
65+
6266
// Espressif IDF requires "freertos/" prefix in include path
6367
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
6468
#define CFG_TUSB_OS_INC_PATH freertos/

0 commit comments

Comments
 (0)