Number serial from 1 to match settings

This commit is contained in:
Scott Lahteine 2021-03-10 12:05:05 -06:00
parent 46246c8db6
commit b713ca2638
51 changed files with 155 additions and 160 deletions

View File

@ -25,7 +25,7 @@
#include "HAL.h"
#ifdef USBCON
DefaultSerial MSerial(false, Serial);
DefaultSerial1 MSerial0(false, Serial);
#ifdef BLUETOOTH
BTSerial btSerial(false, bluetoothSerial);
#endif

View File

@ -83,25 +83,25 @@ typedef int8_t pin_t;
// Serial ports
#ifdef USBCON
#include "../../core/serial_hook.h"
typedef ForwardSerial0Type< decltype(Serial) > DefaultSerial;
extern DefaultSerial MSerial;
typedef ForwardSerial1Class< decltype(Serial) > DefaultSerial1;
extern DefaultSerial1 MSerial0;
#ifdef BLUETOOTH
typedef ForwardSerial0Type< decltype(bluetoothSerial) > BTSerial;
typedef ForwardSerial1Class< decltype(bluetoothSerial) > BTSerial;
extern BTSerial btSerial;
#endif
#define MYSERIAL0 TERN(BLUETOOTH, btSerial, MSerial)
#define MYSERIAL1 TERN(BLUETOOTH, btSerial, MSerial0)
#else
#if !WITHIN(SERIAL_PORT, -1, 3)
#error "SERIAL_PORT must be from -1 to 3. Please update your configuration."
#endif
#define MYSERIAL0 customizedSerial1
#define MYSERIAL1 customizedSerial1
#ifdef SERIAL_PORT_2
#if !WITHIN(SERIAL_PORT_2, -1, 3)
#error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
#endif
#define MYSERIAL1 customizedSerial2
#define MYSERIAL2 customizedSerial2
#endif
#endif

View File

@ -238,11 +238,11 @@
static constexpr bool MAX_RX_QUEUED = ENABLED(SERIAL_STATS_MAX_RX_QUEUED);
};
typedef Serial0Type< MarlinSerial< MarlinSerialCfg<SERIAL_PORT> > > MSerialT;
typedef Serial1Class< MarlinSerial< MarlinSerialCfg<SERIAL_PORT> > > MSerialT;
extern MSerialT customizedSerial1;
#ifdef SERIAL_PORT_2
typedef Serial0Type< MarlinSerial< MarlinSerialCfg<SERIAL_PORT_2> > > MSerialT2;
typedef Serial1Class< MarlinSerial< MarlinSerialCfg<SERIAL_PORT_2> > > MSerialT2;
extern MSerialT2 customizedSerial2;
#endif
@ -262,7 +262,7 @@
static constexpr bool RX_OVERRUNS = false;
};
typedef Serial0Type< MarlinSerial< MMU2SerialCfg<MMU2_SERIAL_PORT> > > MSerialT3;
typedef Serial1Class< MarlinSerial< MMU2SerialCfg<MMU2_SERIAL_PORT> > > MSerialT3;
extern MSerialT3 mmuSerial;
#endif
@ -292,12 +292,12 @@
};
typedef Serial0Type< MarlinSerial< LCDSerialCfg<LCD_SERIAL_PORT> > > MSerialT4;
typedef Serial1Class< MarlinSerial< LCDSerialCfg<LCD_SERIAL_PORT> > > MSerialT4;
extern MSerialT4 lcdSerial;
#endif
// Use the UART for Bluetooth in AT90USB configurations
#if defined(USBCON) && ENABLED(BLUETOOTH)
typedef Serial0Type<HardwareSerial> MSerialT5;
typedef Serial1Class<HardwareSerial> MSerialT5;
extern MSerialT5 bluetoothSerial;
#endif

View File

