mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-01 14:34:31 +00:00
feat(i2c_slave): refactor i2c slave api to version 2 inorder to solve some existing problem
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "hal/i2c_types.h"
|
||||
#include "esp_attr.h"
|
||||
#include "hal/misc.h"
|
||||
#include "hal/assert.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -72,6 +73,8 @@ typedef enum {
|
||||
#define I2C_LL_RESET_SLV_SCL_PULSE_NUM_DEFAULT (9)
|
||||
#define I2C_LL_SCL_WAIT_US_VAL_DEFAULT (2000) // 2000 is not default value on esp32s2, but 0 is not good to be default
|
||||
|
||||
#define I2C_LL_STRETCH_PROTECT_TIME (0x3ff)
|
||||
|
||||
/**
|
||||
* @brief Calculate I2C bus frequency
|
||||
*
|
||||
@@ -309,7 +312,23 @@ static inline void i2c_ll_slave_broadcast_enable(i2c_dev_t *hw, bool broadcast_e
|
||||
__attribute__((always_inline))
|
||||
static inline void i2c_ll_slave_get_stretch_cause(i2c_dev_t *hw, i2c_slave_stretch_cause_t *stretch_cause)
|
||||
{
|
||||
// Not supported on esp32s2
|
||||
switch (hw->status_reg.stretch_cause) {
|
||||
case 0:
|
||||
*stretch_cause = I2C_SLAVE_STRETCH_CAUSE_ADDRESS_MATCH;
|
||||
break;
|
||||
case 1:
|
||||
*stretch_cause = I2C_SLAVE_STRETCH_CAUSE_TX_EMPTY;
|
||||
break;
|
||||
case 2:
|
||||
*stretch_cause = I2C_SLAVE_STRETCH_CAUSE_RX_FULL;
|
||||
break;
|
||||
case 3:
|
||||
*stretch_cause = I2C_SLAVE_STRETCH_CAUSE_SENDING_ACK;
|
||||
break;
|
||||
default:
|
||||
HAL_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -858,6 +877,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.
|
||||
*
|
||||
@@ -885,6 +914,18 @@ static inline uint32_t i2c_ll_calculate_timeout_us_to_reg_val(uint32_t src_clk_h
|
||||
return 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->status_reg.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)//////////////////////////////
|
||||
|
Reference in New Issue
Block a user