extmod/machine_i2c: Increase default SoftI2C timeout to 50ms.

Some devices, eg BNO055, can stretch SCL for a long time, so make the
default large to accommodate them.  50ms matches the current default for
stm32 hardware I2C .

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2022-01-21 14:59:13 +11:00
parent a707fe50b0
commit 7d71ae25ed
2 changed files with 4 additions and 2 deletions

View File

@ -57,7 +57,7 @@ Constructors
of *scl* and *sda* that cannot be changed.
.. _machine.SoftI2C:
.. class:: SoftI2C(scl, sda, *, freq=400000, timeout=255)
.. class:: SoftI2C(scl, sda, *, freq=400000, timeout=50000)
Construct a new software I2C object. The parameters are:

View File

@ -33,6 +33,8 @@
#include "py/runtime.h"
#include "extmod/machine_i2c.h"
#define SOFT_I2C_DEFAULT_TIMEOUT_US (50000) // 50ms
#if MICROPY_PY_MACHINE_SOFTI2C
typedef mp_machine_soft_i2c_obj_t machine_i2c_obj_t;
@ -651,7 +653,7 @@ STATIC void mp_machine_soft_i2c_init(mp_obj_base_t *self_in, size_t n_args, cons
{ MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_sda, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 400000} },
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 255} },
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = SOFT_I2C_DEFAULT_TIMEOUT_US} },
};
mp_machine_soft_i2c_obj_t *self = (mp_machine_soft_i2c_obj_t *)self_in;