From 001f26b642e2957371b1eb988c0c14a3c6dc61ee Mon Sep 17 00:00:00 2001 From: AnoNymous Date: Wed, 3 Oct 2018 18:01:21 +0200 Subject: [PATCH] Template struct simplification for serial (#11990) --- Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp | 16 +++---- Marlin/src/HAL/HAL_AVR/MarlinSerial.h | 29 +++-------- Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.cpp | 8 ++-- Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.h | 53 ++++++++------------- 4 files changed, 38 insertions(+), 68 deletions(-) diff --git a/Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp b/Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp index c0181296e..ea5c489f6 100644 --- a/Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp +++ b/Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp @@ -705,35 +705,35 @@ // Hookup ISR handlers ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_RX_vect)) { - MarlinSerial::store_rxd_char(); + MarlinSerial>::store_rxd_char(); } ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_UDRE_vect)) { - MarlinSerial::_tx_udr_empty_irq(); + MarlinSerial>::_tx_udr_empty_irq(); } // Preinstantiate - template class MarlinSerial; + template class MarlinSerial>; // Instantiate - MarlinSerial customizedSerial1; + MarlinSerial> customizedSerial1; #ifdef SERIAL_PORT_2 // Hookup ISR handlers ISR(SERIAL_REGNAME(USART,SERIAL_PORT_2,_RX_vect)) { - MarlinSerial::store_rxd_char(); + MarlinSerial>::store_rxd_char(); } ISR(SERIAL_REGNAME(USART,SERIAL_PORT_2,_UDRE_vect)) { - MarlinSerial::_tx_udr_empty_irq(); + MarlinSerial>::_tx_udr_empty_irq(); } // Preinstantiate - template class MarlinSerial; + template class MarlinSerial>; // Instantiate - MarlinSerial customizedSerial2; + MarlinSerial> customizedSerial2; #endif diff --git a/Marlin/src/HAL/HAL_AVR/MarlinSerial.h b/Marlin/src/HAL/HAL_AVR/MarlinSerial.h index 399bed97c..4ddab4d6f 100644 --- a/Marlin/src/HAL/HAL_AVR/MarlinSerial.h +++ b/Marlin/src/HAL/HAL_AVR/MarlinSerial.h @@ -254,10 +254,10 @@ static void printNumber(unsigned long, const uint8_t); static void printFloat(double, uint8_t); }; - - // Serial port configuration - struct MarlinSerialCfg1 { - static constexpr int PORT = SERIAL_PORT; + + template + struct MarlinSerialCfg { + static constexpr int PORT = serial; static constexpr unsigned int RX_SIZE = RX_BUFFER_SIZE; static constexpr unsigned int TX_SIZE = TX_BUFFER_SIZE; static constexpr bool XONOFF = bSERIAL_XON_XOFF; @@ -267,29 +267,14 @@ static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS; static constexpr bool MAX_RX_QUEUED = bSERIAL_STATS_MAX_RX_QUEUED; }; - - extern MarlinSerial customizedSerial1; + extern MarlinSerial> customizedSerial1; #ifdef SERIAL_PORT_2 - // Serial port configuration - struct MarlinSerialCfg2 { - static constexpr int PORT = SERIAL_PORT_2; - static constexpr unsigned int RX_SIZE = RX_BUFFER_SIZE; - static constexpr unsigned int TX_SIZE = TX_BUFFER_SIZE; - static constexpr bool XONOFF = bSERIAL_XON_XOFF; - static constexpr bool EMERGENCYPARSER = bEMERGENCY_PARSER; - static constexpr bool DROPPED_RX = bSERIAL_STATS_DROPPED_RX; - static constexpr bool RX_OVERRUNS = bSERIAL_STATS_RX_BUFFER_OVERRUNS; - static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS; - static constexpr bool MAX_RX_QUEUED = bSERIAL_STATS_MAX_RX_QUEUED; - }; - - extern MarlinSerial customizedSerial2; - + extern MarlinSerial> customizedSerial2; + #endif - #endif // !USBCON // Use the UART for Bluetooth in AT90USB configurations diff --git a/Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.cpp b/Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.cpp index 853cc60f3..cbcd9dcd3 100644 --- a/Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.cpp +++ b/Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.cpp @@ -631,20 +631,20 @@ void MarlinSerial::printFloat(double number, uint8_t digits) { #if SERIAL_PORT >= 0 // Preinstantiate - template class MarlinSerial; + template class MarlinSerial>; // Instantiate - MarlinSerial customizedSerial1; + MarlinSerial> customizedSerial1; #endif #ifdef SERIAL_PORT_2 // Preinstantiate - template class MarlinSerial; + template class MarlinSerial>; // Instantiate - MarlinSerial customizedSerial2; + MarlinSerial> customizedSerial2; #endif diff --git a/Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.h b/Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.h index 609d4ab56..6a95897b9 100644 --- a/Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.h +++ b/Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.h @@ -19,6 +19,7 @@ * along with this program. If not, see . * */ +#pragma once /** * MarlinSerial_Due.h - Hardware serial library for Arduino DUE @@ -26,9 +27,6 @@ * Based on MarlinSerial for AVR, copyright (c) 2006 Nicholas Zambetti. All right reserved. */ -#ifndef MARLINSERIAL_DUE_H -#define MARLINSERIAL_DUE_H - #include "../shared/MarlinSerial.h" #include @@ -159,42 +157,29 @@ private: static void printFloat(double, uint8_t); }; +// Serial port configuration +template +struct MarlinSerialCfg { + static constexpr int PORT = serial; + static constexpr unsigned int RX_SIZE = RX_BUFFER_SIZE; + static constexpr unsigned int TX_SIZE = TX_BUFFER_SIZE; + static constexpr bool XONOFF = bSERIAL_XON_XOFF; + static constexpr bool EMERGENCYPARSER = bEMERGENCY_PARSER; + static constexpr bool DROPPED_RX = bSERIAL_STATS_DROPPED_RX; + static constexpr bool RX_OVERRUNS = bSERIAL_STATS_RX_BUFFER_OVERRUNS; + static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS; + static constexpr bool MAX_RX_QUEUED = bSERIAL_STATS_MAX_RX_QUEUED; +}; + #if SERIAL_PORT >= 0 - // Serial port configuration - struct MarlinSerialCfg1 { - static constexpr int PORT = SERIAL_PORT; - static constexpr unsigned int RX_SIZE = RX_BUFFER_SIZE; - static constexpr unsigned int TX_SIZE = TX_BUFFER_SIZE; - static constexpr bool XONOFF = bSERIAL_XON_XOFF; - static constexpr bool EMERGENCYPARSER = bEMERGENCY_PARSER; - static constexpr bool DROPPED_RX = bSERIAL_STATS_DROPPED_RX; - static constexpr bool RX_OVERRUNS = bSERIAL_STATS_RX_BUFFER_OVERRUNS; - static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS; - static constexpr bool MAX_RX_QUEUED = bSERIAL_STATS_MAX_RX_QUEUED; - }; - - extern MarlinSerial customizedSerial1; - + extern MarlinSerial> customizedSerial1; + #endif // SERIAL_PORT >= 0 #ifdef SERIAL_PORT_2 - // Serial port configuration - struct MarlinSerialCfg2 { - static constexpr int PORT = SERIAL_PORT_2; - static constexpr unsigned int RX_SIZE = RX_BUFFER_SIZE; - static constexpr unsigned int TX_SIZE = TX_BUFFER_SIZE; - static constexpr bool XONOFF = bSERIAL_XON_XOFF; - static constexpr bool EMERGENCYPARSER = bEMERGENCY_PARSER; - static constexpr bool DROPPED_RX = bSERIAL_STATS_DROPPED_RX; - static constexpr bool RX_OVERRUNS = bSERIAL_STATS_RX_BUFFER_OVERRUNS; - static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS; - static constexpr bool MAX_RX_QUEUED = bSERIAL_STATS_MAX_RX_QUEUED; - }; - - extern MarlinSerial customizedSerial2; - + extern MarlinSerial> customizedSerial2; + #endif -#endif // MARLINSERIAL_DUE_H