Browse Source

Merge bugfix-2.0.x into 2.0.x

Scott Lahteine 4 years ago
parent
commit
aac0326f7f
100 changed files with 2936 additions and 1944 deletions
  1. 2
    0
      .github/workflows/test-builds.yml
  2. 29
    34
      Marlin/Configuration.h
  3. 39
    33
      Marlin/Configuration_adv.h
  4. 56
    52
      Marlin/Makefile
  5. 8
    32
      Marlin/src/HAL/AVR/HAL.h
  6. 606
    622
      Marlin/src/HAL/AVR/MarlinSerial.cpp
  7. 35
    38
      Marlin/src/HAL/AVR/MarlinSerial.h
  8. 0
    1
      Marlin/src/HAL/AVR/Servo.cpp
  9. 11
    5
      Marlin/src/HAL/AVR/fastio.h
  10. 3
    1
      Marlin/src/HAL/AVR/pinsDebug.h
  11. 3
    6
      Marlin/src/HAL/AVR/pinsDebug_plus_70.h
  12. 1
    0
      Marlin/src/HAL/AVR/timers.h
  13. 2
    2
      Marlin/src/HAL/AVR/u8g_com_HAL_AVR_sw_spi.cpp
  14. 15
    38
      Marlin/src/HAL/DUE/HAL.h
  15. 1
    2
      Marlin/src/HAL/DUE/HAL_SPI.cpp
  16. 2
    0
      Marlin/src/HAL/DUE/MarlinSerial.h
  17. 3
    4
      Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_shared_hw_spi.cpp
  18. 2
    2
      Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi.cpp
  19. 2
    2
      Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp
  20. 0
    1
      Marlin/src/HAL/DUE/eeprom_flash.cpp
  21. 0
    1
      Marlin/src/HAL/DUE/pinsDebug.h
  22. 19
    20
      Marlin/src/HAL/DUE/usb/compiler.h
  23. 1
    3
      Marlin/src/HAL/ESP32/HAL.h
  24. 2
    3
      Marlin/src/HAL/ESP32/WebSocketSerial.cpp
  25. 1
    0
      Marlin/src/HAL/ESP32/ota.h
  26. 6
    0
      Marlin/src/HAL/HAL.h
  27. 0
    1
      Marlin/src/HAL/LINUX/HAL.h
  28. 1
    1
      Marlin/src/HAL/LINUX/include/serial.h
  29. 1
    1
      Marlin/src/HAL/LINUX/main.cpp
  30. 0
    1
      Marlin/src/HAL/LINUX/servo_private.h
  31. 1
    1
      Marlin/src/HAL/LINUX/spi_pins.h
  32. 15
    38
      Marlin/src/HAL/LPC1768/HAL.h
  33. 85
    124
      Marlin/src/HAL/LPC1768/HAL_SPI.cpp
  34. 4
    4
      Marlin/src/HAL/LPC1768/MarlinSerial.cpp
  35. 1
    0
      Marlin/src/HAL/LPC1768/MarlinSerial.h
  36. 0
    1
      Marlin/src/HAL/LPC1768/Servo.h
  37. 36
    23
      Marlin/src/HAL/LPC1768/inc/SanityCheck.h
  38. 18
    4
      Marlin/src/HAL/LPC1768/include/SPI.h
  39. 1
    1
      Marlin/src/HAL/LPC1768/spi_pins.h
  40. 0
    1
      Marlin/src/HAL/LPC1768/tft/xpt2046.cpp
  41. 0
    1
      Marlin/src/HAL/LPC1768/timers.h
  42. 2
    2
      Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_hw_spi.cpp
  43. 2
    2
      Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_ssd_hw_i2c.cpp
  44. 2
    2
      Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_hw_spi.cpp
  45. 2
    2
      Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_sw_spi.cpp
  46. 2
    0
      Marlin/src/HAL/LPC1768/usb_serial.cpp
  47. 14
    38
      Marlin/src/HAL/SAMD51/HAL.h
  48. 0
    1
      Marlin/src/HAL/SAMD51/QSPIFlash.h
  49. 0
    1
      Marlin/src/HAL/SAMD51/pinsDebug.h
  50. 19
    62
      Marlin/src/HAL/STM32/HAL.h
  51. 4
    6
      Marlin/src/HAL/STM32/MarlinSerial.cpp
  52. 4
    0
      Marlin/src/HAL/STM32/MarlinSerial.h
  53. 0
    396
      Marlin/src/HAL/STM32/SoftwareSerial.cpp
  54. 0
    114
      Marlin/src/HAL/STM32/SoftwareSerial.h
  55. 1
    1
      Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h
  56. 1
    1
      Marlin/src/HAL/STM32/tft/tft_fsmc.cpp
  57. 2
    2
      Marlin/src/HAL/STM32/tft/xpt2046.cpp
  58. 99
    31
      Marlin/src/HAL/STM32/timers.cpp
  59. 15
    7
      Marlin/src/HAL/STM32/timers.h
  60. 31
    65
      Marlin/src/HAL/STM32F1/HAL.h
  61. 193
    0
      Marlin/src/HAL/STM32F1/MarlinSerial.cpp
  62. 71
    0
      Marlin/src/HAL/STM32F1/MarlinSerial.h
  63. 4
    1
      Marlin/src/HAL/STM32F1/SPI.cpp
  64. 1
    1
      Marlin/src/HAL/STM32F1/SoftwareSerial.cpp
  65. 2
    2
      Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp
  66. 0
    4
      Marlin/src/HAL/STM32F1/inc/SanityCheck.h
  67. 17
    1
      Marlin/src/HAL/STM32F1/msc_sd.cpp
  68. 20
    1
      Marlin/src/HAL/STM32F1/msc_sd.h
  69. 8
    9
      Marlin/src/HAL/STM32F1/onboard_sd.cpp
  70. 2
    2
      Marlin/src/HAL/STM32F1/sdio.cpp
  71. 12
    0
      Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp
  72. 16
    57
      Marlin/src/HAL/STM32_F4_F7/HAL.h
  73. 1
    1
      Marlin/src/HAL/STM32_F4_F7/HAL_SPI.cpp
  74. 0
    2
      Marlin/src/HAL/STM32_F4_F7/STM32F7/TMC2660.cpp
  75. 0
    1
      Marlin/src/HAL/STM32_F4_F7/STM32F7/TMC2660.h
  76. 9
    11
      Marlin/src/HAL/TEENSY31_32/HAL.h
  77. 13
    12
      Marlin/src/HAL/TEENSY35_36/HAL.h
  78. 1
    1
      Marlin/src/HAL/TEENSY35_36/HAL_SPI.cpp
  79. 1
    0
      Marlin/src/HAL/TEENSY35_36/timers.h
  80. 167
    0
      Marlin/src/HAL/TEENSY40_41/HAL.cpp
  81. 147
    0
      Marlin/src/HAL/TEENSY40_41/HAL.h
  82. 138
    0
      Marlin/src/HAL/TEENSY40_41/HAL_SPI.cpp
  83. 57
    0
      Marlin/src/HAL/TEENSY40_41/Servo.cpp
  84. 39
    0
      Marlin/src/HAL/TEENSY40_41/Servo.h
  85. 77
    0
      Marlin/src/HAL/TEENSY40_41/eeprom.cpp
  86. 66
    0
      Marlin/src/HAL/TEENSY40_41/endstop_interrupts.h
  87. 58
    0
      Marlin/src/HAL/TEENSY40_41/fastio.h
  88. 26
    0
      Marlin/src/HAL/TEENSY40_41/inc/Conditionals_LCD.h
  89. 22
    0
      Marlin/src/HAL/TEENSY40_41/inc/Conditionals_adv.h
  90. 26
    0
      Marlin/src/HAL/TEENSY40_41/inc/Conditionals_post.h
  91. 38
    0
      Marlin/src/HAL/TEENSY40_41/inc/SanityCheck.h
  92. 146
    0
      Marlin/src/HAL/TEENSY40_41/pinsDebug.h
  93. 27
    0
      Marlin/src/HAL/TEENSY40_41/spi_pins.h
  94. 114
    0
      Marlin/src/HAL/TEENSY40_41/timers.cpp
  95. 120
    0
      Marlin/src/HAL/TEENSY40_41/timers.h
  96. 52
    0
      Marlin/src/HAL/TEENSY40_41/watchdog.cpp
  97. 30
    0
      Marlin/src/HAL/TEENSY40_41/watchdog.h
  98. 2
    0
      Marlin/src/HAL/platforms.h
  99. 1
    1
      Marlin/src/HAL/shared/HAL_ST7920.h
  100. 0
    0
      Marlin/src/HAL/shared/backtrace/unwmemaccess.cpp

+ 2
- 0
.github/workflows/test-builds.yml View File

41
         - mega2560
41
         - mega2560
42
         - teensy31
42
         - teensy31
43
         - teensy35
43
         - teensy35
44
+        - teensy41
44
         - SAMD51_grandcentral_m4
45
         - SAMD51_grandcentral_m4
45
 
46
 
46
         # Extended AVR Environments
47
         # Extended AVR Environments
70
         - mks_robin_stm32
71
         - mks_robin_stm32
71
         - ARMED
72
         - ARMED
72
         - FYSETC_S6
73
         - FYSETC_S6
74
+        - STM32F070CB_malyan
73
         - STM32F070RB_malyan
75
         - STM32F070RB_malyan
74
         - malyan_M300
76
         - malyan_M300
75
         - mks_robin_lite
77
         - mks_robin_lite

+ 29
- 34
Marlin/Configuration.h View File

34
  * - Extra features
34
  * - Extra features
35
  *
35
  *
36
  * Advanced settings can be found in Configuration_adv.h
36
  * Advanced settings can be found in Configuration_adv.h
37
- *
38
  */
37
  */
39
-#define CONFIGURATION_H_VERSION 020006
38
+#define CONFIGURATION_H_VERSION 020007
40
 
39
 
41
 //===========================================================================
40
 //===========================================================================
42
 //============================= Getting Started =============================
41
 //============================= Getting Started =============================
390
  *    21 : Pt100 with circuit in the Ultimainboard V2.x with 3.3v excitation (STM32 \ LPC176x....)
389
  *    21 : Pt100 with circuit in the Ultimainboard V2.x with 3.3v excitation (STM32 \ LPC176x....)
391
  *    22 : 100k (hotend) with 4.7k pullup to 3.3V and 220R to analog input (as in GTM32 Pro vB)
390
  *    22 : 100k (hotend) with 4.7k pullup to 3.3V and 220R to analog input (as in GTM32 Pro vB)
392
  *    23 : 100k (bed) with 4.7k pullup to 3.3v and 220R to analog input (as in GTM32 Pro vB)
391
  *    23 : 100k (bed) with 4.7k pullup to 3.3v and 220R to analog input (as in GTM32 Pro vB)
392
+ *    30 : Kis3d Silicone heating mat 200W/300W with 6mm precision cast plate (EN AW 5083) NTC100K / B3950 (4.7k pullup)
393
  *   201 : Pt100 with circuit in Overlord, similar to Ultimainboard V2.x
393
  *   201 : Pt100 with circuit in Overlord, similar to Ultimainboard V2.x
394
  *    60 : 100k Maker's Tool Works Kapton Bed Thermistor beta=3950
394
  *    60 : 100k Maker's Tool Works Kapton Bed Thermistor beta=3950
395
  *    61 : 100k Formbot / Vivedino 3950 350C thermistor 4.7k pullup
395
  *    61 : 100k Formbot / Vivedino 3950 350C thermistor 4.7k pullup
486
   //#define PID_AUTOTUNE_MENU     // Add PID auto-tuning to the "Advanced Settings" menu. (~250 bytes of PROGMEM)
486
   //#define PID_AUTOTUNE_MENU     // Add PID auto-tuning to the "Advanced Settings" menu. (~250 bytes of PROGMEM)
487
   //#define PID_PARAMS_PER_HOTEND // Uses separate PID parameters for each extruder (useful for mismatched extruders)
487
   //#define PID_PARAMS_PER_HOTEND // Uses separate PID parameters for each extruder (useful for mismatched extruders)
488
                                   // Set/get with gcode: M301 E[extruder number, 0-2]
488
                                   // Set/get with gcode: M301 E[extruder number, 0-2]
489
-
490
-  // If you are using a pre-configured hotend then you can use one of the value sets by uncommenting it
491
-
492
-  // Ultimaker
493
-  #define DEFAULT_Kp 22.2
494
-  #define DEFAULT_Ki 1.08
495
-  #define DEFAULT_Kd 114
496
-
497
-  // MakerGear
498
-  //#define DEFAULT_Kp 7.0
499
-  //#define DEFAULT_Ki 0.1
500
-  //#define DEFAULT_Kd 12
501
-
502
-  // Mendel Parts V9 on 12V
503
-  //#define DEFAULT_Kp 63.0
504
-  //#define DEFAULT_Ki 2.25
505
-  //#define DEFAULT_Kd 440
506
-
489
+  #if ENABLED(PID_PARAMS_PER_HOTEND)
490
+    // Specify between 1 and HOTENDS values per array.
491
+    // If fewer than EXTRUDER values are provided, the last element will be repeated.
492
+    #define DEFAULT_Kp_LIST {  22.20,  20.0 }
493
+    #define DEFAULT_Ki_LIST {   1.08,   1.0 }
494
+    #define DEFAULT_Kd_LIST { 114.00, 112.0 }
495
+  #else
496
+    #define DEFAULT_Kp  22.20
497
+    #define DEFAULT_Ki   1.08
498
+    #define DEFAULT_Kd 114.00
499
+  #endif
507
 #endif // PIDTEMP
500
 #endif // PIDTEMP
508
 
501
 
509
 //===========================================================================
502
 //===========================================================================
539
   //#define MIN_BED_POWER 0
532
   //#define MIN_BED_POWER 0
540
   //#define PID_BED_DEBUG // Sends debug data to the serial port.
533
   //#define PID_BED_DEBUG // Sends debug data to the serial port.
541
 
534
 
542
-  //120V 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
543
-  //from FOPDT model - kp=.39 Tp=405 Tdead=66, Tc set to 79.2, aggressive factor of .15 (vs .1, 1, 10)
535
+  // 120V 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
536
+  // from FOPDT model - kp=.39 Tp=405 Tdead=66, Tc set to 79.2, aggressive factor of .15 (vs .1, 1, 10)
544
   #define DEFAULT_bedKp 10.00
537
   #define DEFAULT_bedKp 10.00
545
   #define DEFAULT_bedKi .023
538
   #define DEFAULT_bedKi .023
546
   #define DEFAULT_bedKd 305.4
539
   #define DEFAULT_bedKd 305.4
547
 
540
 
548
-  //120V 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
549
-  //from pidautotune
550
-  //#define DEFAULT_bedKp 97.1
551
-  //#define DEFAULT_bedKi 1.41
552
-  //#define DEFAULT_bedKd 1675.16
553
-
554
   // FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles.
541
   // FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles.
555
 #endif // PIDTEMPBED
542
 #endif // PIDTEMPBED
556
 
543
 
608
 
595
 
609
 // @section machine
596
 // @section machine
610
 
597
 
611
-// Uncomment one of these options to enable CoreXY, CoreXZ, or CoreYZ kinematics
598
+// Enable one of the options below for CoreXY, CoreXZ, or CoreYZ kinematics,
612
 // either in the usual order or reversed
599
 // either in the usual order or reversed
613
 //#define COREXY
600
 //#define COREXY
614
 //#define COREXZ
601
 //#define COREXZ
616
 //#define COREYX
603
 //#define COREYX
617
 //#define COREZX
604
 //#define COREZX
618
 //#define COREZY
605
 //#define COREZY
606
+//#define MARKFORGED_XY  // MarkForged. See https://reprap.org/forum/read.php?152,504042
619
 
607
 
620
 //===========================================================================
608
 //===========================================================================
621
 //============================== Endstop Settings ===========================
609
 //============================== Endstop Settings ===========================
866
  *    - For simple switches connect...
854
  *    - For simple switches connect...
867
  *      - normally-closed switches to GND and D32.
855
  *      - normally-closed switches to GND and D32.
868
  *      - normally-open switches to 5V and D32.
856
  *      - normally-open switches to 5V and D32.
869
- *
870
  */
857
  */
871
 //#define Z_MIN_PROBE_PIN 32 // Pin 32 is the RAMPS default
858
 //#define Z_MIN_PROBE_PIN 32 // Pin 32 is the RAMPS default
872
 
859
 
1578
  *
1565
  *
1579
  *   Caveats: The ending Z should be the same as starting Z.
1566
  *   Caveats: The ending Z should be the same as starting Z.
1580
  * Attention: EXPERIMENTAL. G-code arguments may change.
1567
  * Attention: EXPERIMENTAL. G-code arguments may change.
1581
- *
1582
  */
1568
  */
1583
 //#define NOZZLE_CLEAN_FEATURE
1569
 //#define NOZZLE_CLEAN_FEATURE
1584
 
1570
 
1731
  *
1717
  *
1732
  * SD Card support is disabled by default. If your controller has an SD slot,
1718
  * SD Card support is disabled by default. If your controller has an SD slot,
1733
  * you must uncomment the following option or it won't work.
1719
  * you must uncomment the following option or it won't work.
1734
- *
1735
  */
1720
  */
1736
 //#define SDSUPPORT
1721
 //#define SDSUPPORT
1737
 
1722
 
1968
 //
1953
 //
1969
 //#define FF_INTERFACEBOARD
1954
 //#define FF_INTERFACEBOARD
1970
 
1955
 
1956
+//
1957
+// TFT GLCD Panel with Marlin UI
1958
+// Panel connected to main board by SPI or I2C interface.
1959
+// See https://github.com/Serhiy-K/TFTGLCDAdapter
1960
+//
1961
+//#define TFTGLCD_PANEL_SPI
1962
+//#define TFTGLCD_PANEL_I2C
1963
+
1971
 //=============================================================================
1964
 //=============================================================================
1972
 //=======================   LCD / Controller Selection  =======================
1965
 //=======================   LCD / Controller Selection  =======================
1973
 //=========================      (Graphical LCDs)      ========================
1966
 //=========================      (Graphical LCDs)      ========================
2171
 // Touch-screen LCD for Malyan M200/M300 printers
2164
 // Touch-screen LCD for Malyan M200/M300 printers
2172
 //
2165
 //
2173
 //#define MALYAN_LCD
2166
 //#define MALYAN_LCD
2167
+#if ENABLED(MALYAN_LCD)
2168
+  #define LCD_SERIAL_PORT 1  // Default is 1 for Malyan M200
2169
+#endif
2174
 
2170
 
2175
 //
2171
 //
2176
 // Touch UI for FTDI EVE (FT800/FT810) displays
2172
 // Touch UI for FTDI EVE (FT800/FT810) displays
2184
 //#define ANYCUBIC_LCD_I3MEGA
2180
 //#define ANYCUBIC_LCD_I3MEGA
2185
 //#define ANYCUBIC_LCD_CHIRON
2181
 //#define ANYCUBIC_LCD_CHIRON
2186
 #if EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON)
2182
 #if EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON)
2187
-  #define ANYCUBIC_LCD_SERIAL_PORT 3
2183
+  #define LCD_SERIAL_PORT 3  // Default is 3 for Anycubic
2188
   //#define ANYCUBIC_LCD_DEBUG
2184
   //#define ANYCUBIC_LCD_DEBUG
2189
 #endif
2185
 #endif
2190
 
2186
 
2343
  * *** CAUTION ***
2339
  * *** CAUTION ***
2344
  *
2340
  *
2345
  * LED Type. Enable only one of the following two options.
2341
  * LED Type. Enable only one of the following two options.
2346
- *
2347
  */
2342
  */
2348
 //#define RGB_LED
2343
 //#define RGB_LED
2349
 //#define RGBW_LED
2344
 //#define RGBW_LED

+ 39
- 33
Marlin/Configuration_adv.h View File

29
  * Some of these settings can damage your printer if improperly set!
29
  * Some of these settings can damage your printer if improperly set!
30
  *
30
  *
31
  * Basic settings can be found in Configuration.h
31
  * Basic settings can be found in Configuration.h
32
- *
33
  */
32
  */
34
-#define CONFIGURATION_ADV_H_VERSION 020006
33
+#define CONFIGURATION_ADV_H_VERSION 020007
35
 
34
 
36
 // @section temperature
35
 // @section temperature
37
 
36
 
738
    *               | 4   3 | 1   4 | 2   1 | 3   2 |
737
    *               | 4   3 | 1   4 | 2   1 | 3   2 |
739
    *               |       |       |       |       |
738
    *               |       |       |       |       |
740
    *               | 1   2 | 2   3 | 3   4 | 4   1 |
739
    *               | 1   2 | 2   3 | 3   4 | 4   1 |
741
-   *
742
    */
740
    */
743
   #ifndef Z_STEPPER_ALIGN_XY
741
   #ifndef Z_STEPPER_ALIGN_XY
744
     //#define Z_STEPPERS_ORIENTATION 0
742
     //#define Z_STEPPERS_ORIENTATION 0
773
 //
771
 //
774
 //#define ASSISTED_TRAMMING
772
 //#define ASSISTED_TRAMMING
775
 #if ENABLED(ASSISTED_TRAMMING)
773
 #if ENABLED(ASSISTED_TRAMMING)
776
-
777
   // Define positions for probing points, use the hotend as reference not the sensor.
774
   // Define positions for probing points, use the hotend as reference not the sensor.
778
   #define TRAMMING_POINT_XY { {  20, 20 }, { 200,  20 }, { 200, 200 }, { 20, 200 } }
775
   #define TRAMMING_POINT_XY { {  20, 20 }, { 200,  20 }, { 200, 200 }, { 20, 200 } }
779
 
776
 
786
   // Enable to restore leveling setup after operation
783
   // Enable to restore leveling setup after operation
787
   #define RESTORE_LEVELING_AFTER_G35
784
   #define RESTORE_LEVELING_AFTER_G35
788
 
785
 
786
+  // Add a menu item for Assisted Tramming
787
+  //#define ASSISTED_TRAMMING_MENU_ITEM
788
+
789
   /**
789
   /**
790
    * Screw thread:
790
    * Screw thread:
791
    *   M3: 30 = Clockwise, 31 = Counter-Clockwise
791
    *   M3: 30 = Clockwise, 31 = Counter-Clockwise
793
    *   M5: 50 = Clockwise, 51 = Counter-Clockwise
793
    *   M5: 50 = Clockwise, 51 = Counter-Clockwise
794
    */
794
    */
795
   #define TRAMMING_SCREW_THREAD 30
795
   #define TRAMMING_SCREW_THREAD 30
796
-
797
 #endif
796
 #endif
798
 
797
 
799
 // @section motion
798
 // @section motion
1105
   #define BOOTSCREEN_TIMEOUT 4000        // (ms) Total Duration to display the boot screen(s)
1104
   #define BOOTSCREEN_TIMEOUT 4000        // (ms) Total Duration to display the boot screen(s)
1106
 #endif
1105
 #endif
1107
 
1106
 
1108
-#if HAS_GRAPHICAL_LCD && EITHER(SDSUPPORT, LCD_SET_PROGRESS_MANUALLY)
1109
-  //#define PRINT_PROGRESS_SHOW_DECIMALS // Show progress with decimal digits
1110
-  //#define SHOW_REMAINING_TIME          // Display estimated time to completion
1107
+#if EITHER(SDSUPPORT, LCD_SET_PROGRESS_MANUALLY) && ANY(HAS_MARLINUI_U8GLIB, HAS_MARLINUI_HD44780, IS_TFTGLCD_PANEL)
1108
+  //#define SHOW_REMAINING_TIME       // Display estimated time to completion
1111
   #if ENABLED(SHOW_REMAINING_TIME)
1109
   #if ENABLED(SHOW_REMAINING_TIME)
1112
-    //#define USE_M73_REMAINING_TIME     // Use remaining time from M73 command instead of estimation
1113
-    //#define ROTATE_PROGRESS_DISPLAY    // Display (P)rogress, (E)lapsed, and (R)emaining time
1110
+    //#define USE_M73_REMAINING_TIME  // Use remaining time from M73 command instead of estimation
1111
+    //#define ROTATE_PROGRESS_DISPLAY // Display (P)rogress, (E)lapsed, and (R)emaining time
1114
   #endif
1112
   #endif
1115
-#endif
1116
 
1113
 
1117
-#if HAS_CHARACTER_LCD && EITHER(SDSUPPORT, LCD_SET_PROGRESS_MANUALLY)
1118
-  //#define LCD_PROGRESS_BAR              // Show a progress bar on HD44780 LCDs for SD printing
1119
-  #if ENABLED(LCD_PROGRESS_BAR)
1120
-    #define PROGRESS_BAR_BAR_TIME 2000    // (ms) Amount of time to show the bar
1121
-    #define PROGRESS_BAR_MSG_TIME 3000    // (ms) Amount of time to show the status message
1122
-    #define PROGRESS_MSG_EXPIRE   0       // (ms) Amount of time to retain the status message (0=forever)
1123
-    //#define PROGRESS_MSG_ONCE           // Show the message for MSG_TIME then clear it
1124
-    //#define LCD_PROGRESS_BAR_TEST       // Add a menu item to test the progress bar
1114
+  #if HAS_MARLINUI_U8GLIB
1115
+    //#define PRINT_PROGRESS_SHOW_DECIMALS // Show progress with decimal digits
1116
+  #endif
1117
+
1118
+  #if EITHER(HAS_MARLINUI_HD44780, IS_TFTGLCD_PANEL)
1119
+    //#define LCD_PROGRESS_BAR            // Show a progress bar on HD44780 LCDs for SD printing
1120
+    #if ENABLED(LCD_PROGRESS_BAR)
1121
+      #define PROGRESS_BAR_BAR_TIME 2000  // (ms) Amount of time to show the bar
1122
+      #define PROGRESS_BAR_MSG_TIME 3000  // (ms) Amount of time to show the status message
1123
+      #define PROGRESS_MSG_EXPIRE   0     // (ms) Amount of time to retain the status message (0=forever)
1124
+      //#define PROGRESS_MSG_ONCE         // Show the message for MSG_TIME then clear it
1125
+      //#define LCD_PROGRESS_BAR_TEST     // Add a menu item to test the progress bar
1126
+    #endif
1125
   #endif
1127
   #endif
1126
 #endif
1128
 #endif
1127
 
1129
 
1164
   #if ENABLED(POWER_LOSS_RECOVERY)
1166
   #if ENABLED(POWER_LOSS_RECOVERY)
1165
     #define PLR_ENABLED_DEFAULT   false // Power Loss Recovery enabled by default. (Set with 'M413 Sn' & M500)
1167
     #define PLR_ENABLED_DEFAULT   false // Power Loss Recovery enabled by default. (Set with 'M413 Sn' & M500)
1166
     //#define BACKUP_POWER_SUPPLY       // Backup power / UPS to move the steppers on power loss
1168
     //#define BACKUP_POWER_SUPPLY       // Backup power / UPS to move the steppers on power loss
1169
+    //#define POWER_LOSS_RECOVER_ZHOME  // Z homing is needed for proper recovery. 99.9% of the time this should be disabled!
1167
     //#define POWER_LOSS_ZRAISE       2 // (mm) Z axis raise on resume (on power loss with UPS)
1170
     //#define POWER_LOSS_ZRAISE       2 // (mm) Z axis raise on resume (on power loss with UPS)
1168
     //#define POWER_LOSS_PIN         44 // Pin to detect power loss. Set to -1 to disable default pin on boards without module.
1171
     //#define POWER_LOSS_PIN         44 // Pin to detect power loss. Set to -1 to disable default pin on boards without module.
1169
     //#define POWER_LOSS_STATE     HIGH // State of pin indicating power loss
1172
     //#define POWER_LOSS_STATE     HIGH // State of pin indicating power loss
1324
  * controller events, as there is a trade-off between reliable
1327
  * controller events, as there is a trade-off between reliable
1325
  * printing performance versus fast display updates.
1328
  * printing performance versus fast display updates.
1326
  */
1329
  */
1327
-#if HAS_GRAPHICAL_LCD
1330
+#if HAS_MARLINUI_U8GLIB
1328
   // Show SD percentage next to the progress bar
1331
   // Show SD percentage next to the progress bar
1329
   //#define DOGM_SD_PERCENT
1332
   //#define DOGM_SD_PERCENT
1330
 
1333
 
1394
   //#define MARLIN_SNAKE
1397
   //#define MARLIN_SNAKE
1395
   //#define GAMES_EASTER_EGG          // Add extra blank lines above the "Games" sub-menu
1398
   //#define GAMES_EASTER_EGG          // Add extra blank lines above the "Games" sub-menu
1396
 
1399
 
1397
-#endif // HAS_GRAPHICAL_LCD
1400
+#endif // HAS_MARLINUI_U8GLIB
1398
 
1401
 
1399
 //
1402
 //
1400
 // Additional options for DGUS / DWIN displays
1403
 // Additional options for DGUS / DWIN displays
1401
 //
1404
 //
1402
 #if HAS_DGUS_LCD
1405
 #if HAS_DGUS_LCD
1403
-  #define DGUS_SERIAL_PORT 3
1404
-  #define DGUS_BAUDRATE 115200
1406
+  #define LCD_SERIAL_PORT 3
1407
+  #define LCD_BAUDRATE 115200
1405
 
1408
 
1406
   #define DGUS_RX_BUFFER_SIZE 128
1409
   #define DGUS_RX_BUFFER_SIZE 128
1407
   #define DGUS_TX_BUFFER_SIZE 48
1410
   #define DGUS_TX_BUFFER_SIZE 48
1408
-  //#define DGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS  // Fix Rx overrun situation (Currently only for AVR)
1411
+  //#define SERIAL_STATS_RX_BUFFER_OVERRUNS  // Fix Rx overrun situation (Currently only for AVR)
1409
 
1412
 
1410
   #define DGUS_UPDATE_INTERVAL_MS  500    // (ms) Interval between automatic screen updates
1413
   #define DGUS_UPDATE_INTERVAL_MS  500    // (ms) Interval between automatic screen updates
1411
 
1414
 
1572
 #if ENABLED(BABYSTEPPING)
1575
 #if ENABLED(BABYSTEPPING)
1573
   //#define INTEGRATED_BABYSTEPPING         // EXPERIMENTAL integration of babystepping into the Stepper ISR
1576
   //#define INTEGRATED_BABYSTEPPING         // EXPERIMENTAL integration of babystepping into the Stepper ISR
1574
   //#define BABYSTEP_WITHOUT_HOMING
1577
   //#define BABYSTEP_WITHOUT_HOMING
1578
+  //#define BABYSTEP_ALWAYS_AVAILABLE       // Allow babystepping at all times (not just during movement).
1575
   //#define BABYSTEP_XY                     // Also enable X/Y Babystepping. Not supported on DELTA!
1579
   //#define BABYSTEP_XY                     // Also enable X/Y Babystepping. Not supported on DELTA!
1576
   #define BABYSTEP_INVERT_Z false           // Change if Z babysteps should go the other way
1580
   #define BABYSTEP_INVERT_Z false           // Change if Z babysteps should go the other way
1577
   //#define BABYSTEP_MILLIMETER_UNITS       // Specify BABYSTEP_MULTIPLICATOR_(XY|Z) in mm instead of micro-steps
1581
   //#define BABYSTEP_MILLIMETER_UNITS       // Specify BABYSTEP_MULTIPLICATOR_(XY|Z) in mm instead of micro-steps
1582
   #if ENABLED(DOUBLECLICK_FOR_Z_BABYSTEPPING)
1586
   #if ENABLED(DOUBLECLICK_FOR_Z_BABYSTEPPING)
1583
     #define DOUBLECLICK_MAX_INTERVAL 1250   // Maximum interval between clicks, in milliseconds.
1587
     #define DOUBLECLICK_MAX_INTERVAL 1250   // Maximum interval between clicks, in milliseconds.
1584
                                             // Note: Extra time may be added to mitigate controller latency.
1588
                                             // Note: Extra time may be added to mitigate controller latency.
1585
-    //#define BABYSTEP_ALWAYS_AVAILABLE     // Allow babystepping at all times (not just during movement).
1586
     //#define MOVE_Z_WHEN_IDLE              // Jump to the move Z menu on doubleclick when printer is idle.
1589
     //#define MOVE_Z_WHEN_IDLE              // Jump to the move Z menu on doubleclick when printer is idle.
1587
     #if ENABLED(MOVE_Z_WHEN_IDLE)
1590
     #if ENABLED(MOVE_Z_WHEN_IDLE)
1588
       #define MOVE_Z_IDLE_MULTIPLICATOR 1   // Multiply 1mm by this factor for the move step size.
1591
       #define MOVE_Z_IDLE_MULTIPLICATOR 1   // Multiply 1mm by this factor for the move step size.
1950
  * Be sure to turn off auto-retract during filament change.
1953
  * Be sure to turn off auto-retract during filament change.
1951
  *
1954
  *
1952
  * Note that M207 / M208 / M209 settings are saved to EEPROM.
1955
  * Note that M207 / M208 / M209 settings are saved to EEPROM.
1953
- *
1954
  */
1956
  */
1955
 //#define FWRETRACT
1957
 //#define FWRETRACT
1956
 #if ENABLED(FWRETRACT)
1958
 #if ENABLED(FWRETRACT)
1976
  * Universal tool change settings.
1978
  * Universal tool change settings.
1977
  * Applies to all types of extruders except where explicitly noted.
1979
  * Applies to all types of extruders except where explicitly noted.
1978
  */
1980
  */
1979
-#if EXTRUDERS > 1
1981
+#if HAS_MULTI_EXTRUDER
1980
   // Z raise distance for tool-change, as needed for some extruders
1982
   // Z raise distance for tool-change, as needed for some extruders
1981
   #define TOOLCHANGE_ZRAISE                 2 // (mm)
1983
   #define TOOLCHANGE_ZRAISE                 2 // (mm)
1982
   //#define TOOLCHANGE_ZRAISE_BEFORE_RETRACT  // Apply raise before swap retraction (if enabled)
1984
   //#define TOOLCHANGE_ZRAISE_BEFORE_RETRACT  // Apply raise before swap retraction (if enabled)
2040
     //#define TOOLCHANGE_PARK_X_ONLY          // X axis only move
2042
     //#define TOOLCHANGE_PARK_X_ONLY          // X axis only move
2041
     //#define TOOLCHANGE_PARK_Y_ONLY          // Y axis only move
2043
     //#define TOOLCHANGE_PARK_Y_ONLY          // Y axis only move
2042
   #endif
2044
   #endif
2043
-#endif // EXTRUDERS > 1
2045
+#endif // HAS_MULTI_EXTRUDER
2044
 
2046
 
2045
 /**
2047
 /**
2046
  * Advanced Pause
2048
  * Advanced Pause
2487
   #define E7_HYBRID_THRESHOLD     30
2489
   #define E7_HYBRID_THRESHOLD     30
2488
 
2490
 
2489
   /**
2491
   /**
2490
-   * Use StallGuard2 to home / probe X, Y, Z.
2492
+   * Use StallGuard to home / probe X, Y, Z.
2491
    *
2493
    *
2492
    * TMC2130, TMC2160, TMC2209, TMC2660, TMC5130, and TMC5160 only
2494
    * TMC2130, TMC2160, TMC2209, TMC2660, TMC5130, and TMC5160 only
2493
    * Connect the stepper driver's DIAG1 pin to the X/Y endstop pin.
2495
    * Connect the stepper driver's DIAG1 pin to the X/Y endstop pin.
2508
    *
2510
    *
2509
    * IMPROVE_HOMING_RELIABILITY tunes acceleration and jerk when
2511
    * IMPROVE_HOMING_RELIABILITY tunes acceleration and jerk when
2510
    * homing and adds a guard period for endstop triggering.
2512
    * homing and adds a guard period for endstop triggering.
2513
+   *
2514
+   * Comment *_STALL_SENSITIVITY to disable sensorless homing for that axis.
2511
    */
2515
    */
2512
   //#define SENSORLESS_HOMING // StallGuard capable drivers only
2516
   //#define SENSORLESS_HOMING // StallGuard capable drivers only
2513
 
2517
 
