diff options
author | Damien George <damien@micropython.org> | 2020-09-25 14:47:34 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2020-10-01 12:57:10 +1000 |
commit | 71f3ade770fa7f2637d94f5ba5840b64a16a95db (patch) | |
tree | 4781c54bcfb9238d7e2fb5035ecc44ae9572a173 /extmod/machine_i2c.h | |
parent | 39d50d129ce428858332523548f0594503d0f45b (diff) |
ports: Support legacy soft I2C/SPI construction via id=-1 arg.
With a warning that this way of constructing software I2C/SPI is
deprecated. The check and warning will be removed in a future release.
This should help existing code to migrate to the new SoftI2C/SoftSPI types.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'extmod/machine_i2c.h')
-rw-r--r-- | extmod/machine_i2c.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/extmod/machine_i2c.h b/extmod/machine_i2c.h index 9723069d5..e3a87e282 100644 --- a/extmod/machine_i2c.h +++ b/extmod/machine_i2c.h @@ -29,6 +29,19 @@ #include "py/obj.h" #include "py/mphal.h" +// Temporary support for legacy construction of SoftI2C via I2C type. +#define MP_MACHINE_I2C_CHECK_FOR_LEGACY_SOFTI2C_CONSTRUCTION(n_args, n_kw, all_args) \ + do { \ + if (n_args == 0 || all_args[0] == MP_OBJ_NEW_SMALL_INT(-1)) { \ + mp_print_str(MICROPY_ERROR_PRINTER, "Warning: I2C(-1, ...) is deprecated, use SoftI2C(...) instead\n"); \ + if (n_args != 0) { \ + --n_args; \ + ++all_args; \ + } \ + return mp_machine_soft_i2c_type.make_new(&mp_machine_soft_i2c_type, n_args, n_kw, all_args); \ + } \ + } while (0) + #define MP_MACHINE_I2C_FLAG_READ (0x01) // if not set then it's a write #define MP_MACHINE_I2C_FLAG_STOP (0x02) |