diff --git a/components/usb/usb_helpers.c b/components/usb/usb_helpers.c index 08c50e3b87..b4a00505e1 100644 --- a/components/usb/usb_helpers.c +++ b/components/usb/usb_helpers.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -27,7 +27,7 @@ const usb_standard_desc_t *usb_parse_next_descriptor(const usb_standard_desc_t * return NULL; // Next descriptor is out of bounds } // Return the next descriptor, update offset - const usb_standard_desc_t *ret_desc = (const usb_standard_desc_t *)(((uint32_t)cur_desc) + cur_desc->bLength); + const usb_standard_desc_t *ret_desc = (const usb_standard_desc_t *)(((uintptr_t)cur_desc) + cur_desc->bLength); *offset += cur_desc->bLength; return ret_desc; } diff --git a/tools/mocks/usb/CMakeLists.txt b/tools/mocks/usb/CMakeLists.txt new file mode 100644 index 0000000000..2ae39ff7b5 --- /dev/null +++ b/tools/mocks/usb/CMakeLists.txt @@ -0,0 +1,18 @@ +# NOTE: This kind of mocking currently works on Linux targets only. +# On Espressif chips, too many dependencies are missing at the moment. +message(STATUS "building USB HOST MOCKS") + +idf_component_get_property(original_usb_dir usb COMPONENT_OVERRIDEN_DIR) + +idf_component_mock(INCLUDE_DIRS "${original_usb_dir}/include" + "${original_usb_dir}/include/esp_private" + "${original_usb_dir}/include/usb" + "${original_usb_dir}/private_include" + MOCK_HEADER_FILES ${original_usb_dir}/include/usb/usb_host.h + ${original_usb_dir}/include/esp_private/usb_phy.h + REQUIRES freertos) + + +# We do not mock usb_helpers. We use the original implementation. +# This way, we can test Class drivers descriptor parsing +target_sources(${COMPONENT_LIB} PRIVATE "${original_usb_dir}/usb_helpers.c") diff --git a/tools/mocks/usb/mock/mock_config.yaml b/tools/mocks/usb/mock/mock_config.yaml new file mode 100644 index 0000000000..bbca5f4e3c --- /dev/null +++ b/tools/mocks/usb/mock/mock_config.yaml @@ -0,0 +1,7 @@ +:cmock: + :plugins: + - expect + - expect_any_args + - return_thru_ptr + - ignore + - ignore_arg