From aa107703235a0c3f314baa5121c41d29c367212f Mon Sep 17 00:00:00 2001 From: Cao Sen Miao Date: Tue, 12 Dec 2023 16:46:27 +0800 Subject: [PATCH] refactor(i2c): Make i2c driver as a seperate component --- components/driver/CMakeLists.txt | 12 ++--------- components/driver/Kconfig | 20 ------------------- .../driver/test_apps/.build-test-rules.yml | 10 ++++------ .../test_apps/legacy_i2c_driver/README.md | 4 ++-- .../legacy_i2c_driver/main/test_i2c.c | 5 +++-- components/esp_driver_i2c/CMakeLists.txt | 20 +++++++++++++++++++ components/esp_driver_i2c/Kconfig | 20 +++++++++++++++++++ .../i2c => esp_driver_i2c}/i2c_common.c | 2 -- .../i2c => esp_driver_i2c}/i2c_master.c | 16 +++++++-------- .../i2c => esp_driver_i2c}/i2c_private.h | 0 .../i2c => esp_driver_i2c}/i2c_slave.c | 0 .../include/driver/i2c_master.h | 2 +- .../include/driver/i2c_slave.h | 8 ++++---- .../include/driver/i2c_types.h | 1 - .../{driver/i2c => esp_driver_i2c}/linker.lf | 8 +++++++- .../test_apps/.build-test-rules.yml | 11 ++++++++++ .../test_apps/i2c_test_apps/CMakeLists.txt | 2 +- .../test_apps/i2c_test_apps/README.md | 0 .../i2c_test_apps/main/CMakeLists.txt | 0 .../i2c_test_apps/main/test_app_main.c | 0 .../test_apps/i2c_test_apps/main/test_board.h | 0 .../i2c_test_apps/main/test_i2c_10bit.c | 5 +---- .../i2c_test_apps/main/test_i2c_broadcast.c | 1 - .../i2c_test_apps/main/test_i2c_common.c | 6 +++--- .../i2c_test_apps/main/test_i2c_iram.c | 0 .../i2c_test_apps/main/test_i2c_multi.c | 8 ++------ .../i2c_test_apps/main/test_i2c_ram.c | 6 +----- .../test_apps/i2c_test_apps/pytest_i2c.py | 0 .../i2c_test_apps/sdkconfig.ci.defaults | 0 .../i2c_test_apps/sdkconfig.ci.iram_safe | 0 .../i2c_test_apps/sdkconfig.ci.release | 0 .../i2c_test_apps/sdkconfig.defaults | 0 components/esp_lcd/CMakeLists.txt | 2 +- .../esp_lcd/test_apps/.build-test-rules.yml | 3 +-- components/hal/i2c_hal.c | 6 ++++++ components/hal/i2c_hal_iram.c | 8 +------- components/soc/esp32p4/include/soc/soc_caps.h | 2 +- docs/doxygen/Doxyfile | 6 +++--- docs/en/api-reference/peripherals/i2c.rst | 2 +- .../release-5.x/5.3/peripherals.rst | 1 + .../release-5.x/5.3/peripherals.rst | 1 + examples/peripherals/.build-test-rules.yml | 6 ++++++ 42 files changed, 111 insertions(+), 93 deletions(-) create mode 100644 components/esp_driver_i2c/CMakeLists.txt create mode 100644 components/esp_driver_i2c/Kconfig rename components/{driver/i2c => esp_driver_i2c}/i2c_common.c (99%) rename components/{driver/i2c => esp_driver_i2c}/i2c_master.c (99%) rename components/{driver/i2c => esp_driver_i2c}/i2c_private.h (100%) rename components/{driver/i2c => esp_driver_i2c}/i2c_slave.c (100%) rename components/{driver/i2c => esp_driver_i2c}/include/driver/i2c_master.h (99%) rename components/{driver/i2c => esp_driver_i2c}/include/driver/i2c_slave.h (96%) rename components/{driver/i2c => esp_driver_i2c}/include/driver/i2c_types.h (99%) rename components/{driver/i2c => esp_driver_i2c}/linker.lf (62%) create mode 100644 components/esp_driver_i2c/test_apps/.build-test-rules.yml rename components/{driver => esp_driver_i2c}/test_apps/i2c_test_apps/CMakeLists.txt (88%) rename components/{driver => esp_driver_i2c}/test_apps/i2c_test_apps/README.md (100%) rename components/{driver => esp_driver_i2c}/test_apps/i2c_test_apps/main/CMakeLists.txt (100%) rename components/{driver => esp_driver_i2c}/test_apps/i2c_test_apps/main/test_app_main.c (100%) rename components/{driver => esp_driver_i2c}/test_apps/i2c_test_apps/main/test_board.h (100%) rename components/{driver => esp_driver_i2c}/test_apps/i2c_test_apps/main/test_i2c_10bit.c (99%) rename components/{driver => esp_driver_i2c}/test_apps/i2c_test_apps/main/test_i2c_broadcast.c (99%) rename components/{driver => esp_driver_i2c}/test_apps/i2c_test_apps/main/test_i2c_common.c (97%) rename components/{driver => esp_driver_i2c}/test_apps/i2c_test_apps/main/test_i2c_iram.c (100%) rename components/{driver => esp_driver_i2c}/test_apps/i2c_test_apps/main/test_i2c_multi.c (99%) rename components/{driver => esp_driver_i2c}/test_apps/i2c_test_apps/main/test_i2c_ram.c (99%) rename components/{driver => esp_driver_i2c}/test_apps/i2c_test_apps/pytest_i2c.py (100%) rename components/{driver => esp_driver_i2c}/test_apps/i2c_test_apps/sdkconfig.ci.defaults (100%) rename components/{driver => esp_driver_i2c}/test_apps/i2c_test_apps/sdkconfig.ci.iram_safe (100%) rename components/{driver => esp_driver_i2c}/test_apps/i2c_test_apps/sdkconfig.ci.release (100%) rename components/{driver => esp_driver_i2c}/test_apps/i2c_test_apps/sdkconfig.defaults (100%) diff --git a/components/driver/CMakeLists.txt b/components/driver/CMakeLists.txt index 2d9e3c31ae..116e5b3c9c 100644 --- a/components/driver/CMakeLists.txt +++ b/components/driver/CMakeLists.txt @@ -47,15 +47,7 @@ endif() # I2C related source files if(CONFIG_SOC_I2C_SUPPORTED) - list(APPEND srcs "i2c/i2c.c" - "i2c/i2c_master.c" - "i2c/i2c_common.c" - ) - if(CONFIG_SOC_I2C_SUPPORT_SLAVE) - list(APPEND srcs "i2c/i2c_slave.c") - endif() - - list(APPEND ldfragments "i2c/linker.lf") + list(APPEND srcs "i2c/i2c.c") endif() # I2S related source files @@ -142,7 +134,7 @@ else() # have a public dependency on other "esp_driver_foo" components esp_driver_gpio esp_driver_pcnt esp_driver_gptimer esp_driver_spi esp_driver_mcpwm esp_driver_ana_cmpr esp_driver_i2s esp_driver_sdmmc esp_driver_sdspi esp_driver_sdio - esp_driver_dac esp_driver_rmt esp_driver_tsens esp_driver_sdm + esp_driver_dac esp_driver_rmt esp_driver_tsens esp_driver_sdm esp_driver_i2c LDFRAGMENTS ${ldfragments} ) endif() diff --git a/components/driver/Kconfig b/components/driver/Kconfig index 343532ca1c..abb9f51283 100644 --- a/components/driver/Kconfig +++ b/components/driver/Kconfig @@ -105,24 +105,4 @@ menu "Driver Configurations" orsource "./ledc/Kconfig.ledc" - menu "I2C Configuration" - config I2C_ISR_IRAM_SAFE - bool "I2C ISR IRAM-Safe" - default n - help - Ensure the I2C interrupt is IRAM-Safe by allowing the interrupt handler to be - executable when the cache is disabled (e.g. SPI Flash write). - note: This cannot be used in the I2C legacy driver. - - config I2C_ENABLE_DEBUG_LOG - bool "Enable I2C debug log" - default n - help - Wether to enable the debug log message for I2C driver. - Note that this option only controls the I2C driver log, will not affect other drivers. - - note: This cannot be used in the I2C legacy driver. - - endmenu # I2C Configurations - endmenu # Driver configurations diff --git a/components/driver/test_apps/.build-test-rules.yml b/components/driver/test_apps/.build-test-rules.yml index 4987875f1c..5cd7de2780 100644 --- a/components/driver/test_apps/.build-test-rules.yml +++ b/components/driver/test_apps/.build-test-rules.yml @@ -6,10 +6,6 @@ components/driver/test_apps/dac_test_apps/legacy_dac_driver: depends_components: - esp_adc -components/driver/test_apps/i2c_test_apps: - disable: - - if: SOC_I2C_SUPPORTED != 1 # TODO: IDF-8070 - components/driver/test_apps/i2s_test_apps/legacy_i2s_adc_dac: disable: - if: SOC_I2S_SUPPORTS_ADC_DAC != 1 @@ -31,10 +27,12 @@ components/driver/test_apps/legacy_adc_driver: - if: SOC_ADC_SUPPORTED != 1 components/driver/test_apps/legacy_i2c_driver: - disable: + disable_test: - if: IDF_TARGET == "esp32p4" temporary: true - reason: not supported yet # TODO: IDF-8070 + reason: lack of runner + depends_filepatterns: + - components/driver/i2c/** components/driver/test_apps/legacy_mcpwm_driver: disable: diff --git a/components/driver/test_apps/legacy_i2c_driver/README.md b/components/driver/test_apps/legacy_i2c_driver/README.md index a8b7833fa3..bf47d80ec6 100644 --- a/components/driver/test_apps/legacy_i2c_driver/README.md +++ b/components/driver/test_apps/legacy_i2c_driver/README.md @@ -1,2 +1,2 @@ -| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 | -| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | diff --git a/components/driver/test_apps/legacy_i2c_driver/main/test_i2c.c b/components/driver/test_apps/legacy_i2c_driver/main/test_i2c.c index ea4b03da85..5668bea0b5 100644 --- a/components/driver/test_apps/legacy_i2c_driver/main/test_i2c.c +++ b/components/driver/test_apps/legacy_i2c_driver/main/test_i2c.c @@ -20,6 +20,7 @@ #include "hal/gpio_hal.h" #include "hal/uart_ll.h" #include "hal/i2c_types.h" +#include "soc/uart_periph.h" #include "test_utils.h" #define DATA_LENGTH 512 /*!sda_num, i2c_periph_signal[port_id].sda_out_sig, 0, 0); esp_rom_gpio_connect_in_signal(handle->sda_num, i2c_periph_signal[port_id].sda_in_sig, 0); - // SCL pin configurations gpio_config_t scl_conf = { .intr_type = GPIO_INTR_DISABLE, diff --git a/components/driver/i2c/i2c_master.c b/components/esp_driver_i2c/i2c_master.c similarity index 99% rename from components/driver/i2c/i2c_master.c rename to components/esp_driver_i2c/i2c_master.c index 0cba3b6211..91e44952d5 100644 --- a/components/driver/i2c/i2c_master.c +++ b/components/esp_driver_i2c/i2c_master.c @@ -444,7 +444,7 @@ static void s_i2c_send_command_async(i2c_master_bus_handle_t i2c_master, BaseTyp i2c_master->sent_all = true; return; } - while(i2c_ll_is_bus_busy(hal->dev)){} + while (i2c_ll_is_bus_busy(hal->dev)) {} while (i2c_master->i2c_trans.cmd_count && !needs_start) { i2c_master->in_progress = true; @@ -514,13 +514,12 @@ static esp_err_t s_i2c_transaction_start(i2c_master_dev_handle_t i2c_dev, int xf return ret; } - ///////////////////////////////I2C DRIVERS////////////////////////////////////////////////////////////// IRAM_ATTR static void i2c_isr_receive_handler(i2c_master_bus_t *i2c_master) { i2c_hal_context_t *hal = &i2c_master->base->hal; - while(i2c_ll_is_bus_busy(hal->dev)){} + while (i2c_ll_is_bus_busy(hal->dev)) {} if (i2c_master->status == I2C_STATUS_READ) { i2c_operation_t *i2c_operation = &i2c_master->i2c_trans.ops[i2c_master->trans_idx]; portENTER_CRITICAL_ISR(&i2c_master->base->spinlock); @@ -656,7 +655,7 @@ static esp_err_t i2c_master_bus_destroy(i2c_master_bus_handle_t bus_handle) { ESP_RETURN_ON_FALSE(bus_handle, ESP_ERR_INVALID_ARG, TAG, "no memory for i2c master bus"); i2c_master_bus_handle_t i2c_master = bus_handle; - if(i2c_release_bus_handle(i2c_master->base) == ESP_OK) { + if (i2c_release_bus_handle(i2c_master->base) == ESP_OK) { if (i2c_master) { if (i2c_master->bus_lock_mux) { vSemaphoreDeleteWithCaps(i2c_master->bus_lock_mux); @@ -717,7 +716,7 @@ static esp_err_t s_i2c_asynchronous_transaction(i2c_master_dev_handle_t i2c_dev, i2c_dev->master_bus->queue_trans = false; ESP_RETURN_ON_ERROR(s_i2c_transaction_start(i2c_dev, timeout_ms), TAG, "I2C transaction failed"); } else { - i2c_dev->master_bus->i2c_anyc_ops[i2c_dev->master_bus->index]=(i2c_operation_t(*))heap_caps_calloc(1, sizeof(i2c_operation_t) * 6, I2C_MEM_ALLOC_CAPS); + i2c_dev->master_bus->i2c_anyc_ops[i2c_dev->master_bus->index] = (i2c_operation_t(*))heap_caps_calloc(1, sizeof(i2c_operation_t) * 6, I2C_MEM_ALLOC_CAPS); memcpy(i2c_dev->master_bus->i2c_anyc_ops[i2c_dev->master_bus->index], i2c_ops, sizeof(i2c_operation_t) * ops_dim); i2c_transaction_t i2c_queue_pre; if (i2c_dev->master_bus->num_trans_inflight < i2c_dev->master_bus->queue_size) { @@ -876,7 +875,7 @@ esp_err_t i2c_master_bus_add_device(i2c_master_bus_handle_t bus_handle, const i2 ESP_RETURN_ON_FALSE((bus_handle != NULL), ESP_ERR_INVALID_ARG, TAG, "this bus is not initialized, please call `i2c_new_master_bus`"); ESP_RETURN_ON_FALSE(dev_config, ESP_ERR_INVALID_ARG, TAG, "invalid argument"); ESP_RETURN_ON_FALSE(dev_config->scl_speed_hz > 0, ESP_ERR_INVALID_ARG, TAG, "invalid scl frequency"); - if(bus_handle->base->bus_mode != I2C_BUS_MODE_MASTER) { + if (bus_handle->base->bus_mode != I2C_BUS_MODE_MASTER) { ESP_LOGE(TAG, "This is not master bus!"); return ESP_ERR_INVALID_ARG; } @@ -945,7 +944,6 @@ esp_err_t i2c_master_bus_reset(i2c_master_bus_handle_t bus_handle) return ESP_OK; } - esp_err_t i2c_master_transmit(i2c_master_dev_handle_t i2c_dev, const uint8_t *write_buffer, size_t write_size, int xfer_timeout_ms) { ESP_RETURN_ON_FALSE(i2c_dev != NULL, ESP_ERR_INVALID_ARG, TAG, "i2c handle not initialized"); @@ -959,7 +957,7 @@ esp_err_t i2c_master_transmit(i2c_master_dev_handle_t i2c_dev, const uint8_t *wr }; ESP_RETURN_ON_ERROR(s_i2c_synchronous_transaction(i2c_dev, i2c_ops, DIM(i2c_ops), xfer_timeout_ms), TAG, "I2C transaction failed"); } else { - i2c_dev->master_bus->anyc_write_buffer[i2c_dev->master_bus->index] = (uint8_t*)heap_caps_calloc(1, sizeof(uint8_t)*write_size, I2C_MEM_ALLOC_CAPS); + i2c_dev->master_bus->anyc_write_buffer[i2c_dev->master_bus->index] = (uint8_t*)heap_caps_calloc(1, sizeof(uint8_t) * write_size, I2C_MEM_ALLOC_CAPS); memcpy(i2c_dev->master_bus->anyc_write_buffer[i2c_dev->master_bus->index], write_buffer, write_size); i2c_operation_t i2c_ops[] = { {.hw_cmd = I2C_TRANS_START_COMMAND}, @@ -988,7 +986,7 @@ esp_err_t i2c_master_transmit_receive(i2c_master_dev_handle_t i2c_dev, const uin }; ESP_RETURN_ON_ERROR(s_i2c_synchronous_transaction(i2c_dev, i2c_ops, DIM(i2c_ops), xfer_timeout_ms), TAG, "I2C transaction failed"); } else { - i2c_dev->master_bus->anyc_write_buffer[i2c_dev->master_bus->index] = (uint8_t*)heap_caps_calloc(1, sizeof(uint8_t)*write_size, I2C_MEM_ALLOC_CAPS); + i2c_dev->master_bus->anyc_write_buffer[i2c_dev->master_bus->index] = (uint8_t*)heap_caps_calloc(1, sizeof(uint8_t) * write_size, I2C_MEM_ALLOC_CAPS); memcpy(i2c_dev->master_bus->anyc_write_buffer[i2c_dev->master_bus->index], write_buffer, write_size); i2c_operation_t i2c_ops[] = { diff --git a/components/driver/i2c/i2c_private.h b/components/esp_driver_i2c/i2c_private.h similarity index 100% rename from components/driver/i2c/i2c_private.h rename to components/esp_driver_i2c/i2c_private.h diff --git a/components/driver/i2c/i2c_slave.c b/components/esp_driver_i2c/i2c_slave.c similarity index 100% rename from components/driver/i2c/i2c_slave.c rename to components/esp_driver_i2c/i2c_slave.c diff --git a/components/driver/i2c/include/driver/i2c_master.h b/components/esp_driver_i2c/include/driver/i2c_master.h similarity index 99% rename from components/driver/i2c/include/driver/i2c_master.h rename to components/esp_driver_i2c/include/driver/i2c_master.h index fb78ef47b8..228f64fcc9 100644 --- a/components/driver/i2c/include/driver/i2c_master.h +++ b/components/esp_driver_i2c/include/driver/i2c_master.h @@ -27,7 +27,7 @@ typedef struct { int intr_priority; /*!< I2C interrupt priority, if set to 0, driver will select the default priority (1,2,3). */ size_t trans_queue_depth; /*!< Depth of internal transfer queue, increase this value can support more transfers pending in the background, only valid in asynchronous transaction. (Typically max_device_num * per_transaction)*/ struct { - uint32_t enable_internal_pullup:1; /*!< Enable internal pullups. Note: This is not strong enough to pullup buses under high-speed frequency. Recommend proper external pull-up if possible */ + uint32_t enable_internal_pullup: 1; /*!< Enable internal pullups. Note: This is not strong enough to pullup buses under high-speed frequency. Recommend proper external pull-up if possible */ } flags; /*!< I2C master config flags */ } i2c_master_bus_config_t; diff --git a/components/driver/i2c/include/driver/i2c_slave.h b/components/esp_driver_i2c/include/driver/i2c_slave.h similarity index 96% rename from components/driver/i2c/include/driver/i2c_slave.h rename to components/esp_driver_i2c/include/driver/i2c_slave.h index e705aa3b02..897b9899ed 100644 --- a/components/driver/i2c/include/driver/i2c_slave.h +++ b/components/esp_driver_i2c/include/driver/i2c_slave.h @@ -29,16 +29,16 @@ typedef struct { int intr_priority; /*!< I2C interrupt priority, if set to 0, driver will select the default priority (1,2,3). */ struct { #if SOC_I2C_SLAVE_CAN_GET_STRETCH_CAUSE - uint32_t stretch_en:1; /*!< Enable slave stretch */ + uint32_t stretch_en: 1; /*!< Enable slave stretch */ #endif #if SOC_I2C_SLAVE_SUPPORT_BROADCAST - uint32_t broadcast_en:1; /*!< I2C slave enable broadcast */ + uint32_t broadcast_en: 1; /*!< I2C slave enable broadcast */ #endif #if SOC_I2C_SLAVE_SUPPORT_I2CRAM_ACCESS - uint32_t access_ram_en:1; /*!< Can get access to I2C RAM directly */ + uint32_t access_ram_en: 1; /*!< Can get access to I2C RAM directly */ #endif #if SOC_I2C_SLAVE_SUPPORT_SLAVE_UNMATCH - uint32_t slave_unmatch_en:1; /*!< Can trigger unmatch interrupt when slave address does not match what master sends*/ + uint32_t slave_unmatch_en: 1; /*!< Can trigger unmatch interrupt when slave address does not match what master sends*/ #endif } flags; /*!< I2C slave config flags */ } i2c_slave_config_t; diff --git a/components/driver/i2c/include/driver/i2c_types.h b/components/esp_driver_i2c/include/driver/i2c_types.h similarity index 99% rename from components/driver/i2c/include/driver/i2c_types.h rename to components/esp_driver_i2c/include/driver/i2c_types.h index 8e31bbfe59..903ad1c426 100644 --- a/components/driver/i2c/include/driver/i2c_types.h +++ b/components/esp_driver_i2c/include/driver/i2c_types.h @@ -34,7 +34,6 @@ typedef enum { I2C_STATUS_TIMEOUT, /*!< I2C bus status error, and operation timeout */ } i2c_master_status_t; - typedef enum { I2C_EVENT_ALIVE, /*!< i2c bus in alive status.*/ I2C_EVENT_DONE, /*!< i2c bus transaction done */ diff --git a/components/driver/i2c/linker.lf b/components/esp_driver_i2c/linker.lf similarity index 62% rename from components/driver/i2c/linker.lf rename to components/esp_driver_i2c/linker.lf index c16bd8c206..7a3bcd47e5 100644 --- a/components/driver/i2c/linker.lf +++ b/components/esp_driver_i2c/linker.lf @@ -1,8 +1,14 @@ [mapping:i2c_driver] -archive: libdriver.a +archive: libesp_driver_i2c.a entries: if I2C_ISR_IRAM_SAFE = y: i2c_master: s_i2c_send_command_async (noflash) i2c_master: s_i2c_write_command (noflash) i2c_master: s_i2c_read_command (noflash) i2c_master: s_i2c_start_end_command (noflash) + +[mapping:i2c_hal] +archive: libhal.a +entries: + if I2C_ISR_IRAM_SAFE = y: + i2c_hal: i2c_hal_master_trans_start (noflash) diff --git a/components/esp_driver_i2c/test_apps/.build-test-rules.yml b/components/esp_driver_i2c/test_apps/.build-test-rules.yml new file mode 100644 index 0000000000..074e8796e9 --- /dev/null +++ b/components/esp_driver_i2c/test_apps/.build-test-rules.yml @@ -0,0 +1,11 @@ +# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps + +components/esp_driver_i2c/test_apps/i2c_test_apps: + disable: + - if: SOC_I2C_SUPPORTED != 1 + disable_test: + - if: IDF_TARGET == "esp32p4" + temporary: true + reason: lack of runners + depends_components: + - esp_driver_i2c diff --git a/components/driver/test_apps/i2c_test_apps/CMakeLists.txt b/components/esp_driver_i2c/test_apps/i2c_test_apps/CMakeLists.txt similarity index 88% rename from components/driver/test_apps/i2c_test_apps/CMakeLists.txt rename to components/esp_driver_i2c/test_apps/i2c_test_apps/CMakeLists.txt index ff8c38b0c5..3ebe26f85d 100644 --- a/components/driver/test_apps/i2c_test_apps/CMakeLists.txt +++ b/components/esp_driver_i2c/test_apps/i2c_test_apps/CMakeLists.txt @@ -14,7 +14,7 @@ project(i2c_test) if(CONFIG_COMPILER_DUMP_RTL_FILES) add_custom_target(check_test_app_sections ALL COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py - --rtl-dirs ${CMAKE_BINARY_DIR}/esp-idf/driver/,${CMAKE_BINARY_DIR}/esp-idf/hal/ + --rtl-dirs ${CMAKE_BINARY_DIR}/esp-idf/esp_driver_i2c/,${CMAKE_BINARY_DIR}/esp-idf/hal/ --elf-file ${CMAKE_BINARY_DIR}/i2c_test.elf find-refs --from-sections=.iram0.text diff --git a/components/driver/test_apps/i2c_test_apps/README.md b/components/esp_driver_i2c/test_apps/i2c_test_apps/README.md similarity index 100% rename from components/driver/test_apps/i2c_test_apps/README.md rename to components/esp_driver_i2c/test_apps/i2c_test_apps/README.md diff --git a/components/driver/test_apps/i2c_test_apps/main/CMakeLists.txt b/components/esp_driver_i2c/test_apps/i2c_test_apps/main/CMakeLists.txt similarity index 100% rename from components/driver/test_apps/i2c_test_apps/main/CMakeLists.txt rename to components/esp_driver_i2c/test_apps/i2c_test_apps/main/CMakeLists.txt diff --git a/components/driver/test_apps/i2c_test_apps/main/test_app_main.c b/components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_app_main.c similarity index 100% rename from components/driver/test_apps/i2c_test_apps/main/test_app_main.c rename to components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_app_main.c diff --git a/components/driver/test_apps/i2c_test_apps/main/test_board.h b/components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_board.h similarity index 100% rename from components/driver/test_apps/i2c_test_apps/main/test_board.h rename to components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_board.h diff --git a/components/driver/test_apps/i2c_test_apps/main/test_i2c_10bit.c b/components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_10bit.c similarity index 99% rename from components/driver/test_apps/i2c_test_apps/main/test_i2c_10bit.c rename to components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_10bit.c index 399a2671c9..ec76603e99 100644 --- a/components/driver/test_apps/i2c_test_apps/main/test_i2c_10bit.c +++ b/components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_10bit.c @@ -4,7 +4,6 @@ * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ - #include #include #include "sdkconfig.h" @@ -119,7 +118,6 @@ static void i2c_slave_read_test_10bit(void) TEST_CASE_MULTIPLE_DEVICES("I2C master write slave test 10 bit", "[i2c][test_env=generic_multi_device][timeout=150]", i2c_master_write_test_10bit, i2c_slave_read_test_10bit); - static void master_read_slave_test_10bit(void) { uint8_t data_rd[DATA_LENGTH] = {0}; @@ -153,7 +151,7 @@ static void master_read_slave_test_10bit(void) vTaskDelay(100 / portTICK_PERIOD_MS); for (int i = 0; i < DATA_LENGTH; i++) { printf("%d\n", data_rd[i]); - TEST_ASSERT(data_rd[i]==i); + TEST_ASSERT(data_rd[i] == i); } unity_send_signal("ready to delete 10bit"); @@ -192,5 +190,4 @@ static void slave_write_buffer_test_10bit(void) TEST_ESP_OK(i2c_del_slave_device(slave_handle)); } - TEST_CASE_MULTIPLE_DEVICES("I2C master read slave test 10 bit", "[i2c][test_env=generic_multi_device][timeout=150]", master_read_slave_test_10bit, slave_write_buffer_test_10bit); diff --git a/components/driver/test_apps/i2c_test_apps/main/test_i2c_broadcast.c b/components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_broadcast.c similarity index 99% rename from components/driver/test_apps/i2c_test_apps/main/test_i2c_broadcast.c rename to components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_broadcast.c index e6cf562289..6a90afcf88 100644 --- a/components/driver/test_apps/i2c_test_apps/main/test_i2c_broadcast.c +++ b/components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_broadcast.c @@ -4,7 +4,6 @@ * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ - #include #include #include "sdkconfig.h" diff --git a/components/driver/test_apps/i2c_test_apps/main/test_i2c_common.c b/components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_common.c similarity index 97% rename from components/driver/test_apps/i2c_test_apps/main/test_i2c_common.c rename to components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_common.c index ee307c32a3..cc238cc0a6 100644 --- a/components/driver/test_apps/i2c_test_apps/main/test_i2c_common.c +++ b/components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_common.c @@ -101,21 +101,21 @@ TEST_CASE("I2C device add & remove check", "[i2c]") TEST_ESP_OK(i2c_new_master_bus(&i2c_mst_config_1, &bus_handle)); i2c_device_config_t dev_cfg_1 = { - .scl_speed_hz = 100*1000, + .scl_speed_hz = 100 * 1000, .device_address = 0x10, }; i2c_master_dev_handle_t dev_1; i2c_master_bus_add_device(bus_handle, &dev_cfg_1, &dev_1); i2c_device_config_t dev_cfg_2 = { - .scl_speed_hz = 100*1000, + .scl_speed_hz = 100 * 1000, .device_address = 0x20, }; i2c_master_dev_handle_t dev_2; i2c_master_bus_add_device(bus_handle, &dev_cfg_2, &dev_2); i2c_device_config_t dev_cfg_3 = { - .scl_speed_hz = 100*1000, + .scl_speed_hz = 100 * 1000, .device_address = 0x30, }; i2c_master_dev_handle_t dev_3; diff --git a/components/driver/test_apps/i2c_test_apps/main/test_i2c_iram.c b/components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_iram.c similarity index 100% rename from components/driver/test_apps/i2c_test_apps/main/test_i2c_iram.c rename to components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_iram.c diff --git a/components/driver/test_apps/i2c_test_apps/main/test_i2c_multi.c b/components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_multi.c similarity index 99% rename from components/driver/test_apps/i2c_test_apps/main/test_i2c_multi.c rename to components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_multi.c index eaf026f0c8..e15b5472d2 100644 --- a/components/driver/test_apps/i2c_test_apps/main/test_i2c_multi.c +++ b/components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_multi.c @@ -4,7 +4,6 @@ * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ - #include #include #include "sdkconfig.h" @@ -32,7 +31,7 @@ void disp_buf(uint8_t *buf, int len) int i; for (i = 0; i < len; i++) { printf("%02x ", buf[i]); - if (( i + 1 ) % 16 == 0) { + if ((i + 1) % 16 == 0) { printf("\n"); } } @@ -132,7 +131,6 @@ static void i2c_slave_read_test(void) TEST_CASE_MULTIPLE_DEVICES("I2C master write slave test", "[i2c][test_env=generic_multi_device][timeout=150]", i2c_master_write_test, i2c_slave_read_test); - static void master_read_slave_test(void) { uint8_t data_rd[DATA_LENGTH] = {0}; @@ -166,7 +164,7 @@ static void master_read_slave_test(void) vTaskDelay(100 / portTICK_PERIOD_MS); for (int i = 0; i < DATA_LENGTH; i++) { printf("%d\n", data_rd[i]); - TEST_ASSERT(data_rd[i]==i); + TEST_ASSERT(data_rd[i] == i); } unity_send_signal("ready to delete master read test"); @@ -205,7 +203,6 @@ static void slave_write_buffer_test(void) TEST_ESP_OK(i2c_del_slave_device(slave_handle)); } - TEST_CASE_MULTIPLE_DEVICES("I2C master read slave test", "[i2c][test_env=generic_multi_device][timeout=150]", master_read_slave_test, slave_write_buffer_test); static void i2c_master_write_read_test(void) @@ -313,7 +310,6 @@ static void i2c_slave_read_write_test(void) TEST_CASE_MULTIPLE_DEVICES("I2C read and write test", "[i2c][test_env=generic_multi_device][timeout=150]", i2c_master_write_read_test, i2c_slave_read_write_test); - static void i2c_master_repeat_write(void) { uint8_t data_wr[DATA_LENGTH] = {0}; diff --git a/components/driver/test_apps/i2c_test_apps/main/test_i2c_ram.c b/components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_ram.c similarity index 99% rename from components/driver/test_apps/i2c_test_apps/main/test_i2c_ram.c rename to components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_ram.c index 165d3afb3b..084b60cffa 100644 --- a/components/driver/test_apps/i2c_test_apps/main/test_i2c_ram.c +++ b/components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_ram.c @@ -4,7 +4,6 @@ * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ - #include #include #include "sdkconfig.h" @@ -98,7 +97,6 @@ static void i2c_slave_read_from_ram_test(void) i2c_slave_dev_handle_t slave_handle; TEST_ESP_OK(i2c_new_slave_device(&i2c_slv_config, &slave_handle)); - unity_send_signal("i2c slave init finish"); unity_wait_for_signal("master write"); @@ -115,7 +113,6 @@ static void i2c_slave_read_from_ram_test(void) TEST_CASE_MULTIPLE_DEVICES("I2C master write slave test - slave directly read from ram", "[i2c][test_env=generic_multi_device][timeout=150]", i2c_master_write_to_ram_test, i2c_slave_read_from_ram_test); - static void master_read_slave_from_ram_test(void) { uint8_t data_rd[DATA_LENGTH_RAM] = {0}; @@ -151,7 +148,7 @@ static void master_read_slave_from_ram_test(void) vTaskDelay(100 / portTICK_PERIOD_MS); for (int i = 0; i < DATA_LENGTH_RAM; i++) { printf("%d\n", data_rd[i]); - TEST_ASSERT(data_rd[i]==i); + TEST_ASSERT(data_rd[i] == i); } unity_send_signal("ready to delete ram test"); @@ -191,7 +188,6 @@ static void slave_write_buffer_to_ram_test(void) TEST_ESP_OK(i2c_del_slave_device(slave_handle)); } - TEST_CASE_MULTIPLE_DEVICES("I2C master read slave ram test", "[i2c][test_env=generic_multi_device][timeout=150]", master_read_slave_from_ram_test, slave_write_buffer_to_ram_test); TEST_CASE("I2C slave init as ram but read by fifo", "[i2c]") diff --git a/components/driver/test_apps/i2c_test_apps/pytest_i2c.py b/components/esp_driver_i2c/test_apps/i2c_test_apps/pytest_i2c.py similarity index 100% rename from components/driver/test_apps/i2c_test_apps/pytest_i2c.py rename to components/esp_driver_i2c/test_apps/i2c_test_apps/pytest_i2c.py diff --git a/components/driver/test_apps/i2c_test_apps/sdkconfig.ci.defaults b/components/esp_driver_i2c/test_apps/i2c_test_apps/sdkconfig.ci.defaults similarity index 100% rename from components/driver/test_apps/i2c_test_apps/sdkconfig.ci.defaults rename to components/esp_driver_i2c/test_apps/i2c_test_apps/sdkconfig.ci.defaults diff --git a/components/driver/test_apps/i2c_test_apps/sdkconfig.ci.iram_safe b/components/esp_driver_i2c/test_apps/i2c_test_apps/sdkconfig.ci.iram_safe similarity index 100% rename from components/driver/test_apps/i2c_test_apps/sdkconfig.ci.iram_safe rename to components/esp_driver_i2c/test_apps/i2c_test_apps/sdkconfig.ci.iram_safe diff --git a/components/driver/test_apps/i2c_test_apps/sdkconfig.ci.release b/components/esp_driver_i2c/test_apps/i2c_test_apps/sdkconfig.ci.release similarity index 100% rename from components/driver/test_apps/i2c_test_apps/sdkconfig.ci.release rename to components/esp_driver_i2c/test_apps/i2c_test_apps/sdkconfig.ci.release diff --git a/components/driver/test_apps/i2c_test_apps/sdkconfig.defaults b/components/esp_driver_i2c/test_apps/i2c_test_apps/sdkconfig.defaults similarity index 100% rename from components/driver/test_apps/i2c_test_apps/sdkconfig.defaults rename to components/esp_driver_i2c/test_apps/i2c_test_apps/sdkconfig.defaults diff --git a/components/esp_lcd/CMakeLists.txt b/components/esp_lcd/CMakeLists.txt index 6889de9131..d748393fab 100644 --- a/components/esp_lcd/CMakeLists.txt +++ b/components/esp_lcd/CMakeLists.txt @@ -28,5 +28,5 @@ endif() idf_component_register(SRCS ${srcs} INCLUDE_DIRS ${includes} PRIV_REQUIRES ${priv_requires} - REQUIRES driver esp_driver_gpio esp_driver_spi + REQUIRES driver esp_driver_gpio esp_driver_spi esp_driver_i2c LDFRAGMENTS linker.lf) diff --git a/components/esp_lcd/test_apps/.build-test-rules.yml b/components/esp_lcd/test_apps/.build-test-rules.yml index 1f25b18686..75564d3e09 100644 --- a/components/esp_lcd/test_apps/.build-test-rules.yml +++ b/components/esp_lcd/test_apps/.build-test-rules.yml @@ -5,8 +5,7 @@ components/esp_lcd/test_apps/i2c_lcd: - if: SOC_I2C_SUPPORTED != 1 depends_components: - esp_lcd - depends_filepatterns: - - components/driver/i2c/**/* + - esp_driver_i2c disable_test: - if: IDF_TARGET not in ["esp32c3"] temporary: true diff --git a/components/hal/i2c_hal.c b/components/hal/i2c_hal.c index 2b1248f622..92d64091c5 100644 --- a/components/hal/i2c_hal.c +++ b/components/hal/i2c_hal.c @@ -75,3 +75,9 @@ void i2c_hal_set_timing_config(i2c_hal_context_t *hal, i2c_hal_timing_config_t * i2c_ll_set_sda_timing(hal->dev, timing_config->sda_sample, timing_config->sda_hold); i2c_ll_set_tout(hal->dev, timing_config->timeout); } + +void i2c_hal_master_trans_start(i2c_hal_context_t *hal) +{ + i2c_ll_update(hal->dev); + i2c_ll_master_trans_start(hal->dev); +} diff --git a/components/hal/i2c_hal_iram.c b/components/hal/i2c_hal_iram.c index f495de5595..f7128a64b5 100644 --- a/components/hal/i2c_hal_iram.c +++ b/components/hal/i2c_hal_iram.c @@ -1,17 +1,11 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include "hal/i2c_hal.h" -void i2c_hal_master_trans_start(i2c_hal_context_t *hal) -{ - i2c_ll_update(hal->dev); - i2c_ll_master_trans_start(hal->dev); -} - //////////////////////////////////////////Deprecated Functions////////////////////////////////////////////////////////// /////////////////////////////The following functions are only used by the legacy driver///////////////////////////////// /////////////////////////////They might be removed in the next major release (ESP-IDF 6.0)////////////////////////////// diff --git a/components/soc/esp32p4/include/soc/soc_caps.h b/components/soc/esp32p4/include/soc/soc_caps.h index cd2d070a15..92d8b8681b 100644 --- a/components/soc/esp32p4/include/soc/soc_caps.h +++ b/components/soc/esp32p4/include/soc/soc_caps.h @@ -48,7 +48,7 @@ #define SOC_SDM_SUPPORTED 1 #define SOC_GPSPI_SUPPORTED 1 #define SOC_LEDC_SUPPORTED 1 -#define SOC_I2C_SUPPORTED 1 //TODO: IDF-6507, TODO: IDF-7491 +#define SOC_I2C_SUPPORTED 1 #define SOC_SYSTIMER_SUPPORTED 1 // #define SOC_AES_SUPPORTED 1 //TODO: IDF-6519 #define SOC_MPI_SUPPORTED 1 diff --git a/docs/doxygen/Doxyfile b/docs/doxygen/Doxyfile index dee2b659a2..2d1665f9ec 100644 --- a/docs/doxygen/Doxyfile +++ b/docs/doxygen/Doxyfile @@ -73,9 +73,6 @@ INPUT = \ $(PROJECT_PATH)/components/bt/host/bluedroid/api/include/api/esp_spp_api.h \ $(PROJECT_PATH)/components/bt/host/nimble/esp-hci/include/esp_nimble_hci.h \ $(PROJECT_PATH)/components/console/esp_console.h \ - $(PROJECT_PATH)/components/driver/i2c/include/driver/i2c_master.h \ - $(PROJECT_PATH)/components/driver/i2c/include/driver/i2c_slave.h \ - $(PROJECT_PATH)/components/driver/i2c/include/driver/i2c_types.h \ $(PROJECT_PATH)/components/driver/ledc/include/driver/ledc.h \ $(PROJECT_PATH)/components/driver/parlio/include/driver/parlio_tx.h \ $(PROJECT_PATH)/components/driver/parlio/include/driver/parlio_types.h \ @@ -121,6 +118,9 @@ INPUT = \ $(PROJECT_PATH)/components/esp_driver_mcpwm/include/driver/mcpwm_sync.h \ $(PROJECT_PATH)/components/esp_driver_mcpwm/include/driver/mcpwm_timer.h \ $(PROJECT_PATH)/components/esp_driver_mcpwm/include/driver/mcpwm_types.h \ + $(PROJECT_PATH)/components/esp_driver_i2c/include/driver/i2c_master.h \ + $(PROJECT_PATH)/components/esp_driver_i2c/include/driver/i2c_slave.h \ + $(PROJECT_PATH)/components/esp_driver_i2c/include/driver/i2c_types.h \ $(PROJECT_PATH)/components/esp_driver_i2s/include/driver/i2s_common.h \ $(PROJECT_PATH)/components/esp_driver_i2s/include/driver/i2s_pdm.h \ $(PROJECT_PATH)/components/esp_driver_i2s/include/driver/i2s_std.h \ diff --git a/docs/en/api-reference/peripherals/i2c.rst b/docs/en/api-reference/peripherals/i2c.rst index 127b7e0aed..8563c60c40 100644 --- a/docs/en/api-reference/peripherals/i2c.rst +++ b/docs/en/api-reference/peripherals/i2c.rst @@ -544,5 +544,5 @@ API Reference .. include-build-file:: inc/i2c_slave.inc -.. include-build-file:: inc/components/driver/i2c/include/driver/i2c_types.inc +.. include-build-file:: inc/components/esp_driver_i2c/include/driver/i2c_types.inc .. include-build-file:: inc/components/hal/include/hal/i2c_types.inc \ No newline at end of file diff --git a/docs/en/migration-guides/release-5.x/5.3/peripherals.rst b/docs/en/migration-guides/release-5.x/5.3/peripherals.rst index 9c3275f0f1..ff7b10ec00 100644 --- a/docs/en/migration-guides/release-5.x/5.3/peripherals.rst +++ b/docs/en/migration-guides/release-5.x/5.3/peripherals.rst @@ -19,6 +19,7 @@ In order to control the dependence of other components on drivers at a smaller g - `esp_driver_rmt` - Driver for RMT - `esp_driver_tsens` - Driver for Temperature Sensor - `esp_driver_sdm` - Driver for Sigma-Delta Modulator +- `esp_driver_i2c` - Driver for I2C For compatibility, the original `driver`` component is still treated as an all-in-one component by registering these `esp_driver_xyz`` components as its public dependencies. In other words, you do not need to modify the CMake file of an existing project, but you now have a way to specify the specific peripheral driver that your project depends on. diff --git a/docs/zh_CN/migration-guides/release-5.x/5.3/peripherals.rst b/docs/zh_CN/migration-guides/release-5.x/5.3/peripherals.rst index ee48673a6b..59a5447efa 100644 --- a/docs/zh_CN/migration-guides/release-5.x/5.3/peripherals.rst +++ b/docs/zh_CN/migration-guides/release-5.x/5.3/peripherals.rst @@ -19,6 +19,7 @@ - `esp_driver_rmt` - RMT 驱动 - `esp_driver_tsens` - 温度传感器驱动 - `esp_driver_sdm` - Sigma-Delta 调制器驱动 +- `esp_driver_i2c` - I2C 驱动 为了兼容性,原来的 `driver` 组件仍然存在,并作为一个 “all-in-one" 的组件,将以上这些 `esp_driver_xyz` 组件注册成自己的公共依赖。换句话说,你无需修改既有项目的 CMake 文件,但是你现在多了一个途径去指定你项目依赖的具体的外设驱动。 diff --git a/examples/peripherals/.build-test-rules.yml b/examples/peripherals/.build-test-rules.yml index 66bc91773c..66351ff4a2 100644 --- a/examples/peripherals/.build-test-rules.yml +++ b/examples/peripherals/.build-test-rules.yml @@ -38,6 +38,12 @@ examples/peripherals/gpio/matrix_keyboard: enable: - if: IDF_TARGET == "esp32s2" +examples/peripherals/i2c/i2c_eeprom: + disable: + - if: SOC_I2C_SUPPORTED != 1 + depends_components: + - esp_driver_i2c + examples/peripherals/i2c/i2c_self_test: disable: - if: SOC_I2C_SUPPORT_SLAVE != 1