Skip to content

Commit

Permalink
Merge branch 'change/usb_device_local_tinyusb_component_usage' into '…
Browse files Browse the repository at this point in the history
…master'

change(usb_device): Added possibility to use local tinyusb component during the build

See merge request ae_group/esp-iot-solution!1124
  • Loading branch information
lijunru-hub committed Jan 20, 2025
2 parents 884edf3 + d90a900 commit c880bff
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 23 deletions.
2 changes: 0 additions & 2 deletions .gitlab/ci/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions examples/usb/device/usb_hid_device/hid_device/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
19 changes: 13 additions & 6 deletions examples/usb/device/usb_hid_device/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
idf_component_register(
SRCS "../hid_device/usb_descriptors.c" "tinyusb_hid.c" "usb_hid_device_main.c"
INCLUDE_DIRS "../hid_device"
SRCS "tinyusb_hid.c" "usb_hid_device_main.c"
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)
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} PUBLIC "../hid_device")
target_sources(${tusb_lib} PUBLIC "../hid_device/usb_descriptors.c")

cmake_policy(SET CMP0079 NEW)
target_link_libraries(${tusb_lib} PRIVATE ${COMPONENT_LIB})
8 changes: 1 addition & 7 deletions examples/usb/device/usb_hid_device/main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
18 changes: 15 additions & 3 deletions examples/usb/device/usb_surface_dial/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
idf_component_register(
SRCS "main.c" "usb_descriptors.c"
SRCS "main.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()
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} PUBLIC ".")
target_sources(${tusb_lib} PUBLIC "./usb_descriptors.c")

cmake_policy(SET CMP0079 NEW)
target_link_libraries(${tusb_lib} PRIVATE ${COMPONENT_LIB})
6 changes: 3 additions & 3 deletions examples/usb/device/usb_surface_dial/main/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions examples/usb/device/usb_surface_dial/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 4 additions & 0 deletions examples/usb/device/usb_surface_dial/main/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down

0 comments on commit c880bff

Please sign in to comment.