mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-14 22:16:46 +00:00
feat(regi2c): add regi2c support for esp32h4
This commit is contained in:
@@ -295,37 +295,37 @@ static inline __attribute__((always_inline)) void clk_ll_bbpll_set_freq_mhz(uint
|
||||
*/
|
||||
static inline __attribute__((always_inline)) void clk_ll_bbpll_set_config(uint32_t pll_freq_mhz, uint32_t xtal_freq_mhz)
|
||||
{
|
||||
HAL_ASSERT(pll_freq_mhz == CLK_LL_PLL_96M_FREQ_MHZ);
|
||||
uint8_t div_ref;
|
||||
uint8_t div7_0;
|
||||
uint8_t dr1;
|
||||
uint8_t dr3;
|
||||
uint8_t dchgp;
|
||||
uint8_t dcur;
|
||||
uint8_t dbias;
|
||||
// HAL_ASSERT(pll_freq_mhz == CLK_LL_PLL_96M_FREQ_MHZ);
|
||||
// uint8_t div_ref;
|
||||
// uint8_t div7_0;
|
||||
// uint8_t dr1;
|
||||
// uint8_t dr3;
|
||||
// uint8_t dchgp;
|
||||
// uint8_t dcur;
|
||||
// uint8_t dbias;
|
||||
|
||||
/* Configure 480M PLL */
|
||||
switch (xtal_freq_mhz) {
|
||||
case SOC_XTAL_FREQ_32M:
|
||||
default:
|
||||
div_ref = 0;
|
||||
div7_0 = 8;
|
||||
dr1 = 0;
|
||||
dr3 = 0;
|
||||
dchgp = 5;
|
||||
dcur = 3;
|
||||
dbias = 2;
|
||||
break;
|
||||
}
|
||||
uint8_t i2c_bbpll_lref = (dchgp << I2C_BBPLL_OC_DCHGP_LSB) | (div_ref);
|
||||
uint8_t i2c_bbpll_div_7_0 = div7_0;
|
||||
uint8_t i2c_bbpll_dcur = (1 << I2C_BBPLL_OC_DLREF_SEL_LSB ) | (3 << I2C_BBPLL_OC_DHREF_SEL_LSB) | dcur;
|
||||
REGI2C_WRITE(I2C_BBPLL, I2C_BBPLL_OC_REF_DIV, i2c_bbpll_lref);
|
||||
REGI2C_WRITE(I2C_BBPLL, I2C_BBPLL_OC_DIV_7_0, i2c_bbpll_div_7_0);
|
||||
REGI2C_WRITE_MASK(I2C_BBPLL, I2C_BBPLL_OC_DR1, dr1);
|
||||
REGI2C_WRITE_MASK(I2C_BBPLL, I2C_BBPLL_OC_DR3, dr3);
|
||||
REGI2C_WRITE(I2C_BBPLL, I2C_BBPLL_OC_DCUR, i2c_bbpll_dcur);
|
||||
REGI2C_WRITE_MASK(I2C_BBPLL, I2C_BBPLL_OC_VCO_DBIAS, dbias);
|
||||
// /* Configure 480M PLL */
|
||||
// switch (xtal_freq_mhz) {
|
||||
// case SOC_XTAL_FREQ_32M:
|
||||
// default:
|
||||
// div_ref = 0;
|
||||
// div7_0 = 8;
|
||||
// dr1 = 0;
|
||||
// dr3 = 0;
|
||||
// dchgp = 5;
|
||||
// dcur = 3;
|
||||
// dbias = 2;
|
||||
// break;
|
||||
// }
|
||||
// uint8_t i2c_bbpll_lref = (dchgp << I2C_BBPLL_OC_DCHGP_LSB) | (div_ref);
|
||||
// uint8_t i2c_bbpll_div_7_0 = div7_0;
|
||||
// uint8_t i2c_bbpll_dcur = (1 << I2C_BBPLL_OC_DLREF_SEL_LSB ) | (3 << I2C_BBPLL_OC_DHREF_SEL_LSB) | dcur;
|
||||
// REGI2C_WRITE(I2C_BBPLL, I2C_BBPLL_OC_REF_DIV, i2c_bbpll_lref);
|
||||
// REGI2C_WRITE(I2C_BBPLL, I2C_BBPLL_OC_DIV_7_0, i2c_bbpll_div_7_0);
|
||||
// REGI2C_WRITE_MASK(I2C_BBPLL, I2C_BBPLL_OC_DR1, dr1);
|
||||
// REGI2C_WRITE_MASK(I2C_BBPLL, I2C_BBPLL_OC_DR3, dr3);
|
||||
// REGI2C_WRITE(I2C_BBPLL, I2C_BBPLL_OC_DCUR, i2c_bbpll_dcur);
|
||||
// REGI2C_WRITE_MASK(I2C_BBPLL, I2C_BBPLL_OC_VCO_DBIAS, dbias);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -9,21 +9,72 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "soc/soc.h"
|
||||
#include "soc/regi2c_defs.h"
|
||||
|
||||
//TODO: [ESP32H4] IDF-12315 inherited from verification branch, need check
|
||||
#include "soc/i2c_ana_mst_reg.h"
|
||||
#include "soc/pmu_reg.h"
|
||||
#include "modem/modem_lpcon_struct.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(...) (void)__DECLARE_RCC_RC_ATOMIC_ENV; _regi2c_ctrl_ll_master_enable_clock(__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @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(...) (void)__DECLARE_RCC_RC_ATOMIC_ENV; _regi2c_ctrl_ll_master_reset(__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
// Nothing to configure
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Start BBPLL self-calibration
|
||||
*/
|
||||
static inline __attribute__((always_inline)) void regi2c_ctrl_ll_bbpll_calibration_start(void)
|
||||
{
|
||||
REG_CLR_BIT(I2C_MST_ANA_CONF0_REG, I2C_MST_BBPLL_STOP_FORCE_HIGH);
|
||||
REG_SET_BIT(I2C_MST_ANA_CONF0_REG, I2C_MST_BBPLL_STOP_FORCE_LOW);
|
||||
REG_CLR_BIT(I2C_ANA_MST_ANA_CONF0_REG, I2C_MST_BBPLL_STOP_FORCE_HIGH);
|
||||
REG_SET_BIT(I2C_ANA_MST_ANA_CONF0_REG, I2C_MST_BBPLL_STOP_FORCE_LOW);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,8 +82,8 @@ static inline __attribute__((always_inline)) void regi2c_ctrl_ll_bbpll_calibrati
|
||||
*/
|
||||
static inline __attribute__((always_inline)) void regi2c_ctrl_ll_bbpll_calibration_stop(void)
|
||||
{
|
||||
REG_CLR_BIT(I2C_MST_ANA_CONF0_REG, I2C_MST_BBPLL_STOP_FORCE_LOW);
|
||||
REG_SET_BIT(I2C_MST_ANA_CONF0_REG, I2C_MST_BBPLL_STOP_FORCE_HIGH);
|
||||
REG_CLR_BIT(I2C_ANA_MST_ANA_CONF0_REG, I2C_MST_BBPLL_STOP_FORCE_LOW);
|
||||
REG_SET_BIT(I2C_ANA_MST_ANA_CONF0_REG, I2C_MST_BBPLL_STOP_FORCE_HIGH);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,7 +93,7 @@ static inline __attribute__((always_inline)) void regi2c_ctrl_ll_bbpll_calibrati
|
||||
*/
|
||||
static inline __attribute__((always_inline)) bool regi2c_ctrl_ll_bbpll_calibration_is_done(void)
|
||||
{
|
||||
return REG_GET_BIT(I2C_MST_ANA_CONF0_REG, I2C_MST_BBPLL_CAL_DONE);
|
||||
return REG_GET_BIT(I2C_ANA_MST_ANA_CONF0_REG, I2C_MST_BBPLL_CAL_DONE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,8 +101,7 @@ static inline __attribute__((always_inline)) bool regi2c_ctrl_ll_bbpll_calibrati
|
||||
*/
|
||||
static inline void regi2c_ctrl_ll_i2c_sar_periph_enable(void)
|
||||
{
|
||||
// TODO: [ESP32H4] IDF-12368 IDF-12370
|
||||
abort();
|
||||
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_PERIF_I2C);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,8 +109,7 @@ static inline void regi2c_ctrl_ll_i2c_sar_periph_enable(void)
|
||||
*/
|
||||
static inline void regi2c_ctrl_ll_i2c_sar_periph_disable(void)
|
||||
{
|
||||
// TODO: [ESP32H4] IDF-12368 IDF-12370
|
||||
abort();
|
||||
CLEAR_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_PERIF_I2C);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
Reference in New Issue
Block a user