@ -107,16 +107,16 @@ uint16_t HAL_adc_get_result() {
// Forward the default serial ports
#if ANY_SERIAL_IS(0)
DefaultSerial MSerial(false, Serial);
DefaultSerial1 MSerial0(false, Serial);
#endif
#if ANY_SERIAL_IS(1)
DefaultSerial1 MSerial1(false, Serial1);
DefaultSerial2 MSerial1(false, Serial1);
#endif
#if ANY_SERIAL_IS(2)
DefaultSerial2 MSerial2(false, Serial2);
DefaultSerial3 MSerial2(false, Serial2);
#endif
#if ANY_SERIAL_IS(3)
DefaultSerial3 MSerial3(false, Serial3);
DefaultSerial4 MSerial3(false, Serial3);
#endif
#endif // ARDUINO_ARCH_SAM

View File

@ -38,33 +38,32 @@
#include "../../core/serial_hook.h"
typedef ForwardSerial0Type< decltype(Serial) > DefaultSerial;
typedef ForwardSerial0Type< decltype(Serial1) > DefaultSerial1;
typedef ForwardSerial0Type< decltype(Serial2) > DefaultSerial2;
typedef ForwardSerial0Type< decltype(Serial3) > DefaultSerial3;
extern DefaultSerial MSerial;
extern DefaultSerial1 MSerial1;
extern DefaultSerial2 MSerial2;
extern DefaultSerial3 MSerial3;
typedef ForwardSerial1Class< decltype(Serial) > DefaultSerial1;
typedef ForwardSerial1Class< decltype(Serial1) > DefaultSerial2;
typedef ForwardSerial1Class< decltype(Serial2) > DefaultSerial3;
typedef ForwardSerial1Class< decltype(Serial3) > DefaultSerial4;
extern DefaultSerial1 MSerial0;
extern DefaultSerial2 MSerial1;
extern DefaultSerial3 MSerial2;
extern DefaultSerial4 MSerial3;
#define _MSERIAL(X) MSerial##X
#define MSERIAL(X) _MSERIAL(X)
#define MSerial0 MSerial
// Define MYSERIAL0/1 before MarlinSerial includes!
// Define MYSERIAL1/2 before MarlinSerial includes!
#if SERIAL_PORT == -1 || ENABLED(EMERGENCY_PARSER)
#define MYSERIAL0 customizedSerial1
#define MYSERIAL1 customizedSerial1
#elif WITHIN(SERIAL_PORT, 0, 3)
#define MYSERIAL0 MSERIAL(SERIAL_PORT)
#define MYSERIAL1 MSERIAL(SERIAL_PORT)
#else
#error "The required SERIAL_PORT must be from -1 to 3. Please update your configuration."
#endif
#ifdef SERIAL_PORT_2
#if SERIAL_PORT_2 == -1 || ENABLED(EMERGENCY_PARSER)
#define MYSERIAL1 customizedSerial2
#define MYSERIAL2 customizedSerial2
#elif WITHIN(SERIAL_PORT_2, 0, 3)
#define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
#define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
#else
#error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
#endif

View File

@ -141,11 +141,11 @@ struct MarlinSerialCfg {
};
#if SERIAL_PORT >= 0
typedef Serial0Type< MarlinSerial< MarlinSerialCfg<SERIAL_PORT> > > MSerialT;
typedef Serial1Class< MarlinSerial< MarlinSerialCfg<SERIAL_PORT> > > MSerialT;
extern MSerialT customizedSerial1;
#endif
#if defined(SERIAL_PORT_2) && SERIAL_PORT_2 >= 0
typedef Serial0Type< MarlinSerial< MarlinSerialCfg<SERIAL_PORT_2> > > MSerialT2;
typedef Serial1Class< MarlinSerial< MarlinSerialCfg<SERIAL_PORT_2> > > MSerialT2;
extern MSerialT2 customizedSerial2;
#endif

View File

@ -50,7 +50,7 @@ struct MarlinSerialUSB {
FORCE_INLINE int rxMaxEnqueued() { return 0; }
#endif
};
typedef Serial0Type<MarlinSerialUSB> MSerialT;
typedef Serial1Class<MarlinSerialUSB> MSerialT;
#if SERIAL_PORT == -1
extern MSerialT customizedSerial1;

View File

@ -24,6 +24,6 @@
#include "FlushableHardwareSerial.h"
Serial0Type<FlushableHardwareSerial> flushableSerial(false, 0);
Serial1Class<FlushableHardwareSerial> flushableSerial(false, 0);
#endif

View File

@ -31,4 +31,4 @@ public:
FlushableHardwareSerial(int uart_nr) : HardwareSerial(uart_nr) {}
};
extern Serial0Type<FlushableHardwareSerial> flushableSerial;
extern Serial1Class<FlushableHardwareSerial> flushableSerial;

View File

@ -41,7 +41,7 @@
#endif
#if ENABLED(ESP3D_WIFISUPPORT)
DefaultSerial MSerial(false, Serial2Socket);
DefaultSerial1 MSerial0(false, Serial2Socket);
#endif
// ------------------------

View File

@ -51,15 +51,15 @@
extern portMUX_TYPE spinlock;
#define MYSERIAL0 flushableSerial
#define MYSERIAL1 flushableSerial
#if EITHER(WIFISUPPORT, ESP3D_WIFISUPPORT)
#if ENABLED(ESP3D_WIFISUPPORT)
typedef ForwardSerial0Type< decltype(Serial2Socket) > DefaultSerial;
extern DefaultSerial MSerial;
#define MYSERIAL1 MSerial
typedef ForwardSerial1Class< decltype(Serial2Socket) > DefaultSerial1;
extern DefaultSerial1 MSerial0;
#define MYSERIAL2 MSerial0
#else
#define MYSERIAL1 webSocketSerial
#define MYSERIAL2 webSocketSerial
#endif
#endif

View File

@ -81,5 +81,5 @@ public:
#endif
};
typedef Serial0Type<WebSocketSerial> MSerialT;
typedef Serial1Class<WebSocketSerial> MSerialT;
extern MSerialT webSocketSerial;