3227
 //#define HOST_ACTION_COMMANDS
3231
 //#define HOST_ACTION_COMMANDS
3228
 #if ENABLED(HOST_ACTION_COMMANDS)
3232
 #if ENABLED(HOST_ACTION_COMMANDS)
3229
   //#define HOST_PROMPT_SUPPORT
3233
   //#define HOST_PROMPT_SUPPORT
3234
+  //#define HOST_START_MENU_ITEM  // Add a menu item that tells the host to start
3230
 #endif
3235
 #endif
3231
 
3236
 
3232
 /**
3237
 /**
3334
   #define JOY_X_LIMITS { 5600, 8190-100, 8190+100, 10800 } // min, deadzone start, deadzone end, max
3339
   #define JOY_X_LIMITS { 5600, 8190-100, 8190+100, 10800 } // min, deadzone start, deadzone end, max
3335
   #define JOY_Y_LIMITS { 5600, 8250-100, 8250+100, 11000 }
3340
   #define JOY_Y_LIMITS { 5600, 8250-100, 8250+100, 11000 }
3336
   #define JOY_Z_LIMITS { 4800, 8080-100, 8080+100, 11550 }
3341
   #define JOY_Z_LIMITS { 4800, 8080-100, 8080+100, 11550 }
3342
+  //#define JOYSTICK_DEBUG
3337
 #endif
3343
 #endif
3338
 
3344
 
3339
 /**
3345
 /**
3411
 #if ENABLED(PRUSA_MMU2)
3417
 #if ENABLED(PRUSA_MMU2)
3412
 
3418
 
3413
   // Serial port used for communication with MMU2.
3419
   // Serial port used for communication with MMU2.
3414
-  // For AVR enable the UART port used for the MMU. (e.g., internalSerial)
3420
+  // For AVR enable the UART port used for the MMU. (e.g., mmuSerial)
3415
   // For 32-bit boards check your HAL for available serial ports. (e.g., Serial2)
3421
   // For 32-bit boards check your HAL for available serial ports. (e.g., Serial2)
3416
-  #define INTERNAL_SERIAL_PORT 2
3417
-  #define MMU2_SERIAL internalSerial
3422
+  #define MMU2_SERIAL_PORT 2
3423
+  #define MMU2_SERIAL mmuSerial
3418
 
3424
 
3419
   // Use hardware reset for MMU if a pin is defined for it
3425
   // Use hardware reset for MMU if a pin is defined for it
3420
   //#define MMU2_RST_PIN 23
3426
   //#define MMU2_RST_PIN 23
3465
    */
3471
    */
3466
   //#define MMU_EXTRUDER_SENSOR
3472
   //#define MMU_EXTRUDER_SENSOR
3467
   #if ENABLED(MMU_EXTRUDER_SENSOR)
3473
   #if ENABLED(MMU_EXTRUDER_SENSOR)
3468
-    #define MMU_LOADING_ATTEMPTS_NR 5 //max. number of attempts to load filament if first load fail
3474
+    #define MMU_LOADING_ATTEMPTS_NR 5 // max. number of attempts to load filament if first load fail
3469
   #endif
3475
   #endif
3470
 
3476
 
3471
   /**
3477
   /**

+ 56
- 52
Marlin/Makefile View File

170
 else ifeq ($(HARDWARE_MOTHERBOARD),1101)
170
 else ifeq ($(HARDWARE_MOTHERBOARD),1101)
171
 # Velleman K8400 Controller (derived from 3Drag Controller)
171
 # Velleman K8400 Controller (derived from 3Drag Controller)
172
 else ifeq ($(HARDWARE_MOTHERBOARD),1102)
172
 else ifeq ($(HARDWARE_MOTHERBOARD),1102)
173
-# Velleman K8600 Controller (derived from 3Drag Controller)
173
+# Velleman K8600 Controller (Vertex Nano)
174
 else ifeq ($(HARDWARE_MOTHERBOARD),1103)
174
 else ifeq ($(HARDWARE_MOTHERBOARD),1103)
175
-# 2PrintBeta BAM&DICE with STK drivers
175
+# Velleman K8800 Controller (Vertex Delta)
176
 else ifeq ($(HARDWARE_MOTHERBOARD),1104)
176
 else ifeq ($(HARDWARE_MOTHERBOARD),1104)
177
-# 2PrintBeta BAM&DICE Due with STK drivers
177
+# 2PrintBeta BAM&DICE with STK drivers
178
 else ifeq ($(HARDWARE_MOTHERBOARD),1105)
178
 else ifeq ($(HARDWARE_MOTHERBOARD),1105)
179
-# MKS BASE v1.0
179
+# 2PrintBeta BAM&DICE Due with STK drivers
180
 else ifeq ($(HARDWARE_MOTHERBOARD),1106)
180
 else ifeq ($(HARDWARE_MOTHERBOARD),1106)
181
-# MKS v1.4 with A4982 stepper drivers
181
+# MKS BASE v1.0
182
 else ifeq ($(HARDWARE_MOTHERBOARD),1107)
182
 else ifeq ($(HARDWARE_MOTHERBOARD),1107)
183
-# MKS v1.5 with Allegro A4982 stepper drivers
183
+# MKS v1.4 with A4982 stepper drivers
184
 else ifeq ($(HARDWARE_MOTHERBOARD),1108)
184
 else ifeq ($(HARDWARE_MOTHERBOARD),1108)
185
-# MKS v1.6 with Allegro A4982 stepper drivers
185
+# MKS v1.5 with Allegro A4982 stepper drivers
186
 else ifeq ($(HARDWARE_MOTHERBOARD),1109)
186
 else ifeq ($(HARDWARE_MOTHERBOARD),1109)
187
-# MKS BASE 1.0 with Heroic HR4982 stepper drivers
187
+# MKS v1.6 with Allegro A4982 stepper drivers
188
 else ifeq ($(HARDWARE_MOTHERBOARD),1110)
188
 else ifeq ($(HARDWARE_MOTHERBOARD),1110)
189
-# MKS GEN v1.3 or 1.4
189
+# MKS BASE 1.0 with Heroic HR4982 stepper drivers
190
 else ifeq ($(HARDWARE_MOTHERBOARD),1111)
190
 else ifeq ($(HARDWARE_MOTHERBOARD),1111)
191
-# MKS GEN L
191
+# MKS GEN v1.3 or 1.4
192
 else ifeq ($(HARDWARE_MOTHERBOARD),1112)
192
 else ifeq ($(HARDWARE_MOTHERBOARD),1112)
193
-# zrib V2.0 control board (Chinese knock off RAMPS replica)
193
+# MKS GEN L
194
 else ifeq ($(HARDWARE_MOTHERBOARD),1113)
194
 else ifeq ($(HARDWARE_MOTHERBOARD),1113)
195
-# BigTreeTech or BIQU KFB2.0
195
+# zrib V2.0 control board (Chinese knock off RAMPS replica)
196
 else ifeq ($(HARDWARE_MOTHERBOARD),1114)
196
 else ifeq ($(HARDWARE_MOTHERBOARD),1114)
197
-# Felix 2.0+ Electronics Board (RAMPS like)
197
+# BigTreeTech or BIQU KFB2.0
198
 else ifeq ($(HARDWARE_MOTHERBOARD),1115)
198
 else ifeq ($(HARDWARE_MOTHERBOARD),1115)
199
-# Invent-A-Part RigidBoard
199
+# Felix 2.0+ Electronics Board (RAMPS like)
200
 else ifeq ($(HARDWARE_MOTHERBOARD),1116)
200
 else ifeq ($(HARDWARE_MOTHERBOARD),1116)
201
-# Invent-A-Part RigidBoard V2
201
+# Invent-A-Part RigidBoard
202
 else ifeq ($(HARDWARE_MOTHERBOARD),1117)
202
 else ifeq ($(HARDWARE_MOTHERBOARD),1117)
203
-# Sainsmart 2-in-1 board
203
+# Invent-A-Part RigidBoard V2
204
 else ifeq ($(HARDWARE_MOTHERBOARD),1118)
204
 else ifeq ($(HARDWARE_MOTHERBOARD),1118)
205
-# Ultimaker
205
+# Sainsmart 2-in-1 board
206
 else ifeq ($(HARDWARE_MOTHERBOARD),1119)
206
 else ifeq ($(HARDWARE_MOTHERBOARD),1119)
207
-# Ultimaker (Older electronics. Pre 1.5.4. This is rare)
207
+# Ultimaker
208
 else ifeq ($(HARDWARE_MOTHERBOARD),1120)
208
 else ifeq ($(HARDWARE_MOTHERBOARD),1120)
209
+# Ultimaker (Older electronics. Pre 1.5.4. This is rare)
210
+else ifeq ($(HARDWARE_MOTHERBOARD),1121)
209
   MCU ?= atmega1280
211
   MCU ?= atmega1280
210
 
212
 
211
 # Azteeg X3
213
 # Azteeg X3
212
-else ifeq ($(HARDWARE_MOTHERBOARD),1121)
213
-# Azteeg X3 Pro
214
 else ifeq ($(HARDWARE_MOTHERBOARD),1122)
214
 else ifeq ($(HARDWARE_MOTHERBOARD),1122)
215
-# Ultimainboard 2.x (Uses TEMP_SENSOR 20)
215
+# Azteeg X3 Pro
216
 else ifeq ($(HARDWARE_MOTHERBOARD),1123)
216
 else ifeq ($(HARDWARE_MOTHERBOARD),1123)
217
-# Rumba
217
+# Ultimainboard 2.x (Uses TEMP_SENSOR 20)
218
 else ifeq ($(HARDWARE_MOTHERBOARD),1124)
218
 else ifeq ($(HARDWARE_MOTHERBOARD),1124)
219
-# Raise3D Rumba
219
+# Rumba
220
 else ifeq ($(HARDWARE_MOTHERBOARD),1125)
220
 else ifeq ($(HARDWARE_MOTHERBOARD),1125)
221
-# Rapide Lite RL200 Rumba
221
+# Raise3D Rumba
222
 else ifeq ($(HARDWARE_MOTHERBOARD),1126)
222
 else ifeq ($(HARDWARE_MOTHERBOARD),1126)
223
-# Formbot T-Rex 2 Plus
223
+# Rapide Lite RL200 Rumba
224
 else ifeq ($(HARDWARE_MOTHERBOARD),1127)
224
 else ifeq ($(HARDWARE_MOTHERBOARD),1127)
225
-# Formbot T-Rex 3
225
+# Formbot T-Rex 2 Plus
226
 else ifeq ($(HARDWARE_MOTHERBOARD),1128)
226
 else ifeq ($(HARDWARE_MOTHERBOARD),1128)
227
-# Formbot Raptor
227
+# Formbot T-Rex 3
228
 else ifeq ($(HARDWARE_MOTHERBOARD),1129)
228
 else ifeq ($(HARDWARE_MOTHERBOARD),1129)
229
-# Formbot Raptor 2
229
+# Formbot Raptor
230
 else ifeq ($(HARDWARE_MOTHERBOARD),1130)
230
 else ifeq ($(HARDWARE_MOTHERBOARD),1130)
231
-# bq ZUM Mega 3D
231
+# Formbot Raptor 2
232
 else ifeq ($(HARDWARE_MOTHERBOARD),1131)
232
 else ifeq ($(HARDWARE_MOTHERBOARD),1131)
233
-# MakeBoard Mini v2.1.2 is a control board sold by MicroMake
233
+# bq ZUM Mega 3D
234
 else ifeq ($(HARDWARE_MOTHERBOARD),1132)
234
 else ifeq ($(HARDWARE_MOTHERBOARD),1132)
235
-# TriGorilla Anycubic version 1.3 based on RAMPS EFB
235
+# MakeBoard Mini v2.1.2 is a control board sold by MicroMake
236
 else ifeq ($(HARDWARE_MOTHERBOARD),1133)
236
 else ifeq ($(HARDWARE_MOTHERBOARD),1133)
237
-# TriGorilla Anycubic version 1.4 based on RAMPS EFB
237
+# TriGorilla Anycubic version 1.3 based on RAMPS EFB
238
 else ifeq ($(HARDWARE_MOTHERBOARD),1134)
238
 else ifeq ($(HARDWARE_MOTHERBOARD),1134)
239
-# TriGorilla Anycubic version 1.4 Rev 1.1
239
+# TriGorilla Anycubic version 1.4 based on RAMPS EFB
240
 else ifeq ($(HARDWARE_MOTHERBOARD),1135)
240
 else ifeq ($(HARDWARE_MOTHERBOARD),1135)
241
-# Creality: Ender-4, CR-8
241
+# TriGorilla Anycubic version 1.4 Rev 1.1
242
 else ifeq ($(HARDWARE_MOTHERBOARD),1136)
242
 else ifeq ($(HARDWARE_MOTHERBOARD),1136)
243
-# Creality: CR10S, CR20, CR-X
243
+# Creality: Ender-4, CR-8
244
 else ifeq ($(HARDWARE_MOTHERBOARD),1137)
244
 else ifeq ($(HARDWARE_MOTHERBOARD),1137)
245
-# Dagoma F5
245
+# Creality: CR10S, CR20, CR-X
246
 else ifeq ($(HARDWARE_MOTHERBOARD),1138)
246
 else ifeq ($(HARDWARE_MOTHERBOARD),1138)
247
-# FYSETC F6 1.3
247
+# Dagoma F5
248
 else ifeq ($(HARDWARE_MOTHERBOARD),1139)
248
 else ifeq ($(HARDWARE_MOTHERBOARD),1139)
249
-# FYSETC F6 1.5
249
+# FYSETC F6 1.3
250
 else ifeq ($(HARDWARE_MOTHERBOARD),1140)
250
 else ifeq ($(HARDWARE_MOTHERBOARD),1140)
251
-# Duplicator i3 Plus
251
+# FYSETC F6 1.5
252
 else ifeq ($(HARDWARE_MOTHERBOARD),1141)
252
 else ifeq ($(HARDWARE_MOTHERBOARD),1141)
253
-# VORON
253
+# Duplicator i3 Plus
254
 else ifeq ($(HARDWARE_MOTHERBOARD),1142)
254
 else ifeq ($(HARDWARE_MOTHERBOARD),1142)
255
-# TRONXY V3 1.0
255
+# VORON
256
 else ifeq ($(HARDWARE_MOTHERBOARD),1143)
256
 else ifeq ($(HARDWARE_MOTHERBOARD),1143)
257
-# Z-Bolt X Series
257
+# TRONXY V3 1.0
258
 else ifeq ($(HARDWARE_MOTHERBOARD),1144)
258
 else ifeq ($(HARDWARE_MOTHERBOARD),1144)
259
-# TT OSCAR
259
+# Z-Bolt X Series
260
 else ifeq ($(HARDWARE_MOTHERBOARD),1145)
260
 else ifeq ($(HARDWARE_MOTHERBOARD),1145)
261
-# Overlord/Overlord Pro
261
+# TT OSCAR
262
 else ifeq ($(HARDWARE_MOTHERBOARD),1146)
262
 else ifeq ($(HARDWARE_MOTHERBOARD),1146)
263
-# ADIMLab Gantry v1
263
+# Overlord/Overlord Pro
264
 else ifeq ($(HARDWARE_MOTHERBOARD),1147)
264
 else ifeq ($(HARDWARE_MOTHERBOARD),1147)
265
-# ADIMLab Gantry v2
265
+# ADIMLab Gantry v1
266
 else ifeq ($(HARDWARE_MOTHERBOARD),1148)
266
 else ifeq ($(HARDWARE_MOTHERBOARD),1148)
267
-# BIQU Tango V1
267
+# ADIMLab Gantry v2
268
 else ifeq ($(HARDWARE_MOTHERBOARD),1149)
268
 else ifeq ($(HARDWARE_MOTHERBOARD),1149)
269
-# MKS GEN L V2
269
+# BIQU Tango V1
270
 else ifeq ($(HARDWARE_MOTHERBOARD),1150)
270
 else ifeq ($(HARDWARE_MOTHERBOARD),1150)
271
-# Copymaster 3D
271
+# MKS GEN L V2
272
 else ifeq ($(HARDWARE_MOTHERBOARD),1151)
272
 else ifeq ($(HARDWARE_MOTHERBOARD),1151)
273
-# Ortur 4
273
+# MKS GEN L V2.1
274
 else ifeq ($(HARDWARE_MOTHERBOARD),1152)
274
 else ifeq ($(HARDWARE_MOTHERBOARD),1152)
275
-# Tenlog D3 Hero
275
+# Copymaster 3D
276
 else ifeq ($(HARDWARE_MOTHERBOARD),1153)
276
 else ifeq ($(HARDWARE_MOTHERBOARD),1153)
277
+# Ortur 4
278
+else ifeq ($(HARDWARE_MOTHERBOARD),1154)
279
+# Tenlog D3 Hero
280
+else ifeq ($(HARDWARE_MOTHERBOARD),1155)
277
 
281
 
278
 #
282
 #
279
 # RAMBo and derivatives
283
 # RAMBo and derivatives
694
   LIB_CXXSRC += usb_api.cpp
698
   LIB_CXXSRC += usb_api.cpp
695
 
699
 
696
 else ifeq ($(HARDWARE_VARIANT), archim)
700
 else ifeq ($(HARDWARE_VARIANT), archim)
697
-  CDEFS      += -DARDUINO_SAM_ARCHIM -DARDUINO_ARCH_SAM -D__SAM3X8E__ -DUSB_VID=0x27b1 -DUSB_PID=0x0001 -DUSBCON '-DUSB_MANUFACTURER="UltiMachine"' '-DUSB_PRODUCT="Archim"'
701
+  CDEFS      += -DARDUINO_SAM_ARCHIM -DARDUINO_ARCH_SAM -D__SAM3X8E__ -DUSB_VID=0x27b1 -DUSB_PID=0x0001 -DUSBCON '-DUSB_MANUFACTURER="UltiMachine"' '-DUSB_PRODUCT_STRING="Archim"'
698
   LIB_CXXSRC += variant.cpp IPAddress.cpp Reset.cpp RingBuffer.cpp Stream.cpp UARTClass.cpp  USARTClass.cpp abi.cpp new.cpp watchdog.cpp CDC.cpp PluggableUSB.cpp USBCore.cpp
702
   LIB_CXXSRC += variant.cpp IPAddress.cpp Reset.cpp RingBuffer.cpp Stream.cpp UARTClass.cpp  USARTClass.cpp abi.cpp new.cpp watchdog.cpp CDC.cpp PluggableUSB.cpp USBCore.cpp
699
   LIB_SRC    += cortex_handlers.c iar_calls_sam3.c syscalls_sam3.c dtostrf.c itoa.c
703
   LIB_SRC    += cortex_handlers.c iar_calls_sam3.c syscalls_sam3.c dtostrf.c itoa.c
700
 
704
 

+ 8
- 32
Marlin/src/HAL/AVR/HAL.h View File

15
  *
15
  *
16
  * You should have received a copy of the GNU General Public License
16
  * You should have received a copy of the GNU General Public License
17
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
+ *
18
  */
19
  */
19
 #pragma once
20
 #pragma once
20
 
21
 
81
 
82
 
82
 // Serial ports
83
 // Serial ports
83
 #ifdef USBCON
84
 #ifdef USBCON
84
-  #if ENABLED(BLUETOOTH)
85
-    #define MYSERIAL0 bluetoothSerial
86
-  #else
87
-    #define MYSERIAL0 Serial
88
-  #endif
89
-  #define NUM_SERIAL 1
85
+  #define MYSERIAL0 TERN(BLUETOOTH, bluetoothSerial, Serial)
90
 #else
86
 #else
91
   #if !WITHIN(SERIAL_PORT, -1, 3)
87
   #if !WITHIN(SERIAL_PORT, -1, 3)
92
     #error "SERIAL_PORT must be from -1 to 3. Please update your configuration."
88
     #error "SERIAL_PORT must be from -1 to 3. Please update your configuration."
93
   #endif
89
   #endif
94
-
95
   #define MYSERIAL0 customizedSerial1
90
   #define MYSERIAL0 customizedSerial1
96
 
91
 
97
   #ifdef SERIAL_PORT_2
92
   #ifdef SERIAL_PORT_2
98
     #if !WITHIN(SERIAL_PORT_2, -1, 3)
93
     #if !WITHIN(SERIAL_PORT_2, -1, 3)
99
       #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
94
       #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
100
-    #elif SERIAL_PORT_2 == SERIAL_PORT
101
-      #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration."
102
     #endif
95
     #endif
103
     #define MYSERIAL1 customizedSerial2
96
     #define MYSERIAL1 customizedSerial2
104
-    #define NUM_SERIAL 2
105
-  #else
106
-    #define NUM_SERIAL 1
107
   #endif
97
   #endif
108
 #endif
98
 #endif
109
 
99
 
110
-#ifdef DGUS_SERIAL_PORT
111
-  #if !WITHIN(DGUS_SERIAL_PORT, -1, 3)
112
-    #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration."
113
-  #elif DGUS_SERIAL_PORT == SERIAL_PORT
114
-    #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration."
115
-  #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2
116
-    #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration."
100
+#ifdef LCD_SERIAL_PORT
101
+  #if !WITHIN(LCD_SERIAL_PORT, -1, 3)
102
+    #error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
117
   #endif
103
   #endif
118
-  #define DGUS_SERIAL internalDgusSerial
119
-
120
-  #define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.get_tx_buffer_free
121
-#endif
122
-
123
-#ifdef ANYCUBIC_LCD_SERIAL_PORT
124
-  #if !WITHIN(ANYCUBIC_LCD_SERIAL_PORT, -1, 3)
125
-    #error "ANYCUBIC_LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
126
-  #elif ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT
127
-    #error "ANYCUBIC_LCD_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration."
128
-  #elif defined(SERIAL_PORT_2) && ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT_2
129
-    #error "ANYCUBIC_LCD_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration."
104
+  #define LCD_SERIAL lcdSerial
105
+  #if HAS_DGUS_LCD
106
+    #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.get_tx_buffer_free()
130
   #endif
107
   #endif
131
-  #define ANYCUBIC_LCD_SERIAL anycubicLcdSerial
132
 #endif
108
 #endif
133
 
109
 
134
 // ------------------------
110
 // ------------------------

+ 606
- 622
Marlin/src/HAL/AVR/MarlinSerial.cpp
File diff suppressed because it is too large
View File


+ 35
- 38
Marlin/src/HAL/AVR/MarlinSerial.h View File

48
 
48
 
49
   // These are macros to build serial port register names for the selected SERIAL_PORT (C preprocessor
49
   // These are macros to build serial port register names for the selected SERIAL_PORT (C preprocessor
50
   // requires two levels of indirection to expand macro values properly)
50
   // requires two levels of indirection to expand macro values properly)
51
-  #define SERIAL_REGNAME(registerbase,number,suffix) SERIAL_REGNAME_INTERNAL(registerbase,number,suffix)
51
+  #define SERIAL_REGNAME(registerbase,number,suffix) _SERIAL_REGNAME(registerbase,number,suffix)
52
   #if SERIAL_PORT == 0 && (!defined(UBRR0H) || !defined(UDR0)) // use un-numbered registers if necessary
52
   #if SERIAL_PORT == 0 && (!defined(UBRR0H) || !defined(UDR0)) // use un-numbered registers if necessary
53
-    #define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##suffix
53
+    #define _SERIAL_REGNAME(registerbase,number,suffix) registerbase##suffix
54
   #else
54
   #else
55
-    #define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##number##suffix
55
+    #define _SERIAL_REGNAME(registerbase,number,suffix) registerbase##number##suffix
56
   #endif
56
   #endif
57
 
57
 
58
   // Registers used by MarlinSerial class (expanded depending on selected serial port)
58
   // Registers used by MarlinSerial class (expanded depending on selected serial port)
217
       static ring_buffer_pos_t available();
217
       static ring_buffer_pos_t available();
218
       static void write(const uint8_t c);
218
       static void write(const uint8_t c);
219
       static void flushTX();
219
       static void flushTX();
220
-      #ifdef DGUS_SERIAL_PORT
220
+      #if HAS_DGUS_LCD
221
         static ring_buffer_pos_t get_tx_buffer_free();
221
         static ring_buffer_pos_t get_tx_buffer_free();
222
       #endif
222
       #endif
223
 
223
 
224
+      static inline bool emergency_parser_enabled() { return Cfg::EMERGENCYPARSER; }
225
+
224
       FORCE_INLINE static uint8_t dropped() { return Cfg::DROPPED_RX ? rx_dropped_bytes : 0; }
226
       FORCE_INLINE static uint8_t dropped() { return Cfg::DROPPED_RX ? rx_dropped_bytes : 0; }
225
       FORCE_INLINE static uint8_t buffer_overruns() { return Cfg::RX_OVERRUNS ? rx_buffer_overruns : 0; }
227
       FORCE_INLINE static uint8_t buffer_overruns() { return Cfg::RX_OVERRUNS ? rx_buffer_overruns : 0; }
226
       FORCE_INLINE static uint8_t framing_errors() { return Cfg::RX_FRAMING_ERRORS ? rx_framing_errors : 0; }
228
       FORCE_INLINE static uint8_t framing_errors() { return Cfg::RX_FRAMING_ERRORS ? rx_framing_errors : 0; }
278
 
280
 
279
 #endif // !USBCON
281
 #endif // !USBCON
280
 
282
 
281
-#ifdef INTERNAL_SERIAL_PORT
283
+#ifdef MMU2_SERIAL_PORT
282
   template <uint8_t serial>
284
   template <uint8_t serial>
283
-  struct MarlinInternalSerialCfg {
285
+  struct MMU2SerialCfg {
284
     static constexpr int PORT               = serial;
286
     static constexpr int PORT               = serial;
285
-    static constexpr unsigned int RX_SIZE   = 32;
286
-    static constexpr unsigned int TX_SIZE   = 32;
287
     static constexpr bool XONOFF            = false;
287
     static constexpr bool XONOFF            = false;
288
     static constexpr bool EMERGENCYPARSER   = false;
288
     static constexpr bool EMERGENCYPARSER   = false;
289
     static constexpr bool DROPPED_RX        = false;
289
     static constexpr bool DROPPED_RX        = false;
290
-    static constexpr bool RX_OVERRUNS       = false;
291
     static constexpr bool RX_FRAMING_ERRORS = false;
290
     static constexpr bool RX_FRAMING_ERRORS = false;
292
     static constexpr bool MAX_RX_QUEUED     = false;
291
     static constexpr bool MAX_RX_QUEUED     = false;
292
+    static constexpr unsigned int RX_SIZE   = 32;
293
+    static constexpr unsigned int TX_SIZE   = 32;
294
+    static constexpr bool RX_OVERRUNS       = false;
293
   };
295
   };
294
 
296
 
295
-  extern MarlinSerial<MarlinInternalSerialCfg<INTERNAL_SERIAL_PORT>> internalSerial;
297
+  extern MarlinSerial<MMU2SerialCfg<MMU2_SERIAL_PORT>> mmuSerial;
296
 #endif
298
 #endif
297
 
299
 
298
-#ifdef DGUS_SERIAL_PORT
299
-  template <uint8_t serial>
300
-  struct MarlinInternalSerialCfg {
301
-    static constexpr int PORT               = serial;
302
-    static constexpr unsigned int RX_SIZE   = DGUS_RX_BUFFER_SIZE;
303
-    static constexpr unsigned int TX_SIZE   = DGUS_TX_BUFFER_SIZE;
304
-    static constexpr bool XONOFF            = false;
305
-    static constexpr bool EMERGENCYPARSER   = false;
306
-    static constexpr bool DROPPED_RX        = false;
307
-    static constexpr bool RX_OVERRUNS       = BOTH(HAS_DGUS_LCD, DGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS);
308
-    static constexpr bool RX_FRAMING_ERRORS = false;
309
-    static constexpr bool MAX_RX_QUEUED     = false;
310
-  };
311
-
312
-  extern MarlinSerial<MarlinInternalSerialCfg<DGUS_SERIAL_PORT>> internalDgusSerial;
313
-#endif
300
+#ifdef LCD_SERIAL_PORT
314
 
301
 
315
-#ifdef ANYCUBIC_LCD_SERIAL_PORT
316
   template <uint8_t serial>
302
   template <uint8_t serial>
317
-  struct AnycubicLcdSerialCfg {
318
-    static constexpr int PORT               = serial;
319
-    static constexpr unsigned int RX_SIZE   = 64;
320
-    static constexpr unsigned int TX_SIZE   = 128;
321
-    static constexpr bool XONOFF            = false;
322
-    static constexpr bool EMERGENCYPARSER   = false;
323
-    static constexpr bool DROPPED_RX        = false;
324
-    static constexpr bool RX_OVERRUNS       = false;
325
-    static constexpr bool RX_FRAMING_ERRORS = false;
326
-    static constexpr bool MAX_RX_QUEUED     = false;
303
+  struct LCDSerialCfg {
304
+    static constexpr int PORT                 = serial;
305
+    static constexpr bool XONOFF              = false;
306
+    static constexpr bool EMERGENCYPARSER     = ENABLED(EMERGENCY_PARSER);
307
+    static constexpr bool DROPPED_RX          = false;
308
+    static constexpr bool RX_FRAMING_ERRORS   = false;
309
+    static constexpr bool MAX_RX_QUEUED       = false;
310
+    #if HAS_DGUS_LCD
311
+      static constexpr unsigned int RX_SIZE   = DGUS_RX_BUFFER_SIZE;
312
+      static constexpr unsigned int TX_SIZE   = DGUS_TX_BUFFER_SIZE;
313
+      static constexpr bool RX_OVERRUNS       = ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS);
314
+    #elif EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON)
315
+      static constexpr unsigned int RX_SIZE   = 64;
316
+      static constexpr unsigned int TX_SIZE   = 128;
317
+      static constexpr bool RX_OVERRUNS       = false;
318
+    #else
319
+      static constexpr unsigned int RX_SIZE   = 64;
320
+      static constexpr unsigned int TX_SIZE   = 128;
321
+      static constexpr bool RX_OVERRUNS       = false
322
+    #endif
327
   };
323
   };
328
 
324
 
329
-  extern MarlinSerial<AnycubicLcdSerialCfg<ANYCUBIC_LCD_SERIAL_PORT>> anycubicLcdSerial;
325
+  extern MarlinSerial<LCDSerialCfg<LCD_SERIAL_PORT>> lcdSerial;
326
+
330
 #endif
327
 #endif
331
 
328
 
332
 // Use the UART for Bluetooth in AT90USB configurations
329
 // Use the UART for Bluetooth in AT90USB configurations

+ 0
- 1
Marlin/src/HAL/AVR/Servo.cpp View File

48
  * readMicroseconds()    - Get the last-written servo pulse width in microseconds.
48
  * readMicroseconds()    - Get the last-written servo pulse width in microseconds.
49
  * attached()            - Return true if a servo is attached.
49
  * attached()            - Return true if a servo is attached.
50
  * detach()              - Stop an attached servo from pulsing its i/o pin.
50
  * detach()              - Stop an attached servo from pulsing its i/o pin.
51
- *
52
  */
51
  */
53
 
52
 
54
 #ifdef __AVR__
53
 #ifdef __AVR__

+ 11
- 5
Marlin/src/HAL/AVR/fastio.h View File

29
 
29
 
30
 #include <avr/io.h>
30
 #include <avr/io.h>
31
 
31
 
32
-#define AVR_AT90USB1286_FAMILY (defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1286P__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB646P__) || defined(__AVR_AT90USB647__))
33
-#define AVR_ATmega1284_FAMILY (defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284P__))
34
-#define AVR_ATmega2560_FAMILY (defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__))
35
-#define AVR_ATmega2561_FAMILY (defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__))
36
-#define AVR_ATmega328_FAMILY (defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__))
32
+#if defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1286P__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB646P__) || defined(__AVR_AT90USB647__)
33
+  #define AVR_AT90USB1286_FAMILY 1
34
+#elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284P__)
35
+  #define AVR_ATmega1284_FAMILY 1
36
+#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
37
+  #define AVR_ATmega2560_FAMILY 1
38
+#elif defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__)
39
+  #define AVR_ATmega2561_FAMILY 1
40
+#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
41
+  #define AVR_ATmega328_FAMILY 1
42
+#endif
37
 
43
 
38
 /**
44
 /**
39
  * Include Ports and Functions
45
  * Include Ports and Functions

+ 3
- 1
Marlin/src/HAL/AVR/pinsDebug.h View File

26
 
26
 
27
 #define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
27
 #define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
28
 
28
 
29
-#define AVR_ATmega2560_FAMILY_PLUS_70 MB(BQ_ZUM_MEGA_3D, MIGHTYBOARD_REVE, MINIRAMBO, SCOOVO_X9H)
29
+#if MB(BQ_ZUM_MEGA_3D, MIGHTYBOARD_REVE, MINIRAMBO, SCOOVO_X9H, TRIGORILLA_14)
30
+  #define AVR_ATmega2560_FAMILY_PLUS_70 1
31
+#endif
30
 
32
 
31
 #if AVR_AT90USB1286_FAMILY
33
 #if AVR_AT90USB1286_FAMILY
32
 
34
 

+ 3
- 6
Marlin/src/HAL/AVR/pinsDebug_plus_70.h View File

22
  * Structures for 2560 family boards that use more than 70 pins
22
  * Structures for 2560 family boards that use more than 70 pins
23
  */
23
  */
24
 
24
 
25
-#undef NUM_DIGITAL_PINS
26
-#if MB(BQ_ZUM_MEGA_3D)
25
+#if MB(BQ_ZUM_MEGA_3D, MINIRAMBO, SCOOVO_X9H, TRIGORILLA_14)
26
+  #undef NUM_DIGITAL_PINS
27
   #define NUM_DIGITAL_PINS            85
27
   #define NUM_DIGITAL_PINS            85
28
 #elif MB(MIGHTYBOARD_REVE)
28
 #elif MB(MIGHTYBOARD_REVE)
29
+  #undef NUM_DIGITAL_PINS
29
   #define NUM_DIGITAL_PINS            80
30
   #define NUM_DIGITAL_PINS            80
30
-#elif MB(MINIRAMBO)
31
-  #define NUM_DIGITAL_PINS            85
32
-#elif MB(SCOOVO_X9H)
33
-  #define NUM_DIGITAL_PINS            85
34
 #endif
31
 #endif
35
 
32
 
36
 #define PA 1
33
 #define PA 1

+ 1
- 0
Marlin/src/HAL/AVR/timers.h View File

15
  *
15
  *
16
  * You should have received a copy of the GNU General Public License
16
  * You should have received a copy of the GNU General Public License
17
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
+ *
18
  */
19
  */
19
 #pragma once
20
 #pragma once
20
 
21
 

+ 2
- 2
Marlin/src/HAL/AVR/u8g_com_HAL_AVR_sw_spi.cpp View File

57
 
57
 
58
 #include "../../inc/MarlinConfigPre.h"
58
 #include "../../inc/MarlinConfigPre.h"
59
 
59
 
60
-#if HAS_GRAPHICAL_LCD
60
+#if HAS_MARLINUI_U8GLIB
61
 
61
 
62
 #include "../shared/Marduino.h"
62
 #include "../shared/Marduino.h"
63
 #include "../shared/Delay.h"
63
 #include "../shared/Delay.h"
189
   return 1;
189
   return 1;
190
 }
190
 }
191
 
191
 
192
-#endif // HAS_GRAPHICAL_LCD
192
+#endif // HAS_MARLINUI_U8GLIB
193
 #endif // ARDUINO_ARCH_SAM
193
 #endif // ARDUINO_ARCH_SAM

+ 15
- 38
Marlin/src/HAL/DUE/HAL.h View File

38
 
38
 
39
 #include <stdint.h>
39
 #include <stdint.h>
40
 
40
 
41
+#define _MSERIAL(X) Serial##X
42
+#define MSERIAL(X) _MSERIAL(X)
43
+#define Serial0 Serial
44
+
41
 // Define MYSERIAL0/1 before MarlinSerial includes!
45
 // Define MYSERIAL0/1 before MarlinSerial includes!
42
 #if SERIAL_PORT == -1 || ENABLED(EMERGENCY_PARSER)
