Refactor serial class with templates (#20783)
This commit is contained in:
@ -24,6 +24,11 @@
|
||||
#include <Adafruit_ZeroDMA.h>
|
||||
#include <wiring_private.h>
|
||||
|
||||
#ifdef ADAFRUIT_GRAND_CENTRAL_M4
|
||||
DefaultSerial MSerial(false, Serial);
|
||||
DefaultSerial1 MSerial1(false, Serial1);
|
||||
#endif
|
||||
|
||||
// ------------------------
|
||||
// Local defines
|
||||
// ------------------------
|
||||
|
@ -32,15 +32,19 @@
|
||||
#include "MarlinSerial_AGCM4.h"
|
||||
|
||||
// Serial ports
|
||||
typedef ForwardSerial0Type< decltype(Serial) > DefaultSerial;
|
||||
extern DefaultSerial MSerial;
|
||||
typedef ForwardSerial0Type< decltype(Serial1) > DefaultSerial1;
|
||||
extern DefaultSerial1 MSerial1;
|
||||
|
||||
// MYSERIAL0 required before MarlinSerial includes!
|
||||
|
||||
#define __MSERIAL(X) Serial##X
|
||||
#define __MSERIAL(X) MSerial##X
|
||||
#define _MSERIAL(X) __MSERIAL(X)
|
||||
#define MSERIAL(X) _MSERIAL(INCREMENT(X))
|
||||
|
||||
#if SERIAL_PORT == -1
|
||||
#define MYSERIAL0 Serial
|
||||
#define MYSERIAL0 MSerial
|
||||
#elif WITHIN(SERIAL_PORT, 0, 3)
|
||||
#define MYSERIAL0 MSERIAL(SERIAL_PORT)
|
||||
#else
|
||||
@ -49,7 +53,7 @@
|
||||
|
||||
#ifdef SERIAL_PORT_2
|
||||
#if SERIAL_PORT_2 == -1
|
||||
#define MYSERIAL1 Serial
|
||||
#define MYSERIAL1 MSerial
|
||||
#elif WITHIN(SERIAL_PORT_2, 0, 3)
|
||||
#define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
|
||||
#else
|
||||
@ -59,7 +63,7 @@
|
||||
|
||||
#ifdef MMU2_SERIAL_PORT
|
||||
#if MMU2_SERIAL_PORT == -1
|
||||
#define MMU2_SERIAL Serial
|
||||
#define MMU2_SERIAL MSerial
|
||||
#elif WITHIN(MMU2_SERIAL_PORT, 0, 3)
|
||||
#define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
|
||||
#else
|
||||
@ -69,7 +73,7 @@
|
||||
|
||||
#ifdef LCD_SERIAL_PORT
|
||||
#if LCD_SERIAL_PORT == -1
|
||||
#define LCD_SERIAL Serial
|
||||
#define LCD_SERIAL MSerial
|
||||
#elif WITHIN(LCD_SERIAL_PORT, 0, 3)
|
||||
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
|
||||
#else
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
#if USING_SERIAL_1
|
||||
Uart Serial2(&sercom4, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX);
|
||||
UartT Serial2(false, &sercom4, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX);
|
||||
void SERCOM4_0_Handler() { Serial2.IrqHandler(); }
|
||||
void SERCOM4_1_Handler() { Serial2.IrqHandler(); }
|
||||
void SERCOM4_2_Handler() { Serial2.IrqHandler(); }
|
||||
@ -36,7 +36,7 @@
|
||||
#endif
|
||||
|
||||
#if USING_SERIAL_2
|
||||
Uart Serial3(&sercom1, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX);
|
||||
UartT Serial3(false, &sercom1, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX);
|
||||
void SERCOM1_0_Handler() { Serial3.IrqHandler(); }
|
||||
void SERCOM1_1_Handler() { Serial3.IrqHandler(); }
|
||||
void SERCOM1_2_Handler() { Serial3.IrqHandler(); }
|
||||
@ -44,7 +44,7 @@
|
||||
#endif
|
||||
|
||||
#if USING_SERIAL_3
|
||||
Uart Serial4(&sercom5, PIN_SERIAL4_RX, PIN_SERIAL4_TX, PAD_SERIAL4_RX, PAD_SERIAL4_TX);
|
||||
UartT Serial4(false, &sercom5, PIN_SERIAL4_RX, PIN_SERIAL4_TX, PAD_SERIAL4_RX, PAD_SERIAL4_TX);
|
||||
void SERCOM5_0_Handler() { Serial4.IrqHandler(); }
|
||||
void SERCOM5_1_Handler() { Serial4.IrqHandler(); }
|
||||
void SERCOM5_2_Handler() { Serial4.IrqHandler(); }
|
||||
|
@ -20,6 +20,10 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
extern Uart Serial2;
|
||||
extern Uart Serial3;
|
||||
extern Uart Serial4;
|
||||
#include "../../core/serial_hook.h"
|
||||
|
||||
typedef Serial0Type<Uart> UartT;
|
||||
|
||||
extern UartT Serial2;
|
||||
extern UartT Serial3;
|
||||
extern UartT Serial4;
|
||||
|
Reference in New Issue
Block a user