mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
refactor(esp_hal_regi2c): move regi2c implementation from esp_rom to esp_hal_regi2c
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "soc/soc.h"
|
||||
#include "modem/modem_lpcon_struct.h"
|
||||
#include "modem/modem_syscon_struct.h"
|
||||
#include "soc/pmu_reg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ANA_I2C_MST_CLK_HAS_ROOT_GATING 1 /*!< Any regi2c operation needs enable the analog i2c master clock first */
|
||||
|
||||
/**
|
||||
* @brief Enable analog I2C master clock
|
||||
*/
|
||||
static inline __attribute__((always_inline)) void _regi2c_ctrl_ll_master_enable_clock(bool en)
|
||||
{
|
||||
MODEM_LPCON.clk_conf.clk_i2c_mst_en = en;
|
||||
}
|
||||
|
||||
/// 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_RC_ATOMIC_ENV variable in advance
|
||||
#define regi2c_ctrl_ll_master_enable_clock(...) do { \
|
||||
(void)__DECLARE_RCC_RC_ATOMIC_ENV; \
|
||||
_regi2c_ctrl_ll_master_enable_clock(__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* @brief Check whether analog I2C master clock is enabled
|
||||
*/
|
||||
static inline __attribute__((always_inline)) bool regi2c_ctrl_ll_master_is_clock_enabled(void)
|
||||
{
|
||||
return MODEM_LPCON.clk_conf.clk_i2c_mst_en;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset analog I2C master
|
||||
*/
|
||||
static inline __attribute__((always_inline)) void _regi2c_ctrl_ll_master_reset(void)
|
||||
{
|
||||
MODEM_LPCON.rst_conf.rst_i2c_mst = 1;
|
||||
MODEM_LPCON.rst_conf.rst_i2c_mst = 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_RC_ATOMIC_ENV variable in advance
|
||||
#define regi2c_ctrl_ll_master_reset(...) do { \
|
||||
(void)__DECLARE_RCC_RC_ATOMIC_ENV; \
|
||||
_regi2c_ctrl_ll_master_reset(__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* @brief Force enable analog I2C master clock
|
||||
*/
|
||||
static inline __attribute__((always_inline)) void regi2c_ctrl_ll_master_force_enable_clock(bool en)
|
||||
{
|
||||
MODEM_LPCON.clk_conf_force_on.clk_i2c_mst_fo = en;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure analog I2C master clock
|
||||
*/
|
||||
static inline __attribute__((always_inline)) void regi2c_ctrl_ll_master_configure_clock(void)
|
||||
{
|
||||
MODEM_SYSCON.clk_conf.clk_i2c_mst_sel_160m = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the I2C internal bus to do I2C read/write operation to the SAR_ADC and TSENS registers
|
||||
*/
|
||||
static inline void regi2c_ctrl_ll_i2c_sar_periph_enable(void)
|
||||
{
|
||||
//Enter regi2c reset mode
|
||||
CLEAR_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_PERIF_I2C_RSTB);
|
||||
//Enable REGI2C for SAR_ADC and TSENS
|
||||
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_PERIF_I2C);
|
||||
//Release regi2c reset mode, enter work mode
|
||||
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_PERIF_I2C_RSTB);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the I2C internal bus to do I2C read/write operation to the SAR_ADC and TSENS registers
|
||||
*/
|
||||
static inline void regi2c_ctrl_ll_i2c_sar_periph_disable(void)
|
||||
{
|
||||
CLEAR_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_PERIF_I2C);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user