46
 #if SERIAL_PORT == -1 || ENABLED(EMERGENCY_PARSER)
43
   #define MYSERIAL0 customizedSerial1
47
   #define MYSERIAL0 customizedSerial1
44
-#elif SERIAL_PORT == 0
45
-  #define MYSERIAL0 Serial
46
-#elif SERIAL_PORT == 1
47
-  #define MYSERIAL0 Serial1
48
-#elif SERIAL_PORT == 2
49
-  #define MYSERIAL0 Serial2
50
-#elif SERIAL_PORT == 3
51
-  #define MYSERIAL0 Serial3
48
+#elif WITHIN(SERIAL_PORT, 0, 3)
49
+  #define MYSERIAL0 MSERIAL(SERIAL_PORT)
52
 #else
50
 #else
53
   #error "The required SERIAL_PORT must be from -1 to 3. Please update your configuration."
51
   #error "The required SERIAL_PORT must be from -1 to 3. Please update your configuration."
54
 #endif
52
 #endif
55
 
53
 
56
 #ifdef SERIAL_PORT_2
54
 #ifdef SERIAL_PORT_2
57
-  #if SERIAL_PORT_2 == SERIAL_PORT
58
-    #error "SERIAL_PORT_2 must be different from SERIAL_PORT. Please update your configuration."
59
-  #elif SERIAL_PORT_2 == -1 || ENABLED(EMERGENCY_PARSER)
55
+  #if SERIAL_PORT_2 == -1 || ENABLED(EMERGENCY_PARSER)
60
     #define MYSERIAL1 customizedSerial2
56
     #define MYSERIAL1 customizedSerial2
61
-  #elif SERIAL_PORT_2 == 0
62
-    #define MYSERIAL1 Serial
63
-  #elif SERIAL_PORT_2 == 1
64
-    #define MYSERIAL1 Serial1
65
-  #elif SERIAL_PORT_2 == 2
66
-    #define MYSERIAL1 Serial2
67
-  #elif SERIAL_PORT_2 == 3
68
-    #define MYSERIAL1 Serial3
57
+  #elif WITHIN(SERIAL_PORT_2, 0, 3)
58
+    #define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
69
   #else
59
   #else
70
     #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
60
     #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
71
   #endif
61
   #endif
72
-  #define NUM_SERIAL 2
73
-#else
74
-  #define NUM_SERIAL 1
75
 #endif
62
 #endif
76
 
63
 
77
-#ifdef DGUS_SERIAL_PORT
78
-  #if DGUS_SERIAL_PORT == SERIAL_PORT
79
-    #error "DGUS_SERIAL_PORT must be different from SERIAL_PORT. Please update your configuration."
80
-  #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2
81
-    #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration."
82
-  #elif DGUS_SERIAL_PORT == -1
83
-    #define DGUS_SERIAL internalDgusSerial
84
-  #elif DGUS_SERIAL_PORT == 0
85
-    #define DGUS_SERIAL Serial
86
-  #elif DGUS_SERIAL_PORT == 1
87
-    #define DGUS_SERIAL Serial1
88
-  #elif DGUS_SERIAL_PORT == 2
89
-    #define DGUS_SERIAL Serial2
90
-  #elif DGUS_SERIAL_PORT == 3
91
-    #define DGUS_SERIAL Serial3
64
+#ifdef LCD_SERIAL_PORT
65
+  #if LCD_SERIAL_PORT == -1
66
+    #define LCD_SERIAL lcdSerial
67
+  #elif WITHIN(LCD_SERIAL_PORT, 0, 3)
68
+    #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
92
   #else
69
   #else
93
-    #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration."
70
+    #error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
94
   #endif
71
   #endif
95
 #endif
72
 #endif
96
 
73
 

+ 1
- 2
Marlin/src/HAL/DUE/HAL_SPI.cpp View File

595
       SPI_Enable(SPI0);
595
       SPI_Enable(SPI0);
596
 
596
 
597
       SET_OUTPUT(DAC0_SYNC);
597
       SET_OUTPUT(DAC0_SYNC);
598
-      #if EXTRUDERS > 1
598
+      #if HAS_MULTI_EXTRUDER
599
         SET_OUTPUT(DAC1_SYNC);
599
         SET_OUTPUT(DAC1_SYNC);
600
         WRITE(DAC1_SYNC, HIGH);
600
         WRITE(DAC1_SYNC, HIGH);
601
       #endif
601
       #endif
759
      *
759
      *
760
      *  All of the above can be avoided by defining FORCE_SOFT_SPI to force the
760
      *  All of the above can be avoided by defining FORCE_SOFT_SPI to force the
761
      *  display to use software SPI.
761
      *  display to use software SPI.
762
-     *
763
      */
762
      */
764
 
763
 
765
     void spiInit(uint8_t spiRate=6) {  // Default to slowest rate if not specified)
764
     void spiInit(uint8_t spiRate=6) {  // Default to slowest rate if not specified)

+ 2
- 0
Marlin/src/HAL/DUE/MarlinSerial.h View File

122
   static void write(const uint8_t c);
122
   static void write(const uint8_t c);
123
   static void flushTX();
123
   static void flushTX();
124
 
124
 
125
+  static inline bool emergency_parser_enabled() { return Cfg::EMERGENCYPARSER; }
126
+
125
   FORCE_INLINE static uint8_t dropped() { return Cfg::DROPPED_RX ? rx_dropped_bytes : 0; }
127
   FORCE_INLINE static uint8_t dropped() { return Cfg::DROPPED_RX ? rx_dropped_bytes : 0; }
126
   FORCE_INLINE static uint8_t buffer_overruns() { return Cfg::RX_OVERRUNS ? rx_buffer_overruns : 0; }
128
   FORCE_INLINE static uint8_t buffer_overruns() { return Cfg::RX_OVERRUNS ? rx_buffer_overruns : 0; }
127
   FORCE_INLINE static uint8_t framing_errors() { return Cfg::RX_FRAMING_ERRORS ? rx_framing_errors : 0; }
129
   FORCE_INLINE static uint8_t framing_errors() { return Cfg::RX_FRAMING_ERRORS ? rx_framing_errors : 0; }

+ 3
- 4
Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_shared_hw_spi.cpp View File

52
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
54
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55
- *
56
  */
55
  */
57
 
56
 
58
 #ifdef __SAM3X8E__
57
 #ifdef __SAM3X8E__
59
 
58
 
60
 #include "../../../inc/MarlinConfigPre.h"
59
 #include "../../../inc/MarlinConfigPre.h"
61
 
60
 
62
-#if HAS_GRAPHICAL_LCD
61
+#if HAS_MARLINUI_U8GLIB
63
 
62
 
64
 #include <U8glib.h>
63
 #include <U8glib.h>
65
 
64
 
145
   return 1;
144
   return 1;
146
 }
145
 }
147
 
146
 
148
-#endif // HAS_GRAPHICAL_LCD
147
+#endif // HAS_MARLINUI_U8GLIB
149
 
148
 
150
-#endif //__SAM3X8E__
149
+#endif // __SAM3X8E__

+ 2
- 2
Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi.cpp View File

57
 
57
 
58
 #include "../../../inc/MarlinConfigPre.h"
58
 #include "../../../inc/MarlinConfigPre.h"
59
 
59
 
60
-#if HAS_GRAPHICAL_LCD && DISABLED(U8GLIB_ST7920)
60
+#if HAS_MARLINUI_U8GLIB && DISABLED(U8GLIB_ST7920)
61
 
61
 
62
 #undef SPI_SPEED
62
 #undef SPI_SPEED
63
 #define SPI_SPEED 2  // About 2 MHz
63
 #define SPI_SPEED 2  // About 2 MHz
144
   return 1;
144
   return 1;
145
 }
145
 }
146
 
146
 
147
-#endif // HAS_GRAPHICAL_LCD && !U8GLIB_ST7920
147
+#endif // HAS_MARLINUI_U8GLIB && !U8GLIB_ST7920
148
 #endif // ARDUINO_ARCH_SAM
148
 #endif // ARDUINO_ARCH_SAM

+ 2
- 2
Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp View File

57
 
57
 
58
 #include "../../../inc/MarlinConfigPre.h"
58
 #include "../../../inc/MarlinConfigPre.h"
59
 
59
 
60
-#if HAS_GRAPHICAL_LCD
60
+#if HAS_MARLINUI_U8GLIB
61
 
61
 
62
 #include "../../shared/Delay.h"
62
 #include "../../shared/Delay.h"
63
 
63
 
108
   }
108
   }
109
 }
109
 }
110
 
110
 
111
-#endif // HAS_GRAPHICAL_LCD
111
+#endif // HAS_MARLINUI_U8GLIB
112
 #endif // ARDUINO_ARCH_SAM
112
 #endif // ARDUINO_ARCH_SAM

+ 0
- 1
Marlin/src/HAL/DUE/eeprom_flash.cpp View File

53
  * per page. We can't emulate EE endurance with FLASH for all
53
  * per page. We can't emulate EE endurance with FLASH for all
54
  * bytes, but we can emulate endurance for a given percent of
54
  * bytes, but we can emulate endurance for a given percent of
55
  * bytes.
55
  * bytes.
56
- *
57
  */
56
  */
58
 
57
 
59
 //#define EE_EMU_DEBUG
58
 //#define EE_EMU_DEBUG

+ 0
- 1
Marlin/src/HAL/DUE/pinsDebug.h View File

179
  * ----------------+--------
179
  * ----------------+--------
180
  *  ID             |  PB11
180
  *  ID             |  PB11
181
  *  VBOF           |  PB10
181
  *  VBOF           |  PB10
182
- *
183
  */
182
  */

+ 19
- 20
Marlin/src/HAL/DUE/usb/compiler.h View File

173
 #   define __always_inline   __forceinline
173
 #   define __always_inline   __forceinline
174
 #elif (defined __GNUC__)
174
 #elif (defined __GNUC__)
175
 #ifdef __always_inline
175
 #ifdef __always_inline
176
-#	undef __always_inline
176
+# undef __always_inline
177
 #endif
177
 #endif
178
-#	define __always_inline   inline __attribute__((__always_inline__))
178
+# define __always_inline   inline __attribute__((__always_inline__))
179
 #elif (defined __ICCARM__)
179
 #elif (defined __ICCARM__)
180
-#	define __always_inline   _Pragma("inline=forced")
180
+# define __always_inline   _Pragma("inline=forced")
181
 #endif
181
 #endif
182
 
182
 
183
 /**
183
 /**
188
  * heuristics and not inline the function.
188
  * heuristics and not inline the function.
189
  */
189
  */
190
 #ifdef __CC_ARM
190
 #ifdef __CC_ARM
191
-#   define __no_inline   __attribute__((noinline))
191
+# define __no_inline   __attribute__((noinline))
192
 #elif (defined __GNUC__)
192
 #elif (defined __GNUC__)
193
-#	define __no_inline   __attribute__((__noinline__))
193
+# define __no_inline   __attribute__((__noinline__))
194
 #elif (defined __ICCARM__)
194
 #elif (defined __ICCARM__)
195
-#	define __no_inline   _Pragma("inline=never")
195
+# define __no_inline   _Pragma("inline=never")
196
 #endif
196
 #endif
197
 
197
 
198
 /*! \brief This macro is used to test fatal errors.
198
 /*! \brief This macro is used to test fatal errors.
211
 #  else
211
 #  else
212
 #undef TEST_SUITE_DEFINE_ASSERT_MACRO
212
 #undef TEST_SUITE_DEFINE_ASSERT_MACRO
213
 #    define Assert(expr) \
213
 #    define Assert(expr) \
214
-	{\
215
-		if (!(expr)) while (true);\
216
-	}
214
+  {\
215
+    if (!(expr)) while (true);\
216
+  }
217
 #  endif
217
 #  endif
218
 #else
218
 #else
219
 #  define Assert(expr) ((void) 0)
219
 #  define Assert(expr) ((void) 0)
1106
 /* Converts a 8 Byte array into a 32-Bit value */
1106
 /* Converts a 8 Byte array into a 32-Bit value */
1107
 static inline uint32_t convert_byte_array_to_32_bit(uint8_t *data)
1107
 static inline uint32_t convert_byte_array_to_32_bit(uint8_t *data)
1108
 {
1108
 {
1109
-	union
1110
-	{
1111
-		uint32_t u32;
1112
-		uint8_t u8[8];
1113
-	}long_addr;
1114
-	uint8_t index;
1115
-	for (index = 0; index < 4; index++)
1116
-	{
1117
-		long_addr.u8[index] = *data++;
1118
-	}
1119
-	return long_addr.u32;
1109
+  union
1110
+  {
1111
+    uint32_t u32;
1112
+    uint8_t u8[8];
1113
+  }long_addr;
1114
+  uint8_t index;
1115
+  for (index = 0; index < 4; index++) {
1116
+    long_addr.u8[index] = *data++;
1117
+  }
1118
+  return long_addr.u32;
1120
 }
1119
 }
1121
 
1120
 
1122
 /**
1121
 /**

+ 1
- 3
Marlin/src/HAL/ESP32/HAL.h View File

15
  *
15
  *
16
  * You should have received a copy of the GNU General Public License
16
  * You should have received a copy of the GNU General Public License
17
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
+ *
18
  */
19
  */
19
 #pragma once
20
 #pragma once
20
 
21
 
58
   #else
59
   #else
59
     #define MYSERIAL1 webSocketSerial
60
     #define MYSERIAL1 webSocketSerial
60
   #endif
61
   #endif
61
-  #define NUM_SERIAL 2
62
-#else
63
-  #define NUM_SERIAL 1
64
 #endif
62
 #endif
65
 
63
 
66
 #define CRITICAL_SECTION_START() portENTER_CRITICAL(&spinlock)
64
 #define CRITICAL_SECTION_START() portENTER_CRITICAL(&spinlock)

+ 2
- 3
Marlin/src/HAL/ESP32/WebSocketSerial.cpp View File

86
 ring_buffer_pos_t RingBuffer::read(uint8_t *buffer) {
86
 ring_buffer_pos_t RingBuffer::read(uint8_t *buffer) {
87
    ring_buffer_pos_t len = available();
87
    ring_buffer_pos_t len = available();
88
 
88
 
89
-  for(ring_buffer_pos_t i = 0; read_index != write_index; i++) {
89
+  for (ring_buffer_pos_t i = 0; read_index != write_index; i++) {
90
     buffer[i] = data[read_index];
90
     buffer[i] = data[read_index];
91
     read_index = NEXT_INDEX(read_index, size);
91
     read_index = NEXT_INDEX(read_index, size);
92
   }
92
   }
139
 
139
 
140
 size_t WebSocketSerial::write(const uint8_t* buffer, size_t size) {
140
 size_t WebSocketSerial::write(const uint8_t* buffer, size_t size) {
141
   size_t written = 0;
141
   size_t written = 0;
142
-  for(size_t i = 0; i < size; i++) {
142
+  for (size_t i = 0; i < size; i++)
143
     written += write(buffer[i]);
143
     written += write(buffer[i]);
144
-  }
145
   return written;
144
   return written;
146
 }
145
 }
147
 
146
 

+ 1
- 0
Marlin/src/HAL/ESP32/ota.h View File

15
  *
15
  *
16
  * You should have received a copy of the GNU General Public License
16
  * You should have received a copy of the GNU General Public License
17
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
+ *
18
  */
19
  */
19
 #pragma once
20
 #pragma once
20
 
21
 

+ 6
- 0
Marlin/src/HAL/HAL.h View File

25
 
25
 
26
 #include HAL_PATH(.,HAL.h)
26
 #include HAL_PATH(.,HAL.h)
27
 
27
 
28
+#ifdef SERIAL_PORT_2
29
+  #define NUM_SERIAL 2
30
+#else
31
+  #define NUM_SERIAL 1
32
+#endif
33
+
28
 #define HAL_ADC_RANGE _BV(HAL_ADC_RESOLUTION)
34
 #define HAL_ADC_RANGE _BV(HAL_ADC_RESOLUTION)
29
 
35
 
30
 #ifndef I2C_ADDRESS
36
 #ifndef I2C_ADDRESS

+ 0
- 1
Marlin/src/HAL/LINUX/HAL.h View File

62
 
62
 
63
 extern HalSerial usb_serial;
63
 extern HalSerial usb_serial;
64
 #define MYSERIAL0 usb_serial
64
 #define MYSERIAL0 usb_serial
65
-#define NUM_SERIAL 1
66
 
65
 
67
 #define ST7920_DELAY_1 DELAY_NS(600)
66
 #define ST7920_DELAY_1 DELAY_NS(600)
68
 #define ST7920_DELAY_2 DELAY_NS(750)
67
 #define ST7920_DELAY_2 DELAY_NS(750)

+ 1
- 1
Marlin/src/HAL/LINUX/include/serial.h View File

33
  * Generic RingBuffer
33
  * Generic RingBuffer
34
  * T type of the buffer array
34
  * T type of the buffer array
35
  * S size of the buffer (must be power of 2)
35
  * S size of the buffer (must be power of 2)
36
- *
37
  */
36
  */
38
 template <typename T, uint32_t S> class RingBuffer {
37
 template <typename T, uint32_t S> class RingBuffer {
39
 public:
38
 public:
79
 
78
 
80
   #if ENABLED(EMERGENCY_PARSER)
79
   #if ENABLED(EMERGENCY_PARSER)
81
     EmergencyParser::State emergency_state;
80
     EmergencyParser::State emergency_state;
81
+    static inline bool emergency_parser_enabled() { return true; }
82
   #endif
82
   #endif
83
 
83
 
84
   HalSerial() { host_connected = true; }
84
   HalSerial() { host_connected = true; }

+ 1
- 1
Marlin/src/HAL/LINUX/main.cpp View File

107
   std::thread write_serial (write_serial_thread);
107
   std::thread write_serial (write_serial_thread);
108
   std::thread read_serial (read_serial_thread);
108
   std::thread read_serial (read_serial_thread);
109
 
109
 
110
-  #if NUM_SERIAL > 0
110
+  #ifdef MYSERIAL0
111
     MYSERIAL0.begin(BAUDRATE);
111
     MYSERIAL0.begin(BAUDRATE);
112
     SERIAL_ECHOLNPGM("x86_64 Initialized");
112
     SERIAL_ECHOLNPGM("x86_64 Initialized");
113
     SERIAL_FLUSHTX();
113
     SERIAL_FLUSHTX();

+ 0
- 1
Marlin/src/HAL/LINUX/servo_private.h View File

45
  *           Version 2 Copyright (c) 2009 Michael Margolis.  All right reserved.
45
  *           Version 2 Copyright (c) 2009 Michael Margolis.  All right reserved.
46
  *
46
  *
47
  * The only modification was to update/delete macros to match the LPC176x.
47
  * The only modification was to update/delete macros to match the LPC176x.
48
- *
49
  */
48
  */
50
 
49
 
51
 #include <stdint.h>
50
 #include <stdint.h>

+ 1
- 1
Marlin/src/HAL/LINUX/spi_pins.h View File

24
 #include "../../core/macros.h"
24
 #include "../../core/macros.h"
25
 #include "../../inc/MarlinConfigPre.h"
25
 #include "../../inc/MarlinConfigPre.h"
26
 
26
 
27
-#if BOTH(HAS_GRAPHICAL_LCD, SDSUPPORT) && (LCD_PINS_D4 == SCK_PIN || LCD_PINS_ENABLE == MOSI_PIN || DOGLCD_SCK == SCK_PIN || DOGLCD_MOSI == MOSI_PIN)
27
+#if BOTH(HAS_MARLINUI_U8GLIB, SDSUPPORT) && (LCD_PINS_D4 == SCK_PIN || LCD_PINS_ENABLE == MOSI_PIN || DOGLCD_SCK == SCK_PIN || DOGLCD_MOSI == MOSI_PIN)
28
   #define LPC_SOFTWARE_SPI  // If the SD card and LCD adapter share the same SPI pins, then software SPI is currently
28
   #define LPC_SOFTWARE_SPI  // If the SD card and LCD adapter share the same SPI pins, then software SPI is currently
29
                             // needed due to the speed and mode required for communicating with each device being different.
29
                             // needed due to the speed and mode required for communicating with each device being different.
30
                             // This requirement can be removed if the SPI access to these devices is updated to use
30
                             // This requirement can be removed if the SPI access to these devices is updated to use

+ 15
- 38
Marlin/src/HAL/LPC1768/HAL.h View File

63
   #define ST7920_DELAY_3 DELAY_NS(750)
63
   #define ST7920_DELAY_3 DELAY_NS(750)
64
 #endif
64
 #endif
65
 
65
 
66
+#define _MSERIAL(X) MSerial##X
67
+#define MSERIAL(X) _MSERIAL(X)
68
+#define MSerial0 MSerial
69
+
66
 #if SERIAL_PORT == -1
70
 #if SERIAL_PORT == -1
67
   #define MYSERIAL0 UsbSerial
71
   #define MYSERIAL0 UsbSerial
68
-#elif SERIAL_PORT == 0
69
-  #define MYSERIAL0 MSerial
70
-#elif SERIAL_PORT == 1
71
-  #define MYSERIAL0 MSerial1
72
-#elif SERIAL_PORT == 2
73
-  #define MYSERIAL0 MSerial2
74
-#elif SERIAL_PORT == 3
75
-  #define MYSERIAL0 MSerial3
72
+#elif WITHIN(SERIAL_PORT, 0, 3)
73
+  #define MYSERIAL0 MSERIAL(SERIAL_PORT)
76
 #else
74
 #else
77
   #error "SERIAL_PORT must be from -1 to 3. Please update your configuration."
75
   #error "SERIAL_PORT must be from -1 to 3. Please update your configuration."
78
 #endif
76
 #endif
79
 
77
 
80
 #ifdef SERIAL_PORT_2
78
 #ifdef SERIAL_PORT_2
81
-  #if SERIAL_PORT_2 == SERIAL_PORT
82
-    #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration."
83
-  #elif SERIAL_PORT_2 == -1
79
+  #if SERIAL_PORT_2 == -1
84
     #define MYSERIAL1 UsbSerial
80
     #define MYSERIAL1 UsbSerial
85
-  #elif SERIAL_PORT_2 == 0
86
-    #define MYSERIAL1 MSerial
87
-  #elif SERIAL_PORT_2 == 1
88
-    #define MYSERIAL1 MSerial1
89
-  #elif SERIAL_PORT_2 == 2
90
-    #define MYSERIAL1 MSerial2
91
-  #elif SERIAL_PORT_2 == 3
92
-    #define MYSERIAL1 MSerial3
81
+  #elif WITHIN(SERIAL_PORT_2, 0, 3)
82
+    #define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
93
   #else
83
   #else
94
     #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
84
     #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
95
   #endif
85
   #endif
96
-  #define NUM_SERIAL 2
97
-#else
98
-  #define NUM_SERIAL 1
99
 #endif
86
 #endif
100
 
87
 
101
-#ifdef DGUS_SERIAL_PORT
102
-  #if DGUS_SERIAL_PORT == SERIAL_PORT
103
-    #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration."
104
-  #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2
105
-    #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration."
106
-  #elif DGUS_SERIAL_PORT == -1
107
-    #define DGUS_SERIAL UsbSerial
108
-  #elif DGUS_SERIAL_PORT == 0
109
-    #define DGUS_SERIAL MSerial
110
-  #elif DGUS_SERIAL_PORT == 1
111
-    #define DGUS_SERIAL MSerial1
112
-  #elif DGUS_SERIAL_PORT == 2
113
-    #define DGUS_SERIAL MSerial2
114
-  #elif DGUS_SERIAL_PORT == 3
115
-    #define DGUS_SERIAL MSerial3
88
+#ifdef LCD_SERIAL_PORT
89
+  #if LCD_SERIAL_PORT == -1
90
+    #define LCD_SERIAL UsbSerial
91
+  #elif WITHIN(LCD_SERIAL_PORT, 0, 3)
92
+    #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
116
   #else
93
   #else
117
-    #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration."
94
+    #error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
118
   #endif
95
   #endif
119
 #endif
96
 #endif
120
 
97
 

+ 85
- 124
Marlin/src/HAL/LPC1768/HAL_SPI.cpp View File

39
  * Some of the LCD interfaces/adapters result in the LCD SPI and the SD card
39
  * Some of the LCD interfaces/adapters result in the LCD SPI and the SD card
40
  * SPI sharing pins. The SCK, MOSI & MISO pins can NOT be set/cleared with
40
  * SPI sharing pins. The SCK, MOSI & MISO pins can NOT be set/cleared with
41
  * WRITE nor digitalWrite when the hardware SPI module within the LPC17xx is
41
  * WRITE nor digitalWrite when the hardware SPI module within the LPC17xx is
42
- * active.  If any of these pins are shared then the software SPI must be used.
42
+ * active. If any of these pins are shared then the software SPI must be used.
43
  *
43
  *
44
- * A more sophisticated hardware SPI can be found at the following link.  This
45
- * implementation has not been fully debugged.
44
+ * A more sophisticated hardware SPI can be found at the following link.
45
+ * This implementation has not been fully debugged.
46
  * https://github.com/MarlinFirmware/Marlin/tree/071c7a78f27078fd4aee9a3ef365fcf5e143531e
46
  * https://github.com/MarlinFirmware/Marlin/tree/071c7a78f27078fd4aee9a3ef365fcf5e143531e
47
  */
47
  */
48
 
48
 
100
 
100
 
101
 #else
101
 #else
102
 
102
 
103
-  // decide which HW SPI device to use
104
-  #ifndef LPC_HW_SPI_DEV
105
-    #if (SCK_PIN == P0_07 && MISO_PIN == P0_08 && MOSI_PIN == P0_09)
106
-      #define LPC_HW_SPI_DEV 1
107
-    #else
108
-      #if (SCK_PIN == P0_15 && MISO_PIN == P0_17 && MOSI_PIN == P0_18)
109
-        #define LPC_HW_SPI_DEV 0
110
-      #else
111
-        #error "Invalid pins selected for hardware SPI"
112
-      #endif
113
-    #endif
114
-  #endif
115
-  #if LPC_HW_SPI_DEV == 0
116
-    #define LPC_SSPn LPC_SSP0
117
-  #else
118
-    #define LPC_SSPn LPC_SSP1
119
-  #endif
120
-
121
   void spiBegin() {  // setup SCK, MOSI & MISO pins for SSP0
103
   void spiBegin() {  // setup SCK, MOSI & MISO pins for SSP0
122
-    PINSEL_CFG_Type PinCfg;  // data structure to hold init values
123
-    PinCfg.Funcnum = 2;
124
-    PinCfg.OpenDrain = 0;
125
-    PinCfg.Pinmode = 0;
126
-    PinCfg.Pinnum = LPC176x::pin_bit(SCK_PIN);
127
-    PinCfg.Portnum = LPC176x::pin_port(SCK_PIN);
128
-    PINSEL_ConfigPin(&PinCfg);
129
-    SET_OUTPUT(SCK_PIN);
130
-
131
-    PinCfg.Pinnum = LPC176x::pin_bit(MISO_PIN);
132
-    PinCfg.Portnum = LPC176x::pin_port(MISO_PIN);
133
-    PINSEL_ConfigPin(&PinCfg);
134
-    SET_INPUT(MISO_PIN);
135
-
136
-    PinCfg.Pinnum = LPC176x::pin_bit(MOSI_PIN);
137
-    PinCfg.Portnum = LPC176x::pin_port(MOSI_PIN);
138
-    PINSEL_ConfigPin(&PinCfg);
139
-    SET_OUTPUT(MOSI_PIN);
140
-    // divide PCLK by 2 for SSP0
141
-    CLKPWR_SetPCLKDiv(LPC_HW_SPI_DEV == 0 ? CLKPWR_PCLKSEL_SSP0 : CLKPWR_PCLKSEL_SSP1, CLKPWR_PCLKSEL_CCLK_DIV_2);
142
-    spiInit(0);
143
-    SSP_Cmd(LPC_SSPn, ENABLE);  // start SSP running
104
+    spiInit(SPI_SPEED);
144
   }
105
   }
145
 
106
 
146
   void spiInit(uint8_t spiRate) {
107
   void spiInit(uint8_t spiRate) {
147
-    // table to convert Marlin spiRates (0-5 plus default) into bit rates
148
-    uint32_t Marlin_speed[7]; // CPSR is always 2
149
-    Marlin_speed[0] = 8333333; //(SCR:  2)  desired: 8,000,000  actual: 8,333,333  +4.2%  SPI_FULL_SPEED
150
-    Marlin_speed[1] = 4166667; //(SCR:  5)  desired: 4,000,000  actual: 4,166,667  +4.2%  SPI_HALF_SPEED
151
-    Marlin_speed[2] = 2083333; //(SCR: 11)  desired: 2,000,000  actual: 2,083,333  +4.2%  SPI_QUARTER_SPEED
152
-    Marlin_speed[3] = 1000000; //(SCR: 24)  desired: 1,000,000  actual: 1,000,000         SPI_EIGHTH_SPEED
153
-    Marlin_speed[4] =  500000; //(SCR: 49)  desired:   500,000  actual:   500,000         SPI_SPEED_5
154
-    Marlin_speed[5] =  250000; //(SCR: 99)  desired:   250,000  actual:   250,000         SPI_SPEED_6
155
-    Marlin_speed[6] =  125000; //(SCR:199)  desired:   125,000  actual:   125,000         Default from HAL.h
156
-    // setup for SPI mode
157
-    SSP_CFG_Type HW_SPI_init; // data structure to hold init values
158
-    SSP_ConfigStructInit(&HW_SPI_init);  // set values for SPI mode
159
-    HW_SPI_init.ClockRate = Marlin_speed[_MIN(spiRate, 6)]; // put in the specified bit rate
160
-    HW_SPI_init.Mode |= SSP_CR1_SSP_EN;
161
-    SSP_Init(LPC_SSPn, &HW_SPI_init);  // puts the values into the proper bits in the SSP0 registers
108
+    #if MISO_PIN == BOARD_SPI1_MISO_PIN
109
+      SPI.setModule(1);
110
+    #elif MISO_PIN == BOARD_SPI2_MISO_PIN
111
+      SPI.setModule(2);
112
+    #endif
113
+    SPI.setDataSize(DATA_SIZE_8BIT);
114
+    SPI.setDataMode(SPI_MODE0);
115
+
116
+    SPI.setClock(SPISettings::spiRate2Clock(spiRate));
117
+    SPI.begin();
162
   }
118
   }
163
 
119
 
164
   static uint8_t doio(uint8_t b) {
120
   static uint8_t doio(uint8_t b) {
165
-    /* send and receive a single byte */
166
-    SSP_SendData(LPC_SSPn, b & 0x00FF);
167
-    while (SSP_GetStatus(LPC_SSPn, SSP_STAT_BUSY));  // wait for it to finish
168
-    return SSP_ReceiveData(LPC_SSPn) & 0x00FF;
121
+    return SPI.transfer(b & 0x00FF) & 0x00FF;
169
   }
122
   }
170
 
123
 
171
   void spiSend(uint8_t b) { doio(b); }
124
   void spiSend(uint8_t b) { doio(b); }
217
   while (SSP_GetStatus(spi_d, SSP_STAT_BUSY) == SET) { /* nada */ }     // wait until BSY=0
170
   while (SSP_GetStatus(spi_d, SSP_STAT_BUSY) == SET) { /* nada */ }     // wait until BSY=0
218
 }
171
 }
219
 
172
 
173
+// Retain the pin init state of the SPI, to avoid init more than once,
174
+// even if more instances of SPIClass exist
175
+static bool spiInitialised[BOARD_NR_SPI] = { false };
176
+
220
 SPIClass::SPIClass(uint8_t device) {
177
 SPIClass::SPIClass(uint8_t device) {
221
   // Init things specific to each SPI device
178
   // Init things specific to each SPI device
222
   // clock divider setup is a bit of hack, and needs to be improved at a later date.
179
   // clock divider setup is a bit of hack, and needs to be improved at a later date.
223
 
180
 
224
-  PINSEL_CFG_Type PinCfg;  // data structure to hold init values
225
   #if BOARD_NR_SPI >= 1
181
   #if BOARD_NR_SPI >= 1
226
     _settings[0].spi_d = LPC_SSP0;
182
     _settings[0].spi_d = LPC_SSP0;
227
-    // _settings[0].clockDivider = determine_baud_rate(_settings[0].spi_d, _settings[0].clock);
228
-    PinCfg.Funcnum = 2;
229
-    PinCfg.OpenDrain = 0;
230
-    PinCfg.Pinmode = 0;
231
-    PinCfg.Pinnum = LPC176x::pin_bit(BOARD_SPI1_SCK_PIN);
232
-    PinCfg.Portnum = LPC176x::pin_port(BOARD_SPI1_SCK_PIN);
233
-    PINSEL_ConfigPin(&PinCfg);
234
-    SET_OUTPUT(BOARD_SPI1_SCK_PIN);
235
-
236
-    PinCfg.Pinnum = LPC176x::pin_bit(BOARD_SPI1_MISO_PIN);
237
-    PinCfg.Portnum = LPC176x::pin_port(BOARD_SPI1_MISO_PIN);
238
-    PINSEL_ConfigPin(&PinCfg);
239
-    SET_INPUT(BOARD_SPI1_MISO_PIN);
240
-
241
-    PinCfg.Pinnum = LPC176x::pin_bit(BOARD_SPI1_MOSI_PIN);
242
-    PinCfg.Portnum = LPC176x::pin_port(BOARD_SPI1_MOSI_PIN);
243
-    PINSEL_ConfigPin(&PinCfg);
244
-    SET_OUTPUT(BOARD_SPI1_MOSI_PIN);
183
+    _settings[0].dataMode = SPI_MODE0;
184
+    _settings[0].dataSize = DATA_SIZE_8BIT;
185
+    _settings[0].clock = SPI_CLOCK_MAX;
186
+    //_settings[0].clockDivider = determine_baud_rate(_settings[0].spi_d, _settings[0].clock);
245
   #endif
187
   #endif
246
 
188
 
247
   #if BOARD_NR_SPI >= 2
189
   #if BOARD_NR_SPI >= 2
248
     _settings[1].spi_d = LPC_SSP1;
190
     _settings[1].spi_d = LPC_SSP1;
249
-    // _settings[1].clockDivider = determine_baud_rate(_settings[1].spi_d, _settings[1].clock);
191
+    _settings[1].dataMode = SPI_MODE0;
192
+    _settings[1].dataSize = DATA_SIZE_8BIT;
193
+    _settings[1].clock = SPI_CLOCK_MAX;
194
+    //_settings[1].clockDivider = determine_baud_rate(_settings[1].spi_d, _settings[1].clock);
195
+  #endif
196
+
197
+  setModule(device);
198
+
199
+  // Init the GPDMA controller
200
+  // TODO: call once in the constructor? or each time?
201
+  GPDMA_Init();
202
+}
203
+
204
+void SPIClass::begin() {
205
+  // Init the SPI pins in the first begin call
206
+  if ((_currentSetting->spi_d == LPC_SSP0 && spiInitialised[0] == false) ||
207
+      (_currentSetting->spi_d == LPC_SSP1 && spiInitialised[1] == false)) {
208
+    pin_t sck, miso, mosi;
209
+    if (_currentSetting->spi_d == LPC_SSP0) {
210
+      sck = BOARD_SPI1_SCK_PIN;
211
+      miso = BOARD_SPI1_MISO_PIN;
212
+      mosi = BOARD_SPI1_MOSI_PIN;
213
+      spiInitialised[0] = true;
214
+    }
215
+    else if (_currentSetting->spi_d == LPC_SSP1) {
216
+      sck = BOARD_SPI2_SCK_PIN;
217
+      miso = BOARD_SPI2_MISO_PIN;
218
+      mosi = BOARD_SPI2_MOSI_PIN;
219
+      spiInitialised[1] = true;
220
+    }
221
+    PINSEL_CFG_Type PinCfg;  // data structure to hold init values
250
     PinCfg.Funcnum = 2;
222
     PinCfg.Funcnum = 2;
251
     PinCfg.OpenDrain = 0;
223
     PinCfg.OpenDrain = 0;
252
     PinCfg.Pinmode = 0;
224
     PinCfg.Pinmode = 0;
253
-    PinCfg.Pinnum = LPC176x::pin_bit(BOARD_SPI2_SCK_PIN);
254
-    PinCfg.Portnum = LPC176x::pin_port(BOARD_SPI2_SCK_PIN);
225
+    PinCfg.Pinnum = LPC176x::pin_bit(sck);
226
+    PinCfg.Portnum = LPC176x::pin_port(sck);
255
     PINSEL_ConfigPin(&PinCfg);
227
     PINSEL_ConfigPin(&PinCfg);
256
-    SET_OUTPUT(BOARD_SPI2_SCK_PIN);
228
+    SET_OUTPUT(sck);
257
 
229
 
258
-    PinCfg.Pinnum = LPC176x::pin_bit(BOARD_SPI2_MISO_PIN);
259
-    PinCfg.Portnum = LPC176x::pin_port(BOARD_SPI2_MISO_PIN);
230
+    PinCfg.Pinnum = LPC176x::pin_bit(miso);
231
+    PinCfg.Portnum = LPC176x::pin_port(miso);
260
     PINSEL_ConfigPin(&PinCfg);
232
     PINSEL_ConfigPin(&PinCfg);
261
-    SET_INPUT(BOARD_SPI2_MISO_PIN);
233
+    SET_INPUT(miso);
262
 
234
 
263
-    PinCfg.Pinnum = LPC176x::pin_bit(BOARD_SPI2_MOSI_PIN);
264
-    PinCfg.Portnum = LPC176x::pin_port(BOARD_SPI2_MOSI_PIN);
235
+    PinCfg.Pinnum = LPC176x::pin_bit(mosi);
236
+    PinCfg.Portnum = LPC176x::pin_port(mosi);
265
     PINSEL_ConfigPin(&PinCfg);
237
     PINSEL_ConfigPin(&PinCfg);
266
-    SET_OUTPUT(BOARD_SPI2_MOSI_PIN);
267
-  #endif
268
-
269
-  setModule(device);
270
-
271
-  /* Initialize GPDMA controller */
272
-  //TODO: call once in the constructor? or each time?
273
-  GPDMA_Init();
274
-}
238
+    SET_OUTPUT(mosi);
239
+  }
275
 
240
 
276
-void SPIClass::begin() {
277
   updateSettings();
241
   updateSettings();
278
   SSP_Cmd(_currentSetting->spi_d, ENABLE);  // start SSP running
242
   SSP_Cmd(_currentSetting->spi_d, ENABLE);  // start SSP running
279
 }
243
 }
287
 }
251
 }
