extmod/machine_i2c: Add init protocol method for generic I2C bindings.

Hardware I2C implementations must provide a .init() protocol method if they
want to support reconfiguration.  Otherwise the default is that i2c.init()
raises an OSError (currently the case for all ports).

mp_machine_soft_i2c_locals_dict is renamed to mp_machine_i2c_locals_dict to
match the generic SPI bindings.

Fixes issue #6623 (where calling .init() on a HW I2C would crash).

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2020-11-18 14:50:43 +11:00
parent 3dcb551d89
commit 64180f0742
6 changed files with 59 additions and 45 deletions

View File

@@ -273,7 +273,7 @@ const mp_obj_type_t machine_hard_i2c_type = {
.print = machine_hard_i2c_print,
.make_new = machine_hard_i2c_make_new,
.protocol = &machine_hard_i2c_p,
.locals_dict = (mp_obj_dict_t *)&mp_machine_soft_i2c_locals_dict,
.locals_dict = (mp_obj_dict_t *)&mp_machine_i2c_locals_dict,
};
#endif // MICROPY_HW_ENABLE_HW_I2C