diff options
| author | Andrew Leech <andrew.leech@planetinnovation.com.au> | 2024-09-15 22:12:17 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-10-07 13:22:10 +1100 |
| commit | aad6ee3d8c676c58c9dc390aa410bd8259268f44 (patch) | |
| tree | c3b7f07b7ca069302b6d61511533a45ddb4280b2 | |
| parent | 4963ae72bf7a30aa7d0268383c49ce2ae68f3157 (diff) | |
esp32/machine_i2c: Use IDF function for calculating main timeout.
The esp32 I2C driver sets a global timeout during init. The functionality
for this is currently only correct for original esp32 and esp32-s2, newer
parts have a slightly different argument which is log-base-2 of the
timeout.
Note that `i2c_set_timeout()` is a thin layer around `i2c_ll_set_tout()`
with the latter writing directly to the hardware register. So the timeout
argument passed to `i2c_set_timeout()` needs to be in units calculated by
`i2c_ll_calculate_timeout_us_to_reg_val()`.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
| -rw-r--r-- | ports/esp32/machine_i2c.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/ports/esp32/machine_i2c.c b/ports/esp32/machine_i2c.c index e8d913def..74679d01d 100644 --- a/ports/esp32/machine_i2c.c +++ b/ports/esp32/machine_i2c.c @@ -257,7 +257,7 @@ static void machine_hw_i2c_init(machine_hw_i2c_obj_t *self, bool first_init) { .master.clk_speed = self->freq, }; i2c_param_config(self->port, &conf); - int timeout = I2C_SCLK_FREQ / 1000000 * self->timeout_us; + int timeout = i2c_ll_calculate_timeout_us_to_reg_val(I2C_SCLK_FREQ, self->timeout_us); i2c_set_timeout(self->port, (timeout > I2C_LL_MAX_TIMEOUT) ? I2C_LL_MAX_TIMEOUT : timeout); i2c_driver_install(self->port, I2C_MODE_MASTER, 0, 0, 0); } |