288
 
252
 
289
 uint8_t SPIClass::transfer(const uint16_t b) {
253
 uint8_t SPIClass::transfer(const uint16_t b) {
290
-  /* send and receive a single byte */
254
+  // Send and receive a single byte
291
   SSP_ReceiveData(_currentSetting->spi_d); // read any previous data
255
   SSP_ReceiveData(_currentSetting->spi_d); // read any previous data
292
   SSP_SendData(_currentSetting->spi_d, b);
256
   SSP_SendData(_currentSetting->spi_d, b);
293
   waitSpiTxEnd(_currentSetting->spi_d);  // wait for it to finish
257
   waitSpiTxEnd(_currentSetting->spi_d);  // wait for it to finish
295
 }
259
 }
296
 
260
 
297
 uint16_t SPIClass::transfer16(const uint16_t data) {
261
 uint16_t SPIClass::transfer16(const uint16_t data) {
298
-  return (transfer((data >> 8) & 0xFF) << 8)
299
-       | (transfer(data & 0xFF) & 0xFF);
262
+  return (transfer((data >> 8) & 0xFF) << 8) | (transfer(data & 0xFF) & 0xFF);
300
 }
263
 }
301
 
264
 
302
 void SPIClass::end() {
265
 void SPIClass::end() {
320
   // Destination memory - Not used
283
   // Destination memory - Not used
321
   GPDMACfg.DstMemAddr = 0;
284
   GPDMACfg.DstMemAddr = 0;
322
   // Transfer size
285
   // Transfer size
323
-  GPDMACfg.TransferSize = (minc ? length : 1);
286
+  GPDMACfg.TransferSize = length;
324
   // Transfer width
287
   // Transfer width
325
   GPDMACfg.TransferWidth = (_currentSetting->dataSize == DATA_SIZE_16BIT) ? GPDMA_WIDTH_HALFWORD : GPDMA_WIDTH_BYTE;
288
   GPDMACfg.TransferWidth = (_currentSetting->dataSize == DATA_SIZE_16BIT) ? GPDMA_WIDTH_HALFWORD : GPDMA_WIDTH_BYTE;
326
   // Transfer type
289
   // Transfer type
335
   // Enable dma on SPI
298
   // Enable dma on SPI
336
   SSP_DMACmd(_currentSetting->spi_d, SSP_DMA_TX, ENABLE);
299
   SSP_DMACmd(_currentSetting->spi_d, SSP_DMA_TX, ENABLE);
337
 
300
 
338
-  // if minc=false, I'm repeating the same byte 'length' times, as I could not find yet how do GPDMA without memory increment
339
-  do {
340
-    // Setup channel with given parameter
341
-    GPDMA_Setup(&GPDMACfg);
301
+  // Only increase memory if minc is true
302
+  GPDMACfg.MemoryIncrease = (minc ? GPDMA_DMACCxControl_SI : 0);
342
 
303
 
343
-    // enabled dma
344
-    GPDMA_ChannelCmd(0, ENABLE);
304
+  // Setup channel with given parameter
305
+  GPDMA_Setup(&GPDMACfg);
345
 
306
 
346
-    // wait data transfer
347
-    while (!GPDMA_IntGetStatus(GPDMA_STAT_INTTC, 0) && !GPDMA_IntGetStatus(GPDMA_STAT_INTERR, 0)) { }
307
+  // Enable DMA
308
+  GPDMA_ChannelCmd(0, ENABLE);
348
 
309
 
349
-    // clear err and int
350
-    GPDMA_ClearIntPending (GPDMA_STATCLR_INTTC, 0);
351
-    GPDMA_ClearIntPending (GPDMA_STATCLR_INTERR, 0);
310
+  // Wait for data transfer
311
+  while (!GPDMA_IntGetStatus(GPDMA_STAT_RAWINTTC, 0) && !GPDMA_IntGetStatus(GPDMA_STAT_RAWINTERR, 0)) { }
352
 
312
 
353
-    // dma disable
354
-    GPDMA_ChannelCmd(0, DISABLE);
313
+  // Clear err and int
314
+  GPDMA_ClearIntPending (GPDMA_STATCLR_INTTC, 0);
315
+  GPDMA_ClearIntPending (GPDMA_STATCLR_INTERR, 0);
355
 
316
 
356
-    --length;
357
-  } while (!minc && length > 0);
317
+  // Disable DMA
318
+  GPDMA_ChannelCmd(0, DISABLE);
358
 
319
 
359
   waitSpiTxEnd(_currentSetting->spi_d);
320
   waitSpiTxEnd(_currentSetting->spi_d);
360
 
321
 
382
 }
343
 }
383
 
344
 
384
 void SPIClass::setDataMode(uint8_t dataMode) {
345
 void SPIClass::setDataMode(uint8_t dataMode) {
385
-  _currentSetting->dataSize = dataMode;
346
+  _currentSetting->dataMode = dataMode;
386
 }
347
 }
387
 
348
 
388
 void SPIClass::setDataSize(uint32_t ds) {
349
 void SPIClass::setDataSize(uint32_t ds) {
413
   switch (_currentSetting->dataMode) {
374
   switch (_currentSetting->dataMode) {
414
     case SPI_MODE0:
375
     case SPI_MODE0:
415
       HW_SPI_init.CPHA = SSP_CPHA_FIRST;
376
       HW_SPI_init.CPHA = SSP_CPHA_FIRST;
416
-	    HW_SPI_init.CPOL = SSP_CPOL_HI;
377
+      HW_SPI_init.CPOL = SSP_CPOL_HI;
417
       break;
378
       break;
418
     case SPI_MODE1:
379
     case SPI_MODE1:
419
       HW_SPI_init.CPHA = SSP_CPHA_SECOND;
380
       HW_SPI_init.CPHA = SSP_CPHA_SECOND;
420
-	    HW_SPI_init.CPOL = SSP_CPOL_HI;
381
+      HW_SPI_init.CPOL = SSP_CPOL_HI;
421
       break;
382
       break;
422
     case SPI_MODE2:
383
     case SPI_MODE2:
423
       HW_SPI_init.CPHA = SSP_CPHA_FIRST;
384
       HW_SPI_init.CPHA = SSP_CPHA_FIRST;
424
-	    HW_SPI_init.CPOL = SSP_CPOL_LO;
385
+      HW_SPI_init.CPOL = SSP_CPOL_LO;
425
       break;
386
       break;
426
     case SPI_MODE3:
387
     case SPI_MODE3:
427
       HW_SPI_init.CPHA = SSP_CPHA_SECOND;
388
       HW_SPI_init.CPHA = SSP_CPHA_SECOND;
428
-	    HW_SPI_init.CPOL = SSP_CPOL_LO;
389
+      HW_SPI_init.CPOL = SSP_CPOL_LO;
429
       break;
390
       break;
430
     default:
391
     default:
431
       break;
392
       break;

+ 4
- 4
Marlin/src/HAL/LPC1768/MarlinSerial.cpp View File

24
 #include "../../inc/MarlinConfigPre.h"
24
 #include "../../inc/MarlinConfigPre.h"
25
 #include "MarlinSerial.h"
25
 #include "MarlinSerial.h"
26
 
26
 
27
-#if (defined(SERIAL_PORT) && SERIAL_PORT == 0) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == 0) || (defined(DGUS_SERIAL_PORT) && DGUS_SERIAL_PORT == 0)
27
+#if USING_SERIAL_0
28
   MarlinSerial MSerial(LPC_UART0);
28
   MarlinSerial MSerial(LPC_UART0);
29
   extern "C" void UART0_IRQHandler() {
29
   extern "C" void UART0_IRQHandler() {
30
     MSerial.IRQHandler();
30
     MSerial.IRQHandler();
31
   }
31
   }
32
 #endif
32
 #endif
33
 
33
 
34
-#if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1 || DGUS_SERIAL_PORT == 1
34
+#if USING_SERIAL_1
35
   MarlinSerial MSerial1((LPC_UART_TypeDef *) LPC_UART1);
35
   MarlinSerial MSerial1((LPC_UART_TypeDef *) LPC_UART1);
36
   extern "C" void UART1_IRQHandler() {
36
   extern "C" void UART1_IRQHandler() {
37
     MSerial1.IRQHandler();
37
     MSerial1.IRQHandler();
38
   }
38
   }
39
 #endif
39
 #endif
40
 
40
 
41
-#if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 || DGUS_SERIAL_PORT == 2
41
+#if USING_SERIAL_2
42
   MarlinSerial MSerial2(LPC_UART2);
42
   MarlinSerial MSerial2(LPC_UART2);
43
   extern "C" void UART2_IRQHandler() {
43
   extern "C" void UART2_IRQHandler() {
44
     MSerial2.IRQHandler();
44
     MSerial2.IRQHandler();
45
   }
45
   }
46
 #endif
46
 #endif
47
 
47
 
48
-#if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 || DGUS_SERIAL_PORT == 3
48
+#if USING_SERIAL_3
49
   MarlinSerial MSerial3(LPC_UART3);
49
   MarlinSerial MSerial3(LPC_UART3);
50
   extern "C" void UART3_IRQHandler() {
50
   extern "C" void UART3_IRQHandler() {
51
     MSerial3.IRQHandler();
51
     MSerial3.IRQHandler();

+ 1
- 0
Marlin/src/HAL/LPC1768/MarlinSerial.h View File

57
     }
57
     }
58
 
58
 
59
     EmergencyParser::State emergency_state;
59
     EmergencyParser::State emergency_state;
60
+    static inline bool emergency_parser_enabled() { return true; }
60
   #endif
61
   #endif
61
 };
62
 };
62
 
63
 

+ 0
- 1
Marlin/src/HAL/LPC1768/Servo.h View File

46
  *           Version 2 Copyright (c) 2009 Michael Margolis.  All right reserved.
46
  *           Version 2 Copyright (c) 2009 Michael Margolis.  All right reserved.
47
  *
47
  *
48
  * The only modification was to update/delete macros to match the LPC176x.
48
  * The only modification was to update/delete macros to match the LPC176x.
49
- *
50
  */
49
  */
51
 
50
 
52
 #include <Servo.h>
51
 #include <Servo.h>

+ 36
- 23
Marlin/src/HAL/LPC1768/inc/SanityCheck.h View File

24
 #if PIO_PLATFORM_VERSION < 1001
24
 #if PIO_PLATFORM_VERSION < 1001
25
   #error "nxplpc-arduino-lpc176x package is out of date, Please update the PlatformIO platforms, frameworks and libraries. You may need to remove the platform and let it reinstall automatically."
25
   #error "nxplpc-arduino-lpc176x package is out of date, Please update the PlatformIO platforms, frameworks and libraries. You may need to remove the platform and let it reinstall automatically."
26
 #endif
26
 #endif
27
-#if PIO_FRAMEWORK_VERSION < 2002
27
+#if PIO_FRAMEWORK_VERSION < 2005
28
   #error "framework-arduino-lpc176x package is out of date, Please update the PlatformIO platforms, frameworks and libraries."
28
   #error "framework-arduino-lpc176x package is out of date, Please update the PlatformIO platforms, frameworks and libraries."
29
 #endif
29
 #endif
30
 
30
 
89
  * Serial2 | P0_10 | P0_11 |
89
  * Serial2 | P0_10 | P0_11 |
90
  * Serial3 | P0_00 | P0_01 |
90
  * Serial3 | P0_00 | P0_01 |
91
  */
91
  */
92
-#if (defined(SERIAL_PORT) && SERIAL_PORT == 0) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == 0) || (defined(DGUS_SERIAL_PORT) && DGUS_SERIAL_PORT == 0)
92
+#define ANY_TX(N,V...) DO(IS_TX##N,||,V)
93
+#define ANY_RX(N,V...) DO(IS_RX##N,||,V)
94
+
95
+#if USING_SERIAL_0
93
   #define IS_TX0(P) (P == P0_02)
96
   #define IS_TX0(P) (P == P0_02)
94
   #define IS_RX0(P) (P == P0_03)
97
   #define IS_RX0(P) (P == P0_03)
95
   #if IS_TX0(TMC_SW_MISO) || IS_RX0(TMC_SW_MOSI)
98
   #if IS_TX0(TMC_SW_MISO) || IS_RX0(TMC_SW_MOSI)
103
   #undef IS_RX0
106
   #undef IS_RX0
104
 #endif
107
 #endif
105
 
108
 
106
-#if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1 || DGUS_SERIAL_PORT == 1
109
+#if USING_SERIAL_1
107
   #define IS_TX1(P) (P == P0_15)
110
   #define IS_TX1(P) (P == P0_15)
108
   #define IS_RX1(P) (P == P0_16)
111
   #define IS_RX1(P) (P == P0_16)
112
+  #define _IS_TX1_1 IS_TX1
113
+  #define _IS_RX1_1 IS_RX1
109
   #if IS_TX1(TMC_SW_SCK)
114
   #if IS_TX1(TMC_SW_SCK)
110
     #error "Serial port pins (1) conflict with other pins!"
115
     #error "Serial port pins (1) conflict with other pins!"
111
-  #elif HAS_SPI_LCD
116
+  #elif HAS_WIRED_LCD
112
     #if IS_TX1(BTN_EN2) || IS_RX1(BTN_EN1)
117
     #if IS_TX1(BTN_EN2) || IS_RX1(BTN_EN1)
113
       #error "Serial port pins (1) conflict with Encoder Buttons!"
118
       #error "Serial port pins (1) conflict with Encoder Buttons!"
114
-    #elif IS_TX1(SCK_PIN) || IS_TX1(LCD_PINS_D4) || IS_TX1(DOGLCD_SCK) || IS_TX1(LCD_RESET_PIN) || IS_TX1(LCD_PINS_RS) || IS_TX1(SHIFT_CLK) \
115
-      || IS_RX1(LCD_SDSS) || IS_RX1(LCD_PINS_RS) || IS_RX1(MISO_PIN) || IS_RX1(DOGLCD_A0) || IS_RX1(SS_PIN) || IS_RX1(LCD_SDSS) || IS_RX1(DOGLCD_CS) || IS_RX1(LCD_RESET_PIN) || IS_RX1(LCD_BACKLIGHT_PIN)
119
+    #elif ANY_TX(1, SCK_PIN, LCD_PINS_D4, DOGLCD_SCK, LCD_RESET_PIN, LCD_PINS_RS, SHIFT_CLK) \
120
+       || ANY_RX(1, LCD_SDSS, LCD_PINS_RS, MISO_PIN, DOGLCD_A0, SS_PIN, LCD_SDSS, DOGLCD_CS, LCD_RESET_PIN, LCD_BACKLIGHT_PIN)
116
       #error "Serial port pins (1) conflict with LCD pins!"
121
       #error "Serial port pins (1) conflict with LCD pins!"
117
     #endif
122
     #endif
118
   #endif
123
   #endif
119
   #undef IS_TX1
124
   #undef IS_TX1
120
   #undef IS_RX1
125
   #undef IS_RX1
126
+  #undef _IS_TX1_1
127
+  #undef _IS_RX1_1
121
 #endif
128
 #endif
122
 
129
 
123
-#if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 || DGUS_SERIAL_PORT == 2
130
+#if USING_SERIAL_2
124
   #define IS_TX2(P) (P == P0_10)
131
   #define IS_TX2(P) (P == P0_10)
125
   #define IS_RX2(P) (P == P0_11)
132
   #define IS_RX2(P) (P == P0_11)
126
-  #if  IS_TX2(X2_ENABLE_PIN) || IS_RX2(X2_DIR_PIN) || IS_RX2(X2_STEP_PIN) || (AXIS_HAS_SPI(X2) && IS_TX2(X2_CS_PIN))
133
+  #define _IS_TX2_1 IS_TX2
134
+  #define _IS_RX2_1 IS_RX2
135
+  #if IS_TX2(X2_ENABLE_PIN) || ANY_RX(2, X2_DIR_PIN, X2_STEP_PIN) || (AXIS_HAS_SPI(X2) && IS_TX2(X2_CS_PIN))
127
     #error "Serial port pins (2) conflict with X2 pins!"
136
     #error "Serial port pins (2) conflict with X2 pins!"
128
-  #elif IS_TX2(Y2_ENABLE_PIN) || IS_RX2(Y2_DIR_PIN) || IS_RX2(Y2_STEP_PIN) || (AXIS_HAS_SPI(Y2) && IS_TX2(Y2_CS_PIN))
137
+  #elif IS_TX2(Y2_ENABLE_PIN) || ANY_RX(2, Y2_DIR_PIN, Y2_STEP_PIN) || (AXIS_HAS_SPI(Y2) && IS_TX2(Y2_CS_PIN))
129
     #error "Serial port pins (2) conflict with Y2 pins!"
138
     #error "Serial port pins (2) conflict with Y2 pins!"
130
-  #elif IS_TX2(Z2_ENABLE_PIN) || IS_RX2(Z2_DIR_PIN) || IS_RX2(Z2_STEP_PIN) || (AXIS_HAS_SPI(Z2) && IS_TX2(Z2_CS_PIN))
139
+  #elif IS_TX2(Z2_ENABLE_PIN) || ANY_RX(2, Z2_DIR_PIN, Z2_STEP_PIN) || (AXIS_HAS_SPI(Z2) && IS_TX2(Z2_CS_PIN))
131
     #error "Serial port pins (2) conflict with Z2 pins!"
140
     #error "Serial port pins (2) conflict with Z2 pins!"
132
-  #elif IS_TX2(Z3_ENABLE_PIN) || IS_RX2(Z3_DIR_PIN) || IS_RX2(Z3_STEP_PIN) || (AXIS_HAS_SPI(Z3) && IS_TX2(Z3_CS_PIN))
141
+  #elif IS_TX2(Z3_ENABLE_PIN) || ANY_RX(2, Z3_DIR_PIN, Z3_STEP_PIN) || (AXIS_HAS_SPI(Z3) && IS_TX2(Z3_CS_PIN))
133
     #error "Serial port pins (2) conflict with Z3 pins!"
142
     #error "Serial port pins (2) conflict with Z3 pins!"
134
-  #elif IS_TX2(Z4_ENABLE_PIN) || IS_RX2(Z4_DIR_PIN) || IS_RX2(Z4_STEP_PIN) || (AXIS_HAS_SPI(Z4) && IS_TX2(Z4_CS_PIN))
143
+  #elif IS_TX2(Z4_ENABLE_PIN) || ANY_RX(2, Z4_DIR_PIN, Z4_STEP_PIN) || (AXIS_HAS_SPI(Z4) && IS_TX2(Z4_CS_PIN))
135
     #error "Serial port pins (2) conflict with Z4 pins!"
144
     #error "Serial port pins (2) conflict with Z4 pins!"
136
-  #elif IS_RX2(X_DIR_PIN) || IS_RX2(Y_DIR_PIN)
145
+  #elif ANY_RX(2, X_DIR_PIN, Y_DIR_PIN)
137
     #error "Serial port pins (2) conflict with other pins!"
146
     #error "Serial port pins (2) conflict with other pins!"
138
   #elif Y_HOME_DIR < 0 && IS_TX2(Y_STOP_PIN)
147
   #elif Y_HOME_DIR < 0 && IS_TX2(Y_STOP_PIN)
139
     #error "Serial port pins (2) conflict with Y endstop pin!"
148
     #error "Serial port pins (2) conflict with Y endstop pin!"
140
   #elif HAS_CUSTOM_PROBE_PIN && IS_TX2(Z_MIN_PROBE_PIN)
149
   #elif HAS_CUSTOM_PROBE_PIN && IS_TX2(Z_MIN_PROBE_PIN)
141
     #error "Serial port pins (2) conflict with probe pin!"
150
     #error "Serial port pins (2) conflict with probe pin!"
142
-  #elif IS_TX2(X_ENABLE_PIN) || IS_RX2(X_DIR_PIN) || IS_TX2(Y_ENABLE_PIN) || IS_RX2(Y_DIR_PIN)
151
+  #elif ANY_TX(2, X_ENABLE_PIN, Y_ENABLE_PIN) || ANY_RX(2, X_DIR_PIN, Y_DIR_PIN)
143
     #error "Serial port pins (2) conflict with X/Y stepper pins!"
152
     #error "Serial port pins (2) conflict with X/Y stepper pins!"
144
-  #elif EXTRUDERS > 1 && (IS_TX2(E1_ENABLE_PIN) || (AXIS_HAS_SPI(E1) && IS_TX2(E1_CS_PIN)))
153
+  #elif HAS_MULTI_EXTRUDER && (IS_TX2(E1_ENABLE_PIN) || (AXIS_HAS_SPI(E1) && IS_TX2(E1_CS_PIN)))
145
     #error "Serial port pins (2) conflict with E1 stepper pins!"
154
     #error "Serial port pins (2) conflict with E1 stepper pins!"
146
-  #elif EXTRUDERS && (IS_RX2(E0_DIR_PIN) || IS_RX2(E0_STEP_PIN))
155
+  #elif EXTRUDERS && ANY_RX(2, E0_DIR_PIN, E0_STEP_PIN)
147
     #error "Serial port pins (2) conflict with E stepper pins!"
156
     #error "Serial port pins (2) conflict with E stepper pins!"
148
   #endif
157
   #endif
149
   #undef IS_TX2
158
   #undef IS_TX2
150
   #undef IS_RX2
159
   #undef IS_RX2
160
+  #undef _IS_TX2_1
161
+  #undef _IS_RX2_1
151
 #endif
162
 #endif
152
 
163
 
153
-#if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 || DGUS_SERIAL_PORT == 3
164
+#if USING_SERIAL_3
154
   #define PIN_IS_TX3(P) (PIN_EXISTS(P) && P##_PIN == P0_00)
165
   #define PIN_IS_TX3(P) (PIN_EXISTS(P) && P##_PIN == P0_00)
155
   #define PIN_IS_RX3(P) (P##_PIN == P0_01)
166
   #define PIN_IS_RX3(P) (P##_PIN == P0_01)
156
   #if PIN_IS_TX3(X_MIN) || PIN_IS_RX3(X_MAX)
167
   #if PIN_IS_TX3(X_MIN) || PIN_IS_RX3(X_MAX)
157
     #error "Serial port pins (3) conflict with X endstop pins!"
168
     #error "Serial port pins (3) conflict with X endstop pins!"
158
-  #elif PIN_IS_TX3(Y_SERIAL_TX) || PIN_IS_TX3(Y_SERIAL_RX) \
159
-    ||  PIN_IS_RX3(X_SERIAL_TX) || PIN_IS_RX3(X_SERIAL_RX)
169
+  #elif PIN_IS_TX3(Y_SERIAL_TX) || PIN_IS_TX3(Y_SERIAL_RX) || PIN_IS_RX3(X_SERIAL_TX) || PIN_IS_RX3(X_SERIAL_RX)
160
     #error "Serial port pins (3) conflict with X/Y axis UART pins!"
170
     #error "Serial port pins (3) conflict with X/Y axis UART pins!"
161
   #elif PIN_IS_TX3(X2_DIR) || PIN_IS_RX3(X2_STEP)
171
   #elif PIN_IS_TX3(X2_DIR) || PIN_IS_RX3(X2_STEP)
162
     #error "Serial port pins (3) conflict with X2 pins!"
172
     #error "Serial port pins (3) conflict with X2 pins!"
168
     #error "Serial port pins (3) conflict with Z3 pins!"
178
     #error "Serial port pins (3) conflict with Z3 pins!"
169
   #elif PIN_IS_TX3(Z4_DIR) || PIN_IS_RX3(Z4_STEP)
179
   #elif PIN_IS_TX3(Z4_DIR) || PIN_IS_RX3(Z4_STEP)
170
     #error "Serial port pins (3) conflict with Z4 pins!"
180
     #error "Serial port pins (3) conflict with Z4 pins!"
171
-  #elif EXTRUDERS > 1 && (PIN_IS_TX3(E1_DIR) || PIN_IS_RX3(E1_STEP))
181
+  #elif HAS_MULTI_EXTRUDER && (PIN_IS_TX3(E1_DIR) || PIN_IS_RX3(E1_STEP))
172
     #error "Serial port pins (3) conflict with E1 pins!"
182
     #error "Serial port pins (3) conflict with E1 pins!"
173
   #endif
183
   #endif
174
   #undef PIN_IS_TX3
184
   #undef PIN_IS_TX3
175
   #undef PIN_IS_RX3
185
   #undef PIN_IS_RX3
176
 #endif
186
 #endif
177
 
187
 
188
+#undef ANY_TX
189
+#undef ANY_RX
190
+
178
 //
191
 //
179
 // Flag any i2c pin conflicts
192
 // Flag any i2c pin conflicts
180
 //
193
 //
214
       #error "One or more i2c (1) pins overlaps with Z3 pins! Disable i2c peripherals."
227
       #error "One or more i2c (1) pins overlaps with Z3 pins! Disable i2c peripherals."
215
     #elif PIN_IS_SDA1(Z4_DIR) || PIN_IS_SCL1(Z4_STEP)
228
     #elif PIN_IS_SDA1(Z4_DIR) || PIN_IS_SCL1(Z4_STEP)
216
       #error "One or more i2c (1) pins overlaps with Z4 pins! Disable i2c peripherals."
229
       #error "One or more i2c (1) pins overlaps with Z4 pins! Disable i2c peripherals."
217
-    #elif EXTRUDERS > 1 && (PIN_IS_SDA1(E1_DIR) || PIN_IS_SCL1(E1_STEP))
230
+    #elif HAS_MULTI_EXTRUDER && (PIN_IS_SDA1(E1_DIR) || PIN_IS_SCL1(E1_STEP))
218
       #error "One or more i2c (1) pins overlaps with E1 pins! Disable i2c peripherals."
231
       #error "One or more i2c (1) pins overlaps with E1 pins! Disable i2c peripherals."
219
     #endif
232
     #endif
220
     #undef PIN_IS_SDA1
233
     #undef PIN_IS_SDA1
240
       #error "i2c SDA2 overlaps with Z3 enable pin! Disable i2c peripherals."
253
       #error "i2c SDA2 overlaps with Z3 enable pin! Disable i2c peripherals."
241
     #elif PIN_IS_SDA2(Z4_ENABLE)
254
     #elif PIN_IS_SDA2(Z4_ENABLE)
242
       #error "i2c SDA2 overlaps with Z4 enable pin! Disable i2c peripherals."
255
       #error "i2c SDA2 overlaps with Z4 enable pin! Disable i2c peripherals."
243
-    #elif EXTRUDERS > 1 && PIN_IS_SDA2(E1_ENABLE)
256
+    #elif HAS_MULTI_EXTRUDER && PIN_IS_SDA2(E1_ENABLE)
244
       #error "i2c SDA2 overlaps with E1 enable pin! Disable i2c peripherals."
257
       #error "i2c SDA2 overlaps with E1 enable pin! Disable i2c peripherals."
245
-    #elif EXTRUDERS > 1 && AXIS_HAS_SPI(E1) && PIN_IS_SDA2(E1_CS)
258
+    #elif HAS_MULTI_EXTRUDER && AXIS_HAS_SPI(E1) && PIN_IS_SDA2(E1_CS)
246
       #error "i2c SDA2 overlaps with E1 CS pin! Disable i2c peripherals."
259
       #error "i2c SDA2 overlaps with E1 CS pin! Disable i2c peripherals."
247
     #elif EXTRUDERS && (PIN_IS_SDA2(E0_STEP) || PIN_IS_SDA2(E0_DIR))
260
     #elif EXTRUDERS && (PIN_IS_SDA2(E0_STEP) || PIN_IS_SDA2(E0_DIR))
248
       #error "i2c SCL2 overlaps with E0 STEP/DIR pin! Disable i2c peripherals."
261
       #error "i2c SCL2 overlaps with E0 STEP/DIR pin! Disable i2c peripherals."

+ 18
- 4
Marlin/src/HAL/LPC1768/include/SPI.h View File

61
 
61
 
62
 class SPISettings {
62
 class SPISettings {
63
 public:
63
 public:
64
-  SPISettings(uint32_t speed, int, int) : spi_speed(speed) {};
64
+  SPISettings(uint32_t spiRate, int inBitOrder, int inDataMode) {
65
+    init_AlwaysInline(spiRate2Clock(spiRate), inBitOrder, inDataMode, DATA_SIZE_8BIT);
66
+  }
65
   SPISettings(uint32_t inClock, uint8_t inBitOrder, uint8_t inDataMode, uint32_t inDataSize) {
67
   SPISettings(uint32_t inClock, uint8_t inBitOrder, uint8_t inDataMode, uint32_t inDataSize) {
66
     if (__builtin_constant_p(inClock))
68
     if (__builtin_constant_p(inClock))
67
       init_AlwaysInline(inClock, inBitOrder, inDataMode, inDataSize);
69
       init_AlwaysInline(inClock, inBitOrder, inDataMode, inDataSize);
72
     init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
74
     init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
73
   }
75
   }
74
 
76
 
75
-  uint32_t spiRate() const { return spi_speed; }
77
+  //uint32_t spiRate() const { return spi_speed; }
78
+
79
+  static inline uint32_t spiRate2Clock(uint32_t spiRate) {
80
+    uint32_t Marlin_speed[7]; // CPSR is always 2
81
+    Marlin_speed[0] = 8333333; //(SCR:  2)  desired: 8,000,000  actual: 8,333,333  +4.2%  SPI_FULL_SPEED
82
+    Marlin_speed[1] = 4166667; //(SCR:  5)  desired: 4,000,000  actual: 4,166,667  +4.2%  SPI_HALF_SPEED
83
+    Marlin_speed[2] = 2083333; //(SCR: 11)  desired: 2,000,000  actual: 2,083,333  +4.2%  SPI_QUARTER_SPEED
84
+    Marlin_speed[3] = 1000000; //(SCR: 24)  desired: 1,000,000  actual: 1,000,000         SPI_EIGHTH_SPEED
85
+    Marlin_speed[4] =  500000; //(SCR: 49)  desired:   500,000  actual:   500,000         SPI_SPEED_5
86
+    Marlin_speed[5] =  250000; //(SCR: 99)  desired:   250,000  actual:   250,000         SPI_SPEED_6
87
+    Marlin_speed[6] =  125000; //(SCR:199)  desired:   125,000  actual:   125,000         Default from HAL.h
88
+    return Marlin_speed[spiRate > 6 ? 6 : spiRate];
89
+  }
76
 
90
 
77
 private:
91
 private:
78
   void init_MightInline(uint32_t inClock, uint8_t inBitOrder, uint8_t inDataMode, uint32_t inDataSize) {
92
   void init_MightInline(uint32_t inClock, uint8_t inBitOrder, uint8_t inDataMode, uint32_t inDataSize) {
85
     dataSize = inDataSize;
99
     dataSize = inDataSize;
86
   }
100
   }
87
 
101
 
88
-  uint32_t spi_speed;
102
+  //uint32_t spi_speed;
89
   uint32_t clock;
103
   uint32_t clock;
90
   uint32_t dataSize;
104
   uint32_t dataSize;
91
   //uint32_t clockDivider;
105
   //uint32_t clockDivider;
122
   void end();
136
   void end();
123
 
137
 
124
   void beginTransaction(const SPISettings&);
138
   void beginTransaction(const SPISettings&);
125
-  void endTransaction() {};
139
+  void endTransaction() {}
126
 
140
 
127
   // Transfer using 1 "Data Size"
141
   // Transfer using 1 "Data Size"
128
   uint8_t transfer(uint16_t data);
142
   uint8_t transfer(uint16_t data);

+ 1
- 1
Marlin/src/HAL/LPC1768/spi_pins.h View File

23
 
23
 
24
 #include "../../core/macros.h"
24
 #include "../../core/macros.h"
25
 
25
 
26
-#if BOTH(SDSUPPORT, HAS_GRAPHICAL_LCD) && (LCD_PINS_D4 == SCK_PIN || LCD_PINS_ENABLE == MOSI_PIN || DOGLCD_SCK == SCK_PIN || DOGLCD_MOSI == MOSI_PIN)
26
+#if BOTH(SDSUPPORT, HAS_MARLINUI_U8GLIB) && (LCD_PINS_D4 == SCK_PIN || LCD_PINS_ENABLE == MOSI_PIN || DOGLCD_SCK == SCK_PIN || DOGLCD_MOSI == MOSI_PIN)
27
   #define LPC_SOFTWARE_SPI  // If the SD card and LCD adapter share the same SPI pins, then software SPI is currently
27
   #define LPC_SOFTWARE_SPI  // If the SD card and LCD adapter share the same SPI pins, then software SPI is currently
28
                             // needed due to the speed and mode required for communicating with each device being different.
28
                             // needed due to the speed and mode required for communicating with each device being different.
29
                             // This requirement can be removed if the SPI access to these devices is updated to use
29
                             // This requirement can be removed if the SPI access to these devices is updated to use

+ 0
- 1
Marlin/src/HAL/LPC1768/tft/xpt2046.cpp View File

72
   if (!isTouched()) return false;
72
   if (!isTouched()) return false;
73
   *x = getRawData(XPT2046_X);
73
   *x = getRawData(XPT2046_X);
74
   *y = getRawData(XPT2046_Y);
74
   *y = getRawData(XPT2046_Y);
75
-  SERIAL_ECHOLNPAIR("X: ", *x, ", Y: ", *y);
76
   return isTouched();
75
   return isTouched();
77
 }
76
 }
78
 
77
 

+ 0
- 1
Marlin/src/HAL/LPC1768/timers.h View File

21
 #pragma once
21
 #pragma once
22
 
22
 
23
 /**
23
 /**
24
- *
25
  * HAL For LPC1768
24
  * HAL For LPC1768
26
  */
25
  */
27
 
26
 

+ 2
- 2
Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_hw_spi.cpp View File

57
 
57
 
58
 #include "../../../inc/MarlinConfigPre.h"
58
 #include "../../../inc/MarlinConfigPre.h"
59
 
59
 
60
-#if HAS_GRAPHICAL_LCD
60
+#if HAS_MARLINUI_U8GLIB
61
 
61
 
62
 #include <U8glib.h>
62
 #include <U8glib.h>
63
 #include "../../shared/HAL_SPI.h"
63
 #include "../../shared/HAL_SPI.h"
124
   return 1;
124
   return 1;
125
 }
125
 }
