Browse Source

Expand serial support in DUE/AVR hals exploiting the templated MarlinSerial classes (#11988)

pull/1/head
Eduardo José Tagle 6 years ago
committed by Scott Lahteine
parent
commit
d6955f25b2
  1. 22
      Marlin/src/HAL/HAL_AVR/HAL.h
  2. 27
      Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp
  3. 24
      Marlin/src/HAL/HAL_AVR/MarlinSerial.h
  4. 1
      Marlin/src/HAL/HAL_DUE/HAL.cpp
  5. 22
      Marlin/src/HAL/HAL_DUE/HAL.h
  6. 2
      Marlin/src/HAL/HAL_DUE/HAL_timers_Due.cpp
  7. 1
      Marlin/src/HAL/HAL_DUE/InterruptVectors_Due.cpp
  8. 2
      Marlin/src/HAL/HAL_DUE/MarlinSerialUSB_Due.cpp
  9. 2
      Marlin/src/HAL/HAL_DUE/MarlinSerialUSB_Due.h
  10. 960
      Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.cpp
  11. 49
      Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.h
  12. 1
      Marlin/src/HAL/HAL_DUE/Tone.cpp
  13. 8
      Marlin/src/gcode/control/M111.cpp
  14. 4
      Marlin/src/gcode/queue.cpp

22
Marlin/src/HAL/HAL_AVR/HAL.h

@ -79,16 +79,32 @@ typedef int8_t pin_t;
//extern uint8_t MCUSR;
#define NUM_SERIAL 1
// Serial ports
#ifdef USBCON
#if ENABLED(BLUETOOTH)
#define MYSERIAL0 bluetoothSerial
#else
#define MYSERIAL0 Serial
#endif
#define NUM_SERIAL 1
#else
#define MYSERIAL0 customizedSerial
#if !WITHIN(SERIAL_PORT, -1, 3)
#error "SERIAL_PORT must be from -1 to 3"
#endif
#define MYSERIAL0 customizedSerial1
#ifdef SERIAL_PORT_2
#if !WITHIN(SERIAL_PORT_2, -1, 3)
#error "SERIAL_PORT_2 must be from -1 to 3"
#elif SERIAL_PORT_2 == SERIAL_PORT
#error "SERIAL_PORT_2 must be different than SERIAL_PORT"
#endif
#define NUM_SERIAL 2
#define MYSERIAL1 customizedSerial2
#else
#define NUM_SERIAL 1
#endif
#endif
// --------------------------------------------------------------------------

27
Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp

@ -705,18 +705,37 @@
// Hookup ISR handlers
ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_RX_vect)) {
MarlinSerial<MarlinSerialCfg>::store_rxd_char();
MarlinSerial<MarlinSerialCfg1>::store_rxd_char();
}
ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_UDRE_vect)) {
MarlinSerial<MarlinSerialCfg>::_tx_udr_empty_irq();
MarlinSerial<MarlinSerialCfg1>::_tx_udr_empty_irq();
}
// Preinstantiate
template class MarlinSerial<MarlinSerialCfg>;
template class MarlinSerial<MarlinSerialCfg1>;
// Instantiate
MarlinSerial<MarlinSerialCfg> customizedSerial;
MarlinSerial<MarlinSerialCfg1> customizedSerial1;
#ifdef SERIAL_PORT_2
// Hookup ISR handlers
ISR(SERIAL_REGNAME(USART,SERIAL_PORT_2,_RX_vect)) {
MarlinSerial<MarlinSerialCfg2>::store_rxd_char();
}
ISR(SERIAL_REGNAME(USART,SERIAL_PORT_2,_UDRE_vect)) {
MarlinSerial<MarlinSerialCfg2>::_tx_udr_empty_irq();
}
// Preinstantiate
template class MarlinSerial<MarlinSerialCfg2>;
// Instantiate
MarlinSerial<MarlinSerialCfg2> customizedSerial2;
#endif
#endif // !USBCON && (UBRRH || UBRR0H || UBRR1H || UBRR2H || UBRR3H)

24
Marlin/src/HAL/HAL_AVR/MarlinSerial.h

