From 54326fb06a2306455d5ab04809cb911393c26909 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Wed, 6 Sep 2017 06:28:32 -0500
Subject: [PATCH] HAL updates

---
 .../CMSIS/LPC1768/driver/lpc17xx_emac.c       |   2 +-
 .../CMSIS/LPC1768/lib/LiquidCrystal.cpp       |  72 ++---
 .../frameworks/CMSIS/LPC1768/lib/Stream.cpp   |   2 +-
 Marlin/src/HAL/HAL.h                          |   4 +-
 Marlin/src/HAL/HAL_AVR/HAL_AVR.cpp            |   4 +-
 Marlin/src/HAL/HAL_AVR/HAL_pinsDebug_AVR.h    |   6 +-
 Marlin/src/HAL/HAL_AVR/HAL_spi_AVR.cpp        |   2 +-
 Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp       |   5 +-
 Marlin/src/HAL/HAL_AVR/MarlinSerial.h         |   2 +-
 Marlin/src/HAL/HAL_AVR/endstop_interrupts.h   |   3 +-
 Marlin/src/HAL/HAL_AVR/fastio_AVR.h           |   9 +-
 .../src/HAL/HAL_AVR/persistent_store_impl.cpp |   5 +-
 Marlin/src/HAL/HAL_AVR/pinsDebug_AVR_8_bit.h  |  10 +-
 Marlin/src/HAL/HAL_AVR/servo_AVR.cpp          |   2 +-
 Marlin/src/HAL/HAL_AVR/watchdog_AVR.cpp       |   4 +-
 Marlin/src/HAL/HAL_DUE/HAL_Due.h              |   8 +-
 Marlin/src/HAL/HAL_DUE/HAL_spi_Due.cpp        |   2 +-
 Marlin/src/HAL/HAL_DUE/Servo_Due.cpp          |   2 +-
 .../src/HAL/HAL_DUE/persistent_store_impl.cpp |   5 +-
 Marlin/src/HAL/HAL_DUE/watchdog_Due.cpp       |   2 +-
 Marlin/src/HAL/HAL_DUE/watchdog_Due.h         |   6 +-
 Marlin/src/HAL/HAL_LPC1768/HAL.cpp            |  44 ++-
 Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp        |   2 +-
 Marlin/src/HAL/HAL_LPC1768/HardwareSerial.cpp |   2 +-
 Marlin/src/HAL/HAL_LPC1768/LPC1768_Servo.cpp  |   2 +-
 Marlin/src/HAL/HAL_LPC1768/LPC1768_Servo.h    |  42 +--
 Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp |   2 +-
 Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.h   |  10 +-
 Marlin/src/HAL/HAL_LPC1768/WInterrupts.cpp    | 294 ++++++++----------
 Marlin/src/HAL/HAL_LPC1768/arduino.cpp        |   8 +-
 Marlin/src/HAL/HAL_LPC1768/arduino.h          |  26 +-
 .../HAL/HAL_LPC1768/lpc1768_flag_script.py    |   2 +-
 .../HAL/HAL_LPC1768/persistent_store_impl.cpp |  22 +-
 Marlin/src/HAL/HAL_LPC1768/pinmapping.h       |   4 +-
 Marlin/src/HAL/HAL_LPC1768/pinsDebug_Re_ARM.h |   2 +-
 Marlin/src/HAL/HAL_LPC1768/servo_private.h    |  10 +-
 Marlin/src/HAL/HAL_LPC1768/watchdog.cpp       |   2 +-
 .../HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.cpp  |   2 +-
 Marlin/src/HAL/HAL_TEENSY35_36/HAL_Teensy.h   |  10 +-
 .../HAL/HAL_TEENSY35_36/HAL_spi_Teensy.cpp    |   2 +-
 .../HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h   |   1 -
 .../HAL_TEENSY35_36/persistent_store_impl.cpp |  17 +-
 .../HAL/HAL_TEENSY35_36/watchdog_Teensy.cpp   |   2 +-
 .../src/HAL/HAL_TEENSY35_36/watchdog_Teensy.h |  10 +-
 Marlin/src/HAL/HAL_spi_pins.h                 |   2 -
 Marlin/src/HAL/I2cEeprom.cpp                  |   2 +-
 Marlin/src/HAL/SpiEeprom.cpp                  |   2 +-
 Marlin/src/HAL/math_32bit.h                   |   2 +-
 Marlin/src/HAL/persistent_store_api.h         |   7 +-
 Marlin/src/HAL/servo.cpp                      |   2 +-
 Marlin/src/HAL/servo.h                        |   2 +-
 Marlin/src/HAL/servo_private.h                |  11 +-
 52 files changed, 327 insertions(+), 378 deletions(-)

diff --git a/Marlin/frameworks/CMSIS/LPC1768/driver/lpc17xx_emac.c b/Marlin/frameworks/CMSIS/LPC1768/driver/lpc17xx_emac.c
index dc6c83061fd..f0e4e4627ee 100644
--- a/Marlin/frameworks/CMSIS/LPC1768/driver/lpc17xx_emac.c
+++ b/Marlin/frameworks/CMSIS/LPC1768/driver/lpc17xx_emac.c
@@ -497,7 +497,7 @@ int32_t EMAC_SetPHYMode(uint32_t ulPHYMode)
 #endif
 			/* Wait to complete Auto_Negotiation */
 			for (tout = EMAC_PHY_RESP_TOUT; tout>=0; tout--) {
-				
+
 			}
 			break;
 		case EMAC_MODE_10M_FULL:
diff --git a/Marlin/frameworks/CMSIS/LPC1768/lib/LiquidCrystal.cpp b/Marlin/frameworks/CMSIS/LPC1768/lib/LiquidCrystal.cpp
index 43bce49b265..fdac5629617 100644
--- a/Marlin/frameworks/CMSIS/LPC1768/lib/LiquidCrystal.cpp
+++ b/Marlin/frameworks/CMSIS/LPC1768/lib/LiquidCrystal.cpp
@@ -3,22 +3,22 @@
 #include <stdio.h>
 #include <string.h>
 #include <inttypes.h>
-#include "../../../../src/HAL/HAL_LPC1768/arduino.h"
+#include <HAL_LPC1768/arduino.h>
 
 // When the display powers up, it is configured as follows:
 //
 // 1. Display clear
-// 2. Function set: 
-//    DL = 1; 8-bit interface data 
-//    N = 0; 1-line display 
-//    F = 0; 5x8 dot character font 
-// 3. Display on/off control: 
-//    D = 0; Display off 
-//    C = 0; Cursor off 
-//    B = 0; Blinking off 
-// 4. Entry mode set: 
-//    I/D = 1; Increment by 1 
-//    S = 0; No shift 
+// 2. Function set:
+//    DL = 1; 8-bit interface data
+//    N = 0; 1-line display
+//    F = 0; 5x8 dot character font
+// 3. Display on/off control:
+//    D = 0; Display off
+//    C = 0; Cursor off
+//    B = 0; Blinking off
+// 4. Entry mode set:
+//    I/D = 1; Increment by 1
+//    S = 0; No shift
 //
 // Note, however, that resetting the Arduino doesn't reset the LCD, so we
 // can't assume that its in that state when a sketch starts (and the
@@ -57,22 +57,22 @@ void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t en
   _rs_pin = rs;
   _rw_pin = rw;
   _enable_pin = enable;
-  
+
   _data_pins[0] = d0;
   _data_pins[1] = d1;
   _data_pins[2] = d2;
-  _data_pins[3] = d3; 
+  _data_pins[3] = d3;
   _data_pins[4] = d4;
   _data_pins[5] = d5;
   _data_pins[6] = d6;
-  _data_pins[7] = d7; 
+  _data_pins[7] = d7;
 
   if (fourbitmode)
     _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
-  else 
+  else
     _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS;
-  
-  begin(16, 1);  
+
+  begin(16, 1);
 }
 
 void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
@@ -81,7 +81,7 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
   }
   _numlines = lines;
 