126
 
126
 
127
-#endif // HAS_GRAPHICAL_LCD
127
+#endif // HAS_MARLINUI_U8GLIB
128
 
128
 
129
 #endif // TARGET_LPC1768
129
 #endif // TARGET_LPC1768

+ 2
- 2
Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_ssd_hw_i2c.cpp View File

77
 
77
 
78
 #include "../../../inc/MarlinConfigPre.h"
78
 #include "../../../inc/MarlinConfigPre.h"
79
 
79
 
80
-#if HAS_GRAPHICAL_LCD
80
+#if HAS_MARLINUI_U8GLIB
81
 
81
 
82
 #include <U8glib.h>
82
 #include <U8glib.h>
83
 
83
 
193
   return 1;
193
   return 1;
194
 }
194
 }
195
 
195
 
196
-#endif // HAS_GRAPHICAL_LCD
196
+#endif // HAS_MARLINUI_U8GLIB
197
 
197
 
198
 #endif // TARGET_LPC1768
198
 #endif // TARGET_LPC1768

+ 2
- 2
Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_hw_spi.cpp View File

57
 
57
 
58
 #include "../../../inc/MarlinConfigPre.h"
58
 #include "../../../inc/MarlinConfigPre.h"
59
 
59
 
60
-#if HAS_GRAPHICAL_LCD
60
+#if HAS_MARLINUI_U8GLIB
61
 
61
 
62
 #include <U8glib.h>
62
 #include <U8glib.h>
63
 #include "../../shared/HAL_SPI.h"
63
 #include "../../shared/HAL_SPI.h"
133
   return 1;
133
   return 1;
134
 }
134
 }
135
 
135
 
136
-#endif // HAS_GRAPHICAL_LCD
136
+#endif // HAS_MARLINUI_U8GLIB
137
 
137
 
138
 #endif // TARGET_LPC1768
138
 #endif // TARGET_LPC1768

+ 2
- 2
Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_sw_spi.cpp View File

57
 
57
 
58
 #include "../../../inc/MarlinConfigPre.h"
58
 #include "../../../inc/MarlinConfigPre.h"
59
 
59
 
60
-#if HAS_GRAPHICAL_LCD && DISABLED(U8GLIB_ST7920)
60
+#if HAS_MARLINUI_U8GLIB && DISABLED(U8GLIB_ST7920)
61
 
61
 
62
 #include <SoftwareSPI.h>
62
 #include <SoftwareSPI.h>
63
 
63
 
203
   return 1;
203
   return 1;
204
 }
204
 }
205
 
205
 
206
-#endif // HAS_GRAPHICAL_LCD && !U8GLIB_ST7920
206
+#endif // HAS_MARLINUI_U8GLIB && !U8GLIB_ST7920
207
 #endif // TARGET_LPC1768
207
 #endif // TARGET_LPC1768

+ 2
- 0
Marlin/src/HAL/LPC1768/usb_serial.cpp View File

26
 #if ENABLED(EMERGENCY_PARSER)
26
 #if ENABLED(EMERGENCY_PARSER)
27
 
27
 
28
 #include "../../feature/e_parser.h"
28
 #include "../../feature/e_parser.h"
29
+
29
 EmergencyParser::State emergency_state;
30
 EmergencyParser::State emergency_state;
31
+
30
 bool CDC_RecvCallback(const char buffer) {
32
 bool CDC_RecvCallback(const char buffer) {
31
   emergency_parser.update(emergency_state, buffer);
33
   emergency_parser.update(emergency_state, buffer);
32
   return true;
34
   return true;

+ 14
- 38
Marlin/src/HAL/SAMD51/HAL.h View File

35
 
35
 
36
   // MYSERIAL0 required before MarlinSerial includes!
36
   // MYSERIAL0 required before MarlinSerial includes!
37
 
37
 
38
+  #define _MSERIAL(X) Serial##X
39
+  #define MSERIAL(X) _MSERIAL(INCREMENT(X))
40
+
38
   #if SERIAL_PORT == -1
41
   #if SERIAL_PORT == -1
39
     #define MYSERIAL0 Serial
42
     #define MYSERIAL0 Serial
40
-  #elif SERIAL_PORT == 0
41
-    #define MYSERIAL0 Serial1
42
-  #elif SERIAL_PORT == 1
43
-    #define MYSERIAL0 Serial2
44
-  #elif SERIAL_PORT == 2
45
-    #define MYSERIAL0 Serial3
46
-  #elif SERIAL_PORT == 3
47
-    #define MYSERIAL0 Serial4
43
+  #elif WITHIN(SERIAL_PORT, 0, 3)
44
+    #define MYSERIAL0 MSERIAL(SERIAL_PORT)
48
   #else
45
   #else
49
     #error "SERIAL_PORT must be from -1 to 3. Please update your configuration."
46
     #error "SERIAL_PORT must be from -1 to 3. Please update your configuration."
50
   #endif
47
   #endif
51
 
48
 
52
   #ifdef SERIAL_PORT_2
49
   #ifdef SERIAL_PORT_2
53
-    #if SERIAL_PORT_2 == SERIAL_PORT
54
-      #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration."
55
-    #elif SERIAL_PORT_2 == -1
50
+    #if SERIAL_PORT_2 == -1
56
       #define MYSERIAL1 Serial
51
       #define MYSERIAL1 Serial
57
-    #elif SERIAL_PORT_2 == 0
58
-      #define MYSERIAL1 Serial1
59
-    #elif SERIAL_PORT_2 == 1
60
-      #define MYSERIAL1 Serial2
61
-    #elif SERIAL_PORT_2 == 2
62
-      #define MYSERIAL1 Serial3
63
-    #elif SERIAL_PORT_2 == 3
64
-      #define MYSERIAL1 Serial4
52
+    #elif WITHIN(SERIAL_PORT_2, 0, 3)
53
+      #define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
65
     #else
54
     #else
66
       #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
55
       #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
67
     #endif
56
     #endif
68
-    #define NUM_SERIAL 2
69
-  #else
70
-    #define NUM_SERIAL 1
71
   #endif
57
   #endif
72
 
58
 
73
-  #ifdef DGUS_SERIAL_PORT
74
-    #if DGUS_SERIAL_PORT == SERIAL_PORT
75
-      #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration."
76
-    #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2
77
-      #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration."
78
-    #elif DGUS_SERIAL_PORT == -1
79
-      #define DGUS_SERIAL Serial
80
-    #elif DGUS_SERIAL_PORT == 0
81
-      #define DGUS_SERIAL Serial1
82
-    #elif DGUS_SERIAL_PORT == 1
83
-      #define DGUS_SERIAL Serial2
84
-    #elif DGUS_SERIAL_PORT == 2
85
-      #define DGUS_SERIAL Serial3
86
-    #elif DGUS_SERIAL_PORT == 2
87
-      #define DGUS_SERIAL Serial4
59
+  #ifdef LCD_SERIAL_PORT
60
+    #if LCD_SERIAL_PORT == -1
61
+      #define LCD_SERIAL Serial
62
+    #elif WITHIN(LCD_SERIAL_PORT, 0, 3)
63
+      #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
88
     #else
64
     #else
89
-      #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration."
65
+      #error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
90
     #endif
66
     #endif
91
   #endif
67
   #endif
92
 
68
 

+ 0
- 1
Marlin/src/HAL/SAMD51/QSPIFlash.h View File

24
  * THE SOFTWARE.
24
  * THE SOFTWARE.
25
  *
25
  *
26
  * Derived from Adafruit_SPIFlash class with no SdFat references
26
  * Derived from Adafruit_SPIFlash class with no SdFat references
27
- *
28
  */
27
  */
29
 
28
 
30
 #pragma once
29
 #pragma once

+ 0
- 1
Marlin/src/HAL/SAMD51/pinsDebug.h View File

150
  *  93             |  PA10  | QSPI: IO2
150
  *  93             |  PA10  | QSPI: IO2
151
  *  94             |  PA11  | QSPI: IO3
151
  *  94             |  PA11  | QSPI: IO3
152
  *  95             |  PB31  | SD: DETECT
152
  *  95             |  PB31  | SD: DETECT
153
- *
154
  */
153
  */

+ 19
- 62
Marlin/src/HAL/STM32/HAL.h View File

43
 // ------------------------
43
 // ------------------------
44
 // Defines
44
 // Defines
45
 // ------------------------
45
 // ------------------------
46
+#define _MSERIAL(X) MSerial##X
47
+#define MSERIAL(X) _MSERIAL(X)
46
 
48
 
47
-#if SERIAL_PORT == 0
48
-  #error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
49
-#elif SERIAL_PORT == -1
49
+#if SERIAL_PORT == -1
50
   #define MYSERIAL0 SerialUSB
50
   #define MYSERIAL0 SerialUSB
51
-#elif SERIAL_PORT == 1
52
-  #define MYSERIAL0 MSerial1
53
-#elif SERIAL_PORT == 2
54
-  #define MYSERIAL0 MSerial2
55
-#elif SERIAL_PORT == 3
56
-  #define MYSERIAL0 MSerial3
57
-#elif SERIAL_PORT == 4
58
-  #define MYSERIAL0 MSerial4
59
-#elif SERIAL_PORT == 5
60
-  #define MYSERIAL0 MSerial5
61
-#elif SERIAL_PORT == 6
62
-  #define MYSERIAL0 MSerial6
51
+#elif WITHIN(SERIAL_PORT, 1, 6)
52
+  #define MYSERIAL0 MSERIAL(SERIAL_PORT)
63
 #else
53
 #else
64
-  #error "SERIAL_PORT must be from -1 to 6. Please update your configuration."
54
+  #error "SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
65
 #endif
55
 #endif
66
 
56
 
67
 #ifdef SERIAL_PORT_2
57
 #ifdef SERIAL_PORT_2
68
-  #define NUM_SERIAL 2
69
-  #if SERIAL_PORT_2 == 0
70
-    #error "SERIAL_PORT_2 cannot be 0. (Port 0 does not exist.) Please update your configuration."
71
-  #elif SERIAL_PORT_2 == SERIAL_PORT
72
-    #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration."
73
-  #elif SERIAL_PORT_2 == -1
58
+  #if SERIAL_PORT_2 == -1
74
     #define MYSERIAL1 SerialUSB
59
     #define MYSERIAL1 SerialUSB
75
-  #elif SERIAL_PORT_2 == 1
76
-    #define MYSERIAL1 MSerial1
77
-  #elif SERIAL_PORT_2 == 2
78
-    #define MYSERIAL1 MSerial2
79
-  #elif SERIAL_PORT_2 == 3
80
-    #define MYSERIAL1 MSerial3
81
-  #elif SERIAL_PORT_2 == 4
82
-    #define MYSERIAL1 MSerial4
83
-  #elif SERIAL_PORT_2 == 5
84
-    #define MYSERIAL1 MSerial5
85
-  #elif SERIAL_PORT_2 == 6
86
-    #define MYSERIAL1 MSerial6
60
+  #elif WITHIN(SERIAL_PORT_2, 1, 6)
61
+    #define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
87
   #else
62
   #else
88
-    #error "SERIAL_PORT_2 must be from -1 to 6. Please update your configuration."
63
+    #error "SERIAL_PORT_2 must be -1 or from 1 to 6. Please update your configuration."
89
   #endif
64
   #endif
90
-#else
91
-  #define NUM_SERIAL 1
92
 #endif
65
 #endif
93
 
66
 
94
-#if HAS_DGUS_LCD
95
-  #if DGUS_SERIAL_PORT == 0
96
-    #error "DGUS_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
97
-  #elif DGUS_SERIAL_PORT == SERIAL_PORT
98
-    #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration."
99
-  #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2
100
-    #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration."
101
-  #elif DGUS_SERIAL_PORT == -1
102
-    #define DGUS_SERIAL SerialUSB
103
-  #elif DGUS_SERIAL_PORT == 1
104
-    #define DGUS_SERIAL MSerial1
105
-  #elif DGUS_SERIAL_PORT == 2
106
-    #define DGUS_SERIAL MSerial2
107
-  #elif DGUS_SERIAL_PORT == 3
108
-    #define DGUS_SERIAL MSerial3
109
-  #elif DGUS_SERIAL_PORT == 4
110
-    #define DGUS_SERIAL MSerial4
111
-  #elif DGUS_SERIAL_PORT == 5
112
-    #define DGUS_SERIAL MSerial5
113
-  #elif DGUS_SERIAL_PORT == 6
114
-    #define DGUS_SERIAL MSerial6
67
+#ifdef LCD_SERIAL_PORT
68
+  #if LCD_SERIAL_PORT == -1
69
+    #define LCD_SERIAL SerialUSB
70
+  #elif WITHIN(LCD_SERIAL_PORT, 1, 6)
71
+    #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
115
   #else
72
   #else
116
-    #error "DGUS_SERIAL_PORT must be from -1 to 6. Please update your configuration."
73
+    #error "LCD_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
74
+  #endif
75
+  #if HAS_DGUS_LCD
76
+    #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite()
117
   #endif
77
   #endif
118
-
119
-  #define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.availableForWrite
120
 #endif
78
 #endif
121
 
79
 
122
-
123
 /**
80
 /**
124
  * TODO: review this to return 1 for pins that are not analog input
81
  * TODO: review this to return 1 for pins that are not analog input
125
  */
82
  */

+ 4
- 6
Marlin/src/HAL/STM32/MarlinSerial.cpp View File

49
   DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2)
49
   DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2)
50
 #endif
50
 #endif
51
 
51
 
52
-#if defined(DGUS_SERIAL_PORT) && DGUS_SERIAL_PORT >= 0
53
-  DECLARE_SERIAL_PORT_EXP(DGUS_SERIAL_PORT)
52
+#if defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT >= 0
53
+  DECLARE_SERIAL_PORT_EXP(LCD_SERIAL_PORT)
54
 #endif
54
 #endif
55
 
55
 
56
 void MarlinSerial::begin(unsigned long baud, uint8_t config) {
56
 void MarlinSerial::begin(unsigned long baud, uint8_t config) {
57
   HardwareSerial::begin(baud, config);
57
   HardwareSerial::begin(baud, config);
58
-  // replace the IRQ callback with the one we have defined
59
-  #if ENABLED(EMERGENCY_PARSER)
60
-    _serial.rx_callback = _rx_callback;
61
-  #endif
58
+  // Replace the IRQ callback with the one we have defined
59
+  TERN_(EMERGENCY_PARSER, _serial.rx_callback = _rx_callback);
62
 }
60
 }
63
 
61
 
64
 // This function is Copyright (c) 2006 Nicholas Zambetti.
62
 // This function is Copyright (c) 2006 Nicholas Zambetti.

+ 4
- 0
Marlin/src/HAL/STM32/MarlinSerial.h View File

35
       #endif
35
       #endif
36
   { }
36
   { }
37
 
37
 
38
+  #if ENABLED(EMERGENCY_PARSER)
39
+    static inline bool emergency_parser_enabled() { return true; }
40
+  #endif
41
+
38
   void begin(unsigned long baud, uint8_t config);
42
   void begin(unsigned long baud, uint8_t config);
39
   inline void begin(unsigned long baud) { begin(baud, SERIAL_8N1); }
43
   inline void begin(unsigned long baud) { begin(baud, SERIAL_8N1); }
40
 
44
 

+ 0
- 396
Marlin/src/HAL/STM32/SoftwareSerial.cpp View File

1
-/*
2
- * SoftwareSerial.cpp (formerly NewSoftSerial.cpp)
3
- *
4
- * Multi-instance software serial library for Arduino/Wiring
5
- * -- Interrupt-driven receive and other improvements by ladyada
6
- *    <https://ladyada.net>
7
- * -- Tuning, circular buffer, derivation from class Print/Stream,
8
- *    multi-instance support, porting to 8MHz processors,
9
- *    various optimizations, PROGMEM delay tables, inverse logic and
10
- *    direct port writing by Mikal Hart <http://www.arduiniana.org>
11
- * -- Pin change interrupt macros by Paul Stoffregen <https://www.pjrc.com>
12
- * -- 20MHz processor support by Garrett Mace <http://www.macetech.com>
13
- * -- ATmega1280/2560 support by Brett Hagman <https://www.roguerobotics.com>
14
- * -- STM32 support by Armin van der Togt
15
- *
16
- * This library is free software; you can redistribute it and/or
17
- * modify it under the terms of the GNU Lesser General Public
18
- * License as published by the Free Software Foundation; either
19
- * version 2.1 of the License, or (at your option) any later version.
20
- *
21
- * This library is distributed in the hope that it will be useful,
22
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24
- * Lesser General Public License for more details.
25
- *
26
- * You should have received a copy of the GNU Lesser General Public
27
- * License along with this library; if not, write to the Free Software
28
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
29
- *
30
- * The latest version of this library can always be found at
31
- * http://arduiniana.org.
32
- */
33
-
34
-//
35
-// Includes
36
-//
37
-#if defined(PLATFORMIO) && defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
38
-
39
-#include "../../inc/MarlinConfig.h"
40
-
41
-#include "SoftwareSerial.h"
42
-
43
-#define OVERSAMPLE 3 // in RX, Timer will generate interruption OVERSAMPLE time during a bit. Thus OVERSAMPLE ticks in a bit. (interrupt not synchonized with edge).
44
-
45
-// defined in bit-periods
46
-#define HALFDUPLEX_SWITCH_DELAY 5
47
-// It's best to define TIMER_SERIAL in variant.h. If not defined, we choose one here
48
-// The order is based on (lack of) features and compare channels, we choose the simplest available
49
-// because we only need an update interrupt
50
-#if !defined(TIMER_SERIAL)
51
-#if  defined(TIM18_BASE)
52
-#define TIMER_SERIAL TIM18
53
-#elif defined(TIM7_BASE)
54
-#define TIMER_SERIAL TIM7
55
-#elif defined(TIM6_BASE)
56
-#define TIMER_SERIAL TIM6
57
-#elif defined(TIM22_BASE)
58
-#define TIMER_SERIAL TIM22
59
-#elif defined(TIM21_BASE)
60
-#define TIMER_SERIAL TIM21
61
-#elif defined(TIM17_BASE)
62
-#define TIMER_SERIAL TIM17
63
-#elif defined(TIM16_BASE)
64
-#define TIMER_SERIAL TIM16
65
-#elif defined(TIM15_BASE)
66
-#define TIMER_SERIAL TIM15
67
-#elif defined(TIM14_BASE)
68
-#define TIMER_SERIAL TIM14
69
-#elif defined(TIM13_BASE)
70
-#define TIMER_SERIAL TIM13
71
-#elif defined(TIM11_BASE)
72
-#define TIMER_SERIAL TIM11
73
-#elif defined(TIM10_BASE)
74
-#define TIMER_SERIAL TIM10
75
-#elif defined(TIM12_BASE)
76
-#define TIMER_SERIAL TIM12
77
-#elif defined(TIM19_BASE)
78
-#define TIMER_SERIAL TIM19
79
-#elif defined(TIM9_BASE)
80
-#define TIMER_SERIAL TIM9
81
-#elif defined(TIM5_BASE)
82
-#define TIMER_SERIAL TIM5
83
-#elif defined(TIM4_BASE)
84
-#define TIMER_SERIAL TIM4
85
-#elif defined(TIM3_BASE)
86
-#define TIMER_SERIAL TIM3
87
-#elif defined(TIM2_BASE)
88
-#define TIMER_SERIAL TIM2
89
-#elif defined(TIM20_BASE)
90
-#define TIMER_SERIAL TIM20
91
-#elif defined(TIM8_BASE)
92
-#define TIMER_SERIAL TIM8
93
-#elif defined(TIM1_BASE)
94
-#define TIMER_SERIAL TIM1
95
-#else
96
-#error No suitable timer found for SoftwareSerial, define TIMER_SERIAL in variant.h
97
-#endif
98
-#endif
99
-//
100
-// Statics
101
-//
102
-HardwareTimer SoftwareSerial::timer(TIMER_SERIAL);
103
-const IRQn_Type SoftwareSerial::timer_interrupt_number = static_cast<IRQn_Type>(getTimerUpIrq(TIMER_SERIAL));
104
-uint32_t SoftwareSerial::timer_interrupt_priority = NVIC_EncodePriority(NVIC_GetPriorityGrouping(), TIM_IRQ_PRIO, TIM_IRQ_SUBPRIO);
105
-SoftwareSerial *SoftwareSerial::active_listener = nullptr;
106
-SoftwareSerial *volatile SoftwareSerial::active_out = nullptr;
107
-SoftwareSerial *volatile SoftwareSerial::active_in = nullptr;
108
-int32_t SoftwareSerial::tx_tick_cnt = 0; // OVERSAMPLE ticks needed for a bit
109
-int32_t volatile SoftwareSerial::rx_tick_cnt = 0;  // OVERSAMPLE ticks needed for a bit
110
-uint32_t SoftwareSerial::tx_buffer = 0;
111
-int32_t SoftwareSerial::tx_bit_cnt = 0;
112
-uint32_t SoftwareSerial::rx_buffer = 0;
113
-int32_t SoftwareSerial::rx_bit_cnt = -1; // rx_bit_cnt = -1 :  waiting for start bit
114
-uint32_t SoftwareSerial::cur_speed = 0;
115
-
116
-void SoftwareSerial::setInterruptPriority(uint32_t preemptPriority, uint32_t subPriority) {
117
-  timer_interrupt_priority = NVIC_EncodePriority(NVIC_GetPriorityGrouping(), preemptPriority, subPriority);
118
-}
119
-
120
-//
121
-// Private methods
122
-//
123
-
124
-void SoftwareSerial::setSpeed(uint32_t speed) {
125
-  if (speed != cur_speed) {
126
-    timer.pause();
127
-    if (speed != 0) {
128
-      // Disable the timer
129
-      uint32_t clock_rate, cmp_value;
130
-      // Get timer clock
131
-      clock_rate = timer.getTimerClkFreq();
132
-      int pre = 1;
133
-      // Calculate prescale an compare value
134
-      do {
135
-        cmp_value = clock_rate / (speed * OVERSAMPLE);
136
-        if (cmp_value >= UINT16_MAX) {
137
-          clock_rate /= 2;
138
-          pre *= 2;
139
-        }
140
-      } while (cmp_value >= UINT16_MAX);
141
-      timer.setPrescaleFactor(pre);
142
-      timer.setOverflow(cmp_value);
143
-      timer.setCount(0);
144
-      timer.attachInterrupt(&handleInterrupt);
145
-      timer.resume();
146
-      NVIC_SetPriority(timer_interrupt_number, timer_interrupt_priority);
147
-    }
148
-    else
149
-      timer.detachInterrupt();
150
-    cur_speed = speed;
151
-  }
152
-}
153
-
154
-// This function sets the current object as the "listening"
155
-// one and returns true if it replaces another
156
-bool SoftwareSerial::listen() {
157
-  if (active_listener != this) {
158
-    // wait for any transmit to complete as we may change speed
159
-    while (active_out);
160
-    active_listener->stopListening();
161
-    rx_tick_cnt = 1; // 1 : next interrupt will decrease rx_tick_cnt to 0 which means RX pin level will be considered.
162
-    rx_bit_cnt = -1; // rx_bit_cnt = -1 :  waiting for start bit
163
-    setSpeed(_speed);
164
-    active_listener = this;
165
-    if (!_half_duplex) active_in = this;
166
-    return true;
167
-  }
168
-  return false;
169
-}
170
-
171
-// Stop listening. Returns true if we were actually listening.
172
-bool SoftwareSerial::stopListening() {
173
-  if (active_listener == this) {
174
-    // wait for any output to complete
175
-    while (active_out);
176
-    if (_half_duplex) setRXTX(false);
177
-    active_listener = nullptr;
178
-    active_in = nullptr;
179
-    // turn off ints
180
-    setSpeed(0);
181
-    return true;
182
-  }
183
-  return false;
184
-}
185
-
186
-inline void SoftwareSerial::setTX() {
187
-  if (_inverse_logic)
188
-    LL_GPIO_ResetOutputPin(_transmitPinPort, _transmitPinNumber);
189
-  else
190
-    LL_GPIO_SetOutputPin(_transmitPinPort, _transmitPinNumber);
191
-  pinMode(_transmitPin, OUTPUT);
192
-}
193
-
194
-inline void SoftwareSerial::setRX() {
195
-  pinMode(_receivePin, _inverse_logic ? INPUT_PULLDOWN : INPUT_PULLUP); // pullup for normal logic!
196
-}
197
-
198
-inline void SoftwareSerial::setRXTX(bool input) {
199
-  if (_half_duplex) {
200
-    if (input) {
201
-      if (active_in != this) {
202
-        setRX();
203
-        rx_bit_cnt = -1; // rx_bit_cnt = -1 :  waiting for start bit
204
-        rx_tick_cnt = 2; // 2 : next interrupt will be discarded. 2 interrupts required to consider RX pin level
205
-        active_in = this;
206
-      }
207
-    }
208
-    else {
209
-      if (active_in == this) {
210
-        setTX();
211
-        active_in = nullptr;
212
-      }
213
-    }
214
-  }
215
-}
216
-
217
-inline void SoftwareSerial::send() {
218
-  if (--tx_tick_cnt <= 0) { // if tx_tick_cnt > 0 interrupt is discarded. Only when tx_tick_cnt reaches 0 is TX pin set.
219
-    if (tx_bit_cnt++ < 10) { // tx_bit_cnt < 10 transmission is not finished (10 = 1 start +8 bits + 1 stop)
220
-      // Send data (including start and stop bits)
221
-      if (tx_buffer & 1)
222
-        LL_GPIO_SetOutputPin(_transmitPinPort, _transmitPinNumber);
223
-      else
224
-        LL_GPIO_ResetOutputPin(_transmitPinPort, _transmitPinNumber);
225
-      tx_buffer >>= 1;
226
-      tx_tick_cnt = OVERSAMPLE; // Wait OVERSAMPLE ticks to send next bit
227
-    }
228
-    else { // Transmission finished
229
-      tx_tick_cnt = 1;
230
-      if (_output_pending) {
231
-        active_out = nullptr;
232
-
233
-        // In half-duplex mode wait HALFDUPLEX_SWITCH_DELAY bit-periods after the byte has
234
-        // been transmitted before allowing the switch to RX mode
235
-      }
236
-      else if (tx_bit_cnt > 10 + OVERSAMPLE * HALFDUPLEX_SWITCH_DELAY) {
237
-        if (_half_duplex && active_listener == this) setRXTX(true);
238
-        active_out = nullptr;
239
-      }
240
-    }
241
-  }
242
-}
243
-
244
-//
245
-// The receive routine called by the interrupt handler
246
-//
247
-inline void SoftwareSerial::recv() {
248
-  if (--rx_tick_cnt <= 0) { // if rx_tick_cnt > 0 interrupt is discarded. Only when rx_tick_cnt reaches 0 is RX pin considered
249
-    bool inbit = LL_GPIO_IsInputPinSet(_receivePinPort, _receivePinNumber) ^ _inverse_logic;
250
-    if (rx_bit_cnt == -1) {  // rx_bit_cnt = -1 :  waiting for start bit
251
-      if (!inbit) {
252
-        // got start bit
253
-        rx_bit_cnt = 0; // rx_bit_cnt == 0 : start bit received
254
-        rx_tick_cnt = OVERSAMPLE + 1; // Wait 1 bit (OVERSAMPLE ticks) + 1 tick in order to sample RX pin in the middle of the edge (and not too close to the edge)
255
-        rx_buffer = 0;
256
-      }
257
-      else
258
-        rx_tick_cnt = 1; // Waiting for start bit, but wrong level. Wait for next Interrupt to check RX pin level
259
-    }
260
-    else if (rx_bit_cnt >= 8) { // rx_bit_cnt >= 8 : waiting for stop bit
261
-      if (inbit) {
262
-        // Stop-bit read complete. Add to buffer.
263
-        uint8_t next = (_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF;
264
-        if (next != _receive_buffer_head) {
265
-          // save new data in buffer: tail points to byte destination
266
-          _receive_buffer[_receive_buffer_tail] = rx_buffer; // save new byte
267
-          _receive_buffer_tail = next;
268
-        }
269
-        else // rx_bit_cnt = x  with x = [0..7] correspond to new bit x received
270
-          _buffer_overflow = true;
271
-      }
272
-      // Full trame received. Restart waiting for start bit at next interrupt
273
-      rx_tick_cnt = 1;
274
-      rx_bit_cnt = -1;
275
-    }
276
-    else {
277
-      // data bits
278
-      rx_buffer >>= 1;
279
-      if (inbit) rx_buffer |= 0x80;
280
-      rx_bit_cnt++; // Prepare for next bit
281
-      rx_tick_cnt = OVERSAMPLE; // Wait OVERSAMPLE ticks before sampling next bit
282
-    }
283
-  }
284
-}
285
-
286
-//
287
-// Interrupt handling
288
-//
289
-
290
-/* static */
291
-inline void SoftwareSerial::handleInterrupt(HardwareTimer*) {
292
-  if (active_in)   active_in->recv();
293
-  if (active_out) active_out->send();
294
-}
295
-
296
-//
297
-// Constructor
298
-//
299
-SoftwareSerial::SoftwareSerial(uint16_t receivePin, uint16_t transmitPin, bool inverse_logic /* = false */) :
300
-  _receivePin(receivePin),
301
-  _transmitPin(transmitPin),
302
-  _receivePinPort(digitalPinToPort(receivePin)),
303
-  _receivePinNumber(STM_LL_GPIO_PIN(digitalPinToPinName(receivePin))),
304
-  _transmitPinPort(digitalPinToPort(transmitPin)),
305
-  _transmitPinNumber(STM_LL_GPIO_PIN(digitalPinToPinName(transmitPin))),
306
-  _speed(0),
307
-  _buffer_overflow(false),
308
-  _inverse_logic(inverse_logic),
309
-  _half_duplex(receivePin == transmitPin),
310
-  _output_pending(0),
311
-  _receive_buffer_tail(0),
312
-  _receive_buffer_head(0)
313
-{
314
-  if ((receivePin < NUM_DIGITAL_PINS) || (transmitPin < NUM_DIGITAL_PINS)) {
315
-    /* Enable GPIO clock for tx and rx pin*/
316
-    set_GPIO_Port_Clock(STM_PORT(digitalPinToPinName(transmitPin)));
317
-    set_GPIO_Port_Clock(STM_PORT(digitalPinToPinName(receivePin)));
318
-  }
319
-  else
320
-    _Error_Handler("ERROR: invalid pin number\n", -1);
321
-}
322
-
323
-//
324
-// Destructor
325
-//
326
-SoftwareSerial::~SoftwareSerial() { end(); }
327
-
328
-//
329
-// Public methods
330
-//
331
-
332
-void SoftwareSerial::begin(long speed) {
333
-  #ifdef FORCE_BAUD_RATE
334
-    speed = FORCE_BAUD_RATE;
335
-  #endif
336
-  _speed = speed;
337
-  if (!_half_duplex) {
338
-    setTX();
339
-    setRX();
340
-    listen();
341
-  }
342
-  else
343
-    setTX();
344
-}
345
-
346
-void SoftwareSerial::end() {
347
-  stopListening();
348
-}
349
-
350
-// Read data from buffer
351
-int SoftwareSerial::read() {
352
-  // Empty buffer?
353
-  if (_receive_buffer_head == _receive_buffer_tail) return -1;
354
-
355
-  // Read from "head"
356
-  uint8_t d = _receive_buffer[_receive_buffer_head]; // grab next byte
357
-  _receive_buffer_head = (_receive_buffer_head + 1) % _SS_MAX_RX_BUFF;
358
-  return d;
359
-}
360
-
361
-int SoftwareSerial::available() {
362
-  return (_receive_buffer_tail + _SS_MAX_RX_BUFF - _receive_buffer_head) % _SS_MAX_RX_BUFF;
363
-}
364
-
365
-size_t SoftwareSerial::write(uint8_t b) {
366
-  // wait for previous transmit to complete
367
-  _output_pending = 1;
368
-  while (active_out) { /* nada */ }
369
-  // add start and stop bits.
370
-  tx_buffer = b << 1 | 0x200;
371
-  if (_inverse_logic) tx_buffer = ~tx_buffer;
372
-  tx_bit_cnt = 0;
373
-  tx_tick_cnt = OVERSAMPLE;
374
-  setSpeed(_speed);
375
-  if (_half_duplex) setRXTX(false);
376
-  _output_pending = 0;
377
-  // make us active
378
-  active_out = this;
379
-  return 1;
380
-}
381
-
382
-void SoftwareSerial::flush() {
383
-  noInterrupts();
384
-  _receive_buffer_head = _receive_buffer_tail = 0;
385
-  interrupts();
386
-}
387
-
388
-int SoftwareSerial::peek() {
389
-  // Empty buffer?
390
-  if (_receive_buffer_head == _receive_buffer_tail) return -1;
391
-
392
-  // Read from "head"
393
-  return _receive_buffer[_receive_buffer_head];
394
-}
395
-
396
-#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC

+ 0
- 114
Marlin/src/HAL/STM32/SoftwareSerial.h View File

1
-/**
2
- * SoftwareSerial.h (formerly NewSoftSerial.h)
3
- *
4
- * Multi-instance software serial library for Arduino/Wiring
5
- * -- Interrupt-driven receive and other improvements by ladyada
6
- *    (https://ladyada.net)
7
- * -- Tuning, circular buffer, derivation from class Print/Stream,
8
- *    multi-instance support, porting to 8MHz processors,
9
- *    various optimizations, PROGMEM delay tables, inverse logic and
10
- *    direct port writing by Mikal Hart (http://www.arduiniana.org)
11
- * -- Pin change interrupt macros by Paul Stoffregen (https://www.pjrc.com)
12
- * -- 20MHz processor support by Garrett Mace (http://www.macetech.com)
13
- * -- ATmega1280/2560 support by Brett Hagman (https://www.roguerobotics.com/)
14
- *
15
- * This library is free software; you can redistribute it and/or
16
- * modify it under the terms of the GNU Lesser General Public
17
- * License as published by the Free Software Foundation; either
18
- * version 2.1 of the License, or (at your option) any later version.
19
- *
20
- * This library is distributed in the hope that it will be useful,
21
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23
- * Lesser General Public License for more details.
24
- *
25
- * You should have received a copy of the GNU Lesser General Public
26
- * License along with this library; if not, write to the Free Software
27
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28
- *
29
- * The latest version of this library can always be found at
30
- * http://arduiniana.org.
31
- */
32
-#pragma once
33
-
34
-#include <Arduino.h>
35
-
36
-/******************************************************************************
37
- * Definitions
38
- ******************************************************************************/
39
-
40
-#define _SS_MAX_RX_BUFF 64 // RX buffer size
41
-
42
-class SoftwareSerial : public Stream {
43
-  private:
44
-    // per object data
45
-    uint16_t _receivePin;
46
-    uint16_t _transmitPin;
47
-    GPIO_TypeDef *_receivePinPort;
48
-    uint32_t _receivePinNumber;
49
-    GPIO_TypeDef *_transmitPinPort;
50
-    uint32_t _transmitPinNumber;
51
-    uint32_t _speed;
52
-
53
-    uint16_t _buffer_overflow: 1;
54
-    uint16_t _inverse_logic: 1;
55
-    uint16_t _half_duplex: 1;
56
-    uint16_t _output_pending: 1;
57
-
58
-    unsigned char _receive_buffer[_SS_MAX_RX_BUFF];
59
-    volatile uint8_t _receive_buffer_tail;
60
-    volatile uint8_t _receive_buffer_head;
61
-
62
-    uint32_t delta_start = 0;
63
-
64
-    // static data
65
-    static HardwareTimer timer;
66
-    static const IRQn_Type timer_interrupt_number;
67
-    static uint32_t timer_interrupt_priority;
68
-    static SoftwareSerial *active_listener;
69
-    static SoftwareSerial *volatile active_out;
70
-    static SoftwareSerial *volatile active_in;
71
-    static int32_t tx_tick_cnt;
72
-    static volatile int32_t rx_tick_cnt;
73
-    static uint32_t tx_buffer;
74
-    static int32_t tx_bit_cnt;
75
-    static uint32_t rx_buffer;
76
-    static int32_t rx_bit_cnt;
77
-    static uint32_t cur_speed;
78
-
79
-    // private methods
80
-    void send();
81
-    void recv();
82
-    void setTX();
83
-    void setRX();
84
-    void setSpeed(uint32_t speed);
85
-    void setRXTX(bool input);
86
-    static void handleInterrupt(HardwareTimer *timer);
87
-
88
-  public:
89
-    // public methods
90
-
91
-    SoftwareSerial(uint16_t receivePin, uint16_t transmitPin, bool inverse_logic=false);
92
-    virtual ~SoftwareSerial();
93
-    void begin(long speed);
94
-    bool listen();
95
-    void end();
96
-    bool isListening() { return active_listener == this; }
97
-    bool stopListening();
98
-    bool overflow() {
99
-      bool ret = _buffer_overflow;
100
-      if (ret) _buffer_overflow = false;
101
-      return ret;
102
-    }
103
-    int peek();
104
-
105
-    virtual size_t write(uint8_t byte);
106
-    virtual int read();
107
-    virtual int available();
108
-    virtual void flush();
109
-    operator bool() { return true; }
110
-
111
-    static void setInterruptPriority(uint32_t preemptPriority, uint32_t subPriority);
112
-
113
-    using Print::write;
114
-};

+ 1
- 1
Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h View File

98
     timer_dev * const tdev = PIN_MAP[pin].timer_device;
98
     timer_dev * const tdev = PIN_MAP[pin].timer_device;
99
     const uint8_t channel = PIN_MAP[pin].timer_channel;
99
     const uint8_t channel = PIN_MAP[pin].timer_channel;
100
     const char num = (
100
     const char num = (
101
-      #if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY)
101
+      #if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY)
102
         tdev == &timer8 ? '8' :
102
         tdev == &timer8 ? '8' :
103
         tdev == &timer5 ? '5' :
103
         tdev == &timer5 ? '5' :
104
       #endif
104
       #endif

+ 1
- 1
Marlin/src/HAL/STM32/tft/tft_fsmc.cpp View File

87
 
87
 
88
   __HAL_RCC_FSMC_CLK_ENABLE();
88
   __HAL_RCC_FSMC_CLK_ENABLE();
89
 
89
 
90
-  for(uint16_t i = 0; PinMap_FSMC[i].pin != NC; i++)
90
+  for (uint16_t i = 0; PinMap_FSMC[i].pin != NC; i++)
91
     pinmap_pinout(PinMap_FSMC[i].pin, PinMap_FSMC);
91
     pinmap_pinout(PinMap_FSMC[i].pin, PinMap_FSMC);
92
   pinmap_pinout(digitalPinToPinName(TFT_CS_PIN), PinMap_FSMC_CS);
92
   pinmap_pinout(digitalPinToPinName(TFT_CS_PIN), PinMap_FSMC_CS);
93
   pinmap_pinout(digitalPinToPinName(TFT_RS_PIN), PinMap_FSMC_RS);
93
   pinmap_pinout(digitalPinToPinName(TFT_RS_PIN), PinMap_FSMC_RS);

+ 2
- 2
Marlin/src/HAL/STM32/tft/xpt2046.cpp View File

155
 
155
 
156
 uint16_t XPT2046::HardwareIO(uint16_t data) {
156
 uint16_t XPT2046::HardwareIO(uint16_t data) {
157
   __HAL_SPI_ENABLE(&SPIx);
157
   __HAL_SPI_ENABLE(&SPIx);
158
-  while((SPIx.Instance->SR & SPI_FLAG_TXE) != SPI_FLAG_TXE) {}
158
+  while ((SPIx.Instance->SR & SPI_FLAG_TXE) != SPI_FLAG_TXE) {}
159
   SPIx.Instance->DR = data;
159
   SPIx.Instance->DR = data;
160
-  while((SPIx.Instance->SR & SPI_FLAG_RXNE) != SPI_FLAG_RXNE) {}
160
+  while ((SPIx.Instance->SR & SPI_FLAG_RXNE) != SPI_FLAG_RXNE) {}
161
   __HAL_SPI_DISABLE(&SPIx);
161
   __HAL_SPI_DISABLE(&SPIx);
162
 
162
 
163
   return SPIx.Instance->DR;
163
   return SPIx.Instance->DR;

+ 99
- 31
Marlin/src/HAL/STM32/timers.cpp View File

110
 // ------------------------
110
 // ------------------------
111
 
111
 
112
 HardwareTimer *timer_instance[NUM_HARDWARE_TIMERS] = { NULL };
112
 HardwareTimer *timer_instance[NUM_HARDWARE_TIMERS] = { NULL };
113
-bool timer_enabled[NUM_HARDWARE_TIMERS] = { false };
114
 
113
 
115
 // ------------------------
114
 // ------------------------
116
 // Public functions
115
 // Public functions
135
          * which changes the prescaler when an IRQ frequency change is needed
134
          * which changes the prescaler when an IRQ frequency change is needed
136
          * (for example when steppers are turned on)
135
          * (for example when steppers are turned on)
137
          */
136
          */
137
+
138
         timer_instance[timer_num]->setPrescaleFactor(STEPPER_TIMER_PRESCALE); //the -1 is done internally
138
         timer_instance[timer_num]->setPrescaleFactor(STEPPER_TIMER_PRESCALE); //the -1 is done internally
139
         timer_instance[timer_num]->setOverflow(_MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (HAL_TIMER_RATE) / (STEPPER_TIMER_PRESCALE) /* /frequency */), TICK_FORMAT);
139
         timer_instance[timer_num]->setOverflow(_MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (HAL_TIMER_RATE) / (STEPPER_TIMER_PRESCALE) /* /frequency */), TICK_FORMAT);
140
         break;
140
         break;
145
         break;
145
         break;
146
     }
146
     }
147
 
147
 
148
+    // Disable preload. Leaving it default-enabled can cause the timer to stop if it happens
149
+    // to exit the ISR after the start time for the next interrupt has already passed.
150
+    timer_instance[timer_num]->setPreloadEnable(false);
151
+
148
     HAL_timer_enable_interrupt(timer_num);
152
     HAL_timer_enable_interrupt(timer_num);
149
 
153
 
150
-    /*
151
-     * Initializes (and unfortunately starts) the timer.
152
-     * This is needed to set correct IRQ priority at the moment but causes
153
-     * no harm since every call to HAL_timer_start() is actually followed by
154
-     * a call to HAL_timer_enable_interrupt() which means that there isn't
155
-     * a case in which you want the timer to run without a callback.
156
-     */
154
+    // Start the timer.
157
     timer_instance[timer_num]->resume(); // First call to resume() MUST follow the attachInterrupt()
155
     timer_instance[timer_num]->resume(); // First call to resume() MUST follow the attachInterrupt()
158
 
156
 
159
     // This is fixed in Arduino_Core_STM32 1.8.
157
     // This is fixed in Arduino_Core_STM32 1.8.
161
     // timer_instance[timer_num]->setInterruptPriority
159
     // timer_instance[timer_num]->setInterruptPriority
162
     switch (timer_num) {
160
     switch (timer_num) {
163
       case STEP_TIMER_NUM:
161
       case STEP_TIMER_NUM:
164
-        HAL_NVIC_SetPriority(STEP_TIMER_IRQ_NAME, STEP_TIMER_IRQ_PRIO, 0);
162
+        timer_instance[timer_num]->setInterruptPriority(STEP_TIMER_IRQ_PRIO, 0);
165
         break;
163
         break;
166
       case TEMP_TIMER_NUM:
164
       case TEMP_TIMER_NUM:
167
-        HAL_NVIC_SetPriority(TEMP_TIMER_IRQ_NAME, TEMP_TIMER_IRQ_PRIO, 0);
165
+        timer_instance[timer_num]->setInterruptPriority(TEMP_TIMER_IRQ_PRIO, 0);
168
         break;
166
         break;
169
     }
167
     }
170
   }
