feat(i2c_slave): refactor i2c slave api to version 2 inorder to solve some existing problem

This commit is contained in:
C.S.M
2024-11-08 17:59:10 +08:00
parent f15c1b4c4f
commit 941d0e0779
22 changed files with 873 additions and 44 deletions

View File

@@ -77,6 +77,8 @@ typedef enum {
#define I2C_LL_RESET_SLV_SCL_PULSE_NUM_DEFAULT (9)
#define I2C_LL_SCL_WAIT_US_VAL_DEFAULT (2000) // Approximate value for SCL timeout regs (in us).
#define I2C_LL_STRETCH_PROTECT_TIME (0x3ff)
// Record for Pins usage logs
#define LP_I2C_SCL_PIN_ERR_LOG "SCL pin can only be configured as GPIO#7"
@@ -956,6 +958,16 @@ static inline void i2c_ll_slave_clear_stretch(i2c_dev_t *dev)
dev->scl_stretch_conf.slave_scl_stretch_clr = 1;
}
/**
* @brief Set I2C clock stretch protect num
*
* @param dev Beginning address of the peripheral registers
*/
static inline void i2c_ll_slave_set_stretch_protect_num(i2c_dev_t *dev, uint32_t protect_num)
{
dev->scl_stretch_conf.stretch_protect_num = protect_num;
}
/**
* @brief Check if i2c command is done.
*
@@ -984,6 +996,18 @@ static inline uint32_t i2c_ll_calculate_timeout_us_to_reg_val(uint32_t src_clk_h
return 32 - __builtin_clz(clk_cycle_num_per_us * timeout_us);
}
/**
* @brief Get status of i2c slave
*
* @param Beginning address of the peripheral registers
* @return i2c slave working status
*/
__attribute__((always_inline))
static inline i2c_slave_read_write_status_t i2c_ll_slave_get_read_write_status(i2c_dev_t *hw)
{
return (hw->sr.slave_rw == 0) ? I2C_SLAVE_WRITE_BY_MASTER : I2C_SLAVE_READ_BY_MASTER;
}
//////////////////////////////////////////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)//////////////////////////////