View File

@ -61,7 +61,7 @@ uint8_t _getc();
#define SHARED_SERVOS HAS_SERVOS
extern MSerialT usb_serial;
#define MYSERIAL0 usb_serial
#define MYSERIAL1 usb_serial
#define ST7920_DELAY_1 DELAY_NS(600)
#define ST7920_DELAY_2 DELAY_NS(750)

View File

@ -115,4 +115,4 @@ struct HalSerial {
volatile bool host_connected;
};
typedef Serial0Type<HalSerial> MSerialT;
typedef Serial1Class<HalSerial> MSerialT;

View File

@ -105,8 +105,8 @@ int main() {
std::thread write_serial (write_serial_thread);
std::thread read_serial (read_serial_thread);
#ifdef MYSERIAL0
MYSERIAL0.begin(BAUDRATE);
#ifdef MYSERIAL1
MYSERIAL1.begin(BAUDRATE);
SERIAL_ECHOLNPGM("x86_64 Initialized");
SERIAL_FLUSHTX();
#endif

View File

@ -29,7 +29,7 @@
#include "watchdog.h"
#endif
DefaultSerial USBSerial(false, UsbSerial);
DefaultSerial1 USBSerial(false, UsbSerial);
uint32_t HAL_adc_reading = 0;

View File

@ -60,26 +60,25 @@ extern "C" volatile uint32_t _millis;
#define ST7920_DELAY_3 DELAY_NS(750)
#endif
typedef ForwardSerial0Type< decltype(UsbSerial) > DefaultSerial;
extern DefaultSerial USBSerial;
typedef ForwardSerial1Class< decltype(UsbSerial) > DefaultSerial1;
extern DefaultSerial1 USBSerial;
#define _MSERIAL(X) MSerial##X
#define MSERIAL(X) _MSERIAL(X)
#define MSerial0 MSerial
#if SERIAL_PORT == -1
#define MYSERIAL0 USBSerial
#define MYSERIAL1 USBSerial
#elif WITHIN(SERIAL_PORT, 0, 3)
#define MYSERIAL0 MSERIAL(SERIAL_PORT)
#define MYSERIAL1 MSERIAL(SERIAL_PORT)
#else
#error "SERIAL_PORT must be from -1 to 3. Please update your configuration."
#endif
#ifdef SERIAL_PORT_2
#if SERIAL_PORT_2 == -1
#define MYSERIAL1 USBSerial
#define MYSERIAL2 USBSerial
#elif WITHIN(SERIAL_PORT_2, 0, 3)
#define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
#define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
#else
#error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
#endif

View File

@ -26,7 +26,7 @@
#if ANY_SERIAL_IS(0)
MarlinSerial _MSerial(LPC_UART0);
MSerialT MSerial(true, _MSerial);
MSerialT MSerial0(true, _MSerial);
extern "C" void UART0_IRQHandler() { _MSerial.IRQHandler(); }
#endif
#if ANY_SERIAL_IS(1)
@ -51,7 +51,7 @@
// Need to figure out which serial port we are and react in consequence (Marlin does not have CONTAINER_OF macro)
if (false) {}
#if ANY_SERIAL_IS(0)
else if (this == &_MSerial) emergency_parser.update(MSerial.emergency_state, c);
else if (this == &_MSerial) emergency_parser.update(MSerial0.emergency_state, c);
#endif
#if ANY_SERIAL_IS(1)
else if (this == &_MSerial1) emergency_parser.update(MSerial1.emergency_state, c);

View File

@ -54,8 +54,8 @@ public:
// On LPC176x framework, HardwareSerial does not implement the same interface as Arduino's Serial, so overloads
// of 'available' and 'read' method are not used in this multiple inheritance scenario.
// Instead, use a ForwardSerial here that adapts the interface.
typedef ForwardSerial0Type<MarlinSerial> MSerialT;
extern MSerialT MSerial;
typedef ForwardSerial1Class<MarlinSerial> MSerialT;
extern MSerialT MSerial0;
extern MSerialT MSerial1;
extern MSerialT MSerial2;
extern MSerialT MSerial3;

View File

@ -26,19 +26,19 @@
#ifdef ADAFRUIT_GRAND_CENTRAL_M4
#if ANY_SERIAL_IS(-1)
DefaultSerial MSerial(false, Serial);
DefaultSerial1 MSerial0(false, Serial);
#endif
#if ANY_SERIAL_IS(0)
DefaultSerial1 MSerial1(false, Serial1);
DefaultSerial2 MSerial1(false, Serial1);
#endif
#if ANY_SERIAL_IS(1)
DefaultSerial2 MSerial2(false, Serial2);
DefaultSerial3 MSerial2(false, Serial2);
#endif
#if ANY_SERIAL_IS(2)
DefaultSerial3 MSerial3(false, Serial3);
DefaultSerial4 MSerial3(false, Serial3);
#endif
#if ANY_SERIAL_IS(3)
DefaultSerial4 MSerial4(false, Serial4);
DefaultSerial5 MSerial4(false, Serial4);
#endif
#endif

View File

@ -32,36 +32,36 @@
#include "MarlinSerial_AGCM4.h"
// Serial ports
typedef ForwardSerial0Type< decltype(Serial) > DefaultSerial;
typedef ForwardSerial0Type< decltype(Serial1) > DefaultSerial1;
typedef ForwardSerial0Type< decltype(Serial2) > DefaultSerial2;
typedef ForwardSerial0Type< decltype(Serial3) > DefaultSerial3;
typedef ForwardSerial0Type< decltype(Serial4) > DefaultSerial4;
extern DefaultSerial MSerial;
extern DefaultSerial1 MSerial1;
extern DefaultSerial2 MSerial2;
extern DefaultSerial3 MSerial3;
extern DefaultSerial4 MSerial4;
typedef ForwardSerial1Class< decltype(Serial) > DefaultSerial1;
typedef ForwardSerial1Class< decltype(Serial1) > DefaultSerial2;
typedef ForwardSerial1Class< decltype(Serial2) > DefaultSerial3;
typedef ForwardSerial1Class< decltype(Serial3) > DefaultSerial4;
typedef ForwardSerial1Class< decltype(Serial4) > DefaultSerial5;
extern DefaultSerial1 MSerial0;
extern DefaultSerial2 MSerial1;
extern DefaultSerial3 MSerial2;
extern DefaultSerial4 MSerial3;
extern DefaultSerial5 MSerial4;
// MYSERIAL0 required before MarlinSerial includes!
// MYSERIAL1 required before MarlinSerial includes!
#define __MSERIAL(X) MSerial##X
#define _MSERIAL(X) __MSERIAL(X)
#define MSERIAL(X) _MSERIAL(INCREMENT(X))
#if SERIAL_PORT == -1
#define MYSERIAL0 MSerial
#define MYSERIAL1 MSerial0
#elif WITHIN(SERIAL_PORT, 0, 3)
#define MYSERIAL0 MSERIAL(SERIAL_PORT)
#define MYSERIAL1 MSERIAL(SERIAL_PORT)
#else
#error "SERIAL_PORT must be from -1 to 3. Please update your configuration."
#endif
#ifdef SERIAL_PORT_2
#if SERIAL_PORT_2 == -1
#define MYSERIAL1 MSerial
#define MYSERIAL2 MSerial0
#elif WITHIN(SERIAL_PORT_2, 0, 3)
#define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
#define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
#else
#error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
#endif
@ -69,7 +69,7 @@
#ifdef MMU2_SERIAL_PORT
#if MMU2_SERIAL_PORT == -1
#define MMU2_SERIAL MSerial
#define MMU2_SERIAL MSerial0
#elif WITHIN(MMU2_SERIAL_PORT, 0, 3)
#define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
#else
@ -79,7 +79,7 @@
#ifdef LCD_SERIAL_PORT
#if LCD_SERIAL_PORT == -1
#define LCD_SERIAL MSerial
#define LCD_SERIAL MSerial0
#elif WITHIN(LCD_SERIAL_PORT, 0, 3)
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#else

View File

@ -22,7 +22,7 @@
#include "../../core/serial_hook.h"
typedef Serial0Type<Uart> UartT;
typedef Serial1Class<Uart> UartT;
extern UartT Serial2;
extern UartT Serial3;

View File

@ -29,7 +29,7 @@
#include "../shared/Delay.h"
#ifdef USBCON
DefaultSerial MSerial(false, SerialUSB);
DefaultSerial1 MSerial0(false, SerialUSB);
#endif
#if ENABLED(SRAM_EEPROM_EMULATION)

View File

@ -40,8 +40,8 @@
#ifdef USBCON
#include <USBSerial.h>
#include "../../core/serial_hook.h"
typedef ForwardSerial0Type< decltype(SerialUSB) > DefaultSerial;
extern DefaultSerial MSerial;
typedef ForwardSerial1Class< decltype(SerialUSB) > DefaultSerial1;
extern DefaultSerial1 MSerial0;
#endif
// ------------------------
@ -51,18 +51,18 @@
#define MSERIAL(X) _MSERIAL(X)
#if SERIAL_PORT == -1
#define MYSERIAL0 MSerial
#define MYSERIAL1 MSerial0
#elif WITHIN(SERIAL_PORT, 1, 6)
#define MYSERIAL0 MSERIAL(SERIAL_PORT)
#define MYSERIAL1 MSERIAL(SERIAL_PORT)
#else
#error "SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
#endif
#ifdef SERIAL_PORT_2
#if SERIAL_PORT_2 == -1
#define MYSERIAL1 MSerial
#define MYSERIAL2 MSerial0
#elif WITHIN(SERIAL_PORT_2, 1, 6)
#define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
#define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
#else
#error "SERIAL_PORT_2 must be -1 or from 1 to 6. Please update your configuration."
#endif
@ -70,7 +70,7 @@
#ifdef MMU2_SERIAL_PORT
#if MMU2_SERIAL_PORT == -1
#define MMU2_SERIAL MSerial
#define MMU2_SERIAL MSerial0
#elif WITHIN(MMU2_SERIAL_PORT, 1, 6)
#define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
#else
@ -80,7 +80,7 @@
#ifdef LCD_SERIAL_PORT
#if LCD_SERIAL_PORT == -1
#define LCD_SERIAL MSerial
#define LCD_SERIAL MSerial0
#elif WITHIN(LCD_SERIAL_PORT, 1, 6)
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#else

View File

@ -42,7 +42,7 @@ protected:
usart_rx_callback_t _rx_callback;
};
typedef Serial0Type<MarlinSerial> MSerialT;
typedef Serial1Class<MarlinSerial> MSerialT;
extern MSerialT MSerial1;
extern MSerialT MSerial2;
extern MSerialT MSerial3;

