소스 검색

Expand serial support in DUE/AVR hals exploiting the templated MarlinSerial classes (#11988)

Eduardo José Tagle 6 년 전
부모
커밋
d6955f25b2

+ 19
- 3
Marlin/src/HAL/HAL_AVR/HAL.h 파일 보기

@@ -79,16 +79,32 @@ typedef int8_t pin_t;
79 79
 
80 80
 //extern uint8_t MCUSR;
81 81
 
82
-#define NUM_SERIAL 1
83
-
82
+// Serial ports
84 83
 #ifdef USBCON
85 84
   #if ENABLED(BLUETOOTH)
86 85
     #define MYSERIAL0 bluetoothSerial
87 86
   #else
88 87
     #define MYSERIAL0 Serial
89 88
   #endif
89
+  #define NUM_SERIAL 1
90 90
 #else
91
-  #define MYSERIAL0 customizedSerial
91
+  #if !WITHIN(SERIAL_PORT, -1, 3)
92
+    #error "SERIAL_PORT must be from -1 to 3"
93
+  #endif
94
+
95
+  #define MYSERIAL0 customizedSerial1
96
+
97
+  #ifdef SERIAL_PORT_2
98
+    #if !WITHIN(SERIAL_PORT_2, -1, 3)
99
+      #error "SERIAL_PORT_2 must be from -1 to 3"
100
+    #elif SERIAL_PORT_2 == SERIAL_PORT
101
+      #error "SERIAL_PORT_2 must be different than SERIAL_PORT"
102
+    #endif
103
+    #define NUM_SERIAL 2
104
+    #define MYSERIAL1 customizedSerial2
105
+  #else
106
+    #define NUM_SERIAL 1
107
+  #endif
92 108
 #endif
93 109
 
94 110
 // --------------------------------------------------------------------------

+ 23
- 4
Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp 파일 보기

@@ -705,18 +705,37 @@
705 705
 
706 706
   // Hookup ISR handlers
707 707
   ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_RX_vect)) {
708
-    MarlinSerial<MarlinSerialCfg>::store_rxd_char();
708
+    MarlinSerial<MarlinSerialCfg1>::store_rxd_char();
709 709
   }
710 710
 
711 711
   ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_UDRE_vect)) {
712
-    MarlinSerial<MarlinSerialCfg>::_tx_udr_empty_irq();
712
+    MarlinSerial<MarlinSerialCfg1>::_tx_udr_empty_irq();
713 713
   }
714 714
 
715 715
   // Preinstantiate
716
-  template class MarlinSerial<MarlinSerialCfg>;
716
+  template class MarlinSerial<MarlinSerialCfg1>;
717 717
 
718 718
   // Instantiate
719
-  MarlinSerial<MarlinSerialCfg> customizedSerial;
719
+  MarlinSerial<MarlinSerialCfg1> customizedSerial1;
720
+
721
+  #ifdef SERIAL_PORT_2
722
+
723
+    // Hookup ISR handlers
724
+    ISR(SERIAL_REGNAME(USART,SERIAL_PORT_2,_RX_vect)) {
725
+      MarlinSerial<MarlinSerialCfg2>::store_rxd_char();
726
+    }
727
+
728
+    ISR(SERIAL_REGNAME(USART,SERIAL_PORT_2,_UDRE_vect)) {
729
+      MarlinSerial<MarlinSerialCfg2>::_tx_udr_empty_irq();
730
+    }
731
+
732
+    // Preinstantiate
733
+    template class MarlinSerial<MarlinSerialCfg2>;
734
+
735
+    // Instantiate
736
+    MarlinSerial<MarlinSerialCfg2> customizedSerial2;
737
+
738
+  #endif
720 739
 
721 740
 #endif // !USBCON && (UBRRH || UBRR0H || UBRR1H || UBRR2H || UBRR3H)
722 741
 

+ 22
- 2
Marlin/src/HAL/HAL_AVR/MarlinSerial.h 파일 보기

@@ -256,7 +256,7 @@
256 256
   };
257 257
 
258 258
   // Serial port configuration
