Browse Source

Don't create unused Serial Port instances (#21066)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
Giuliano Zaro 3 years ago
parent
commit
8fd88eee2b
No account linked to committer's email address
4 changed files with 37 additions and 11 deletions
  1. 13
    6
      Marlin/src/HAL/DUE/HAL.cpp
  2. 2
    2
      Marlin/src/HAL/DUE/HAL.h
  3. 15
    2
      Marlin/src/HAL/SAMD51/HAL.cpp
  4. 7
    1
      Marlin/src/HAL/SAMD51/HAL.h

+ 13
- 6
Marlin/src/HAL/DUE/HAL.cpp View File

@@ -102,11 +102,18 @@ uint16_t HAL_adc_get_result() {
102 102
   return HAL_adc_result;
103 103
 }
104 104
 
105
-// Forward the default serial port
106
-DefaultSerial MSerial(false, Serial);
107
-
108
-DefaultSerial1 MSerial1(false, Serial1);
109
-DefaultSerial2 MSerial2(false, Serial2);
110
-DefaultSerial3 MSerial3(false, Serial3);
105
+// Forward the default serial ports
106
+#if ANY_SERIAL_IS(0)
107
+  DefaultSerial MSerial(false, Serial);
108
+#endif
109
+#if ANY_SERIAL_IS(1)
110
+  DefaultSerial1 MSerial1(false, Serial1);
111
+#endif
112
+#if ANY_SERIAL_IS(2)
113
+  DefaultSerial2 MSerial2(false, Serial2);
114
+#endif
115
+#if ANY_SERIAL_IS(3)
116
+  DefaultSerial3 MSerial3(false, Serial3);
117
+#endif
111 118
 
112 119
 #endif // ARDUINO_ARCH_SAM

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

@@ -37,12 +37,12 @@
37 37
 #include <stdint.h>
38 38
 
39 39
 #include "../../core/serial_hook.h"
40
-typedef ForwardSerial0Type< decltype(Serial) > DefaultSerial;
41
-extern DefaultSerial MSerial;
42 40
 
41
+typedef ForwardSerial0Type< decltype(Serial) > DefaultSerial;
43 42
 typedef ForwardSerial0Type< decltype(Serial1) > DefaultSerial1;
44 43
 typedef ForwardSerial0Type< decltype(Serial2) > DefaultSerial2;
45 44
 typedef ForwardSerial0Type< decltype(Serial3) > DefaultSerial3;
45
+extern DefaultSerial MSerial;
46 46
 extern DefaultSerial1 MSerial1;
47 47
 extern DefaultSerial2 MSerial2;
48 48
 extern DefaultSerial3 MSerial3;

+ 15
- 2
Marlin/src/HAL/SAMD51/HAL.cpp View File

@@ -25,8 +25,21 @@
25 25
 #include <wiring_private.h>
26 26
 
27 27
 #ifdef ADAFRUIT_GRAND_CENTRAL_M4
28
-  DefaultSerial MSerial(false, Serial);
29
-  DefaultSerial1 MSerial1(false, Serial1);
28
+  #if ANY_SERIAL_IS(-1)
29
+    DefaultSerial MSerial(false, Serial);
30
+  #endif
31
+  #if ANY_SERIAL_IS(0)
32
+    DefaultSerial1 MSerial1(false, Serial1);
33
+  #endif
34
+  #if ANY_SERIAL_IS(1)
35
+    DefaultSerial2 MSerial2(false, Serial2);
36
+  #endif
37
+  #if ANY_SERIAL_IS(2)
38
+    DefaultSerial3 MSerial3(false, Serial3);
39
+  #endif
40
+  #if ANY_SERIAL_IS(3)
41
+    DefaultSerial4 MSerial4(false, Serial4);
42
+  #endif
30 43
 #endif
31 44
 
32 45
 // ------------------------

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

@@ -33,9 +33,15 @@
33 33
 
34 34
   // Serial ports
35 35
   typedef ForwardSerial0Type< decltype(Serial) > DefaultSerial;
36
-  extern DefaultSerial MSerial;
37 36
   typedef ForwardSerial0Type< decltype(Serial1) > DefaultSerial1;
37
+  typedef ForwardSerial0Type< decltype(Serial2) > DefaultSerial2;
38
+  typedef ForwardSerial0Type< decltype(Serial3) > DefaultSerial3;
39
+  typedef ForwardSerial0Type< decltype(Serial4) > DefaultSerial4;
40
+  extern DefaultSerial MSerial;
38 41
   extern DefaultSerial1 MSerial1;
42
+  extern DefaultSerial2 MSerial2;
43
+  extern DefaultSerial3 MSerial3;
44
+  extern DefaultSerial4 MSerial4;
39 45
 
40 46
   // MYSERIAL0 required before MarlinSerial includes!
41 47
 

Loading…
Cancel
Save