@ -256,7 +256,7 @@
};
// Serial port configuration
struct MarlinSerialCfg {
struct MarlinSerialCfg1 {
static constexpr int PORT = SERIAL_PORT;
static constexpr unsigned int RX_SIZE = RX_BUFFER_SIZE;
static constexpr unsigned int TX_SIZE = TX_BUFFER_SIZE;
@ -268,7 +268,27 @@
static constexpr bool MAX_RX_QUEUED = bSERIAL_STATS_MAX_RX_QUEUED;
};
extern MarlinSerial<MarlinSerialCfg> customizedSerial;
extern MarlinSerial<MarlinSerialCfg1> customizedSerial1;
#ifdef SERIAL_PORT_2
// Serial port configuration
struct MarlinSerialCfg2 {
static constexpr int PORT = SERIAL_PORT_2;
static constexpr unsigned int RX_SIZE = RX_BUFFER_SIZE;
static constexpr unsigned int TX_SIZE = TX_BUFFER_SIZE;
static constexpr bool XONOFF = bSERIAL_XON_XOFF;
static constexpr bool EMERGENCYPARSER = bEMERGENCY_PARSER;
static constexpr bool DROPPED_RX = bSERIAL_STATS_DROPPED_RX;
static constexpr bool RX_OVERRUNS = bSERIAL_STATS_RX_BUFFER_OVERRUNS;
static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS;
static constexpr bool MAX_RX_QUEUED = bSERIAL_STATS_MAX_RX_QUEUED;
};
extern MarlinSerial<MarlinSerialCfg2> customizedSerial2;
#endif
#endif // !USBCON

1
Marlin/src/HAL/HAL_DUE/HAL.cpp

@ -29,6 +29,7 @@
// Includes
// --------------------------------------------------------------------------
#include "../../inc/MarlinConfig.h"
#include "HAL.h"
#include <Wire.h>

22
Marlin/src/HAL/HAL_DUE/HAL.h

@ -41,9 +41,25 @@
#include "watchdog_Due.h"
#include "HAL_timers_Due.h"
#define NUM_SERIAL 1
// Required before the include or compilation fails
#define MYSERIAL0 customizedSerial
// Serial ports
#if !WITHIN(SERIAL_PORT, -1, 3)
#error "SERIAL_PORT must be from -1 to 3"
#endif
// MYSERIAL0 required before MarlinSerial includes!
#define MYSERIAL0 customizedSerial1
#ifdef SERIAL_PORT_2
#if !WITHIN(SERIAL_PORT_2, -1, 3)
#error "SERIAL_PORT_2 must be from -1 to 3"
#elif SERIAL_PORT_2 == SERIAL_PORT
#error "SERIAL_PORT_2 must be different than SERIAL_PORT"
#endif
#define NUM_SERIAL 2
#define MYSERIAL1 customizedSerial2
#else
#define NUM_SERIAL 1
#endif
#include "MarlinSerial_Due.h"
#include "MarlinSerialUSB_Due.h"

2
Marlin/src/HAL/HAL_DUE/HAL_timers_Due.cpp

@ -31,7 +31,7 @@
// --------------------------------------------------------------------------
// Includes
// --------------------------------------------------------------------------
#include "../../inc/MarlinConfig.h"
#include "HAL.h"
#include "HAL_timers_Due.h"

1
Marlin/src/HAL/HAL_DUE/InterruptVectors_Due.cpp

@ -32,6 +32,7 @@
*/
#ifdef ARDUINO_ARCH_SAM
#include "../../inc/MarlinConfig.h"
#include "HAL.h"
#include "InterruptVectors_Due.h"

2
Marlin/src/HAL/HAL_DUE/MarlinSerialUSB_Due.cpp

@ -285,7 +285,7 @@ void MarlinSerialUSB::printFloat(double number, uint8_t digits) {
}
// Preinstantiate
MarlinSerialUSB customizedSerial;
MarlinSerialUSB customizedSerial1;
#endif // SERIAL_PORT == -1

2
Marlin/src/HAL/HAL_DUE/MarlinSerialUSB_Due.h

@ -89,7 +89,7 @@ private:
static void printFloat(double, uint8_t);
};
extern MarlinSerialUSB customizedSerial;
extern MarlinSerialUSB customizedSerial1;
#endif // SERIAL_PORT == -1
#endif // MARLINSERIAL_DUE_H

