Fix and improve STM32F1 serial (#19464)

This commit is contained in:
Jason Smith 2020-09-24 18:28:48 -07:00 committed by GitHub
parent 6bb6f7f288
commit da6c8317a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 1009 additions and 942 deletions

View file

@ -2165,6 +2165,9 @@
// Touch-screen LCD for Malyan M200/M300 printers // Touch-screen LCD for Malyan M200/M300 printers
// //
//#define MALYAN_LCD //#define MALYAN_LCD
#if ENABLED(MALYAN_LCD)
#define LCD_SERIAL_PORT 1 // Default is 1 for Malyan M200
#endif
// //
// Touch UI for FTDI EVE (FT800/FT810) displays // Touch UI for FTDI EVE (FT800/FT810) displays
@ -2178,7 +2181,7 @@
//#define ANYCUBIC_LCD_I3MEGA //#define ANYCUBIC_LCD_I3MEGA
//#define ANYCUBIC_LCD_CHIRON //#define ANYCUBIC_LCD_CHIRON
#if EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON) #if EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON)
#define ANYCUBIC_LCD_SERIAL_PORT 3 #define LCD_SERIAL_PORT 3 // Default is 3 for Anycubic
//#define ANYCUBIC_LCD_DEBUG //#define ANYCUBIC_LCD_DEBUG
#endif #endif

View file

@ -1404,8 +1404,8 @@
// Additional options for DGUS / DWIN displays // Additional options for DGUS / DWIN displays
// //
#if HAS_DGUS_LCD #if HAS_DGUS_LCD
#define DGUS_SERIAL_PORT 3 #define LCD_SERIAL_PORT 3
#define DGUS_BAUDRATE 115200 #define LCD_BAUDRATE 115200
#define DGUS_RX_BUFFER_SIZE 128 #define DGUS_RX_BUFFER_SIZE 128
#define DGUS_TX_BUFFER_SIZE 48 #define DGUS_TX_BUFFER_SIZE 48
@ -3419,10 +3419,10 @@
#if ENABLED(PRUSA_MMU2) #if ENABLED(PRUSA_MMU2)
// Serial port used for communication with MMU2. // Serial port used for communication with MMU2.
// For AVR enable the UART port used for the MMU. (e.g., internalSerial) // For AVR enable the UART port used for the MMU. (e.g., mmuSerial)
// For 32-bit boards check your HAL for available serial ports. (e.g., Serial2) // For 32-bit boards check your HAL for available serial ports. (e.g., Serial2)
#define INTERNAL_SERIAL_PORT 2 #define MMU2_SERIAL_PORT 2
#define MMU2_SERIAL internalSerial #define MMU2_SERIAL mmuSerial
// Use hardware reset for MMU if a pin is defined for it // Use hardware reset for MMU if a pin is defined for it
//#define MMU2_RST_PIN 23 //#define MMU2_RST_PIN 23

View file

@ -96,19 +96,14 @@ typedef int8_t pin_t;
#endif #endif
#endif #endif
#ifdef DGUS_SERIAL_PORT #ifdef LCD_SERIAL_PORT
#if !WITHIN(DGUS_SERIAL_PORT, -1, 3) #if !WITHIN(LCD_SERIAL_PORT, -1, 3)
#error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration." #error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
#endif #endif
#define DGUS_SERIAL internalDgusSerial #define LCD_SERIAL lcdSerial
#define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.get_tx_buffer_free #if HAS_DGUS_LCD
#endif #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.get_tx_buffer_free()
#ifdef ANYCUBIC_LCD_SERIAL_PORT
#if !WITHIN(ANYCUBIC_LCD_SERIAL_PORT, -1, 3)
#error "ANYCUBIC_LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
#endif #endif
#define ANYCUBIC_LCD_SERIAL anycubicLcdSerial
#endif #endif
// ------------------------ // ------------------------

View file

@ -40,32 +40,32 @@
#if !defined(USBCON) && (defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)) #if !defined(USBCON) && (defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H))
#include "MarlinSerial.h" #include "MarlinSerial.h"
#include "../../MarlinCore.h" #include "../../MarlinCore.h"
#if ENABLED(DIRECT_STEPPING) #if ENABLED(DIRECT_STEPPING)
#include "../../feature/direct_stepping.h" #include "../../feature/direct_stepping.h"
#endif #endif
template<typename Cfg> typename MarlinSerial<Cfg>::ring_buffer_r MarlinSerial<Cfg>::rx_buffer = { 0, 0, { 0 } }; template<typename Cfg> typename MarlinSerial<Cfg>::ring_buffer_r MarlinSerial<Cfg>::rx_buffer = { 0, 0, { 0 } };
template<typename Cfg> typename MarlinSerial<Cfg>::ring_buffer_t MarlinSerial<Cfg>::tx_buffer = { 0 }; template<typename Cfg> typename MarlinSerial<Cfg>::ring_buffer_t MarlinSerial<Cfg>::tx_buffer = { 0 };
template<typename Cfg> bool MarlinSerial<Cfg>::_written = false; template<typename Cfg> bool MarlinSerial<Cfg>::_written = false;
template<typename Cfg> uint8_t MarlinSerial<Cfg>::xon_xoff_state = MarlinSerial<Cfg>::XON_XOFF_CHAR_SENT | MarlinSerial<Cfg>::XON_CHAR; template<typename Cfg> uint8_t MarlinSerial<Cfg>::xon_xoff_state = MarlinSerial<Cfg>::XON_XOFF_CHAR_SENT | MarlinSerial<Cfg>::XON_CHAR;
template<typename Cfg> uint8_t MarlinSerial<Cfg>::rx_dropped_bytes = 0; template<typename Cfg> uint8_t MarlinSerial<Cfg>::rx_dropped_bytes = 0;
template<typename Cfg> uint8_t MarlinSerial<Cfg>::rx_buffer_overruns = 0; template<typename Cfg> uint8_t MarlinSerial<Cfg>::rx_buffer_overruns = 0;
template<typename Cfg> uint8_t MarlinSerial<Cfg>::rx_framing_errors = 0; template<typename Cfg> uint8_t MarlinSerial<Cfg>::rx_framing_errors = 0;
template<typename Cfg> typename MarlinSerial<Cfg>::ring_buffer_pos_t MarlinSerial<Cfg>::rx_max_enqueued = 0; template<typename Cfg> typename MarlinSerial<Cfg>::ring_buffer_pos_t MarlinSerial<Cfg>::rx_max_enqueued = 0;
// A SW memory barrier, to ensure GCC does not overoptimize loops // A SW memory barrier, to ensure GCC does not overoptimize loops
#define sw_barrier() asm volatile("": : :"memory"); #define sw_barrier() asm volatile("": : :"memory");
#include "../../feature/e_parser.h" #include "../../feature/e_parser.h"
// "Atomically" read the RX head index value without disabling interrupts: // "Atomically" read the RX head index value without disabling interrupts:
// This MUST be called with RX interrupts enabled, and CAN'T be called // This MUST be called with RX interrupts enabled, and CAN'T be called
// from the RX ISR itself! // from the RX ISR itself!
template<typename Cfg> template<typename Cfg>
FORCE_INLINE typename MarlinSerial<Cfg>::ring_buffer_pos_t MarlinSerial<Cfg>::atomic_read_rx_head() { FORCE_INLINE typename MarlinSerial<Cfg>::ring_buffer_pos_t MarlinSerial<Cfg>::atomic_read_rx_head() {
if (Cfg::RX_SIZE > 256) { if (Cfg::RX_SIZE > 256) {
// Keep reading until 2 consecutive reads return the same value, // Keep reading until 2 consecutive reads return the same value,
// meaning there was no update in-between caused by an interrupt. // meaning there was no update in-between caused by an interrupt.
@ -85,19 +85,19 @@
// With an 8bit index, reads are always atomic. No need for special handling // With an 8bit index, reads are always atomic. No need for special handling
return rx_buffer.head; return rx_buffer.head;
} }
} }
template<typename Cfg> template<typename Cfg>
volatile bool MarlinSerial<Cfg>::rx_tail_value_not_stable = false; volatile bool MarlinSerial<Cfg>::rx_tail_value_not_stable = false;
template<typename Cfg> template<typename Cfg>
volatile uint16_t MarlinSerial<Cfg>::rx_tail_value_backup = 0; volatile uint16_t MarlinSerial<Cfg>::rx_tail_value_backup = 0;
// Set RX tail index, taking into account the RX ISR could interrupt // Set RX tail index, taking into account the RX ISR could interrupt
// the write to this variable in the middle - So a backup strategy // the write to this variable in the middle - So a backup strategy
// is used to ensure reads of the correct values. // is used to ensure reads of the correct values.
// -Must NOT be called from the RX ISR - // -Must NOT be called from the RX ISR -
template<typename Cfg> template<typename Cfg>
FORCE_INLINE void MarlinSerial<Cfg>::atomic_set_rx_tail(typename MarlinSerial<Cfg>::ring_buffer_pos_t value) { FORCE_INLINE void MarlinSerial<Cfg>::atomic_set_rx_tail(typename MarlinSerial<Cfg>::ring_buffer_pos_t value) {
if (Cfg::RX_SIZE > 256) { if (Cfg::RX_SIZE > 256) {
// Store the new value in the backup // Store the new value in the backup
rx_tail_value_backup = value; rx_tail_value_backup = value;
@ -114,24 +114,24 @@
} }
else else
rx_buffer.tail = value; rx_buffer.tail = value;
} }
// Get the RX tail index, taking into account the read could be // Get the RX tail index, taking into account the read could be
// interrupting in the middle of the update of that index value // interrupting in the middle of the update of that index value
// -Called from the RX ISR - // -Called from the RX ISR -
template<typename Cfg> template<typename Cfg>
FORCE_INLINE typename MarlinSerial<Cfg>::ring_buffer_pos_t MarlinSerial<Cfg>::atomic_read_rx_tail() { FORCE_INLINE typename MarlinSerial<Cfg>::ring_buffer_pos_t MarlinSerial<Cfg>::atomic_read_rx_tail() {
if (Cfg::RX_SIZE > 256) { if (Cfg::RX_SIZE > 256) {
// If the true index is being modified, return the backup value // If the true index is being modified, return the backup value
if (rx_tail_value_not_stable) return rx_tail_value_backup; if (rx_tail_value_not_stable) return rx_tail_value_backup;
} }
// The true index is stable, return it // The true index is stable, return it
return rx_buffer.tail; return rx_buffer.tail;
} }
// (called with RX interrupts disabled) // (called with RX interrupts disabled)
template<typename Cfg> template<typename Cfg>
FORCE_INLINE void MarlinSerial<Cfg>::store_rxd_char() { FORCE_INLINE void MarlinSerial<Cfg>::store_rxd_char() {
static EmergencyParser::State emergency_state; // = EP_RESET static EmergencyParser::State emergency_state; // = EP_RESET
@ -275,11 +275,11 @@
// Store the new head value - The main loop will retry until the value is stable // Store the new head value - The main loop will retry until the value is stable
rx_buffer.head = h; rx_buffer.head = h;
} }
// (called with TX irqs disabled) // (called with TX irqs disabled)
template<typename Cfg> template<typename Cfg>
FORCE_INLINE void MarlinSerial<Cfg>::_tx_udr_empty_irq() { FORCE_INLINE void MarlinSerial<Cfg>::_tx_udr_empty_irq() {
if (Cfg::TX_SIZE > 0) { if (Cfg::TX_SIZE > 0) {
// Read positions // Read positions
uint8_t t = tx_buffer.tail; uint8_t t = tx_buffer.tail;
@ -328,11 +328,11 @@
// Disable interrupts if there is nothing to transmit following this byte // Disable interrupts if there is nothing to transmit following this byte
if (h == t) B_UDRIE = 0; // (Non-atomic, could be reenabled by the main program, but eventually this will succeed) if (h == t) B_UDRIE = 0; // (Non-atomic, could be reenabled by the main program, but eventually this will succeed)
} }
} }
// Public Methods // Public Methods
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::begin(const long baud) { void MarlinSerial<Cfg>::begin(const long baud) {
uint16_t baud_setting; uint16_t baud_setting;
bool useU2X = true; bool useU2X = true;
@ -360,24 +360,24 @@
B_RXCIE = 1; B_RXCIE = 1;
if (Cfg::TX_SIZE > 0) B_UDRIE = 0; if (Cfg::TX_SIZE > 0) B_UDRIE = 0;
_written = false; _written = false;
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::end() { void MarlinSerial<Cfg>::end() {
B_RXEN = 0; B_RXEN = 0;
B_TXEN = 0; B_TXEN = 0;
B_RXCIE = 0; B_RXCIE = 0;
B_UDRIE = 0; B_UDRIE = 0;
} }
template<typename Cfg> template<typename Cfg>
int MarlinSerial<Cfg>::peek() { int MarlinSerial<Cfg>::peek() {
const ring_buffer_pos_t h = atomic_read_rx_head(), t = rx_buffer.tail; const ring_buffer_pos_t h = atomic_read_rx_head(), t = rx_buffer.tail;
return h == t ? -1 : rx_buffer.buffer[t]; return h == t ? -1 : rx_buffer.buffer[t];
} }
template<typename Cfg> template<typename Cfg>
int MarlinSerial<Cfg>::read() { int MarlinSerial<Cfg>::read() {
const ring_buffer_pos_t h = atomic_read_rx_head(); const ring_buffer_pos_t h = atomic_read_rx_head();
// Read the tail. Main thread owns it, so it is safe to directly read it // Read the tail. Main thread owns it, so it is safe to directly read it
@ -417,16 +417,16 @@
} }
return v; return v;
} }
template<typename Cfg> template<typename Cfg>
typename MarlinSerial<Cfg>::ring_buffer_pos_t MarlinSerial<Cfg>::available() { typename MarlinSerial<Cfg>::ring_buffer_pos_t MarlinSerial<Cfg>::available() {
const ring_buffer_pos_t h = atomic_read_rx_head(), t = rx_buffer.tail; const ring_buffer_pos_t h = atomic_read_rx_head(), t = rx_buffer.tail;
return (ring_buffer_pos_t)(Cfg::RX_SIZE + h - t) & (Cfg::RX_SIZE - 1); return (ring_buffer_pos_t)(Cfg::RX_SIZE + h - t) & (Cfg::RX_SIZE - 1);
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::flush() { void MarlinSerial<Cfg>::flush() {
// Set the tail to the head: // Set the tail to the head:
// - Read the RX head index in a safe way. (See atomic_read_rx_head.) // - Read the RX head index in a safe way. (See atomic_read_rx_head.)
@ -451,10 +451,10 @@
} }
} }
} }
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::write(const uint8_t c) { void MarlinSerial<Cfg>::write(const uint8_t c) {
if (Cfg::TX_SIZE == 0) { if (Cfg::TX_SIZE == 0) {
_written = true; _written = true;
@ -510,10 +510,10 @@
// Enable TX ISR - Non atomic, but it will eventually enable TX ISR // Enable TX ISR - Non atomic, but it will eventually enable TX ISR
B_UDRIE = 1; B_UDRIE = 1;
} }
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::flushTX() { void MarlinSerial<Cfg>::flushTX() {
if (Cfg::TX_SIZE == 0) { if (Cfg::TX_SIZE == 0) {
// No bytes written, no need to flush. This special case is needed since there's // No bytes written, no need to flush. This special case is needed since there's
@ -554,34 +554,34 @@
// At this point nothing is queued anymore (DRIE is disabled) and // At this point nothing is queued anymore (DRIE is disabled) and
// the hardware finished transmission (TXC is set). // the hardware finished transmission (TXC is set).
} }
} }
/** /**
* Imports from print.h * Imports from print.h
*/ */
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::print(char c, int base) { void MarlinSerial<Cfg>::print(char c, int base) {
print((long)c, base); print((long)c, base);
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::print(unsigned char b, int base) { void MarlinSerial<Cfg>::print(unsigned char b, int base) {
print((unsigned long)b, base); print((unsigned long)b, base);
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::print(int n, int base) { void MarlinSerial<Cfg>::print(int n, int base) {
print((long)n, base); print((long)n, base);
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::print(unsigned int n, int base) { void MarlinSerial<Cfg>::print(unsigned int n, int base) {
print((unsigned long)n, base); print((unsigned long)n, base);
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::print(long n, int base) { void MarlinSerial<Cfg>::print(long n, int base) {
if (base == 0) write(n); if (base == 0) write(n);
else if (base == 10) { else if (base == 10) {
if (n < 0) { print('-'); n = -n; } if (n < 0) { print('-'); n = -n; }
@ -589,83 +589,83 @@
} }
else else
printNumber(n, base); printNumber(n, base);
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::print(unsigned long n, int base) { void MarlinSerial<Cfg>::print(unsigned long n, int base) {
if (base == 0) write(n); if (base == 0) write(n);
else printNumber(n, base); else printNumber(n, base);
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::print(double n, int digits) { void MarlinSerial<Cfg>::print(double n, int digits) {
printFloat(n, digits); printFloat(n, digits);
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println() { void MarlinSerial<Cfg>::println() {
print('\r'); print('\r');
print('\n'); print('\n');
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(const String& s) { void MarlinSerial<Cfg>::println(const String& s) {
print(s); print(s);
println(); println();
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(const char c[]) { void MarlinSerial<Cfg>::println(const char c[]) {
print(c); print(c);
println(); println();
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(char c, int base) { void MarlinSerial<Cfg>::println(char c, int base) {
print(c, base); print(c, base);
println(); println();
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(unsigned char b, int base) { void MarlinSerial<Cfg>::println(unsigned char b, int base) {
print(b, base); print(b, base);
println(); println();
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(int n, int base) { void MarlinSerial<Cfg>::println(int n, int base) {
print(n, base); print(n, base);
println(); println();
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(unsigned int n, int base) { void MarlinSerial<Cfg>::println(unsigned int n, int base) {
print(n, base); print(n, base);
println(); println();
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(long n, int base) { void MarlinSerial<Cfg>::println(long n, int base) {
print(n, base); print(n, base);
println(); println();
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(unsigned long n, int base) { void MarlinSerial<Cfg>::println(unsigned long n, int base) {
print(n, base); print(n, base);
println(); println();
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(double n, int digits) { void MarlinSerial<Cfg>::println(double n, int digits) {
print(n, digits); print(n, digits);
println(); println();
} }
// Private Methods // Private Methods
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::printNumber(unsigned long n, uint8_t base) { void MarlinSerial<Cfg>::printNumber(unsigned long n, uint8_t base) {
if (n) { if (n) {
unsigned char buf[8 * sizeof(long)]; // Enough space for base 2 unsigned char buf[8 * sizeof(long)]; // Enough space for base 2
int8_t i = 0; int8_t i = 0;
@ -678,10 +678,10 @@
} }
else else
print('0'); print('0');
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::printFloat(double number, uint8_t digits) { void MarlinSerial<Cfg>::printFloat(double number, uint8_t digits) {
// Handle negative numbers // Handle negative numbers
if (number < 0.0) { if (number < 0.0) {
print('-'); print('-');
@ -709,24 +709,24 @@
remainder -= toPrint; remainder -= toPrint;
} }
} }
} }
// Hookup ISR handlers // Hookup ISR handlers
ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _RX_vect)) { ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _RX_vect)) {
MarlinSerial<MarlinSerialCfg<SERIAL_PORT>>::store_rxd_char(); MarlinSerial<MarlinSerialCfg<SERIAL_PORT>>::store_rxd_char();
} }
ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _UDRE_vect)) { ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _UDRE_vect)) {
MarlinSerial<MarlinSerialCfg<SERIAL_PORT>>::_tx_udr_empty_irq(); MarlinSerial<MarlinSerialCfg<SERIAL_PORT>>::_tx_udr_empty_irq();
} }
// Preinstantiate // Preinstantiate
template class MarlinSerial<MarlinSerialCfg<SERIAL_PORT>>; template class MarlinSerial<MarlinSerialCfg<SERIAL_PORT>>;
// Instantiate // Instantiate
MarlinSerial<MarlinSerialCfg<SERIAL_PORT>> customizedSerial1; MarlinSerial<MarlinSerialCfg<SERIAL_PORT>> customizedSerial1;
#ifdef SERIAL_PORT_2 #ifdef SERIAL_PORT_2
// Hookup ISR handlers // Hookup ISR handlers
ISR(SERIAL_REGNAME(USART, SERIAL_PORT_2, _RX_vect)) { ISR(SERIAL_REGNAME(USART, SERIAL_PORT_2, _RX_vect)) {
@ -743,30 +743,43 @@
// Instantiate // Instantiate
MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>> customizedSerial2; MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>> customizedSerial2;
#endif #endif
#endif // !USBCON && (UBRRH || UBRR0H || UBRR1H || UBRR2H || UBRR3H) #ifdef MMU2_SERIAL_PORT
#ifdef INTERNAL_SERIAL_PORT ISR(SERIAL_REGNAME(USART, MMU2_SERIAL_PORT, _RX_vect)) {
MarlinSerial<MMU2SerialCfg<MMU2_SERIAL_PORT>>::store_rxd_char();
ISR(SERIAL_REGNAME(USART, INTERNAL_SERIAL_PORT, _RX_vect)) {
MarlinSerial<MarlinInternalSerialCfg<INTERNAL_SERIAL_PORT>>::store_rxd_char();
} }
ISR(SERIAL_REGNAME(USART, INTERNAL_SERIAL_PORT, _UDRE_vect)) { ISR(SERIAL_REGNAME(USART, MMU2_SERIAL_PORT, _UDRE_vect)) {
MarlinSerial<MarlinInternalSerialCfg<INTERNAL_SERIAL_PORT>>::_tx_udr_empty_irq(); MarlinSerial<MMU2SerialCfg<MMU2_SERIAL_PORT>>::_tx_udr_empty_irq();
} }
// Preinstantiate // Preinstantiate
template class MarlinSerial<MarlinInternalSerialCfg<INTERNAL_SERIAL_PORT>>; template class MarlinSerial<MMU2SerialCfg<MMU2_SERIAL_PORT>>;
// Instantiate // Instantiate
MarlinSerial<MarlinInternalSerialCfg<INTERNAL_SERIAL_PORT>> internalSerial; MarlinSerial<MMU2SerialCfg<MMU2_SERIAL_PORT>> mmuSerial;
#endif #endif
#ifdef DGUS_SERIAL_PORT #ifdef LCD_SERIAL_PORT
ISR(SERIAL_REGNAME(USART, LCD_SERIAL_PORT, _RX_vect)) {
MarlinSerial<LCDSerialCfg<LCD_SERIAL_PORT>>::store_rxd_char();
}
ISR(SERIAL_REGNAME(USART, LCD_SERIAL_PORT, _UDRE_vect)) {
MarlinSerial<LCDSerialCfg<LCD_SERIAL_PORT>>::_tx_udr_empty_irq();
}
// Preinstantiate
template class MarlinSerial<LCDSerialCfg<LCD_SERIAL_PORT>>;
// Instantiate
MarlinSerial<LCDSerialCfg<LCD_SERIAL_PORT>> lcdSerial;
#if HAS_DGUS_LCD
template<typename Cfg> template<typename Cfg>
typename MarlinSerial<Cfg>::ring_buffer_pos_t MarlinSerial<Cfg>::get_tx_buffer_free() { typename MarlinSerial<Cfg>::ring_buffer_pos_t MarlinSerial<Cfg>::get_tx_buffer_free() {
const ring_buffer_pos_t t = tx_buffer.tail, // next byte to send. const ring_buffer_pos_t t = tx_buffer.tail, // next byte to send.
@ -775,40 +788,11 @@
if (ret < 0) ret += Cfg::TX_SIZE + 1; if (ret < 0) ret += Cfg::TX_SIZE + 1;
return ret; return ret;
} }
#endif
ISR(SERIAL_REGNAME(USART, DGUS_SERIAL_PORT, _RX_vect)) {
MarlinSerial<MarlinInternalSerialCfg<DGUS_SERIAL_PORT>>::store_rxd_char();
}
ISR(SERIAL_REGNAME(USART, DGUS_SERIAL_PORT, _UDRE_vect)) {
MarlinSerial<MarlinInternalSerialCfg<DGUS_SERIAL_PORT>>::_tx_udr_empty_irq();
}
// Preinstantiate
template class MarlinSerial<MarlinInternalSerialCfg<DGUS_SERIAL_PORT>>;
// Instantiate
MarlinSerial<MarlinInternalSerialCfg<DGUS_SERIAL_PORT>> internalDgusSerial;
#endif #endif
#ifdef ANYCUBIC_LCD_SERIAL_PORT #endif // !USBCON && (UBRRH || UBRR0H || UBRR1H || UBRR2H || UBRR3H)
ISR(SERIAL_REGNAME(USART, ANYCUBIC_LCD_SERIAL_PORT, _RX_vect)) {
MarlinSerial<AnycubicLcdSerialCfg<ANYCUBIC_LCD_SERIAL_PORT>>::store_rxd_char();
}
ISR(SERIAL_REGNAME(USART, ANYCUBIC_LCD_SERIAL_PORT, _UDRE_vect)) {
MarlinSerial<AnycubicLcdSerialCfg<ANYCUBIC_LCD_SERIAL_PORT>>::_tx_udr_empty_irq();
}
// Preinstantiate
template class MarlinSerial<AnycubicLcdSerialCfg<ANYCUBIC_LCD_SERIAL_PORT>>;
// Instantiate
MarlinSerial<AnycubicLcdSerialCfg<ANYCUBIC_LCD_SERIAL_PORT>> anycubicLcdSerial;
#endif
// For AT90USB targets use the UART for BT interfacing // For AT90USB targets use the UART for BT interfacing
#if defined(USBCON) && ENABLED(BLUETOOTH) #if defined(USBCON) && ENABLED(BLUETOOTH)

View file

@ -217,10 +217,12 @@
static ring_buffer_pos_t available(); static ring_buffer_pos_t available();
static void write(const uint8_t c); static void write(const uint8_t c);
static void flushTX(); static void flushTX();
#ifdef DGUS_SERIAL_PORT #if HAS_DGUS_LCD
static ring_buffer_pos_t get_tx_buffer_free(); static ring_buffer_pos_t get_tx_buffer_free();
#endif #endif
static inline bool emergency_parser_enabled() { return Cfg::EMERGENCYPARSER; }
FORCE_INLINE static uint8_t dropped() { return Cfg::DROPPED_RX ? rx_dropped_bytes : 0; } FORCE_INLINE static uint8_t dropped() { return Cfg::DROPPED_RX ? rx_dropped_bytes : 0; }
FORCE_INLINE static uint8_t buffer_overruns() { return Cfg::RX_OVERRUNS ? rx_buffer_overruns : 0; } FORCE_INLINE static uint8_t buffer_overruns() { return Cfg::RX_OVERRUNS ? rx_buffer_overruns : 0; }
FORCE_INLINE static uint8_t framing_errors() { return Cfg::RX_FRAMING_ERRORS ? rx_framing_errors : 0; } FORCE_INLINE static uint8_t framing_errors() { return Cfg::RX_FRAMING_ERRORS ? rx_framing_errors : 0; }
@ -278,55 +280,50 @@
#endif // !USBCON #endif // !USBCON
#ifdef INTERNAL_SERIAL_PORT #ifdef MMU2_SERIAL_PORT
template <uint8_t serial> template <uint8_t serial>
struct MarlinInternalSerialCfg { struct MMU2SerialCfg {
static constexpr int PORT = serial; static constexpr int PORT = serial;
static constexpr bool XONOFF = false;
static constexpr bool EMERGENCYPARSER = false;
static constexpr bool DROPPED_RX = false;
static constexpr bool RX_FRAMING_ERRORS = false;
static constexpr bool MAX_RX_QUEUED = false;
static constexpr unsigned int RX_SIZE = 32; static constexpr unsigned int RX_SIZE = 32;
static constexpr unsigned int TX_SIZE = 32; static constexpr unsigned int TX_SIZE = 32;
static constexpr bool XONOFF = false;
static constexpr bool EMERGENCYPARSER = false;
static constexpr bool DROPPED_RX = false;
static constexpr bool RX_OVERRUNS = false; static constexpr bool RX_OVERRUNS = false;
static constexpr bool RX_FRAMING_ERRORS = false;
static constexpr bool MAX_RX_QUEUED = false;
}; };
extern MarlinSerial<MarlinInternalSerialCfg<INTERNAL_SERIAL_PORT>> internalSerial; extern MarlinSerial<MMU2SerialCfg<MMU2_SERIAL_PORT>> mmuSerial;
#endif #endif
#ifdef DGUS_SERIAL_PORT #ifdef LCD_SERIAL_PORT
template <uint8_t serial> template <uint8_t serial>
struct MarlinInternalSerialCfg { struct LCDSerialCfg {
static constexpr int PORT = serial; static constexpr int PORT = serial;
static constexpr bool XONOFF = false;
static constexpr bool EMERGENCYPARSER = ENABLED(EMERGENCY_PARSER);
static constexpr bool DROPPED_RX = false;
static constexpr bool RX_FRAMING_ERRORS = false;
static constexpr bool MAX_RX_QUEUED = false;
#if HAS_DGUS_LCD
static constexpr unsigned int RX_SIZE = DGUS_RX_BUFFER_SIZE; static constexpr unsigned int RX_SIZE = DGUS_RX_BUFFER_SIZE;
static constexpr unsigned int TX_SIZE = DGUS_TX_BUFFER_SIZE; static constexpr unsigned int TX_SIZE = DGUS_TX_BUFFER_SIZE;
static constexpr bool XONOFF = false; static constexpr bool RX_OVERRUNS = ENABLED(DGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS);
static constexpr bool EMERGENCYPARSER = false; #elif EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON)
static constexpr bool DROPPED_RX = false;
static constexpr bool RX_OVERRUNS = BOTH(HAS_DGUS_LCD, DGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS);
static constexpr bool RX_FRAMING_ERRORS = false;
static constexpr bool MAX_RX_QUEUED = false;
};
extern MarlinSerial<MarlinInternalSerialCfg<DGUS_SERIAL_PORT>> internalDgusSerial;
#endif
#ifdef ANYCUBIC_LCD_SERIAL_PORT
template <uint8_t serial>
struct AnycubicLcdSerialCfg {
static constexpr int PORT = serial;
static constexpr unsigned int RX_SIZE = 64; static constexpr unsigned int RX_SIZE = 64;
static constexpr unsigned int TX_SIZE = 128; static constexpr unsigned int TX_SIZE = 128;
static constexpr bool XONOFF = false;
static constexpr bool EMERGENCYPARSER = false;
static constexpr bool DROPPED_RX = false;
static constexpr bool RX_OVERRUNS = false; static constexpr bool RX_OVERRUNS = false;
static constexpr bool RX_FRAMING_ERRORS = false; #else
static constexpr bool MAX_RX_QUEUED = false; static constexpr unsigned int RX_SIZE = 64;
static constexpr unsigned int TX_SIZE = 128;
static constexpr bool RX_OVERRUNS = false
#endif
}; };
extern MarlinSerial<AnycubicLcdSerialCfg<ANYCUBIC_LCD_SERIAL_PORT>> anycubicLcdSerial; extern MarlinSerial<LCDSerialCfg<LCD_SERIAL_PORT>> lcdSerial;
#endif #endif
// Use the UART for Bluetooth in AT90USB configurations // Use the UART for Bluetooth in AT90USB configurations

View file

@ -61,13 +61,13 @@
#endif #endif
#endif #endif
#ifdef DGUS_SERIAL_PORT #ifdef LCD_SERIAL_PORT
#if DGUS_SERIAL_PORT == -1 #if LCD_SERIAL_PORT == -1
#define DGUS_SERIAL internalDgusSerial #define LCD_SERIAL lcdSerial
#elif WITHIN(DGUS_SERIAL_PORT, 0, 3) #elif WITHIN(LCD_SERIAL_PORT, 0, 3)
#define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#else #else
#error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration." #error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
#endif #endif
#endif #endif

View file

@ -122,6 +122,8 @@ public:
static void write(const uint8_t c); static void write(const uint8_t c);
static void flushTX(); static void flushTX();
static inline bool emergency_parser_enabled() { return Cfg::EMERGENCYPARSER; }
FORCE_INLINE static uint8_t dropped() { return Cfg::DROPPED_RX ? rx_dropped_bytes : 0; } FORCE_INLINE static uint8_t dropped() { return Cfg::DROPPED_RX ? rx_dropped_bytes : 0; }
FORCE_INLINE static uint8_t buffer_overruns() { return Cfg::RX_OVERRUNS ? rx_buffer_overruns : 0; } FORCE_INLINE static uint8_t buffer_overruns() { return Cfg::RX_OVERRUNS ? rx_buffer_overruns : 0; }
FORCE_INLINE static uint8_t framing_errors() { return Cfg::RX_FRAMING_ERRORS ? rx_framing_errors : 0; } FORCE_INLINE static uint8_t framing_errors() { return Cfg::RX_FRAMING_ERRORS ? rx_framing_errors : 0; }

View file

@ -79,6 +79,7 @@ public:
#if ENABLED(EMERGENCY_PARSER) #if ENABLED(EMERGENCY_PARSER)
EmergencyParser::State emergency_state; EmergencyParser::State emergency_state;
static inline bool emergency_parser_enabled() { return true; }
#endif #endif
HalSerial() { host_connected = true; } HalSerial() { host_connected = true; }

View file

@ -85,13 +85,13 @@ extern "C" volatile uint32_t _millis;
#endif #endif
#endif #endif
#ifdef DGUS_SERIAL_PORT #ifdef LCD_SERIAL_PORT
#if DGUS_SERIAL_PORT == -1 #if LCD_SERIAL_PORT == -1
#define DGUS_SERIAL UsbSerial #define LCD_SERIAL UsbSerial
#elif WITHIN(DGUS_SERIAL_PORT, 0, 3) #elif WITHIN(LCD_SERIAL_PORT, 0, 3)
#define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#else #else
#error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration." #error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
#endif #endif
#endif #endif

View file

@ -24,28 +24,28 @@
#include "../../inc/MarlinConfigPre.h" #include "../../inc/MarlinConfigPre.h"
#include "MarlinSerial.h" #include "MarlinSerial.h"
#if (defined(SERIAL_PORT) && SERIAL_PORT == 0) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == 0) || (defined(DGUS_SERIAL_PORT) && DGUS_SERIAL_PORT == 0) #if USING_SERIAL_0
MarlinSerial MSerial(LPC_UART0); MarlinSerial MSerial(LPC_UART0);
extern "C" void UART0_IRQHandler() { extern "C" void UART0_IRQHandler() {
MSerial.IRQHandler(); MSerial.IRQHandler();
} }
#endif #endif
#if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1 || DGUS_SERIAL_PORT == 1 #if USING_SERIAL_1
MarlinSerial MSerial1((LPC_UART_TypeDef *) LPC_UART1); MarlinSerial MSerial1((LPC_UART_TypeDef *) LPC_UART1);
extern "C" void UART1_IRQHandler() { extern "C" void UART1_IRQHandler() {
MSerial1.IRQHandler(); MSerial1.IRQHandler();
} }
#endif #endif
#if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 || DGUS_SERIAL_PORT == 2 #if USING_SERIAL_2
MarlinSerial MSerial2(LPC_UART2); MarlinSerial MSerial2(LPC_UART2);
extern "C" void UART2_IRQHandler() { extern "C" void UART2_IRQHandler() {
MSerial2.IRQHandler(); MSerial2.IRQHandler();
} }
#endif #endif
#if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 || DGUS_SERIAL_PORT == 3 #if USING_SERIAL_3
MarlinSerial MSerial3(LPC_UART3); MarlinSerial MSerial3(LPC_UART3);
extern "C" void UART3_IRQHandler() { extern "C" void UART3_IRQHandler() {
MSerial3.IRQHandler(); MSerial3.IRQHandler();

View file

@ -57,6 +57,7 @@ public:
} }
EmergencyParser::State emergency_state; EmergencyParser::State emergency_state;
static inline bool emergency_parser_enabled() { return true; }
#endif #endif
}; };

View file

@ -92,7 +92,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
#define ANY_TX(N,V...) DO(IS_TX##N,||,V) #define ANY_TX(N,V...) DO(IS_TX##N,||,V)
#define ANY_RX(N,V...) DO(IS_RX##N,||,V) #define ANY_RX(N,V...) DO(IS_RX##N,||,V)
#if (defined(SERIAL_PORT) && SERIAL_PORT == 0) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == 0) || (defined(DGUS_SERIAL_PORT) && DGUS_SERIAL_PORT == 0) #if USING_SERIAL_0
#define IS_TX0(P) (P == P0_02) #define IS_TX0(P) (P == P0_02)
#define IS_RX0(P) (P == P0_03) #define IS_RX0(P) (P == P0_03)
#if IS_TX0(TMC_SW_MISO) || IS_RX0(TMC_SW_MOSI) #if IS_TX0(TMC_SW_MISO) || IS_RX0(TMC_SW_MOSI)
@ -106,7 +106,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
#undef IS_RX0 #undef IS_RX0
#endif #endif
#if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1 || DGUS_SERIAL_PORT == 1 #if USING_SERIAL_1
#define IS_TX1(P) (P == P0_15) #define IS_TX1(P) (P == P0_15)
#define IS_RX1(P) (P == P0_16) #define IS_RX1(P) (P == P0_16)
#define _IS_TX1_1 IS_TX1 #define _IS_TX1_1 IS_TX1
@ -127,7 +127,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
#undef _IS_RX1_1 #undef _IS_RX1_1
#endif #endif
#if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 || DGUS_SERIAL_PORT == 2 #if USING_SERIAL_2
#define IS_TX2(P) (P == P0_10) #define IS_TX2(P) (P == P0_10)
#define IS_RX2(P) (P == P0_11) #define IS_RX2(P) (P == P0_11)
#define _IS_TX2_1 IS_TX2 #define _IS_TX2_1 IS_TX2
@ -161,7 +161,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
#undef _IS_RX2_1 #undef _IS_RX2_1
#endif #endif
#if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 || DGUS_SERIAL_PORT == 3 #if USING_SERIAL_3
#define PIN_IS_TX3(P) (PIN_EXISTS(P) && P##_PIN == P0_00) #define PIN_IS_TX3(P) (PIN_EXISTS(P) && P##_PIN == P0_00)
#define PIN_IS_RX3(P) (P##_PIN == P0_01) #define PIN_IS_RX3(P) (P##_PIN == P0_01)
#if PIN_IS_TX3(X_MIN) || PIN_IS_RX3(X_MAX) #if PIN_IS_TX3(X_MIN) || PIN_IS_RX3(X_MAX)

View file

@ -26,7 +26,9 @@
#if ENABLED(EMERGENCY_PARSER) #if ENABLED(EMERGENCY_PARSER)
#include "../../feature/e_parser.h" #include "../../feature/e_parser.h"
EmergencyParser::State emergency_state; EmergencyParser::State emergency_state;
bool CDC_RecvCallback(const char buffer) { bool CDC_RecvCallback(const char buffer) {
emergency_parser.update(emergency_state, buffer); emergency_parser.update(emergency_state, buffer);
return true; return true;

View file

@ -56,13 +56,13 @@
#endif #endif
#endif #endif
#ifdef DGUS_SERIAL_PORT #ifdef LCD_SERIAL_PORT
#if DGUS_SERIAL_PORT == -1 #if LCD_SERIAL_PORT == -1
#define DGUS_SERIAL Serial #define LCD_SERIAL Serial
#elif WITHIN(DGUS_SERIAL_PORT, 0, 3) #elif WITHIN(LCD_SERIAL_PORT, 0, 3)
#define MYSERIAL0 MSERIAL(DGUS_SERIAL_PORT) #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#else #else
#error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration." #error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
#endif #endif
#endif #endif

View file

@ -64,18 +64,7 @@
#endif #endif
#endif #endif
#if HAS_DGUS_LCD #ifdef LCD_SERIAL_PORT
#if DGUS_SERIAL_PORT == -1
#define DGUS_SERIAL SerialUSB
#elif WITHIN(DGUS_SERIAL_PORT, 1, 6)
#define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT)
#else
#error "DGUS_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
#endif
#define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.availableForWrite
#endif
#if ENABLED(MALYAN_LCD)
#if LCD_SERIAL_PORT == -1 #if LCD_SERIAL_PORT == -1
#define LCD_SERIAL SerialUSB #define LCD_SERIAL SerialUSB
#elif WITHIN(LCD_SERIAL_PORT, 1, 6) #elif WITHIN(LCD_SERIAL_PORT, 1, 6)
@ -83,6 +72,9 @@
#else #else
#error "LCD_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration." #error "LCD_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
#endif #endif
#if HAS_DGUS_LCD
#define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite()
#endif
#endif #endif
/** /**

View file

@ -49,8 +49,8 @@
DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2) DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2)
#endif #endif
#if defined(DGUS_SERIAL_PORT) && DGUS_SERIAL_PORT >= 0 #if defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT >= 0
DECLARE_SERIAL_PORT_EXP(DGUS_SERIAL_PORT) DECLARE_SERIAL_PORT_EXP(LCD_SERIAL_PORT)
#endif #endif
void MarlinSerial::begin(unsigned long baud, uint8_t config) { void MarlinSerial::begin(unsigned long baud, uint8_t config) {

View file

@ -35,6 +35,10 @@ public:
#endif #endif
{ } { }
#if ENABLED(EMERGENCY_PARSER)
static inline bool emergency_parser_enabled() { return true; }
#endif
void begin(unsigned long baud, uint8_t config); void begin(unsigned long baud, uint8_t config);
inline void begin(unsigned long baud) { begin(baud, SERIAL_8N1); } inline void begin(unsigned long baud) { begin(baud, SERIAL_8N1); }

View file

@ -68,71 +68,49 @@
#endif #endif
#endif #endif
#if SERIAL_PORT == 0 #define _MSERIAL(X) MSerial##X
#error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration." #define MSERIAL(X) _MSERIAL(X)
#elif SERIAL_PORT == -1
#define MYSERIAL0 UsbSerial #if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY)
#elif SERIAL_PORT == 1 #define NUM_UARTS 5
#define MYSERIAL0 MSerial1
#elif SERIAL_PORT == 2
#define MYSERIAL0 MSerial2
#elif SERIAL_PORT == 3
#define MYSERIAL0 MSerial3
#elif SERIAL_PORT == 4
#define MYSERIAL0 MSerial4
#elif SERIAL_PORT == 5
#define MYSERIAL0 MSerial5
#else #else
#error "SERIAL_PORT must be from -1 to 5. Please update your configuration." #define NUM_UARTS 3
#endif
#if SERIAL_PORT == -1
#define MYSERIAL0 UsbSerial
#elif WITHIN(SERIAL_PORT, 1, NUM_UARTS)
#define MYSERIAL0 MSERIAL(SERIAL_PORT)
#elif NUM_UARTS == 5
#error "SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
#else
#error "SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration."
#endif #endif
#ifdef SERIAL_PORT_2 #ifdef SERIAL_PORT_2
#if SERIAL_PORT_2 == 0 #if SERIAL_PORT_2 == -1
#error "SERIAL_PORT_2 cannot be 0. (Port 0 does not exist.) Please update your configuration."
#elif SERIAL_PORT_2 == SERIAL_PORT
#error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration."
#elif SERIAL_PORT_2 == -1
#define MYSERIAL1 UsbSerial #define MYSERIAL1 UsbSerial
#elif SERIAL_PORT_2 == 1 #elif WITHIN(SERIAL_PORT_2, 1, NUM_UARTS)
#define MYSERIAL1 MSerial1 #define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
#elif SERIAL_PORT_2 == 2 #elif NUM_UARTS == 5
#define MYSERIAL1 MSerial2 #error "SERIAL_PORT_2 must be -1 or from 1 to 5. Please update your configuration."
#elif SERIAL_PORT_2 == 3
#define MYSERIAL1 MSerial3
#elif SERIAL_PORT_2 == 4
#define MYSERIAL1 MSerial4
#elif SERIAL_PORT_2 == 5
#define MYSERIAL1 MSerial5
#else #else
#error "SERIAL_PORT_2 must be from -1 to 5. Please update your configuration." #error "SERIAL_PORT_2 must be -1 or from 1 to 3. Please update your configuration."
#endif #endif
#endif #endif
#ifdef DGUS_SERIAL_PORT #ifdef LCD_SERIAL_PORT
#if DGUS_SERIAL_PORT == 0 #if LCD_SERIAL_PORT == -1
#error "DGUS_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration." #define LCD_SERIAL UsbSerial
#elif DGUS_SERIAL_PORT == SERIAL_PORT #elif WITHIN(LCD_SERIAL_PORT, 1, NUM_UARTS)
#error "DGUS_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration." #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2 #elif NUM_UARTS == 5
#error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." #error "LCD_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration."
#elif DGUS_SERIAL_PORT == -1
#define DGUS_SERIAL UsbSerial
#elif DGUS_SERIAL_PORT == 1
#define DGUS_SERIAL MSerial1
#elif DGUS_SERIAL_PORT == 2
#define DGUS_SERIAL MSerial2
#elif DGUS_SERIAL_PORT == 3
#define DGUS_SERIAL MSerial3
#elif DGUS_SERIAL_PORT == 4
#define DGUS_SERIAL MSerial4
#elif DGUS_SERIAL_PORT == 5
#define DGUS_SERIAL MSerial5
#else #else
#error "DGUS_SERIAL_PORT must be from -1 to 5. Please update your configuration." #error "LCD_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration."
#endif #endif
#endif #endif
// Set interrupt grouping for this MCU // Set interrupt grouping for this MCU
void HAL_init(); void HAL_init();
#define HAL_IDLETASK 1 #define HAL_IDLETASK 1

View file

@ -22,7 +22,7 @@
#ifdef __STM32F1__ #ifdef __STM32F1__
#include "../../inc/MarlinConfigPre.h" #include "../../inc/MarlinConfig.h"
#include "MarlinSerial.h" #include "MarlinSerial.h"
#include <libmaple/usart.h> #include <libmaple/usart.h>
@ -53,6 +53,7 @@ static inline __always_inline void my_usart_irq(ring_buffer *rb, ring_buffer *wb
rb_push_insert(rb, c); rb_push_insert(rb, c);
#endif #endif
#if ENABLED(EMERGENCY_PARSER) #if ENABLED(EMERGENCY_PARSER)
if (serial.emergency_parser_enabled())
emergency_parser.update(serial.emergency_state, c); emergency_parser.update(serial.emergency_state, c);
#endif #endif
} }
@ -73,10 +74,27 @@ static inline __always_inline void my_usart_irq(ring_buffer *rb, ring_buffer *wb
} }
} }
// Not every MarlinSerial port should handle emergency parsing.
// It would not make sense to parse GCode from TMC responses, for example.
constexpr bool serial_handles_emergency(int port) {
return false
#ifdef SERIAL_PORT
|| (SERIAL_PORT) == port
#endif
#ifdef SERIAL_PORT_2
|| (SERIAL_PORT_2) == port
#endif
#ifdef LCD_SERIAL_PORT
|| (LCD_SERIAL_PORT) == port
#endif
;
}
#define DEFINE_HWSERIAL_MARLIN(name, n) \ #define DEFINE_HWSERIAL_MARLIN(name, n) \
MarlinSerial name(USART##n, \ MarlinSerial name(USART##n, \
BOARD_USART##n##_TX_PIN, \ BOARD_USART##n##_TX_PIN, \
BOARD_USART##n##_RX_PIN); \ BOARD_USART##n##_RX_PIN, \
serial_handles_emergency(n)); \
extern "C" void __irq_usart##n(void) { \ extern "C" void __irq_usart##n(void) { \
my_usart_irq(USART##n->rb, USART##n->wb, USART##n##_BASE, MSerial##n); \ my_usart_irq(USART##n->rb, USART##n->wb, USART##n##_BASE, MSerial##n); \
} }
@ -84,29 +102,92 @@ static inline __always_inline void my_usart_irq(ring_buffer *rb, ring_buffer *wb
#define DEFINE_HWSERIAL_UART_MARLIN(name, n) \ #define DEFINE_HWSERIAL_UART_MARLIN(name, n) \
MarlinSerial name(UART##n, \ MarlinSerial name(UART##n, \
BOARD_USART##n##_TX_PIN, \ BOARD_USART##n##_TX_PIN, \
BOARD_USART##n##_RX_PIN); \ BOARD_USART##n##_RX_PIN, \
serial_handles_emergency(n)); \
extern "C" void __irq_usart##n(void) { \ extern "C" void __irq_usart##n(void) { \
my_usart_irq(USART##n->rb, USART##n->wb, USART##n##_BASE, MSerial##n); \ my_usart_irq(UART##n->rb, UART##n->wb, UART##n##_BASE, MSerial##n); \
} }
#if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1 || DGUS_SERIAL_PORT == 1 // Instantiate all UARTs even if they are not needed
DEFINE_HWSERIAL_MARLIN(MSerial1, 1); // This avoids a bunch of logic to figure out every serial
#endif // port which may be in use on the system.
DEFINE_HWSERIAL_MARLIN(MSerial1, 1);
#if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 || DGUS_SERIAL_PORT == 2 DEFINE_HWSERIAL_MARLIN(MSerial2, 2);
DEFINE_HWSERIAL_MARLIN(MSerial2, 2); DEFINE_HWSERIAL_MARLIN(MSerial3, 3);
#endif #if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY)
#if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 || DGUS_SERIAL_PORT == 3
DEFINE_HWSERIAL_MARLIN(MSerial3, 3);
#endif
#if SERIAL_PORT == 4 || SERIAL_PORT_2 == 4 || DGUS_SERIAL_PORT == 4
DEFINE_HWSERIAL_UART_MARLIN(MSerial4, 4); DEFINE_HWSERIAL_UART_MARLIN(MSerial4, 4);
#endif
#if SERIAL_PORT == 5 || SERIAL_PORT_2 == 5 || DGUS_SERIAL_PORT == 5
DEFINE_HWSERIAL_UART_MARLIN(MSerial5, 5); DEFINE_HWSERIAL_UART_MARLIN(MSerial5, 5);
#endif #endif
// Check the type of each serial port by passing it to a template function.
// HardwareSerial is known to sometimes hang the controller when an error occurs,
// so this case will fail the static assert. All other classes are assumed to be ok.
template <typename T>
constexpr bool IsSerialClassAllowed(const T&) { return true; }
constexpr bool IsSerialClassAllowed(const HardwareSerial&) { return false; }
#define CHECK_CFG_SERIAL(A) static_assert(IsSerialClassAllowed(A), STRINGIFY(A) " is defined incorrectly");
#define CHECK_AXIS_SERIAL(A) static_assert(IsSerialClassAllowed(A##_HARDWARE_SERIAL), STRINGIFY(A) "_HARDWARE_SERIAL must be defined in the form MSerial1, rather than Serial1");
// 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 LCD_SERIAL
CHECK_CFG_SERIAL(LCD_SERIAL);
#endif
#if AXIS_HAS_HW_SERIAL(X)
CHECK_AXIS_SERIAL(X);
#endif
#if AXIS_HAS_HW_SERIAL(X2)
CHECK_AXIS_SERIAL(X2);
#endif
#if AXIS_HAS_HW_SERIAL(Y)
CHECK_AXIS_SERIAL(Y);
#endif
#if AXIS_HAS_HW_SERIAL(Y2)
CHECK_AXIS_SERIAL(Y2);
#endif
#if AXIS_HAS_HW_SERIAL(Z)
CHECK_AXIS_SERIAL(Z);
#endif
#if AXIS_HAS_HW_SERIAL(Z2)
CHECK_AXIS_SERIAL(Z2);
#endif
#if AXIS_HAS_HW_SERIAL(Z3)
CHECK_AXIS_SERIAL(Z3);
#endif
#if AXIS_HAS_HW_SERIAL(Z4)
CHECK_AXIS_SERIAL(Z4);
#endif
#if AXIS_HAS_HW_SERIAL(E0)
CHECK_AXIS_SERIAL(E0);
#endif
#if AXIS_HAS_HW_SERIAL(E1)
CHECK_AXIS_SERIAL(E1);
#endif
#if AXIS_HAS_HW_SERIAL(E2)
CHECK_AXIS_SERIAL(E2);
#endif
#if AXIS_HAS_HW_SERIAL(E3)
CHECK_AXIS_SERIAL(E3);
#endif
#if AXIS_HAS_HW_SERIAL(E4)
CHECK_AXIS_SERIAL(E4);
#endif
#if AXIS_HAS_HW_SERIAL(E5)
CHECK_AXIS_SERIAL(E5);
#endif
#if AXIS_HAS_HW_SERIAL(E6)
CHECK_AXIS_SERIAL(E6);
#endif
#if AXIS_HAS_HW_SERIAL(E7)
CHECK_AXIS_SERIAL(E7);
#endif
#endif // __STM32F1__ #endif // __STM32F1__

View file

@ -35,15 +35,22 @@
class MarlinSerial : public HardwareSerial { class MarlinSerial : public HardwareSerial {
public: public:
MarlinSerial(struct usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin) : #if ENABLED(EMERGENCY_PARSER)
const bool ep_enabled;
EmergencyParser::State emergency_state;
inline bool emergency_parser_enabled() { return ep_enabled; }
#endif
MarlinSerial(struct usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin, bool TERN_(EMERGENCY_PARSER, ep_capable)) :
HardwareSerial(usart_device, tx_pin, rx_pin) HardwareSerial(usart_device, tx_pin, rx_pin)
#if ENABLED(EMERGENCY_PARSER) #if ENABLED(EMERGENCY_PARSER)
, ep_enabled(ep_capable)
, emergency_state(EmergencyParser::State::EP_RESET) , emergency_state(EmergencyParser::State::EP_RESET)
#endif #endif
{ } { }
#ifdef UART_IRQ_PRIO #ifdef UART_IRQ_PRIO
// shadow the parent methods to set irq priority after the begin // Shadow the parent methods to set IRQ priority after begin()
void begin(uint32 baud) { void begin(uint32 baud) {
MarlinSerial::begin(baud, SERIAL_8N1); MarlinSerial::begin(baud, SERIAL_8N1);
} }
@ -53,14 +60,12 @@ public:
nvic_irq_set_priority(c_dev()->irq_num, UART_IRQ_PRIO); nvic_irq_set_priority(c_dev()->irq_num, UART_IRQ_PRIO);
} }
#endif #endif
#if ENABLED(EMERGENCY_PARSER)
EmergencyParser::State emergency_state;
#endif
}; };
extern MarlinSerial MSerial1; extern MarlinSerial MSerial1;
extern MarlinSerial MSerial2; extern MarlinSerial MSerial2;
extern MarlinSerial MSerial3; extern MarlinSerial MSerial3;
extern MarlinSerial MSerial4; #if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY)
extern MarlinSerial MSerial5; extern MarlinSerial MSerial4;
extern MarlinSerial MSerial5;
#endif

View file

@ -32,6 +32,7 @@ public:
#if ENABLED(EMERGENCY_PARSER) #if ENABLED(EMERGENCY_PARSER)
EmergencyParser::State emergency_state; EmergencyParser::State emergency_state;
inline bool emergency_parser_enabled() { return true; }
#endif #endif
}; };

View file

@ -72,15 +72,15 @@
#endif #endif
#endif #endif
#ifdef DGUS_SERIAL_PORT #ifdef LCD_SERIAL_PORT
#if defined(STM32F4) && DGUS_SERIAL_PORT == 0 #if defined(STM32F4) && LCD_SERIAL_PORT == 0
#error "DGUS_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration." #error "LCD_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
#elif DGUS_SERIAL_PORT == -1 #elif LCD_SERIAL_PORT == -1
#define DGUS_SERIAL SerialUSB #define LCD_SERIAL SerialUSB
#elif WITHIN(DGUS_SERIAL_PORT, 0, 6) #elif WITHIN(LCD_SERIAL_PORT, 0, 6)
#define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#else #else
#error "DGUS_SERIAL_PORT must be from -1 to 6. Please update your configuration." #error "LCD_SERIAL_PORT must be from -1 to 6. Please update your configuration."
#endif #endif
#endif #endif

View file

@ -422,3 +422,37 @@
#if ANY(AUTO_BED_LEVELING_UBL, AUTO_BED_LEVELING_LINEAR, Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS) #if ANY(AUTO_BED_LEVELING_UBL, AUTO_BED_LEVELING_LINEAR, Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
#define NEED_LSF 1 #define NEED_LSF 1
#endif #endif
// Flag the indexed serial ports that are in use
#define ANY_SERIAL_IS(N) (defined(SERIAL_PORT) && SERIAL_PORT == (N)) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == (N)) || (defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT == (N))
#if ANY_SERIAL_IS(-1)
#define USING_SERIAL_DEFAULT
#endif
#if ANY_SERIAL_IS(0)
#define USING_SERIAL_0 1
#endif
#if ANY_SERIAL_IS(1)
#define USING_SERIAL_1 1
#endif
#if ANY_SERIAL_IS(2)
#define USING_SERIAL_2 1
#endif
#if ANY_SERIAL_IS(3)
#define USING_SERIAL_3 1
#endif
#if ANY_SERIAL_IS(4)
#define USING_SERIAL_4 1
#endif
#if ANY_SERIAL_IS(5)
#define USING_SERIAL_5 1
#endif
#if ANY_SERIAL_IS(6)
#define USING_SERIAL_6 1
#endif
#if ANY_SERIAL_IS(7)
#define USING_SERIAL_7 1
#endif
#if ANY_SERIAL_IS(8)
#define USING_SERIAL_8 1
#endif
#undef ANY_SERIAL_IS

View file

@ -477,6 +477,10 @@
#error "HOME_USING_SPREADCYCLE is now obsolete. Please remove it from Configuration_adv.h." #error "HOME_USING_SPREADCYCLE is now obsolete. Please remove it from Configuration_adv.h."
#elif defined(DGUS_LCD) #elif defined(DGUS_LCD)
#error "DGUS_LCD is now DGUS_LCD_UI_(ORIGIN|FYSETC|HIPRECY). Please update your configuration." #error "DGUS_LCD is now DGUS_LCD_UI_(ORIGIN|FYSETC|HIPRECY). Please update your configuration."
#elif defined(DGUS_SERIAL_PORT)
#error "DGUS_SERIAL_PORT is now LCD_SERIAL_PORT. Please update your configuration."
#elif defined(DGUS_BAUDRATE)
#error "DGUS_BAUDRATE is now LCD_BAUDRATE. Please update your configuration."
#elif defined(X_DUAL_ENDSTOPS_ADJUSTMENT) #elif defined(X_DUAL_ENDSTOPS_ADJUSTMENT)
#error "X_DUAL_ENDSTOPS_ADJUSTMENT is now X2_ENDSTOP_ADJUSTMENT. Please update Configuration_adv.h." #error "X_DUAL_ENDSTOPS_ADJUSTMENT is now X2_ENDSTOP_ADJUSTMENT. Please update Configuration_adv.h."
#elif defined(Y_DUAL_ENDSTOPS_ADJUSTMENT) #elif defined(Y_DUAL_ENDSTOPS_ADJUSTMENT)
@ -2281,31 +2285,20 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
/** /**
* Serial displays require a dedicated serial port * Serial displays require a dedicated serial port
*/ */
#if HAS_DGUS_LCD #ifdef LCD_SERIAL_PORT
#ifndef DGUS_SERIAL_PORT #if LCD_SERIAL_PORT == SERIAL_PORT
#error "The DGUS LCD requires DGUS_SERIAL_PORT to be defined in Configuration.h"
#elif DGUS_SERIAL_PORT == SERIAL_PORT
#error "DGUS_SERIAL_PORT cannot be the same as SERIAL_PORT. Please update your configuration."
#elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2
#error "DGUS_SERIAL_PORT cannot be the same as SERIAL_PORT_2. Please update your configuration."
#endif
#elif ENABLED(MALYAN_LCD)
#ifndef LCD_SERIAL_PORT
#error "MALYAN_LCD requires LCD_SERIAL_PORT to be defined in Configuration.h"
#elif LCD_SERIAL_PORT == SERIAL_PORT
#error "LCD_SERIAL_PORT cannot be the same as SERIAL_PORT. Please update your configuration." #error "LCD_SERIAL_PORT cannot be the same as SERIAL_PORT. Please update your configuration."
#elif defined(SERIAL_PORT_2) && LCD_SERIAL_PORT == SERIAL_PORT_2 #elif defined(SERIAL_PORT_2) && LCD_SERIAL_PORT == SERIAL_PORT_2
#error "LCD_SERIAL_PORT cannot be the same as SERIAL_PORT_2. Please update your configuration." #error "LCD_SERIAL_PORT cannot be the same as SERIAL_PORT_2. Please update your configuration."
#endif #endif
#elif EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON) #else
#ifndef ANYCUBIC_LCD_SERIAL_PORT #if HAS_DGUS_LCD
#error "The ANYCUBIC LCD requires ANYCUBIC_LCD_SERIAL_PORT to be defined in Configuration.h" #error "The DGUS LCD requires LCD_SERIAL_PORT to be defined in Configuration.h"
#elif ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT #elif EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON)
#error "ANYCUBIC_LCD_SERIAL_PORT cannot be the same as SERIAL_PORT. Please update your configuration." #error "The ANYCUBIC LCD requires LCD_SERIAL_PORT to be defined in Configuration.h"
#elif defined(SERIAL_PORT_2) && ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT_2 #elif ENABLED(MALYAN_LCD)
#error "ANYCUBIC_LCD_SERIAL_PORT cannot be the same as SERIAL_PORT_2. Please update your configuration." #error "MALYAN_LCD requires LCD_SERIAL_PORT to be defined in Configuration.h"
#endif #endif
#define ANYCUBIC_LCD_SERIAL anycubicLcdSerial
#endif #endif
/** /**

View file

@ -53,12 +53,12 @@ static bool is_printing_from_sd = false;
static bool is_out_of_filament = false; static bool is_out_of_filament = false;
static void sendNewLine(void) { static void sendNewLine(void) {
ANYCUBIC_LCD_SERIAL.write('\r'); LCD_SERIAL.write('\r');
ANYCUBIC_LCD_SERIAL.write('\n'); LCD_SERIAL.write('\n');
} }
static void send(const char *str) { static void send(const char *str) {
ANYCUBIC_LCD_SERIAL.print(str); LCD_SERIAL.print(str);
} }
static void sendLine(const char *str) { static void sendLine(const char *str) {
@ -68,7 +68,7 @@ static void sendLine(const char *str) {
static void send_P(PGM_P str) { static void send_P(PGM_P str) {
while (const char c = pgm_read_byte(str++)) while (const char c = pgm_read_byte(str++))
ANYCUBIC_LCD_SERIAL.write(c); LCD_SERIAL.write(c);
} }
static void sendLine_P(PGM_P str) { static void sendLine_P(PGM_P str) {
@ -78,23 +78,23 @@ static void sendLine_P(PGM_P str) {
static void sendValue_P(PGM_P prefix, int value) { static void sendValue_P(PGM_P prefix, int value) {
send_P(prefix); send_P(prefix);
ANYCUBIC_LCD_SERIAL.print(value); LCD_SERIAL.print(value);
} }
static void sendValue_P(PGM_P prefix, float value) { static void sendValue_P(PGM_P prefix, float value) {
send_P(prefix); send_P(prefix);
ANYCUBIC_LCD_SERIAL.print(value); LCD_SERIAL.print(value);
} }
static void sendValueLine_P(PGM_P prefix, int value) { static void sendValueLine_P(PGM_P prefix, int value) {
send_P(prefix); send_P(prefix);
ANYCUBIC_LCD_SERIAL.print(value); LCD_SERIAL.print(value);
sendNewLine(); sendNewLine();
} }
static void sendValueLine_P(PGM_P prefix, float value) { static void sendValueLine_P(PGM_P prefix, float value) {
send_P(prefix); send_P(prefix);
ANYCUBIC_LCD_SERIAL.print(value); LCD_SERIAL.print(value);
sendNewLine(); sendNewLine();
} }
@ -426,8 +426,8 @@ namespace ExtUI {
static char rxBuffer[RX_LEN_MAX+1]; static char rxBuffer[RX_LEN_MAX+1];
static uint8_t rxLen = 0; static uint8_t rxLen = 0;
while (ANYCUBIC_LCD_SERIAL.available()) { while (LCD_SERIAL.available()) {
const char c = ANYCUBIC_LCD_SERIAL.read(); const char c = LCD_SERIAL.read();
switch (c) { switch (c) {
case '\r': case '\n': case '\r': case '\n':
if (rxLen > 0 && rxLen <= RX_LEN_MAX) { if (rxLen > 0 && rxLen <= RX_LEN_MAX) {
@ -466,7 +466,10 @@ namespace ExtUI {
} }
void onStartup() { void onStartup() {
ANYCUBIC_LCD_SERIAL.begin(115200); #ifndef LCD_BAUDRATE
#define LCD_BAUDRATE 115200
#endif
LCD_SERIAL.begin(LCD_BAUDRATE);
sendNewLine(); sendNewLine();
SENDLINE_PGM("J17"); // Reset SENDLINE_PGM("J17"); // Reset
delay_ms(10); delay_ms(10);

View file

@ -59,12 +59,12 @@ char *itostr2(const uint8_t &x) {
} }
static void sendNewLine(void) { static void sendNewLine(void) {
ANYCUBIC_LCD_SERIAL.write('\r'); LCD_SERIAL.write('\r');
ANYCUBIC_LCD_SERIAL.write('\n'); LCD_SERIAL.write('\n');
} }
static void send(const char *str) { static void send(const char *str) {
ANYCUBIC_LCD_SERIAL.print(str); LCD_SERIAL.print(str);
} }
static void sendLine(const char *str) { static void sendLine(const char *str) {
@ -74,7 +74,7 @@ static void sendLine(const char *str) {
static void send_P(PGM_P str) { static void send_P(PGM_P str) {
while (const char c = pgm_read_byte(str++)) while (const char c = pgm_read_byte(str++))
ANYCUBIC_LCD_SERIAL.write(c); LCD_SERIAL.write(c);
} }
static void sendLine_P(PGM_P str) { static void sendLine_P(PGM_P str) {
@ -576,8 +576,8 @@ void AnycubicTFTClass::OnPrintTimerStopped() {
void AnycubicTFTClass::GetCommandFromTFT() { void AnycubicTFTClass::GetCommandFromTFT() {
char *starpos = NULL; char *starpos = NULL;
while (ANYCUBIC_LCD_SERIAL.available() > 0 && TFTbuflen < TFTBUFSIZE) { while (LCD_SERIAL.available() > 0 && TFTbuflen < TFTBUFSIZE) {
serial3_char = ANYCUBIC_LCD_SERIAL.read(); serial3_char = LCD_SERIAL.read();
if (serial3_char == '\n' || if (serial3_char == '\n' ||
serial3_char == '\r' || serial3_char == '\r' ||
serial3_char == ':' || serial3_char == ':' ||
@ -639,11 +639,11 @@ void AnycubicTFTClass::GetCommandFromTFT() {
float yPostition = ExtUI::getAxisPosition_mm(ExtUI::Y); float yPostition = ExtUI::getAxisPosition_mm(ExtUI::Y);
float zPostition = ExtUI::getAxisPosition_mm(ExtUI::Z); float zPostition = ExtUI::getAxisPosition_mm(ExtUI::Z);
SEND_PGM("A5V X: "); SEND_PGM("A5V X: ");
ANYCUBIC_LCD_SERIAL.print(xPostition); LCD_SERIAL.print(xPostition);
SEND_PGM(" Y: "); SEND_PGM(" Y: ");
ANYCUBIC_LCD_SERIAL.print(yPostition); LCD_SERIAL.print(yPostition);
SEND_PGM(" Z: "); SEND_PGM(" Z: ");
ANYCUBIC_LCD_SERIAL.print(zPostition); LCD_SERIAL.print(zPostition);
SENDLINE_PGM(""); SENDLINE_PGM("");
} }
break; break;

View file

@ -59,23 +59,13 @@ constexpr uint8_t DGUS_CMD_READVAR = 0x83;
bool dguslcd_local_debug; // = false; bool dguslcd_local_debug; // = false;
#endif #endif
#define dgusserial DGUS_SERIAL
void DGUSDisplay::InitDisplay() { void DGUSDisplay::InitDisplay() {
dgusserial.begin(DGUS_BAUDRATE); #ifndef LCD_BAUDRATE
#define LCD_BAUDRATE 115200
if (true
#if ENABLED(POWER_LOSS_RECOVERY)
&& !recovery.valid()
#endif #endif
) LCD_SERIAL.begin(LCD_BAUDRATE);
RequestScreen( if (TERN1(POWER_LOSS_RECOVERY, !recovery.valid()))
#if ENABLED(SHOW_BOOTSCREEN) RequestScreen(TERN(SHOW_BOOTSCREEN, DGUSLCD_SCREEN_BOOT, DGUSLCD_SCREEN_MAIN));
DGUSLCD_SCREEN_BOOT
#else
DGUSLCD_SCREEN_MAIN
#endif
);
} }
void DGUSDisplay::WriteVariable(uint16_t adr, const void* values, uint8_t valueslen, bool isstr) { void DGUSDisplay::WriteVariable(uint16_t adr, const void* values, uint8_t valueslen, bool isstr) {
@ -89,7 +79,7 @@ void DGUSDisplay::WriteVariable(uint16_t adr, const void* values, uint8_t values
strend = true; strend = true;
x = ' '; x = ' ';
} }
dgusserial.write(x); LCD_SERIAL.write(x);
} }
} }
@ -133,41 +123,41 @@ void DGUSDisplay::WriteVariablePGM(uint16_t adr, const void* values, uint8_t val
strend = true; strend = true;
x = ' '; x = ' ';
} }
dgusserial.write(x); LCD_SERIAL.write(x);
} }
} }
void DGUSDisplay::ProcessRx() { void DGUSDisplay::ProcessRx() {
#if ENABLED(DGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS) #if ENABLED(DGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS)
if (!dgusserial.available() && dgusserial.buffer_overruns()) { if (!LCD_SERIAL.available() && LCD_SERIAL.buffer_overruns()) {
// Overrun, but reset the flag only when the buffer is empty // Overrun, but reset the flag only when the buffer is empty
// We want to extract as many as valid datagrams possible... // We want to extract as many as valid datagrams possible...
DEBUG_ECHOPGM("OVFL"); DEBUG_ECHOPGM("OVFL");
rx_datagram_state = DGUS_IDLE; rx_datagram_state = DGUS_IDLE;
//dgusserial.reset_rx_overun(); //LCD_SERIAL.reset_rx_overun();
dgusserial.flush(); LCD_SERIAL.flush();
} }
#endif #endif
uint8_t receivedbyte; uint8_t receivedbyte;
while (dgusserial.available()) { while (LCD_SERIAL.available()) {
switch (rx_datagram_state) { switch (rx_datagram_state) {
case DGUS_IDLE: // Waiting for the first header byte case DGUS_IDLE: // Waiting for the first header byte
receivedbyte = dgusserial.read(); receivedbyte = LCD_SERIAL.read();
//DEBUG_ECHOPAIR("< ",x); //DEBUG_ECHOPAIR("< ",x);
if (DGUS_HEADER1 == receivedbyte) rx_datagram_state = DGUS_HEADER1_SEEN; if (DGUS_HEADER1 == receivedbyte) rx_datagram_state = DGUS_HEADER1_SEEN;
break; break;
case DGUS_HEADER1_SEEN: // Waiting for the second header byte case DGUS_HEADER1_SEEN: // Waiting for the second header byte
receivedbyte = dgusserial.read(); receivedbyte = LCD_SERIAL.read();
//DEBUG_ECHOPAIR(" ",x); //DEBUG_ECHOPAIR(" ",x);
rx_datagram_state = (DGUS_HEADER2 == receivedbyte) ? DGUS_HEADER2_SEEN : DGUS_IDLE; rx_datagram_state = (DGUS_HEADER2 == receivedbyte) ? DGUS_HEADER2_SEEN : DGUS_IDLE;
break; break;
case DGUS_HEADER2_SEEN: // Waiting for the length byte case DGUS_HEADER2_SEEN: // Waiting for the length byte
rx_datagram_len = dgusserial.read(); rx_datagram_len = LCD_SERIAL.read();
DEBUG_ECHOPAIR(" (", rx_datagram_len, ") "); DEBUG_ECHOPAIR(" (", rx_datagram_len, ") ");
// Telegram min len is 3 (command and one word of payload) // Telegram min len is 3 (command and one word of payload)
@ -175,10 +165,10 @@ void DGUSDisplay::ProcessRx() {
break; break;
case DGUS_WAIT_TELEGRAM: // wait for complete datagram to arrive. case DGUS_WAIT_TELEGRAM: // wait for complete datagram to arrive.
if (dgusserial.available() < rx_datagram_len) return; if (LCD_SERIAL.available() < rx_datagram_len) return;
Initialized = true; // We've talked to it, so we defined it as initialized. Initialized = true; // We've talked to it, so we defined it as initialized.
uint8_t command = dgusserial.read(); uint8_t command = LCD_SERIAL.read();
DEBUG_ECHOPAIR("# ", command); DEBUG_ECHOPAIR("# ", command);
@ -186,7 +176,7 @@ void DGUSDisplay::ProcessRx() {
unsigned char tmp[rx_datagram_len - 1]; unsigned char tmp[rx_datagram_len - 1];
unsigned char *ptmp = tmp; unsigned char *ptmp = tmp;
while (readlen--) { while (readlen--) {
receivedbyte = dgusserial.read(); receivedbyte = LCD_SERIAL.read();
DEBUG_ECHOPAIR(" ", receivedbyte); DEBUG_ECHOPAIR(" ", receivedbyte);
*ptmp++ = receivedbyte; *ptmp++ = receivedbyte;
} }
@ -229,19 +219,19 @@ void DGUSDisplay::ProcessRx() {
} }
} }
size_t DGUSDisplay::GetFreeTxBuffer() { return DGUS_SERIAL_GET_TX_BUFFER_FREE(); } size_t DGUSDisplay::GetFreeTxBuffer() { return SERIAL_GET_TX_BUFFER_FREE(); }
void DGUSDisplay::WriteHeader(uint16_t adr, uint8_t cmd, uint8_t payloadlen) { void DGUSDisplay::WriteHeader(uint16_t adr, uint8_t cmd, uint8_t payloadlen) {
dgusserial.write(DGUS_HEADER1); LCD_SERIAL.write(DGUS_HEADER1);
dgusserial.write(DGUS_HEADER2); LCD_SERIAL.write(DGUS_HEADER2);
dgusserial.write(payloadlen + 3); LCD_SERIAL.write(payloadlen + 3);
dgusserial.write(cmd); LCD_SERIAL.write(cmd);
dgusserial.write(adr >> 8); LCD_SERIAL.write(adr >> 8);
dgusserial.write(adr & 0xFF); LCD_SERIAL.write(adr & 0xFF);
} }
void DGUSDisplay::WritePGM(const char str[], uint8_t len) { void DGUSDisplay::WritePGM(const char str[], uint8_t len) {
while (len--) dgusserial.write(pgm_read_byte(str++)); while (len--) LCD_SERIAL.write(pgm_read_byte(str++));
} }
void DGUSDisplay::loop() { void DGUSDisplay::loop() {

View file

@ -7,6 +7,7 @@
set -e set -e
use_example_configs Mks/Robin_Pro use_example_configs Mks/Robin_Pro
opt_enable EMERGENCY_PARSER
opt_set SDCARD_CONNECTION LCD opt_set SDCARD_CONNECTION LCD
opt_set X_DRIVER_TYPE TMC2209 opt_set X_DRIVER_TYPE TMC2209
opt_set Y_DRIVER_TYPE TMC2130 opt_set Y_DRIVER_TYPE TMC2130