From df75a606ffa6a6a63644114de24f3c649144fd83 Mon Sep 17 00:00:00 2001
From: Laurent <timh0r@users.noreply.github.com>
Date: Tue, 16 Apr 2019 00:03:10 +0200
Subject: [PATCH] Support MKS SGen board (#13694)

---
 Marlin/src/core/boards.h         |  1 +
 Marlin/src/pins/pins.h           |  2 ++
 Marlin/src/pins/pins_MKS_SBASE.h | 10 ++++--
 Marlin/src/pins/pins_MKS_SGEN.h  | 60 ++++++++++++++++++++++++++++++++
 4 files changed, 70 insertions(+), 3 deletions(-)
 create mode 100644 Marlin/src/pins/pins_MKS_SGEN.h

diff --git a/Marlin/src/core/boards.h b/Marlin/src/core/boards.h
index ee9da1fd16..4a7fb642b9 100644
--- a/Marlin/src/core/boards.h
+++ b/Marlin/src/core/boards.h
@@ -194,6 +194,7 @@
 #define BOARD_BIQU_B300_V1_0      1760  // BIQU B300_V1.0 (Power outputs: Hotend0, Fan, Bed, SPI Driver)
 #define BOARD_BIGTREE_SKR_V1_3    1761  // BIGTREE SKR_V1.3 (Power outputs: Hotend0, Hotend1, Fan, Bed)
 #define BOARD_AZTEEG_X5_MINI      1762  // Azteeg X5 Mini (Power outputs: Hotend0, Bed, Fan)
+#define BOARD_MKS_SGEN            1763  // MKS-SGen (Power outputs: Hotend0, Hotend1, Bed, Fan)
 
 //
 // SAM3X8E ARM Cortex M3
diff --git a/Marlin/src/pins/pins.h b/Marlin/src/pins/pins.h
index 68de292c0c..bb7a10108e 100644
--- a/Marlin/src/pins/pins.h
+++ b/Marlin/src/pins/pins.h
@@ -316,6 +316,8 @@
   #include "pins_RAMPS_RE_ARM.h"        // LPC1768                                    env:LPC1768
 #elif MB(MKS_SBASE)
   #include "pins_MKS_SBASE.h"           // LPC1768                                    env:LPC1768
+#elif MB(MKS_SGEN)
+  #include "pins_MKS_SGEN.h"            // LPC1769                                    env:LPC1769
 #elif MB(AZSMZ_MINI)
   #include "pins_AZSMZ_MINI.h"          // LPC1768                                    env:LPC1768
 #elif MB(AZTEEG_X5_GT)
diff --git a/Marlin/src/pins/pins_MKS_SBASE.h b/Marlin/src/pins/pins_MKS_SBASE.h
index 19f9e5acf4..39667507d6 100644
--- a/Marlin/src/pins/pins_MKS_SBASE.h
+++ b/Marlin/src/pins/pins_MKS_SBASE.h
@@ -28,8 +28,12 @@
   #error "Oops! Make sure you have the LPC1768 environment selected in your IDE."
 #endif
 
-#define BOARD_NAME        "MKS SBASE"
-#define BOARD_WEBSITE_URL "https://github.com/makerbase-mks/MKS-SBASE"
+#ifndef BOARD_NAME
+  #define BOARD_NAME        "MKS SBASE"
+#endif
+#ifndef BOARD_WEBSITE_URL
+  #define BOARD_WEBSITE_URL "https://github.com/makerbase-mks/MKS-SBASE"
+#endif
 
 #define LED_PIN            P1_18   // Used as a status indicator
 #define LED2_PIN           P1_19
@@ -281,7 +285,7 @@
  #endif
 #endif
 
-#if HAS_DRIVER(TMC2208)
+#if MB(MKS_SBASE) && HAS_DRIVER(TMC2208)
   // The shortage of pins becomes apparent.
   // Worst case you may have to give up the LCD
   // RX pins need to be interrupt capable
diff --git a/Marlin/src/pins/pins_MKS_SGEN.h b/Marlin/src/pins/pins_MKS_SGEN.h
new file mode 100644
index 0000000000..2aa6bcc551
--- /dev/null
+++ b/Marlin/src/pins/pins_MKS_SGEN.h
@@ -0,0 +1,60 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (C) 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * Based on Sprinter and grbl.
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+/**
+ * MKS SGen pin assignments
+ */
+
+#ifndef LPC1769
+  #error "Oops! Make sure you have the LPC1769 environment selected in your IDE."
+#endif
+
+#define BOARD_NAME        "MKS SGEN"
+#define BOARD_WEBSITE_URL "https://github.com/makerbase-mks/MKS-SGEN"
+
+#include "pins_MKS_SBASE.h"
+
+#undef E1_STEP_PIN
+#undef E1_DIR_PIN
+#undef E1_ENABLE_PIN
+
+//#undef BTN_EN1
+//#undef BTN_EN2
+//#define BTN_EN1        P1_23   // EXP2.5
+//#define BTN_EN2        P1_22   // EXP2.3
+
+#if HAS_DRIVER(TMC2208)
+  // The shortage of pins becomes apparent.
+  // In the worst case you may have to give up the LCD.
+  // RX pins must be interrupt-capable.
+  #define X_SERIAL_TX_PIN  P4_29   // J8-2
+  #define X_SERIAL_RX_PIN  P4_29   // J8-2
+
+  #define Y_SERIAL_TX_PIN  P2_08   // J8-3
+  #define Y_SERIAL_RX_PIN  P2_08   // J8-3
+
+  #define Z_SERIAL_TX_PIN  P2_11   // J8-4
+  #define Z_SERIAL_RX_PIN  P2_11   // J8-4
+  #define E0_SERIAL_TX_PIN P2_13   // J8-5
+  #define E0_SERIAL_RX_PIN P2_13   // J8-5
+#endif
-- 
GitLab