Merge branch 'feature/esp32h21_i2c_support' into 'master'

Feature/esp32h21 i2c support

Closes IDF-11578 and IDF-11580

See merge request espressif/esp-idf!37227
This commit is contained in:
Gao Xu
2025-03-17 15:06:13 +08:00
29 changed files with 1430 additions and 324 deletions

View File

@@ -486,7 +486,7 @@ static inline void i2c_ll_get_rxfifo_cnt(i2c_dev_t *hw, uint32_t *length)
__attribute__((always_inline))
static inline void i2c_ll_get_txfifo_len(i2c_dev_t *hw, uint32_t *length)
{
*length = SOC_I2C_FIFO_LEN - hw->status_reg.tx_fifo_cnt;
*length = (hw->status_reg.tx_fifo_cnt >= SOC_I2C_FIFO_LEN) ? 0 : (SOC_I2C_FIFO_LEN - hw->status_reg.tx_fifo_cnt);
}
/**
@@ -978,7 +978,7 @@ static inline void i2c_ll_master_get_event(i2c_dev_t *hw, i2c_intr_event_t *even
}
/**
* @brief
* @brief Enable I2C slave TX interrupt
*
* @param hw Beginning address of the peripheral registers
*

View File

@@ -523,7 +523,7 @@ static inline void i2c_ll_get_rxfifo_cnt(i2c_dev_t *hw, uint32_t *length)
__attribute__((always_inline))
static inline void i2c_ll_get_txfifo_len(i2c_dev_t *hw, uint32_t *length)
{
*length = SOC_I2C_FIFO_LEN - hw->sr.txfifo_cnt;
*length = (hw->sr.txfifo_cnt >= SOC_I2C_FIFO_LEN) ? 0 : (SOC_I2C_FIFO_LEN - hw->sr.txfifo_cnt);
}
/**

View File

@@ -1142,7 +1142,7 @@ static inline void i2c_ll_master_disable_rx_it(i2c_dev_t *hw)
}
/**
* @brief
* @brief Enable I2C slave TX interrupt
*
* @param hw Beginning address of the peripheral registers
*

View File

@@ -561,7 +561,7 @@ static inline void i2c_ll_get_rxfifo_cnt(i2c_dev_t *hw, uint32_t *length)
__attribute__((always_inline))
static inline void i2c_ll_get_txfifo_len(i2c_dev_t *hw, uint32_t *length)
{
*length = SOC_I2C_FIFO_LEN - hw->sr.txfifo_cnt;
*length = (hw->sr.txfifo_cnt >= SOC_I2C_FIFO_LEN) ? 0 : (SOC_I2C_FIFO_LEN - hw->sr.txfifo_cnt);
}
/**
@@ -1181,7 +1181,7 @@ static inline void i2c_ll_master_disable_rx_it(i2c_dev_t *hw)
}
/**
* @brief
* @brief Enable I2C slave TX interrupt
*
* @param hw Beginning address of the peripheral registers
*

View File

@@ -565,7 +565,7 @@ static inline void i2c_ll_get_rxfifo_cnt(i2c_dev_t *hw, uint32_t *length)
__attribute__((always_inline))
static inline void i2c_ll_get_txfifo_len(i2c_dev_t *hw, uint32_t *length)
{
*length = SOC_I2C_FIFO_LEN - hw->sr.txfifo_cnt;
*length = (hw->sr.txfifo_cnt >= SOC_I2C_FIFO_LEN) ? 0 : (SOC_I2C_FIFO_LEN - hw->sr.txfifo_cnt);
}
/**
@@ -1183,7 +1183,7 @@ static inline void i2c_ll_master_disable_rx_it(i2c_dev_t *hw)
}
/**
* @brief
* @brief Enable I2C slave TX interrupt
*
* @param hw Beginning address of the peripheral registers
*

View File

@@ -555,7 +555,7 @@ static inline void i2c_ll_get_rxfifo_cnt(i2c_dev_t *hw, uint32_t *length)
__attribute__((always_inline))
static inline void i2c_ll_get_txfifo_len(i2c_dev_t *hw, uint32_t *length)
{
*length = SOC_I2C_FIFO_LEN - hw->sr.txfifo_cnt;
*length = (hw->sr.txfifo_cnt >= SOC_I2C_FIFO_LEN) ? 0 : (SOC_I2C_FIFO_LEN - hw->sr.txfifo_cnt);
}
/**
@@ -1107,7 +1107,7 @@ static inline void i2c_ll_master_disable_rx_it(i2c_dev_t *hw)
}
/**
* @brief
* @brief Enable I2C slave TX interrupt
*
* @param hw Beginning address of the peripheral registers
*

View File

@@ -551,7 +551,7 @@ static inline void i2c_ll_get_rxfifo_cnt(i2c_dev_t *hw, uint32_t *length)
__attribute__((always_inline))
static inline void i2c_ll_get_txfifo_len(i2c_dev_t *hw, uint32_t *length)
{
*length = SOC_I2C_FIFO_LEN - hw->sr.txfifo_cnt;
*length = (hw->sr.txfifo_cnt >= SOC_I2C_FIFO_LEN) ? 0 : (SOC_I2C_FIFO_LEN - hw->sr.txfifo_cnt);
}
/**
@@ -1090,7 +1090,7 @@ static inline void i2c_ll_master_disable_rx_it(i2c_dev_t *hw)
}
/**
* @brief
* @brief Enable I2C slave TX interrupt
*
* @param hw Beginning address of the peripheral registers
*

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -276,6 +276,16 @@ static inline __attribute__((always_inline)) bool clk_ll_rc32k_digi_is_enabled(v
return LP_CLKRST.clk_to_hp.clkrst_icg_hp_osc32k;
}
/**
* @brief Get XTAL_CLK frequency
*
* @return Main XTAL clock frequency, in MHz.
*/
static inline __attribute__((always_inline)) uint32_t clk_ll_xtal_get_freq_mhz(void)
{
return PCR.sysclk_conf.clk_xtal_freq;
}
/**
* @brief Get PLL_CLK frequency
*

File diff suppressed because it is too large Load Diff

View File

@@ -580,7 +580,7 @@ static inline void i2c_ll_get_rxfifo_cnt(i2c_dev_t *hw, uint32_t *length)
__attribute__((always_inline))
static inline void i2c_ll_get_txfifo_len(i2c_dev_t *hw, uint32_t *length)
{
*length = SOC_I2C_FIFO_LEN - hw->sr.txfifo_cnt;
*length = (hw->sr.txfifo_cnt >= SOC_I2C_FIFO_LEN) ? 0 : (SOC_I2C_FIFO_LEN - hw->sr.txfifo_cnt);
}
/**
@@ -1214,7 +1214,7 @@ static inline void i2c_ll_master_disable_rx_it(i2c_dev_t *hw)
}
/**
* @brief
* @brief Enable I2C slave TX interrupt
*
* @param hw Beginning address of the peripheral registers
*

View File

@@ -531,7 +531,7 @@ static inline void i2c_ll_get_rxfifo_cnt(i2c_dev_t *hw, uint32_t *length)
__attribute__((always_inline))
static inline void i2c_ll_get_txfifo_len(i2c_dev_t *hw, uint32_t *length)
{
*length = SOC_I2C_FIFO_LEN - hw->status_reg.tx_fifo_cnt;
*length = (hw->status_reg.tx_fifo_cnt >= SOC_I2C_FIFO_LEN) ? 0 : (SOC_I2C_FIFO_LEN - hw->status_reg.tx_fifo_cnt);
}
/**
@@ -1098,7 +1098,7 @@ static inline void i2c_ll_master_disable_rx_it(i2c_dev_t *hw)
}
/**
* @brief Enable I2C slave TX interrupt
* @brief Enable I2C slave TX interrupt
*
* @param hw Beginning address of the peripheral registers
*

View File

@@ -612,7 +612,7 @@ static inline void i2c_ll_get_rxfifo_cnt(i2c_dev_t *hw, uint32_t *length)
__attribute__((always_inline))
static inline void i2c_ll_get_txfifo_len(i2c_dev_t *hw, uint32_t *length)
{
*length = SOC_I2C_FIFO_LEN - hw->sr.txfifo_cnt;
*length = (hw->sr.txfifo_cnt >= SOC_I2C_FIFO_LEN) ? 0 : (SOC_I2C_FIFO_LEN - hw->sr.txfifo_cnt);
}
/**
@@ -1146,7 +1146,7 @@ static inline void i2c_ll_master_disable_rx_it(i2c_dev_t *hw)
}
/**
* @brief
* @brief Enable I2C slave TX interrupt
*
* @param hw Beginning address of the peripheral registers
*

View File

@@ -1,5 +1,5 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- |
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- |
# HAL I2C test

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -132,7 +132,13 @@ esp_err_t hal_i2c_init(hal_i2c_config *cfg)
I2C_CLOCK_SRC_ATOMIC() {
i2c_ll_set_source_clk(dev, SOC_MOD_CLK_XTAL);
}
i2c_ll_master_cal_bus_clk(clk_hal_xtal_get_freq_mhz() * MHZ, freq, &clk_cal);
uint32_t xtal_freq = 0;
#if SOC_CLK_TREE_SUPPORTED
xtal_freq = clk_hal_xtal_get_freq_mhz();
#else
xtal_freq = clk_ll_xtal_get_freq_mhz();
#endif
i2c_ll_master_cal_bus_clk(xtal_freq * MHZ, freq, &clk_cal);
i2c_ll_master_set_bus_timing(dev, &clk_cal);
i2c_ll_update(dev);