|
60 | 60 | #include "soc/system_reg.h"
|
61 | 61 | #include "soc/gpio_sig_map.h"
|
62 | 62 | #include "soc/i2c_periph.h"
|
| 63 | +#include "esp_clk_tree.h" |
63 | 64 | #if defined(CONFIG_ESPRESSIF_ESP32H2) || defined(CONFIG_ESPRESSIF_ESP32C6)
|
64 | 65 | # include "soc/pcr_reg.h"
|
65 | 66 | #endif
|
|
129 | 130 |
|
130 | 131 | #define I2C_CLR_BUS_TIMEOUT_MS (50)
|
131 | 132 |
|
| 133 | +/* SCL timeout value in microseconds */ |
| 134 | + |
| 135 | +#define SCL_TIMEOUT_VAL_US (CONFIG_ESPRESSIF_I2CTIMEOMS * 1000) |
| 136 | + |
132 | 137 | /****************************************************************************
|
133 | 138 | * Private Types
|
134 | 139 | ****************************************************************************/
|
@@ -713,14 +718,21 @@ static void esp_i2c_sendstop(struct esp_i2c_priv_s *priv)
|
713 | 718 | static void esp_i2c_init_clock(struct esp_i2c_priv_s *priv,
|
714 | 719 | uint32_t bus_freq)
|
715 | 720 | {
|
| 721 | + uint32_t src_clk_frequency; |
| 722 | + |
716 | 723 | if (bus_freq == priv->clk_freq)
|
717 | 724 | {
|
718 | 725 | return ;
|
719 | 726 | }
|
720 | 727 |
|
721 | 728 | i2c_clock_source_t src_clk = I2C_CLK_SRC_DEFAULT;
|
| 729 | + esp_clk_tree_src_get_freq_hz((soc_module_clk_t)src_clk, |
| 730 | + ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED, |
| 731 | + &src_clk_frequency); |
722 | 732 | i2c_hal_set_bus_timing(priv->ctx, priv->config->clk_freq,
|
723 |
| - src_clk, XTAL_CLK_FREQ); |
| 733 | + src_clk, src_clk_frequency); |
| 734 | + i2c_hal_master_set_scl_timeout_val(priv->ctx, SCL_TIMEOUT_VAL_US, |
| 735 | + src_clk_frequency); |
724 | 736 | i2c_ll_update(priv->ctx->dev);
|
725 | 737 | priv->clk_freq = bus_freq;
|
726 | 738 | }
|
|
0 commit comments