浏览代码

HAL and serial cleanup

Co-Authored-By: Jason Smith <20053467+sjasonsmith@users.noreply.github.com>
Scott Lahteine 3 年前
父节点
当前提交
4b928b2da8
共有 33 个文件被更改,包括 220 次插入420 次删除
  1. 1
    20
      Marlin/src/HAL/AVR/HAL.h
  2. 10
    10
      Marlin/src/HAL/AVR/MarlinSerial.cpp
  3. 3
    3
      Marlin/src/HAL/AVR/MarlinSerial.h
  4. 12
    35
      Marlin/src/HAL/DUE/HAL.h
  5. 0
    3
      Marlin/src/HAL/ESP32/HAL.h
  6. 6
    0
      Marlin/src/HAL/HAL.h
  7. 0
    1
      Marlin/src/HAL/LINUX/HAL.h
  8. 1
    1
      Marlin/src/HAL/LINUX/main.cpp
  9. 12
    35
      Marlin/src/HAL/LPC1768/HAL.h
  10. 25
    12
      Marlin/src/HAL/LPC1768/inc/SanityCheck.h
  11. 11
    35
      Marlin/src/HAL/SAMD51/HAL.h
  12. 23
    58
      Marlin/src/HAL/STM32/HAL.h
  13. 1
    1
      Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h
  14. 1
    4
      Marlin/src/HAL/STM32F1/HAL.h
  15. 1
    0
      Marlin/src/HAL/STM32F1/MarlinSerial.h
  16. 1
    1
      Marlin/src/HAL/STM32F1/sdio.cpp
  17. 10
    51
      Marlin/src/HAL/STM32_F4_F7/HAL.h
  18. 5
    9
      Marlin/src/HAL/TEENSY31_32/HAL.h
  19. 5
    9
      Marlin/src/HAL/TEENSY35_36/HAL.h
  20. 9
    42
      Marlin/src/HAL/TEENSY40_41/HAL.h
  21. 8
    10
      Marlin/src/MarlinCore.cpp
  22. 3
    16
      Marlin/src/gcode/config/M575.cpp
  23. 34
    6
      Marlin/src/inc/SanityCheck.h
  24. 1
    5
      Marlin/src/lcd/extui/malyan_lcd.cpp
  25. 4
    4
      Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h
  26. 4
    4
      Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h
  27. 4
    4
      Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h
  28. 4
    4
      Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h
  29. 5
    11
      Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h
  30. 4
    4
      Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h
  31. 5
    11
      Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h
  32. 6
    11
      Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h
  33. 1
    0
      buildroot/tests/malyan_M300-tests

+ 1
- 20
Marlin/src/HAL/AVR/HAL.h 查看文件

@@ -81,12 +81,7 @@ typedef int8_t pin_t;
81 81
 
82 82
 // Serial ports
83 83
 #ifdef USBCON
84
-  #if ENABLED(BLUETOOTH)
85
-    #define MYSERIAL0 bluetoothSerial
86
-  #else
87
-    #define MYSERIAL0 Serial
88
-  #endif
89
-  #define NUM_SERIAL 1
84
+  #define MYSERIAL0 TERN(BLUETOOTH, bluetoothSerial, Serial)
90 85
 #else
91 86
   #if !WITHIN(SERIAL_PORT, -1, 3)
92 87
     #error "SERIAL_PORT must be from -1 to 3. Please update your configuration."
@@ -97,36 +92,22 @@ typedef int8_t pin_t;
97 92
   #ifdef SERIAL_PORT_2
98 93
     #if !WITHIN(SERIAL_PORT_2, -1, 3)
99 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 95
     #endif
103 96
     #define MYSERIAL1 customizedSerial2
104
-    #define NUM_SERIAL 2
105
-  #else
106
-    #define NUM_SERIAL 1
107 97
   #endif
108 98
 #endif
109 99
 
110 100
 #ifdef DGUS_SERIAL_PORT
111 101
   #if !WITHIN(DGUS_SERIAL_PORT, -1, 3)
112 102
     #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."
117 103
   #endif
118 104
   #define DGUS_SERIAL internalDgusSerial
119
-
120 105
   #define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.get_tx_buffer_free
121 106
 #endif
122 107
 
123 108
 #ifdef ANYCUBIC_LCD_SERIAL_PORT
124 109
   #if !WITHIN(ANYCUBIC_LCD_SERIAL_PORT, -1, 3)
125 110
     #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."
130 111
   #endif
131 112
   #define ANYCUBIC_LCD_SERIAL anycubicLcdSerial
132 113
 #endif

+ 10
- 10
Marlin/src/HAL/AVR/MarlinSerial.cpp 查看文件

@@ -712,11 +712,11 @@
712 712
   }
713 713
 
714 714
   // Hookup ISR handlers
715
-  ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_RX_vect)) {
715
+  ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _RX_vect)) {
716 716
     MarlinSerial<MarlinSerialCfg<SERIAL_PORT>>::store_rxd_char();
717 717
   }
718 718
 
719
-  ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_UDRE_vect)) {
719
+  ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _UDRE_vect)) {
720 720
     MarlinSerial<MarlinSerialCfg<SERIAL_PORT>>::_tx_udr_empty_irq();
721 721
   }
722 722
 
@@ -729,11 +729,11 @@
729 729
   #ifdef SERIAL_PORT_2
730 730
 
731 731
     // Hookup ISR handlers
