From 7b4cd55d97e3d59aac1eb8b5f58427f24ae97cf5 Mon Sep 17 00:00:00 2001 From: Jakob Hasse Date: Fri, 10 Nov 2023 11:49:23 +0800 Subject: [PATCH] refactor(ci): removed unnecessary hal and soc mock header files --- components/esp_rom/CMakeLists.txt | 1 - .../soc/linux/include/soc/Kconfig.soc_caps.in | 8 +++ .../soc/linux/include/soc/clk_tree_defs.h | 27 ++++++++ components/soc/linux/include/soc/gpio_pins.h | 9 +++ components/soc/linux/include/soc/soc_caps.h | 11 +++- tools/mocks/driver/CMakeLists.txt | 9 ++- tools/mocks/hal/include/hal/i2c_types.h | 63 ------------------- tools/mocks/hal/include/hal/rmt_types.h | 31 --------- tools/mocks/hal/include/hal/spi_types.h | 34 ---------- tools/mocks/soc/include/soc/clk_tree_defs.h | 19 ------ tools/mocks/soc/include/soc/gpio_pins.h | 9 --- .../driver_mock/main/driver_mock_main.c | 38 ++++++++++- 12 files changed, 95 insertions(+), 164 deletions(-) create mode 100644 components/soc/linux/include/soc/clk_tree_defs.h create mode 100644 components/soc/linux/include/soc/gpio_pins.h delete mode 100644 tools/mocks/hal/include/hal/i2c_types.h delete mode 100644 tools/mocks/hal/include/hal/rmt_types.h delete mode 100644 tools/mocks/hal/include/hal/spi_types.h delete mode 100644 tools/mocks/soc/include/soc/clk_tree_defs.h delete mode 100644 tools/mocks/soc/include/soc/gpio_pins.h diff --git a/components/esp_rom/CMakeLists.txt b/components/esp_rom/CMakeLists.txt index 0701edc6c8..7775cde4a6 100644 --- a/components/esp_rom/CMakeLists.txt +++ b/components/esp_rom/CMakeLists.txt @@ -11,7 +11,6 @@ if(target STREQUAL "linux") "${target}/esp_rom_crc.c" "${target}/esp_rom_md5.c" "${target}/esp_rom_efuse.c") - list(APPEND include_dirs "${IDF_PATH}/tools/mocks/soc/include") else() list(APPEND include_dirs "${target}") list(APPEND sources "patches/esp_rom_crc.c" diff --git a/components/soc/linux/include/soc/Kconfig.soc_caps.in b/components/soc/linux/include/soc/Kconfig.soc_caps.in index dc7c432ae4..a4bd226159 100644 --- a/components/soc/linux/include/soc/Kconfig.soc_caps.in +++ b/components/soc/linux/include/soc/Kconfig.soc_caps.in @@ -10,3 +10,11 @@ config SOC_GPIO_IN_RANGE_MAX config SOC_GPIO_OUT_RANGE_MAX int default 65535 + +config SOC_I2C_SUPPORT_SLAVE + bool + default y + +config SOC_I2C_SUPPORT_10BIT_ADDR + bool + default y diff --git a/components/soc/linux/include/soc/clk_tree_defs.h b/components/soc/linux/include/soc/clk_tree_defs.h new file mode 100644 index 0000000000..a3accf30b5 --- /dev/null +++ b/components/soc/linux/include/soc/clk_tree_defs.h @@ -0,0 +1,27 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#pragma once + +/** + * Mock definitions for running on the host. + */ + +/** + * @brief Supported clock sources for modules (CPU, peripherals, RTC, etc.) + * + * @note enum starts from 1, to save 0 for special purpose + */ +typedef enum { + SOC_MOD_CLK_APB = 1, +} soc_module_clk_t; + +/** + * @brief Type of SPI clock source. + */ +typedef enum { + SPI_CLK_SRC_DEFAULT = SOC_MOD_CLK_APB, + SPI_CLK_SRC_APB = SOC_MOD_CLK_APB, +} soc_periph_spi_clk_src_t; diff --git a/components/soc/linux/include/soc/gpio_pins.h b/components/soc/linux/include/soc/gpio_pins.h new file mode 100644 index 0000000000..59894c0862 --- /dev/null +++ b/components/soc/linux/include/soc/gpio_pins.h @@ -0,0 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * NOTE: this is a stripped-down copy to support building on host when using mocking (CMock). + */ diff --git a/components/soc/linux/include/soc/soc_caps.h b/components/soc/linux/include/soc/soc_caps.h index 8659f9e7fa..521b1b6d96 100644 --- a/components/soc/linux/include/soc/soc_caps.h +++ b/components/soc/linux/include/soc/soc_caps.h @@ -22,8 +22,17 @@ * */ +/* + * NOTE: These definitions are only meant to allow host-based unit testing of some features using CMock. + * They DO NOT imply any functionality on the host. + */ + #pragma once -// No meaning to define GPIO number for Linux target, only to avoid build warning on Kconfig ESP_CONSOLE_UART_TX_GPIO, ESP_CONSOLE_UART_RX_GPIO +/*-------------------------- GPIO CAPS ---------------------------------------*/ #define SOC_GPIO_IN_RANGE_MAX (65535) #define SOC_GPIO_OUT_RANGE_MAX (65535) + +/*-------------------------- I2C CAPS ----------------------------------------*/ +#define SOC_I2C_SUPPORT_SLAVE (1) +#define SOC_I2C_SUPPORT_10BIT_ADDR (1) diff --git a/tools/mocks/driver/CMakeLists.txt b/tools/mocks/driver/CMakeLists.txt index f591918734..75a81606af 100644 --- a/tools/mocks/driver/CMakeLists.txt +++ b/tools/mocks/driver/CMakeLists.txt @@ -14,11 +14,12 @@ set(include_dirs "${original_driver_dir}/usb_serial_jtag/include/driver" "${original_driver_dir}/i2c/include" "${original_driver_dir}/rmt/include" - "${original_driver_dir}/usb_serial_jtag/include" - "${CMAKE_CURRENT_SOURCE_DIR}/../hal/include") + "${original_driver_dir}/usb_serial_jtag/include") +# Note: "hal" and "soc" are only required for corresponding header files and their definitions +# here, they don't provide functionality when built for running on the host. idf_component_mock(INCLUDE_DIRS ${include_dirs} - REQUIRES freertos + REQUIRES freertos hal soc MOCK_HEADER_FILES ${IDF_PATH}/components/esp_driver_gpio/include/driver/gpio.h ${IDF_PATH}/components/esp_driver_spi/include/driver/spi_master.h @@ -29,5 +30,3 @@ idf_component_mock(INCLUDE_DIRS ${include_dirs} ${original_driver_dir}/rmt/include/driver/rmt_common.h ${original_driver_dir}/rmt/include/driver/rmt_encoder.h ${original_driver_dir}/usb_serial_jtag/include/driver/usb_serial_jtag.h) - -target_compile_definitions(${COMPONENT_LIB} PUBLIC SOC_I2C_NUM=2) diff --git a/tools/mocks/hal/include/hal/i2c_types.h b/tools/mocks/hal/include/hal/i2c_types.h deleted file mode 100644 index ad76ed43e7..0000000000 --- a/tools/mocks/hal/include/hal/i2c_types.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * NOTE: this is not the original header file from the hal component. It is a stripped-down copy to support mocking. - */ - -#pragma once - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief I2C port number, can be I2C_NUM_0 ~ (I2C_NUM_MAX-1). - */ -typedef enum { - I2C_NUM_0 = 0, /*!< I2C port 0 */ -#if SOC_I2C_NUM >= 2 - I2C_NUM_1, /*!< I2C port 1 */ -#endif - I2C_NUM_MAX, /*!< I2C port max */ -} i2c_port_t; - -typedef enum{ - I2C_MODE_SLAVE = 0, /*!< I2C slave mode */ - I2C_MODE_MASTER, /*!< I2C master mode */ - I2C_MODE_MAX, -} i2c_mode_t; - -typedef enum { - I2C_MASTER_WRITE = 0, /*!< I2C write data */ - I2C_MASTER_READ, /*!< I2C read data */ -} i2c_rw_t; - -typedef enum { - I2C_DATA_MODE_MSB_FIRST = 0, /*!< I2C data msb first */ - I2C_DATA_MODE_LSB_FIRST = 1, /*!< I2C data lsb first */ - I2C_DATA_MODE_MAX -} i2c_trans_mode_t; - -typedef enum { - I2C_ADDR_BIT_7 = 0, /*!< I2C 7bit address for slave mode */ - I2C_ADDR_BIT_10, /*!< I2C 10bit address for slave mode */ - I2C_ADDR_BIT_MAX, -} i2c_addr_mode_t; - -typedef enum { - I2C_MASTER_ACK = 0x0, /*!< I2C ack for each byte read */ - I2C_MASTER_NACK = 0x1, /*!< I2C nack for each byte read */ - I2C_MASTER_LAST_NACK = 0x2, /*!< I2C nack for the last byte*/ - I2C_MASTER_ACK_MAX, -} i2c_ack_type_t; - -#ifdef __cplusplus -} -#endif diff --git a/tools/mocks/hal/include/hal/rmt_types.h b/tools/mocks/hal/include/hal/rmt_types.h deleted file mode 100644 index 12df5fa1c8..0000000000 --- a/tools/mocks/hal/include/hal/rmt_types.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * NOTE: this is not the original header file from the hal component. It is a stripped-down copy to support mocking. - */ - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -typedef int rmt_clock_source_t; - -typedef union { - struct { - unsigned int duration0 : 15; /*!< Duration of level0 */ - unsigned int level0 : 1; /*!< Level of the first part */ - unsigned int duration1 : 15; /*!< Duration of level1 */ - unsigned int level1 : 1; /*!< Level of the second part */ - }; - unsigned int val; /*!< Equivalent unsigned value for the RMT symbol */ -} rmt_symbol_word_t; - -#ifdef __cplusplus -} -#endif diff --git a/tools/mocks/hal/include/hal/spi_types.h b/tools/mocks/hal/include/hal/spi_types.h deleted file mode 100644 index 42b59406f7..0000000000 --- a/tools/mocks/hal/include/hal/spi_types.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * NOTE: this is not the original header file from the hal component. It is a stripped-down copy to support mocking. - */ - -#pragma once - -/** - * @brief Enum with the three SPI peripherals that are software-accessible in it - */ -typedef enum { -// SPI_HOST (SPI1_HOST) is not supported by the SPI Master and SPI Slave driver on ESP32-S2 - SPI1_HOST=0, ///< SPI1 - SPI2_HOST=1, ///< SPI2 - SPI3_HOST=2, ///< SPI3 - SPI_HOST_MAX=3, ///< invalid host value -} spi_host_device_t; - -/** - * @brief Type of SPI clock source. - */ -typedef enum { - SPI_CLK_SRC_DEFAULT, /*!< Select PLL as SPI source clock */ - SPI_CLK_SRC_PLL_F40M, /*!< Select PLL as SPI source clock */ - SPI_CLK_SRC_PLL_F80M, /*!< Select PLL as SPI source clock */ - SPI_CLK_SRC_APB, /*!< Select APB as SPI source clock */ - SPI_CLK_SRC_XTAL, /*!< Select XTAL as SPI source clock */ - SPI_CLK_SRC_RC_FAST, /*!< Select RC_FAST as SPI source clock */ -} spi_clock_source_t; diff --git a/tools/mocks/soc/include/soc/clk_tree_defs.h b/tools/mocks/soc/include/soc/clk_tree_defs.h deleted file mode 100644 index ac56598a4b..0000000000 --- a/tools/mocks/soc/include/soc/clk_tree_defs.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Type of SPI clock source. - */ -typedef int soc_periph_spi_clk_src_t; - -#ifdef __cplusplus -} -#endif diff --git a/tools/mocks/soc/include/soc/gpio_pins.h b/tools/mocks/soc/include/soc/gpio_pins.h deleted file mode 100644 index f2a0497086..0000000000 --- a/tools/mocks/soc/include/soc/gpio_pins.h +++ /dev/null @@ -1,9 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * NOTE: this is not the original header file from the soc component. It is a stripped-down copy to support mocking. - */ diff --git a/tools/test_apps/linux_compatible/driver_mock/main/driver_mock_main.c b/tools/test_apps/linux_compatible/driver_mock/main/driver_mock_main.c index f36d705f89..8c47f3016c 100644 --- a/tools/test_apps/linux_compatible/driver_mock/main/driver_mock_main.c +++ b/tools/test_apps/linux_compatible/driver_mock/main/driver_mock_main.c @@ -17,7 +17,7 @@ #include "Mockrmt_tx.h" #include "Mockrmt_rx.h" -/*Test that mock functions exist*/ +/* Test that mock functions exist and that required definitions are available */ void app_main(void) { i2c_driver_delete(0); @@ -26,6 +26,42 @@ void app_main(void) int gpio_num = GPIO_NUM_39; (void)gpio_num; + spi_host_device_t spi_dev = SPI1_HOST; + spi_dev = SPI2_HOST; + (void)spi_dev; + spi_clock_source_t spi_default_clock = SPI_CLK_SRC_DEFAULT; + (void)spi_default_clock; + soc_periph_spi_clk_src_t soc_periph_spi_clk_src = 0; + (void)soc_periph_spi_clk_src; + + rmt_clock_source_t rmt_clk_source = 0; + (void)rmt_clk_source; + rmt_symbol_word_t rm_symbol_word = { .duration0 = 47, .level0 = 0, .duration1 = 47, .level1 = 1 }; + (void)rm_symbol_word; + + i2c_port_t i2c_port = I2C_NUM_0; + (void)i2c_port; + i2c_mode_t i2c_mode = I2C_MODE_MASTER; + i2c_mode = I2C_MODE_SLAVE; + (void)i2c_mode; + i2c_rw_t i2c_rw = I2C_MASTER_WRITE; + i2c_rw = I2C_MASTER_READ; + (void)i2c_rw; + i2c_trans_mode_t i2c = I2C_DATA_MODE_MSB_FIRST; + i2c = I2C_DATA_MODE_LSB_FIRST; + (void)i2c; + i2c_addr_bit_len_t i2c_addr_bit_len = I2C_ADDR_BIT_LEN_7; + + #if SOC_I2C_SUPPORT_10BIT_ADDR + i2c_addr_bit_len = I2C_ADDR_BIT_LEN_10; + #endif + + (void)i2c_addr_bit_len; + i2c_ack_type_t i2c_ack = I2C_MASTER_ACK; + i2c_ack = I2C_MASTER_NACK; + i2c_ack = I2C_MASTER_LAST_NACK; + (void)i2c_ack; + rmt_channel_handle_t channel = 0; rmt_new_bytes_encoder(NULL, NULL); rmt_new_rx_channel(NULL, NULL);