-  setRowOffsets(0x00, 0x40, 0x00 + cols, 0x40 + cols);  
+  setRowOffsets(0x00, 0x40, 0x00 + cols, 0x40 + cols);
 
   // for some 1 line displays you can select a 10 pixel high font
   if ((dotsize != LCD_5x8DOTS) && (lines == 1)) {
@@ -90,28 +90,28 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
 
   pinMode(_rs_pin, OUTPUT);
   // we can save 1 pin by not using RW. Indicate by passing 255 instead of pin#
-  if (_rw_pin != 255) { 
+  if (_rw_pin != 255) {
     pinMode(_rw_pin, OUTPUT);
   }
   pinMode(_enable_pin, OUTPUT);
-  
+
   // Do these once, instead of every time a character is drawn for speed reasons.
   for (int i=0; i<((_displayfunction & LCD_8BITMODE) ? 8 : 4); ++i)
   {
     pinMode(_data_pins[i], OUTPUT);
-   } 
+   }
 
   // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
   // according to datasheet, we need at least 40ms after power rises above 2.7V
   // before sending commands. Arduino can turn on way before 4.5V so we'll wait 50
-  delayMicroseconds(50000); 
+  delayMicroseconds(50000);
   // Now we pull both RS and R/W low to begin commands
   digitalWrite(_rs_pin, LOW);
   digitalWrite(_enable_pin, LOW);
-  if (_rw_pin != 255) { 
+  if (_rw_pin != 255) {
     digitalWrite(_rw_pin, LOW);
   }
-  
+
   //put the LCD into 4 bit or 8 bit mode
   if (! (_displayfunction & LCD_8BITMODE)) {
     // this is according to the hitachi HD44780 datasheet
@@ -124,13 +124,13 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
     // second try
     write4bits(0x03);
     delayMicroseconds(4500); // wait min 4.1ms
-    
+
     // third go!
-    write4bits(0x03); 
+    write4bits(0x03);
     delayMicroseconds(150);
 
     // finally, set to 4-bit interface
-    write4bits(0x02); 
+    write4bits(0x02);
   } else {
     // this is according to the hitachi HD44780 datasheet
     // page 45 figure 23
@@ -148,10 +148,10 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
   }
 
   // finally, set # lines, font size, etc.
-  command(LCD_FUNCTIONSET | _displayfunction);  
+  command(LCD_FUNCTIONSET | _displayfunction);
 
   // turn the display on with no cursor or blinking default
-  _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;  
+  _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
   display();
 
   // clear it off
@@ -194,7 +194,7 @@ void LiquidCrystal::setCursor(uint8_t col, uint8_t row)
   if ( row >= _numlines ) {
     row = _numlines - 1;    // we count rows starting w/0
   }
-  
+
   command(LCD_SETDDRAMADDR | (col + _row_offsets[row]));
 }
 
@@ -288,12 +288,12 @@ void LiquidCrystal::send(uint8_t value, uint8_t mode) {
   digitalWrite(_rs_pin, mode);
 
   // if there is a RW pin indicated, set it low to Write
-  if (_rw_pin != 255) { 
+  if (_rw_pin != 255) {
     digitalWrite(_rw_pin, LOW);
   }
-  
+
   if (_displayfunction & LCD_8BITMODE) {
-    write8bits(value); 
+    write8bits(value);
   } else {
     write4bits(value>>4);
     write4bits(value);
@@ -302,7 +302,7 @@ void LiquidCrystal::send(uint8_t value, uint8_t mode) {
 
 void LiquidCrystal::pulseEnable(void) {
   digitalWrite(_enable_pin, LOW);
-  delayMicroseconds(1);    
+  delayMicroseconds(1);
   digitalWrite(_enable_pin, HIGH);
   delayMicroseconds(1);    // enable pulse must be >450ns
   digitalWrite(_enable_pin, LOW);
@@ -321,6 +321,6 @@ void LiquidCrystal::write8bits(uint8_t value) {
   for (int i = 0; i < 8; i++) {
     digitalWrite(_data_pins[i], (value >> i) & 0x01);
   }
-  
+
   pulseEnable();
 }
diff --git a/Marlin/frameworks/CMSIS/LPC1768/lib/Stream.cpp b/Marlin/frameworks/CMSIS/LPC1768/lib/Stream.cpp
index b1e507e9e8c..6a54327d286 100644
--- a/Marlin/frameworks/CMSIS/LPC1768/lib/Stream.cpp
+++ b/Marlin/frameworks/CMSIS/LPC1768/lib/Stream.cpp
@@ -23,7 +23,7 @@
  */
 
 #include <stdlib.h>
-#include "../../../../src/HAL/HAL_LPC1768/arduino.h"
+#include <HAL_LPC1768/arduino.h>
 
 #include "Stream.h"
 
diff --git a/Marlin/src/HAL/HAL.h b/Marlin/src/HAL/HAL.h
index fd9cbbff205..897096ab16d 100644
--- a/Marlin/src/HAL/HAL.h
+++ b/Marlin/src/HAL/HAL.h
@@ -92,7 +92,7 @@ void spiSendBlock(uint8_t token, const uint8_t* buf);
   #include "math_32bit.h"
   #include "HAL_LPC1768/HAL.h"
 #else
-  #error Unsupported Platform!
+  #error "Unsupported Platform!"
 #endif
 
-#endif /* HAL_H_ */
+#endif // _HAL_H
diff --git a/Marlin/src/HAL/HAL_AVR/HAL_AVR.cpp b/Marlin/src/HAL/HAL_AVR/HAL_AVR.cpp
index c572b2ccab9..92e8fdf498f 100644
--- a/Marlin/src/HAL/HAL_AVR/HAL_AVR.cpp
+++ b/Marlin/src/HAL/HAL_AVR/HAL_AVR.cpp
@@ -34,7 +34,7 @@
 // --------------------------------------------------------------------------
 
 #include "../HAL.h"
-#include "../../../macros.h"
+#include "../../core/macros.h"
 
 // --------------------------------------------------------------------------
 // Externals
@@ -75,7 +75,7 @@
 // --------------------------------------------------------------------------
 
 #if ENABLED(SDSUPPORT)
-  #include "../../../SdFatUtil.h"
+  #include "../../sd/SdFatUtil.h"
   int freeMemory() { return SdFatUtil::FreeRam(); }
 #else
 
diff --git a/Marlin/src/HAL/HAL_AVR/HAL_pinsDebug_AVR.h b/Marlin/src/HAL/HAL_AVR/HAL_pinsDebug_AVR.h
index 51108196a10..92e4f48ea57 100644
--- a/Marlin/src/HAL/HAL_AVR/HAL_pinsDebug_AVR.h
+++ b/Marlin/src/HAL/HAL_AVR/HAL_pinsDebug_AVR.h
@@ -56,7 +56,7 @@ bool endstop_monitor_flag = false;
 #define REPORT_NAME_DIGITAL(NAME, COUNTER) _ADD_PIN(#NAME, COUNTER)
 #define REPORT_NAME_ANALOG(NAME, COUNTER) _ADD_PIN(#NAME, COUNTER)
 
-#include "../../../pinsDebug_list.h"
+#include "../../pins/pinsDebug_list.h"
 #line 51
 
 // manually add pins that have names that are macros which don't play well with these macros
@@ -107,7 +107,7 @@ const PinInfo pin_array[] PROGMEM = {
     #endif
   #endif
 
-  #include "../../../pinsDebug_list.h"
+  #include "../../pins/pinsDebug_list.h"
   #line 102
 
 };
@@ -483,7 +483,7 @@ inline void report_pin_state_extended(int8_t pin, bool ignore, bool extended = f
         SERIAL_CHAR('.');
         SERIAL_ECHO_SP(26 + strlen(start_string));  // add padding if not the first instance found
       }
-      name_mem_pointer = (char*)pgm_read_word(&pin_array[x].name);
+      name_mem_pointer = (char*)pgm_read_ptr(&pin_array[x].name);
       for (uint8_t y = 0; y < 28; y++) {                   // always print pin name
         temp_char = pgm_read_byte(name_mem_pointer + y);
         if (temp_char != 0)
diff --git a/Marlin/src/HAL/HAL_AVR/HAL_spi_AVR.cpp b/Marlin/src/HAL/HAL_AVR/HAL_spi_AVR.cpp
index 128e73555c4..b0f0f45a440 100644
--- a/Marlin/src/HAL/HAL_AVR/HAL_spi_AVR.cpp
+++ b/Marlin/src/HAL/HAL_AVR/HAL_spi_AVR.cpp
@@ -37,7 +37,7 @@
 // Includes
 // --------------------------------------------------------------------------
 
-#include "../../../MarlinConfig.h"
+#include "../../inc/MarlinConfig.h"
 
 // --------------------------------------------------------------------------
 // Public Variables
diff --git a/Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp b/Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp
index b4f03f5f075..6c82379e1fe 100644
--- a/Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp
+++ b/Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp
@@ -31,7 +31,7 @@
 #ifdef ARDUINO_ARCH_AVR
 
 #include "MarlinSerial.h"
-#include "../../../Marlin.h"
+#include "../../Marlin.h"
 
 // Disable HardwareSerial.cpp to support chips without a UART (Attiny, etc.)
 
@@ -47,8 +47,7 @@
 
   #if ENABLED(EMERGENCY_PARSER)
 
-    #include "../../../stepper.h"
-    #include "../../../language.h"
+    #include "../../module/stepper.h"
 
     // Currently looking for: M108, M112, M410
     // If you alter the parser please don't forget to update the capabilities in Conditionals_post.h
diff --git a/Marlin/src/HAL/HAL_AVR/MarlinSerial.h b/Marlin/src/HAL/HAL_AVR/MarlinSerial.h
index cf96330f569..0448e5502cb 100644
--- a/Marlin/src/HAL/HAL_AVR/MarlinSerial.h
+++ b/Marlin/src/HAL/HAL_AVR/MarlinSerial.h
@@ -32,7 +32,7 @@
 #ifndef MARLINSERIAL_H
 #define MARLINSERIAL_H
 
-#include "../../../MarlinConfig.h"
+#include "../../inc/MarlinConfig.h"
 
 #include <WString.h>
 
diff --git a/Marlin/src/HAL/HAL_AVR/endstop_interrupts.h b/Marlin/src/HAL/HAL_AVR/endstop_interrupts.h
index 10aa6529637..d78ee97510c 100644
--- a/Marlin/src/HAL/HAL_AVR/endstop_interrupts.h
+++ b/Marlin/src/HAL/HAL_AVR/endstop_interrupts.h
@@ -38,7 +38,8 @@
 #ifndef _ENDSTOP_INTERRUPTS_H_
 #define _ENDSTOP_INTERRUPTS_H_
 
-#include "../../../macros.h"
+#include "../../core/macros.h"
+#include <stdint.h>
 
 /**
  * Patch for pins_arduino.h (...\Arduino\hardware\arduino\avr\variants\mega\pins_arduino.h)
diff --git a/Marlin/src/HAL/HAL_AVR/fastio_AVR.h b/Marlin/src/HAL/HAL_AVR/fastio_AVR.h
index 035e3a5d126..5e3292d8224 100644
--- a/Marlin/src/HAL/HAL_AVR/fastio_AVR.h
+++ b/Marlin/src/HAL/HAL_AVR/fastio_AVR.h
@@ -30,7 +30,7 @@
 #define _FASTIO_ARDUINO_H
 
 #include <avr/io.h>
-#include "../../../macros.h"
+#include "../../core/macros.h"
 
 #define AVR_AT90USB1286_FAMILY (defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1286P__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB646P__)  || defined(__AVR_AT90USB647__))
 #define AVR_ATmega1284_FAMILY (defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284P__))
@@ -168,6 +168,7 @@ typedef enum {
 } ClockSource2;
 
 // Get interrupt bits in an orderly way
+// Ex: cs = GET_CS(0); coma1 = GET_COM(A,1);
 #define GET_WGM(T)   (((TCCR##T##A >> WGM##T##0) & 0x3) | ((TCCR##T##B >> WGM##T##2 << 2) & 0xC))
 #define GET_CS(T)    ((TCCR##T##B >> CS##T##0) & 0x7)
 #define GET_COM(T,Q) ((TCCR##T##Q >> COM##T##Q##0) & 0x3)
@@ -182,6 +183,7 @@ typedef enum {
 #define GET_FOCC(T)  GET_FOC(T,C)
 
 // Set Wave Generation Mode bits
+// Ex: SET_WGM(5,CTC_ICRn);
 #define _SET_WGM(T,V) do{ \
     TCCR##T##A = (TCCR##T##A & ~(0x3 << WGM##T##0)) | (( int(V)       & 0x3) << WGM##T##0); \
     TCCR##T##B = (TCCR##T##B & ~(0x3 << WGM##T##2)) | (((int(V) >> 2) & 0x3) << WGM##T##2); \
@@ -189,6 +191,7 @@ typedef enum {
 #define SET_WGM(T,V) _SET_WGM(T,WGM_##V)
 
 // Set Clock Select bits
+// Ex: SET_CS3(PRESCALER_64);
 #define _SET_CS(T,V) (TCCR##T##B = (TCCR##T##B & ~(0x7 << CS##T##0)) | ((int(V) & 0x7) << CS##T##0))
 #define _SET_CS0(V) _SET_CS(0,V)
 #define _SET_CS1(V) _SET_CS(1,V)
@@ -213,6 +216,7 @@ typedef enum {
 #define SET_CS(T,V) SET_CS##T(V)
 
 // Set Compare Mode bits
+// Ex: SET_COMS(4,CLEAR_SET,CLEAR_SET,CLEAR_SET);
 #define _SET_COM(T,Q,V) (TCCR##T##Q = (TCCR##T##Q & ~(0x3 << COM##T##Q##0)) | (int(V) << COM##T##Q##0))
 #define SET_COM(T,Q,V) _SET_COM(T,Q,COM_##V)
 #define SET_COMA(T,V) SET_COM(T,A,V)
@@ -221,12 +225,15 @@ typedef enum {
 #define SET_COMS(T,V1,V2,V3) do{ SET_COMA(T,V1); SET_COMB(T,V2); SET_COMC(T,V3); }while(0)
 
 // Set Noise Canceler bit
+// Ex: SET_ICNC(2,1)
 #define SET_ICNC(T,V) (TCCR##T##B = (V) ? TCCR##T##B | _BV(ICNC##T) : TCCR##T##B & ~_BV(ICNC##T))
 
 // Set Input Capture Edge Select bit
+// Ex: SET_ICES(5,0)
 #define SET_ICES(T,V) (TCCR##T##B = (V) ? TCCR##T##B | _BV(ICES##T) : TCCR##T##B & ~_BV(ICES##T))
 
 // Set Force Output Compare bit
+// Ex: SET_FOC(3,A,1)
 #define SET_FOC(T,Q,V) (TCCR##T##C = (V) ? TCCR##T##C | _BV(FOC##T##Q) : TCCR##T##C & ~_BV(FOC##T##Q))
 #define SET_FOCA(T,V) SET_FOC(T,A,V)
 #define SET_FOCB(T,V) SET_FOC(T,B,V)
diff --git a/Marlin/src/HAL/HAL_AVR/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_AVR/persistent_store_impl.cpp
index a4017a14458..ff26673fb4d 100644
--- a/Marlin/src/HAL/HAL_AVR/persistent_store_impl.cpp
+++ b/Marlin/src/HAL/HAL_AVR/persistent_store_impl.cpp
@@ -2,10 +2,7 @@
 
 #include "../persistent_store_api.h"
 
-#include "../../../types.h"
-#include "../../../language.h"
-#include "../../../serial.h"
-#include "../../../utility.h"
+#include "../../inc/MarlinConfig.h"
 
 #if ENABLED(EEPROM_SETTINGS)
 
diff --git a/Marlin/src/HAL/HAL_AVR/pinsDebug_AVR_8_bit.h b/Marlin/src/HAL/HAL_AVR/pinsDebug_AVR_8_bit.h
index a65b28f519c..9343b3b284d 100644
--- a/Marlin/src/HAL/HAL_AVR/pinsDebug_AVR_8_bit.h
+++ b/Marlin/src/HAL/HAL_AVR/pinsDebug_AVR_8_bit.h
@@ -54,13 +54,13 @@
   #define GET_ARRAY_PIN(p) pgm_read_byte(&pin_array[p].pin)
 #endif
 
-#define VALID_PIN(pin)) (pin >= 0 && pin < NUM_DIGITAL_PINS ? 1 : 0)
+#define VALID_PIN(pin) (pin >= 0 && pin < NUM_DIGITAL_PINS ? 1 : 0)
 #define DIGITAL_PIN_TO_ANALOG_PIN(p) int(p - analogInputToDigitalPin(0))
 #define IS_ANALOG(P) ((P) >= analogInputToDigitalPin(0) && ((P) <= analogInputToDigitalPin(15) || (P) <= analogInputToDigitalPin(7)))
 #define GET_ARRAY_PIN(p) pgm_read_byte(&pin_array[p].pin)
 
 void PRINT_ARRAY_NAME(uint8_t x) {
-  char *name_mem_pointer = (char*)pgm_read_word(&pin_array[x].name);
+  char *name_mem_pointer = (char*)pgm_read_ptr(&pin_array[x].name);
   for (uint8_t y = 0; y < MAX_NAME_LENGTH; y++) {
     char temp_char = pgm_read_byte(name_mem_pointer + y);
     if (temp_char != 0)
@@ -362,7 +362,8 @@ static void pwm_details(uint8_t pin) {
   }
 #endif
 
-#ifndef PRINT_PORT(p)
+#ifndef PRINT_PORT
+
   void print_port(int8_t pin) {   // print port number
     #ifdef digitalPinToPort_DEBUG
       uint8_t x;
@@ -394,4 +395,7 @@ static void pwm_details(uint8_t pin) {
   }
   
   #define PRINT_PORT(p) print_port(p)
+
 #endif
+
+#define GET_PIN_INFO(pin) do{}while(0)
diff --git a/Marlin/src/HAL/HAL_AVR/servo_AVR.cpp b/Marlin/src/HAL/HAL_AVR/servo_AVR.cpp
index a57b823ba27..f6d808fde90 100644
--- a/Marlin/src/HAL/HAL_AVR/servo_AVR.cpp
+++ b/Marlin/src/HAL/HAL_AVR/servo_AVR.cpp
@@ -53,7 +53,7 @@
 
 #ifdef ARDUINO_ARCH_AVR
 
-#include "../../../MarlinConfig.h"
+#include "../../inc/MarlinConfig.h"
 
 #if HAS_SERVOS
 
diff --git a/Marlin/src/HAL/HAL_AVR/watchdog_AVR.cpp b/Marlin/src/HAL/HAL_AVR/watchdog_AVR.cpp
index eb412ed2522..0de550eb928 100644
--- a/Marlin/src/HAL/HAL_AVR/watchdog_AVR.cpp
+++ b/Marlin/src/HAL/HAL_AVR/watchdog_AVR.cpp
@@ -22,13 +22,13 @@
 
 #ifdef ARDUINO_ARCH_AVR
 
-#include "../../../MarlinConfig.h"
+#include "../../inc/MarlinConfig.h"
 
 #if ENABLED(USE_WATCHDOG)
 
 #include "watchdog_AVR.h"
 
-#include "../../../Marlin.h"
+#include "../../Marlin.h"
 
 // Initialize watchdog with a 4 sec interrupt time
 void watchdog_init() {
diff --git a/Marlin/src/HAL/HAL_DUE/HAL_Due.h b/Marlin/src/HAL/HAL_DUE/HAL_Due.h
index 6280cbab9d5..2b8cca80988 100644
--- a/Marlin/src/HAL/HAL_DUE/HAL_Due.h
+++ b/Marlin/src/HAL/HAL_DUE/HAL_Due.h
@@ -74,9 +74,15 @@
   #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
 #endif
 
+#ifndef vsnprintf_P
+  #define vsnprintf_P vsnprintf
+#endif
+
 // Fix bug in pgm_read_ptr
 #undef pgm_read_ptr
-#define pgm_read_ptr(addr) (*(addr))
+#define pgm_read_ptr(addr) (*((void**)(addr)))
+#undef pgm_read_word
+#define pgm_read_word(addr) (*((uint16_t*)(addr)))
 
 #define RST_POWER_ON   1
 #define RST_EXTERNAL   2
diff --git a/Marlin/src/HAL/HAL_DUE/HAL_spi_Due.cpp b/Marlin/src/HAL/HAL_DUE/HAL_spi_Due.cpp
index 2a7aa807049..ee2fa1b1145 100644
--- a/Marlin/src/HAL/HAL_DUE/HAL_spi_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/HAL_spi_Due.cpp
@@ -37,7 +37,7 @@
 // Includes
 // --------------------------------------------------------------------------
 
-#include "../../../MarlinConfig.h"
+#include "../../inc/MarlinConfig.h"
 
 // --------------------------------------------------------------------------
 // Public Variables
diff --git a/Marlin/src/HAL/HAL_DUE/Servo_Due.cpp b/Marlin/src/HAL/HAL_DUE/Servo_Due.cpp
index 66667cee388..166111baa36 100644
--- a/Marlin/src/HAL/HAL_DUE/Servo_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/Servo_Due.cpp
@@ -40,7 +40,7 @@
 
 #ifdef ARDUINO_ARCH_SAM
 
-#include "../../../MarlinConfig.h"
+#include "../../inc/MarlinConfig.h"
 
 #if HAS_SERVOS
 
diff --git a/Marlin/src/HAL/HAL_DUE/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_DUE/persistent_store_impl.cpp
index 3ada740207a..2a1caffb63f 100644
--- a/Marlin/src/HAL/HAL_DUE/persistent_store_impl.cpp
+++ b/Marlin/src/HAL/HAL_DUE/persistent_store_impl.cpp
@@ -2,10 +2,7 @@
 
 #include "../persistent_store_api.h"
 
-#include "../../../types.h"
-#include "../../../language.h"
-#include "../../../serial.h"
-#include "../../../utility.h"
+#include "../../inc/MarlinConfig.h"
 
 #if ENABLED(EEPROM_SETTINGS)
 
diff --git a/Marlin/src/HAL/HAL_DUE/watchdog_Due.cpp b/Marlin/src/HAL/HAL_DUE/watchdog_Due.cpp
index 00a992d750d..55c5ac8cfb5 100644
--- a/Marlin/src/HAL/HAL_DUE/watchdog_Due.cpp
+++ b/Marlin/src/HAL/HAL_DUE/watchdog_Due.cpp
@@ -22,7 +22,7 @@
 
 #ifdef ARDUINO_ARCH_SAM
  
-#include "../../../MarlinConfig.h"
+#include "../../inc/MarlinConfig.h"
 
 #if ENABLED(USE_WATCHDOG)
 
diff --git a/Marlin/src/HAL/HAL_DUE/watchdog_Due.h b/Marlin/src/HAL/HAL_DUE/watchdog_Due.h
index 1b4c68b01ba..be8afd2e81e 100644
--- a/Marlin/src/HAL/HAL_DUE/watchdog_Due.h
+++ b/Marlin/src/HAL/HAL_DUE/watchdog_Due.h
@@ -23,10 +23,10 @@
 #ifndef WATCHDOG_DUE_H
 #define WATCHDOG_DUE_H
 
-//#include "../../../Marlin.h"
-
 // Arduino Due core now has watchdog support
 
+#include "../HAL.h"
+
 // Initialize watchdog with a 4 second interrupt time
 void watchdog_init();
 
@@ -34,4 +34,4 @@ void watchdog_init();
 // first watchdog_init or AVR will go into emergency procedures.
 inline void watchdog_reset() { watchdogReset(); }
 
-#endif /* WATCHDOG_DUE_H */
+#endif // WATCHDOG_DUE_H
diff --git a/Marlin/src/HAL/HAL_LPC1768/HAL.cpp b/Marlin/src/HAL/HAL_LPC1768/HAL.cpp
index ca3fb7e66a4..181180fe465 100644
--- a/Marlin/src/HAL/HAL_LPC1768/HAL.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/HAL.cpp
@@ -18,16 +18,13 @@
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ****************************************************************************/
 
-
-/**
- *
- * For TARGET_LPC1768
- */
-
 #ifdef TARGET_LPC1768
-#include "../../../macros.h"
+
+#include "../../core/macros.h"
 #include "../HAL.h"
 
+#include <stdint.h>
+
 extern "C" {
   //#include <lpc17xx_adc.h>
   //#include <lpc17xx_pinsel.h>
@@ -51,7 +48,7 @@ extern "C" void u8g_Delay(uint16_t val) {
 //************************//
 
 // return free heap space
-int freeMemory(){
+int freeMemory() {
   char stack_end;
   void *heap_start = malloc(sizeof(uint32_t));
   if (heap_start == 0) return 0;
@@ -82,22 +79,22 @@ void HAL_adc_init(void) {
 }
 
 // externals need to make the call to KILL compile
-#include "../../../language.h"
+#include "../../core/language.h"
 
 extern void kill(const char*);
 extern const char errormagic[];
 
 void HAL_adc_enable_channel(int pin) {
-  if (pin < 0 || pin >= NUM_ANALOG_INPUTS)  {
+  if (!WITHIN(pin, 0, NUM_ANALOG_INPUTS - 1)) {
     usb_serial.printf("%sINVALID ANALOG PORT:%d\n", errormagic, pin);
     kill(MSG_KILLED);
   }
 
-  int8_t pin_port = adc_pin_map[pin].port;
-  int8_t pin_port_pin = adc_pin_map[pin].pin;
-  int8_t pinsel_start_bit = pin_port_pin > 15 ? 2 * (pin_port_pin - 16) : 2 * pin_port_pin;
+  int8_t pin_port = adc_pin_map[pin].port,
+         pin_port_pin = adc_pin_map[pin].pin,
+         pinsel_start_bit = pin_port_pin > 15 ? 2 * (pin_port_pin - 16) : 2 * pin_port_pin;
   uint8_t pin_sel_register = (pin_port == 0 && pin_port_pin <= 15) ? 0 :
-                             (pin_port == 0)                       ? 1 :
+                              pin_port == 0                        ? 1 :
                               pin_port == 1                        ? 3 : 10;
 
   switch (pin_sel_register) {
@@ -117,24 +114,21 @@ void HAL_adc_enable_channel(int pin) {
 }
 
 void HAL_adc_start_conversion(uint8_t adc_pin) {
-  if(  (adc_pin >= NUM_ANALOG_INPUTS) || (adc_pin_map[adc_pin].port == 0xFF) ) {
-    usb_serial.printf("HAL: HAL_adc_start_conversion: no pinmap for %d\n",adc_pin);
+  if (adc_pin >= (NUM_ANALOG_INPUTS) || adc_pin_map[adc_pin].port == 0xFF) {
+    usb_serial.printf("HAL: HAL_adc_start_conversion: no pinmap for %d\n", adc_pin);
     return;
   }
-  LPC_ADC->ADCR &= ~0xFF;                                // Reset
-  LPC_ADC->ADCR |= ( 0x01 << adc_pin_map[adc_pin].adc ); // Select Channel
-  LPC_ADC->ADCR |= ( 0x01 << 24 );                       // start conversion
+  LPC_ADC->ADCR &= ~0xFF;                       // Reset
+  SBI(LPC_ADC->ADCR, adc_pin_map[adc_pin].adc); // Select Channel
+  SBI(LPC_ADC->ADCR, 24);                       // Start conversion
 }
 
-bool HAL_adc_finished(void) {
-  return LPC_ADC->ADGDR & ADC_DONE;
-}
+bool HAL_adc_finished(void) { return LPC_ADC->ADGDR & ADC_DONE; }
 
 uint16_t HAL_adc_get_result(void) {
   uint32_t data = LPC_ADC->ADGDR;
-  LPC_ADC->ADCR &= ~(1 << 24); //stop conversion
-  if ( data & ADC_OVERRUN ) return 0;
-  return ((data >> 6) & 0x3ff); //10bit
+  CBI(LPC_ADC->ADCR, 24);                       // Stop conversion
+  return (data & ADC_OVERRUN) ? 0 : (data >> 6) & 0x3FF; // 10bit
 }
 
 #define SBIT_CNTEN     0
diff --git a/Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp b/Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp
index 55e5d659385..be3ffc605b8 100644
--- a/Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp
@@ -36,7 +36,7 @@
 // Includes
 // --------------------------------------------------------------------------
 
-#include "../../../MarlinConfig.h"
+#include "../../inc/MarlinConfig.h"
 
 // --------------------------------------------------------------------------
 // Public Variables
diff --git a/Marlin/src/HAL/HAL_LPC1768/HardwareSerial.cpp b/Marlin/src/HAL/HAL_LPC1768/HardwareSerial.cpp
index 9d5c392f0c7..69676eab918 100644
--- a/Marlin/src/HAL/HAL_LPC1768/HardwareSerial.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/HardwareSerial.cpp
@@ -22,7 +22,7 @@
 
 #ifdef TARGET_LPC1768
 
-#include "../../../macros.h"
+#include "../../core/macros.h"
 #include "../HAL.h"
 #include "HardwareSerial.h"
 #define UART3 3
diff --git a/Marlin/src/HAL/HAL_LPC1768/LPC1768_Servo.cpp b/Marlin/src/HAL/HAL_LPC1768/LPC1768_Servo.cpp
index f2a311e5a8a..3147b22c8a2 100644
--- a/Marlin/src/HAL/HAL_LPC1768/LPC1768_Servo.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/LPC1768_Servo.cpp
@@ -60,7 +60,7 @@
  * unless DEACTIVATE_SERVOS_AFTER_MOVE is enabled and a MOVE command was issued.
  */
 
-#include "../../../MarlinConfig.h"
+#include "../../inc/MarlinConfig.h"
 
 #if HAS_SERVOS && defined(TARGET_LPC1768)
 
diff --git a/Marlin/src/HAL/HAL_LPC1768/LPC1768_Servo.h b/Marlin/src/HAL/HAL_LPC1768/LPC1768_Servo.h
index 7cbd97826c6..291ca130aa1 100644
--- a/Marlin/src/HAL/HAL_LPC1768/LPC1768_Servo.h
+++ b/Marlin/src/HAL/HAL_LPC1768/LPC1768_Servo.h
@@ -34,29 +34,29 @@
 #ifndef LPC1768_SERVO_H
 #define LPC1768_SERVO_H
 
-#include <inttypes.h>
+#include <stdint.h>
 
-class Servo {
-  public:
-    Servo();
-    int8_t attach(int pin);            // attach the given pin to the next free channel, set pinMode, return channel number (-1 on fail)
-    int8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes.
-    void detach();
-    void write(int value);             // if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds
-    void writeMicroseconds(int value); // write pulse width in microseconds
-    void move(int value);              // attach the servo, then move to value
-                                       // if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds
-                                       // if DEACTIVATE_SERVOS_AFTER_MOVE wait SERVO_DELAY, then detach
-    int read();                        // returns current pulse width as an angle between 0 and 180 degrees
-    int readMicroseconds();            // returns current pulse width in microseconds for this servo (was read_us() in first release)
-    bool attached();                   // return true if this servo is attached, otherwise false
+  class Servo {
+    public:
+      Servo();
+      int8_t attach(int pin);            // attach the given pin to the next free channel, set pinMode, return channel number (-1 on fail)
+      int8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes.
+      void detach();
+      void write(int value);             // if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds
+      void writeMicroseconds(int value); // write pulse width in microseconds
+      void move(int value);              // attach the servo, then move to value
+                                         // if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds
+                                         // if DEACTIVATE_SERVOS_AFTER_MOVE wait SERVO_DELAY, then detach
+      int read();                        // returns current pulse width as an angle between 0 and 180 degrees
+      int readMicroseconds();            // returns current pulse width in microseconds for this servo (was read_us() in first release)
+      bool attached();                   // return true if this servo is attached, otherwise false
 
-  private:
-    uint8_t servoIndex;               // index into the channel data for this servo
-    int min;
-    int max;
-};
+    private:
+      uint8_t servoIndex;               // index into the channel data for this servo
+      int min;
+      int max;
+  };
 
-#define HAL_SERVO_LIB Servo
+  #define HAL_SERVO_LIB Servo
 
 #endif // LPC1768_SERVO_H
diff --git a/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp b/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp
index f89d704f5eb..1196c0bf432 100644
--- a/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp
@@ -35,7 +35,7 @@ http://arduiniana.org.
 // Includes
 //
 //#include <WInterrupts.h>
-#include "../../../macros.h"
+#include "../../core/macros.h"
 #include "../HAL.h"
 #include <stdint.h>
 #include <stdarg.h>
diff --git a/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.h b/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.h
index e78c59744ca..544c7c450ac 100644
--- a/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.h
+++ b/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.h
@@ -29,13 +29,13 @@ The latest version of this library can always be found at
 http://arduiniana.org.
 */
 
-#ifndef SoftwareSerial_h
-#define SoftwareSerial_h
+#ifndef SOFTWARESERIAL_H
+#define SOFTWARESERIAL_H
 
 #include "arduino.h"
-#include <inttypes.h>
+#include <stdint.h>
 //#include "serial.h"
- #include <Stream.h>
+#include <Stream.h>
 #include <Print.h>
 
 /******************************************************************************
@@ -116,4 +116,4 @@ public:
 #undef abs
 #undef round
 
-#endif
+#endif // SOFTWARESERIAL_H
diff --git a/Marlin/src/HAL/HAL_LPC1768/WInterrupts.cpp b/Marlin/src/HAL/HAL_LPC1768/WInterrupts.cpp
index 7bf93c1a7e0..8c2ca1d5e47 100644
--- a/Marlin/src/HAL/HAL_LPC1768/WInterrupts.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/WInterrupts.cpp
@@ -18,7 +18,7 @@
 
 #ifdef TARGET_LPC1768
 
-#include "../../../macros.h"
+#include "../../core/macros.h"
 #include "../HAL.h"
 #include "arduino.h"
 #include "pinmapping.h"
@@ -32,197 +32,159 @@ typedef void (*interruptCB)(void);
 static interruptCB callbacksP0[GNUM];
 static interruptCB callbacksP2[GNUM];
 
-	extern "C" void GpioEnableInt(uint32_t port, uint32_t pin, uint32_t mode);
-	extern "C" void GpioDisableInt(uint32_t port, uint32_t pin);
+extern "C" void GpioEnableInt(const uint32_t port, const uint32_t pin, const uint32_t mode);
+extern "C" void GpioDisableInt(const uint32_t port, const uint32_t pin);
 
 //void deadloop(void) {}
 
 /* Configure PIO interrupt sources */
 static void __initialize() {
-	int i;
-	for (i=0; i<GNUM; i++) {
-		callbacksP0[i] = 0;
-		callbacksP2[i] = 0;
-		}
-NVIC_EnableIRQ(EINT3_IRQn);
+  for (uint8_t i = 0; i < GNUM; i++) {
+    callbacksP0[i] = 0;
+    callbacksP2[i] = 0;
+  }
+  NVIC_EnableIRQ(EINT3_IRQn);
 }
 
-void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode)
-{
-	static int enabled = 0;
+void attachInterrupt(const uint32_t pin, void (*callback)(void), uint32_t mode) {
+  static int enabled = 0;
 
-	if(!INTERRUPT_PIN(pin)) return;
+  if (!INTERRUPT_PIN(pin)) return;
 
-	if (!enabled) {
-		__initialize();
-		enabled = 1;
-	}
-	uint8_t myport = pin_map[pin].port;
-	uint8_t mypin = pin_map[pin].pin;
+  if (!enabled) {
+    __initialize();
+    ++enabled;
+  }
+  uint8_t myport = pin_map[pin].port,
+          mypin = pin_map[pin].pin;
 
+  if (myport == 0)
+    callbacksP0[mypin] = callback;
+  else
+    callbacksP2[mypin] = callback;
 
-	if (myport == 0 )
-		callbacksP0[mypin] = callback;
-	else
-		callbacksP2[mypin] = callback;
-
-	// Enable interrupt
-		GpioEnableInt(myport,mypin,mode);
+  // Enable interrupt
+  GpioEnableInt(myport,mypin,mode);
 }
 
-void detachInterrupt(uint32_t pin)
-{
-	if(!INTERRUPT_PIN(pin)) return;
+void detachInterrupt(const uint32_t pin) {
+  if (!INTERRUPT_PIN(pin)) return;
 
-  uint8_t myport = pin_map[pin].port;
-  uint8_t mypin = pin_map[pin].pin;
+  const uint8_t myport = pin_map[pin].port,
+                mypin = pin_map[pin].pin;
 
-	// Disable interrupt
-	GpioDisableInt(myport,mypin);
+  // Disable interrupt
+  GpioDisableInt(myport, mypin);
 
-//unset callback
-	if (myport == 0 )
-		callbacksP0[mypin] = 0;
-	else //if (myport == 2 )
-		callbacksP2[mypin] = 0;
-	}
-
-
-	extern "C" void GpioEnableInt(uint32_t port, uint32_t pin, uint32_t mode) {
-	//pin here is the processor pin, not logical pin
-	if (port==0) {
-		LPC_GPIOINT->IO0IntClr = (1 << pin);
-		if (mode ==RISING) {
-			LPC_GPIOINT->IO0IntEnR |= (1<<pin);
-  		LPC_GPIOINT->IO0IntEnF &= ~(1<<pin);
-		}
-		else if (mode==FALLING) {
-			LPC_GPIOINT->IO0IntEnF |= (1<<pin);
-  		LPC_GPIOINT->IO0IntEnR &= ~(1<<pin);
-		}
-		else if (mode==CHANGE) {
-		LPC_GPIOINT->IO0IntEnR |= (1<<pin);
-		LPC_GPIOINT->IO0IntEnF |= (1<<pin);
-		}
-	}
-	else{
-		LPC_GPIOINT->IO2IntClr = (1 << pin);
-		if (mode ==RISING) {
-			LPC_GPIOINT->IO2IntEnR |= (1<<pin);
-			LPC_GPIOINT->IO2IntEnF &= ~(1<<pin);
-		}
-		else if (mode==FALLING) {
-			LPC_GPIOINT->IO2IntEnF |= (1<<pin);
-			LPC_GPIOINT->IO2IntEnR &= ~(1<<pin);
-		}
-		else if (mode==CHANGE) {
-		LPC_GPIOINT->IO2IntEnR |= (1<<pin);
-		LPC_GPIOINT->IO2IntEnF |= (1<<pin);
-		}
-	}
-}
-extern "C"  void GpioDisableInt(uint32_t port, uint32_t pin)
-{
-	if (port==0){
-		LPC_GPIOINT->IO0IntEnR &= ~(1<<pin);
-		LPC_GPIOINT->IO0IntEnF &= ~(1<<pin);
-		LPC_GPIOINT->IO0IntClr = 1 << pin;
-	}
-	else {
-		LPC_GPIOINT->IO2IntEnR &= ~(1<<pin);
-		LPC_GPIOINT->IO2IntEnF &= ~(1<<pin);
-		LPC_GPIOINT->IO2IntClr = 1 << pin;
-	}
+  // unset callback
+  if (myport == 0)
+    callbacksP0[mypin] = 0;
+  else //if (myport == 2 )
+    callbacksP2[mypin] = 0;
 }
 
-bool isPowerOf2(unsigned int n)
 
-{
+extern "C" void GpioEnableInt(uint32_t port, uint32_t pin, uint32_t mode) {
+  //pin here is the processor pin, not logical pin
+  if (port == 0) {
+    LPC_GPIOINT->IO0IntClr = _BV(pin);
+    if (mode == RISING) {
+      SBI(LPC_GPIOINT->IO0IntEnR, pin);
+      CBI(LPC_GPIOINT->IO0IntEnF, pin);
+    }
+    else if (mode == FALLING) {
+      SBI(LPC_GPIOINT->IO0IntEnF, pin);
+      CBI(LPC_GPIOINT->IO0IntEnR, pin);
+    }
+    else if (mode == CHANGE) {
+      SBI(LPC_GPIOINT->IO0IntEnR, pin);
+      SBI(LPC_GPIOINT->IO0IntEnF, pin);
+    }
+  }
+  else {
+    LPC_GPIOINT->IO2IntClr = _BV(pin);
+    if (mode == RISING) {
+      SBI(LPC_GPIOINT->IO2IntEnR, pin);
+      CBI(LPC_GPIOINT->IO2IntEnF, pin);
+    }
+    else if (mode == FALLING) {
+      SBI(LPC_GPIOINT->IO2IntEnF, pin);
+      CBI(LPC_GPIOINT->IO2IntEnR, pin);
+    }
+    else if (mode == CHANGE) {
+      SBI(LPC_GPIOINT->IO2IntEnR, pin);
+      SBI(LPC_GPIOINT->IO2IntEnF, pin);
+    }
+  }
+}
 
-    return n == 1 || (n & (n-1)) == 0;
+extern "C" void GpioDisableInt(const uint32_t port, const uint32_t pin) {
+  if (port == 0) {
+    CBI(LPC_GPIOINT->IO0IntEnR, pin);
+    CBI(LPC_GPIOINT->IO0IntEnF, pin);
+    LPC_GPIOINT->IO0IntClr = _BV(pin);
+  }
+  else {
+    CBI(LPC_GPIOINT->IO2IntEnR, pin);
+    CBI(LPC_GPIOINT->IO2IntEnF, pin);
+    LPC_GPIOINT->IO2IntClr = _BV(pin);
+  }
+}
 
+bool isPowerOf2(unsigned int n) {
+  return n == 1 || (n & (n - 1)) == 0;
 }
 
 #if 0
-extern "C" void EINT3_IRQHandler () {
-	LPC_GPIOINT->IO0IntClr = LPC_GPIOINT->IO2IntClr = 0xFFFFFFFF;
-	TOGGLE(13);
-	//NVIC_ClearPendingIRQ(EINT3_IRQn);
-}
+  extern "C" void EINT3_IRQHandler () {
+    LPC_GPIOINT->IO0IntClr = LPC_GPIOINT->IO2IntClr = 0xFFFFFFFF;
+    TOGGLE(13);
+    //NVIC_ClearPendingIRQ(EINT3_IRQn);
+  }
 #else
-extern "C" void EINT3_IRQHandler(void)
-{
-	// Read in all current interrupt registers. We do this once as the
-// GPIO interrupt registers are on the APB bus, and this is slow.
-uint32_t rise0 = LPC_GPIOINT->IO0IntStatR;
-uint32_t fall0 = LPC_GPIOINT->IO0IntStatF;
-uint32_t rise2 = LPC_GPIOINT->IO2IntStatR;
-uint32_t fall2 = LPC_GPIOINT->IO2IntStatF;
-//Clear teh interrupts ASAP
-LPC_GPIOINT->IO0IntClr = LPC_GPIOINT->IO2IntClr = 0xFFFFFFFF;
-NVIC_ClearPendingIRQ(EINT3_IRQn);
-uint8_t bitloc;
-if (rise0 == 0)
-	goto fall0;
-	/* multiple pins changes happened.*/
-	while(rise0 > 0) {      //Continue as long as there are interrupts pending
-			bitloc = 31 - __CLZ(rise0); //CLZ returns number of leading zeros, 31 minus that is location of first pending interrupt
-			if (callbacksP0[bitloc]!=0)
-				callbacksP0[bitloc]();
-			rise0 -= 1<<bitloc;
-	}
-fall0:
-if (fall0==0)
-	goto rise2;
-/* if (isPowerOf2(fall0) && callbacksP0[31 - __CLZ(rise0)])
-  callbacksP0[31 - __CLZ(rise0)](); */
-	//LPC_GPIOINT->IO0IntClr = fall0;*/
-else {
-while(fall0 > 0) {
-		bitloc = 31 - __CLZ(fall0);
-		if (callbacksP0[bitloc]!=0)
-			callbacksP0[bitloc]();
-		fall0 -= 1<<bitloc;
+
+  extern "C" void EINT3_IRQHandler(void) {
+    // Read in all current interrupt registers. We do this once as the
+    // GPIO interrupt registers are on the APB bus, and this is slow.
+    uint32_t rise0 = LPC_GPIOINT->IO0IntStatR,
+             fall0 = LPC_GPIOINT->IO0IntStatF,
+             rise2 = LPC_GPIOINT->IO2IntStatR,
+             fall2 = LPC_GPIOINT->IO2IntStatF;
+    // Clear the interrupts ASAP
+    LPC_GPIOINT->IO0IntClr = LPC_GPIOINT->IO2IntClr = 0xFFFFFFFF;
+    NVIC_ClearPendingIRQ(EINT3_IRQn);
+
+    /* multiple pins changes happened.*/
+    if (rise0) while (rise0 > 0) {      // Continue as long as there are interrupts pending
+      const uint8_t bitloc = 31 - __CLZ(rise0); //CLZ returns number of leading zeros, 31 minus that is location of first pending interrupt
+      if (callbacksP0[bitloc] != NULL) callbacksP0[bitloc]();
+      rise0 -= _BV(bitloc);
+    }
+
+    if (fall0) while (fall0 > 0) {
+      const uint8_t bitloc = 31 - __CLZ(fall0);
+      if (callbacksP0[bitloc] != NULL) callbacksP0[bitloc]();
+      fall0 -= _BV(bitloc);
+    }
+
+    if (rise2) while(rise2 > 0) {
+      const uint8_t bitloc = 31 - __CLZ(rise2);
+      if (callbacksP2[bitloc] != NULL) callbacksP2[bitloc]();
+      //LPC_GPIOINT->IO2IntClr = 1 << bitloc;
+      rise2 -= _BV(bitloc);
+    }
+
+    if (fall2) while (fall2 > 0) {
+      const uint8_t bitloc = 31 - __CLZ(fall2);
+      if (callbacksP2[bitloc] != NULL) callbacksP2[bitloc]();
+      //LPC_GPIOINT->IO2IntClr = 1 << bitloc;
+      fall2 -= _BV(bitloc);
+    }
+    //NVIC_ClearPendingIRQ(EINT3_IRQn);
+    //LPC_GPIOINT->IO0IntClr = LPC_GPIOINT->IO2IntClr = 0xFFFFFFFF;
+    //NVIC_ClearPendingIRQ(EINT3_IRQn);
   }
-}
-rise2:
-if (rise2==0)
-	goto fall2;
-/*if ((rise2 & (rise2 - 1)) == 0) {
-  callbacksP2[rise2]();
-	//LPC_GPIOINT->IO2IntClr = rise2;
-}*/
-else {
-while(rise2 > 0) {
-		bitloc = 31 - __CLZ(rise2);
-		if (callbacksP2[bitloc]!=0)
-			callbacksP2[bitloc]();
-		//LPC_GPIOINT->IO2IntClr = 1 << bitloc;
-		rise2 -= 1<<bitloc;
-  }
-}
-fall2:
-if (fall2==0)
-	goto end;
-/*if ((fall2 & (fall2 - 1)) == 0) {
-  callbacksP2[fall2]();
-	//LPC_GPIOINT->IO2IntClr = fall2;
-}*/
-else {
-while(fall2 > 0) {
-		bitloc = 31 - __CLZ(fall2);
-		if (callbacksP2[bitloc]!=0)
-			callbacksP2[bitloc]();
-		//LPC_GPIOINT->IO2IntClr = 1 << bitloc;
-		fall2 -= 1<<bitloc;
-}
-end:
-//NVIC_ClearPendingIRQ(EINT3_IRQn);
-//LPC_GPIOINT->IO0IntClr = LPC_GPIOINT->IO2IntClr = 0xFFFFFFFF;
-//NVIC_ClearPendingIRQ(EINT3_IRQn);
-return; //silences warning
-}
-}
+
 #endif
 
 #endif // TARGET_LPC1768
diff --git a/Marlin/src/HAL/HAL_LPC1768/arduino.cpp b/Marlin/src/HAL/HAL_LPC1768/arduino.cpp
index 7fec1ac1385..4ea428808b1 100644
--- a/Marlin/src/HAL/HAL_LPC1768/arduino.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/arduino.cpp
@@ -21,19 +21,15 @@
  */
 
 #ifdef TARGET_LPC1768
+
 #include <lpc17xx_pinsel.h>
 #include "HAL.h"
-#include "../../macros.h"
+#include "../../core/macros.h"
 
 // Interrupts
 void cli(void) { __disable_irq(); } // Disable
 void sei(void) { __enable_irq(); }  // Enable
 
-// Program Memory
-void serialprintPGM(const char * str){
-  usb_serial.print(str);
-}
-
 // Time functions
 void _delay_ms(int delay_ms) {
   delay (delay_ms);
diff --git a/Marlin/src/HAL/HAL_LPC1768/arduino.h b/Marlin/src/HAL/HAL_LPC1768/arduino.h
index f34e8217ab4..9fa9c54b3f1 100644
--- a/Marlin/src/HAL/HAL_LPC1768/arduino.h
+++ b/Marlin/src/HAL/HAL_LPC1768/arduino.h
@@ -38,7 +38,7 @@
 
 #define _BV(bit) (1 << (bit))
 
-#define E2END 4096 //EEPROM end address
+#define E2END 0xFFF // EEPROM end address
 
 typedef uint8_t byte;
 #define PROGMEM
@@ -49,10 +49,10 @@ typedef uint8_t byte;
 #define max(a,b) ((a)>(b)?(a):(b))
 #define abs(x) ((x)>0?(x):-(x))
 #ifndef isnan
-#define isnan std::isnan
+  #define isnan std::isnan
 #endif
 #ifndef isinf
-#define isinf std::isinf
+  #define isinf std::isinf
 #endif
 
 //not constexpr until c++14
@@ -73,15 +73,15 @@ extern "C" void GpioEnableInt(uint32_t port, uint32_t pin, uint32_t mode);
 extern "C" void GpioDisableInt(uint32_t port, uint32_t pin);
 
 // Program Memory
-#define pgm_read_ptr(address_short) (*(address_short))
-#define pgm_read_byte_near(address_short) (*address_short)
-#define pgm_read_byte(address_short) pgm_read_byte_near(address_short)
-#define pgm_read_float_near(address_short) (*address_short)
-#define pgm_read_float(address_short) pgm_read_float_near(address_short)
-#define pgm_read_word_near(address_short) (*address_short)
-#define pgm_read_word(address_short) pgm_read_word_near(address_short)
-#define pgm_read_dword_near(address_short) (*address_short)
-#define pgm_read_dword(address_short) pgm_read_dword_near(address_short)
+#define pgm_read_ptr(addr)        (*((void**)(addr)))
+#define pgm_read_byte_near(addr)  (*((uint8_t*)(addr)))
+#define pgm_read_float_near(addr) (*((float*)(addr)))
+#define pgm_read_word_near(addr)  (*((uint16_t*)(addr)))
+#define pgm_read_dword_near(addr) (*((uint32_t*)(addr)))
+#define pgm_read_byte(addr)       pgm_read_byte_near(addr)
+#define pgm_read_float(addr)      pgm_read_float_near(addr)
+#define pgm_read_word(addr)       pgm_read_word_near(addr)
+#define pgm_read_dword(addr)      pgm_read_dword_near(addr)
 
 #define sprintf_P sprintf
 #define strstr_P strstr
@@ -90,8 +90,6 @@ extern "C" void GpioDisableInt(uint32_t port, uint32_t pin);
 #define strcpy_P strcpy
 #define snprintf_P snprintf
 
-void serialprintPGM(const char *);
-
 // Time functions
 extern "C" {
 void delay(int milis);
diff --git a/Marlin/src/HAL/HAL_LPC1768/lpc1768_flag_script.py b/Marlin/src/HAL/HAL_LPC1768/lpc1768_flag_script.py
index a08e222d2e0..47e5bf1e22c 100644
--- a/Marlin/src/HAL/HAL_LPC1768/lpc1768_flag_script.py
+++ b/Marlin/src/HAL/HAL_LPC1768/lpc1768_flag_script.py
@@ -1,4 +1,4 @@
-#dynaomic build flags for generic compile options
+#dynamic build flags for generic compile options
 if __name__ == "__main__":
   print " ".join([  "-std=gnu11",
                     "-std=gnu++11",
diff --git a/Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp
index 9e30547e1fd..a3acfb85774 100644
--- a/Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp
@@ -1,21 +1,17 @@
 #ifdef TARGET_LPC1768
-#include "../persistent_store_api.h"
 
-#include "../../../types.h"
-#include "../../../language.h"
-#include "../../../serial.h"
-#include "../../../utility.h"
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(EEPROM_SETTINGS)
+
+#include "../persistent_store_api.h"
 
 #include "chanfs/diskio.h"
 #include "chanfs/ff.h"
 
-
-#if ENABLED(EEPROM_SETTINGS)
-
 namespace HAL {
 namespace PersistentStore {
 
-
 FATFS fat_fs;
 FIL eeprom_file;
 
@@ -25,7 +21,7 @@ bool access_start() {
   return (res == FR_OK);
 }
 
-bool access_finish(){
+bool access_finish() {
   f_close(&eeprom_file);
   f_unmount("");
   return true;
@@ -48,8 +44,8 @@ void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
   pos = pos + size;
 }
 
-}
-}
+} // PersistentStore
+} // HAL
 
 #endif // EEPROM_SETTINGS
-#endif // ARDUINO_ARCH_AVR
+#endif // TARGET_LPC1768
diff --git a/Marlin/src/HAL/HAL_LPC1768/pinmapping.h b/Marlin/src/HAL/HAL_LPC1768/pinmapping.h
index d3fd53f77d0..adff789b88d 100644
--- a/Marlin/src/HAL/HAL_LPC1768/pinmapping.h
+++ b/Marlin/src/HAL/HAL_LPC1768/pinmapping.h
@@ -22,12 +22,12 @@
 
 #ifndef __HAL_PINMAPPING_H__
 #define __HAL_PINMAPPING_H__
-#include "../../../macros.h"
+#include "../../core/macros.h"
 
 struct pin_data { uint8_t port, pin; };
 struct adc_pin_data { uint8_t port, pin, adc; };
 
-#if defined(IS_REARM)
+#if ENABLED(IS_REARM)
   #include "pinmap_re_arm.h"
 #else
   #error "HAL: LPC1768: No defined pin-mapping"
diff --git a/Marlin/src/HAL/HAL_LPC1768/pinsDebug_Re_ARM.h b/Marlin/src/HAL/HAL_LPC1768/pinsDebug_Re_ARM.h
index a919d80aa06..a93f7c07672 100644
--- a/Marlin/src/HAL/HAL_LPC1768/pinsDebug_Re_ARM.h
+++ b/Marlin/src/HAL/HAL_LPC1768/pinsDebug_Re_ARM.h
@@ -81,4 +81,4 @@ if (pin == 7) return;
 #define NAME_FORMAT(p) PSTR("%-##p##s")
 //  #define PRINT_ARRAY_NAME(x)  do {sprintf_P(buffer, NAME_FORMAT(MAX_NAME_LENGTH) , pin_array[x].name); SERIAL_ECHO(buffer);} while (0)
 #define PRINT_ARRAY_NAME(x)  do {sprintf_P(buffer, PSTR("%-35s") , pin_array[x].name); SERIAL_ECHO(buffer);} while (0)
-#define GET_ARRAY_IS_DIGITAL(x)  !pin_Re_ARM_analog
\ No newline at end of file
+#define GET_ARRAY_IS_DIGITAL(x)  !pin_Re_ARM_analog
diff --git a/Marlin/src/HAL/HAL_LPC1768/servo_private.h b/Marlin/src/HAL/HAL_LPC1768/servo_private.h
index e7192b801aa..eb2a7a69c6f 100644
--- a/Marlin/src/HAL/HAL_LPC1768/servo_private.h
+++ b/Marlin/src/HAL/HAL_LPC1768/servo_private.h
@@ -48,11 +48,10 @@
  */
 
 
-#ifndef servo_private_h
-#define servo_private_h
-
-#include <inttypes.h>
+#ifndef SERVO_PRIVATE_H
+#define SERVO_PRIVATE_H
 
+#include <stdint.h>
 
 // Macros
 //values in microseconds
@@ -83,5 +82,4 @@ typedef struct {
 extern uint8_t ServoCount;
 extern ServoInfo_t servo_info[MAX_SERVOS];
 
-
-#endif
+#endif // SERVO_PRIVATE_H
diff --git a/Marlin/src/HAL/HAL_LPC1768/watchdog.cpp b/Marlin/src/HAL/HAL_LPC1768/watchdog.cpp
index 89d10a3cb3c..21cdb2070fe 100644
--- a/Marlin/src/HAL/HAL_LPC1768/watchdog.cpp
+++ b/Marlin/src/HAL/HAL_LPC1768/watchdog.cpp
@@ -22,7 +22,7 @@
 
 #ifdef TARGET_LPC1768
 
-#include "../../../MarlinConfig.h"
+#include "../../inc/MarlinConfig.h"
 
 #include "lpc17xx_wdt.h"
 #include "watchdog.h"
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.cpp
index 79495f83c09..751aa94feb5 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Servo_Teensy.cpp
@@ -2,7 +2,7 @@
 
 
 #include "HAL_Servo_Teensy.h"
-#include "../../../MarlinConfig.h"
+#include "../../inc/MarlinConfig.h"
 
 
 int8_t libServo::attach(int pin) {
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Teensy.h b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Teensy.h
index 51311feceeb..fc24b5a9217 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Teensy.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_Teensy.h
@@ -30,8 +30,6 @@
 // Includes
 // --------------------------------------------------------------------------
 
-#include <stdint.h>
-
 #include "Arduino.h"
 
 #include "fastio_Teensy.h"
@@ -39,10 +37,13 @@
 
 #include "HAL_timers_Teensy.h"
 
+#include <stdint.h>
+
 // --------------------------------------------------------------------------
 // Defines
 // --------------------------------------------------------------------------
 
+#undef MOTHERBOARD
 #define MOTHERBOARD BOARD_TEENSY35_36
 
 #define IS_32BIT_TEENSY (defined(__MK64FX512__) || defined(__MK66FX1M0__))
@@ -79,9 +80,10 @@
 
 // Fix bug in pgm_read_ptr
 #undef pgm_read_ptr
-#define pgm_read_ptr(addr) (*(addr))
+#define pgm_read_ptr(addr) (*((void**)(addr)))
+// Add type-checking to pgm_read_word
 #undef pgm_read_word
-#define pgm_read_word(addr) (*(addr))
+#define pgm_read_word(addr) (*((uint16_t*)(addr)))
 
 #define RST_POWER_ON   1
 #define RST_EXTERNAL   2
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_spi_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_spi_Teensy.cpp
index 36c9305bbad..77a87b4b7ff 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_spi_Teensy.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_spi_Teensy.cpp
@@ -4,7 +4,7 @@
 #include <SPI.h>
 #include <pins_arduino.h>
 #include "spi_pins.h"
-#include "../../../macros.h"
+#include "../../core/macros.h"
 
 static SPISettings spiConfig;
 
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h
index 04a09b15ec5..a9b92d7b9b9 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h
@@ -25,7 +25,6 @@
  * Teensy3.6 (__MK66FX1M0__)
  */
 
-
 #ifndef _HAL_TIMERS_TEENSY_H
 #define _HAL_TIMERS_TEENSY_H
 
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_impl.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_impl.cpp
index 95a97a921b7..a50beb869fe 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_impl.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_impl.cpp
@@ -1,14 +1,11 @@
 #if defined(__MK64FX512__) || defined(__MK66FX1M0__)
 
-#include "../persistent_store_api.h"
-
-#include "../../../types.h"
-#include "../../../language.h"
-#include "../../../serial.h"
-#include "../../../utility.h"
+#include "../../inc/MarlinConfig.h"
 
 #if ENABLED(EEPROM_SETTINGS)
 
+#include "../persistent_store_api.h"
+
 namespace HAL {
 namespace PersistentStore {
 
@@ -16,7 +13,7 @@ bool access_start() {
   return true;
 }
 
-bool access_finish(){
+bool access_finish() {
   return true;
 }
 
@@ -51,8 +48,8 @@ void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
   } while (--size);
 }
 
-}
-}
+} // PersistentStore
+} // HAL
 
 #endif // EEPROM_SETTINGS
-#endif // ARDUINO_ARCH_AVR
+#endif // __MK64FX512__ || __MK66FX1M0__
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.cpp
index 7a1a9fe99e7..2d4990dd45f 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.cpp
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.cpp
@@ -22,7 +22,7 @@
 
 #if defined(__MK64FX512__) || defined(__MK66FX1M0__)
  
-  #include "../../../Marlin.h"
+  #include "../../Marlin.h"
 
   #if ENABLED(USE_WATCHDOG)
 
diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.h b/Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.h
index c774a4eef5a..a286f4fc98b 100644
--- a/Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.h
+++ b/Marlin/src/HAL/HAL_TEENSY35_36/watchdog_Teensy.h
@@ -23,16 +23,16 @@
 #ifndef WATCHDOG_TEENSY_H
 #define WATCHDOG_TEENSY_H
 
-//#include "../../../Marlin.h"
+#include "../HAL.h"
 
 // Arduino Due core now has watchdog support
 
 void watchdog_init();
 
 inline void watchdog_reset() {
-	// Watchdog refresh sequence
-	WDOG_REFRESH = 0xA602;
-	WDOG_REFRESH = 0xB480;
+  // Watchdog refresh sequence
+  WDOG_REFRESH = 0xA602;
+  WDOG_REFRESH = 0xB480;
 }
 
-#endif /* WATCHDOG_TEENSY_H */
+#endif // WATCHDOG_TEENSY_H
diff --git a/Marlin/src/HAL/HAL_spi_pins.h b/Marlin/src/HAL/HAL_spi_pins.h
index 4d4c27d070d..a041f33a5df 100644
--- a/Marlin/src/HAL/HAL_spi_pins.h
+++ b/Marlin/src/HAL/HAL_spi_pins.h
@@ -23,8 +23,6 @@
 #ifndef HAL_SPI_PINS_H_
 #define HAL_SPI_PINS_H_
 
-#include "../../MarlinConfig.h"
-
 #ifdef ARDUINO_ARCH_SAM
   #include "HAL_DUE/spi_pins.h"
 
diff --git a/Marlin/src/HAL/I2cEeprom.cpp b/Marlin/src/HAL/I2cEeprom.cpp
index d5f6e6dd7f5..15518fc43f0 100644
--- a/Marlin/src/HAL/I2cEeprom.cpp
+++ b/Marlin/src/HAL/I2cEeprom.cpp
@@ -25,7 +25,7 @@
  * Not platform dependent.
  */
 
-#include "../../MarlinConfig.h"
+#include "../inc/MarlinConfig.h"
 
 #if ENABLED(I2C_EEPROM)
 
diff --git a/Marlin/src/HAL/SpiEeprom.cpp b/Marlin/src/HAL/SpiEeprom.cpp
index 86d68fb3eb7..356bb3d9d52 100644
--- a/Marlin/src/HAL/SpiEeprom.cpp
+++ b/Marlin/src/HAL/SpiEeprom.cpp
@@ -25,7 +25,7 @@
  * Not platform dependent.
  */
 
-#include "../../MarlinConfig.h"
+#include "../inc/MarlinConfig.h"
 
 #if ENABLED(SPI_EEPROM)
 
diff --git a/Marlin/src/HAL/math_32bit.h b/Marlin/src/HAL/math_32bit.h
index 8586c00006b..98b6a55f9f1 100644
--- a/Marlin/src/HAL/math_32bit.h
+++ b/Marlin/src/HAL/math_32bit.h
@@ -30,4 +30,4 @@
 #define MultiU32X32toH32(intRes, longIn1, longIn2) intRes = ((uint64_t)longIn1 * longIn2 + 0x80000000) >> 32
 #define MultiU32X24toH32(intRes, longIn1, longIn2) intRes = ((uint64_t)longIn1 * longIn2 + 0x00800000) >> 24
 
-#endif
+#endif // MATH_32BIT_H
diff --git a/Marlin/src/HAL/persistent_store_api.h b/Marlin/src/HAL/persistent_store_api.h
index 7d548704d81..71bd01bc7ae 100644
--- a/Marlin/src/HAL/persistent_store_api.h
+++ b/Marlin/src/HAL/persistent_store_api.h
@@ -12,8 +12,7 @@ bool access_finish();
 bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc);
 void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) ;
 
-}
-}
+} // PersistentStore
+} // HAL
 
-
-#endif /* _PERSISTANT_STORE_H_ */
+#endif // _PERSISTENT_STORE_H_
diff --git a/Marlin/src/HAL/servo.cpp b/Marlin/src/HAL/servo.cpp
index 46ab76aa054..1ccd73afa40 100644
--- a/Marlin/src/HAL/servo.cpp
+++ b/Marlin/src/HAL/servo.cpp
@@ -52,7 +52,7 @@
  */
 
 
-#include "../../MarlinConfig.h"
+#include "../inc/MarlinConfig.h"
 
 #include "HAL.h"
 
diff --git a/Marlin/src/HAL/servo.h b/Marlin/src/HAL/servo.h
index efbe90071a7..ba228350347 100644
--- a/Marlin/src/HAL/servo.h
+++ b/Marlin/src/HAL/servo.h
@@ -76,7 +76,7 @@
   #include "HAL_LPC1768/LPC1768_Servo.h"
 
 #else
-  #include <inttypes.h>
+  #include <stdint.h>
 
   #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAM)
     // we're good to go
diff --git a/Marlin/src/HAL/servo_private.h b/Marlin/src/HAL/servo_private.h
index 3d8c50c0dfa..9b85b9cf7c9 100644
--- a/Marlin/src/HAL/servo_private.h
+++ b/Marlin/src/HAL/servo_private.h
@@ -21,7 +21,7 @@
  */
 
 /**
-  servo.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2
+  servo_private.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2
   Copyright (c) 2009 Michael Margolis.  All right reserved.
 
   This library is free software; you can redistribute it and/or
@@ -39,10 +39,10 @@
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
-#ifndef servo_private_h
-#define servo_private_h
+#ifndef SERVO_PRIVATE_H
+#define SERVO_PRIVATE_H
 
-#include <inttypes.h>
+#include <stdint.h>
 
 // Architecture specific include
 #ifdef ARDUINO_ARCH_AVR
@@ -99,5 +99,4 @@ extern ServoInfo_t servo_info[MAX_SERVOS];
 extern void initISR(timer16_Sequence_t timer);
 extern void finISR(timer16_Sequence_t timer);
 
-
-#endif
+#endif // SERVO_PRIVATE_H