From 58331e3c28e41ad7e3c3dd7dabf6d508a8bfe1cb Mon Sep 17 00:00:00 2001
From: Damien George <damien.p.george@gmail.com>
Date: Thu, 17 May 2018 23:37:12 +1000
Subject: [PATCH] esp8266/modmachine: Allow I2C and SPI to be configured out of
 the build.

I2C costs about 3000 bytes of code, and SPI costs about 4400 bytes.
---
 ports/esp8266/machine_hspi.c | 4 ++++
 ports/esp8266/modmachine.c   | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/ports/esp8266/machine_hspi.c b/ports/esp8266/machine_hspi.c
index ff77282911..07770c8c89 100644
--- a/ports/esp8266/machine_hspi.c
+++ b/ports/esp8266/machine_hspi.c
@@ -39,6 +39,8 @@
 #include "modmachine.h"
 #include "hspi.h"
 
+#if MICROPY_PY_MACHINE_SPI
+
 typedef struct _machine_hspi_obj_t {
     mp_obj_base_t base;
     uint32_t baudrate;
@@ -180,3 +182,5 @@ const mp_obj_type_t machine_hspi_type = {
     .protocol = &machine_hspi_p,
     .locals_dict = (mp_obj_dict_t*)&mp_machine_spi_locals_dict,
 };
+
+#endif // MICROPY_PY_MACHINE_SPI
diff --git a/ports/esp8266/modmachine.c b/ports/esp8266/modmachine.c
index 99286848e2..7e5f6714bf 100644
--- a/ports/esp8266/modmachine.c
+++ b/ports/esp8266/modmachine.c
@@ -255,8 +255,12 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
     { MP_ROM_QSTR(MP_QSTR_PWM), MP_ROM_PTR(&pyb_pwm_type) },
     { MP_ROM_QSTR(MP_QSTR_ADC), MP_ROM_PTR(&pyb_adc_type) },
     { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&pyb_uart_type) },
+    #if MICROPY_PY_MACHINE_I2C
     { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&machine_i2c_type) },
+    #endif
+    #if MICROPY_PY_MACHINE_SPI
     { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&machine_hspi_type) },
+    #endif
 
     // wake abilities
     { MP_ROM_QSTR(MP_QSTR_DEEPSLEEP), MP_ROM_INT(MACHINE_WAKE_DEEPSLEEP) },