From ae2476dfdbcd19f349aeafb28f92778e5c91fa83 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Project-J=C2=B2?= <contact@projectj2.fr>
Date: Sun, 14 May 2017 18:59:32 +0200
Subject: [PATCH] Add UltiController v2.1 support

Add compatibility with the original screen bord from Ultimaker 2 printer
(UltiController v2.1 with the PG-2864ALBP I2C display)
---
 Marlin/Conditionals_LCD.h   | 20 ++++++++++++++++----
 Marlin/Configuration.h      |  6 ++++++
 Marlin/SanityCheck.h        |  3 +++
 Marlin/ultralcd_impl_DOGM.h |  3 +++
 4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/Marlin/Conditionals_LCD.h b/Marlin/Conditionals_LCD.h
index 4b91450a54..97784a182a 100644
--- a/Marlin/Conditionals_LCD.h
+++ b/Marlin/Conditionals_LCD.h
@@ -142,10 +142,21 @@
     #define DEFAULT_LCD_CONTRAST 17
   #endif
 
-  // Generic support for SSD1306 / SH1106 OLED based LCDs.
-  #if ENABLED(U8GLIB_SSD1306) || ENABLED(U8GLIB_SH1106)
+  #if ENABLED(ULTI_CONTROLLER)
+    #define U8GLIB_SSD1309
+    #define REVERSE_ENCODER_DIRECTION
+    #define LCD_RESET_PIN LCD_PINS_D6 //  This controller need a reset pin
+    #define LCD_CONTRAST_MIN 0
+    #define LCD_CONTRAST_MAX 254
+    #define DEFAULT_LCD_CONTRAST 127
+    #define ENCODER_PULSES_PER_STEP 2
+    #define ENCODER_STEPS_PER_MENU_ITEM 2
+  #endif
+
+  // Generic support for SSD1306 / SSD1309 / SH1106 OLED based LCDs.
+  #if ENABLED(U8GLIB_SSD1306) || ENABLED(U8GLIB_SSD1309) || ENABLED(U8GLIB_SH1106)
     #define ULTRA_LCD  //general LCD support, also 16x2
-    #define DOGLCD  // Support for I2C LCD 128x64 (Controller SSD1306 / SH1106 graphic Display Family)
+    #define DOGLCD  // Support for I2C LCD 128x64 (Controller SSD1306 / SSD1309 / SH1106 graphic Display Family)
   #endif
 
   #if ENABLED(PANEL_ONE) || ENABLED(U8GLIB_SH1106)
@@ -169,7 +180,8 @@
   #if ENABLED(ULTIMAKERCONTROLLER)              \
    || ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER) \
    || ENABLED(G3D_PANEL)                        \
-   || ENABLED(RIGIDBOT_PANEL)
+   || ENABLED(RIGIDBOT_PANEL)                   \
+   || ENABLED(ULTI_CONTROLLER)
     #define ULTIPANEL
   #endif
 
diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h
index 8abc9b668a..31aae4ff5e 100644
--- a/Marlin/Configuration.h
+++ b/Marlin/Configuration.h
@@ -1603,6 +1603,12 @@
   #define U8GLIB_SH1106
 #endif
 
+//
+// Original Ulticontroller from Ultimaker 2 printer with SSD1309 I2C display and encoder
+// https://github.com/Ultimaker/Ultimaker2/tree/master/1249_Ulticontroller_Board_(x1)
+//
+//#define ULTI_CONTROLLER
+
 //
 // CONTROLLER TYPE: Shift register panels
 //
diff --git a/Marlin/SanityCheck.h b/Marlin/SanityCheck.h
index 65eb8d085c..7e11dc413d 100644
--- a/Marlin/SanityCheck.h
+++ b/Marlin/SanityCheck.h
@@ -1421,6 +1421,9 @@ static_assert(1 >= 0
   #if ENABLED(ZONESTAR_LCD)
     + 1
   #endif
+  #if ENABLED(ULTI_CONTROLLER)
+    + 1
+  #endif
   , "Please select no more than one LCD controller option."
 );
 
diff --git a/Marlin/ultralcd_impl_DOGM.h b/Marlin/ultralcd_impl_DOGM.h
index 07b4b2678c..77a09b3907 100644
--- a/Marlin/ultralcd_impl_DOGM.h
+++ b/Marlin/ultralcd_impl_DOGM.h
@@ -197,6 +197,9 @@
   // Generic support for SH1106 OLED I2C LCDs
   //U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST);  // 8 stripes
   U8GLIB_SH1106_128X64_2X u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 4 stripes
+#elif ENABLED(U8GLIB_SSD1309)
+  // Generic support for SSD1309 OLED I2C LCDs
+  U8GLIB_SSD1309_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST);
 #elif ENABLED(MINIPANEL)
   // The MINIPanel display
   //U8GLIB_MINI12864 u8g(DOGLCD_CS, DOGLCD_A0);  // 8 stripes