Skip to content

Commit

Permalink
Add USB serial support to SERIAL_PORT_2 on DUE (MarlinFirmware#17245)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
  • Loading branch information
2 people authored and mathom committed Apr 16, 2020
1 parent af090f5 commit c66a14d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 29 deletions.
1 change: 0 additions & 1 deletion Marlin/src/HAL/DUE/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
#endif
#endif


#include "MarlinSerial.h"
#include "MarlinSerialUSB.h"

Expand Down
20 changes: 5 additions & 15 deletions Marlin/src/HAL/DUE/MarlinSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,23 +629,13 @@ void MarlinSerial<Cfg>::printFloat(double number, uint8_t digits) {

// If not using the USB port as serial port
#if SERIAL_PORT >= 0

// Preinstantiate
template class MarlinSerial<MarlinSerialCfg<SERIAL_PORT>>;

// Instantiate
MarlinSerial<MarlinSerialCfg<SERIAL_PORT>> customizedSerial1;

template class MarlinSerial<MarlinSerialCfg<SERIAL_PORT>>; // Define
MarlinSerial<MarlinSerialCfg<SERIAL_PORT>> customizedSerial1; // Instantiate
#endif

#ifdef SERIAL_PORT_2

// Preinstantiate
template class MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>>;

// Instantiate
MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>> customizedSerial2;

#if defined(SERIAL_PORT_2) && SERIAL_PORT_2 >= 0
template class MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>>; // Define
MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>> customizedSerial2; // Instantiate
#endif

#endif // ARDUINO_ARCH_SAM
8 changes: 2 additions & 6 deletions Marlin/src/HAL/DUE/MarlinSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,9 @@ struct MarlinSerialCfg {
};

#if SERIAL_PORT >= 0

extern MarlinSerial<MarlinSerialCfg<SERIAL_PORT>> customizedSerial1;
#endif

#endif // SERIAL_PORT >= 0

#ifdef SERIAL_PORT_2

#if defined(SERIAL_PORT_2) && SERIAL_PORT_2 >= 0
extern MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>> customizedSerial2;

#endif
12 changes: 8 additions & 4 deletions Marlin/src/HAL/DUE/MarlinSerialUSB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#include "../../inc/MarlinConfig.h"

#if SERIAL_PORT == -1
#if HAS_USB_SERIAL

#include "MarlinSerialUSB.h"

Expand Down Expand Up @@ -283,8 +283,12 @@ void MarlinSerialUSB::printFloat(double number, uint8_t digits) {
}

// Preinstantiate
MarlinSerialUSB customizedSerial1;

#endif // SERIAL_PORT == -1
#if SERIAL_PORT == -1
MarlinSerialUSB customizedSerial1;
#endif
#if SERIAL_PORT_2 == -1
MarlinSerialUSB customizedSerial2;
#endif

#endif // HAS_USB_SERIAL
#endif // ARDUINO_ARCH_SAM
12 changes: 9 additions & 3 deletions Marlin/src/HAL/DUE/MarlinSerialUSB.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include "../../inc/MarlinConfig.h"

#if SERIAL_PORT == -1
#if HAS_USB_SERIAL

#include <WString.h>

Expand Down Expand Up @@ -88,6 +88,12 @@ class MarlinSerialUSB {
static void printFloat(double, uint8_t);
};

extern MarlinSerialUSB customizedSerial1;
#if SERIAL_PORT == -1
extern MarlinSerialUSB customizedSerial1;
#endif

#if SERIAL_PORT_2 == -1
extern MarlinSerialUSB customizedSerial2;
#endif

#endif // SERIAL_PORT == -1
#endif // HAS_USB_SERIAL
4 changes: 4 additions & 0 deletions Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,10 @@
#define SPI_SPEED SPI_FULL_SPEED
#endif

#if SERIAL_PORT == -1 || SERIAL_PORT_2 == -1
#define HAS_USB_SERIAL 1
#endif

/**
* This setting is also used by M109 when trying to calculate
* a ballpark safe margin to prevent wait-forever situation.
Expand Down

0 comments on commit c66a14d

Please sign in to comment.