extmod/machine_i2c: Make SoftI2C configurable via macro option.

The zephyr port doesn't support SoftI2C so it's not enabled, and the legacy
I2C constructor check can be removed.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2021-09-02 12:37:00 +10:00
parent 7c54b64280
commit 122d901ef1
9 changed files with 21 additions and 4 deletions

View File

@@ -33,7 +33,7 @@
#include "py/runtime.h"
#include "extmod/machine_i2c.h"
#if MICROPY_PY_MACHINE_I2C
#if MICROPY_PY_MACHINE_SOFTI2C
typedef mp_machine_soft_i2c_obj_t machine_i2c_obj_t;
@@ -240,9 +240,13 @@ int mp_machine_soft_i2c_transfer(mp_obj_base_t *self_in, uint16_t addr, size_t n
return transfer_ret;
}
#endif // MICROPY_PY_MACHINE_SOFTI2C
/******************************************************************************/
// Generic helper functions
#if MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_SOFTI2C
// For use by ports that require a single buffer of data for a read/write transfer
int mp_machine_i2c_transfer_adaptor(mp_obj_base_t *self, uint16_t addr, size_t n, mp_machine_i2c_buf_t *bufs, unsigned int flags) {
size_t len;
@@ -628,9 +632,13 @@ STATIC const mp_rom_map_elem_t machine_i2c_locals_dict_table[] = {
};
MP_DEFINE_CONST_DICT(mp_machine_i2c_locals_dict, machine_i2c_locals_dict_table);
#endif // MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_SOFTI2C
/******************************************************************************/
// Implementation of soft I2C
#if MICROPY_PY_MACHINE_SOFTI2C
STATIC void mp_machine_soft_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
mp_machine_soft_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "SoftI2C(scl=" MP_HAL_PIN_FMT ", sda=" MP_HAL_PIN_FMT ", freq=%u)",
@@ -711,4 +719,4 @@ const mp_obj_type_t mp_machine_soft_i2c_type = {
.locals_dict = (mp_obj_dict_t *)&mp_machine_i2c_locals_dict,
};
#endif // MICROPY_PY_MACHINE_I2C
#endif // MICROPY_PY_MACHINE_SOFTI2C