mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-16 06:54:22 +00:00
refactor(i2c): Add reset and clock control to i2c ll layer
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "soc/soc_caps.h"
|
||||
#include "soc/i2c_struct.h"
|
||||
#include "soc/clk_tree_defs.h"
|
||||
#include "soc/system_struct.h"
|
||||
#include "hal/i2c_types.h"
|
||||
#include "esp_attr.h"
|
||||
#include "esp_assert.h"
|
||||
@@ -126,6 +127,46 @@ static inline void i2c_ll_update(i2c_dev_t *hw)
|
||||
hw->ctr.conf_upgate = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the bus clock for I2C module
|
||||
*
|
||||
* @param i2c_port I2C port id
|
||||
* @param enable true to enable, false to disable
|
||||
*/
|
||||
static inline void i2c_ll_enable_bus_clock(int i2c_port, bool enable)
|
||||
{
|
||||
if (i2c_port == 0) {
|
||||
SYSTEM.perip_clk_en0.i2c_ext0_clk_en = enable;
|
||||
} else if (i2c_port == 1) {
|
||||
SYSTEM.perip_clk_en0.i2c_ext1_clk_en = enable;
|
||||
}
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define i2c_ll_enable_bus_clock(...) do {(void)__DECLARE_RCC_ATOMIC_ENV; i2c_ll_enable_bus_clock(__VA_ARGS__);} while(0)
|
||||
|
||||
/**
|
||||
* @brief Reset the I2C module
|
||||
*
|
||||
* @param i2c_port Group ID
|
||||
*/
|
||||
static inline void i2c_ll_reset_register(int i2c_port)
|
||||
{
|
||||
if (i2c_port == 0) {
|
||||
SYSTEM.perip_rst_en0.i2c_ext0_rst = 1;
|
||||
SYSTEM.perip_rst_en0.i2c_ext0_rst = 0;
|
||||
} else if (i2c_port == 1) {
|
||||
SYSTEM.perip_rst_en0.i2c_ext1_rst = 1;
|
||||
SYSTEM.perip_rst_en0.i2c_ext1_rst = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define i2c_ll_reset_register(...) do {(void)__DECLARE_RCC_ATOMIC_ENV; i2c_ll_reset_register(__VA_ARGS__);} while(0)
|
||||
|
||||
/**
|
||||
* @brief Configure the I2C bus timing related register.
|
||||
*
|
||||
|
Reference in New Issue
Block a user