summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/stm32/i2c.c4
-rw-r--r--ports/stm32/machine_i2c.c4
-rw-r--r--ports/stm32/main.c3
-rw-r--r--ports/stm32/modpyb.c2
-rw-r--r--ports/stm32/mpconfigport.h12
5 files changed, 24 insertions, 1 deletions
diff --git a/ports/stm32/i2c.c b/ports/stm32/i2c.c
index b22787cab..e255cbc6b 100644
--- a/ports/stm32/i2c.c
+++ b/ports/stm32/i2c.c
@@ -36,6 +36,8 @@
#include "dma.h"
#include "i2c.h"
+#if MICROPY_HW_ENABLE_HW_I2C
+
/// \moduleref pyb
/// \class I2C - a two-wire serial protocol
///
@@ -1033,3 +1035,5 @@ const mp_obj_type_t pyb_i2c_type = {
.make_new = pyb_i2c_make_new,
.locals_dict = (mp_obj_dict_t*)&pyb_i2c_locals_dict,
};
+
+#endif // MICROPY_HW_ENABLE_HW_I2C
diff --git a/ports/stm32/machine_i2c.c b/ports/stm32/machine_i2c.c
index 1be2151e3..1018a9b1a 100644
--- a/ports/stm32/machine_i2c.c
+++ b/ports/stm32/machine_i2c.c
@@ -34,6 +34,8 @@
#include "genhdr/pins.h"
#include "i2c.h"
+#if MICROPY_HW_ENABLE_HW_I2C
+
STATIC const mp_obj_type_t machine_hard_i2c_type;
#if defined(MCU_SERIES_F4)
@@ -548,3 +550,5 @@ STATIC const mp_obj_type_t machine_hard_i2c_type = {
.protocol = &machine_hard_i2c_p,
.locals_dict = (mp_obj_dict_t*)&mp_machine_soft_i2c_locals_dict,
};
+
+#endif // MICROPY_HW_ENABLE_HW_I2C
diff --git a/ports/stm32/main.c b/ports/stm32/main.c
index 9a83f9f36..352c09bcd 100644
--- a/ports/stm32/main.c
+++ b/ports/stm32/main.c
@@ -556,7 +556,10 @@ soft_reset:
rng_init0();
#endif
+ #if MICROPY_HW_ENABLE_HW_I2C
i2c_init0();
+ #endif
+
spi_init0();
pyb_usb_init0();
diff --git a/ports/stm32/modpyb.c b/ports/stm32/modpyb.c
index 81cbdcc19..4d186e278 100644
--- a/ports/stm32/modpyb.c
+++ b/ports/stm32/modpyb.c
@@ -203,7 +203,9 @@ STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
#if defined(MICROPY_HW_LED1)
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pyb_led_type) },
#endif
+ #if MICROPY_HW_ENABLE_HW_I2C
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&pyb_i2c_type) },
+ #endif
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&pyb_spi_type) },
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&pyb_uart_type) },
#if MICROPY_HW_ENABLE_CAN
diff --git a/ports/stm32/mpconfigport.h b/ports/stm32/mpconfigport.h
index 51d442561..6fa286b26 100644
--- a/ports/stm32/mpconfigport.h
+++ b/ports/stm32/mpconfigport.h
@@ -131,7 +131,6 @@
#define MICROPY_PY_MACHINE_PULSE (1)
#define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new
#define MICROPY_PY_MACHINE_I2C (1)
-#define MICROPY_PY_MACHINE_I2C_MAKE_NEW machine_hard_i2c_make_new
#define MICROPY_PY_MACHINE_SPI (1)
#define MICROPY_PY_MACHINE_SPI_MSB (SPI_FIRSTBIT_MSB)
#define MICROPY_PY_MACHINE_SPI_LSB (SPI_FIRSTBIT_LSB)
@@ -245,6 +244,17 @@ extern const struct _mp_obj_module_t mp_module_onewire;
#define MICROPY_HW_MAX_UART (6)
#endif
+// enable hardware I2C if there are any peripherals defined
+#define MICROPY_HW_ENABLE_HW_I2C ( \
+ defined(MICROPY_HW_I2C1_SCL) \
+ || defined(MICROPY_HW_I2C2_SCL) \
+ || defined(MICROPY_HW_I2C3_SCL) \
+ || defined(MICROPY_HW_I2C4_SCL) \
+)
+#if MICROPY_HW_ENABLE_HW_I2C
+#define MICROPY_PY_MACHINE_I2C_MAKE_NEW machine_hard_i2c_make_new
+#endif
+
#define MP_STATE_PORT MP_STATE_VM
#define MICROPY_PORT_ROOT_POINTERS \