Browse Source

Template struct simplification for serial (#11990)

AnoNymous 5 years ago
parent
commit
001f26b642

+ 8
- 8
Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp View File

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

+ 7
- 22
Marlin/src/HAL/HAL_AVR/MarlinSerial.h View File

@@ -254,10 +254,10 @@
254 254
       static void printNumber(unsigned long, const uint8_t);
255 255
       static void printFloat(double, uint8_t);
256 256
   };
257
-
258
-  // Serial port configuration
259
-  struct MarlinSerialCfg1 {
260
-    static constexpr int PORT               = SERIAL_PORT;
257
+  
258
+  template <uint8_t serial>
259
+  struct MarlinSerialCfg {
260
+    static constexpr int PORT               = serial;
261 261
     static constexpr unsigned int RX_SIZE   = RX_BUFFER_SIZE;
262 262
     static constexpr unsigned int TX_SIZE   = TX_BUFFER_SIZE;
263 263
     static constexpr bool XONOFF            = bSERIAL_XON_XOFF;
@@ -267,29 +267,14 @@
267 267
     static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS;
268 268
     static constexpr bool MAX_RX_QUEUED     = bSERIAL_STATS_MAX_RX_QUEUED;
269 269
   };
270
-
271
-  extern MarlinSerial<MarlinSerialCfg1> customizedSerial1;
270
+  extern MarlinSerial<MarlinSerialCfg<SERIAL_PORT>> customizedSerial1;
272 271
 
273 272
   #ifdef SERIAL_PORT_2
274 273
 
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
-
274
+    extern MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>> customizedSerial2;
275
+    
290 276
   #endif
291 277
 
292
-
293 278
 #endif // !USBCON
294 279
 
295 280
 // Use the UART for Bluetooth in AT90USB configurations

+ 4
- 4
Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.cpp View File

@@ -631,20 +631,20 @@ void MarlinSerial<Cfg>::printFloat(double number, uint8_t digits) {
631 631
 #if SERIAL_PORT >= 0
632 632
 
633 633
   // Preinstantiate
634
-  template class MarlinSerial<MarlinSerialCfg1>;
634
+  template class MarlinSerial<MarlinSerialCfg<SERIAL_PORT>>;
635 635
 
636 636
   // Instantiate
637
-  MarlinSerial<MarlinSerialCfg1> customizedSerial1;
637
+  MarlinSerial<MarlinSerialCfg<SERIAL_PORT>> customizedSerial1;
638 638
 
639 639
 #endif
640 640
 
641 641
 #ifdef SERIAL_PORT_2
642 642
 
643 643
   // Preinstantiate
644
-  template class MarlinSerial<MarlinSerialCfg2>;
644
+  template class MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>>;
645 645
 
646 646
   // Instantiate
647
-  MarlinSerial<MarlinSerialCfg2> customizedSerial2;
647
+  MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>> customizedSerial2;
648 648
 
649 649
 #endif
650 650
 

+ 19
- 34
Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.h View File

@@ -19,6 +19,7 @@
19 19
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 20
  *
21 21
  */
22
+#pragma once
22 23
 
23 24
 /**
24 25
  * MarlinSerial_Due.h - Hardware serial library for Arduino DUE
@@ -26,9 +27,6 @@
26 27
  * Based on MarlinSerial for AVR, copyright (c) 2006 Nicholas Zambetti.  All right reserved.
27 28
  */
28 29
 
29
-#ifndef MARLINSERIAL_DUE_H
30
-#define MARLINSERIAL_DUE_H
31
-
32 30
 #include "../shared/MarlinSerial.h"
33 31
 
34 32
 #include <WString.h>
@@ -159,42 +157,29 @@ private:
159 157
   static void printFloat(double, uint8_t);
160 158
 };
161 159
 
160
+// Serial port configuration
161
+template <uint8_t serial>
162
+struct MarlinSerialCfg {
163
+  static constexpr int PORT               = serial;
164
+  static constexpr unsigned int RX_SIZE   = RX_BUFFER_SIZE;
165
+  static constexpr unsigned int TX_SIZE   = TX_BUFFER_SIZE;
166
+  static constexpr bool XONOFF            = bSERIAL_XON_XOFF;
167
+  static constexpr bool EMERGENCYPARSER   = bEMERGENCY_PARSER;
168
+  static constexpr bool DROPPED_RX        = bSERIAL_STATS_DROPPED_RX;
169
+  static constexpr bool RX_OVERRUNS       = bSERIAL_STATS_RX_BUFFER_OVERRUNS;
170
+  static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS;
171
+  static constexpr bool MAX_RX_QUEUED     = bSERIAL_STATS_MAX_RX_QUEUED;
172
+};
173
+  
162 174
 #if SERIAL_PORT >= 0
163 175
 
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
-
177
-  extern MarlinSerial<MarlinSerialCfg1> customizedSerial1;
178
-
176
+  extern MarlinSerial<MarlinSerialCfg<SERIAL_PORT>> customizedSerial1;
177
+  
179 178
 #endif // SERIAL_PORT >= 0
180 179
 
181 180
 #ifdef SERIAL_PORT_2
182 181
 
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
-
182
+  extern MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>> customizedSerial2;
183
+  
198 184
 #endif
199 185
 
200
-#endif // MARLINSERIAL_DUE_H

Loading…
Cancel
Save