View File

@ -84,7 +84,7 @@
#if defined(SERIAL_USB) && !HAS_SD_HOST_DRIVE
USBSerial SerialUSB;
DefaultSerial MSerial(true, SerialUSB);
DefaultSerial1 MSerial0(true, SerialUSB);
#if ENABLED(EMERGENCY_PARSER)
#include "../libmaple/usb/stm32f1/usb_reg_map.h"
@ -107,7 +107,7 @@
len = usb_cdcacm_peek(buf, total);
for (uint32 i = 0; i < len; i++)
emergency_parser.update(MSerial.emergency_state, buf[i + total - len]);
emergency_parser.update(MSerial0.emergency_state, buf[i + total - len]);
}
#endif
#endif

View File

@ -61,11 +61,11 @@
#endif
#ifdef SERIAL_USB
typedef ForwardSerial0Type< USBSerial > DefaultSerial;
extern DefaultSerial MSerial;
typedef ForwardSerial1Class< USBSerial > DefaultSerial1;
extern DefaultSerial1 MSerial0;
#if !HAS_SD_HOST_DRIVE
#define UsbSerial MSerial
#define UsbSerial MSerial0
#else
#define UsbSerial MarlinCompositeSerial
#endif
@ -81,9 +81,9 @@
#endif
#if SERIAL_PORT == -1
#define MYSERIAL0 UsbSerial
#define MYSERIAL1 UsbSerial
#elif WITHIN(SERIAL_PORT, 1, NUM_UARTS)
#define MYSERIAL0 MSERIAL(SERIAL_PORT)
#define MYSERIAL1 MSERIAL(SERIAL_PORT)
#elif NUM_UARTS == 5
#error "SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
#else
@ -92,9 +92,9 @@
#ifdef SERIAL_PORT_2
#if SERIAL_PORT_2 == -1
#define MYSERIAL1 UsbSerial
#define MYSERIAL2 UsbSerial
#elif WITHIN(SERIAL_PORT_2, 1, NUM_UARTS)
#define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
#define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
#elif NUM_UARTS == 5
#error "SERIAL_PORT_2 must be -1 or from 1 to 5. Please update your configuration."
#else