732
-    ISR(SERIAL_REGNAME(USART,SERIAL_PORT_2,_RX_vect)) {
732
+    ISR(SERIAL_REGNAME(USART, SERIAL_PORT_2, _RX_vect)) {
733 733
       MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>>::store_rxd_char();
734 734
     }
735 735
 
736
-    ISR(SERIAL_REGNAME(USART,SERIAL_PORT_2,_UDRE_vect)) {
736
+    ISR(SERIAL_REGNAME(USART, SERIAL_PORT_2, _UDRE_vect)) {
737 737
       MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>>::_tx_udr_empty_irq();
738 738
     }
739 739
 
@@ -749,11 +749,11 @@
749 749
 
750 750
 #ifdef INTERNAL_SERIAL_PORT
751 751
 
752
-  ISR(SERIAL_REGNAME(USART,INTERNAL_SERIAL_PORT,_RX_vect)) {
752
+  ISR(SERIAL_REGNAME(USART, INTERNAL_SERIAL_PORT, _RX_vect)) {
753 753
     MarlinSerial<MarlinInternalSerialCfg<INTERNAL_SERIAL_PORT>>::store_rxd_char();
754 754
   }
755 755
 
756
-  ISR(SERIAL_REGNAME(USART,INTERNAL_SERIAL_PORT,_UDRE_vect)) {
756
+  ISR(SERIAL_REGNAME(USART, INTERNAL_SERIAL_PORT, _UDRE_vect)) {
757 757
     MarlinSerial<MarlinInternalSerialCfg<INTERNAL_SERIAL_PORT>>::_tx_udr_empty_irq();
758 758
   }
759 759
 
@@ -776,11 +776,11 @@
776 776
     return ret;
777 777
   }
778 778
 
779
-  ISR(SERIAL_REGNAME(USART,DGUS_SERIAL_PORT,_RX_vect)) {
779
+  ISR(SERIAL_REGNAME(USART, DGUS_SERIAL_PORT, _RX_vect)) {
780 780
     MarlinSerial<MarlinInternalSerialCfg<DGUS_SERIAL_PORT>>::store_rxd_char();
781 781
   }
782 782
 
783
-  ISR(SERIAL_REGNAME(USART,DGUS_SERIAL_PORT,_UDRE_vect)) {
783
+  ISR(SERIAL_REGNAME(USART, DGUS_SERIAL_PORT, _UDRE_vect)) {
784 784
     MarlinSerial<MarlinInternalSerialCfg<DGUS_SERIAL_PORT>>::_tx_udr_empty_irq();
785 785
   }
786 786
 
@@ -794,11 +794,11 @@
794 794
 
795 795
 #ifdef ANYCUBIC_LCD_SERIAL_PORT
796 796
 
797
-  ISR(SERIAL_REGNAME(USART,ANYCUBIC_LCD_SERIAL_PORT,_RX_vect)) {
797
+  ISR(SERIAL_REGNAME(USART, ANYCUBIC_LCD_SERIAL_PORT, _RX_vect)) {
798 798
     MarlinSerial<AnycubicLcdSerialCfg<ANYCUBIC_LCD_SERIAL_PORT>>::store_rxd_char();
799 799
   }
800 800
 
801
-  ISR(SERIAL_REGNAME(USART,ANYCUBIC_LCD_SERIAL_PORT,_UDRE_vect)) {
801
+  ISR(SERIAL_REGNAME(USART, ANYCUBIC_LCD_SERIAL_PORT, _UDRE_vect)) {
802 802
     MarlinSerial<AnycubicLcdSerialCfg<ANYCUBIC_LCD_SERIAL_PORT>>::_tx_udr_empty_irq();
803 803
   }
804 804
 

+ 3
- 3
Marlin/src/HAL/AVR/MarlinSerial.h 查看文件

@@ -48,11 +48,11 @@
48 48
 
49 49
   // These are macros to build serial port register names for the selected SERIAL_PORT (C preprocessor
50 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 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 54
   #else
55
-    #define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##number##suffix
55
+    #define _SERIAL_REGNAME(registerbase,number,suffix) registerbase##number##suffix
56 56
   #endif
57 57
 
58 58
   // Registers used by MarlinSerial class (expanded depending on selected serial port)

+ 12
- 35
Marlin/src/HAL/DUE/HAL.h 查看文件

@@ -38,57 +38,34 @@
38 38
 
39 39
 #include <stdint.h>
40 40
 
41
+#define _MSERIAL(X) Serial##X
42
+#define MSERIAL(X) _MSERIAL(X)
43
+#define Serial0 Serial
44
+
41 45
 // Define MYSERIAL0/1 before MarlinSerial includes!
42 46
 #if SERIAL_PORT == -1 || ENABLED(EMERGENCY_PARSER)
43 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 50
 #else
53 51
   #error "The required SERIAL_PORT must be from -1 to 3. Please update your configuration."
54 52
 #endif
55 53
 
56 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 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 59
   #else
70 60
     #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
71 61
   #endif
72
-  #define NUM_SERIAL 2
73
-#else
74
-  #define NUM_SERIAL 1
75 62
 #endif
76 63
 
77 64
 #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
65
+  #if DGUS_SERIAL_PORT == -1
83 66
     #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
67
+  #elif WITHIN(DGUS_SERIAL_PORT, 0, 3)
68
+    #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT)
92 69
   #else
93 70
     #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration."
94 71
   #endif

+ 0
- 3
Marlin/src/HAL/ESP32/HAL.h 查看文件

@@ -58,9 +58,6 @@ extern portMUX_TYPE spinlock;
58 58
   #else
59 59
     #define MYSERIAL1 webSocketSerial
60 60
   #endif
61
-  #define NUM_SERIAL 2
62
-#else
63
-  #define NUM_SERIAL 1
64 61
 #endif
65 62
 
66 63
 #define CRITICAL_SECTION_START() portENTER_CRITICAL(&spinlock)

+ 6
- 0
Marlin/src/HAL/HAL.h 查看文件

@@ -25,6 +25,12 @@
25 25
 
26 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 34
 #define HAL_ADC_RANGE _BV(HAL_ADC_RESOLUTION)
29 35
 
30 36
 #ifndef I2C_ADDRESS

+ 0
- 1
Marlin/src/HAL/LINUX/HAL.h 查看文件

@@ -62,7 +62,6 @@ uint8_t _getc();
62 62
 
63 63
 extern HalSerial usb_serial;
64 64
 #define MYSERIAL0 usb_serial
65
-#define NUM_SERIAL 1
66 65
 
67 66
 #define ST7920_DELAY_1 DELAY_NS(600)
68 67
 #define ST7920_DELAY_2 DELAY_NS(750)

+ 1
- 1
Marlin/src/HAL/LINUX/main.cpp 查看文件

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

+ 12
- 35
Marlin/src/HAL/LPC1768/HAL.h 查看文件

@@ -63,56 +63,33 @@ extern "C" volatile uint32_t _millis;
63 63
   #define ST7920_DELAY_3 DELAY_NS(750)
64 64
 #endif
65 65
 
66
+#define _MSERIAL(X) MSerial##X
67
+#define MSERIAL(X) _MSERIAL(X)
68
+#define MSerial0 MSerial
69
+
66 70
 #if SERIAL_PORT == -1
67 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 74
 #else
77 75
   #error "SERIAL_PORT must be from -1 to 3. Please update your configuration."
78 76
 #endif
79 77
 
80 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 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 83
   #else
94 84
     #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
95 85
   #endif
96
-  #define NUM_SERIAL 2
97
-#else
98
-  #define NUM_SERIAL 1
99 86
 #endif
100 87
 
101 88
 #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
89
+  #if DGUS_SERIAL_PORT == -1
107 90
     #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
91
+  #elif WITHIN(DGUS_SERIAL_PORT, 0, 3)
92
+    #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT)
116 93
   #else
117 94
     #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration."
118 95
   #endif

+ 25
- 12
Marlin/src/HAL/LPC1768/inc/SanityCheck.h 查看文件

@@ -89,6 +89,9 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
89 89
  * Serial2 | P0_10 | P0_11 |
90 90
  * Serial3 | P0_00 | P0_01 |
91 91
  */
92
+#define ANY_TX(N,V...) DO(IS_TX##N,||,V)
93
+#define ANY_RX(N,V...) DO(IS_RX##N,||,V)
94
+
92 95
 #if (defined(SERIAL_PORT) && SERIAL_PORT == 0) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == 0) || (defined(DGUS_SERIAL_PORT) && DGUS_SERIAL_PORT == 0)
93 96
   #define IS_TX0(P) (P == P0_02)
94 97
   #define IS_RX0(P) (P == P0_03)
@@ -106,48 +109,56 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
106 109
 #if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1 || DGUS_SERIAL_PORT == 1
107 110
   #define IS_TX1(P) (P == P0_15)
108 111
   #define IS_RX1(P) (P == P0_16)
112
+  #define _IS_TX1_1 IS_TX1
113
+  #define _IS_RX1_1 IS_RX1
109 114
   #if IS_TX1(TMC_SW_SCK)
110 115
     #error "Serial port pins (1) conflict with other pins!"
111 116
   #elif HAS_SPI_LCD
112 117
     #if IS_TX1(BTN_EN2) || IS_RX1(BTN_EN1)
113 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 121
       #error "Serial port pins (1) conflict with LCD pins!"
117 122
     #endif
118 123
   #endif
119 124
   #undef IS_TX1
120 125
   #undef IS_RX1
126
+  #undef _IS_TX1_1
127
+  #undef _IS_RX1_1
121 128
 #endif
122 129
 
123 130
 #if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 || DGUS_SERIAL_PORT == 2
124 131
   #define IS_TX2(P) (P == P0_10)
125 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 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 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 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 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 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 146
     #error "Serial port pins (2) conflict with other pins!"
138 147
   #elif Y_HOME_DIR < 0 && IS_TX2(Y_STOP_PIN)
139 148
     #error "Serial port pins (2) conflict with Y endstop pin!"
140 149
   #elif HAS_CUSTOM_PROBE_PIN && IS_TX2(Z_MIN_PROBE_PIN)
141 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 152
     #error "Serial port pins (2) conflict with X/Y stepper pins!"
144 153
   #elif HAS_MULTI_EXTRUDER && (IS_TX2(E1_ENABLE_PIN) || (AXIS_HAS_SPI(E1) && IS_TX2(E1_CS_PIN)))
145 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 156
     #error "Serial port pins (2) conflict with E stepper pins!"
148 157
   #endif
149 158
   #undef IS_TX2
150 159
   #undef IS_RX2
160
+  #undef _IS_TX2_1
161
+  #undef _IS_RX2_1
151 162
 #endif
152 163
 
153 164
 #if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 || DGUS_SERIAL_PORT == 3
@@ -155,8 +166,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
155 166
   #define PIN_IS_RX3(P) (P##_PIN == P0_01)
156 167
   #if PIN_IS_TX3(X_MIN) || PIN_IS_RX3(X_MAX)
157 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 170
     #error "Serial port pins (3) conflict with X/Y axis UART pins!"
161 171
   #elif PIN_IS_TX3(X2_DIR) || PIN_IS_RX3(X2_STEP)
162 172
     #error "Serial port pins (3) conflict with X2 pins!"
@@ -175,6 +185,9 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
175 185
   #undef PIN_IS_RX3
176 186
 #endif
177 187
 
188
+#undef ANY_TX
189
+#undef ANY_RX
190
+
178 191
 //
179 192
 // Flag any i2c pin conflicts
180 193
 //

+ 11
- 35
Marlin/src/HAL/SAMD51/HAL.h 查看文件

@@ -35,56 +35,32 @@
35 35
 
36 36
   // MYSERIAL0 required before MarlinSerial includes!
37 37
 
38
+  #define _MSERIAL(X) Serial##X
39
+  #define MSERIAL(X) _MSERIAL(INCREMENT(X))
40
+
38 41
   #if SERIAL_PORT == -1
39 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 45
   #else
49 46
     #error "SERIAL_PORT must be from -1 to 3. Please update your configuration."
50 47
   #endif
51 48
 
52 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 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 MYSERIAL0 MSERIAL(SERIAL_PORT_2)
65 54
     #else
66 55
       #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
67 56
     #endif
68
-    #define NUM_SERIAL 2
69
-  #else
70
-    #define NUM_SERIAL 1
71 57
   #endif
72 58
 
73 59
   #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
60
+    #if DGUS_SERIAL_PORT == -1
79 61
       #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
62
+    #elif WITHIN(DGUS_SERIAL_PORT, 0, 3)
63
+      #define MYSERIAL0 MSERIAL(DGUS_SERIAL_PORT)
88 64
     #else
89 65
       #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration."
90 66
     #endif

+ 23
- 58
Marlin/src/HAL/STM32/HAL.h 查看文件

@@ -43,82 +43,47 @@
43 43
 // ------------------------
44 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 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 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 55
 #endif
66 56
 
67 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 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 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 64
   #endif
90
-#else
91
-  #define NUM_SERIAL 1
92 65
 #endif
93 66
 
94 67
 #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
68
+  #if DGUS_SERIAL_PORT == -1
102 69
     #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
70
+  #elif WITHIN(DGUS_SERIAL_PORT, 1, 6)
71
+    #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT)
115 72
   #else
116
-    #error "DGUS_SERIAL_PORT must be from -1 to 6. Please update your configuration."
73
+    #error "DGUS_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
117 74
   #endif
118
-
119 75
   #define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.availableForWrite
120 76
 #endif
121 77
 
78
+#if ENABLED(MALYAN_LCD)
79
+  #if LCD_SERIAL_PORT == -1
80
+    #define LCD_SERIAL SerialUSB
81
+  #elif WITHIN(LCD_SERIAL_PORT, 1, 6)
82
+    #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
83
+  #else
84
+    #error "LCD_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
85
+  #endif
86
+#endif
122 87
 
123 88
 /**
124 89
  * TODO: review this to return 1 for pins that are not analog input

+ 1
- 1
Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h 查看文件

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

+ 1
- 4
Marlin/src/HAL/STM32F1/HAL.h 查看文件

@@ -53,7 +53,7 @@
53 53
 // ------------------------
54 54
 
55 55
 #ifndef STM32_FLASH_SIZE
56
-  #if defined(MCU_STM32F103RE) || defined(MCU_STM32F103VE)
56
+  #if EITHER(MCU_STM32F103RE, MCU_STM32F103VE)
57 57
     #define STM32_FLASH_SIZE 512
58 58
   #else
59 59
     #define STM32_FLASH_SIZE 256
@@ -106,9 +106,6 @@
106 106
   #else
107 107
     #error "SERIAL_PORT_2 must be from -1 to 5. Please update your configuration."
108 108
   #endif
109
-  #define NUM_SERIAL 2
110
-#else
111
-  #define NUM_SERIAL 1
112 109
 #endif
113 110
 
114 111
 #ifdef DGUS_SERIAL

+ 1
- 0
Marlin/src/HAL/STM32F1/MarlinSerial.h 查看文件

@@ -30,6 +30,7 @@
30 30
   #include "../../feature/e_parser.h"
31 31
 #endif
32 32
 
33
+// Increase priority of serial interrupts, to reduce overflow errors
33 34
 #define UART_IRQ_PRIO 1
34 35
 
35 36
 class MarlinSerial : public HardwareSerial {

+ 1
- 1
Marlin/src/HAL/STM32F1/sdio.cpp 查看文件

@@ -26,7 +26,7 @@
26 26
 
27 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 31
 #include "sdio.h"
32 32
 

+ 10
- 51
Marlin/src/HAL/STM32_F4_F7/HAL.h 查看文件

@@ -46,24 +46,16 @@
46 46
 // Serial override
47 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 53
 #if defined(STM32F4) && SERIAL_PORT == 0
50 54
   #error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
51 55
 #elif SERIAL_PORT == -1
52 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 59
 #else
68 60
   #error "SERIAL_PORT must be from -1 to 6. Please update your configuration."
69 61
 #endif
@@ -71,55 +63,22 @@
71 63
 #ifdef SERIAL_PORT_2
72 64
   #if defined(STM32F4) && SERIAL_PORT_2 == 0
73 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 66
   #elif SERIAL_PORT_2 == -1
77 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 70
   #else
93 71
     #error "SERIAL_PORT_2 must be from -1 to 6. Please update your configuration."
94 72
   #endif
95
-  #define NUM_SERIAL 2
96
-#else
97
-  #define NUM_SERIAL 1
98 73
 #endif
99 74
 
100 75
 #ifdef DGUS_SERIAL_PORT
101 76
   #if defined(STM32F4) && DGUS_SERIAL_PORT == 0
102 77
     #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 78
   #elif DGUS_SERIAL_PORT == -1
108 79
     #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
80
+  #elif WITHIN(DGUS_SERIAL_PORT, 0, 6)
81
+    #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT)
123 82
   #else
124 83
     #error "DGUS_SERIAL_PORT must be from -1 to 6. Please update your configuration."
125 84
   #endif

+ 5
- 9
Marlin/src/HAL/TEENSY31_32/HAL.h 查看文件

@@ -49,18 +49,14 @@
49 49
   #define IS_TEENSY32 1
50 50
 #endif
51 51
 
52
-#define NUM_SERIAL 1
52
+#define _MSERIAL(X) Serial##X
53
+#define MSERIAL(X) _MSERIAL(X)
54
+#define Serial0 Serial
53 55
 
54 56
 #if SERIAL_PORT == -1
55 57
   #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
58
+#elif WITHIN(SERIAL_PORT, 0, 3)
59
+  #define MYSERIAL0 MSERIAL(SERIAL_PORT)
64 60
 #endif
65 61
 
66 62
 #define HAL_SERVO_LIB libServo

+ 5
- 9
Marlin/src/HAL/TEENSY35_36/HAL.h 查看文件

@@ -54,18 +54,14 @@
54 54
   #define IS_TEENSY36 1
55 55
 #endif
56 56
 
57
-#define NUM_SERIAL 1
57
+#define _MSERIAL(X) Serial##X
58
+#define MSERIAL(X) _MSERIAL(X)
59
+#define Serial0 Serial
58 60
 
59 61
 #if SERIAL_PORT == -1
60 62
   #define MYSERIAL0 SerialUSB
61
-#elif SERIAL_PORT == 0
62
-  #define MYSERIAL0 Serial
63
-#elif SERIAL_PORT == 1
64
-  #define MYSERIAL0 Serial1
65
-#elif SERIAL_PORT == 2
66
-  #define MYSERIAL0 Serial2
67
-#elif SERIAL_PORT == 3
68
-  #define MYSERIAL0 Serial3
63
+#elif WITHIN(SERIAL_PORT, 0, 3)
64
+  #define MYSERIAL0 MSERIAL(SERIAL_PORT)
69 65
 #endif
70 66
 
71 67
 #define HAL_SERVO_LIB libServo

+ 9
- 42
Marlin/src/HAL/TEENSY40_41/HAL.h 查看文件

@@ -50,59 +50,26 @@
50 50
   #define IS_TEENSY41 1
51 51
 #endif
52 52
 
53
+#define _MSERIAL(X) Serial##X
54
+#define MSERIAL(X) _MSERIAL(X)
55
+#define Serial0 Serial
56
+
53 57
 #if SERIAL_PORT == -1
54 58
   #define MYSERIAL0 SerialUSB
55
-#elif SERIAL_PORT == 0
56
-  #define MYSERIAL0 Serial
57
-#elif SERIAL_PORT == 1
58
-  #define MYSERIAL0 Serial1
59
-#elif SERIAL_PORT == 2
60
-  #define MYSERIAL0 Serial2
61
-#elif SERIAL_PORT == 3
62
-  #define MYSERIAL0 Serial3
63
-#elif SERIAL_PORT == 4
64
-  #define MYSERIAL0 Serial4
65
-#elif SERIAL_PORT == 5
66
-  #define MYSERIAL0 Serial5
67
-#elif SERIAL_PORT == 6
68
-  #define MYSERIAL0 Serial6
69
-#elif SERIAL_PORT == 7
70
-  #define MYSERIAL0 Serial7
71
-#elif SERIAL_PORT == 8
72
-  #define MYSERIAL0 Serial8
59
+#elif WITHIN(SERIAL_PORT, 0, 8)
60
+  #define MYSERIAL0 MSERIAL(SERIAL_PORT)
73 61
 #else
74 62
   #error "The required SERIAL_PORT must be from -1 to 8. Please update your configuration."
75 63
 #endif
76 64
 
77 65
 #ifdef SERIAL_PORT_2
78
-  #if SERIAL_PORT_2 == SERIAL_PORT
79
-    #error "SERIAL_PORT_2 must be different from SERIAL_PORT. Please update your configuration."
80
-  #elif SERIAL_PORT_2 == -1
66
+  #if SERIAL_PORT_2 == -1
81 67
     #define MYSERIAL1 usbSerial
82
-  #elif SERIAL_PORT_2 == 0
83
-    #define MYSERIAL1 Serial
84
-  #elif SERIAL_PORT_2 == 1
85
-    #define MYSERIAL1 Serial1
86
-  #elif SERIAL_PORT_2 == 2
87
-    #define MYSERIAL1 Serial2
88
-  #elif SERIAL_PORT_2 == 3
89
-    #define MYSERIAL1 Serial3
90
-  #elif SERIAL_PORT_2 == 4
91
-    #define MYSERIAL1 Serial4
92
-  #elif SERIAL_PORT_2 == 5
93
-    #define MYSERIAL1 Serial5
94
-  #elif SERIAL_PORT_2 == 6
95
-    #define MYSERIAL1 Serial6
96
-  #elif SERIAL_PORT_2 == 7
97
-    #define MYSERIAL1 Serial7
98
-  #elif SERIAL_PORT_2 == 8
99
-    #define MYSERIAL1 Serial8
68
+  #elif WITHIN(SERIAL_PORT_2, 0, 8)
69
+    #define MYSERIAL0 MSERIAL(SERIAL_PORT_2)
100 70
   #else
101 71
       #error "SERIAL_PORT_2 must be from -1 to 8. Please update your configuration."
102 72
   #endif
103
-  #define NUM_SERIAL 2
104
-#else
105
-  #define NUM_SERIAL 1
106 73
 #endif
107 74
 
108 75
 #define HAL_SERVO_LIB libServo

+ 8
- 10
Marlin/src/MarlinCore.cpp 查看文件

@@ -912,17 +912,15 @@ void setup() {
912 912
     #endif
913 913
   #endif
914 914
 
915
-  #if NUM_SERIAL > 0
916
-    MYSERIAL0.begin(BAUDRATE);
917
-    uint32_t serial_connect_timeout = millis() + 1000UL;
918
-    while (!MYSERIAL0 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
919
-    #if HAS_MULTI_SERIAL
920
-      MYSERIAL1.begin(BAUDRATE);
921
-      serial_connect_timeout = millis() + 1000UL;
922
-      while (!MYSERIAL1 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
923
-    #endif
924
-    SERIAL_ECHO_MSG("start");
915
+  MYSERIAL0.begin(BAUDRATE);
916
+  uint32_t serial_connect_timeout = millis() + 1000UL;
917
+  while (!MYSERIAL0 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
918
+  #if HAS_MULTI_SERIAL
919
+    MYSERIAL1.begin(BAUDRATE);
920
+    serial_connect_timeout = millis() + 1000UL;
921
+    while (!MYSERIAL1 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
925 922
   #endif
923
+  SERIAL_ECHO_MSG("start");
926 924
 
927 925
   #if BOTH(HAS_TFT_LVGL_UI, USE_WIFI_FUNCTION)
928 926
     mks_esp_wifi_init();

+ 3
- 16
Marlin/src/gcode/config/M575.cpp 查看文件

@@ -53,23 +53,10 @@ void GcodeSuite::M575() {
53 53
     case 115200: case 250000: case 500000: case 1000000: {
54 54
       const int8_t port = parser.intval('P', -99);
55 55
       const bool set0 = (port == -99 || port == 0);
56
-      if (set0) {
57
-        SERIAL_ECHO_START();
58
-        SERIAL_ECHOLNPAIR(" Serial "
59
-          #if HAS_MULTI_SERIAL
60
-            , '0',
61
-          #else
62
-            "0"
63
-          #endif
64
-          " baud rate set to ", baud
65
-        );
66
-      }
56
+      if (set0) SERIAL_ECHO_MSG(" Serial ", '0', " baud rate set to ", baud);
67 57
       #if HAS_MULTI_SERIAL
68 58
         const bool set1 = (port == -99 || port == 1);
69
-        if (set1) {
70
-          SERIAL_ECHO_START();
71
-          SERIAL_ECHOLNPAIR(" Serial ", '1', " baud rate set to ", baud);
72
-        }
59
+        if (set1) SERIAL_ECHO_MSG(" Serial ", '1', " baud rate set to ", baud);
73 60
       #endif
74 61
 
75 62
       SERIAL_FLUSH();
@@ -85,4 +72,4 @@ void GcodeSuite::M575() {
85 72
   }
86 73
 }
87 74
 
88
-#endif // NUM_SERIAL > 0 && BAUD_RATE_GCODE
75
+#endif // BAUD_RATE_GCODE

+ 34
- 6
Marlin/src/inc/SanityCheck.h 查看文件

@@ -582,12 +582,10 @@
582 582
   #error "SERIAL_XON_XOFF and SERIAL_STATS_* features not supported on USB-native AVR devices."
583 583
 #endif
584 584
 
585
-#if SERIAL_PORT > 7
586
-  #error "Set SERIAL_PORT to the port on your board. Usually this is 0."
587
-#endif
588
-
589
-#if defined(SERIAL_PORT_2) && NUM_SERIAL < 2
590
-  #error "SERIAL_PORT_2 is not supported for your MOTHERBOARD. Disable it to continue."
585
+#ifndef SERIAL_PORT
586
+  #error "SERIAL_PORT must be defined in Configuration.h"
587
+#elif defined(SERIAL_PORT_2) && SERIAL_PORT_2 == SERIAL_PORT
588
+  #error "SERIAL_PORT_2 cannot be the same as SERIAL_PORT. Please update your configuration."
591 589
 #endif
592 590
 
593 591
 /**
@@ -2281,6 +2279,36 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
2281 2279
 #endif
2282 2280
 
2283 2281
 /**
2282
+ * Serial displays require a dedicated serial port
2283
+ */
2284
+#if HAS_DGUS_LCD
2285
+  #ifndef DGUS_SERIAL_PORT
2286
+    #error "The DGUS LCD requires DGUS_SERIAL_PORT to be defined in Configuration.h"
2287
+  #elif DGUS_SERIAL_PORT == SERIAL_PORT
2288
+    #error "DGUS_SERIAL_PORT cannot be the same as SERIAL_PORT. Please update your configuration."
2289
+  #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2
2290
+    #error "DGUS_SERIAL_PORT cannot be the same as SERIAL_PORT_2. Please update your configuration."
2291
+  #endif
2292
+#elif ENABLED(MALYAN_LCD)
2293
+  #ifndef LCD_SERIAL_PORT
2294
+    #error "MALYAN_LCD requires LCD_SERIAL_PORT to be defined in Configuration.h"
2295
+  #elif LCD_SERIAL_PORT == SERIAL_PORT
2296
+    #error "LCD_SERIAL_PORT cannot be the same as SERIAL_PORT. Please update your configuration."
2297
+  #elif defined(SERIAL_PORT_2) && LCD_SERIAL_PORT == SERIAL_PORT_2
2298
+    #error "LCD_SERIAL_PORT cannot be the same as SERIAL_PORT_2. Please update your configuration."
2299
+  #endif
2300
+#elif EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON)
2301
+  #ifndef ANYCUBIC_LCD_SERIAL_PORT
2302
+    #error "The ANYCUBIC LCD requires ANYCUBIC_LCD_SERIAL_PORT to be defined in Configuration.h"
2303
+  #elif ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT
2304
+    #error "ANYCUBIC_LCD_SERIAL_PORT cannot be the same as SERIAL_PORT. Please update your configuration."
2305
+  #elif defined(SERIAL_PORT_2) && ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT_2
2306
+    #error "ANYCUBIC_LCD_SERIAL_PORT cannot be the same as SERIAL_PORT_2. Please update your configuration."
2307
+  #endif
2308
+  #define ANYCUBIC_LCD_SERIAL anycubicLcdSerial
2309
+#endif
2310
+
2311
+/**
2284 2312
  * FYSETC Mini 12864 RGB backlighting required
2285 2313
  */
2286 2314
 #if EITHER(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0) && DISABLED(RGB_LED)

+ 1
- 5
Marlin/src/lcd/extui/malyan_lcd.cpp 查看文件

@@ -45,7 +45,7 @@
45 45
 
46 46
 #if ENABLED(MALYAN_LCD)
47 47
 
48
-#define DEBUG_MALYAN_LCD
48
+//#define DEBUG_MALYAN_LCD
49 49
 
50 50
 #include "ui_api.h"
51 51
 
@@ -61,10 +61,6 @@
61 61
 #define DEBUG_OUT ENABLED(DEBUG_MALYAN_LCD)
62 62
 #include "../../core/debug_out.h"
63 63
 
64
-// On the Malyan M200, this will be Serial1. On a RAMPS board,
65
-// it might not be.
66
-#define LCD_SERIAL Serial1
67
-
68 64
 // This is based on longest sys command + a filename, plus some buffer
69 65
 // in case we encounter some data we don't recognize
70 66
 // There is no evidence a line will ever be this long, but better safe than sorry

+ 4
- 4
Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h 查看文件

@@ -117,10 +117,10 @@
117 117
    * Hardware serial communication ports.
118 118
    * If undefined software serial is used according to the pins below
119 119
    */
120
-  //#define X_HARDWARE_SERIAL  Serial1
121
-  //#define Y_HARDWARE_SERIAL  Serial1
122
-  //#define Z_HARDWARE_SERIAL  Serial1
123
-  //#define E0_HARDWARE_SERIAL Serial1
120
+  //#define X_HARDWARE_SERIAL  MSerial1
121
+  //#define Y_HARDWARE_SERIAL  MSerial1
122
+  //#define Z_HARDWARE_SERIAL  MSerial1
123
+  //#define E0_HARDWARE_SERIAL MSerial1
124 124
 
125 125
   //
126 126
   // Software serial

+ 4
- 4
Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h 查看文件

@@ -30,8 +30,8 @@
30 30
  * Hardware serial communication ports.
31 31
  */
32 32
 #if HAS_TMC_UART
33
-  #define X_HARDWARE_SERIAL  Serial4
34
-  #define Y_HARDWARE_SERIAL  Serial4
35
-  #define Z_HARDWARE_SERIAL  Serial4
36
-  #define E0_HARDWARE_SERIAL Serial4
33
+  #define X_HARDWARE_SERIAL  MSerial4
34
+  #define Y_HARDWARE_SERIAL  MSerial4
35
+  #define Z_HARDWARE_SERIAL  MSerial4
36
+  #define E0_HARDWARE_SERIAL MSerial4
37 37
 #endif

+ 4
- 4
Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h 查看文件

@@ -52,8 +52,8 @@
52 52
  * Hardware serial communication ports.
53 53
  */
54 54
 #if HAS_TMC_UART
55
-  #define X_HARDWARE_SERIAL  Serial4
56
-  #define Y_HARDWARE_SERIAL  Serial4
57
-  #define Z_HARDWARE_SERIAL  Serial4
58
-  #define E0_HARDWARE_SERIAL Serial4
55
+  #define X_HARDWARE_SERIAL  MSerial4
56
+  #define Y_HARDWARE_SERIAL  MSerial4
57
+  #define Z_HARDWARE_SERIAL  MSerial4
58
+  #define E0_HARDWARE_SERIAL MSerial4
59 59
 #endif

+ 4
- 4
Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h 查看文件

@@ -93,10 +93,10 @@
93 93
   //
94 94
   // Hardware serial with switch
95 95
   //
96
-  #define X_HARDWARE_SERIAL  Serial1
97
-  #define Y_HARDWARE_SERIAL  Serial1
98
-  #define Z_HARDWARE_SERIAL  Serial1
99
-  #define E0_HARDWARE_SERIAL Serial1
96
+  #define X_HARDWARE_SERIAL  MSerial1
97
+  #define Y_HARDWARE_SERIAL  MSerial1
98
+  #define Z_HARDWARE_SERIAL  MSerial1
99
+  #define E0_HARDWARE_SERIAL MSerial1
100 100
 
101 101
   // The 4xTMC2209 module doesn't have a serial multiplexer and
102 102
   // needs to set *_SLAVE_ADDRESS in Configuration_adv.h for X,Y,Z,E0

+ 5
- 11
Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h 查看文件

@@ -188,17 +188,11 @@
188 188
    * Hardware serial communication ports.
189 189
    * If undefined software serial is used according to the pins below
190 190
    */
191
-  //#define X_HARDWARE_SERIAL  Serial1
192
-  //#define X2_HARDWARE_SERIAL Serial1
193
-  //#define Y_HARDWARE_SERIAL  Serial1
194
-  //#define Y2_HARDWARE_SERIAL Serial1
195
-  //#define Z_HARDWARE_SERIAL  Serial1
196
-  //#define Z2_HARDWARE_SERIAL Serial1
197
-  //#define E0_HARDWARE_SERIAL Serial1
198
-  //#define E1_HARDWARE_SERIAL Serial1
199
-  //#define E2_HARDWARE_SERIAL Serial1
200
-  //#define E3_HARDWARE_SERIAL Serial1
201
-  //#define E4_HARDWARE_SERIAL Serial1
191
+  //#define X_HARDWARE_SERIAL  MSerial1
192
+  //#define Y_HARDWARE_SERIAL  MSerial1
193
+  //#define Z_HARDWARE_SERIAL  MSerial1
194
+  //#define E0_HARDWARE_SERIAL MSerial1
195
+  //#define E1_HARDWARE_SERIAL MSerial1
202 196
 
203 197
   // Unused servo pins may be repurposed with SoftwareSerialM
204 198
   //#define X_SERIAL_TX_PIN                 PF8   // SERVO3_PIN -- XS2 - 6

+ 4
- 4
Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h 查看文件

@@ -83,10 +83,10 @@
83 83
    * Hardware serial communication ports.
84 84
    * If undefined software serial is used according to the pins below
85 85
    */
86
-  //#define X_HARDWARE_SERIAL  Serial1
87
-  //#define Y_HARDWARE_SERIAL  Serial1
88
-  //#define Z_HARDWARE_SERIAL  Serial1
89
-  //#define E0_HARDWARE_SERIAL Serial1
86
+  //#define X_HARDWARE_SERIAL  MSerial1
87
+  //#define Y_HARDWARE_SERIAL  MSerial1
88
+  //#define Z_HARDWARE_SERIAL  MSerial1
89
+  //#define E0_HARDWARE_SERIAL MSerial1
90 90
 
91 91
   //
92 92
   // Software serial

+ 5
- 11
Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h 查看文件

@@ -132,17 +132,11 @@
132 132
    * Hardware serial communication ports.
133 133
    * If undefined software serial is used according to the pins below
134 134
    */
135
-  //#define X_HARDWARE_SERIAL  Serial1
136
-  //#define X2_HARDWARE_SERIAL Serial1
137
-  //#define Y_HARDWARE_SERIAL  Serial1
138
-  //#define Y2_HARDWARE_SERIAL Serial1
139
-  //#define Z_HARDWARE_SERIAL  Serial1
140
-  //#define Z2_HARDWARE_SERIAL Serial1
141
-  //#define E0_HARDWARE_SERIAL Serial1
142
-  //#define E1_HARDWARE_SERIAL Serial1
143
-  //#define E2_HARDWARE_SERIAL Serial1
144
-  //#define E3_HARDWARE_SERIAL Serial1
145
-  //#define E4_HARDWARE_SERIAL Serial1
135
+  //#define X_HARDWARE_SERIAL  MSerial1
136
+  //#define Y_HARDWARE_SERIAL  MSerial1
137
+  //#define Z_HARDWARE_SERIAL  MSerial1
138
+  //#define E0_HARDWARE_SERIAL MSerial1
139
+  //#define E1_HARDWARE_SERIAL MSerial1
146 140
 
147 141
   //
148 142
   // Software serial

+ 6
- 11
Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h 查看文件

@@ -125,17 +125,12 @@
125 125
    * Hardware serial communication ports.
126 126
    * If undefined software serial is used according to the pins below
127 127
    */
128
-  //#define X_HARDWARE_SERIAL  Serial1
129
-  //#define X2_HARDWARE_SERIAL Serial1
130
-  //#define Y_HARDWARE_SERIAL  Serial1
131
-  //#define Y2_HARDWARE_SERIAL Serial1
132
-  //#define Z_HARDWARE_SERIAL  Serial1
133
-  //#define Z2_HARDWARE_SERIAL Serial1
134
-  //#define E0_HARDWARE_SERIAL Serial1
135
-  //#define E1_HARDWARE_SERIAL Serial1
136
-  //#define E2_HARDWARE_SERIAL Serial1
137
-  //#define E3_HARDWARE_SERIAL Serial1
138
-  //#define E4_HARDWARE_SERIAL Serial1
128
+  //#define X_HARDWARE_SERIAL  MSerial1
129
+  //#define Y_HARDWARE_SERIAL  MSerial1
130
+  //#define Z_HARDWARE_SERIAL  MSerial1
131
+  //#define E0_HARDWARE_SERIAL MSerial1
132
+  //#define E1_HARDWARE_SERIAL MSerial1
133
+  //#define E2_HARDWARE_SERIAL MSerial1
139 134
 
140 135
   //
141 136
   // Software serial

+ 1
- 0
buildroot/tests/malyan_M300-tests 查看文件

@@ -9,6 +9,7 @@ set -e
9 9
 restore_configs
10 10
 use_example_configs "delta/Malyan M300"
11 11
 opt_disable AUTO_BED_LEVELING_3POINT
12
+opt_set LCD_SERIAL_PORT 1
12 13
 exec_test $1 $2 "Malyan M300 (delta)"
13 14
 
14 15
 # cleanup

正在加载...
取消
保存