960
Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.cpp

File diff suppressed because it is too large

49
Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.h

@ -31,8 +31,6 @@
#include "../shared/MarlinSerial.h"
#if SERIAL_PORT >= 0
#include <WString.h>
#define DEC 10
@ -161,21 +159,42 @@ private:
static void printFloat(double, uint8_t);
};
// Serial port configuration
struct MarlinSerialCfg {
static constexpr int PORT = SERIAL_PORT;
static constexpr unsigned int RX_SIZE = RX_BUFFER_SIZE;
static constexpr unsigned int TX_SIZE = TX_BUFFER_SIZE;
static constexpr bool XONOFF = bSERIAL_XON_XOFF;
static constexpr bool EMERGENCYPARSER = bEMERGENCY_PARSER;
static constexpr bool DROPPED_RX = bSERIAL_STATS_DROPPED_RX;
static constexpr bool RX_OVERRUNS = bSERIAL_STATS_RX_BUFFER_OVERRUNS;
static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS;
static constexpr bool MAX_RX_QUEUED = bSERIAL_STATS_MAX_RX_QUEUED;
};
#if SERIAL_PORT >= 0
// Serial port configuration
struct MarlinSerialCfg1 {
static constexpr int PORT = SERIAL_PORT;
static constexpr unsigned int RX_SIZE = RX_BUFFER_SIZE;
static constexpr unsigned int TX_SIZE = TX_BUFFER_SIZE;
static constexpr bool XONOFF = bSERIAL_XON_XOFF;
static constexpr bool EMERGENCYPARSER = bEMERGENCY_PARSER;
static constexpr bool DROPPED_RX = bSERIAL_STATS_DROPPED_RX;
static constexpr bool RX_OVERRUNS = bSERIAL_STATS_RX_BUFFER_OVERRUNS;
static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS;
static constexpr bool MAX_RX_QUEUED = bSERIAL_STATS_MAX_RX_QUEUED;
};
extern MarlinSerial<MarlinSerialCfg> customizedSerial;
extern MarlinSerial<MarlinSerialCfg1> customizedSerial1;
#endif // SERIAL_PORT >= 0
#ifdef SERIAL_PORT_2
// Serial port configuration
struct MarlinSerialCfg2 {
static constexpr int PORT = SERIAL_PORT_2;
static constexpr unsigned int RX_SIZE = RX_BUFFER_SIZE;
static constexpr unsigned int TX_SIZE = TX_BUFFER_SIZE;
static constexpr bool XONOFF = bSERIAL_XON_XOFF;
static constexpr bool EMERGENCYPARSER = bEMERGENCY_PARSER;
static constexpr bool DROPPED_RX = bSERIAL_STATS_DROPPED_RX;
static constexpr bool RX_OVERRUNS = bSERIAL_STATS_RX_BUFFER_OVERRUNS;
static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS;
static constexpr bool MAX_RX_QUEUED = bSERIAL_STATS_MAX_RX_QUEUED;
};
extern MarlinSerial<MarlinSerialCfg2> customizedSerial2;
#endif
#endif // MARLINSERIAL_DUE_H

1
Marlin/src/HAL/HAL_DUE/Tone.cpp

@ -27,6 +27,7 @@
#ifdef ARDUINO_ARCH_SAM
#include "../../inc/MarlinConfig.h"
#include "HAL.h"
#include "HAL_timers_Due.h"

8
Marlin/src/gcode/control/M111.cpp

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

4
Marlin/src/gcode/queue.cpp

@ -562,11 +562,11 @@ void advance_command_queue() {
#if !defined(__AVR__) || !defined(USBCON)
#if ENABLED(SERIAL_STATS_DROPPED_RX)
SERIAL_ECHOLNPAIR("Dropped bytes: ", customizedSerial.dropped());
SERIAL_ECHOLNPAIR("Dropped bytes: ", MYSERIAL0.dropped());
#endif
#if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
SERIAL_ECHOLNPAIR("Max RX Queue Size: ", customizedSerial.rxMaxEnqueued());
SERIAL_ECHOLNPAIR("Max RX Queue Size: ", MYSERIAL0.rxMaxEnqueued());
#endif
#endif // !defined(__AVR__) || !defined(USBCON)

Loading…
Cancel
Save