168
   }
171
 }
169
 }
172
 
170
 
173
 void HAL_timer_enable_interrupt(const uint8_t timer_num) {
171
 void HAL_timer_enable_interrupt(const uint8_t timer_num) {
174
-  if (HAL_timer_initialized(timer_num) && !timer_enabled[timer_num]) {
175
-    timer_enabled[timer_num] = true;
172
+  if (HAL_timer_initialized(timer_num) && !timer_instance[timer_num]->hasInterrupt()) {
176
     switch (timer_num) {
173
     switch (timer_num) {
177
       case STEP_TIMER_NUM:
174
       case STEP_TIMER_NUM:
178
-      timer_instance[timer_num]->attachInterrupt(Step_Handler);
179
-      break;
180
-    case TEMP_TIMER_NUM:
181
-      timer_instance[timer_num]->attachInterrupt(Temp_Handler);
182
-      break;
175
+        timer_instance[timer_num]->attachInterrupt(Step_Handler);
176
+        break;
177
+      case TEMP_TIMER_NUM:
178
+        timer_instance[timer_num]->attachInterrupt(Temp_Handler);
179
+        break;
183
     }
180
     }
184
   }
181
   }
185
 }
182
 }
186
 
183
 
187
 void HAL_timer_disable_interrupt(const uint8_t timer_num) {
184
 void HAL_timer_disable_interrupt(const uint8_t timer_num) {
188
-  if (HAL_timer_interrupt_enabled(timer_num)) {
189
-    timer_instance[timer_num]->detachInterrupt();
190
-    timer_enabled[timer_num] = false;
191
-  }
185
+  if (HAL_timer_initialized(timer_num)) timer_instance[timer_num]->detachInterrupt();
192
 }
186
 }
193
 
187
 
194
 bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
188
 bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
195
-  return HAL_timer_initialized(timer_num) && timer_enabled[timer_num];
196
-}
197
-
198
-// Only for use within the HAL
199
-TIM_TypeDef * HAL_timer_device(const uint8_t timer_num) {
200
-  switch (timer_num) {
201
-    case STEP_TIMER_NUM: return STEP_TIMER_DEV;
202
-    case TEMP_TIMER_NUM: return TEMP_TIMER_DEV;
203
-  }
204
-  return nullptr;
189
+  return HAL_timer_initialized(timer_num) && timer_instance[timer_num]->hasInterrupt();
205
 }
190
 }
206
 
191
 
207
 void SetTimerInterruptPriorities() {
192
 void SetTimerInterruptPriorities() {
209
   TERN_(HAS_SERVOS, libServo::setInterruptPriority(SERVO_TIMER_IRQ_PRIO, 0));
194
   TERN_(HAS_SERVOS, libServo::setInterruptPriority(SERVO_TIMER_IRQ_PRIO, 0));
210
 }
195
 }
211
 
196
 
197
+// This is a terrible hack to replicate the behavior used in the framework's SoftwareSerial.cpp
198
+// to choose a serial timer. It will select TIM7 on most boards used by Marlin, but this is more
199
+// resiliant to new MCUs which may not have a TIM7. Best practice is to explicitly specify
200
+// TIMER_SERIAL to avoid relying on framework selections which may not be predictable.
201
+#if !defined(TIMER_SERIAL)
202
+  #if defined (TIM18_BASE)
203
+    #define TIMER_SERIAL TIM18
204
+  #elif defined (TIM7_BASE)
205
+    #define TIMER_SERIAL TIM7
206
+  #elif defined (TIM6_BASE)
207
+    #define TIMER_SERIAL TIM6
208
+  #elif defined (TIM22_BASE)
209
+    #define TIMER_SERIAL TIM22
210
+  #elif defined (TIM21_BASE)
211
+    #define TIMER_SERIAL TIM21
212
+  #elif defined (TIM17_BASE)
213
+    #define TIMER_SERIAL TIM17
214
+  #elif defined (TIM16_BASE)
215
+    #define TIMER_SERIAL TIM16
216
+  #elif defined (TIM15_BASE)
217
+    #define TIMER_SERIAL TIM15
218
+  #elif defined (TIM14_BASE)
219
+    #define TIMER_SERIAL TIM14
220
+  #elif defined (TIM13_BASE)
221
+    #define TIMER_SERIAL TIM13
222
+  #elif defined (TIM11_BASE)
223
+    #define TIMER_SERIAL TIM11
224
+  #elif defined (TIM10_BASE)
225
+    #define TIMER_SERIAL TIM10
226
+  #elif defined (TIM12_BASE)
227
+    #define TIMER_SERIAL TIM12
228
+  #elif defined (TIM19_BASE)
229
+    #define TIMER_SERIAL TIM19
230
+  #elif defined (TIM9_BASE)
231
+    #define TIMER_SERIAL TIM9
232
+  #elif defined (TIM5_BASE)
233
+    #define TIMER_SERIAL TIM5
234
+  #elif defined (TIM4_BASE)
235
+    #define TIMER_SERIAL TIM4
236
+  #elif defined (TIM3_BASE)
237
+    #define TIMER_SERIAL TIM3
238
+  #elif defined (TIM2_BASE)
239
+    #define TIMER_SERIAL TIM2
240
+  #elif defined (TIM20_BASE)
241
+    #define TIMER_SERIAL TIM20
242
+  #elif defined (TIM8_BASE)
243
+    #define TIMER_SERIAL TIM8
244
+  #elif defined (TIM1_BASE)
245
+    #define TIMER_SERIAL TIM1
246
+  #else
247
+    #error No suitable timer found for SoftwareSerial, define TIMER_SERIAL in variant.h
248
+  #endif
249
+#endif
250
+
251
+// Place all timers used into an array, then recursively check for duplicates during compilation.
252
+// This does not currently account for timers used for PWM, such as for fans.
253
+// Timers are actually pointers. Convert to integers to simplify constexpr logic.
254
+static constexpr uintptr_t timers_in_use[] = {
255
+  uintptr_t(TEMP_TIMER_DEV),  // Override in pins file
256
+  uintptr_t(STEP_TIMER_DEV),  // Override in pins file
257
+  #if HAS_TMC_SW_SERIAL
258
+    uintptr_t(TIMER_SERIAL),  // Set in variant.h, or as a define in platformio.h if not present in variant.h
259
+  #endif
260
+  #if ENABLED(SPEAKER)
261
+    uintptr_t(TIMER_TONE),    // Set in variant.h, or as a define in platformio.h if not present in variant.h
262
+  #endif
263
+  #if HAS_SERVOS
264
+    uintptr_t(TIMER_SERVO),   // Set in variant.h, or as a define in platformio.h if not present in variant.h
265
+  #endif
266
+  };
267
+
268
+static constexpr bool verify_no_duplicate_timers() {
269
+  LOOP_L_N(i, COUNT(timers_in_use))
270
+    LOOP_S_L_N(j, i + 1, COUNT(timers_in_use))
271
+      if (timers_in_use[i] == timers_in_use[j]) return false;
272
+  return true;
273
+}
274
+
275
+// If this assertion fails at compile time, review the timers_in_use array. If default_envs is
276
+// defined properly in platformio.ini, VS Code can evaluate the array when hovering over it,
277
+// making it easy to identify the conflicting timers.
278
+static_assert(verify_no_duplicate_timers(), "One or more timer conflict detected");
279
+
212
 #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
280
 #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC

+ 15
- 7
Marlin/src/HAL/STM32/timers.h View File

30
 
30
 
31
 #define FORCE_INLINE __attribute__((always_inline)) inline
31
 #define FORCE_INLINE __attribute__((always_inline)) inline
32
 
32
 
33
+// STM32 timers may be 16 or 32 bit. Limiting HAL_TIMER_TYPE_MAX to 16 bits
34
+// avoids issues with STM32F0 MCUs, which seem to pause timers if UINT32_MAX
35
+// is written to the register. STM32F4 timers do not manifest this issue,
36
+// even when writing to 16 bit timers.
37
+//
38
+// The range of the timer can be queried at runtime using IS_TIM_32B_COUNTER_INSTANCE.
39
+// This is a more expensive check than a simple compile-time constant, so its
40
+// implementation is deferred until the desire for a 32-bit range outweighs the cost
41
+// of adding a run-time check and HAL_TIMER_TYPE_MAX is refactored to allow unique
42
+// values for each timer.
33
 #define hal_timer_t uint32_t
43
 #define hal_timer_t uint32_t
34
-#define HAL_TIMER_TYPE_MAX 0xFFFFFFFF // Timers can be 16 or 32 bit
44
+#define HAL_TIMER_TYPE_MAX UINT16_MAX
35
 
45
 
36
 #ifndef STEP_TIMER_NUM
46
 #ifndef STEP_TIMER_NUM
37
   #define STEP_TIMER_NUM        0  // Timer Index for Stepper
47
   #define STEP_TIMER_NUM        0  // Timer Index for Stepper
61
 #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
71
 #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
62
 #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
72
 #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
63
 
73
 
64
-extern void Step_Handler(HardwareTimer *htim);
65
-extern void Temp_Handler(HardwareTimer *htim);
74
+extern void Step_Handler();
75
+extern void Temp_Handler();
66
 
76
 
67
 #ifndef HAL_STEP_TIMER_ISR
77
 #ifndef HAL_STEP_TIMER_ISR
68
-  #define HAL_STEP_TIMER_ISR() void Step_Handler(HardwareTimer *htim)
78
+  #define HAL_STEP_TIMER_ISR() void Step_Handler()
69
 #endif
79
 #endif
70
 #ifndef HAL_TEMP_TIMER_ISR
80
 #ifndef HAL_TEMP_TIMER_ISR
71
-  #define HAL_TEMP_TIMER_ISR() void Temp_Handler(HardwareTimer *htim)
81
+  #define HAL_TEMP_TIMER_ISR() void Temp_Handler()
72
 #endif
82
 #endif
73
 
83
 
74
 // ------------------------
84
 // ------------------------
90
 // Exposed here to allow all timer priority information to reside in timers.cpp
100
 // Exposed here to allow all timer priority information to reside in timers.cpp
91
 void SetTimerInterruptPriorities();
101
 void SetTimerInterruptPriorities();
92
 
102
 
93
-//TIM_TypeDef* HAL_timer_device(const uint8_t timer_num); no need to be public for now. not public = not used externally
94
-
95
 // FORCE_INLINE because these are used in performance-critical situations
103
 // FORCE_INLINE because these are used in performance-critical situations
96
 FORCE_INLINE bool HAL_timer_initialized(const uint8_t timer_num) {
104
 FORCE_INLINE bool HAL_timer_initialized(const uint8_t timer_num) {
97
   return timer_instance[timer_num] != NULL;
105
   return timer_instance[timer_num] != NULL;

+ 31
- 65
Marlin/src/HAL/STM32F1/HAL.h View File

46
   #include "msc_sd.h"
46
   #include "msc_sd.h"
47
 #endif
47
 #endif
48
 
48
 
49
+#include "MarlinSerial.h"
50
+
49
 // ------------------------
51
 // ------------------------
50
 // Defines
52
 // Defines
51
 // ------------------------
53
 // ------------------------
52
 
54
 
53
 #ifndef STM32_FLASH_SIZE
55
 #ifndef STM32_FLASH_SIZE
54
-  #if defined(MCU_STM32F103RE) || defined(MCU_STM32F103VE)
56
+  #if EITHER(MCU_STM32F103RE, MCU_STM32F103VE)
55
     #define STM32_FLASH_SIZE 512
57
     #define STM32_FLASH_SIZE 512
56
   #else
58
   #else
57
     #define STM32_FLASH_SIZE 256
59
     #define STM32_FLASH_SIZE 256
64
   #else
66
   #else
65
     #define UsbSerial MarlinCompositeSerial
67
     #define UsbSerial MarlinCompositeSerial
66
   #endif
68
   #endif
67
-  #define MSerial1  Serial1
68
-  #define MSerial2  Serial2
69
-  #define MSerial3  Serial3
70
-  #define MSerial4  Serial4
71
-  #define MSerial5  Serial5
69
+#endif
70
+
71
+#define _MSERIAL(X) MSerial##X
72
+#define MSERIAL(X) _MSERIAL(X)
73
+
74
+#if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY)
75
+  #define NUM_UARTS 5
72
 #else
76
 #else
73
-  #define MSerial1  Serial
74
-  #define MSerial2  Serial1
75
-  #define MSerial3  Serial2
76
-  #define MSerial4  Serial3
77
-  #define MSerial5  Serial4
77
+  #define NUM_UARTS 3
78
 #endif
78
 #endif
79
 
79
 
80
-#if SERIAL_PORT == 0
81
-  #error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
82
-#elif SERIAL_PORT == -1
80
+#if SERIAL_PORT == -1
83
   #define MYSERIAL0 UsbSerial
81
   #define MYSERIAL0 UsbSerial
84
-#elif SERIAL_PORT == 1
85
-  #define MYSERIAL0 MSerial1
86
-#elif SERIAL_PORT == 2
87
-  #define MYSERIAL0 MSerial2
88
-#elif SERIAL_PORT == 3
89
-  #define MYSERIAL0 MSerial3
90
-#elif SERIAL_PORT == 4
91
-  #define MYSERIAL0 MSerial4
92
-#elif SERIAL_PORT == 5
93
-  #define MYSERIAL0 MSerial5
82
+#elif WITHIN(SERIAL_PORT, 1, NUM_UARTS)
83
+  #define MYSERIAL0 MSERIAL(SERIAL_PORT)
84
+#elif NUM_UARTS == 5
85
+  #error "SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
94
 #else
86
 #else
95
-  #error "SERIAL_PORT must be from -1 to 5. Please update your configuration."
87
+  #error "SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration."
96
 #endif
88
 #endif
97
 
89
 
98
 #ifdef SERIAL_PORT_2
90
 #ifdef SERIAL_PORT_2
99
-  #if SERIAL_PORT_2 == 0
100
-    #error "SERIAL_PORT_2 cannot be 0. (Port 0 does not exist.) Please update your configuration."
101
-  #elif SERIAL_PORT_2 == SERIAL_PORT
102
-    #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration."
103
-  #elif SERIAL_PORT_2 == -1
91
+  #if SERIAL_PORT_2 == -1
104
     #define MYSERIAL1 UsbSerial
92
     #define MYSERIAL1 UsbSerial
105
-  #elif SERIAL_PORT_2 == 1
106
-    #define MYSERIAL1 MSerial1
107
-  #elif SERIAL_PORT_2 == 2
108
-    #define MYSERIAL1 MSerial2
109
-  #elif SERIAL_PORT_2 == 3
110
-    #define MYSERIAL1 MSerial3
111
-  #elif SERIAL_PORT_2 == 4
112
-    #define MYSERIAL1 MSerial4
113
-  #elif SERIAL_PORT_2 == 5
114
-    #define MYSERIAL1 MSerial5
93
+  #elif WITHIN(SERIAL_PORT_2, 1, NUM_UARTS)
94
+    #define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
95
+  #elif NUM_UARTS == 5
96
+    #error "SERIAL_PORT_2 must be -1 or from 1 to 5. Please update your configuration."
115
   #else
97
   #else
116
-    #error "SERIAL_PORT_2 must be from -1 to 5. Please update your configuration."
98
+    #error "SERIAL_PORT_2 must be -1 or from 1 to 3. Please update your configuration."
117
   #endif
99
   #endif
118
-  #define NUM_SERIAL 2
119
-#else
120
-  #define NUM_SERIAL 1
121
 #endif
100
 #endif
122
 
101
 
123
-#ifdef DGUS_SERIAL
124
-  #if DGUS_SERIAL_PORT == 0
125
-    #error "DGUS_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
126
-  #elif DGUS_SERIAL_PORT == SERIAL_PORT
127
-    #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration."
128
-  #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2
129
-    #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration."
130
-  #elif DGUS_SERIAL_PORT == -1
131
-    #define DGUS_SERIAL UsbSerial
132
-  #elif DGUS_SERIAL_PORT == 1
133
-    #define DGUS_SERIAL MSerial1
134
-  #elif DGUS_SERIAL_PORT == 2
135
-    #define DGUS_SERIAL MSerial2
136
-  #elif DGUS_SERIAL_PORT == 3
137
-    #define DGUS_SERIAL MSerial3
138
-  #elif DGUS_SERIAL_PORT == 4
139
-    #define DGUS_SERIAL MSerial4
140
-  #elif DGUS_SERIAL_PORT == 5
141
-    #define DGUS_SERIAL MSerial5
102
+#ifdef LCD_SERIAL_PORT
103
+  #if LCD_SERIAL_PORT == -1
104
+    #define LCD_SERIAL UsbSerial
105
+  #elif WITHIN(LCD_SERIAL_PORT, 1, NUM_UARTS)
106
+    #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
107
+  #elif NUM_UARTS == 5
108
+    #error "LCD_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
142
   #else
109
   #else
143
-    #error "DGUS_SERIAL_PORT must be from -1 to 5. Please update your configuration."
110
+    #error "LCD_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration."
144
   #endif
111
   #endif
145
 #endif
112
 #endif
146
 
113
 
147
-
148
 // Set interrupt grouping for this MCU
114
 // Set interrupt grouping for this MCU
149
 void HAL_init();
115
 void HAL_init();
150
 #define HAL_IDLETASK 1
116
 #define HAL_IDLETASK 1

+ 193
- 0
Marlin/src/HAL/STM32F1/MarlinSerial.cpp View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifdef __STM32F1__
24
+
25
+#include "../../inc/MarlinConfig.h"
26
+#include "MarlinSerial.h"
27
+#include <libmaple/usart.h>
28
+
29
+// Copied from ~/.platformio/packages/framework-arduinoststm32-maple/STM32F1/system/libmaple/usart_private.h
30
+// Changed to handle Emergency Parser
31
+static inline __always_inline void my_usart_irq(ring_buffer *rb, ring_buffer *wb, usart_reg_map *regs, MarlinSerial &serial) {
32
+ /* Handle RXNEIE and TXEIE interrupts.
33
+  * RXNE signifies availability of a byte in DR.
34
+  *
35
+  * See table 198 (sec 27.4, p809) in STM document RM0008 rev 15.
36
+  * We enable RXNEIE.
37
+  */
38
+  uint32_t srflags = regs->SR, cr1its = regs->CR1;
39
+
40
+  if ((cr1its & USART_CR1_RXNEIE) && (srflags & USART_SR_RXNE)) {
41
+    if (srflags & USART_SR_FE || srflags & USART_SR_PE ) {
42
+      // framing error or parity error
43
+      regs->DR; // Read and throw away the data, which also clears FE and PE
44
+    }
45
+    else {
46
+      uint8_t c = (uint8)regs->DR;
47
+      #ifdef USART_SAFE_INSERT
48
+        // If the buffer is full and the user defines USART_SAFE_INSERT,
49
+        // ignore new bytes.
50
+        rb_safe_insert(rb, c);
51
+      #else
52
+        // By default, push bytes around in the ring buffer.
53
+        rb_push_insert(rb, c);
54
+      #endif
55
+      #if ENABLED(EMERGENCY_PARSER)
56
+        if (serial.emergency_parser_enabled())
57
+          emergency_parser.update(serial.emergency_state, c);
58
+      #endif
59
+    }
60
+  }
61
+  else if (srflags & USART_SR_ORE) {
62
+    // overrun and empty data, just do a dummy read to clear ORE
63
+    // and prevent a raise condition where a continous interrupt stream (due to ORE set) occurs
64
+    // (see chapter "Overrun error" ) in STM32 reference manual
65
+    regs->DR;
66
+  }
67
+
68
+  // TXE signifies readiness to send a byte to DR.
69
+  if ((cr1its & USART_CR1_TXEIE) && (srflags & USART_SR_TXE)) {
70
+    if (!rb_is_empty(wb))
71
+      regs->DR=rb_remove(wb);
72
+    else
73
+      regs->CR1 &= ~((uint32)USART_CR1_TXEIE); // disable TXEIE
74
+  }
75
+}
76
+
77
+// Not every MarlinSerial port should handle emergency parsing.
78
+// It would not make sense to parse GCode from TMC responses, for example.
79
+constexpr bool serial_handles_emergency(int port) {
80
+  return false
81
+    #ifdef SERIAL_PORT
82
+      || (SERIAL_PORT) == port
83
+    #endif
84
+    #ifdef SERIAL_PORT_2
85
+      || (SERIAL_PORT_2) == port
86
+    #endif
87
+    #ifdef LCD_SERIAL_PORT
88
+      || (LCD_SERIAL_PORT) == port
89
+    #endif
90
+  ;
91
+}
92
+
93
+#define DEFINE_HWSERIAL_MARLIN(name, n)   \
94
+  MarlinSerial name(USART##n,             \
95
+            BOARD_USART##n##_TX_PIN,      \
96
+            BOARD_USART##n##_RX_PIN,      \
97
+            serial_handles_emergency(n)); \
98
+  extern "C" void __irq_usart##n(void) {  \
99
+    my_usart_irq(USART##n->rb, USART##n->wb, USART##n##_BASE, MSerial##n); \
100
+  }
101
+
102
+#define DEFINE_HWSERIAL_UART_MARLIN(name, n) \
103
+  MarlinSerial name(UART##n,                 \
104
+          BOARD_USART##n##_TX_PIN,           \
105
+          BOARD_USART##n##_RX_PIN,           \
106
+          serial_handles_emergency(n));      \
107
+  extern "C" void __irq_usart##n(void) {     \
108
+    my_usart_irq(UART##n->rb, UART##n->wb, UART##n##_BASE, MSerial##n); \
109
+  }
110
+
111
+// Instantiate all UARTs even if they are not needed
112
+// This avoids a bunch of logic to figure out every serial
113
+// port which may be in use on the system.
114
+DEFINE_HWSERIAL_MARLIN(MSerial1, 1);
115
+DEFINE_HWSERIAL_MARLIN(MSerial2, 2);
116
+DEFINE_HWSERIAL_MARLIN(MSerial3, 3);
117
+#if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY)
118
+  DEFINE_HWSERIAL_UART_MARLIN(MSerial4, 4);
119
+  DEFINE_HWSERIAL_UART_MARLIN(MSerial5, 5);
120
+#endif
121
+
122
+// Check the type of each serial port by passing it to a template function.
123
+// HardwareSerial is known to sometimes hang the controller when an error occurs,
124
+// so this case will fail the static assert. All other classes are assumed to be ok.
125
+template <typename T>
126
+constexpr bool IsSerialClassAllowed(const T&) { return true; }
127
+constexpr bool IsSerialClassAllowed(const HardwareSerial&) { return false; }
128
+
129
+#define CHECK_CFG_SERIAL(A) static_assert(IsSerialClassAllowed(A), STRINGIFY(A) " is defined incorrectly");
130
+#define CHECK_AXIS_SERIAL(A) static_assert(IsSerialClassAllowed(A##_HARDWARE_SERIAL), STRINGIFY(A) "_HARDWARE_SERIAL must be defined in the form MSerial1, rather than Serial1");
131
+
132
+// If you encounter this error, replace SerialX with MSerialX, for example MSerial3.
133
+
134
+// Non-TMC ports were already validated in HAL.h, so do not require verbose error messages.
135
+#ifdef MYSERIAL0
136
+  CHECK_CFG_SERIAL(MYSERIAL0);
137
+#endif
138
+#ifdef MYSERIAL1
139
+  CHECK_CFG_SERIAL(MYSERIAL1);
140
+#endif
141
+#ifdef LCD_SERIAL
142
+  CHECK_CFG_SERIAL(LCD_SERIAL);
143
+#endif
144
+#if AXIS_HAS_HW_SERIAL(X)
145
+  CHECK_AXIS_SERIAL(X);
146
+#endif
147
+#if AXIS_HAS_HW_SERIAL(X2)
148
+  CHECK_AXIS_SERIAL(X2);
149
+#endif
150
+#if AXIS_HAS_HW_SERIAL(Y)
151
+  CHECK_AXIS_SERIAL(Y);
152
+#endif
153
+#if AXIS_HAS_HW_SERIAL(Y2)
154
+  CHECK_AXIS_SERIAL(Y2);
155
+#endif
156
+#if AXIS_HAS_HW_SERIAL(Z)
157
+  CHECK_AXIS_SERIAL(Z);
158
+#endif
159
+#if AXIS_HAS_HW_SERIAL(Z2)
160
+  CHECK_AXIS_SERIAL(Z2);
161
+#endif
162
+#if AXIS_HAS_HW_SERIAL(Z3)
163
+  CHECK_AXIS_SERIAL(Z3);
164
+#endif
165
+#if AXIS_HAS_HW_SERIAL(Z4)
166
+  CHECK_AXIS_SERIAL(Z4);
167
+#endif
168
+#if AXIS_HAS_HW_SERIAL(E0)
169
+  CHECK_AXIS_SERIAL(E0);
170
+#endif
171
+#if AXIS_HAS_HW_SERIAL(E1)
172
+  CHECK_AXIS_SERIAL(E1);
173
+#endif
174
+#if AXIS_HAS_HW_SERIAL(E2)
175
+  CHECK_AXIS_SERIAL(E2);
176
+#endif
177
+#if AXIS_HAS_HW_SERIAL(E3)
178
+  CHECK_AXIS_SERIAL(E3);
179
+#endif
180
+#if AXIS_HAS_HW_SERIAL(E4)
181
+  CHECK_AXIS_SERIAL(E4);
182
+#endif
183
+#if AXIS_HAS_HW_SERIAL(E5)
184
+  CHECK_AXIS_SERIAL(E5);
185
+#endif
186
+#if AXIS_HAS_HW_SERIAL(E6)
187
+  CHECK_AXIS_SERIAL(E6);
188
+#endif
189
+#if AXIS_HAS_HW_SERIAL(E7)
190
+  CHECK_AXIS_SERIAL(E7);
191
+#endif
192
+
193
+#endif // __STM32F1__

+ 71
- 0
Marlin/src/HAL/STM32F1/MarlinSerial.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include <HardwareSerial.h>
25
+#include <libmaple/usart.h>
26
+#include <WString.h>
27
+
28
+#include "../../inc/MarlinConfigPre.h"
29
+#if ENABLED(EMERGENCY_PARSER)
30
+  #include "../../feature/e_parser.h"
31
+#endif
32
+
33
+// Increase priority of serial interrupts, to reduce overflow errors
34
+#define UART_IRQ_PRIO 1
35
+
36
+class MarlinSerial : public HardwareSerial {
37
+public:
38
+  #if ENABLED(EMERGENCY_PARSER)
39
+    const bool ep_enabled;
40
+    EmergencyParser::State emergency_state;
41
+    inline bool emergency_parser_enabled() { return ep_enabled; }
42
+  #endif
43
+
44
+  MarlinSerial(struct usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin, bool TERN_(EMERGENCY_PARSER, ep_capable)) :
45
+    HardwareSerial(usart_device, tx_pin, rx_pin)
46
+    #if ENABLED(EMERGENCY_PARSER)
47
+      , ep_enabled(ep_capable)
48
+      , emergency_state(EmergencyParser::State::EP_RESET)
49
+    #endif
50
+    { }
51
+
52
+  #ifdef UART_IRQ_PRIO
53
+    // Shadow the parent methods to set IRQ priority after begin()
54
+    void begin(uint32 baud) {
55
+      MarlinSerial::begin(baud, SERIAL_8N1);
56
+    }
57
+
58
+    void begin(uint32 baud, uint8_t config) {
59
+      HardwareSerial::begin(baud, config);
60
+      nvic_irq_set_priority(c_dev()->irq_num, UART_IRQ_PRIO);
61
+    }
62
+  #endif
63
+};
64
+
65
+extern MarlinSerial MSerial1;
66
+extern MarlinSerial MSerial2;
67
+extern MarlinSerial MSerial3;
68
+#if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY)
69
+  extern MarlinSerial MSerial4;
70
+  extern MarlinSerial MSerial5;
71
+#endif

+ 4
- 1
Marlin/src/HAL/STM32F1/SPI.cpp View File

40
 #include <boards.h>
40
 #include <boards.h>
41
 #include <wirish.h>
41
 #include <wirish.h>
42
 
42
 
43
+#include "../../inc/MarlinConfig.h"
44
+#include "spi_pins.h"
45
+
43
 /** Time in ms for DMA receive timeout */
46
 /** Time in ms for DMA receive timeout */
44
 #define DMA_TIMEOUT 100
47
 #define DMA_TIMEOUT 100
45
 
48
 
710
   return baud_rates[i];
713
   return baud_rates[i];
711
 }
714
 }
