Refactor serial class with templates (#20783)

This commit is contained in:
X-Ryl669
2021-01-28 09:02:06 +01:00
committed by GitHub
parent c929fb52dd
commit 3f01b222b2
64 changed files with 782 additions and 948 deletions

View File

@@ -24,21 +24,15 @@
#include "../../feature/e_parser.h"
#endif
#include "../../core/serial_hook.h"
typedef void (*usart_rx_callback_t)(serial_t * obj);
class MarlinSerial : public HardwareSerial {
public:
struct MarlinSerial : public HardwareSerial {
MarlinSerial(void* peripheral, usart_rx_callback_t rx_callback) :
HardwareSerial(peripheral), _rx_callback(rx_callback)
#if ENABLED(EMERGENCY_PARSER)
, emergency_state(EmergencyParser::State::EP_RESET)
#endif
{ }
#if ENABLED(EMERGENCY_PARSER)
static inline bool emergency_parser_enabled() { return true; }
#endif
void begin(unsigned long baud, uint8_t config);
inline void begin(unsigned long baud) { begin(baud, SERIAL_8N1); }
@@ -46,19 +40,17 @@ public:
protected:
usart_rx_callback_t _rx_callback;
#if ENABLED(EMERGENCY_PARSER)
EmergencyParser::State emergency_state;
#endif
};
extern MarlinSerial MSerial1;
extern MarlinSerial MSerial2;
extern MarlinSerial MSerial3;
extern MarlinSerial MSerial4;
extern MarlinSerial MSerial5;
extern MarlinSerial MSerial6;
extern MarlinSerial MSerial7;
extern MarlinSerial MSerial8;
extern MarlinSerial MSerial9;
extern MarlinSerial MSerial10;
extern MarlinSerial MSerialLP1;
typedef Serial0Type<MarlinSerial> MSerialT;
extern MSerialT MSerial1;
extern MSerialT MSerial2;
extern MSerialT MSerial3;
extern MSerialT MSerial4;
extern MSerialT MSerial5;
extern MSerialT MSerial6;
extern MSerialT MSerial7;
extern MSerialT MSerial8;
extern MSerialT MSerial9;
extern MSerialT MSerial10;
extern MSerialT MSerialLP1;