esp32/machine_i2c: Allow boards to configure I2C pins using new macros.
Following how SPI is configured (and how stm32 does it).
#include "driver/i2c.h"
-#define I2C_0_DEFAULT_SCL (GPIO_NUM_18)
-#define I2C_0_DEFAULT_SDA (GPIO_NUM_19)
+#ifndef MICROPY_HW_I2C0_SCL
+#define MICROPY_HW_I2C0_SCL (GPIO_NUM_18)
+#define MICROPY_HW_I2C0_SDA (GPIO_NUM_19)
+#endif
+
+#ifndef MICROPY_HW_I2C1_SCL
#if CONFIG_IDF_TARGET_ESP32
-#define I2C_1_DEFAULT_SCL (GPIO_NUM_25)
-#define I2C_1_DEFAULT_SDA (GPIO_NUM_26)
+#define MICROPY_HW_I2C1_SCL (GPIO_NUM_25)
+#define MICROPY_HW_I2C1_SDA (GPIO_NUM_26)
#else
-#define I2C_1_DEFAULT_SCL (GPIO_NUM_9)
-#define I2C_1_DEFAULT_SDA (GPIO_NUM_8)
+#define MICROPY_HW_I2C1_SCL (GPIO_NUM_9)
+#define MICROPY_HW_I2C1_SDA (GPIO_NUM_8)
+#endif
#endif
#define I2C_DEFAULT_TIMEOUT_US (10000) // 10ms
@@ -147,11 +152,11 @@ mp_obj_t machine_hw_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_
self->base.type = &machine_hw_i2c_type;
self->port = i2c_id;
if (self->port == I2C_NUM_0) {
- self->scl = I2C_0_DEFAULT_SCL;
- self->sda = I2C_0_DEFAULT_SDA;
+ self->scl = MICROPY_HW_I2C0_SCL;
+ self->sda = MICROPY_HW_I2C0_SDA;
} else {
- self->scl = I2C_1_DEFAULT_SCL;
- self->sda = I2C_1_DEFAULT_SDA;
+ self->scl = MICROPY_HW_I2C1_SCL;
+ self->sda = MICROPY_HW_I2C1_SDA;
}
first_init = true;
}