712
 
715
 
713
-SPIClass SPI(1);
716
+SPIClass SPI(SPI_DEVICE);
714
 
717
 
715
 #endif // __STM32F1__
718
 #endif // __STM32F1__

+ 1
- 1
Marlin/src/HAL/STM32F1/SoftwareSerial.cpp View File

57
   listening = false;
57
   listening = false;
58
 }
58
 }
59
 
59
 
60
-#endif //__STM32F1__
60
+#endif // __STM32F1__

+ 2
- 2
Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp View File

20
 
20
 
21
 #include "../../../inc/MarlinConfig.h"
21
 #include "../../../inc/MarlinConfig.h"
22
 
22
 
23
-#if BOTH(HAS_GRAPHICAL_LCD, FORCE_SOFT_SPI)
23
+#if BOTH(HAS_MARLINUI_U8GLIB, FORCE_SOFT_SPI)
24
 
24
 
25
 #include "../HAL.h"
25
 #include "../HAL.h"
26
 #include <U8glib.h>
26
 #include <U8glib.h>
161
   return 1;
161
   return 1;
162
 }
162
 }
163
 
163
 
164
-#endif // HAS_GRAPHICAL_LCD
164
+#endif // HAS_MARLINUI_U8GLIB
165
 #endif // STM32F1
165
 #endif // STM32F1

+ 0
- 4
Marlin/src/HAL/STM32F1/inc/SanityCheck.h View File

25
  * Test STM32F1-specific configuration values for errors at compile-time.
25
  * Test STM32F1-specific configuration values for errors at compile-time.
26
  */
26
  */
27
 
27
 
28
-#if ENABLED(EMERGENCY_PARSER)
29
-  #error "EMERGENCY_PARSER is not yet implemented for STM32F1. Disable EMERGENCY_PARSER to continue."
30
-#endif
31
-
32
 #if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_FREQUENCY
28
 #if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_FREQUENCY
33
   #error "Features requiring Hardware PWM (FAST_PWM_FAN, SPINDLE_LASER_FREQUENCY) are not yet supported on STM32F1."
29
   #error "Features requiring Hardware PWM (FAST_PWM_FAN, SPINDLE_LASER_FREQUENCY) are not yet supported on STM32F1."
34
 #endif
30
 #endif

+ 17
- 1
Marlin/src/HAL/STM32F1/msc_sd.cpp View File

21
 #define PRODUCT_ID 0x29
21
 #define PRODUCT_ID 0x29
22
 
22
 
23
 USBMassStorage MarlinMSC;
23
 USBMassStorage MarlinMSC;
24
-USBCompositeSerial MarlinCompositeSerial;
24
+MarlinUSBCompositeSerial MarlinCompositeSerial;
25
 
25
 
26
 #include "../../inc/MarlinConfig.h"
26
 #include "../../inc/MarlinConfig.h"
27
 
27
 
38
 
38
 
39
 #endif
39
 #endif
40
 
40
 
41
+#if ENABLED(EMERGENCY_PARSER)
42
+  void (*real_rx_callback)(void);
43
+
44
+  void my_rx_callback(void) {
45
+    real_rx_callback();
46
+    int len = MarlinCompositeSerial.available();
47
+    while (len-- > 0) // >0 because available() may return a negative value
48
+      emergency_parser.update(MarlinCompositeSerial.emergency_state, MarlinCompositeSerial.peek());
49
+  }
50
+#endif
51
+
41
 void MSC_SD_init() {
52
 void MSC_SD_init() {
42
   USBComposite.setProductId(PRODUCT_ID);
53
   USBComposite.setProductId(PRODUCT_ID);
43
   // Just set MarlinCompositeSerial enabled to true
54
   // Just set MarlinCompositeSerial enabled to true
59
   // Register composite Serial
70
   // Register composite Serial
60
   MarlinCompositeSerial.registerComponent();
71
   MarlinCompositeSerial.registerComponent();
61
   USBComposite.begin();
72
   USBComposite.begin();
73
+  #if ENABLED(EMERGENCY_PARSER)
74
+    //rx is usbSerialPart.endpoints[2]
75
+    real_rx_callback = usbSerialPart.endpoints[2].callback;
76
+    usbSerialPart.endpoints[2].callback = my_rx_callback;
77
+  #endif
62
 }
78
 }
63
 
79
 
64
 #endif // USE_USB_COMPOSITE
80
 #endif // USE_USB_COMPOSITE

+ 20
- 1
Marlin/src/HAL/STM32F1/msc_sd.h View File

17
 
17
 
18
 #include <USBComposite.h>
18
 #include <USBComposite.h>
19
 
19
 
20
+#include "../../inc/MarlinConfigPre.h"
21
+#if ENABLED(EMERGENCY_PARSER)
22
+  #include "../../feature/e_parser.h"
23
+#endif
24
+
25
+class MarlinUSBCompositeSerial : public USBCompositeSerial {
26
+public:
27
+  MarlinUSBCompositeSerial() : USBCompositeSerial()
28
+    #if ENABLED(EMERGENCY_PARSER)
29
+      , emergency_state(EmergencyParser::State::EP_RESET)
30
+    #endif
31
+    { }
32
+
33
+  #if ENABLED(EMERGENCY_PARSER)
34
+    EmergencyParser::State emergency_state;
35
+    inline bool emergency_parser_enabled() { return true; }
36
+  #endif
37
+};
38
+
20
 extern USBMassStorage MarlinMSC;
39
 extern USBMassStorage MarlinMSC;
21
-extern USBCompositeSerial MarlinCompositeSerial;
40
+extern MarlinUSBCompositeSerial MarlinCompositeSerial;
22
 
41
 
23
 void MSC_SD_init();
42
 void MSC_SD_init();

+ 8
- 9
Marlin/src/HAL/STM32F1/onboard_sd.cpp View File

9
  * No restriction on use. You can use, modify and redistribute it for
9
  * No restriction on use. You can use, modify and redistribute it for
10
  * personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
10
  * personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
11
  * Redistributions of source code must retain the above copyright notice.
11
  * Redistributions of source code must retain the above copyright notice.
12
- *
13
  */
12
  */
14
 
13
 
15
 #include "../../inc/MarlinConfig.h"
14
 #include "../../inc/MarlinConfig.h"
21
 #include "fastio.h"
20
 #include "fastio.h"
22
 
21
 
23
 #if HAS_SHARED_MEDIA
22
 #if HAS_SHARED_MEDIA
24
-  #ifndef ON_BOARD_SPI_DEVICE
25
-    #define ON_BOARD_SPI_DEVICE SPI_DEVICE
23
+  #ifndef ONBOARD_SPI_DEVICE
24
+    #define ONBOARD_SPI_DEVICE SPI_DEVICE
26
   #endif
25
   #endif
27
   #define ONBOARD_SD_SPI SPI
26
   #define ONBOARD_SD_SPI SPI
28
 #else
27
 #else
29
-  SPIClass OnBoardSPI(ON_BOARD_SPI_DEVICE);
30
-  #define ONBOARD_SD_SPI OnBoardSPI
28
+  SPIClass OnboardSPI(ONBOARD_SPI_DEVICE);
29
+  #define ONBOARD_SD_SPI OnboardSPI
31
 #endif
30
 #endif
32
 
31
 
33
-#if ON_BOARD_SPI_DEVICE == 1
32
+#if ONBOARD_SPI_DEVICE == 1
34
   #define SPI_CLOCK_MAX SPI_BAUD_PCLK_DIV_4
33
   #define SPI_CLOCK_MAX SPI_BAUD_PCLK_DIV_4
35
 #else
34
 #else
36
   #define SPI_CLOCK_MAX SPI_BAUD_PCLK_DIV_2
35
   #define SPI_CLOCK_MAX SPI_BAUD_PCLK_DIV_2
37
 #endif
36
 #endif
38
 
37
 
39
-#define CS_LOW()  WRITE(ONBOARD_SD_CS_PIN, LOW)  /* Set OnBoardSPI cs low */
40
-#define CS_HIGH() WRITE(ONBOARD_SD_CS_PIN, HIGH) /* Set OnBoardSPI cs high */
38
+#define CS_LOW()  WRITE(ONBOARD_SD_CS_PIN, LOW)  /* Set OnboardSPI cs low */
39
+#define CS_HIGH() WRITE(ONBOARD_SD_CS_PIN, HIGH) /* Set OnboardSPI cs high */
41
 
40
 
42
 #define FCLK_FAST() ONBOARD_SD_SPI.setClockDivider(SPI_CLOCK_MAX)
41
 #define FCLK_FAST() ONBOARD_SD_SPI.setClockDivider(SPI_CLOCK_MAX)
43
 #define FCLK_SLOW() ONBOARD_SD_SPI.setClockDivider(SPI_BAUD_PCLK_DIV_256)
42
 #define FCLK_SLOW() ONBOARD_SD_SPI.setClockDivider(SPI_BAUD_PCLK_DIV_256)
152
 /*-----------------------------------------------------------------------*/
151
 /*-----------------------------------------------------------------------*/
153
 
152
 
154
 static void power_on() {  /* Enable SSP module and attach it to I/O pads */
153
 static void power_on() {  /* Enable SSP module and attach it to I/O pads */
155
-  ONBOARD_SD_SPI.setModule(ON_BOARD_SPI_DEVICE);
154
+  ONBOARD_SD_SPI.setModule(ONBOARD_SPI_DEVICE);
156
   ONBOARD_SD_SPI.begin();
155
   ONBOARD_SD_SPI.begin();
157
   ONBOARD_SD_SPI.setBitOrder(MSBFIRST);
156
   ONBOARD_SD_SPI.setBitOrder(MSBFIRST);
158
   ONBOARD_SD_SPI.setDataMode(SPI_MODE0);
157
   ONBOARD_SD_SPI.setDataMode(SPI_MODE0);

+ 2
- 2
Marlin/src/HAL/STM32F1/sdio.cpp View File

26
 
26
 
27
 #include "../../inc/MarlinConfig.h" // Allow pins/pins.h to set density
27
 #include "../../inc/MarlinConfig.h" // Allow pins/pins.h to set density
28
 
28
 
29
-#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY)
29
+#if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY)
30
 
30
 
31
 #include "sdio.h"
31
 #include "sdio.h"
32
 
32
 
108
     SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS);
108
     SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS);
109
     dma_disable(SDIO_DMA_DEV, SDIO_DMA_CHANNEL);
109
     dma_disable(SDIO_DMA_DEV, SDIO_DMA_CHANNEL);
110
     return false;
110
     return false;
111
-	}
111
+  }
112
 
112
 
113
   //Wait for DMA transaction to complete
113
   //Wait for DMA transaction to complete
114
   while ((DMA2_BASE->ISR & (DMA_ISR_TEIF4|DMA_ISR_TCIF4)) == 0 ) { /* wait */ }
114
   while ((DMA2_BASE->ISR & (DMA_ISR_TEIF4|DMA_ISR_TCIF4)) == 0 ) { /* wait */ }

+ 12
- 0
Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp View File

89
   uint8_t cs = FSMC_CS_PIN, rs = FSMC_RS_PIN;
89
   uint8_t cs = FSMC_CS_PIN, rs = FSMC_RS_PIN;
90
   uint32_t controllerAddress;
90
   uint32_t controllerAddress;
91
 
91
 
92
+  #if PIN_EXISTS(TFT_BACKLIGHT)
93
+    OUT_WRITE(TFT_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT));
94
+  #endif
95
+
96
+  #if ENABLED(LCD_USE_DMA_FSMC)
97
+    dma_init(FSMC_DMA_DEV);
98
+    dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
99
+    dma_set_priority(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, DMA_PRIORITY_MEDIUM);
100
+  #endif
101
+
92
   #if PIN_EXISTS(TFT_RESET)
102
   #if PIN_EXISTS(TFT_RESET)
93
     OUT_WRITE(TFT_RESET_PIN, HIGH);
103
     OUT_WRITE(TFT_RESET_PIN, HIGH);
94
     delay(100);
104
     delay(100);
201
     id = ReadID(LCD_READ_ID);
211
     id = ReadID(LCD_READ_ID);
202
   if ((id & 0xFFFF) == 0 || (id & 0xFFFF) == 0xFFFF)
212
   if ((id & 0xFFFF) == 0 || (id & 0xFFFF) == 0xFFFF)
203
     id = ReadID(LCD_READ_ID4);
213
     id = ReadID(LCD_READ_ID4);
214
+  if ((id & 0xFF00) == 0 && (id & 0xFF) != 0)
215
+    id = ReadID(LCD_READ_ID4);
204
   return id;
216
   return id;
205
 }
217
 }
206
 
218
 

+ 16
- 57
Marlin/src/HAL/STM32_F4_F7/HAL.h View File

46
 // Serial override
46
 // Serial override
47
 //extern HalSerial usb_serial;
47
 //extern HalSerial usb_serial;
48
 
48
 
49
+#define _MSERIAL(X) SerialUART##X
50
+#define MSERIAL(X) _MSERIAL(X)
51
+#define SerialUART0 Serial1
52
+
49
 #if defined(STM32F4) && SERIAL_PORT == 0
53
 #if defined(STM32F4) && SERIAL_PORT == 0
50
   #error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
54
   #error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
51
 #elif SERIAL_PORT == -1
55
 #elif SERIAL_PORT == -1
52
   #define MYSERIAL0 SerialUSB
56
   #define MYSERIAL0 SerialUSB
53
-#elif SERIAL_PORT == 0
54
-  #define MYSERIAL0 Serial1
55
-#elif SERIAL_PORT == 1
56
-  #define MYSERIAL0 SerialUART1
57
-#elif SERIAL_PORT == 2
58
-  #define MYSERIAL0 SerialUART2
59
-#elif SERIAL_PORT == 3
60
-  #define MYSERIAL0 SerialUART3
61
-#elif SERIAL_PORT == 4
62
-  #define MYSERIAL0 SerialUART4
63
-#elif SERIAL_PORT == 5
64
-  #define MYSERIAL0 SerialUART5
65
-#elif SERIAL_PORT == 6
66
-  #define MYSERIAL0 SerialUART6
57
+#elif WITHIN(SERIAL_PORT, 0, 6)
58
+  #define MYSERIAL0 MSERIAL(SERIAL_PORT)
67
 #else
59
 #else
68
   #error "SERIAL_PORT must be from -1 to 6. Please update your configuration."
60
   #error "SERIAL_PORT must be from -1 to 6. Please update your configuration."
69
 #endif
61
 #endif
71
 #ifdef SERIAL_PORT_2
63
 #ifdef SERIAL_PORT_2
72
   #if defined(STM32F4) && SERIAL_PORT_2 == 0
64
   #if defined(STM32F4) && SERIAL_PORT_2 == 0
73
     #error "SERIAL_PORT_2 cannot be 0. (Port 0 does not exist.) Please update your configuration."
65
     #error "SERIAL_PORT_2 cannot be 0. (Port 0 does not exist.) Please update your configuration."
74
-  #elif SERIAL_PORT_2 == SERIAL_PORT
75
-    #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration."
76
   #elif SERIAL_PORT_2 == -1
66
   #elif SERIAL_PORT_2 == -1
77
     #define MYSERIAL1 SerialUSB
67
     #define MYSERIAL1 SerialUSB
78
-  #elif SERIAL_PORT_2 == 0
79
-    #define MYSERIAL1 Serial1
80
-  #elif SERIAL_PORT_2 == 1
81
-    #define MYSERIAL1 SerialUART1
82
-  #elif SERIAL_PORT_2 == 2
83
-    #define MYSERIAL1 SerialUART2
84
-  #elif SERIAL_PORT_2 == 3
85
-    #define MYSERIAL1 SerialUART3
86
-  #elif SERIAL_PORT_2 == 4
87
-    #define MYSERIAL1 SerialUART4
88
-  #elif SERIAL_PORT_2 == 5
89
-    #define MYSERIAL1 SerialUART5
90
-  #elif SERIAL_PORT_2 == 6
91
-    #define MYSERIAL1 SerialUART6
68
+  #elif WITHIN(SERIAL_PORT_2, 0, 6)
69
+    #define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
92
   #else
70
   #else
93
     #error "SERIAL_PORT_2 must be from -1 to 6. Please update your configuration."
71
     #error "SERIAL_PORT_2 must be from -1 to 6. Please update your configuration."
94
   #endif
72
   #endif
95
-  #define NUM_SERIAL 2
96
-#else
97
-  #define NUM_SERIAL 1
98
 #endif
73
 #endif
99
 
74
 
100
-#ifdef DGUS_SERIAL_PORT
101
-  #if defined(STM32F4) && DGUS_SERIAL_PORT == 0
102
-    #error "DGUS_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
103
-  #elif DGUS_SERIAL_PORT == SERIAL_PORT
104
-    #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration."
105
-  #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2
106
-    #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration."
107
-  #elif DGUS_SERIAL_PORT == -1
108
-    #define DGUS_SERIAL SerialUSB
109
-  #elif DGUS_SERIAL_PORT == 0
110
-    #define DGUS_SERIAL Serial1
111
-  #elif DGUS_SERIAL_PORT == 1
112
-    #define DGUS_SERIAL SerialUART1
113
-  #elif DGUS_SERIAL_PORT == 2
114
-    #define DGUS_SERIAL SerialUART2
115
-  #elif DGUS_SERIAL_PORT == 3
116
-    #define DGUS_SERIAL SerialUART3
117
-  #elif DGUS_SERIAL_PORT == 4
118
-    #define DGUS_SERIAL SerialUART4
119
-  #elif DGUS_SERIAL_PORT == 5
120
-    #define DGUS_SERIAL SerialUART5
121
-  #elif DGUS_SERIAL_PORT == 6
122
-    #define DGUS_SERIAL SerialUART6
75
+#ifdef LCD_SERIAL_PORT
76
+  #if defined(STM32F4) && LCD_SERIAL_PORT == 0
77
+    #error "LCD_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
78
+  #elif LCD_SERIAL_PORT == -1
79
+    #define LCD_SERIAL SerialUSB
80
+  #elif WITHIN(LCD_SERIAL_PORT, 0, 6)
81
+    #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
123
   #else
82
   #else
124
-    #error "DGUS_SERIAL_PORT must be from -1 to 6. Please update your configuration."
83
+    #error "LCD_SERIAL_PORT must be from -1 to 6. Please update your configuration."
125
   #endif
84
   #endif
126
 #endif
85
 #endif
127
 
86
 

+ 1
- 1
Marlin/src/HAL/STM32_F4_F7/HAL_SPI.cpp View File

72
  */
72
  */
