Browse Source

Fix and improve STM32F1 serial (#19464)

vanilla_fb_2.0.x
Jason Smith 4 years ago
committed by GitHub
parent
commit
da6c8317a7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      Marlin/Configuration.h
  2. 10
      Marlin/Configuration_adv.h
  3. 17
      Marlin/src/HAL/AVR/HAL.h
  4. 1228
      Marlin/src/HAL/AVR/MarlinSerial.cpp
  5. 67
      Marlin/src/HAL/AVR/MarlinSerial.h
  6. 12
      Marlin/src/HAL/DUE/HAL.h
  7. 2
      Marlin/src/HAL/DUE/MarlinSerial.h
  8. 1
      Marlin/src/HAL/LINUX/include/serial.h
  9. 12
      Marlin/src/HAL/LPC1768/HAL.h
  10. 8
      Marlin/src/HAL/LPC1768/MarlinSerial.cpp
  11. 1
      Marlin/src/HAL/LPC1768/MarlinSerial.h
  12. 8
      Marlin/src/HAL/LPC1768/inc/SanityCheck.h
  13. 2
      Marlin/src/HAL/LPC1768/usb_serial.cpp
  14. 12
      Marlin/src/HAL/SAMD51/HAL.h
  15. 16
      Marlin/src/HAL/STM32/HAL.h
  16. 4
      Marlin/src/HAL/STM32/MarlinSerial.cpp
  17. 4
      Marlin/src/HAL/STM32/MarlinSerial.h
  18. 80
      Marlin/src/HAL/STM32F1/HAL.h
  19. 127
      Marlin/src/HAL/STM32F1/MarlinSerial.cpp
  20. 21
      Marlin/src/HAL/STM32F1/MarlinSerial.h
  21. 1
      Marlin/src/HAL/STM32F1/msc_sd.h
  22. 16
      Marlin/src/HAL/STM32_F4_F7/HAL.h
  23. 34
      Marlin/src/inc/Conditionals_adv.h
  24. 33
      Marlin/src/inc/SanityCheck.h
  25. 25
      Marlin/src/lcd/extui/anycubic_chiron_lcd.cpp
  26. 18
      Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp
  27. 62
      Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp
  28. 1
      buildroot/tests/mks_robin_pro-tests

5
Marlin/Configuration.h

@ -2165,6 +2165,9 @@
// Touch-screen LCD for Malyan M200/M300 printers
//
//#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
@ -2178,7 +2181,7 @@
//#define ANYCUBIC_LCD_I3MEGA
//#define 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
#endif

10
Marlin/Configuration_adv.h

@ -1404,8 +1404,8 @@
// Additional options for DGUS / DWIN displays
//
#if HAS_DGUS_LCD
#define DGUS_SERIAL_PORT 3
#define DGUS_BAUDRATE 115200
#define LCD_SERIAL_PORT 3
#define LCD_BAUDRATE 115200
#define DGUS_RX_BUFFER_SIZE 128
#define DGUS_TX_BUFFER_SIZE 48
@ -3419,10 +3419,10 @@
#if ENABLED(PRUSA_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)
#define INTERNAL_SERIAL_PORT 2
#define MMU2_SERIAL internalSerial
#define MMU2_SERIAL_PORT 2
#define MMU2_SERIAL mmuSerial
// Use hardware reset for MMU if a pin is defined for it
//#define MMU2_RST_PIN 23

17
Marlin/src/HAL/AVR/HAL.h

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

1228
Marlin/src/HAL/AVR/MarlinSerial.cpp

File diff suppressed because it is too large

67
Marlin/src/HAL/AVR/MarlinSerial.h

@ -217,10 +217,12 @@
static ring_buffer_pos_t available();
static void write(const uint8_t c);
static void flushTX();
#ifdef DGUS_SERIAL_PORT
#if HAS_DGUS_LCD
static ring_buffer_pos_t get_tx_buffer_free();
#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 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; }
@ -278,55 +280,50 @@
#endif // !USBCON
#ifdef INTERNAL_SERIAL_PORT
#ifdef MMU2_SERIAL_PORT
template <uint8_t serial>
struct MarlinInternalSerialCfg {
struct MMU2SerialCfg {
static constexpr int PORT = serial;
static constexpr unsigned int RX_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_FRAMING_ERRORS = false;
static constexpr bool MAX_RX_QUEUED = false;
static constexpr unsigned int RX_SIZE = 32;
static constexpr unsigned int TX_SIZE = 32;
static constexpr bool RX_OVERRUNS = false;
};
extern MarlinSerial<MarlinInternalSerialCfg<INTERNAL_SERIAL_PORT>> internalSerial;
extern MarlinSerial<MMU2SerialCfg<MMU2_SERIAL_PORT>> mmuSerial;
#endif
#ifdef DGUS_SERIAL_PORT
template <uint8_t serial>
struct MarlinInternalSerialCfg {
static constexpr int PORT = serial;
static constexpr unsigned int RX_SIZE = DGUS_RX_BUFFER_SIZE;
static constexpr unsigned int TX_SIZE = DGUS_TX_BUFFER_SIZE;
static constexpr bool XONOFF = false;
static constexpr bool EMERGENCYPARSER = false;
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 LCD_SERIAL_PORT
#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 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_FRAMING_ERRORS = false;
static constexpr bool MAX_RX_QUEUED = false;
struct LCDSerialCfg {
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 TX_SIZE = DGUS_TX_BUFFER_SIZE;
static constexpr bool RX_OVERRUNS = ENABLED(DGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS);
#elif EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON)
static constexpr unsigned int RX_SIZE = 64;
static constexpr unsigned int TX_SIZE = 128;
static constexpr bool RX_OVERRUNS = false;
#else
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
// Use the UART for Bluetooth in AT90USB configurations

12
Marlin/src/HAL/DUE/HAL.h

@ -61,13 +61,13 @@
#endif
#endif
#ifdef DGUS_SERIAL_PORT
#if DGUS_SERIAL_PORT == -1
#define DGUS_SERIAL internalDgusSerial
#elif WITHIN(DGUS_SERIAL_PORT, 0, 3)
#define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT)
#ifdef LCD_SERIAL_PORT
#if LCD_SERIAL_PORT == -1
#define LCD_SERIAL lcdSerial
#elif WITHIN(LCD_SERIAL_PORT, 0, 3)
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#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

2
Marlin/src/HAL/DUE/MarlinSerial.h

@ -122,6 +122,8 @@ public:
static void write(const uint8_t c);
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 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; }

1
Marlin/src/HAL/LINUX/include/serial.h

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

12
Marlin/src/HAL/LPC1768/HAL.h

@ -85,13 +85,13 @@ extern "C" volatile uint32_t _millis;
#endif
#endif
#ifdef DGUS_SERIAL_PORT
#if DGUS_SERIAL_PORT == -1
#define DGUS_SERIAL UsbSerial
#elif WITHIN(DGUS_SERIAL_PORT, 0, 3)
#define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT)
#ifdef LCD_SERIAL_PORT
#if LCD_SERIAL_PORT == -1
#define LCD_SERIAL UsbSerial
#elif WITHIN(LCD_SERIAL_PORT, 0, 3)
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#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

8
Marlin/src/HAL/LPC1768/MarlinSerial.cpp

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

1
Marlin/src/HAL/LPC1768/MarlinSerial.h

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

8
Marlin/src/HAL/LPC1768/inc/SanityCheck.h

@ -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_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_RX0(P) (P == P0_03)
#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
#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_RX1(P) (P == P0_16)
#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
#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_RX2(P) (P == P0_11)
#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
#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_RX3(P) (P##_PIN == P0_01)
#if PIN_IS_TX3(X_MIN) || PIN_IS_RX3(X_MAX)

2
Marlin/src/HAL/LPC1768/usb_serial.cpp

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

12
Marlin/src/HAL/SAMD51/HAL.h

@ -56,13 +56,13 @@
#endif
#endif
#ifdef DGUS_SERIAL_PORT
#if DGUS_SERIAL_PORT == -1
#define DGUS_SERIAL Serial
#elif WITHIN(DGUS_SERIAL_PORT, 0, 3)
#define MYSERIAL0 MSERIAL(DGUS_SERIAL_PORT)
#ifdef LCD_SERIAL_PORT
#if LCD_SERIAL_PORT == -1
#define LCD_SERIAL Serial
#elif WITHIN(LCD_SERIAL_PORT, 0, 3)
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#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

16
Marlin/src/HAL/STM32/HAL.h

@ -64,18 +64,7 @@
#endif
#endif
#if HAS_DGUS_LCD
#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)
#ifdef LCD_SERIAL_PORT
#if LCD_SERIAL_PORT == -1
#define LCD_SERIAL SerialUSB
#elif WITHIN(LCD_SERIAL_PORT, 1, 6)
@ -83,6 +72,9 @@
#else
#error "LCD_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
#endif
#if HAS_DGUS_LCD
#define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite()
#endif
#endif
/**

4
Marlin/src/HAL/STM32/MarlinSerial.cpp

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

4
Marlin/src/HAL/STM32/MarlinSerial.h

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

80
Marlin/src/HAL/STM32F1/HAL.h

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

127
Marlin/src/HAL/STM32F1/MarlinSerial.cpp

@ -22,7 +22,7 @@
#ifdef __STM32F1__
#include "../../inc/MarlinConfigPre.h"
#include "../../inc/MarlinConfig.h"
#include "MarlinSerial.h"
#include <libmaple/usart.h>
@ -53,7 +53,8 @@ static inline __always_inline void my_usart_irq(ring_buffer *rb, ring_buffer *wb
rb_push_insert(rb, c);
#endif
#if ENABLED(EMERGENCY_PARSER)
emergency_parser.update(serial.emergency_state, c);
if (serial.emergency_parser_enabled())
emergency_parser.update(serial.emergency_state, c);
#endif
}
}
@ -73,40 +74,120 @@ static inline __always_inline void my_usart_irq(ring_buffer *rb, ring_buffer *wb
}
}
#define DEFINE_HWSERIAL_MARLIN(name, n) \
MarlinSerial name(USART##n, \
BOARD_USART##n##_TX_PIN, \
BOARD_USART##n##_RX_PIN); \
extern "C" void __irq_usart##n(void) { \
// 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) \
MarlinSerial name(USART##n, \
BOARD_USART##n##_TX_PIN, \
BOARD_USART##n##_RX_PIN, \
serial_handles_emergency(n)); \
extern "C" void __irq_usart##n(void) { \
my_usart_irq(USART##n->rb, USART##n->wb, USART##n##_BASE, MSerial##n); \
}
#define DEFINE_HWSERIAL_UART_MARLIN(name, n) \
MarlinSerial name(UART##n, \
BOARD_USART##n##_TX_PIN, \
BOARD_USART##n##_RX_PIN); \
BOARD_USART##n##_TX_PIN, \
BOARD_USART##n##_RX_PIN, \
serial_handles_emergency(n)); \
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
DEFINE_HWSERIAL_MARLIN(MSerial1, 1);
// Instantiate all UARTs even if they are not needed
// This avoids a bunch of logic to figure out every serial
// port which may be in use on the system.
DEFINE_HWSERIAL_MARLIN(MSerial1, 1);
DEFINE_HWSERIAL_MARLIN(MSerial2, 2);
DEFINE_HWSERIAL_MARLIN(MSerial3, 3);
#if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY)
DEFINE_HWSERIAL_UART_MARLIN(MSerial4, 4);
DEFINE_HWSERIAL_UART_MARLIN(MSerial5, 5);
#endif
#if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 || DGUS_SERIAL_PORT == 2
DEFINE_HWSERIAL_MARLIN(MSerial2, 2);
#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; }
#if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 || DGUS_SERIAL_PORT == 3
DEFINE_HWSERIAL_MARLIN(MSerial3, 3);
#endif
#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 SERIAL_PORT == 4 || SERIAL_PORT_2 == 4 || DGUS_SERIAL_PORT == 4
DEFINE_HWSERIAL_UART_MARLIN(MSerial4, 4);
#endif
// If you encounter this error, replace SerialX with MSerialX, for example MSerial3.
#if SERIAL_PORT == 5 || SERIAL_PORT_2 == 5 || DGUS_SERIAL_PORT == 5
DEFINE_HWSERIAL_UART_MARLIN(MSerial5, 5);
// 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__

21
Marlin/src/HAL/STM32F1/MarlinSerial.h

@ -35,15 +35,22 @@
class MarlinSerial : public HardwareSerial {
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)
#if ENABLED(EMERGENCY_PARSER)
, ep_enabled(ep_capable)
, emergency_state(EmergencyParser::State::EP_RESET)
#endif
{ }
#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) {
MarlinSerial::begin(baud, SERIAL_8N1);
}
@ -53,14 +60,12 @@ public:
nvic_irq_set_priority(c_dev()->irq_num, UART_IRQ_PRIO);
}
#endif
#if ENABLED(EMERGENCY_PARSER)
EmergencyParser::State emergency_state;
#endif
};
extern MarlinSerial MSerial1;
extern MarlinSerial MSerial2;
extern MarlinSerial MSerial3;
extern MarlinSerial MSerial4;
extern MarlinSerial MSerial5;
#if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY)
extern MarlinSerial MSerial4;
extern MarlinSerial MSerial5;
#endif

1
Marlin/src/HAL/STM32F1/msc_sd.h

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

16
Marlin/src/HAL/STM32_F4_F7/HAL.h

@ -72,15 +72,15 @@
#endif
#endif
#ifdef DGUS_SERIAL_PORT
#if defined(STM32F4) && DGUS_SERIAL_PORT == 0
#error "DGUS_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
#elif DGUS_SERIAL_PORT == -1
#define DGUS_SERIAL SerialUSB
#elif WITHIN(DGUS_SERIAL_PORT, 0, 6)
#define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT)
#ifdef LCD_SERIAL_PORT
#if defined(STM32F4) && LCD_SERIAL_PORT == 0
#error "LCD_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
#elif LCD_SERIAL_PORT == -1
#define LCD_SERIAL SerialUSB
#elif WITHIN(LCD_SERIAL_PORT, 0, 6)
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
#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

34
Marlin/src/inc/Conditionals_adv.h

@ -422,3 +422,37 @@
#if ANY(AUTO_BED_LEVELING_UBL, AUTO_BED_LEVELING_LINEAR, Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
#define NEED_LSF 1
#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

33
Marlin/src/inc/SanityCheck.h

@ -477,6 +477,10 @@
#error "HOME_USING_SPREADCYCLE is now obsolete. Please remove it from Configuration_adv.h."
#elif defined(DGUS_LCD)
#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)
#error "X_DUAL_ENDSTOPS_ADJUSTMENT is now X2_ENDSTOP_ADJUSTMENT. Please update Configuration_adv.h."
#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
*/
#if HAS_DGUS_LCD
#ifndef DGUS_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
#ifdef LCD_SERIAL_PORT
#if LCD_SERIAL_PORT == SERIAL_PORT
#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
#error "LCD_SERIAL_PORT cannot be the same as SERIAL_PORT_2. Please update your configuration."
#endif
#elif EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON)
#ifndef ANYCUBIC_LCD_SERIAL_PORT
#error "The ANYCUBIC LCD requires ANYCUBIC_LCD_SERIAL_PORT to be defined in Configuration.h"
#elif ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT
#error "ANYCUBIC_LCD_SERIAL_PORT cannot be the same as SERIAL_PORT. Please update your configuration."
#elif defined(SERIAL_PORT_2) && ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT_2
#error "ANYCUBIC_LCD_SERIAL_PORT cannot be the same as SERIAL_PORT_2. Please update your configuration."
#else
#if HAS_DGUS_LCD
#error "The DGUS LCD requires LCD_SERIAL_PORT to be defined in Configuration.h"
#elif EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON)
#error "The ANYCUBIC LCD requires LCD_SERIAL_PORT to be defined in Configuration.h"
#elif ENABLED(MALYAN_LCD)
#error "MALYAN_LCD requires LCD_SERIAL_PORT to be defined in Configuration.h"
#endif
#define ANYCUBIC_LCD_SERIAL anycubicLcdSerial
#endif
/**

25
Marlin/src/lcd/extui/anycubic_chiron_lcd.cpp

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

18
Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp

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

62
Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp

@ -59,23 +59,13 @@ constexpr uint8_t DGUS_CMD_READVAR = 0x83;
bool dguslcd_local_debug; // = false;
#endif
#define dgusserial DGUS_SERIAL
void DGUSDisplay::InitDisplay() {
dgusserial.begin(DGUS_BAUDRATE);
if (true
#if ENABLED(POWER_LOSS_RECOVERY)
&& !recovery.valid()
#endif
)
RequestScreen(
#if ENABLED(SHOW_BOOTSCREEN)
DGUSLCD_SCREEN_BOOT
#else
DGUSLCD_SCREEN_MAIN
#endif
);
#ifndef LCD_BAUDRATE
#define LCD_BAUDRATE 115200
#endif
LCD_SERIAL.begin(LCD_BAUDRATE);
if (TERN1(POWER_LOSS_RECOVERY, !recovery.valid()))
RequestScreen(TERN(SHOW_BOOTSCREEN, DGUSLCD_SCREEN_BOOT, DGUSLCD_SCREEN_MAIN));
}
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;
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;
x = ' ';
}
dgusserial.write(x);
LCD_SERIAL.write(x);
}
}
void DGUSDisplay::ProcessRx() {
#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
// We want to extract as many as valid datagrams possible...
DEBUG_ECHOPGM("OVFL");
rx_datagram_state = DGUS_IDLE;
//dgusserial.reset_rx_overun();
dgusserial.flush();
//LCD_SERIAL.reset_rx_overun();
LCD_SERIAL.flush();
}
#endif
uint8_t receivedbyte;
while (dgusserial.available()) {
while (LCD_SERIAL.available()) {
switch (rx_datagram_state) {
case DGUS_IDLE: // Waiting for the first header byte
receivedbyte = dgusserial.read();
receivedbyte = LCD_SERIAL.read();
//DEBUG_ECHOPAIR("< ",x);
if (DGUS_HEADER1 == receivedbyte) rx_datagram_state = DGUS_HEADER1_SEEN;
break;
case DGUS_HEADER1_SEEN: // Waiting for the second header byte
receivedbyte = dgusserial.read();
receivedbyte = LCD_SERIAL.read();
//DEBUG_ECHOPAIR(" ",x);
rx_datagram_state = (DGUS_HEADER2 == receivedbyte) ? DGUS_HEADER2_SEEN : DGUS_IDLE;
break;
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, ") ");
// Telegram min len is 3 (command and one word of payload)
@ -175,10 +165,10 @@ void DGUSDisplay::ProcessRx() {
break;
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.
uint8_t command = dgusserial.read();
uint8_t command = LCD_SERIAL.read();
DEBUG_ECHOPAIR("# ", command);
@ -186,7 +176,7 @@ void DGUSDisplay::ProcessRx() {
unsigned char tmp[rx_datagram_len - 1];
unsigned char *ptmp = tmp;
while (readlen--) {
receivedbyte = dgusserial.read();
receivedbyte = LCD_SERIAL.read();
DEBUG_ECHOPAIR(" ", 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) {
dgusserial.write(DGUS_HEADER1);
dgusserial.write(DGUS_HEADER2);
dgusserial.write(payloadlen + 3);
dgusserial.write(cmd);
dgusserial.write(adr >> 8);
dgusserial.write(adr & 0xFF);
LCD_SERIAL.write(DGUS_HEADER1);
LCD_SERIAL.write(DGUS_HEADER2);
LCD_SERIAL.write(payloadlen + 3);
LCD_SERIAL.write(cmd);
LCD_SERIAL.write(adr >> 8);
LCD_SERIAL.write(adr & 0xFF);
}
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() {

1
buildroot/tests/mks_robin_pro-tests

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

Loading…
Cancel
Save