aboutsummaryrefslogtreecommitdiff
path: root/extmod/machine_i2c.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2021-09-02 12:37:00 +1000
committerDamien George <damien@micropython.org>2021-09-02 13:11:23 +1000
commit122d901ef1b624c26771532cb4725eaa8f85e0f4 (patch)
tree7754e525b9cbf33c21e02029c69602ecd0833a65 /extmod/machine_i2c.c
parent7c54b6428058a236b8a48c93c255948ece7e718b (diff)
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>
Diffstat (limited to 'extmod/machine_i2c.c')
-rw-r--r--extmod/machine_i2c.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/extmod/machine_i2c.c b/extmod/machine_i2c.c
index 44161fbbb..b2e39c534 100644
--- a/extmod/machine_i2c.c
+++ b/extmod/machine_i2c.c
@@ -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