Browse Source

🧑‍💻 Clarify MSerialUSB, drop HardwareSerial workaround

Scott Lahteine 2 years ago
parent
commit
66e32cb0fa
4 changed files with 33 additions and 24 deletions
  1. 0
    1
      Marlin/src/HAL/AVR/HAL.h
  2. 1
    1
      Marlin/src/HAL/STM32/HAL.cpp
  3. 31
    21
      Marlin/src/HAL/STM32/HAL.h
  4. 1
    1
      Marlin/src/core/serial_hook.h

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

@@ -32,7 +32,6 @@
32 32
 #ifdef USBCON
33 33
   #include <HardwareSerial.h>
34 34
 #else
35
-  #define HardwareSerial_h // Hack to prevent HardwareSerial.h header inclusion
36 35
   #include "MarlinSerial.h"
37 36
 #endif
38 37
 

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

@@ -31,7 +31,7 @@
31 31
 #include "../shared/Delay.h"
32 32
 
33 33
 #ifdef USBCON
34
-  DefaultSerial1 MSerial0(false, SerialUSB);
34
+  DefaultSerial1 MSerialUSB(false, SerialUSB);
35 35
 #endif
36 36
 
37 37
 #if ENABLED(SRAM_EEPROM_EMULATION)

+ 31
- 21
Marlin/src/HAL/STM32/HAL.h View File

@@ -51,57 +51,67 @@
51 51
   #include <USBSerial.h>
52 52
   #include "../../core/serial_hook.h"
53 53
   typedef ForwardSerial1Class< decltype(SerialUSB) > DefaultSerial1;
54
-  extern DefaultSerial1 MSerial0;
54
+  extern DefaultSerial1 MSerialUSB;
55 55
 #endif
56 56
 
57 57
 #define _MSERIAL(X) MSerial##X
58 58
 #define MSERIAL(X) _MSERIAL(X)
59 59
 
60
-#if SERIAL_PORT == -1
61
-  #define MYSERIAL1 MSerial0
62
-#elif WITHIN(SERIAL_PORT, 1, 6)
60
+#if WITHIN(SERIAL_PORT, 1, 6)
63 61
   #define MYSERIAL1 MSERIAL(SERIAL_PORT)
62
+#elif !defined(USBCON)
63
+  #error "SERIAL_PORT must be from 1 to 6."
64
+#elif SERIAL_PORT == -1
65
+  #define MYSERIAL1 MSerialUSB
64 66
 #else
65
-  #error "SERIAL_PORT must be from 1 to 6. You can also use -1 if the board supports Native USB."
67
+  #error "SERIAL_PORT must be from 1 to 6, or -1 for Native USB."
66 68
 #endif
67 69
 
68 70
 #ifdef SERIAL_PORT_2
69
-  #if SERIAL_PORT_2 == -1
70
-    #define MYSERIAL2 MSerial0
71
-  #elif WITHIN(SERIAL_PORT_2, 1, 6)
71
+  #if WITHIN(SERIAL_PORT_2, 1, 6)
72 72
     #define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
73
+  #elif !defined(USBCON)
74
+    #error "SERIAL_PORT must be from 1 to 6."
75
+  #elif SERIAL_PORT_2 == -1
76
+    #define MYSERIAL2 MSerialUSB
73 77
   #else
74
-    #error "SERIAL_PORT_2 must be from 1 to 6. You can also use -1 if the board supports Native USB."
78
+    #error "SERIAL_PORT_2 must be from 1 to 6, or -1 for Native USB."
75 79
   #endif
76 80
 #endif
77 81
 
78 82
 #ifdef SERIAL_PORT_3
79
-  #if SERIAL_PORT_3 == -1
80
-    #define MYSERIAL3 MSerial0
81
-  #elif WITHIN(SERIAL_PORT_3, 1, 6)
83
+  #if WITHIN(SERIAL_PORT_3, 1, 6)
82 84
     #define MYSERIAL3 MSERIAL(SERIAL_PORT_3)
85
+  #elif !defined(USBCON)
86
+    #error "SERIAL_PORT must be from 1 to 6."
87
+  #elif SERIAL_PORT_3 == -1
88
+    #define MYSERIAL3 MSerialUSB
83 89
   #else
84
-    #error "SERIAL_PORT_3 must be from 1 to 6. You can also use -1 if the board supports Native USB."
90
+    #error "SERIAL_PORT_3 must be from 1 to 6, or -1 for Native USB."
85 91
   #endif
86 92
 #endif
87 93
 
88 94
 #ifdef MMU2_SERIAL_PORT
89
-  #if MMU2_SERIAL_PORT == -1
90
-    #define MMU2_SERIAL MSerial0
91
-  #elif WITHIN(MMU2_SERIAL_PORT, 1, 6)
95
+  #if WITHIN(MMU2_SERIAL_PORT, 1, 6)
92 96
     #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
97
+  #elif !defined(USBCON)
98
+    #error "SERIAL_PORT must be from 1 to 6."
99
+  #elif MMU2_SERIAL_PORT == -1
100
+    #define MMU2_SERIAL MSerialUSB
93 101
   #else
94
-    #error "MMU2_SERIAL_PORT must be from 1 to 6. You can also use -1 if the board supports Native USB."
102
+    #error "MMU2_SERIAL_PORT must be from 1 to 6, or -1 for Native USB."
95 103
   #endif
96 104
 #endif
97 105
 
98 106
 #ifdef LCD_SERIAL_PORT
99
-  #if LCD_SERIAL_PORT == -1
100
-    #define LCD_SERIAL MSerial0
101
-  #elif WITHIN(LCD_SERIAL_PORT, 1, 6)
107
+  #if WITHIN(LCD_SERIAL_PORT, 1, 6)
102 108
     #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
109
+  #elif !defined(USBCON)
110
+    #error "SERIAL_PORT must be from 1 to 6."
111
+  #elif LCD_SERIAL_PORT == -1
112
+    #define LCD_SERIAL MSerialUSB
103 113
   #else
104
-    #error "LCD_SERIAL_PORT must be from 1 to 6. You can also use -1 if the board supports Native USB."
114
+    #error "LCD_SERIAL_PORT must be from 1 to 6, or -1 for Native USB."
105 115
   #endif
106 116
   #if HAS_DGUS_LCD
107 117
     #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite()

+ 1
- 1
Marlin/src/core/serial_hook.h View File

@@ -300,7 +300,7 @@ struct MultiSerial : public SerialBase< MultiSerial< REPEAT(NUM_SERIAL, _S_NAME)
300 300
 // Build the actual serial object depending on current configuration
301 301
 #define Serial1Class TERN(SERIAL_RUNTIME_HOOK, RuntimeSerial, BaseSerial)
302 302
 #define ForwardSerial1Class TERN(SERIAL_RUNTIME_HOOK, RuntimeSerial, ForwardSerial)
303
-#ifdef HAS_MULTI_SERIAL
303
+#if HAS_MULTI_SERIAL
304 304
   #define Serial2Class ConditionalSerial
305 305
   #if NUM_SERIAL >= 3
306 306
     #define Serial3Class ConditionalSerial

Loading…
Cancel
Save