259
-  struct MarlinSerialCfg {
259
+  struct MarlinSerialCfg1 {
260 260
     static constexpr int PORT               = SERIAL_PORT;
261 261
     static constexpr unsigned int RX_SIZE   = RX_BUFFER_SIZE;
262 262
     static constexpr unsigned int TX_SIZE   = TX_BUFFER_SIZE;
@@ -268,7 +268,27 @@
268 268
     static constexpr bool MAX_RX_QUEUED     = bSERIAL_STATS_MAX_RX_QUEUED;
269 269
   };
270 270
 
271
-  extern MarlinSerial<MarlinSerialCfg> customizedSerial;
271
+  extern MarlinSerial<MarlinSerialCfg1> customizedSerial1;
272
+
273
+  #ifdef SERIAL_PORT_2
274
+
275
+    // Serial port configuration
276
+    struct MarlinSerialCfg2 {
277
+      static constexpr int PORT               = SERIAL_PORT_2;
278
+      static constexpr unsigned int RX_SIZE   = RX_BUFFER_SIZE;
279
+      static constexpr unsigned int TX_SIZE   = TX_BUFFER_SIZE;
280
+      static constexpr bool XONOFF            = bSERIAL_XON_XOFF;
281
+      static constexpr bool EMERGENCYPARSER   = bEMERGENCY_PARSER;
282
+      static constexpr bool DROPPED_RX        = bSERIAL_STATS_DROPPED_RX;
283
+      static constexpr bool RX_OVERRUNS       = bSERIAL_STATS_RX_BUFFER_OVERRUNS;
284
+      static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS;
285
+      static constexpr bool MAX_RX_QUEUED     = bSERIAL_STATS_MAX_RX_QUEUED;
286
+    };
287
+
288
+    extern MarlinSerial<MarlinSerialCfg2> customizedSerial2;
289
+
290
+  #endif
291
+
272 292
 
273 293
 #endif // !USBCON
274 294
 

+ 1
- 0
Marlin/src/HAL/HAL_DUE/HAL.cpp 파일 보기

@@ -29,6 +29,7 @@
29 29
 // Includes
30 30
 // --------------------------------------------------------------------------
31 31
 
32
+#include "../../inc/MarlinConfig.h"
32 33
 #include "HAL.h"
33 34
 
34 35
 #include <Wire.h>

+ 19
- 3
Marlin/src/HAL/HAL_DUE/HAL.h 파일 보기

@@ -41,9 +41,25 @@
41 41
 #include "watchdog_Due.h"
42 42
 #include "HAL_timers_Due.h"
43 43
 
44
-#define NUM_SERIAL 1
45
-// Required before the include or compilation fails
46
-#define MYSERIAL0 customizedSerial
44
+// Serial ports
45
+#if !WITHIN(SERIAL_PORT, -1, 3)
46
+  #error "SERIAL_PORT must be from -1 to 3"
47
+#endif
48
+
49
+// MYSERIAL0 required before MarlinSerial includes!
50
+#define MYSERIAL0 customizedSerial1
51
+
52
+#ifdef SERIAL_PORT_2
53
+  #if !WITHIN(SERIAL_PORT_2, -1, 3)
54
+    #error "SERIAL_PORT_2 must be from -1 to 3"
55
+  #elif SERIAL_PORT_2 == SERIAL_PORT
56
+    #error "SERIAL_PORT_2 must be different than SERIAL_PORT"
57
+  #endif
58
+  #define NUM_SERIAL 2
59
+  #define MYSERIAL1 customizedSerial2
60
+#else
61
+  #define NUM_SERIAL 1
62
+#endif
47 63
 
48 64
 #include "MarlinSerial_Due.h"
49 65
 #include "MarlinSerialUSB_Due.h"

+ 1
- 1
Marlin/src/HAL/HAL_DUE/HAL_timers_Due.cpp 파일 보기

@@ -31,7 +31,7 @@
31 31
 // --------------------------------------------------------------------------
32 32
 // Includes
33 33
 // --------------------------------------------------------------------------
34
-
34
+#include "../../inc/MarlinConfig.h"
35 35
 #include "HAL.h"
36 36
 
37 37
 #include "HAL_timers_Due.h"

+ 1
- 0
Marlin/src/HAL/HAL_DUE/InterruptVectors_Due.cpp 파일 보기

@@ -32,6 +32,7 @@
32 32
  */
33 33
 #ifdef ARDUINO_ARCH_SAM
34 34
 
35
+#include "../../inc/MarlinConfig.h"
35 36
 #include "HAL.h"
36 37
 #include "InterruptVectors_Due.h"
37 38
 

+ 1
- 1
Marlin/src/HAL/HAL_DUE/MarlinSerialUSB_Due.cpp 파일 보기

@@ -285,7 +285,7 @@ void MarlinSerialUSB::printFloat(double number, uint8_t digits) {
285 285
 }
286 286
 
287 287
 // Preinstantiate
288
-MarlinSerialUSB customizedSerial;
288
+MarlinSerialUSB customizedSerial1;
289 289
 
290 290
 #endif // SERIAL_PORT == -1
291 291
 

+ 1
- 1
Marlin/src/HAL/HAL_DUE/MarlinSerialUSB_Due.h 파일 보기

@@ -89,7 +89,7 @@ private:
89 89
   static void printFloat(double, uint8_t);
90 90
 };