View File

@ -44,8 +44,8 @@ static void TXBegin() {
#warning "Using POSTMORTEM_DEBUGGING requires a physical U(S)ART hardware in case of severe error."
#warning "Disabling the severe error reporting feature currently because the used serial port is not a HW port."
#else
// We use MYSERIAL0 here, so we need to figure out how to get the linked register
struct usart_dev* dev = MYSERIAL0.c_dev();
// We use MYSERIAL1 here, so we need to figure out how to get the linked register
struct usart_dev* dev = MYSERIAL1.c_dev();
// Or use this if removing libmaple
// int irq = dev->irq_num;
@ -80,7 +80,7 @@ static void TXBegin() {
#define sw_barrier() __asm__ volatile("": : :"memory");
static void TX(char c) {
#if WITHIN(SERIAL_PORT, 1, 6)
struct usart_dev* dev = MYSERIAL0.c_dev();
struct usart_dev* dev = MYSERIAL1.c_dev();
while (!(dev->regs->SR & USART_SR_TXE)) {
TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
sw_barrier();

View File

@ -134,12 +134,12 @@ constexpr bool IsSerialClassAllowed(const HardwareSerial&) { return false; }
// If you encounter this error, replace SerialX with MSerialX, for example MSerial3.
// Non-TMC ports were already validated in HAL.h, so do not require verbose error messages.
#ifdef MYSERIAL0
CHECK_CFG_SERIAL(MYSERIAL0);
#endif
#ifdef MYSERIAL1
CHECK_CFG_SERIAL(MYSERIAL1);
#endif
#ifdef MYSERIAL2
CHECK_CFG_SERIAL(MYSERIAL2);
#endif
#ifdef LCD_SERIAL
CHECK_CFG_SERIAL(LCD_SERIAL);
#endif

View File

@ -47,7 +47,7 @@ struct MarlinSerial : public HardwareSerial {
#endif
};
typedef Serial0Type<MarlinSerial> MSerialT;
typedef Serial1Class<MarlinSerial> MSerialT;
extern MSerialT MSerial1;
extern MSerialT MSerial2;

View File

@ -24,7 +24,7 @@
#define PRODUCT_ID 0x29
USBMassStorage MarlinMSC;
Serial0Type<USBCompositeSerial> MarlinCompositeSerial(true);
Serial1Class<USBCompositeSerial> MarlinCompositeSerial(true);
#include "../../inc/MarlinConfig.h"

View File

@ -21,6 +21,6 @@
#include "../../core/serial_hook.h"
extern USBMassStorage MarlinMSC;
extern Serial0Type<USBCompositeSerial> MarlinCompositeSerial;
extern Serial1Class<USBCompositeSerial> MarlinCompositeSerial;
void MSC_SD_init();

View File

@ -31,7 +31,7 @@
#include <Wire.h>
DefaultSerial MSerial(false);
DefaultSerial1 MSerial0(false);
USBSerialType USBSerial(false, SerialUSB);
uint16_t HAL_adc_result;

View File

@ -51,19 +51,18 @@
#endif
#include "../../core/serial_hook.h"
typedef Serial0Type<decltype(Serial)> DefaultSerial;
extern DefaultSerial MSerial;
typedef ForwardSerial0Type<decltype(SerialUSB)> USBSerialType;
typedef Serial1Class<decltype(Serial)> DefaultSerial1;
extern DefaultSerial1 MSerial0;
typedef ForwardSerial1Class<decltype(SerialUSB)> USBSerialType;
extern USBSerialType USBSerial;
#define _MSERIAL(X) MSerial##X
#define MSERIAL(X) _MSERIAL(X)
#define MSerial0 MSerial
#if SERIAL_PORT == -1
#define MYSERIAL0 USBSerial
#define MYSERIAL1 USBSerial
#elif WITHIN(SERIAL_PORT, 0, 3)
#define MYSERIAL0 MSERIAL(SERIAL_PORT)
#define MYSERIAL1 MSERIAL(SERIAL_PORT)
#endif
#define HAL_SERVO_LIB libServo

View File

@ -31,7 +31,7 @@
#include <Wire.h>
DefaultSerial MSerial(false);
DefaultSerial1 MSerial0(false);
USBSerialType USBSerial(false, SerialUSB);
uint16_t HAL_adc_result, HAL_adc_select;

View File

@ -54,19 +54,18 @@
#endif
#include "../../core/serial_hook.h"
typedef Serial0Type<decltype(Serial)> DefaultSerial;
extern DefaultSerial MSerial;
typedef ForwardSerial0Type<decltype(SerialUSB)> USBSerialType;
typedef Serial1Class<decltype(Serial)> DefaultSerial1;
extern DefaultSerial1 MSerial0;
typedef ForwardSerial1Class<decltype(SerialUSB)> USBSerialType;
extern USBSerialType USBSerial;
#define _MSERIAL(X) MSerial##X
#define MSERIAL(X) _MSERIAL(X)
#define MSerial0 MSerial
#if SERIAL_PORT == -1
#define MYSERIAL0 USBSerial
#define MYSERIAL1 USBSerial
#elif WITHIN(SERIAL_PORT, 0, 3)
#define MYSERIAL0 MSERIAL(SERIAL_PORT)
#define MYSERIAL1 MSERIAL(SERIAL_PORT)
#endif
#define HAL_SERVO_LIB libServo

View File

@ -32,7 +32,7 @@
#include <Wire.h>
DefaultSerial MSerial(false);
DefaultSerial1 MSerial0(false);
USBSerialType USBSerial(false, SerialUSB);
uint16_t HAL_adc_result, HAL_adc_select;

View File

@ -56,30 +56,29 @@
#endif
#include "../../core/serial_hook.h"
typedef Serial0Type<decltype(Serial)> DefaultSerial;
extern DefaultSerial MSerial;
typedef ForwardSerial0Type<decltype(SerialUSB)> USBSerialType;
typedef Serial1Class<decltype(Serial)> DefaultSerial1;
extern DefaultSerial1 MSerial0;
typedef ForwardSerial1Class<decltype(SerialUSB)> USBSerialType;
extern USBSerialType USBSerial;
#define _MSERIAL(X) MSerial##X
#define MSERIAL(X) _MSERIAL(X)
#define MSerial0 MSerial
#if SERIAL_PORT == -1
#define MYSERIAL0 SerialUSB
#define MYSERIAL1 SerialUSB
#elif WITHIN(SERIAL_PORT, 0, 8)
#define MYSERIAL0 MSERIAL(SERIAL_PORT)
#define MYSERIAL1 MSERIAL(SERIAL_PORT)
#else
#error "The required SERIAL_PORT must be from -1 to 8. Please update your configuration."
#endif
#ifdef SERIAL_PORT_2
#if SERIAL_PORT_2 == -1
#define MYSERIAL1 usbSerial
#define MYSERIAL2 usbSerial
#elif SERIAL_PORT_2 == -2
#define MYSERIAL1 ethernet.telnetClient
#define MYSERIAL2 ethernet.telnetClient
#elif WITHIN(SERIAL_PORT_2, 0, 8)
#define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
#define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
#else
#error "SERIAL_PORT_2 must be from -2 to 8. Please update your configuration."
#endif

View File

@ -43,12 +43,12 @@ PGMSTR(SP_X_LBL, " X:"); PGMSTR(SP_Y_LBL, " Y:"); PGMSTR(SP_Z_LBL, " Z:"); PGMST
#else
#if HAS_ETHERNET
// Runtime checking of the condition variable
ConditionalSerial<decltype(MYSERIAL1)> serialOut1(ethernet.have_telnet_client, MYSERIAL1, false); // Takes reference here
ConditionalSerial<decltype(MYSERIAL2)> serialOut2(ethernet.have_telnet_client, MYSERIAL2, false); // Takes reference here
#else
// Don't pay for runtime checking a true variable, instead use the output directly
#define serialOut1 MYSERIAL1
#define serialOut2 MYSERIAL2
#endif
SerialOutputT multiSerial(MYSERIAL0, serialOut1);
SerialOutputT multiSerial(MYSERIAL1, serialOut2);
#endif
#endif

View File

@ -69,7 +69,7 @@ extern uint8_t marlin_debug_flags;
#ifdef SERIAL_CATCHALL
typedef MultiSerial<decltype(MYSERIAL), decltype(SERIAL_CATCHALL), 0> SerialOutputT;
#else
typedef MultiSerial<decltype(MYSERIAL0), TERN(HAS_ETHERNET, ConditionalSerial<decltype(MYSERIAL1)>, decltype(MYSERIAL1)), 0> SerialOutputT;
typedef MultiSerial<decltype(MYSERIAL1), TERN(HAS_ETHERNET, ConditionalSerial<decltype(MYSERIAL2)>, decltype(MYSERIAL2)), 0> SerialOutputT;
#endif
extern SerialOutputT multiSerial;
#define _SERIAL_IMPL multiSerial
@ -77,7 +77,7 @@ extern uint8_t marlin_debug_flags;
#define _PORT_REDIRECT(n,p) NOOP
#define _PORT_RESTORE(n) NOOP
#define SERIAL_ASSERT(P) NOOP
#define _SERIAL_IMPL MYSERIAL0
#define _SERIAL_IMPL MYSERIAL1
#endif
#if ENABLED(MEATPACK)

View File

@ -257,8 +257,8 @@ struct MultiSerial : public SerialBase< MultiSerial<Serial0T, Serial1T, offset,
};
// Build the actual serial object depending on current configuration
#define Serial0Type TERN(SERIAL_RUNTIME_HOOK, RuntimeSerial, BaseSerial)
#define ForwardSerial0Type TERN(SERIAL_RUNTIME_HOOK, RuntimeSerial, ForwardSerial)
#define Serial1Class TERN(SERIAL_RUNTIME_HOOK, RuntimeSerial, BaseSerial)
#define ForwardSerial1Class TERN(SERIAL_RUNTIME_HOOK, RuntimeSerial, ForwardSerial)
#ifdef HAS_MULTI_SERIAL
#define Serial1Type ConditionalSerial
#define Serial2Class ConditionalSerial
#endif

View File

@ -124,7 +124,7 @@ void MarlinEthernet::check() {
if (!Ethernet.localIP()) break;
SERIAL_ECHOPGM("Successfully started telnet server with IP ");
MYSERIAL0.println(Ethernet.localIP());
MYSERIAL1.println(Ethernet.localIP());
linkState = LINKED;
break;

View File

@ -61,10 +61,10 @@ void GcodeSuite::M575() {
SERIAL_FLUSH();
if (set0) { MYSERIAL0.end(); MYSERIAL0.begin(baud); }
if (set0) { MYSERIAL1.end(); MYSERIAL1.begin(baud); }
#if HAS_MULTI_SERIAL
if (set1) { MYSERIAL1.end(); MYSERIAL1.begin(baud); }
if (set1) { MYSERIAL2.end(); MYSERIAL2.begin(baud); }
#endif
} break;

View File

@ -57,19 +57,19 @@ void GcodeSuite::M111() {
SERIAL_ECHOPGM(STR_DEBUG_OFF);
#if !defined(__AVR__) || !defined(USBCON)
#if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
SERIAL_ECHOPAIR("\nBuffer Overruns: ", MYSERIAL0.buffer_overruns());
SERIAL_ECHOPAIR("\nBuffer Overruns: ", MYSERIAL1.buffer_overruns());
#endif
#if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
SERIAL_ECHOPAIR("\nFraming Errors: ", MYSERIAL0.framing_errors());
SERIAL_ECHOPAIR("\nFraming Errors: ", MYSERIAL1.framing_errors());
#endif
#if ENABLED(SERIAL_STATS_DROPPED_RX)
SERIAL_ECHOPAIR("\nDropped bytes: ", MYSERIAL0.dropped());
SERIAL_ECHOPAIR("\nDropped bytes: ", MYSERIAL1.dropped());
#endif
#if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
SERIAL_ECHOPAIR("\nMax RX Queue Size: ", MYSERIAL0.rxMaxEnqueued());
SERIAL_ECHOPAIR("\nMax RX Queue Size: ", MYSERIAL1.rxMaxEnqueued());
#endif
#endif // !__AVR__ || !USBCON
}

View File

@ -635,10 +635,10 @@ void GCodeQueue::advance() {
#if !defined(__AVR__) || !defined(USBCON)
#if ENABLED(SERIAL_STATS_DROPPED_RX)
SERIAL_ECHOLNPAIR("Dropped bytes: ", MYSERIAL0.dropped());
SERIAL_ECHOLNPAIR("Dropped bytes: ", MYSERIAL1.dropped());
#endif
#if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
SERIAL_ECHOLNPAIR("Max RX Queue Size: ", MYSERIAL0.rxMaxEnqueued());
SERIAL_ECHOLNPAIR("Max RX Queue Size: ", MYSERIAL1.rxMaxEnqueued());
#endif
#endif

View File

@ -80,7 +80,7 @@ void lv_serial_capt_hook(void * userPointer, uint8_t c)
void lv_eom_hook(void *)
{
// Message is done, let's remove the hook now
MYSERIAL0.setHook();
MYSERIAL1.setHook();
// We are back from the keyboard, so let's redraw ourselves
draw_return_ui();
}

View File

@ -164,7 +164,7 @@ static void lv_kb_event_cb(lv_obj_t *kb, lv_event_t event) {
case GCodeCommand:
if (!queue.ring_buffer.full(3)) {
// Hook anything that goes to the serial port
MYSERIAL0.setHook(lv_serial_capt_hook, lv_eom_hook, 0);
MYSERIAL1.setHook(lv_serial_capt_hook, lv_eom_hook, 0);
queue.enqueue_one_now(ret_ta_txt);
}
lv_clear_keyboard();

View File

@ -414,8 +414,8 @@ void update_usb_status(const bool forceUpdate) {
// This is mildly different than stock, which
// appears to use the usb discovery status.
// This is more logical.
if (last_usb_connected_status != MYSERIAL0.connected() || forceUpdate) {
last_usb_connected_status = MYSERIAL0.connected();
if (last_usb_connected_status != MYSERIAL1.connected() || forceUpdate) {
last_usb_connected_status = MYSERIAL1.connected();
write_to_lcd_P(last_usb_connected_status ? PSTR("{R:UC}\r\n") : PSTR("{R:UD}\r\n"));
}
}

View File

@ -54,7 +54,7 @@
#define UHS_DEVICE_WINDOWS_USB_SPEC_VIOLATION_DESCRIPTOR_DEVICE 1
#define UHS_HOST_MAX_INTERFACE_DRIVERS 2
#define MASS_MAX_SUPPORTED_LUN 1
#define USB_HOST_SERIAL MYSERIAL0
#define USB_HOST_SERIAL MYSERIAL1
// Workaround for certain issues with UHS3
#define SKIP_PAGE3F // Required for IOGEAR media adapter

View File

@ -66,7 +66,7 @@
* For example Serial3.
*/
#if ENABLED(USB_FLASH_DRIVE_SUPPORT)
#define USB_HOST_SERIAL MYSERIAL0
#define USB_HOST_SERIAL MYSERIAL1
#endif
#ifndef USB_HOST_SERIAL

View File

@ -32,12 +32,12 @@ This is easily done via type definition of the feature.
For example, to create a single serial interface with 2 serial outputs (one enabled at runtime and the other switchable):
```cpp
typedef MultiSerial< RuntimeSerial<Serial>, ConditionalSerial<TelnetClient> > Serial0Type;
typedef MultiSerial< RuntimeSerial<Serial>, ConditionalSerial<TelnetClient> > Serial1Class;
```
To send the same output to 4 serial ports you could nest `MultiSerial` like this:
```cpp
typedef MultiSerial< MultiSerial< BaseSerial<Serial>, BaseSerial<Serial1> >, MultiSerial< BaseSerial<Serial2>, BaseSerial<Serial3>, 2, 1>, 0, 2> Serial0Type;
typedef MultiSerial< MultiSerial< BaseSerial<Serial>, BaseSerial<Serial1> >, MultiSerial< BaseSerial<Serial2>, BaseSerial<Serial3>, 2, 1>, 0, 2> Serial1Class;
```
The magical numbers here are the step and offset for computing the serial port. Simplifying the above monster a bit:
```cpp