Expand serial support in DUE/AVR hals exploiting the templated MarlinSerial classes (#11988)
This commit is contained in:
parent
f6f2246f59
commit
d6955f25b2
|
@ -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
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
// Includes
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "HAL.h"
|
||||
|
||||
#include <Wire.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"
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
// --------------------------------------------------------------------------
|
||||
// Includes
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "HAL.h"
|
||||
|
||||
#include "HAL_timers_Due.h"
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
*/
|
||||
#ifdef ARDUINO_ARCH_SAM
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "HAL.h"
|
||||
#include "InterruptVectors_Due.h"
|
||||
|
||||
|
|
|
@ -285,7 +285,7 @@ void MarlinSerialUSB::printFloat(double number, uint8_t digits) {
|
|||
}
|
||||
|
||||
// Preinstantiate
|
||||
MarlinSerialUSB customizedSerial;
|
||||
MarlinSerialUSB customizedSerial1;
|
||||
|
||||
#endif // SERIAL_PORT == -1
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -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
|
||||
|
||||
extern MarlinSerial<MarlinSerialCfg> customizedSerial;
|
||||
// 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<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
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#ifdef ARDUINO_ARCH_SAM
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "HAL.h"
|
||||
#include "HAL_timers_Due.h"
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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…
Reference in a new issue