Template struct simplification for serial (#11990)

This commit is contained in:
AnoNymous
2018-10-03 18:01:21 +02:00
committed by Scott Lahteine
parent 348004c34f
commit 001f26b642
4 changed files with 38 additions and 68 deletions

View File

@ -705,35 +705,35 @@
// Hookup ISR handlers
ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_RX_vect)) {
MarlinSerial<MarlinSerialCfg1>::store_rxd_char();
MarlinSerial<MarlinSerialCfg<SERIAL_PORT>>::store_rxd_char();
}
ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_UDRE_vect)) {
MarlinSerial<MarlinSerialCfg1>::_tx_udr_empty_irq();
MarlinSerial<MarlinSerialCfg<SERIAL_PORT>>::_tx_udr_empty_irq();
}
// Preinstantiate
template class MarlinSerial<MarlinSerialCfg1>;
template class MarlinSerial<MarlinSerialCfg<SERIAL_PORT>>;
// Instantiate
MarlinSerial<MarlinSerialCfg1> customizedSerial1;
MarlinSerial<MarlinSerialCfg<SERIAL_PORT>> customizedSerial1;
#ifdef SERIAL_PORT_2
// Hookup ISR handlers
ISR(SERIAL_REGNAME(USART,SERIAL_PORT_2,_RX_vect)) {
MarlinSerial<MarlinSerialCfg2>::store_rxd_char();
MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>>::store_rxd_char();
}
ISR(SERIAL_REGNAME(USART,SERIAL_PORT_2,_UDRE_vect)) {
MarlinSerial<MarlinSerialCfg2>::_tx_udr_empty_irq();
MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>>::_tx_udr_empty_irq();
}
// Preinstantiate
template class MarlinSerial<MarlinSerialCfg2>;
template class MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>>;
// Instantiate
MarlinSerial<MarlinSerialCfg2> customizedSerial2;
MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>> customizedSerial2;
#endif

View File

@ -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 <uint8_t serial>
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<MarlinSerialCfg1> customizedSerial1;
extern MarlinSerial<MarlinSerialCfg<SERIAL_PORT>> 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<MarlinSerialCfg2> customizedSerial2;
extern MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>> customizedSerial2;
#endif
#endif // !USBCON
// Use the UART for Bluetooth in AT90USB configurations