91 91
 
92
-extern MarlinSerialUSB customizedSerial;
92
+extern MarlinSerialUSB customizedSerial1;
93 93
 
94 94
 #endif // SERIAL_PORT == -1
95 95
 #endif // MARLINSERIAL_DUE_H

+ 485
- 475
Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.cpp
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
파일 보기


+ 34
- 15
Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.h 파일 보기

@@ -31,8 +31,6 @@
31 31
 
32 32
 #include "../shared/MarlinSerial.h"
33 33
 
34
-#if SERIAL_PORT >= 0
35
-
36 34
 #include <WString.h>
37 35
 
38 36
 #define DEC 10
@@ -161,21 +159,42 @@ private:
161 159
   static void printFloat(double, uint8_t);
162 160
 };
163 161
 
164
-// Serial port configuration
165
-struct MarlinSerialCfg {
166
-  static constexpr int PORT               = SERIAL_PORT;
167
-  static constexpr unsigned int RX_SIZE   = RX_BUFFER_SIZE;
168
-  static constexpr unsigned int TX_SIZE   = TX_BUFFER_SIZE;
169
-  static constexpr bool XONOFF            = bSERIAL_XON_XOFF;
170
-  static constexpr bool EMERGENCYPARSER   = bEMERGENCY_PARSER;
171
-  static constexpr bool DROPPED_RX        = bSERIAL_STATS_DROPPED_RX;
172
-  static constexpr bool RX_OVERRUNS       = bSERIAL_STATS_RX_BUFFER_OVERRUNS;
173
-  static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS;
174
-  static constexpr bool MAX_RX_QUEUED     = bSERIAL_STATS_MAX_RX_QUEUED;
175
-};
162
+#if SERIAL_PORT >= 0
163
+
164
+  // Serial port configuration
165
+  struct MarlinSerialCfg1 {
166
+    static constexpr int PORT               = SERIAL_PORT;
167
+    static constexpr unsigned int RX_SIZE   = RX_BUFFER_SIZE;
168
+    static constexpr unsigned int TX_SIZE   = TX_BUFFER_SIZE;
169
+    static constexpr bool XONOFF            = bSERIAL_XON_XOFF;
170
+    static constexpr bool EMERGENCYPARSER   = bEMERGENCY_PARSER;
171
+    static constexpr bool DROPPED_RX        = bSERIAL_STATS_DROPPED_RX;
172
+    static constexpr bool RX_OVERRUNS       = bSERIAL_STATS_RX_BUFFER_OVERRUNS;
173
+    static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS;
174
+    static constexpr bool MAX_RX_QUEUED     = bSERIAL_STATS_MAX_RX_QUEUED;
175
+  };
176 176
 
177
-extern MarlinSerial<MarlinSerialCfg> customizedSerial;
177
+  extern MarlinSerial<MarlinSerialCfg1> customizedSerial1;
178 178
 
179 179
 #endif // SERIAL_PORT >= 0
180 180
 
