ソースを参照

Fix and improve STM32F1 serial (#19464)

Jason Smith 3年前
コミット
da6c8317a7
コミッターのメールアドレスに関連付けられたアカウントが存在しません

+ 4
- 1
Marlin/Configuration.h ファイルの表示

@@ -2165,6 +2165,9 @@
2165 2165
 // Touch-screen LCD for Malyan M200/M300 printers
2166 2166
 //
2167 2167
 //#define MALYAN_LCD
2168
+#if ENABLED(MALYAN_LCD)
2169
+  #define LCD_SERIAL_PORT 1  // Default is 1 for Malyan M200
2170
+#endif
2168 2171
 
2169 2172
 //
2170 2173
 // Touch UI for FTDI EVE (FT800/FT810) displays
@@ -2178,7 +2181,7 @@
2178 2181
 //#define ANYCUBIC_LCD_I3MEGA
2179 2182
 //#define ANYCUBIC_LCD_CHIRON
2180 2183
 #if EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON)
2181
-  #define ANYCUBIC_LCD_SERIAL_PORT 3
2184
+  #define LCD_SERIAL_PORT 3  // Default is 3 for Anycubic
2182 2185
   //#define ANYCUBIC_LCD_DEBUG
2183 2186
 #endif
2184 2187
 

+ 5
- 5
Marlin/Configuration_adv.h ファイルの表示

@@ -1404,8 +1404,8 @@
1404 1404
 // Additional options for DGUS / DWIN displays
1405 1405
 //
1406 1406
 #if HAS_DGUS_LCD
1407
-  #define DGUS_SERIAL_PORT 3
1408
-  #define DGUS_BAUDRATE 115200
1407
+  #define LCD_SERIAL_PORT 3
1408
+  #define LCD_BAUDRATE 115200
1409 1409
 
1410 1410
   #define DGUS_RX_BUFFER_SIZE 128
1411 1411
   #define DGUS_TX_BUFFER_SIZE 48
@@ -3419,10 +3419,10 @@
3419 3419
 #if ENABLED(PRUSA_MMU2)
3420 3420
 
3421 3421
   // Serial port used for communication with MMU2.
3422
-  // For AVR enable the UART port used for the MMU. (e.g., internalSerial)
3422
+  // For AVR enable the UART port used for the MMU. (e.g., mmuSerial)
3423 3423
   // For 32-bit boards check your HAL for available serial ports. (e.g., Serial2)
3424
-  #define INTERNAL_SERIAL_PORT 2
3425
-  #define MMU2_SERIAL internalSerial
3424
+  #define MMU2_SERIAL_PORT 2
3425
+  #define MMU2_SERIAL mmuSerial
3426 3426
 
3427 3427
   // Use hardware reset for MMU if a pin is defined for it
3428 3428
   //#define MMU2_RST_PIN 23

+ 6
- 11
Marlin/src/HAL/AVR/HAL.h ファイルの表示

@@ -96,19 +96,14 @@ typedef int8_t pin_t;
96 96
   #endif
97 97
 #endif
98 98
 
99
-#ifdef DGUS_SERIAL_PORT
100
-  #if !WITHIN(DGUS_SERIAL_PORT, -1, 3)
101
-    #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration."
99
+#ifdef LCD_SERIAL_PORT
100
+  #if !WITHIN(LCD_SERIAL_PORT, -1, 3)
101
+    #error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
102 102
   #endif
103
-  #define DGUS_SERIAL internalDgusSerial
104
-  #define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.get_tx_buffer_free
105
-#endif
106
-
107
-#ifdef ANYCUBIC_LCD_SERIAL_PORT
108
-  #if !WITHIN(ANYCUBIC_LCD_SERIAL_PORT, -1, 3)
109
-    #error "ANYCUBIC_LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
103
+  #define LCD_SERIAL lcdSerial
104
+  #if HAS_DGUS_LCD
105
+    #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.get_tx_buffer_free()
110 106
   #endif
111
-  #define ANYCUBIC_LCD_SERIAL anycubicLcdSerial
112 107
 #endif
113 108
 
114 109
 // ------------------------

+ 606
- 622
Marlin/src/HAL/AVR/MarlinSerial.cpp
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 32
- 35
Marlin/src/HAL/AVR/MarlinSerial.h ファイルの表示

@@ -217,10 +217,12 @@
217 217
       static ring_buffer_pos_t available();
218 218
       static void write(const uint8_t c);
219 219
       static void flushTX();
220
-      #ifdef DGUS_SERIAL_PORT
220
+      #if HAS_DGUS_LCD
221 221
         static ring_buffer_pos_t get_tx_buffer_free();
222 222
       #endif
223 223
 
224
+      static inline bool emergency_parser_enabled() { return Cfg::EMERGENCYPARSER; }
225
+
224 226
       FORCE_INLINE static uint8_t dropped() { return Cfg::DROPPED_RX ? rx_dropped_bytes : 0; }
225 227
       FORCE_INLINE static uint8_t buffer_overruns() { return Cfg::RX_OVERRUNS ? rx_buffer_overruns : 0; }
226 228
       FORCE_INLINE static uint8_t framing_errors() { return Cfg::RX_FRAMING_ERRORS ? rx_framing_errors : 0; }
@@ -278,55 +280,50 @@
278 280
 
279 281
 #endif // !USBCON
280 282
 
281
-#ifdef INTERNAL_SERIAL_PORT
283
+#ifdef MMU2_SERIAL_PORT
282 284
   template <uint8_t serial>
283
-  struct MarlinInternalSerialCfg {
285
+  struct MMU2SerialCfg {
284 286
     static constexpr int PORT               = serial;
285
-    static constexpr unsigned int RX_SIZE   = 32;
286
-    static constexpr unsigned int TX_SIZE   = 32;
287 287
     static constexpr bool XONOFF            = false;
288 288
     static constexpr bool EMERGENCYPARSER   = false;
289 289
     static constexpr bool DROPPED_RX        = false;
290
-    static constexpr bool RX_OVERRUNS       = false;
291 290
     static constexpr bool RX_FRAMING_ERRORS = false;
292 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 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 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(DGUS_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 327
 #endif
331 328
 
332 329
 // Use the UART for Bluetooth in AT90USB configurations

+ 6
- 6
Marlin/src/HAL/DUE/HAL.h ファイルの表示

@@ -61,13 +61,13 @@
61 61
   #endif
62 62
 #endif
63 63
 
64
-#ifdef DGUS_SERIAL_PORT
65
-  #if DGUS_SERIAL_PORT == -1
66
-    #define DGUS_SERIAL internalDgusSerial
67
-  #elif WITHIN(DGUS_SERIAL_PORT, 0, 3)
68
-    #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT)
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)
69 69
   #else
70
-    #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."
71 71
   #endif
72 72
 #endif
73 73
 

+ 2
- 0
Marlin/src/HAL/DUE/MarlinSerial.h ファイルの表示

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

+ 1
- 0
Marlin/src/HAL/LINUX/include/serial.h ファイルの表示

@@ -79,6 +79,7 @@ public:
79 79
 
80 80
   #if ENABLED(EMERGENCY_PARSER)
81 81
     EmergencyParser::State emergency_state;
82
+    static inline bool emergency_parser_enabled() { return true; }
82 83
   #endif
83 84
 
84 85
   HalSerial() { host_connected = true; }

+ 6
- 6
Marlin/src/HAL/LPC1768/HAL.h ファイルの表示

@@ -85,13 +85,13 @@ extern "C" volatile uint32_t _millis;
85 85
   #endif
86 86
 #endif
87 87
 
88
-#ifdef DGUS_SERIAL_PORT
89
-  #if DGUS_SERIAL_PORT == -1
90
-    #define DGUS_SERIAL UsbSerial
91
-  #elif WITHIN(DGUS_SERIAL_PORT, 0, 3)
92
-    #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT)
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)
93 93
   #else
94
-    #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."
95 95
   #endif
96 96
 #endif
97 97
 

+ 4
- 4
Marlin/src/HAL/LPC1768/MarlinSerial.cpp ファイルの表示

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

+ 1
- 0
Marlin/src/HAL/LPC1768/MarlinSerial.h ファイルの表示

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

+ 4
- 4
Marlin/src/HAL/LPC1768/inc/SanityCheck.h ファイルの表示

@@ -92,7 +92,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
92 92
 #define ANY_TX(N,V...) DO(IS_TX##N,||,V)
93 93
 #define ANY_RX(N,V...) DO(IS_RX##N,||,V)
94 94
 
95
-#if (defined(SERIAL_PORT) && SERIAL_PORT == 0) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == 0) || (defined(DGUS_SERIAL_PORT) && DGUS_SERIAL_PORT == 0)
95
+#if USING_SERIAL_0
96 96
   #define IS_TX0(P) (P == P0_02)
97 97
   #define IS_RX0(P) (P == P0_03)
98 98
   #if IS_TX0(TMC_SW_MISO) || IS_RX0(TMC_SW_MOSI)
@@ -106,7 +106,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
106 106
   #undef IS_RX0
107 107
 #endif
108 108
 
109
-#if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1 || DGUS_SERIAL_PORT == 1
109
+#if USING_SERIAL_1
110 110
   #define IS_TX1(P) (P == P0_15)
111 111
   #define IS_RX1(P) (P == P0_16)
112 112
   #define _IS_TX1_1 IS_TX1
@@ -127,7 +127,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
127 127
   #undef _IS_RX1_1
128 128
 #endif
129 129
 
130
-#if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 || DGUS_SERIAL_PORT == 2
130
+#if USING_SERIAL_2
131 131
   #define IS_TX2(P) (P == P0_10)
132 132
   #define IS_RX2(P) (P == P0_11)
133 133
   #define _IS_TX2_1 IS_TX2
@@ -161,7 +161,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
161 161
   #undef _IS_RX2_1
162 162
 #endif
163 163
 
164
-#if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 || DGUS_SERIAL_PORT == 3
164
+#if USING_SERIAL_3
165 165
   #define PIN_IS_TX3(P) (PIN_EXISTS(P) && P##_PIN == P0_00)
166 166
   #define PIN_IS_RX3(P) (P##_PIN == P0_01)
167 167
   #if PIN_IS_TX3(X_MIN) || PIN_IS_RX3(X_MAX)

+ 2
- 0
Marlin/src/HAL/LPC1768/usb_serial.cpp ファイルの表示

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

+ 6
- 6
Marlin/src/HAL/SAMD51/HAL.h ファイルの表示

@@ -56,13 +56,13 @@
56 56
     #endif
57 57
   #endif
58 58
 
59
-  #ifdef DGUS_SERIAL_PORT
60
-    #if DGUS_SERIAL_PORT == -1
61
-      #define DGUS_SERIAL Serial
62
-    #elif WITHIN(DGUS_SERIAL_PORT, 0, 3)
63
-      #define MYSERIAL0 MSERIAL(DGUS_SERIAL_PORT)
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)
64 64
     #else
65
-      #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."
66 66
     #endif
67 67
   #endif
68 68
 

+ 4
- 12
Marlin/src/HAL/STM32/HAL.h ファイルの表示

@@ -64,18 +64,7 @@
64 64
   #endif
65 65
 #endif
66 66
 
67
-#if HAS_DGUS_LCD
68
-  #if DGUS_SERIAL_PORT == -1
69
-    #define DGUS_SERIAL SerialUSB
70
-  #elif WITHIN(DGUS_SERIAL_PORT, 1, 6)
71
-    #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT)
72
-  #else
73
-    #error "DGUS_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
74
-  #endif
75
-  #define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.availableForWrite
76
-#endif
77
-
78
-#if ENABLED(MALYAN_LCD)
67
+#ifdef LCD_SERIAL_PORT
79 68
   #if LCD_SERIAL_PORT == -1
80 69
     #define LCD_SERIAL SerialUSB
81 70
   #elif WITHIN(LCD_SERIAL_PORT, 1, 6)
@@ -83,6 +72,9 @@
83 72
   #else
84 73
     #error "LCD_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
85 74
   #endif
75
+  #if HAS_DGUS_LCD
76
+    #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite()
77
+  #endif
86 78
 #endif
87 79
 
88 80
 /**

+ 2
- 2
Marlin/src/HAL/STM32/MarlinSerial.cpp ファイルの表示

@@ -49,8 +49,8 @@
49 49
   DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2)
50 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 54
 #endif
55 55
 
56 56
 void MarlinSerial::begin(unsigned long baud, uint8_t config) {

+ 4
- 0
Marlin/src/HAL/STM32/MarlinSerial.h ファイルの表示

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

+ 29
- 51
Marlin/src/HAL/STM32F1/HAL.h ファイルの表示

@@ -68,71 +68,49 @@
68 68
   #endif
69 69
 #endif
70 70
 
71
-#if SERIAL_PORT == 0
72
-  #error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
73
-#elif SERIAL_PORT == -1
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
76
+#else
77
+  #define NUM_UARTS 3
78
+#endif
79
+
80
+#if SERIAL_PORT == -1
74 81
   #define MYSERIAL0 UsbSerial
75
-#elif SERIAL_PORT == 1
76
-  #define MYSERIAL0 MSerial1
77
-#elif SERIAL_PORT == 2
78
-  #define MYSERIAL0 MSerial2
79
-#elif SERIAL_PORT == 3
80
-  #define MYSERIAL0 MSerial3
81
-#elif SERIAL_PORT == 4
82
-  #define MYSERIAL0 MSerial4
83
-#elif SERIAL_PORT == 5
84
-  #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."
85 86
 #else
86
-  #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."
87 88
 #endif
88 89
 
89 90
 #ifdef SERIAL_PORT_2
90
-  #if SERIAL_PORT_2 == 0
91
-    #error "SERIAL_PORT_2 cannot be 0. (Port 0 does not exist.) Please update your configuration."
92
-  #elif SERIAL_PORT_2 == SERIAL_PORT
93
-    #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration."
94
-  #elif SERIAL_PORT_2 == -1
91
+  #if SERIAL_PORT_2 == -1
95 92
     #define MYSERIAL1 UsbSerial
96
-  #elif SERIAL_PORT_2 == 1
97
-    #define MYSERIAL1 MSerial1
98
-  #elif SERIAL_PORT_2 == 2
99
-    #define MYSERIAL1 MSerial2
100
-  #elif SERIAL_PORT_2 == 3
101
-    #define MYSERIAL1 MSerial3
102
-  #elif SERIAL_PORT_2 == 4
103
-    #define MYSERIAL1 MSerial4
104
-  #elif SERIAL_PORT_2 == 5
105
-    #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."
106 97
   #else
107
-    #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."
108 99
   #endif
109 100
 #endif
110 101
 
111
-#ifdef DGUS_SERIAL_PORT
112
-  #if DGUS_SERIAL_PORT == 0
113
-    #error "DGUS_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
114
-  #elif DGUS_SERIAL_PORT == SERIAL_PORT
115
-    #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration."
116
-  #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2
117
-    #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration."
118
-  #elif DGUS_SERIAL_PORT == -1
119
-    #define DGUS_SERIAL UsbSerial
120
-  #elif DGUS_SERIAL_PORT == 1
121
-    #define DGUS_SERIAL MSerial1
122
-  #elif DGUS_SERIAL_PORT == 2
123
-    #define DGUS_SERIAL MSerial2
124
-  #elif DGUS_SERIAL_PORT == 3
125
-    #define DGUS_SERIAL MSerial3
126
-  #elif DGUS_SERIAL_PORT == 4
127
-    #define DGUS_SERIAL MSerial4
128
-  #elif DGUS_SERIAL_PORT == 5
129
-    #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."
130 109
   #else
131
-    #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."
132 111
   #endif
133 112
 #endif
134 113
 
135
-
136 114
 // Set interrupt grouping for this MCU
137 115
 void HAL_init();
138 116
 #define HAL_IDLETASK 1

+ 104
- 23
Marlin/src/HAL/STM32F1/MarlinSerial.cpp ファイルの表示

@@ -22,7 +22,7 @@
22 22
 
23 23
 #ifdef __STM32F1__
24 24
 
25
-#include "../../inc/MarlinConfigPre.h"
25
+#include "../../inc/MarlinConfig.h"
26 26
 #include "MarlinSerial.h"
27 27
 #include <libmaple/usart.h>
28 28
 
@@ -53,7 +53,8 @@ static inline __always_inline void my_usart_irq(ring_buffer *rb, ring_buffer *wb
53 53
         rb_push_insert(rb, c);
54 54
       #endif
55 55
       #if ENABLED(EMERGENCY_PARSER)
56
-        emergency_parser.update(serial.emergency_state, c);
56
+        if (serial.emergency_parser_enabled())
57
+          emergency_parser.update(serial.emergency_state, c);
57 58
       #endif
58 59
     }
59 60
   }
@@ -73,40 +74,120 @@ static inline __always_inline void my_usart_irq(ring_buffer *rb, ring_buffer *wb
73 74
   }
74 75
 }
75 76
 
76
-#define DEFINE_HWSERIAL_MARLIN(name, n)  \
77
-  MarlinSerial name(USART##n,            \
78
-            BOARD_USART##n##_TX_PIN,     \
79
-            BOARD_USART##n##_RX_PIN);    \
80
-  extern "C" void __irq_usart##n(void) { \
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) {  \
81 99
     my_usart_irq(USART##n->rb, USART##n->wb, USART##n##_BASE, MSerial##n); \
82 100
   }
83 101
 
84 102
 #define DEFINE_HWSERIAL_UART_MARLIN(name, n) \
85 103
   MarlinSerial name(UART##n,                 \
86
-            BOARD_USART##n##_TX_PIN,         \
87
-            BOARD_USART##n##_RX_PIN);        \
104
+          BOARD_USART##n##_TX_PIN,           \
105
+          BOARD_USART##n##_RX_PIN,           \
106
+          serial_handles_emergency(n));      \
88 107
   extern "C" void __irq_usart##n(void) {     \
89
-    my_usart_irq(USART##n->rb, USART##n->wb, USART##n##_BASE, MSerial##n); \
108
+    my_usart_irq(UART##n->rb, UART##n->wb, UART##n##_BASE, MSerial##n); \
90 109
   }
91 110
 
92
-#if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1 || DGUS_SERIAL_PORT == 1
93
-  DEFINE_HWSERIAL_MARLIN(MSerial1, 1);
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);
94 120
 #endif
95 121
 
96
-#if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 || DGUS_SERIAL_PORT == 2
97
-  DEFINE_HWSERIAL_MARLIN(MSerial2, 2);
98
-#endif
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; }
99 128
 
100
-#if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 || DGUS_SERIAL_PORT == 3
101
-  DEFINE_HWSERIAL_MARLIN(MSerial3, 3);
102
-#endif
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");
103 131
 
104
-#if SERIAL_PORT == 4 || SERIAL_PORT_2 == 4 || DGUS_SERIAL_PORT == 4
105
-  DEFINE_HWSERIAL_UART_MARLIN(MSerial4, 4);
106
-#endif
132
+// If you encounter this error, replace SerialX with MSerialX, for example MSerial3.
107 133
 
108
-#if SERIAL_PORT == 5 || SERIAL_PORT_2 == 5 || DGUS_SERIAL_PORT == 5
109
-  DEFINE_HWSERIAL_UART_MARLIN(MSerial5, 5);
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);
110 191
 #endif
111 192
 
112 193
 #endif // __STM32F1__

+ 13
- 8
Marlin/src/HAL/STM32F1/MarlinSerial.h ファイルの表示

@@ -35,15 +35,22 @@
35 35
 
36 36
 class MarlinSerial : public HardwareSerial {
37 37
 public:
38
-  MarlinSerial(struct usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin) :
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)) :
39 45
     HardwareSerial(usart_device, tx_pin, rx_pin)
40 46
     #if ENABLED(EMERGENCY_PARSER)
47
+      , ep_enabled(ep_capable)
41 48
       , emergency_state(EmergencyParser::State::EP_RESET)
42 49
     #endif
43 50
     { }
44 51
 
45 52
   #ifdef UART_IRQ_PRIO
46
-    // shadow the parent methods to set irq priority after the begin
53
+    // Shadow the parent methods to set IRQ priority after begin()
47 54
     void begin(uint32 baud) {
48 55
       MarlinSerial::begin(baud, SERIAL_8N1);
49 56
     }
@@ -53,14 +60,12 @@ public:
53 60
       nvic_irq_set_priority(c_dev()->irq_num, UART_IRQ_PRIO);
54 61
     }
55 62
   #endif
56
-
57
-  #if ENABLED(EMERGENCY_PARSER)
58
-    EmergencyParser::State emergency_state;
59
-  #endif
60 63
 };
61 64
 
62 65
 extern MarlinSerial MSerial1;
63 66
 extern MarlinSerial MSerial2;
64 67
 extern MarlinSerial MSerial3;
65
-extern MarlinSerial MSerial4;
66
-extern MarlinSerial MSerial5;
68
+#if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY)
69
+  extern MarlinSerial MSerial4;
70
+  extern MarlinSerial MSerial5;
71
+#endif

+ 1
- 0
Marlin/src/HAL/STM32F1/msc_sd.h ファイルの表示

@@ -32,6 +32,7 @@ public:
32 32
 
33 33
   #if ENABLED(EMERGENCY_PARSER)
34 34
     EmergencyParser::State emergency_state;
35
+    inline bool emergency_parser_enabled() { return true; }
35 36
   #endif
36 37
 };
37 38
 

+ 8
- 8
Marlin/src/HAL/STM32_F4_F7/HAL.h ファイルの表示

@@ -72,15 +72,15 @@
72 72
   #endif
73 73
 #endif
74 74
 
75
-#ifdef DGUS_SERIAL_PORT
76
-  #if defined(STM32F4) && DGUS_SERIAL_PORT == 0
77
-    #error "DGUS_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
78
-  #elif DGUS_SERIAL_PORT == -1
79
-    #define DGUS_SERIAL SerialUSB
80
-  #elif WITHIN(DGUS_SERIAL_PORT, 0, 6)
81
-    #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT)
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)
82 82
   #else
83
-    #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."
84 84
   #endif
85 85
 #endif
86 86
 

+ 34
- 0
Marlin/src/inc/Conditionals_adv.h ファイルの表示

@@ -422,3 +422,37 @@
422 422
 #if ANY(AUTO_BED_LEVELING_UBL, AUTO_BED_LEVELING_LINEAR, Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
423 423
   #define NEED_LSF 1
424 424
 #endif
425
+
426
+// Flag the indexed serial ports that are in use
427
+#define ANY_SERIAL_IS(N) (defined(SERIAL_PORT) && SERIAL_PORT == (N)) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == (N)) || (defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == (N))
428
+#if ANY_SERIAL_IS(-1)
429
+  #define USING_SERIAL_DEFAULT
430
+#endif
431
+#if ANY_SERIAL_IS(0)
432
+  #define USING_SERIAL_0 1
433
+#endif
434
+#if ANY_SERIAL_IS(1)
435
+  #define USING_SERIAL_1 1
436
+#endif
437
+#if ANY_SERIAL_IS(2)
438
+  #define USING_SERIAL_2 1
439
+#endif
440
+#if ANY_SERIAL_IS(3)
441
+  #define USING_SERIAL_3 1
442
+#endif
443
+#if ANY_SERIAL_IS(4)
444
+  #define USING_SERIAL_4 1
445
+#endif
446
+#if ANY_SERIAL_IS(5)
447
+  #define USING_SERIAL_5 1
448
+#endif
449
+#if ANY_SERIAL_IS(6)
450
+  #define USING_SERIAL_6 1
451
+#endif
452
+#if ANY_SERIAL_IS(7)
453
+  #define USING_SERIAL_7 1
454
+#endif
455
+#if ANY_SERIAL_IS(8)
456
+  #define USING_SERIAL_8 1
457
+#endif
458
+#undef ANY_SERIAL_IS

+ 13
- 20
Marlin/src/inc/SanityCheck.h ファイルの表示

@@ -477,6 +477,10 @@
477 477
   #error "HOME_USING_SPREADCYCLE is now obsolete. Please remove it from Configuration_adv.h."
478 478
 #elif defined(DGUS_LCD)
479 479
   #error "DGUS_LCD is now DGUS_LCD_UI_(ORIGIN|FYSETC|HIPRECY). Please update your configuration."
480
+#elif defined(DGUS_SERIAL_PORT)
481
+  #error "DGUS_SERIAL_PORT is now LCD_SERIAL_PORT. Please update your configuration."
482
+#elif defined(DGUS_BAUDRATE)
483
+  #error "DGUS_BAUDRATE is now LCD_BAUDRATE. Please update your configuration."
480 484
 #elif defined(X_DUAL_ENDSTOPS_ADJUSTMENT)
481 485
   #error "X_DUAL_ENDSTOPS_ADJUSTMENT is now X2_ENDSTOP_ADJUSTMENT. Please update Configuration_adv.h."
482 486
 #elif defined(Y_DUAL_ENDSTOPS_ADJUSTMENT)
@@ -2281,31 +2285,20 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
2281 2285
 /**
2282 2286
  * Serial displays require a dedicated serial port
2283 2287
  */
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
2288
+#ifdef LCD_SERIAL_PORT
2289
+  #if LCD_SERIAL_PORT == SERIAL_PORT
2296 2290
     #error "LCD_SERIAL_PORT cannot be the same as SERIAL_PORT. Please update your configuration."
2297 2291
   #elif defined(SERIAL_PORT_2) && LCD_SERIAL_PORT == SERIAL_PORT_2
2298 2292
     #error "LCD_SERIAL_PORT cannot be the same as SERIAL_PORT_2. Please update your configuration."
2299 2293
   #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."
2294
+#else
2295
+  #if HAS_DGUS_LCD
2296
+    #error "The DGUS LCD requires LCD_SERIAL_PORT to be defined in Configuration.h"
2297
+  #elif EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON)
2298
+    #error "The ANYCUBIC LCD requires LCD_SERIAL_PORT to be defined in Configuration.h"
2299
+  #elif ENABLED(MALYAN_LCD)
2300
+    #error "MALYAN_LCD requires LCD_SERIAL_PORT to be defined in Configuration.h"
2307 2301
   #endif
2308
-  #define ANYCUBIC_LCD_SERIAL anycubicLcdSerial
2309 2302
 #endif
2310 2303
 
2311 2304
 /**

+ 14
- 11
Marlin/src/lcd/extui/anycubic_chiron_lcd.cpp ファイルの表示

@@ -53,12 +53,12 @@ static bool is_printing_from_sd = false;
53 53
 static bool is_out_of_filament = false;
54 54
 
55 55
 static void sendNewLine(void) {
56
-  ANYCUBIC_LCD_SERIAL.write('\r');
57
-  ANYCUBIC_LCD_SERIAL.write('\n');
56
+  LCD_SERIAL.write('\r');
57
+  LCD_SERIAL.write('\n');
58 58
 }
59 59
 
60 60
 static void send(const char *str) {
61
-  ANYCUBIC_LCD_SERIAL.print(str);
61
+  LCD_SERIAL.print(str);
62 62
 }
63 63
 
64 64
 static void sendLine(const char *str) {
@@ -68,7 +68,7 @@ static void sendLine(const char *str) {
68 68
 
69 69
 static void send_P(PGM_P str) {
70 70
   while (const char c = pgm_read_byte(str++))
71
-    ANYCUBIC_LCD_SERIAL.write(c);
71
+    LCD_SERIAL.write(c);
72 72
 }
73 73
 
74 74
 static void sendLine_P(PGM_P str) {
@@ -78,23 +78,23 @@ static void sendLine_P(PGM_P str) {
78 78
 
79 79
 static void sendValue_P(PGM_P prefix, int value) {
80 80
   send_P(prefix);
81
-  ANYCUBIC_LCD_SERIAL.print(value);
81
+  LCD_SERIAL.print(value);
82 82
 }
83 83
 
84 84
 static void sendValue_P(PGM_P prefix, float value) {
85 85
   send_P(prefix);
86
-  ANYCUBIC_LCD_SERIAL.print(value);
86
+  LCD_SERIAL.print(value);
87 87
 }
88 88
 
89 89
 static void sendValueLine_P(PGM_P prefix, int value) {
90 90
   send_P(prefix);
91
-  ANYCUBIC_LCD_SERIAL.print(value);
91
+  LCD_SERIAL.print(value);
92 92
   sendNewLine();
93 93
 }
94 94
 
95 95
 static void sendValueLine_P(PGM_P prefix, float value) {
96 96
   send_P(prefix);
97
-  ANYCUBIC_LCD_SERIAL.print(value);
97
+  LCD_SERIAL.print(value);
98 98
   sendNewLine();
99 99
 }
100 100
 
@@ -426,8 +426,8 @@ namespace ExtUI {
426 426
     static char rxBuffer[RX_LEN_MAX+1];
427 427
     static uint8_t rxLen = 0;
428 428
 
429
-    while (ANYCUBIC_LCD_SERIAL.available()) {
430
-      const char c = ANYCUBIC_LCD_SERIAL.read();
429
+    while (LCD_SERIAL.available()) {
430
+      const char c = LCD_SERIAL.read();
431 431
       switch (c) {
432 432
         case '\r': case '\n':
433 433
           if (rxLen > 0 && rxLen <= RX_LEN_MAX) {
@@ -466,7 +466,10 @@ namespace ExtUI {
466 466
   }
467 467
 
468 468
   void onStartup() {
469
-    ANYCUBIC_LCD_SERIAL.begin(115200);
469
+    #ifndef LCD_BAUDRATE
470
+      #define LCD_BAUDRATE 115200
471
+    #endif
472
+    LCD_SERIAL.begin(LCD_BAUDRATE);
470 473
     sendNewLine();
471 474
     SENDLINE_PGM("J17"); // Reset
472 475
     delay_ms(10);

+ 9
- 9
Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp ファイルの表示

@@ -59,12 +59,12 @@ char *itostr2(const uint8_t &x) {
59 59
 }
60 60
 
61 61
 static void sendNewLine(void) {
62
-  ANYCUBIC_LCD_SERIAL.write('\r');
63
-  ANYCUBIC_LCD_SERIAL.write('\n');
62
+  LCD_SERIAL.write('\r');
63
+  LCD_SERIAL.write('\n');
64 64
 }
65 65
 
66 66
 static void send(const char *str) {
67
-  ANYCUBIC_LCD_SERIAL.print(str);
67
+  LCD_SERIAL.print(str);
68 68
 }
69 69
 
70 70
 static void sendLine(const char *str) {
@@ -74,7 +74,7 @@ static void sendLine(const char *str) {
74 74
 
75 75
 static void send_P(PGM_P str) {
76 76
   while (const char c = pgm_read_byte(str++))
77
-    ANYCUBIC_LCD_SERIAL.write(c);
77
+    LCD_SERIAL.write(c);
78 78
 }
79 79
 
80 80
 static void sendLine_P(PGM_P str) {
@@ -576,8 +576,8 @@ void AnycubicTFTClass::OnPrintTimerStopped() {
576 576
 
577 577
 void AnycubicTFTClass::GetCommandFromTFT() {
578 578
   char *starpos = NULL;
579
-  while (ANYCUBIC_LCD_SERIAL.available() > 0  && TFTbuflen < TFTBUFSIZE) {
580
-    serial3_char = ANYCUBIC_LCD_SERIAL.read();
579
+  while (LCD_SERIAL.available() > 0  && TFTbuflen < TFTBUFSIZE) {
580
+    serial3_char = LCD_SERIAL.read();
581 581
     if (serial3_char == '\n' ||
582 582
         serial3_char == '\r' ||
583 583
         serial3_char == ':'  ||
@@ -639,11 +639,11 @@ void AnycubicTFTClass::GetCommandFromTFT() {
639 639
             float yPostition = ExtUI::getAxisPosition_mm(ExtUI::Y);
640 640
             float zPostition = ExtUI::getAxisPosition_mm(ExtUI::Z);
641 641
             SEND_PGM("A5V X: ");
642
-            ANYCUBIC_LCD_SERIAL.print(xPostition);
642
+            LCD_SERIAL.print(xPostition);
643 643
             SEND_PGM(" Y: ");
644
-            ANYCUBIC_LCD_SERIAL.print(yPostition);
644
+            LCD_SERIAL.print(yPostition);
645 645
             SEND_PGM(" Z: ");
646
-            ANYCUBIC_LCD_SERIAL.print(zPostition);
646
+            LCD_SERIAL.print(zPostition);
647 647
             SENDLINE_PGM("");
648 648
           }
649 649
           break;

+ 26
- 36
Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp ファイルの表示

@@ -59,23 +59,13 @@ constexpr uint8_t DGUS_CMD_READVAR = 0x83;
59 59
   bool dguslcd_local_debug; // = false;
60 60
 #endif
61 61
 
62
-#define dgusserial DGUS_SERIAL
63
-
64 62
 void DGUSDisplay::InitDisplay() {
65
-  dgusserial.begin(DGUS_BAUDRATE);
66
-
67
-  if (true
68
-    #if ENABLED(POWER_LOSS_RECOVERY)
69
-      && !recovery.valid()
70
-    #endif
71
-  )
72
-    RequestScreen(
73
-      #if ENABLED(SHOW_BOOTSCREEN)
74
-        DGUSLCD_SCREEN_BOOT
75
-      #else
76
-        DGUSLCD_SCREEN_MAIN
77
-      #endif
78
-    );
63
+  #ifndef LCD_BAUDRATE
64
+    #define LCD_BAUDRATE 115200
65
+  #endif
66
+  LCD_SERIAL.begin(LCD_BAUDRATE);
67
+  if (TERN1(POWER_LOSS_RECOVERY, !recovery.valid()))
68
+    RequestScreen(TERN(SHOW_BOOTSCREEN, DGUSLCD_SCREEN_BOOT, DGUSLCD_SCREEN_MAIN));
79 69
 }
80 70
 
81 71
 void DGUSDisplay::WriteVariable(uint16_t adr, const void* values, uint8_t valueslen, bool isstr) {
@@ -89,7 +79,7 @@ void DGUSDisplay::WriteVariable(uint16_t adr, const void* values, uint8_t values
89 79
       strend = true;
90 80
       x = ' ';
91 81
     }
92
-    dgusserial.write(x);
82
+    LCD_SERIAL.write(x);
93 83
   }
94 84
 }
95 85
 
@@ -133,41 +123,41 @@ void DGUSDisplay::WriteVariablePGM(uint16_t adr, const void* values, uint8_t val
133 123
       strend = true;
134 124
       x = ' ';
135 125
     }
136
-    dgusserial.write(x);
126
+    LCD_SERIAL.write(x);
137 127
   }
138 128
 }
139 129
 
140 130
 void DGUSDisplay::ProcessRx() {
141 131
 
142 132
   #if ENABLED(DGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS)
143
-    if (!dgusserial.available() && dgusserial.buffer_overruns()) {
133
+    if (!LCD_SERIAL.available() && LCD_SERIAL.buffer_overruns()) {
144 134
       // Overrun, but reset the flag only when the buffer is empty
145 135
       // We want to extract as many as valid datagrams possible...
146 136
       DEBUG_ECHOPGM("OVFL");
147 137
       rx_datagram_state = DGUS_IDLE;
148
-      //dgusserial.reset_rx_overun();
149
-      dgusserial.flush();
138
+      //LCD_SERIAL.reset_rx_overun();
139
+      LCD_SERIAL.flush();
150 140
     }
151 141
   #endif
152 142
 
153 143
   uint8_t receivedbyte;
154
-  while (dgusserial.available()) {
144
+  while (LCD_SERIAL.available()) {
155 145
     switch (rx_datagram_state) {
156 146
 
157 147
       case DGUS_IDLE: // Waiting for the first header byte
158
-        receivedbyte = dgusserial.read();
148
+        receivedbyte = LCD_SERIAL.read();
159 149
         //DEBUG_ECHOPAIR("< ",x);
160 150
         if (DGUS_HEADER1 == receivedbyte) rx_datagram_state = DGUS_HEADER1_SEEN;
161 151
         break;
162 152
 
163 153
       case DGUS_HEADER1_SEEN: // Waiting for the second header byte
164
-        receivedbyte = dgusserial.read();
154
+        receivedbyte = LCD_SERIAL.read();
165 155
         //DEBUG_ECHOPAIR(" ",x);
166 156
         rx_datagram_state = (DGUS_HEADER2 == receivedbyte) ? DGUS_HEADER2_SEEN : DGUS_IDLE;
167 157
         break;
168 158
 
169 159
       case DGUS_HEADER2_SEEN: // Waiting for the length byte
170
-        rx_datagram_len = dgusserial.read();
160
+        rx_datagram_len = LCD_SERIAL.read();
171 161
         DEBUG_ECHOPAIR(" (", rx_datagram_len, ") ");
172 162
 
173 163
         // Telegram min len is 3 (command and one word of payload)
@@ -175,10 +165,10 @@ void DGUSDisplay::ProcessRx() {
175 165
         break;
176 166
 
177 167
       case DGUS_WAIT_TELEGRAM: // wait for complete datagram to arrive.
178
-        if (dgusserial.available() < rx_datagram_len) return;
168
+        if (LCD_SERIAL.available() < rx_datagram_len) return;
179 169
 
180 170
         Initialized = true; // We've talked to it, so we defined it as initialized.
181
-        uint8_t command = dgusserial.read();
171
+        uint8_t command = LCD_SERIAL.read();
182 172
 
183 173
         DEBUG_ECHOPAIR("# ", command);
184 174
 
@@ -186,7 +176,7 @@ void DGUSDisplay::ProcessRx() {
186 176
         unsigned char tmp[rx_datagram_len - 1];
187 177
         unsigned char *ptmp = tmp;
188 178
         while (readlen--) {
189
-          receivedbyte = dgusserial.read();
179
+          receivedbyte = LCD_SERIAL.read();
190 180
           DEBUG_ECHOPAIR(" ", receivedbyte);
191 181
           *ptmp++ = receivedbyte;
192 182
         }
@@ -229,19 +219,19 @@ void DGUSDisplay::ProcessRx() {
229 219
   }
230 220
 }
231 221
 
232
-size_t DGUSDisplay::GetFreeTxBuffer() { return DGUS_SERIAL_GET_TX_BUFFER_FREE(); }
222
+size_t DGUSDisplay::GetFreeTxBuffer() { return SERIAL_GET_TX_BUFFER_FREE(); }
233 223
 
234 224
 void DGUSDisplay::WriteHeader(uint16_t adr, uint8_t cmd, uint8_t payloadlen) {
235
-  dgusserial.write(DGUS_HEADER1);
236
-  dgusserial.write(DGUS_HEADER2);
237
-  dgusserial.write(payloadlen + 3);
238
-  dgusserial.write(cmd);
239
-  dgusserial.write(adr >> 8);
240
-  dgusserial.write(adr & 0xFF);
225
+  LCD_SERIAL.write(DGUS_HEADER1);
226
+  LCD_SERIAL.write(DGUS_HEADER2);
227
+  LCD_SERIAL.write(payloadlen + 3);
228
+  LCD_SERIAL.write(cmd);
229
+  LCD_SERIAL.write(adr >> 8);
230
+  LCD_SERIAL.write(adr & 0xFF);
241 231
 }
242 232
 
243 233
 void DGUSDisplay::WritePGM(const char str[], uint8_t len) {
244
-  while (len--) dgusserial.write(pgm_read_byte(str++));
234
+  while (len--) LCD_SERIAL.write(pgm_read_byte(str++));
245 235
 }
246 236
 
247 237
 void DGUSDisplay::loop() {

+ 1
- 0
buildroot/tests/mks_robin_pro-tests ファイルの表示

@@ -7,6 +7,7 @@
7 7
 set -e
8 8
 
9 9
 use_example_configs Mks/Robin_Pro
10
+opt_enable EMERGENCY_PARSER
10 11
 opt_set SDCARD_CONNECTION LCD
11 12
 opt_set X_DRIVER_TYPE TMC2209
12 13
 opt_set Y_DRIVER_TYPE TMC2130

読み込み中…
キャンセル
保存