Merge branch 'refactor/esp_driver_i2c' into 'master'

refactor(i2c): Make i2c  driver as a seperate component

See merge request espressif/esp-idf!27860
This commit is contained in:
C.S.M 2023-12-15 10:48:33 +08:00
commit 77c49cf3e2
42 changed files with 111 additions and 93 deletions

View File

@ -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()

View File

@ -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

View File

@ -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:

View File

@ -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 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |

View File

@ -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 /*!<Data buffer length for test buffer*/
@ -682,8 +683,8 @@ static void uart_aut_baud_det_init(int rxd_io_num)
{
gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[rxd_io_num], PIN_FUNC_GPIO);
gpio_set_direction(rxd_io_num, GPIO_MODE_INPUT_OUTPUT);
esp_rom_gpio_connect_out_signal(rxd_io_num, I2CEXT0_SCL_OUT_IDX, 0, 0);
esp_rom_gpio_connect_in_signal(rxd_io_num, U1RXD_IN_IDX, 0);
esp_rom_gpio_connect_out_signal(rxd_io_num, i2c_periph_signal[0].scl_out_sig, 0, 0);
esp_rom_gpio_connect_in_signal(rxd_io_num, UART_PERIPH_SIGNAL(1, SOC_UART_RX_PIN_IDX), 0);
periph_module_enable(PERIPH_UART1_MODULE);
/* Reset all the bits */
uart_ll_disable_intr_mask(&UART1, ~0);

View File

@ -0,0 +1,20 @@
set(srcs)
set(include "include")
# I2C related source files
if(CONFIG_SOC_I2C_SUPPORTED)
list(APPEND srcs
"i2c_master.c"
"i2c_common.c"
)
if(CONFIG_SOC_I2C_SUPPORT_SLAVE)
list(APPEND srcs "i2c_slave.c")
endif()
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${include}
PRIV_REQUIRES esp_driver_gpio esp_pm esp_ringbuf
LDFRAGMENTS "linker.lf"
)

View File

@ -0,0 +1,20 @@
menu "ESP-Driver:I2C Configurations"
depends on SOC_I2C_SUPPORTED
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

View File

@ -218,7 +218,6 @@ esp_err_t i2c_select_periph_clock(i2c_bus_handle_t handle, i2c_clock_source_t cl
}
#endif // CONFIG_PM_ENABLE
ESP_LOGD(TAG, "bus clock source frequency: %"PRIu32"hz", periph_src_clk_hz);
return ret;
}
@ -243,7 +242,6 @@ esp_err_t i2c_common_set_pins(i2c_bus_handle_t handle)
esp_rom_gpio_connect_out_signal(handle->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,

View File

@ -514,7 +514,6 @@ 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)
@ -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");

View File

@ -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 */

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -4,7 +4,6 @@
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h>
#include <string.h>
#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};
@ -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);

View File

@ -4,7 +4,6 @@
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h>
#include <string.h>
#include "sdkconfig.h"

View File

@ -4,7 +4,6 @@
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h>
#include <string.h>
#include "sdkconfig.h"
@ -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};
@ -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};

View File

@ -4,7 +4,6 @@
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h>
#include <string.h>
#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};
@ -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]")

View File

@ -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)

View File

@ -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

View File

@ -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);
}

View File

@ -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)//////////////////////////////

View File

@ -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

View File

@ -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 \

View File

@ -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

View File

@ -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.

View File

@ -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 文件,但是你现在多了一个途径去指定你项目依赖的具体的外设驱动。

View File

@ -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