Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Clarify MSerialUSB, drop HardwareSerial workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed May 14, 2022
1 parent a13ccea commit 2204f05
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
1 change: 0 additions & 1 deletion Marlin/src/HAL/AVR/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#ifdef USBCON
#include <HardwareSerial.h>
#else
#define HardwareSerial_h // Hack to prevent HardwareSerial.h header inclusion
#include "MarlinSerial.h"
#endif

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "../shared/Delay.h"

#ifdef USBCON
DefaultSerial1 MSerial0(false, SerialUSB);
DefaultSerial1 MSerialUSB(false, SerialUSB);
#endif

#if ENABLED(SRAM_EEPROM_EMULATION)
Expand Down
52 changes: 31 additions & 21 deletions Marlin/src/HAL/STM32/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,57 +51,67 @@
#include <USBSerial.h>
#include "../../core/serial_hook.h"
typedef ForwardSerial1Class< decltype(SerialUSB) > DefaultSerial1;
extern DefaultSerial1 MSerial0;
extern DefaultSerial1 MSerialUSB;
#endif

#define _MSERIAL(X) MSerial##X
#define MSERIAL(X) _MSERIAL(X)

#if SERIAL_PORT == -1
#define MYSERIAL1 MSerial0
#elif WITHIN(SERIAL_PORT, 1, 6)
#if WITHIN(SERIAL_PORT, 1, 6)
#define MYSERIAL1 MSERIAL(SERIAL_PORT)
#elif !defined(USBCON)
#error "SERIAL_PORT must be from 1 to 6."
#elif SERIAL_PORT == -1
#define MYSERIAL1 MSerialUSB
#else
#error "SERIAL_PORT must be from 1 to 6. You can also use -1 if the board supports Native USB."
#error "SERIAL_PORT must be from 1 to 6, or -1 for Native USB."
#endif

#ifdef SERIAL_PORT_2
#if SERIAL_PORT_2 == -1
#define MYSERIAL2 MSerial0
#elif WITHIN(SERIAL_PORT_2, 1, 6)
#if WITHIN(SERIAL_PORT_2, 1, 6)
#define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
#elif !defined(USBCON)
#error "SERIAL_PORT must be from 1 to 6."
#elif SERIAL_PORT_2 == -1
#define MYSERIAL2 MSerialUSB
#else
#error "SERIAL_PORT_2 must be from 1 to 6. You can also use -1 if the board supports Native USB."
#error "SERIAL_PORT_2 must be from 1 to 6, or -1 for Native USB."
#endif
#endif

#ifdef SERIAL_PORT_3
#if SERIAL_PORT_3 == -1
#define MYSERIAL3 MSerial0
#elif WITHIN(SERIAL_PORT_3, 1, 6)
#if WITHIN(SERIAL_PORT_3, 1, 6)
#define MYSERIAL3 MSERIAL(SERIAL_PORT_3)
#elif !defined(USBCON)
#error "SERIAL_PORT must be from 1 to 6."
#elif SERIAL_PORT_3 == -1
#define MYSERIAL3 MSerialUSB
#else
#error "SERIAL_PORT_3 must be from 1 to 6. You can also use -1 if the board supports Native USB."
#error "SERIAL_PORT_3 must be from 1 to 6, or -1 for Native USB."
#endif
#endif

#ifdef MMU2_SERIAL_PORT
#if MMU2_SERIAL_PORT == -1
#define MMU2_SERIAL MSerial0
#elif WITHIN(MMU2_SERIAL_PORT, 1, 6)
#if WITHIN(MMU2_SERIAL_PORT, 1, 6)
#define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
#elif !defined(USBCON)
#error "SERIAL_PORT must be from 1 to 6."
#elif MMU2_SERIAL_PORT == -1
#define MMU2_SERIAL MSerialUSB
#else
#error "MMU2_SERIAL_PORT must be from 1 to 6. You can also use -1 if the board supports Native USB."
#error "MMU2_SERIAL_PORT must be from 1 to 6, or -1 for Native USB."
#endif
#endif

#ifdef LCD_SERIAL_PORT
#if LCD_SERIAL_PORT == -1
#define LCD_SERIAL MSerial0
#elif WITHIN(LCD_SERIAL_PORT, 1, 6)
#if WITHIN(LCD_SERIAL_PORT, 1, 6)
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#elif !defined(USBCON)
#error "SERIAL_PORT must be from 1 to 6."
#elif LCD_SERIAL_PORT == -1
#define LCD_SERIAL MSerialUSB
#else
#error "LCD_SERIAL_PORT must be from 1 to 6. You can also use -1 if the board supports Native USB."
#error "LCD_SERIAL_PORT must be from 1 to 6, or -1 for Native USB."
#endif
#if HAS_DGUS_LCD
#define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite()
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/core/serial_hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ struct MultiSerial : public SerialBase< MultiSerial< REPEAT(NUM_SERIAL, _S_NAME)
// Build the actual serial object depending on current configuration
#define Serial1Class TERN(SERIAL_RUNTIME_HOOK, RuntimeSerial, BaseSerial)
#define ForwardSerial1Class TERN(SERIAL_RUNTIME_HOOK, RuntimeSerial, ForwardSerial)
#ifdef HAS_MULTI_SERIAL
#if HAS_MULTI_SERIAL
#define Serial2Class ConditionalSerial
#if NUM_SERIAL >= 3
#define Serial3Class ConditionalSerial
Expand Down

0 comments on commit 2204f05

Please sign in to comment.