From f65bb2129da83054ad3c7c4a22986b2300ee200d Mon Sep 17 00:00:00 2001 From: Roman Leonov Date: Mon, 13 Jan 2025 12:45:11 +0100 Subject: [PATCH 1/2] change(usb_hid_device, usb_surface_dial): Added possibility to use local tinyusb component --- .../device/usb_hid_device/main/CMakeLists.txt | 21 ++++++++++++++----- .../usb_surface_dial/main/CMakeLists.txt | 20 ++++++++++++++++-- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/examples/usb/device/usb_hid_device/main/CMakeLists.txt b/examples/usb/device/usb_hid_device/main/CMakeLists.txt index abad87f35..2c08b2204 100644 --- a/examples/usb/device/usb_hid_device/main/CMakeLists.txt +++ b/examples/usb/device/usb_hid_device/main/CMakeLists.txt @@ -1,13 +1,24 @@ idf_component_register( SRCS "../hid_device/usb_descriptors.c" "tinyusb_hid.c" "usb_hid_device_main.c" - INCLUDE_DIRS "../hid_device" + INCLUDE_DIRS "." + PRIV_INCLUDE_DIRS "../hid_device" ) -if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0") -idf_component_get_property(tusb_lib espressif__tinyusb COMPONENT_LIB) +# Determine whether tinyusb is fetched from component registry or from local path +idf_build_get_property(build_components BUILD_COMPONENTS) +if(tinyusb IN_LIST build_components) + set(tinyusb_name tinyusb) # Local component else() -idf_component_get_property(tusb_lib leeebo__tinyusb_src COMPONENT_LIB) + if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0") + set(tinyusb_name espressif__tinyusb) # Managed component + else () + set(tinyusb_name leeebo__tinyusb_src) # Managed component + endif() endif() +# Pass tusb_config.h to the example +idf_component_get_property(tusb_lib ${tinyusb_name} COMPONENT_LIB) +target_include_directories(${tusb_lib} INTERFACE "../hid_device") +target_link_libraries(${tusb_lib} INTERFACE ${COMPONENT_LIB}) + cmake_policy(SET CMP0079 NEW) -target_link_libraries(${tusb_lib} PRIVATE ${COMPONENT_LIB}) diff --git a/examples/usb/device/usb_surface_dial/main/CMakeLists.txt b/examples/usb/device/usb_surface_dial/main/CMakeLists.txt index 45415b70b..985b30e06 100644 --- a/examples/usb/device/usb_surface_dial/main/CMakeLists.txt +++ b/examples/usb/device/usb_surface_dial/main/CMakeLists.txt @@ -1,8 +1,24 @@ idf_component_register( SRCS "main.c" "usb_descriptors.c" INCLUDE_DIRS "." + PRIV_INCLUDE_DIRS "." ) -idf_component_get_property(tusb_lib leeebo__tinyusb_src COMPONENT_LIB) +# Determine whether tinyusb is fetched from component registry or from local path +idf_build_get_property(build_components BUILD_COMPONENTS) +if(tinyusb IN_LIST build_components) + set(tinyusb_name tinyusb) # Local component +else() + if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0") + set(tinyusb_name espressif__tinyusb) # Managed component + else () + set(tinyusb_name leeebo__tinyusb_src) # Managed component + endif() +endif() + +# Pass tusb_config.h to the example +idf_component_get_property(tusb_lib ${tinyusb_name} COMPONENT_LIB) +target_include_directories(${tusb_lib} INTERFACE ".") +target_link_libraries(${tusb_lib} INTERFACE ${COMPONENT_LIB}) + cmake_policy(SET CMP0079 NEW) -target_link_libraries(${tusb_lib} PRIVATE ${COMPONENT_LIB}) From d90a900836f499ba21ff9500c0bb5efe79b0d058 Mon Sep 17 00:00:00 2001 From: Li Junru Date: Fri, 17 Jan 2025 15:21:50 +0800 Subject: [PATCH 2/2] fix(usb_device): make usb device example use 0.17.0 tinyusb --- .gitlab/ci/build.yml | 2 -- .../device/usb_hid_device/hid_device/tusb_config.h | 4 ++++ .../usb/device/usb_hid_device/main/CMakeLists.txt | 12 ++++-------- .../usb/device/usb_hid_device/main/idf_component.yml | 8 +------- .../usb/device/usb_surface_dial/main/CMakeLists.txt | 12 ++++-------- .../device/usb_surface_dial/main/idf_component.yml | 6 +++--- examples/usb/device/usb_surface_dial/main/main.c | 4 ++-- .../usb/device/usb_surface_dial/main/tusb_config.h | 4 ++++ 8 files changed, 22 insertions(+), 30 deletions(-) diff --git a/.gitlab/ci/build.yml b/.gitlab/ci/build.yml index 176af50fc..a96d6ef79 100644 --- a/.gitlab/ci/build.yml +++ b/.gitlab/ci/build.yml @@ -765,7 +765,6 @@ build_example_usb_device_usb_hid_device: - .rules:build:example_usb_device_usb_hid_device parallel: matrix: - - IMAGE: espressif/idf:release-v4.4 - IMAGE: espressif/idf:release-v5.0 variables: EXAMPLE_DIR: examples/usb/device/usb_hid_device @@ -795,7 +794,6 @@ build_example_usb_device_usb_surface_dial: - .rules:build:example_usb_device_usb_surface_dial parallel: matrix: - - IMAGE: espressif/idf:release-v4.4 - IMAGE: espressif/idf:release-v5.0 variables: EXAMPLE_DIR: examples/usb/device/usb_surface_dial diff --git a/examples/usb/device/usb_hid_device/hid_device/tusb_config.h b/examples/usb/device/usb_hid_device/hid_device/tusb_config.h index 19fb9862d..26c71e1c1 100644 --- a/examples/usb/device/usb_hid_device/hid_device/tusb_config.h +++ b/examples/usb/device/usb_hid_device/hid_device/tusb_config.h @@ -59,6 +59,10 @@ extern "C" { #define CFG_TUSB_OS OPT_OS_FREERTOS #endif +#ifndef ESP_PLATFORM +#define ESP_PLATFORM 1 +#endif + // Espressif IDF requires "freertos/" prefix in include path #if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) #define CFG_TUSB_OS_INC_PATH freertos/ diff --git a/examples/usb/device/usb_hid_device/main/CMakeLists.txt b/examples/usb/device/usb_hid_device/main/CMakeLists.txt index 2c08b2204..e0544072c 100644 --- a/examples/usb/device/usb_hid_device/main/CMakeLists.txt +++ b/examples/usb/device/usb_hid_device/main/CMakeLists.txt @@ -1,5 +1,5 @@ idf_component_register( - SRCS "../hid_device/usb_descriptors.c" "tinyusb_hid.c" "usb_hid_device_main.c" + SRCS "tinyusb_hid.c" "usb_hid_device_main.c" INCLUDE_DIRS "." PRIV_INCLUDE_DIRS "../hid_device" ) @@ -9,16 +9,12 @@ idf_build_get_property(build_components BUILD_COMPONENTS) if(tinyusb IN_LIST build_components) set(tinyusb_name tinyusb) # Local component else() - if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0") - set(tinyusb_name espressif__tinyusb) # Managed component - else () - set(tinyusb_name leeebo__tinyusb_src) # Managed component - endif() + set(tinyusb_name espressif__tinyusb) # Managed component endif() # Pass tusb_config.h to the example idf_component_get_property(tusb_lib ${tinyusb_name} COMPONENT_LIB) -target_include_directories(${tusb_lib} INTERFACE "../hid_device") -target_link_libraries(${tusb_lib} INTERFACE ${COMPONENT_LIB}) +target_include_directories(${tusb_lib} PUBLIC "../hid_device") +target_sources(${tusb_lib} PUBLIC "../hid_device/usb_descriptors.c") cmake_policy(SET CMP0079 NEW) diff --git a/examples/usb/device/usb_hid_device/main/idf_component.yml b/examples/usb/device/usb_hid_device/main/idf_component.yml index 83552b7c3..0d0338075 100644 --- a/examples/usb/device/usb_hid_device/main/idf_component.yml +++ b/examples/usb/device/usb_hid_device/main/idf_component.yml @@ -1,15 +1,9 @@ dependencies: - idf: ">=4.4" + idf: ">=5.0" espressif/button: version: "~2.5.0" espressif/tinyusb: version: ">=0.15.0~2" - rules: - - if: "idf_version >=5.0" - leeebo/tinyusb_src: - version: ">=0.15.0~6" - rules: - - if: "idf_version >=4.4,<5.0" espressif/esp32_s3_usb_otg: version: "^1.5.1" rules: diff --git a/examples/usb/device/usb_surface_dial/main/CMakeLists.txt b/examples/usb/device/usb_surface_dial/main/CMakeLists.txt index 985b30e06..f65d5b764 100644 --- a/examples/usb/device/usb_surface_dial/main/CMakeLists.txt +++ b/examples/usb/device/usb_surface_dial/main/CMakeLists.txt @@ -1,5 +1,5 @@ idf_component_register( - SRCS "main.c" "usb_descriptors.c" + SRCS "main.c" INCLUDE_DIRS "." PRIV_INCLUDE_DIRS "." ) @@ -9,16 +9,12 @@ idf_build_get_property(build_components BUILD_COMPONENTS) if(tinyusb IN_LIST build_components) set(tinyusb_name tinyusb) # Local component else() - if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0") - set(tinyusb_name espressif__tinyusb) # Managed component - else () - set(tinyusb_name leeebo__tinyusb_src) # Managed component - endif() + set(tinyusb_name espressif__tinyusb) # Managed component endif() # Pass tusb_config.h to the example idf_component_get_property(tusb_lib ${tinyusb_name} COMPONENT_LIB) -target_include_directories(${tusb_lib} INTERFACE ".") -target_link_libraries(${tusb_lib} INTERFACE ${COMPONENT_LIB}) +target_include_directories(${tusb_lib} PUBLIC ".") +target_sources(${tusb_lib} PUBLIC "./usb_descriptors.c") cmake_policy(SET CMP0079 NEW) diff --git a/examples/usb/device/usb_surface_dial/main/idf_component.yml b/examples/usb/device/usb_surface_dial/main/idf_component.yml index eccca4ec3..8a154df39 100644 --- a/examples/usb/device/usb_surface_dial/main/idf_component.yml +++ b/examples/usb/device/usb_surface_dial/main/idf_component.yml @@ -2,12 +2,12 @@ dependencies: ## Required IDF version idf: - version: ">=4.4.0" + version: ">=5.0" espressif/button: version: ">=2.3.0" override_path: "../../../../../components/button" - leeebo/tinyusb_src: - version: ">=0.0.4" + espressif/tinyusb: + version: ">=0.15.0~2" espressif/knob: version: ">=0.1.0" override_path: "../../../../../components/knob" diff --git a/examples/usb/device/usb_surface_dial/main/main.c b/examples/usb/device/usb_surface_dial/main/main.c index 02d70a9fc..7159eede1 100644 --- a/examples/usb/device/usb_surface_dial/main/main.c +++ b/examples/usb/device/usb_surface_dial/main/main.c @@ -73,13 +73,13 @@ static void _button_press_up_cb(void *arg, void *data) static void _knob_right_cb(void *arg, void *data) { - ESP_LOGI(TAG, "KONB: KONB_RIGHT,count_value:%"PRId32"", iot_knob_get_count_value((button_handle_t)arg)); + ESP_LOGI(TAG, "KONB: KONB_RIGHT,count_value:%d", iot_knob_get_count_value((button_handle_t)arg)); surface_dial_report(DIAL_L); } static void _knob_left_cb(void *arg, void *data) { - ESP_LOGI(TAG, "KONB: KONB_LEFT,count_value:%"PRId32"", iot_knob_get_count_value((button_handle_t)arg)); + ESP_LOGI(TAG, "KONB: KONB_LEFT,count_value:%d", iot_knob_get_count_value((button_handle_t)arg)); surface_dial_report(DIAL_R); } diff --git a/examples/usb/device/usb_surface_dial/main/tusb_config.h b/examples/usb/device/usb_surface_dial/main/tusb_config.h index 26327e3fd..f7d636b96 100644 --- a/examples/usb/device/usb_surface_dial/main/tusb_config.h +++ b/examples/usb/device/usb_surface_dial/main/tusb_config.h @@ -59,6 +59,10 @@ extern "C" { #define CFG_TUSB_OS OPT_OS_FREERTOS #endif +#ifndef ESP_PLATFORM +#define ESP_PLATFORM 1 +#endif + // Espressif IDF requires "freertos/" prefix in include path #if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) #define CFG_TUSB_OS_INC_PATH freertos/