From 93da52d011969a2881d8fdb7cb0f64f642688f1c Mon Sep 17 00:00:00 2001
From: fmalpartida <fmalpartida@gmail.com>
Date: Sun, 31 May 2015 18:53:29 +0200
Subject: [PATCH] Added support for OLED SSD1306 I2C based LCDs.

---
 Marlin/Conditionals.h            | 10 ++++++++++
 Marlin/Configuration.h           |  4 ++++
 Marlin/dogm_lcd_implementation.h |  3 +++
 Marlin/pins_SAV_MKI.h            |  2 +-
 4 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/Marlin/Conditionals.h b/Marlin/Conditionals.h
index 59a599bc846..36974d012c7 100644
--- a/Marlin/Conditionals.h
+++ b/Marlin/Conditionals.h
@@ -42,6 +42,13 @@
     #define ENCODER_STEPS_PER_MENU_ITEM 1
   #endif
 
+  // Generic support for SSD1306 OLED based LCDs.
+  #if defined(U8GLIB_SSD1306)
+    #define ULTRA_LCD  //general LCD support, also 16x2
+    #define DOGLCD  // Support for I2C LCD 128x64 (Controller SSD1306 graphic Display Family)
+  #endif
+
+
   #ifdef PANEL_ONE
     #define SDSUPPORT
     #define ULTIMAKERCONTROLLER
@@ -199,6 +206,9 @@
     #ifdef U8GLIB_ST7920
       #undef HAS_LCD_CONTRAST
     #endif
+    #ifdef U8GLIB_SSD1306
+      #undef HAS_LCD_CONTRAST
+    #endif  
   #endif
 
 #else // CONFIGURATION_LCD
diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h
index 32a0a888d21..288daffcbe5 100644
--- a/Marlin/Configuration.h
+++ b/Marlin/Configuration.h
@@ -702,6 +702,10 @@ const bool Z_PROBE_ENDSTOP_INVERTING = false; // set to true to invert the logic
 
 // Panucatt VIKI LCD with status LEDs, integrated click & L/R/U/P buttons, separate encoder inputs
 //#define LCD_I2C_VIKI
+  
+// SSD1306 OLED generic display support
+// ==> REMEMBER TO INSTALL U8glib to your ARDUINO library folder: http://code.google.com/p/u8glib/wiki/u8glib
+//#define U8GLIB_SSD1306
 
 // Shift register panels
 // ---------------------
diff --git a/Marlin/dogm_lcd_implementation.h b/Marlin/dogm_lcd_implementation.h
index d935d767a97..53d7c79574f 100644
--- a/Marlin/dogm_lcd_implementation.h
+++ b/Marlin/dogm_lcd_implementation.h
@@ -125,6 +125,9 @@
 #elif defined(U8GLIB_LM6059_AF)
   // Based on the Adafruit ST7565 (http://www.adafruit.com/products/250)
   U8GLIB_LM6059 u8g(DOGLCD_CS, DOGLCD_A0);
+#elif defined U8GLIB_SSD1306
+  // Generic support for SSD1306 OLED I2C LCDs
+  U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);
 #else
   // for regular DOGM128 display with HW-SPI
   U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0);  // HW-SPI Com: CS, A0
diff --git a/Marlin/pins_SAV_MKI.h b/Marlin/pins_SAV_MKI.h
index e853b63b958..25403157dfd 100644
--- a/Marlin/pins_SAV_MKI.h
+++ b/Marlin/pins_SAV_MKI.h
@@ -79,7 +79,7 @@
   #define BTN_ENC            12
 
   #define KILL_PIN           42 // A2 = 42 - teensy = 40
-  #define HOME_PIN          -1 // A4 = marlin 44 - teensy = 42
+  #define HOME_PIN           44 // A4 = marlin 44 - teensy = 42
 
   #ifdef NUM_SERVOS
     #define SERVO0_PIN       41 // In teensy's pin definition for pinMode (in servo.cpp)