73
 void spiBegin() {
73
 void spiBegin() {
74
   #if !defined(SS_PIN) || SS_PIN < 0
74
   #if !defined(SS_PIN) || SS_PIN < 0
75
-    #error SS_PIN not defined!
75
+    #error "SS_PIN not defined!"
76
   #endif
76
   #endif
77
 
77
 
78
   OUT_WRITE(SS_PIN, HIGH);
78
   OUT_WRITE(SS_PIN, HIGH);

+ 0
- 2
Marlin/src/HAL/STM32_F4_F7/STM32F7/TMC2660.cpp View File

22
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
  * THE SOFTWARE.
24
  * THE SOFTWARE.
25
- *
26
  */
25
  */
27
 
26
 
28
 #if defined(STM32GENERIC) && defined(STM32F7)
27
 #if defined(STM32GENERIC) && defined(STM32F7)
662
 /**
661
 /**
663
  * reads a value from the TMC26X status register. The value is not obtained directly but can then
662
  * reads a value from the TMC26X status register. The value is not obtained directly but can then
664
  * be read by the various status routines.
663
  * be read by the various status routines.
665
- *
666
  */
664
  */
667
 void TMC26XStepper::readStatus(char read_value) {
665
 void TMC26XStepper::readStatus(char read_value) {
668
   uint32_t old_driver_configuration_register_value = driver_configuration_register_value;
666
   uint32_t old_driver_configuration_register_value = driver_configuration_register_value;

+ 0
- 1
Marlin/src/HAL/STM32_F4_F7/STM32F7/TMC2660.h View File

22
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
  * THE SOFTWARE.
24
  * THE SOFTWARE.
25
- *
26
  */
25
  */
27
 #pragma once
26
 #pragma once
28
 
27
 

+ 9
- 11
Marlin/src/HAL/TEENSY31_32/HAL.h View File

44
 //#undef MOTHERBOARD
44
 //#undef MOTHERBOARD
45
 //#define MOTHERBOARD BOARD_TEENSY31_32
45
 //#define MOTHERBOARD BOARD_TEENSY31_32
46
 
46
 
47
-#define IS_32BIT_TEENSY defined(__MK20DX256__)
48
-#define IS_TEENSY32 defined(__MK20DX256__)
47
+#ifdef __MK20DX256__
48
+  #define IS_32BIT_TEENSY 1
49
+  #define IS_TEENSY32 1
50
+#endif
49
 
51
 
50
-#define NUM_SERIAL 1
52
+#define _MSERIAL(X) Serial##X
53
+#define MSERIAL(X) _MSERIAL(X)
54
+#define Serial0 Serial
51
 
55
 
52
 #if SERIAL_PORT == -1
56
 #if SERIAL_PORT == -1
53
   #define MYSERIAL0 SerialUSB
57
   #define MYSERIAL0 SerialUSB
54
-#elif SERIAL_PORT == 0
55
-  #define MYSERIAL0 Serial
56
-#elif SERIAL_PORT == 1
57
-  #define MYSERIAL0 Serial1
58
-#elif SERIAL_PORT == 2
59
-  #define MYSERIAL0 Serial2
60
-#elif SERIAL_PORT == 3
61
-  #define MYSERIAL0 Serial3
58
+#elif WITHIN(SERIAL_PORT, 0, 3)
59
+  #define MYSERIAL0 MSERIAL(SERIAL_PORT)
62
 #endif
60
 #endif
63
 
61
 
64
 #define HAL_SERVO_LIB libServo
62
 #define HAL_SERVO_LIB libServo

+ 13
- 12
Marlin/src/HAL/TEENSY35_36/HAL.h View File

45
 // Defines
45
 // Defines
46
 // ------------------------
46
 // ------------------------
47
 
47
 
48
-#define IS_32BIT_TEENSY (defined(__MK64FX512__) || defined(__MK66FX1M0__))
49
-#define IS_TEENSY35 defined(__MK64FX512__)
50
-#define IS_TEENSY36 defined(__MK66FX1M0__)
48
+#ifdef __MK64FX512__
49
+  #define IS_32BIT_TEENSY 1
50
+  #define IS_TEENSY35 1
51
+#endif
52
+#ifdef __MK66FX1M0__
53
+  #define IS_32BIT_TEENSY 1
54
+  #define IS_TEENSY36 1
55
+#endif
51
 
56
 
52
-#define NUM_SERIAL 1
57
+#define _MSERIAL(X) Serial##X
58
+#define MSERIAL(X) _MSERIAL(X)
59
+#define Serial0 Serial
53
 
60
 
54
 #if SERIAL_PORT == -1
61
 #if SERIAL_PORT == -1
55
   #define MYSERIAL0 SerialUSB
62
   #define MYSERIAL0 SerialUSB
56
-#elif SERIAL_PORT == 0
57
-  #define MYSERIAL0 Serial
58
-#elif SERIAL_PORT == 1
59
-  #define MYSERIAL0 Serial1
60
-#elif SERIAL_PORT == 2
61
-  #define MYSERIAL0 Serial2
62
-#elif SERIAL_PORT == 3
63
-  #define MYSERIAL0 Serial3
63
+#elif WITHIN(SERIAL_PORT, 0, 3)
64
+  #define MYSERIAL0 MSERIAL(SERIAL_PORT)
64
 #endif
65
 #endif
65
 
66
 
66
 #define HAL_SERVO_LIB libServo
67
 #define HAL_SERVO_LIB libServo

+ 1
- 1
Marlin/src/HAL/TEENSY35_36/HAL_SPI.cpp View File

31
 
31
 
32
 void spiBegin() {
32
 void spiBegin() {
33
   #if !PIN_EXISTS(SS)
33
   #if !PIN_EXISTS(SS)
34
-    #error SS_PIN not defined!
34
+    #error "SS_PIN not defined!"
35
   #endif
35
   #endif
36
   OUT_WRITE(SS_PIN, HIGH);
36
   OUT_WRITE(SS_PIN, HIGH);
37
   SET_OUTPUT(SCK_PIN);
37
   SET_OUTPUT(SCK_PIN);

+ 1
- 0
Marlin/src/HAL/TEENSY35_36/timers.h View File

16
  *
16
  *
17
  * You should have received a copy of the GNU General Public License
17
  * You should have received a copy of the GNU General Public License
18
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
+ *
19
  */
20
  */
20
 #pragma once
21
 #pragma once
21
 
22
 

+ 167
- 0
Marlin/src/HAL/TEENSY40_41/HAL.cpp View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * Description: HAL for Teensy40 (IMXRT1062)
25
+ */
26
+
27
+#ifdef __IMXRT1062__
28
+
29
+#include "HAL.h"
30
+#include "../shared/Delay.h"
31
+#include "timers.h"
32
+
33
+#include <Wire.h>
34
+
35
+uint16_t HAL_adc_result, HAL_adc_select;
36
+
37
+static const uint8_t pin2sc1a[] = {
38
+  0x07,  // 0/A0  AD_B1_02
39
+  0x08,  // 1/A1  AD_B1_03
40
+  0x0C,  // 2/A2  AD_B1_07
41
+  0x0B,  // 3/A3  AD_B1_06
42
+  0x06,  // 4/A4  AD_B1_01
43
+  0x05,  // 5/A5  AD_B1_00
44
+  0x0F,  // 6/A6  AD_B1_10
45
+  0x00,  // 7/A7  AD_B1_11
46
+  0x0D,  // 8/A8  AD_B1_08
47
+  0x0E,  // 9/A9  AD_B1_09
48
+  0x01,  // 24/A10 AD_B0_12
49
+  0x02,  // 25/A11 AD_B0_13
50
+  0x83,  // 26/A12 AD_B1_14 - only on ADC2, 3
51
+  0x84,  // 27/A13 AD_B1_15 - only on ADC2, 4
52
+  0x07,  // 14/A0  AD_B1_02
53
+  0x08,  // 15/A1  AD_B1_03
54
+  0x0C,  // 16/A2  AD_B1_07
55
+  0x0B,  // 17/A3  AD_B1_06
56
+  0x06,  // 18/A4  AD_B1_01
57
+  0x05,  // 19/A5  AD_B1_00
58
+  0x0F,  // 20/A6  AD_B1_10
59
+  0x00,  // 21/A7  AD_B1_11
60
+  0x0D,  // 22/A8  AD_B1_08
61
+  0x0E,  // 23/A9  AD_B1_09
62
+  0x01,  // 24/A10 AD_B0_12
63
+  0x02,  // 25/A11 AD_B0_13
64
+  0x83,  // 26/A12 AD_B1_14 - only on ADC2, 3
65
+  0x84,  // 27/A13 AD_B1_15 - only on ADC2, 4
66
+  #ifdef ARDUINO_TEENSY41
67
+    0xFF,  // 28
68
+    0xFF,  // 29
69
+    0xFF,  // 30
70
+    0xFF,  // 31
71
+    0xFF,  // 32
72
+    0xFF,  // 33
73
+    0xFF,  // 34
74
+    0xFF,  // 35
75
+    0xFF,  // 36
76
+    0xFF,  // 37
77
+    0x81,  // 38/A14 AD_B1_12 - only on ADC2, 1
78
+    0x82,  // 39/A15 AD_B1_13 - only on ADC2, 2
79
+    0x09,  // 40/A16 AD_B1_04
80
+    0x0A,  // 41/A17 AD_B1_05
81
+  #endif
82
+};
83
+
84
+/*
85
+// disable interrupts
86
+void cli() { noInterrupts(); }
87
+
88
+// enable interrupts
89
+void sei() { interrupts(); }
90
+*/
91
+
92
+void HAL_adc_init() {
93
+  analog_init();
94
+  while (ADC1_GC & ADC_GC_CAL) ;
95
+  while (ADC2_GC & ADC_GC_CAL) ;
96
+}
97
+
98
+void HAL_clear_reset_source() {
99
+  uint32_t reset_source = SRC_SRSR;
100
+  SRC_SRSR = reset_source;
101
+ }
102
+
103
+uint8_t HAL_get_reset_source() {
104
+  switch (SRC_SRSR & 0xFF) {
105
+    case 1: return RST_POWER_ON; break;
106
+    case 2: return RST_SOFTWARE; break;
107
+    case 4: return RST_EXTERNAL; break;
108
+    // case 8: return RST_BROWN_OUT; break;
109
+    case 16: return RST_WATCHDOG; break;
110
+     case 64: return RST_JTAG; break;
111
+    // case 128: return RST_OVERTEMP; break;
112
+  }
113
+  return 0;
114
+}
115
+
116
+#define __bss_end _ebss
117
+
118
+extern "C" {
119
+  extern char __bss_end;
120
+  extern char __heap_start;
121
+  extern void* __brkval;
122
+
123
+  // Doesn't work on Teensy 4.x
124
+  uint32_t freeMemory() {
125
+    uint32_t free_memory;
126
+    if ((uint32_t)__brkval == 0)
127
+      free_memory = ((uint32_t)&free_memory) - ((uint32_t)&__bss_end);
128
+    else
129
+      free_memory = ((uint32_t)&free_memory) - ((uint32_t)__brkval);
130
+    return free_memory;
131
+  }
132
+}
133
+
134
+void HAL_adc_start_conversion(const uint8_t adc_pin) {
135
+  const uint16_t pin = pin2sc1a[adc_pin];
136
+  if (pin == 0xFF) {
137
+    HAL_adc_select = -1; // Digital only
138
+  }
139
+  else if (pin & 0x80) {
140
+    HAL_adc_select = 1;
141
+    ADC2_HC0 = pin & 0x7F;
142
+  }
143
+  else {
144
+    HAL_adc_select = 0;
145
+    ADC1_HC0 = pin;
146
+  }
147
+}
148
+
149
+uint16_t HAL_adc_get_result() {
150
+  switch (HAL_adc_select) {
151
+    case 0:
152
+      while (!(ADC1_HS & ADC_HS_COCO0)) ; // wait
153
+      return ADC1_R0;
154
+    case 1:
155
+      while (!(ADC2_HS & ADC_HS_COCO0)) ; // wait
156
+      return ADC2_R0;
157
+  }
158
+  return 0;
159
+}
160
+
161
+bool is_output(uint8_t pin) {
162
+  const struct digital_pin_bitband_and_config_table_struct *p;
163
+  p = digital_pin_to_info_PGM + pin;
164
+  return (*(p->reg + 1) & p->mask);
165
+}
166
+
167
+#endif // __IMXRT1062__

+ 147
- 0
Marlin/src/HAL/TEENSY40_41/HAL.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ *
4
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
6
+ * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+/**
25
+ * Description: HAL for Teensy 4.0 and Teensy 4.1
26
+ */
27
+
28
+#define CPU_32_BIT
29
+
30
+#include "../shared/Marduino.h"
31
+#include "../shared/math_32bit.h"
32
+#include "../shared/HAL_SPI.h"
33
+
34
+#include "fastio.h"
35
+#include "watchdog.h"
36
+
37
+#include <stdint.h>
38
+#include <util/atomic.h>
39
+
40
+//#define ST7920_DELAY_1 DELAY_NS(600)
41
+//#define ST7920_DELAY_2 DELAY_NS(750)
42
+//#define ST7920_DELAY_3 DELAY_NS(750)
43
+
44
+// ------------------------
45
+// Defines
46
+// ------------------------
47
+
48
+#ifdef __IMXRT1062__
49
+  #define IS_32BIT_TEENSY 1
50
+  #define IS_TEENSY41 1
51
+#endif
52
+
53
+#define _MSERIAL(X) Serial##X
54
+#define MSERIAL(X) _MSERIAL(X)
55
+#define Serial0 Serial
56
+
57
+#if SERIAL_PORT == -1
58
+  #define MYSERIAL0 SerialUSB
59
+#elif WITHIN(SERIAL_PORT, 0, 8)
60
+  #define MYSERIAL0 MSERIAL(SERIAL_PORT)
61
+#else
62
+  #error "The required SERIAL_PORT must be from -1 to 8. Please update your configuration."
63
+#endif
64
+
65
+#ifdef SERIAL_PORT_2
66
+  #if SERIAL_PORT_2 == -1
67
+    #define MYSERIAL1 usbSerial
68
+  #elif WITHIN(SERIAL_PORT_2, 0, 8)
69
+    #define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
70
+  #else
71
+      #error "SERIAL_PORT_2 must be from -1 to 8. Please update your configuration."
72
+  #endif
73
+#endif
74
+
75
+#define HAL_SERVO_LIB libServo
76
+
77
+typedef int8_t pin_t;
78
+
79
+#ifndef analogInputToDigitalPin
80
+  #define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
81
+#endif
82
+
83
+#define CRITICAL_SECTION_START()  uint32_t primask = __get_primask(); __disable_irq()
84
+#define CRITICAL_SECTION_END()    if (!primask) __enable_irq()
85
+#define ISRS_ENABLED() (!__get_primask())
86
+#define ENABLE_ISRS()  __enable_irq()
87
+#define DISABLE_ISRS() __disable_irq()
88
+
89
+#undef sq
90
+#define sq(x) ((x)*(x))
91
+
92
+#ifndef strncpy_P
93
+  #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
94
+#endif
95
+
96
+// Don't place string constants in PROGMEM
97
+#undef PSTR
98
+#define PSTR(str) ({static const char *data = (str); &data[0];})
99
+
100
+// Fix bug in pgm_read_ptr
101
+#undef pgm_read_ptr
102
+#define pgm_read_ptr(addr) (*((void**)(addr)))
103
+// Add type-checking to pgm_read_word
104
+#undef pgm_read_word
105
+#define pgm_read_word(addr) (*((uint16_t*)(addr)))
106
+
107
+// Enable hooks into idle and setup for HAL
108
+#define HAL_IDLETASK 1
109
+FORCE_INLINE void HAL_idletask() {}
110
+FORCE_INLINE void HAL_init() {}
111
+
112
+// Clear reset reason
113
+void HAL_clear_reset_source();
114
+
115
+// Reset reason
116
+uint8_t HAL_get_reset_source();
117
+
118
+FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
119
+
120
+#pragma GCC diagnostic push
121
+#pragma GCC diagnostic ignored "-Wunused-function"
122
+extern "C" {
123
+  uint32_t freeMemory();
124
+}
125
+#pragma GCC diagnostic pop
126
+
127
+// ADC
128
+
129
+void HAL_adc_init();
130
+
131
+#define HAL_ADC_VREF         3.3
132
+#define HAL_ADC_RESOLUTION  10
133
+#define HAL_ADC_FILTERED      // turn off ADC oversampling
134
+#define HAL_START_ADC(pin)  HAL_adc_start_conversion(pin)
135
+#define HAL_READ_ADC()      HAL_adc_get_result()
136
+#define HAL_ADC_READY()     true
137
+
138
+#define HAL_ANALOG_SELECT(pin)
139
+
140
+void HAL_adc_start_conversion(const uint8_t adc_pin);
141
+uint16_t HAL_adc_get_result();
142
+
143
+#define GET_PIN_MAP_PIN(index) index
144
+#define GET_PIN_MAP_INDEX(pin) pin
145
+#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
146
+
147
+bool is_output(uint8_t pin);

+ 138
- 0
Marlin/src/HAL/TEENSY40_41/HAL_SPI.cpp View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#ifdef __IMXRT1062__
23
+
24
+#include "HAL.h"
25
+#include <SPI.h>
26
+#include <pins_arduino.h>
27
+#include "spi_pins.h"
28
+#include "../../core/macros.h"
29
+
30
+static SPISettings spiConfig;
31
+
32
+// ------------------------
33
+// Public functions
34
+// ------------------------
35
+
36
+#if ENABLED(SOFTWARE_SPI)
37
+  // ------------------------
38
+  // Software SPI
39
+  // ------------------------
40
+  #error "Software SPI not supported for Teensy 4. Use Hardware SPI."
41
+#else
42
+
43
+// ------------------------
44
+// Hardware SPI
45
+// ------------------------
46
+
47
+void spiBegin() {
48
+  #ifndef SS_PIN
49
+    #error "SS_PIN is not defined!"
50
+  #endif
51
+
52
+  OUT_WRITE(SS_PIN, HIGH);
53
+
54
+  //SET_OUTPUT(SCK_PIN);
55
+  //SET_INPUT(MISO_PIN);
56
+  //SET_OUTPUT(MOSI_PIN);
57
+
58
+  #if 0 && DISABLED(SOFTWARE_SPI)
59
+    // set SS high - may be chip select for another SPI device
60
+    #if SET_SPI_SS_HIGH
61
+      WRITE(SS_PIN, HIGH);
62
+    #endif
63
+    // set a default rate
64
+    spiInit(SPI_HALF_SPEED); // 1
65
+  #endif
66
+}
67
+
68
+void spiInit(uint8_t spiRate) {
69
+  // Use Marlin data-rates
70
+  uint32_t clock;
71
+  switch (spiRate) {
72
+  case SPI_FULL_SPEED:    clock = 10000000; break;
73
+  case SPI_HALF_SPEED:    clock =  5000000; break;
74
+  case SPI_QUARTER_SPEED: clock =  2500000; break;
75
+  case SPI_EIGHTH_SPEED:  clock =  1250000; break;
76
+  case SPI_SPEED_5:       clock =   625000; break;
77
+  case SPI_SPEED_6:       clock =   312500; break;
78
+  default:
79
+    clock = 4000000; // Default from the SPI libarary
80
+  }
81
+  spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
82
+  SPI.begin();
83
+}
84
+
85
+uint8_t spiRec() {
86
+  SPI.beginTransaction(spiConfig);
87
+  uint8_t returnByte = SPI.transfer(0xFF);
88
+  SPI.endTransaction();
89
+  return returnByte;
90
+  //SPDR = 0xFF;
91
+  //while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
92
+  //return SPDR;
93
+}
94
+
95
+void spiRead(uint8_t* buf, uint16_t nbyte) {
96
+  SPI.beginTransaction(spiConfig);
97
+  SPI.transfer(buf, nbyte);
98
+  SPI.endTransaction();
99
+  //if (nbyte-- == 0) return;
100
+  //  SPDR = 0xFF;
101
+  //for (uint16_t i = 0; i < nbyte; i++) {
102
+  //  while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
103
+  //  buf[i] = SPDR;
104
+  //  SPDR = 0xFF;
105
+  //}
106
+  //while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
107
+  //buf[nbyte] = SPDR;
108
+}
109
+
110
+void spiSend(uint8_t b) {
111
+  SPI.beginTransaction(spiConfig);
112
+  SPI.transfer(b);
113
+  SPI.endTransaction();
114
+  //SPDR = b;
115
+  //while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
116
+}
117
+
118
+void spiSendBlock(uint8_t token, const uint8_t* buf) {
119
+  SPI.beginTransaction(spiConfig);
120
+  SPDR = token;
121
+  for (uint16_t i = 0; i < 512; i += 2) {
122
+    while (!TEST(SPSR, SPIF)) { /* nada */ };
123
+    SPDR = buf[i];
124
+    while (!TEST(SPSR, SPIF)) { /* nada */ };
125
+    SPDR = buf[i + 1];
126
+  }
127
+  while (!TEST(SPSR, SPIF)) { /* nada */ };
128
+  SPI.endTransaction();
129
+}
130
+
131
+// Begin SPI transaction, set clock, bit order, data mode
132
+void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
133
+  spiConfig = SPISettings(spiClock, bitOrder, dataMode);
134
+  SPI.beginTransaction(spiConfig);
135
+}
136
+
137
+#endif // SOFTWARE_SPI
138
+#endif // __IMXRT1062__

+ 57
- 0
Marlin/src/HAL/TEENSY40_41/Servo.cpp View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#ifdef __IMXRT1062__
23
+
24
+#include "../../inc/MarlinConfig.h"
25
+
26
+#if HAS_SERVOS
27
+
28
+#include "Servo.h"
29
+
30
+int8_t libServo::attach(const int inPin) {
31
+  if (inPin > 0) servoPin = inPin;
32
+  return super::attach(servoPin);
33
+}
34
+
35
+int8_t libServo::attach(const int inPin, const int inMin, const int inMax) {
36
+  if (inPin > 0) servoPin = inPin;
37
+  return super::attach(servoPin, inMin, inMax);
38
+}
39
+
40
+void libServo::move(const int value) {
41
+  constexpr uint16_t servo_delay[] = SERVO_DELAY;
42
+  static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
43
+  if (attach(0) >= 0) {
44
+    write(value);
45
+    safe_delay(servo_delay[servoIndex]);
46
+    TERN_(DEACTIVATE_SERVOS_AFTER_MOVE, detach());
47
+  }
48
+}
49
+
50
+void libServo::detach() {
51
+  // PWMServo library does not have detach() function
52
+  //super::detach();
53
+}
54
+
55
+#endif // HAS_SERVOS
56
+
57
+#endif // __IMXRT1062__

+ 39
- 0
Marlin/src/HAL/TEENSY40_41/Servo.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include <PWMServo.h>
25
+
26
+// Inherit and expand on core Servo library
27
+class libServo : public PWMServo {
28
+  public:
29
+    int8_t attach(const int pin);
30
+    int8_t attach(const int pin, const int min, const int max);
31
+    void move(const int value);
32
+    void detach(void);
33
+  private:
34
+    typedef PWMServo super;
35
+    uint8_t servoPin;
36
+    uint16_t min_ticks;
37
+    uint16_t max_ticks;
38
+    uint8_t servoIndex; // Index into the channel data for this servo
39
+};

+ 77
- 0
Marlin/src/HAL/TEENSY40_41/eeprom.cpp View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ *
4
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
6
+ * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
7
+ * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
8
+ *
9
+ * This program is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
21
+ *
22
+ */
23
+#ifdef __IMXRT1062__
24
+
25
+#include "../../inc/MarlinConfig.h"
26
+
27
+#if USE_WIRED_EEPROM
28
+
29
+/**
30
+ * PersistentStore for Arduino-style EEPROM interface
31
+ * with implementations supplied by the framework.
32
+ */
33
+
34
+#include "../shared/eeprom_api.h"
35
+#include <avr/eeprom.h>
36
+
37
+#ifndef MARLIN_EEPROM_SIZE
38
+  #define MARLIN_EEPROM_SIZE size_t(E2END + 1)
39
+#endif
40
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
41
+
42
+bool PersistentStore::access_start()  { return true; }
43
+bool PersistentStore::access_finish() { return true; }
44
+
45
+bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
46
+  while (size--) {
47
+    uint8_t * const p = (uint8_t * const)pos;
48
+    uint8_t v = *value;
49
+    // EEPROM has only ~100,000 write cycles,
50
+    // so only write bytes that have changed!
51
+    if (v != eeprom_read_byte(p)) {
52
+      eeprom_write_byte(p, v);
53
+      if (eeprom_read_byte(p) != v) {
54
+        SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
55
+        return true;
56
+      }
57
+    }
58
+    crc16(crc, &v, 1);
59
+    pos++;
60
+    value++;
61
+  }
62
+  return false;
63
+}
64
+
65
+bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
66
+  do {
67
+    uint8_t c = eeprom_read_byte((uint8_t*)pos);
68
+    if (writing) *value = c;
69
+    crc16(crc, &c, 1);
70
+    pos++;
71
+    value++;
72
+  } while (--size);
73
+  return false;
74
+}
75
+
76
+#endif // USE_WIRED_EEPROM
77
+#endif // __IMXRT1062__

+ 66
- 0
Marlin/src/HAL/TEENSY40_41/endstop_interrupts.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+/**
25
+ * Endstop Interrupts
26
+ *
27
+ * Without endstop interrupts the endstop pins must be polled continually in
28
+ * the temperature-ISR via endstops.update(), most of the time finding no change.
29
+ * With this feature endstops.update() is called only when we know that at
30
+ * least one endstop has changed state, saving valuable CPU cycles.
31
+ *
32
+ * This feature only works when all used endstop pins can generate an 'external interrupt'.
33
+ *
34
+ * Test whether pins issue interrupts on your board by flashing 'pin_interrupt_test.ino'.
35
+ * (Located in Marlin/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino)
36
+ */
37
+
38
+#include "../../module/endstops.h"
39
+
40
+// One ISR for all EXT-Interrupts
41
+void endstop_ISR() { endstops.update(); }
42
+
43
+/**
44
+ * Endstop interrupts for Due based targets.
45
+ * On Due, all pins support external interrupt capability.
46
+ */
47
+void setup_endstop_interrupts() {
48
+  #define _ATTACH(P) attachInterrupt(digitalPinToInterrupt(P), endstop_ISR, CHANGE)
49
+  TERN_(HAS_X_MAX, _ATTACH(X_MAX_PIN));
50
+  TERN_(HAS_X_MIN, _ATTACH(X_MIN_PIN));
51
+  TERN_(HAS_Y_MAX, _ATTACH(Y_MAX_PIN));
52
+  TERN_(HAS_Y_MIN, _ATTACH(Y_MIN_PIN));
53
+  TERN_(HAS_Z_MAX, _ATTACH(Z_MAX_PIN));
54
+  TERN_(HAS_Z_MIN, _ATTACH(Z_MIN_PIN));
55
+  TERN_(HAS_X2_MAX, _ATTACH(X2_MAX_PIN));
56
+  TERN_(HAS_X2_MIN, _ATTACH(X2_MIN_PIN));
57
+  TERN_(HAS_Y2_MAX, _ATTACH(Y2_MAX_PIN));
58
+  TERN_(HAS_Y2_MIN, _ATTACH(Y2_MIN_PIN));
59
+  TERN_(HAS_Z2_MAX, _ATTACH(Z2_MAX_PIN));
60
+  TERN_(HAS_Z2_MIN, _ATTACH(Z2_MIN_PIN));
61
+  TERN_(HAS_Z3_MAX, _ATTACH(Z3_MAX_PIN));
62
+  TERN_(HAS_Z3_MIN, _ATTACH(Z3_MIN_PIN));
63
+  TERN_(HAS_Z4_MAX, _ATTACH(Z4_MAX_PIN));
64
+  TERN_(HAS_Z4_MIN, _ATTACH(Z4_MIN_PIN));
65
+  TERN_(HAS_Z_MIN_PROBE_PIN, _ATTACH(Z_MIN_PROBE_PIN));
66
+}

+ 58
- 0
Marlin/src/HAL/TEENSY40_41/fastio.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ * Copyright (c) 2017 Victor Perez
8
+ *
9
+ * This program is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
21
+ *
22
+ */
23
+#pragma once
24
+
25
+/**
26
+ * Fast I/O interfaces for Teensy 4
27
+ * These use GPIO functions instead of Direct Port Manipulation, as on AVR.
28
+ */
29
+
30
+#ifndef PWM
31
+  #define PWM OUTPUT
32
+#endif
33
+
34
+#define READ(IO)                digitalRead(IO)
35
+#define WRITE(IO,V)             digitalWrite(IO,V)
36
+
37
+#define _GET_MODE(IO)           !is_output(IO)
38
+#define _SET_MODE(IO,M)         pinMode(IO, M)
39
+#define _SET_OUTPUT(IO)         pinMode(IO, OUTPUT)                               /*!< Output Push Pull Mode & GPIO_NOPULL   */
40
+
41
+#define OUT_WRITE(IO,V)         do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0)
42
+
43
+#define SET_INPUT(IO)           _SET_MODE(IO, INPUT)                              /*!< Input Floating Mode                   */
44
+#define SET_INPUT_PULLUP(IO)    _SET_MODE(IO, INPUT_PULLUP)                       /*!< Input with Pull-up activation         */
45
+#define SET_INPUT_PULLDOWN(IO)  _SET_MODE(IO, INPUT_PULLDOWN)                     /*!< Input with Pull-down activation       */
46
+#define SET_OUTPUT(IO)          OUT_WRITE(IO, LOW)
47
+#define SET_PWM(IO)             _SET_MODE(IO, PWM)
48
+
49
+#define TOGGLE(IO)              OUT_WRITE(IO, !READ(IO))
50
+
51
+#define IS_INPUT(IO)            !is_output(IO)
52
+#define IS_OUTPUT(IO)           is_output(IO)
53
+
54
+#define PWM_PIN(P)            digitalPinHasPWM(P)
55
+
56
+// digitalRead/Write wrappers
57
+#define extDigitalRead(IO)    digitalRead(IO)
58
+#define extDigitalWrite(IO,V) digitalWrite(IO,V)

+ 26
- 0
Marlin/src/HAL/TEENSY40_41/inc/Conditionals_LCD.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#if HAS_SPI_TFT || HAS_FSMC_TFT
25
+  #error "Sorry! TFT displays are not available for HAL/TEENSY40_41."
26
+#endif

+ 22
- 0
Marlin/src/HAL/TEENSY40_41/inc/Conditionals_adv.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once

+ 26
- 0
Marlin/src/HAL/TEENSY40_41/inc/Conditionals_post.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#if USE_FALLBACK_EEPROM
25
+  #define USE_WIRED_EEPROM 1
26
+#endif

+ 38
- 0
Marlin/src/HAL/TEENSY40_41/inc/SanityCheck.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+/**
25
+ * Test TEENSY41 specific configuration values for errors at compile-time.
26
+ */
27
+
28
+#if ENABLED(EMERGENCY_PARSER)
29
+  #error "EMERGENCY_PARSER is not yet implemented for Teensy 4.0/4.1. Disable EMERGENCY_PARSER to continue."
30
+#endif
31
+
32
+#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_FREQUENCY
33
+  #error "Features requiring Hardware PWM (FAST_PWM_FAN, SPINDLE_LASER_FREQUENCY) are not yet supported on Teensy 4.0/4.1."
34
+#endif
35
+
36
+#if HAS_TMC_SW_SERIAL
37
+  #error "TMC220x Software Serial is not supported on this platform."
38
+#endif

+ 146
- 0
Marlin/src/HAL/TEENSY40_41/pinsDebug.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
+ *
18
+ */
19
+#pragma once
20
+
21
+#warning "PINS_DEBUGGING is not fully supported for Teensy 4.0 / 4.1 so 'M43' may cause hangs."
22
+
23
+#define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
24
+
25
+#define digitalRead_mod(p) extDigitalRead(p)  // AVR digitalRead disabled PWM before it read the pin
26
+#define PRINT_PORT(p)
27
+#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
28
+#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%02d"), p); SERIAL_ECHO(buffer); }while(0)
29
+#define GET_ARRAY_PIN(p) pin_array[p].pin
30
+#define GET_ARRAY_IS_DIGITAL(p) pin_array[p].is_digital
31
+#define VALID_PIN(pin) (pin >= 0 && pin < (int8_t)NUMBER_PINS_TOTAL ? 1 : 0)
32
+#define DIGITAL_PIN_TO_ANALOG_PIN(p) int(p - analogInputToDigitalPin(0))
33
+#define IS_ANALOG(P) ((P) >= analogInputToDigitalPin(0) && (P) <= analogInputToDigitalPin(13)) || ((P) >= analogInputToDigitalPin(14) && (P) <= analogInputToDigitalPin(17))
34
+#define pwm_status(pin) HAL_pwm_status(pin)
35
+#define GET_PINMODE(PIN) (VALID_PIN(pin) && IS_OUTPUT(pin))
36
+#define MULTI_NAME_PAD 16 // space needed to be pretty if not first name assigned to a pin
37
+
38
+struct pwm_pin_info_struct {
39
+  uint8_t type;    // 0=no pwm, 1=flexpwm, 2=quad
40
+  uint8_t module;  // 0-3, 0-3
41
+  uint8_t channel; // 0=X, 1=A, 2=B
42
+  uint8_t muxval;  //
43
+};
44
+
45
+#define M(a, b) ((((a) - 1) << 4) | (b))
46
+
47
+const struct pwm_pin_info_struct pwm_pin_info[] = {
48
+  {1, M(1, 1), 0, 4},  // FlexPWM1_1_X   0  // AD_B0_03
49
+  {1, M(1, 0), 0, 4},  // FlexPWM1_0_X   1  // AD_B0_02
50
+  {1, M(4, 2), 1, 1},  // FlexPWM4_2_A   2  // EMC_04
51
+  {1, M(4, 2), 2, 1},  // FlexPWM4_2_B   3  // EMC_05
52
+  {1, M(2, 0), 1, 1},  // FlexPWM2_0_A   4  // EMC_06
53
+  {1, M(2, 1), 1, 1},  // FlexPWM2_1_A   5  // EMC_08
54
+  {1, M(2, 2), 1, 2},  // FlexPWM2_2_A   6  // B0_10
55
+  {1, M(1, 3), 2, 6},  // FlexPWM1_3_B   7  // B1_01
56
+  {1, M(1, 3), 1, 6},  // FlexPWM1_3_A   8  // B1_00
57
+  {1, M(2, 2), 2, 2},  // FlexPWM2_2_B   9  // B0_11
58
+  {2, M(1, 0), 0, 1},  // QuadTimer1_0  10  // B0_00
59
+  {2, M(1, 2), 0, 1},  // QuadTimer1_2  11  // B0_02
60
+  {2, M(1, 1), 0, 1},  // QuadTimer1_1  12  // B0_01
61
+  {2, M(2, 0), 0, 1},  // QuadTimer2_0  13  // B0_03
62
+  {2, M(3, 2), 0, 1},  // QuadTimer3_2  14  // AD_B1_02
63
+  {2, M(3, 3), 0, 1},  // QuadTimer3_3  15  // AD_B1_03
64
+  {0, M(1, 0), 0, 0},
65
+  {0, M(1, 0), 0, 0},
66
+  {2, M(3, 1), 0, 1},  // QuadTimer3_1  18  // AD_B1_01
67
+  {2, M(3, 0), 0, 1},  // QuadTimer3_0  19  // AD_B1_00
68
+  {0, M(1, 0), 0, 0},
69
+  {0, M(1, 0), 0, 0},
70
+  {1, M(4, 0), 1, 1},  // FlexPWM4_0_A  22  // AD_B1_08
71
+  {1, M(4, 1), 1, 1},  // FlexPWM4_1_A  23  // AD_B1_09
72
+  {1, M(1, 2), 0, 4},  // FlexPWM1_2_X  24  // AD_B0_12
73
+  {1, M(1, 3), 0, 4},  // FlexPWM1_3_X  25  // AD_B0_13
74
+  {0, M(1, 0), 0, 0},
75
+  {0, M(1, 0), 0, 0},
76
+  {1, M(3, 1), 2, 1},  // FlexPWM3_1_B  28  // EMC_32
77
+  {1, M(3, 1), 1, 1},  // FlexPWM3_1_A  29  // EMC_31
78
+  {0, M(1, 0), 0, 0},
79
+  {0, M(1, 0), 0, 0},
80
+  {0, M(1, 0), 0, 0},
81
+  {1, M(2, 0), 2, 1},  // FlexPWM2_0_B  33  // EMC_07
82
+  #ifdef ARDUINO_TEENSY40
83
+    {1, M(1, 1), 2, 1},  // FlexPWM1_1_B  34  // SD_B0_03
84
+    {1, M(1, 1), 1, 1},  // FlexPWM1_1_A  35  // SD_B0_02
85
+    {1, M(1, 0), 2, 1},  // FlexPWM1_0_B  36  // SD_B0_01
86
+    {1, M(1, 0), 1, 1},  // FlexPWM1_0_A  37  // SD_B0_00
87
+    {1, M(1, 2), 2, 1},  // FlexPWM1_2_B  38  // SD_B0_05
88
+    {1, M(1, 2), 1, 1},  // FlexPWM1_2_A  39  // SD_B0_04
89
+  #endif
90
+  #ifdef ARDUINO_TEENSY41
91
+    {0, M(1, 0), 0, 0},
92
+    {0, M(1, 0), 0, 0},
93
+    {1, M(2, 3), 1, 6},  // FlexPWM2_3_A  36  // B1_00
94
+    {1, M(2, 3), 2, 6},  // FlexPWM2_3_B  37  // B1_01
95
+    {0, M(1, 0), 0, 0},
96
+    {0, M(1, 0), 0, 0},
97
+    {0, M(1, 0), 0, 0},
98
+    {0, M(1, 0), 0, 0},
99
+    {1, M(1, 1), 2, 1},  // FlexPWM1_1_B  42  // SD_B0_03
100
+    {1, M(1, 1), 1, 1},  // FlexPWM1_1_A  43  // SD_B0_02
101
+    {1, M(1, 0), 2, 1},  // FlexPWM1_0_B  44  // SD_B0_01
102
+    {1, M(1, 0), 1, 1},  // FlexPWM1_0_A  45  // SD_B0_00
103
+    {1, M(1, 2), 2, 1},  // FlexPWM1_2_B  46  // SD_B0_05
104
+    {1, M(1, 2), 1, 1},  // FlexPWM1_2_A  47  // SD_B0_04
105
+    {0, M(1, 0), 0, 0},  // duplicate FlexPWM1_0_B
106
+    {0, M(1, 0), 0, 0},  // duplicate FlexPWM1_2_A
107
+    {0, M(1, 0), 0, 0},  // duplicate FlexPWM1_2_B
108
+    {1, M(3, 3), 2, 1},  // FlexPWM3_3_B  51  // EMC_22
109
+    {0, M(1, 0), 0, 0},  // duplicate FlexPWM1_1_B
110
+    {0, M(1, 0), 0, 0},  // duplicate FlexPWM1_1_A
111
+    {1, M(3, 0), 1, 1},  // FlexPWM3_0_A  53  // EMC_29
112
+  #endif
113
+};
114
+
115
+void HAL_print_analog_pin(char buffer[], int8_t pin) {
116
+  if (pin <= 23)      sprintf_P(buffer, PSTR("(A%2d)  "), int(pin - 14));
117
+  else if (pin <= 41) sprintf_P(buffer, PSTR("(A%2d)  "), int(pin - 24));
118
+}
119
+
120
+void HAL_analog_pin_state(char buffer[], int8_t pin) {
121
+  if (pin <= 23)      sprintf_P(buffer, PSTR("Analog in =% 5d"), analogRead(pin - 14));
122
+  else if (pin <= 41) sprintf_P(buffer, PSTR("Analog in =% 5d"), analogRead(pin - 24));
123
+}
124
+
125
+#define PWM_PRINT(V) do{ sprintf_P(buffer, PSTR("PWM:  %4d"), V); SERIAL_ECHO(buffer); }while(0)
126
+
127
+/**
128
+ * Print a pin's PWM status.
129
+ * Return true if it's currently a PWM pin.
130
+ */
131
+bool HAL_pwm_status(int8_t pin) {
132
+  char buffer[20];   // for the sprintf statements
133
+  const struct pwm_pin_info_struct *info;
134
+
135
+  if (pin >= CORE_NUM_DIGITAL) return 0;
136
+  info = pwm_pin_info + pin;
137
+
138
+  if (info->type == 0) return 0;
139
+
140
+  /* TODO decode pwm value from timers */
141
+  // for now just indicate if output is set as pwm
142
+  PWM_PRINT(*(portConfigRegister(pin)) == info->muxval);
143
+  return (*(portConfigRegister(pin)) == info->muxval);
144
+}
145
+
146
+static void pwm_details(uint8_t pin) { /* TODO */ }

+ 27
- 0
Marlin/src/HAL/TEENSY40_41/spi_pins.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#define SCK_PIN   13
25
+#define MISO_PIN  12
26
+#define MOSI_PIN  11
27
+#define SS_PIN    20 // SDSS // A.28, A.29, B.21, C.26, C.29

+ 114
- 0
Marlin/src/HAL/TEENSY40_41/timers.cpp View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * Teensy4.0/4.1 (__IMXRT1062__)
25
+ */
26
+
27
+#ifdef __IMXRT1062__
28
+
29
+#include "../../inc/MarlinConfig.h"
30
+
31
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
32
+  switch (timer_num) {
33
+    case 0:
34
+      CCM_CSCMR1 &= ~CCM_CSCMR1_PERCLK_CLK_SEL; // turn off 24mhz mode
35
+      CCM_CCGR1 |= CCM_CCGR1_GPT1_BUS(CCM_CCGR_ON);
36
+
37
+      GPT1_CR = 0;                   // disable timer
38
+      GPT1_SR = 0x3F;                // clear all prior status
39
+      GPT1_PR = GPT1_TIMER_PRESCALE - 1;
40
+      GPT1_CR |= GPT_CR_CLKSRC(1);   //clock selection #1 (peripheral clock = 150 MHz)
41
+      GPT1_CR |= GPT_CR_ENMOD;       //reset count to zero before enabling
42
+      GPT1_CR |= GPT_CR_OM1(1);      // toggle mode
43
+      GPT1_OCR1 = (GPT1_TIMER_RATE / frequency) -1; // Initial compare value
44
+      GPT1_IR = GPT_IR_OF1IE;        // Compare3 value
45
+      GPT1_CR |= GPT_CR_EN;          //enable GPT2 counting at 150 MHz
46
+
47
+      OUT_WRITE(15, HIGH);
48
+      attachInterruptVector(IRQ_GPT1, &stepTC_Handler);
49
+      NVIC_SET_PRIORITY(IRQ_GPT1, 16);
50
+      break;
51
+    case 1:
52
+      CCM_CSCMR1 &= ~CCM_CSCMR1_PERCLK_CLK_SEL; // turn off 24mhz mode
53
+      CCM_CCGR0 |= CCM_CCGR0_GPT2_BUS(CCM_CCGR_ON);
54
+
55
+      GPT2_CR = 0;                   // disable timer
56
+      GPT2_SR = 0x3F;                // clear all prior status
57
+      GPT2_PR = GPT2_TIMER_PRESCALE - 1;
58
+      GPT2_CR |= GPT_CR_CLKSRC(1);   //clock selection #1 (peripheral clock = 150 MHz)
59
+      GPT2_CR |= GPT_CR_ENMOD;       //reset count to zero before enabling
60
+      GPT2_CR |= GPT_CR_OM1(1);      // toggle mode
61
+      GPT2_OCR1 = (GPT2_TIMER_RATE / frequency) -1; // Initial compare value
62
+      GPT2_IR = GPT_IR_OF1IE;        // Compare3 value
63
+      GPT2_CR |= GPT_CR_EN;          //enable GPT2 counting at 150 MHz
64
+
65
+      OUT_WRITE(14, HIGH);
66
+      attachInterruptVector(IRQ_GPT2, &tempTC_Handler);
67
+      NVIC_SET_PRIORITY(IRQ_GPT2, 32);
68
+      break;
69
+  }
70
+}
71
+
72
+void HAL_timer_enable_interrupt(const uint8_t timer_num) {
73
+  switch (timer_num) {
74
+    case 0:
75
+      NVIC_ENABLE_IRQ(IRQ_GPT1);
76
+      break;
77
+    case 1:
78
+      NVIC_ENABLE_IRQ(IRQ_GPT2);
79
+      break;
80
+  }
81
+}
82
+
83
+void HAL_timer_disable_interrupt(const uint8_t timer_num) {
84
+  switch (timer_num) {
85
+    case 0: NVIC_DISABLE_IRQ(IRQ_GPT1); break;
86
+    case 1: NVIC_DISABLE_IRQ(IRQ_GPT2); break;
87
+  }
88
+
89
+  // We NEED memory barriers to ensure Interrupts are actually disabled!
90
+  // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
91
+  asm volatile("dsb");
92
+}
93
+
94
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
95
+  switch (timer_num) {
96
+    case 0: return (NVIC_IS_ENABLED(IRQ_GPT1));
97
+    case 1: return (NVIC_IS_ENABLED(IRQ_GPT2));
98
+  }
99
+  return false;
100
+}
101
+
102
+void HAL_timer_isr_prologue(const uint8_t timer_num) {
103
+  switch (timer_num) {
104
+    case 0:
105
+      GPT1_SR = GPT_IR_OF1IE;  // clear OF3 bit
106
+      break;
107
+    case 1:
108
+      GPT2_SR = GPT_IR_OF1IE;  // clear OF3 bit
109
+      break;
110
+  }
111
+  asm volatile("dsb");
112
+}
113
+
114
+#endif // __IMXRT1062__

+ 120
- 0
Marlin/src/HAL/TEENSY40_41/timers.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
5
+ * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU General Public License
18
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
+ *
20
+ */
21
+#pragma once
22
+
23
+/**
24
+ * Description: HAL for
25
+ * Teensy4.0/4.1 (__IMXRT1062__)
26
+ */
27
+
28
+#include <stdint.h>
29
+
30
+// ------------------------
31
+// Defines
32
+// ------------------------
33
+
34
+#define FORCE_INLINE __attribute__((always_inline)) inline
35
+
36
+typedef uint32_t hal_timer_t;
37
+#define HAL_TIMER_TYPE_MAX 0xFFFFFFFE
38
+
39
+#define GPT_TIMER_RATE F_BUS_ACTUAL   // 150MHz
40
+
41
+#define GPT1_TIMER_PRESCALE 2
42
+#define GPT2_TIMER_PRESCALE 10
43
+
44
+#define GPT1_TIMER_RATE (GPT_TIMER_RATE / GPT1_TIMER_PRESCALE) // 75MHz
45
+#define GPT2_TIMER_RATE (GPT_TIMER_RATE / GPT2_TIMER_PRESCALE) // 15MHz
46
+
47
+#ifndef STEP_TIMER_NUM
48
+  #define STEP_TIMER_NUM        0  // Timer Index for Stepper
49
+#endif
50
+#ifndef PULSE_TIMER_NUM
51
+  #define PULSE_TIMER_NUM       STEP_TIMER_NUM
52
+#endif
53
+#ifndef TEMP_TIMER_NUM
54
+  #define TEMP_TIMER_NUM        1  // Timer Index for Temperature
55
+#endif
56
+
57
+#define TEMP_TIMER_RATE        1000000
58
+#define TEMP_TIMER_FREQUENCY   1000
59
+
60
+#define STEPPER_TIMER_RATE     GPT1_TIMER_RATE
61
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000)
62
+#define STEPPER_TIMER_PRESCALE ((GPT_TIMER_RATE / 1000000) / STEPPER_TIMER_TICKS_PER_US)
63
+
64
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
65
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
66
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
67
+
68
+#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
69
+#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
70
+#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
71
+
72
+#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
73
+#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
74
+
75
+#ifndef HAL_STEP_TIMER_ISR
76
+  #define HAL_STEP_TIMER_ISR()  extern "C" void stepTC_Handler() // GPT1_Handler()
77
+#endif
78
+#ifndef HAL_TEMP_TIMER_ISR
79
+  #define HAL_TEMP_TIMER_ISR()  extern "C" void tempTC_Handler() // GPT2_Handler()
80
+#endif
81
+
82
+extern "C" void stepTC_Handler();
83
+extern "C" void tempTC_Handler();
84
+
85
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
86
+
87
+FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
88
+  switch (timer_num) {
89
+    case 0:
90
+      GPT1_OCR1 = compare - 1;
91
+      break;
92
+    case 1:
93
+      GPT2_OCR1 = compare - 1;
94
+      break;
95
+  }
96
+}
97
+
98
+FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
99
+  switch (timer_num) {
100
+    case 0: return GPT1_OCR1;
101
+    case 1: return GPT2_OCR1;
102
+  }
103
+  return 0;
104
+}
105
+
106
+FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
107
+  switch (timer_num) {
108
+    case 0: return GPT1_CNT;
109
+    case 1: return GPT2_CNT;
110
+  }
111
+  return 0;
112
+}
113
+
114
+void HAL_timer_enable_interrupt(const uint8_t timer_num);
115
+void HAL_timer_disable_interrupt(const uint8_t timer_num);
116
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
117
+
118
+void HAL_timer_isr_prologue(const uint8_t timer_num);
119
+//void HAL_timer_isr_epilogue(const uint8_t timer_num) {}
120
+#define HAL_timer_isr_epilogue(TIMER_NUM)

+ 52
- 0
Marlin/src/HAL/TEENSY40_41/watchdog.cpp View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#ifdef __IMXRT1062__
23
+
24
+#include "../../inc/MarlinConfig.h"
25
+
26
+#if ENABLED(USE_WATCHDOG)
27
+
28
+#include "watchdog.h"
29
+
30
+// 4 seconds timeout
31
+#define WDTO 4 //seconds
32
+
33
+uint8_t timeoutval = (WDTO - 0.5f) / 0.5f;
34
+
35
+void watchdog_init() {
36
+
37
+  CCM_CCGR3 |= CCM_CCGR3_WDOG1(3);  // enable WDOG1 clocks
38
+  WDOG1_WMCR = 0;                   // disable power down PDE
39
+  WDOG1_WCR |= WDOG_WCR_SRS | WDOG_WCR_WT(timeoutval);
40
+  WDOG1_WCR |= WDOG_WCR_WDE | WDOG_WCR_WDT | WDOG_WCR_SRE;
41
+
42
+}
43
+
44
+void HAL_watchdog_refresh() {
45
+  // Watchdog refresh sequence
46
+  WDOG1_WSR = 0x5555;
47
+  WDOG1_WSR = 0xAAAA;
48
+}
49
+
50
+#endif // USE_WATCHDOG
51
+
52
+#endif // __IMXRT1062__

+ 30
- 0
Marlin/src/HAL/TEENSY40_41/watchdog.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+/**
25
+ * Watchdog for Teensy4.0/4.1 (__IMXRT1062__)
26
+ */
27
+
28
+void watchdog_init();
29
+
30
+void HAL_watchdog_refresh();

+ 2
- 0
Marlin/src/HAL/platforms.h View File

31
   #define HAL_PATH(PATH, NAME) XSTR(PATH/TEENSY31_32/NAME)
31
   #define HAL_PATH(PATH, NAME) XSTR(PATH/TEENSY31_32/NAME)
32
 #elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
32
 #elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
33
   #define HAL_PATH(PATH, NAME) XSTR(PATH/TEENSY35_36/NAME)
33
   #define HAL_PATH(PATH, NAME) XSTR(PATH/TEENSY35_36/NAME)
34
+#elif defined(__IMXRT1062__)
35
+  #define HAL_PATH(PATH, NAME) XSTR(PATH/TEENSY40_41/NAME)
34
 #elif defined(TARGET_LPC1768)
36
 #elif defined(TARGET_LPC1768)
35
   #define HAL_PATH(PATH, NAME) XSTR(PATH/LPC1768/NAME)
37
   #define HAL_PATH(PATH, NAME) XSTR(PATH/LPC1768/NAME)
36
 #elif defined(__STM32F1__) || defined(TARGET_STM32F1)
38
 #elif defined(__STM32F1__) || defined(TARGET_STM32F1)

+ 1
- 1
Marlin/src/HAL/shared/HAL_ST7920.h View File

27
  * (bypassing U8G), it will allow the LIGHTWEIGHT_UI to operate.
27
  * (bypassing U8G), it will allow the LIGHTWEIGHT_UI to operate.
28
  */
28
  */
29
 
29
 
30
-#if BOTH(HAS_GRAPHICAL_LCD, LIGHTWEIGHT_UI)
30
+#if BOTH(HAS_MARLINUI_U8GLIB, LIGHTWEIGHT_UI)
31
   void ST7920_cs();
31
   void ST7920_cs();
32
   void ST7920_ncs();
32
   void ST7920_ncs();
33
   void ST7920_set_cmd();
33
   void ST7920_set_cmd();

+ 0
- 0
Marlin/src/HAL/shared/backtrace/unwmemaccess.cpp View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save