181
+#ifdef SERIAL_PORT_2
182
+
183
+  // Serial port configuration
184
+  struct MarlinSerialCfg2 {
185
+    static constexpr int PORT               = SERIAL_PORT_2;
186
+    static constexpr unsigned int RX_SIZE   = RX_BUFFER_SIZE;
187
+    static constexpr unsigned int TX_SIZE   = TX_BUFFER_SIZE;
188
+    static constexpr bool XONOFF            = bSERIAL_XON_XOFF;
189
+    static constexpr bool EMERGENCYPARSER   = bEMERGENCY_PARSER;
190
+    static constexpr bool DROPPED_RX        = bSERIAL_STATS_DROPPED_RX;
191
+    static constexpr bool RX_OVERRUNS       = bSERIAL_STATS_RX_BUFFER_OVERRUNS;
192
+    static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS;
193
+    static constexpr bool MAX_RX_QUEUED     = bSERIAL_STATS_MAX_RX_QUEUED;
194
+  };
195
+
196
+  extern MarlinSerial<MarlinSerialCfg2> customizedSerial2;
197
+
198
+#endif
199
+
181 200
 #endif // MARLINSERIAL_DUE_H

+ 1
- 0
Marlin/src/HAL/HAL_DUE/Tone.cpp 파일 보기

@@ -27,6 +27,7 @@
27 27
 
28 28
 #ifdef ARDUINO_ARCH_SAM
29 29
 
30
+#include "../../inc/MarlinConfig.h"
30 31
 #include "HAL.h"
31 32
 #include "HAL_timers_Due.h"
32 33
 

+ 4
- 4
Marlin/src/gcode/control/M111.cpp 파일 보기

@@ -60,19 +60,19 @@ void GcodeSuite::M111() {
60 60
     SERIAL_ECHOPGM(MSG_DEBUG_OFF);
61 61
     #if !defined(__AVR__) || !defined(USBCON)
62 62
       #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
63
-        SERIAL_ECHOPAIR("\nBuffer Overruns: ", customizedSerial.buffer_overruns());
63
+        SERIAL_ECHOPAIR("\nBuffer Overruns: ", MYSERIAL0.buffer_overruns());
64 64
       #endif
65 65
 
66 66
       #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
67
-        SERIAL_ECHOPAIR("\nFraming Errors: ", customizedSerial.framing_errors());
67
+        SERIAL_ECHOPAIR("\nFraming Errors: ", MYSERIAL0.framing_errors());
68 68
       #endif
69 69
 
70 70
       #if ENABLED(SERIAL_STATS_DROPPED_RX)
71
-        SERIAL_ECHOPAIR("\nDropped bytes: ", customizedSerial.dropped());
71
+        SERIAL_ECHOPAIR("\nDropped bytes: ", MYSERIAL0.dropped());
72 72
       #endif
73 73
 
74 74
       #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
75
-        SERIAL_ECHOPAIR("\nMax RX Queue Size: ", customizedSerial.rxMaxEnqueued());
75
+        SERIAL_ECHOPAIR("\nMax RX Queue Size: ", MYSERIAL0.rxMaxEnqueued());
76 76
       #endif
77 77
     #endif //  !defined(__AVR__) || !defined(USBCON)
78 78
   }

+ 2
- 2
Marlin/src/gcode/queue.cpp 파일 보기

@@ -562,11 +562,11 @@ void advance_command_queue() {
562 562
 
563 563
         #if !defined(__AVR__) || !defined(USBCON)
564 564
           #if ENABLED(SERIAL_STATS_DROPPED_RX)
565
-            SERIAL_ECHOLNPAIR("Dropped bytes: ", customizedSerial.dropped());
565
+            SERIAL_ECHOLNPAIR("Dropped bytes: ", MYSERIAL0.dropped());
566 566
           #endif
567 567
 
568 568
           #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
569
-            SERIAL_ECHOLNPAIR("Max RX Queue Size: ", customizedSerial.rxMaxEnqueued());
569
+            SERIAL_ECHOLNPAIR("Max RX Queue Size: ", MYSERIAL0.rxMaxEnqueued());
570 570
           #endif
571 571
         #endif //  !defined(__AVR__) || !defined(USBCON)
572 572
 

Loading…
취소
저장