From 3e3e187f34d6780af40d0b4e6e2743a7ccbeb7ea Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Sun, 20 Sep 2020 21:27:06 -0700 Subject: [PATCH 01/33] Update Malyan LCD to use MSerial on STM32F1, and try to prevent use of non-MSerial ports. --- Marlin/src/HAL/STM32F1/HAL.h | 84 ++++++------ Marlin/src/HAL/STM32F1/MarlinSerial.cpp | 129 +++++++++++++++--- Marlin/src/HAL/STM32F1/MarlinSerial.h | 19 ++- Marlin/src/lcd/extui/malyan_lcd.cpp | 14 +- Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h | 10 +- .../pins/stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h | 8 +- .../pins/stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h | 8 +- Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h | 8 +- Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h | 16 +-- .../pins/stm32f1/pins_MKS_ROBIN_E3_common.h | 8 +- .../src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h | 16 +-- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h | 17 +-- 12 files changed, 208 insertions(+), 129 deletions(-) diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h index f76d8c54a0e3..803fa0c4ef53 100644 --- a/Marlin/src/HAL/STM32F1/HAL.h +++ b/Marlin/src/HAL/STM32F1/HAL.h @@ -68,43 +68,36 @@ #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 defined(STM32_HIGH_DENSITY) || defined(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 defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) + #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 + #if 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 - #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 defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) + #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 #define NUM_SERIAL 2 #else @@ -112,29 +105,36 @@ #endif #ifdef DGUS_SERIAL - #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 + #if 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 + #elif WITHIN(DGUS_SERIAL_PORT, 1, NUM_UARTS) + #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) + #elif defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) + #error "DGUS_SERIAL 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 "DGUS_SERIAL must be -1 or from 1 to 3. Please update your configuration." #endif #endif +#ifdef MALYAN_LCD + #if MALYAN_LCD_SERIAL_PORT == SERIAL_PORT + #error "MALYAN_LCD_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration." + #elif defined(SERIAL_PORT_2) && MALYAN_LCD_SERIAL_PORT == SERIAL_PORT_2 + #error "MALYAN_LCD_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." + #elif defined(DGUS_SERIAL) && MALYAN_LCD_SERIAL_PORT == DGUS_SERIAL_PORT + #error "MALYAN_LCD_SERIAL_PORT must be different than DGUS_SERIAL_PORT. Please update your configuration." + #elif WITHIN(MALYAN_LCD_SERIAL_PORT, 1, NUM_UARTS) + #define MALYAN_LCD_SERIAL MSERIAL(MALYAN_LCD_SERIAL_PORT) + #elif defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) + #error "MALYAN_LCD_SERIAL_PORT must be from 1 to 5. Please update your configuration." + #else + #error "MALYAN_LCD_SERIAL_PORT must be from 1 to 3. Please update your configuration." + #endif +#endif // Set interrupt grouping for this MCU void HAL_init(); diff --git a/Marlin/src/HAL/STM32F1/MarlinSerial.cpp b/Marlin/src/HAL/STM32F1/MarlinSerial.cpp index 9a48e901f42d..c57fff81b656 100644 --- a/Marlin/src/HAL/STM32F1/MarlinSerial.cpp +++ b/Marlin/src/HAL/STM32F1/MarlinSerial.cpp @@ -22,7 +22,7 @@ #ifdef __STM32F1__ -#include "../../inc/MarlinConfigPre.h" +#include "../../inc/MarlinConfig.h" #include "MarlinSerial.h" #include @@ -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,124 @@ 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 DGUS_SERIAL_PORT + || (DGUS_SERIAL_PORT) == port + #endif + ; +} + #define DEFINE_HWSERIAL_MARLIN(name, n) \ MarlinSerial name(USART##n, \ 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) { \ 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); \ - extern "C" void __irq_usart##n(void) { \ - my_usart_irq(USART##n->rb, USART##n->wb, USART##n##_BASE, MSerial##n); \ - } +MarlinSerial name(UART##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(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 defined(STM32_HIGH_DENSITY) || defined(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 +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 DGUS_SERIAL + CHECK_CFG_SERIAL(DGUS_SERIAL); +#endif +#ifdef MALYAN_LCD_SERIAL + CHECK_CFG_SERIAL(MALYAN_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__ diff --git a/Marlin/src/HAL/STM32F1/MarlinSerial.h b/Marlin/src/HAL/STM32F1/MarlinSerial.h index eb0059bfbcae..c99f5078cf79 100644 --- a/Marlin/src/HAL/STM32F1/MarlinSerial.h +++ b/Marlin/src/HAL/STM32F1/MarlinSerial.h @@ -30,16 +30,22 @@ #include "../../feature/e_parser.h" #endif +// Increase priority of serial interrupts, to reduce overflow errors #define UART_IRQ_PRIO 1 class MarlinSerial : public HardwareSerial { public: - MarlinSerial(struct usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin) : + MarlinSerial(struct usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin, bool emergency_parser) : HardwareSerial(usart_device, tx_pin, rx_pin) #if ENABLED(EMERGENCY_PARSER) - , emergency_state(EmergencyParser::State::EP_RESET) + , emergency_parser_enabled(emergency_parser), + emergency_state(EmergencyParser::State::EP_RESET) #endif - { } + { + #if DISABLED(EMERGENCY_PARSER) + UNUSED(emergency_parser); + #endif + } #ifdef UART_IRQ_PRIO // shadow the parent methods to set irq priority after the begin @@ -54,6 +60,7 @@ class MarlinSerial : public HardwareSerial { #endif #if ENABLED(EMERGENCY_PARSER) + bool emergency_parser_enabled; EmergencyParser::State emergency_state; #endif }; @@ -61,5 +68,7 @@ class MarlinSerial : public HardwareSerial { extern MarlinSerial MSerial1; extern MarlinSerial MSerial2; extern MarlinSerial MSerial3; -extern MarlinSerial MSerial4; -extern MarlinSerial MSerial5; +#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) + extern MarlinSerial MSerial4; + extern MarlinSerial MSerial5; +#endif diff --git a/Marlin/src/lcd/extui/malyan_lcd.cpp b/Marlin/src/lcd/extui/malyan_lcd.cpp index b5148065c7cc..7c4e8c05eec0 100644 --- a/Marlin/src/lcd/extui/malyan_lcd.cpp +++ b/Marlin/src/lcd/extui/malyan_lcd.cpp @@ -63,7 +63,9 @@ // On the Malyan M200, this will be Serial1. On a RAMPS board, // it might not be. -#define LCD_SERIAL Serial1 +#ifndef MALYAN_LCD_SERIAL + #error "Must define MALYAN_LCD_SERIAL to use MALYAN_LCD" +#endif // This is based on longest sys command + a filename, plus some buffer // in case we encounter some data we don't recognize @@ -84,7 +86,7 @@ void write_to_lcd_P(PGM_P const message) { LOOP_L_N(i, message_length) encoded_message[i] = pgm_read_byte(&message[i]) | 0x80; - LCD_SERIAL.Print::write(encoded_message, message_length); + MALYAN_LCD_SERIAL.Print::write(encoded_message, message_length); } void write_to_lcd(const char * const message) { @@ -94,7 +96,7 @@ void write_to_lcd(const char * const message) { LOOP_L_N(i, message_length) encoded_message[i] = message[i] | 0x80; - LCD_SERIAL.Print::write(encoded_message, message_length); + MALYAN_LCD_SERIAL.Print::write(encoded_message, message_length); } // {E:} is for error states. @@ -432,7 +434,7 @@ namespace ExtUI { * it and translate into ExtUI operations where possible. */ inbound_count = 0; - LCD_SERIAL.begin(500000); + MALYAN_LCD_SERIAL.begin(500000); // Signal init write_to_lcd_P(PSTR("{SYS:STARTED}\r\n")); @@ -455,8 +457,8 @@ namespace ExtUI { update_usb_status(false); // now drain commands... - while (LCD_SERIAL.available()) - parse_lcd_byte((byte)LCD_SERIAL.read()); + while (MALYAN_LCD_SERIAL.available()) + parse_lcd_byte((byte)MALYAN_LCD_SERIAL.read()); #if ENABLED(SDSUPPORT) // The way last printing status works is simple: diff --git a/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h b/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h index cff34daf2f02..ebea752c7a4c 100644 --- a/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h +++ b/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h @@ -28,7 +28,7 @@ #define BOARD_INFO_NAME "BTT SKR E3 DIP V1.0" // Release PB3/PB4 (TMC_SW Pins) from JTAG pins -#define DISABLE_JTAG +// #define DISABLE_JTAG // Ignore temp readings during development. //#define BOGUS_TEMPERATURE_GRACE_PERIOD 2000 @@ -117,10 +117,10 @@ * Hardware serial communication ports. * If undefined software serial is used according to the pins below */ - //#define X_HARDWARE_SERIAL Serial1 - //#define Y_HARDWARE_SERIAL Serial1 - //#define Z_HARDWARE_SERIAL Serial1 - //#define E0_HARDWARE_SERIAL Serial1 + //#define X_HARDWARE_SERIAL MSerial1 + //#define Y_HARDWARE_SERIAL MSerial1 + //#define Z_HARDWARE_SERIAL MSerial1 + //#define E0_HARDWARE_SERIAL MSerial1 // // Software serial diff --git a/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h b/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h index b658f3d714b8..78751a6bac87 100644 --- a/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h +++ b/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h @@ -30,8 +30,8 @@ * Hardware serial communication ports. */ #if HAS_TMC_UART - #define X_HARDWARE_SERIAL Serial4 - #define Y_HARDWARE_SERIAL Serial4 - #define Z_HARDWARE_SERIAL Serial4 - #define E0_HARDWARE_SERIAL Serial4 + #define X_HARDWARE_SERIAL MSerial4 + #define Y_HARDWARE_SERIAL MSerial4 + #define Z_HARDWARE_SERIAL MSerial4 + #define E0_HARDWARE_SERIAL MSerial4 #endif diff --git a/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h b/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h index cb94f0bdcacd..0a0d857db3f4 100644 --- a/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h +++ b/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h @@ -52,8 +52,8 @@ * Hardware serial communication ports. */ #if HAS_TMC_UART - #define X_HARDWARE_SERIAL Serial4 - #define Y_HARDWARE_SERIAL Serial4 - #define Z_HARDWARE_SERIAL Serial4 - #define E0_HARDWARE_SERIAL Serial4 + #define X_HARDWARE_SERIAL MSerial4 + #define Y_HARDWARE_SERIAL MSerial4 + #define Z_HARDWARE_SERIAL MSerial4 + #define E0_HARDWARE_SERIAL MSerial4 #endif diff --git a/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h b/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h index ca9364a570d9..f8cbec1e26ac 100644 --- a/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h +++ b/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h @@ -93,10 +93,10 @@ // // Hardware serial with switch // - #define X_HARDWARE_SERIAL Serial1 - #define Y_HARDWARE_SERIAL Serial1 - #define Z_HARDWARE_SERIAL Serial1 - #define E0_HARDWARE_SERIAL Serial1 + #define X_HARDWARE_SERIAL MSerial1 + #define Y_HARDWARE_SERIAL MSerial1 + #define Z_HARDWARE_SERIAL MSerial1 + #define E0_HARDWARE_SERIAL MSerial1 // The 4xTMC2209 module doesn't have a serial multiplexer and // needs to set *_SLAVE_ADDRESS in Configuration_adv.h for X,Y,Z,E0 diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h index 1ab9165830e0..ab6a125472d7 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h @@ -188,17 +188,11 @@ * Hardware serial communication ports. * If undefined software serial is used according to the pins below */ - //#define X_HARDWARE_SERIAL Serial1 - //#define X2_HARDWARE_SERIAL Serial1 - //#define Y_HARDWARE_SERIAL Serial1 - //#define Y2_HARDWARE_SERIAL Serial1 - //#define Z_HARDWARE_SERIAL Serial1 - //#define Z2_HARDWARE_SERIAL Serial1 - //#define E0_HARDWARE_SERIAL Serial1 - //#define E1_HARDWARE_SERIAL Serial1 - //#define E2_HARDWARE_SERIAL Serial1 - //#define E3_HARDWARE_SERIAL Serial1 - //#define E4_HARDWARE_SERIAL Serial1 + //#define X_HARDWARE_SERIAL MSerial1 + //#define Y_HARDWARE_SERIAL MSerial1 + //#define Z_HARDWARE_SERIAL MSerial1 + //#define E0_HARDWARE_SERIAL MSerial1 + //#define E1_HARDWARE_SERIAL MSerial1 // Unused servo pins may be repurposed with SoftwareSerialM //#define X_SERIAL_TX_PIN PF8 // SERVO3_PIN -- XS2 - 6 diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h index 9461a828af01..1bedb331fd53 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h @@ -83,10 +83,10 @@ * Hardware serial communication ports. * If undefined software serial is used according to the pins below */ - //#define X_HARDWARE_SERIAL Serial1 - //#define Y_HARDWARE_SERIAL Serial1 - //#define Z_HARDWARE_SERIAL Serial1 - //#define E0_HARDWARE_SERIAL Serial1 + //#define X_HARDWARE_SERIAL MSerial1 + //#define Y_HARDWARE_SERIAL MSerial1 + //#define Z_HARDWARE_SERIAL MSerial1 + //#define E0_HARDWARE_SERIAL MSerial1 // // Software serial diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h index d911ab2b517b..1732513af100 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h @@ -132,17 +132,11 @@ * Hardware serial communication ports. * If undefined software serial is used according to the pins below */ - //#define X_HARDWARE_SERIAL Serial1 - //#define X2_HARDWARE_SERIAL Serial1 - //#define Y_HARDWARE_SERIAL Serial1 - //#define Y2_HARDWARE_SERIAL Serial1 - //#define Z_HARDWARE_SERIAL Serial1 - //#define Z2_HARDWARE_SERIAL Serial1 - //#define E0_HARDWARE_SERIAL Serial1 - //#define E1_HARDWARE_SERIAL Serial1 - //#define E2_HARDWARE_SERIAL Serial1 - //#define E3_HARDWARE_SERIAL Serial1 - //#define E4_HARDWARE_SERIAL Serial1 + //#define X_HARDWARE_SERIAL MSerial1 + //#define Y_HARDWARE_SERIAL MSerial1 + //#define Z_HARDWARE_SERIAL MSerial1 + //#define E0_HARDWARE_SERIAL MSerial1 + //#define E1_HARDWARE_SERIAL MSerial1 // // Software serial diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h index 9b3817df8c7b..7c09602442fe 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h @@ -125,17 +125,12 @@ * Hardware serial communication ports. * If undefined software serial is used according to the pins below */ - //#define X_HARDWARE_SERIAL Serial1 - //#define X2_HARDWARE_SERIAL Serial1 - //#define Y_HARDWARE_SERIAL Serial1 - //#define Y2_HARDWARE_SERIAL Serial1 - //#define Z_HARDWARE_SERIAL Serial1 - //#define Z2_HARDWARE_SERIAL Serial1 - //#define E0_HARDWARE_SERIAL Serial1 - //#define E1_HARDWARE_SERIAL Serial1 - //#define E2_HARDWARE_SERIAL Serial1 - //#define E3_HARDWARE_SERIAL Serial1 - //#define E4_HARDWARE_SERIAL Serial1 + //#define X_HARDWARE_SERIAL MSerial1 + //#define Y_HARDWARE_SERIAL MSerial1 + //#define Z_HARDWARE_SERIAL MSerial1 + //#define E0_HARDWARE_SERIAL MSerial1 + //#define E1_HARDWARE_SERIAL MSerial1 + //#define E2_HARDWARE_SERIAL MSerial1 // // Software serial From 6a718b2a652dd251bce8cd20a36bcdc2758ba3b3 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Sun, 20 Sep 2020 22:25:57 -0700 Subject: [PATCH 02/33] Add Configuration.h option. --- Marlin/Configuration.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 2635bc750eb0..14d4fa5355bf 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -2165,6 +2165,10 @@ // Touch-screen LCD for Malyan M200/M300 printers // //#define MALYAN_LCD +#if ENABLED(MALYAN_LCD) + // This will be 1 on a Malyan M200, but may differ on other boards. + #define MALYAN_LCD_SERIAL_PORT 1 +#endif // // Touch UI for FTDI EVE (FT800/FT810) displays From d59c3d22ad92793aa77e69562f9ac1366c7864f2 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Mon, 21 Sep 2020 19:57:03 -0700 Subject: [PATCH 03/33] Allow compiling with STM32 HAL (for Malyan M200/M300) --- Marlin/src/HAL/STM32/HAL.h | 81 ++++++++++++----------------- Marlin/src/HAL/STM32F1/HAL.h | 4 +- Marlin/src/lcd/extui/malyan_lcd.cpp | 2 +- 3 files changed, 37 insertions(+), 50 deletions(-) diff --git a/Marlin/src/HAL/STM32/HAL.h b/Marlin/src/HAL/STM32/HAL.h index 08081331b736..a83135a45651 100644 --- a/Marlin/src/HAL/STM32/HAL.h +++ b/Marlin/src/HAL/STM32/HAL.h @@ -43,82 +43,67 @@ // ------------------------ // Defines // ------------------------ +#define _MSERIAL(X) MSerial##X +#define MSERIAL(X) _MSERIAL(X) -#if SERIAL_PORT == 0 - #error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration." -#elif SERIAL_PORT == -1 +#if SERIAL_PORT == -1 #define MYSERIAL0 SerialUSB -#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 SERIAL_PORT == 6 - #define MYSERIAL0 MSerial6 +#elif WITHIN(SERIAL_PORT, 1, 6) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #else - #error "SERIAL_PORT must be from -1 to 6. Please update your configuration." + #error "SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration." #endif #ifdef SERIAL_PORT_2 #define NUM_SERIAL 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 + #if 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 SerialUSB - #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 SERIAL_PORT_2 == 6 - #define MYSERIAL1 MSerial6 + #elif WITHIN(SERIAL_PORT, 1, 6) + #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #else - #error "SERIAL_PORT_2 must be from -1 to 6. Please update your configuration." + #error "SERIAL_PORT_2 must be -1 or from 1 to 6. Please update your configuration." #endif #else #define NUM_SERIAL 1 #endif + #if HAS_DGUS_LCD - #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 + #if 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 SerialUSB - #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 - #elif DGUS_SERIAL_PORT == 6 - #define DGUS_SERIAL MSerial6 + #elif WITHIN(DGUS_SERIAL_PORT, 1, 6) + #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) #else - #error "DGUS_SERIAL_PORT must be from -1 to 6. Please update your configuration." + #error "DGUS_SERIAL must be -1 or from 1 to 6. Please update your configuration." #endif #define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.availableForWrite #endif +#ifdef MALYAN_LCD + #define _FRAMEWORK_SERIAL(X) Serial##X + #define FRAMEWORK_SERIAL(X) _FRAMEWORK_SERIAL(X) + + #ifndef MALYAN_LCD_SERIAL_PORT + #error "MALYAN_LCD requires MALYAN_LCD_SERIAL_PORT to be defined in Configuration.h" + #elif MALYAN_LCD_SERIAL_PORT == SERIAL_PORT + #error "MALYAN_LCD_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration." + #elif defined(SERIAL_PORT_2) && MALYAN_LCD_SERIAL_PORT == SERIAL_PORT_2 + #error "MALYAN_LCD_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." + #elif defined(DGUS_SERIAL) && MALYAN_LCD_SERIAL_PORT == DGUS_SERIAL_PORT + #error "MALYAN_LCD_SERIAL_PORT must be different than DGUS_SERIAL_PORT. Please update your configuration." + #elif WITHIN(MALYAN_LCD_SERIAL_PORT, 1, 6) + #define MALYAN_LCD_SERIAL FRAMEWORK_SERIAL(MALYAN_LCD_SERIAL_PORT) + #else + #error "MALYAN_LCD_SERIAL_PORT must be from 1 to 6. Please update your configuration." + #endif +#endif /** * TODO: review this to return 1 for pins that are not analog input diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h index 803fa0c4ef53..c744839ad0ef 100644 --- a/Marlin/src/HAL/STM32F1/HAL.h +++ b/Marlin/src/HAL/STM32F1/HAL.h @@ -121,7 +121,9 @@ #endif #ifdef MALYAN_LCD - #if MALYAN_LCD_SERIAL_PORT == SERIAL_PORT + #ifndef MALYAN_LCD_SERIAL_PORT + #error "MALYAN_LCD requires MALYAN_LCD_SERIAL_PORT to be defined in Configuration.h" + #elif MALYAN_LCD_SERIAL_PORT == SERIAL_PORT #error "MALYAN_LCD_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration." #elif defined(SERIAL_PORT_2) && MALYAN_LCD_SERIAL_PORT == SERIAL_PORT_2 #error "MALYAN_LCD_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." diff --git a/Marlin/src/lcd/extui/malyan_lcd.cpp b/Marlin/src/lcd/extui/malyan_lcd.cpp index 7c4e8c05eec0..8293e6280f77 100644 --- a/Marlin/src/lcd/extui/malyan_lcd.cpp +++ b/Marlin/src/lcd/extui/malyan_lcd.cpp @@ -64,7 +64,7 @@ // On the Malyan M200, this will be Serial1. On a RAMPS board, // it might not be. #ifndef MALYAN_LCD_SERIAL - #error "Must define MALYAN_LCD_SERIAL to use MALYAN_LCD" + #error "Must define MALYAN_LCD_SERIAL_PORT in Configuration.h to use MALYAN_LCD" #endif // This is based on longest sys command + a filename, plus some buffer From 2b824e45e7663ae135dd944bfa6de136ac7a32cc Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Mon, 21 Sep 2020 20:38:47 -0700 Subject: [PATCH 04/33] Fix minor issues impacting CI --- Marlin/src/HAL/STM32/HAL.h | 2 +- buildroot/tests/malyan_M300-tests | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Marlin/src/HAL/STM32/HAL.h b/Marlin/src/HAL/STM32/HAL.h index a83135a45651..0c24fc984a3c 100644 --- a/Marlin/src/HAL/STM32/HAL.h +++ b/Marlin/src/HAL/STM32/HAL.h @@ -60,7 +60,7 @@ #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration." #elif SERIAL_PORT_2 == -1 #define MYSERIAL1 SerialUSB - #elif WITHIN(SERIAL_PORT, 1, 6) + #elif WITHIN(SERIAL_PORT_2, 1, 6) #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #else #error "SERIAL_PORT_2 must be -1 or from 1 to 6. Please update your configuration." diff --git a/buildroot/tests/malyan_M300-tests b/buildroot/tests/malyan_M300-tests index ada60d558429..8b41114470eb 100755 --- a/buildroot/tests/malyan_M300-tests +++ b/buildroot/tests/malyan_M300-tests @@ -9,6 +9,7 @@ set -e restore_configs use_example_configs "delta/Malyan M300" opt_disable AUTO_BED_LEVELING_3POINT +opt_set MALYAN_LCD_SERIAL_PORT 1 exec_test $1 $2 "Malyan M300 (delta)" # cleanup From 343215043214c52fca7e90329372f5dd8eb04340 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 16:57:49 -0500 Subject: [PATCH 05/33] Macros for other serial port defines --- Marlin/src/HAL/AVR/HAL.h | 6 +--- Marlin/src/HAL/DUE/HAL.h | 34 ++++++--------------- Marlin/src/HAL/LPC1768/HAL.h | 34 ++++++--------------- Marlin/src/HAL/SAMD51/HAL.h | 33 ++++++-------------- Marlin/src/HAL/STM32_F4_F7/HAL.h | 52 ++++++-------------------------- Marlin/src/HAL/TEENSY31_32/HAL.h | 14 ++++----- Marlin/src/HAL/TEENSY35_36/HAL.h | 14 ++++----- Marlin/src/HAL/TEENSY40_41/HAL.h | 44 +++++---------------------- 8 files changed, 60 insertions(+), 171 deletions(-) diff --git a/Marlin/src/HAL/AVR/HAL.h b/Marlin/src/HAL/AVR/HAL.h index 609375e386e8..9db3c22617b6 100644 --- a/Marlin/src/HAL/AVR/HAL.h +++ b/Marlin/src/HAL/AVR/HAL.h @@ -81,11 +81,7 @@ typedef int8_t pin_t; // Serial ports #ifdef USBCON - #if ENABLED(BLUETOOTH) - #define MYSERIAL0 bluetoothSerial - #else - #define MYSERIAL0 Serial - #endif + #define MYSERIAL0 TERN(BLUETOOTH, bluetoothSerial, Serial) #define NUM_SERIAL 1 #else #if !WITHIN(SERIAL_PORT, -1, 3) diff --git a/Marlin/src/HAL/DUE/HAL.h b/Marlin/src/HAL/DUE/HAL.h index 31409c76dd56..9b20b7363ac4 100644 --- a/Marlin/src/HAL/DUE/HAL.h +++ b/Marlin/src/HAL/DUE/HAL.h @@ -38,17 +38,15 @@ #include +#define _MSERIAL(X) Serial##X +#define MSERIAL(X) _MSERIAL(X) +#define Serial0 Serial + // Define MYSERIAL0/1 before MarlinSerial includes! #if SERIAL_PORT == -1 || ENABLED(EMERGENCY_PARSER) #define MYSERIAL0 customizedSerial1 -#elif SERIAL_PORT == 0 - #define MYSERIAL0 Serial -#elif SERIAL_PORT == 1 - #define MYSERIAL0 Serial1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 Serial2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 Serial3 +#elif WITHIN(SERIAL_PORT, 0, 3) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #else #error "The required SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif @@ -58,14 +56,8 @@ #error "SERIAL_PORT_2 must be different from SERIAL_PORT. Please update your configuration." #elif SERIAL_PORT_2 == -1 || ENABLED(EMERGENCY_PARSER) #define MYSERIAL1 customizedSerial2 - #elif SERIAL_PORT_2 == 0 - #define MYSERIAL1 Serial - #elif SERIAL_PORT_2 == 1 - #define MYSERIAL1 Serial1 - #elif SERIAL_PORT_2 == 2 - #define MYSERIAL1 Serial2 - #elif SERIAL_PORT_2 == 3 - #define MYSERIAL1 Serial3 + #elif WITHIN(SERIAL_PORT_2, 0, 3) + #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #else #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." #endif @@ -81,14 +73,8 @@ #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." #elif DGUS_SERIAL_PORT == -1 #define DGUS_SERIAL internalDgusSerial - #elif DGUS_SERIAL_PORT == 0 - #define DGUS_SERIAL Serial - #elif DGUS_SERIAL_PORT == 1 - #define DGUS_SERIAL Serial1 - #elif DGUS_SERIAL_PORT == 2 - #define DGUS_SERIAL Serial2 - #elif DGUS_SERIAL_PORT == 3 - #define DGUS_SERIAL Serial3 + #elif WITHIN(DGUS_SERIAL_PORT, 0, 3) + #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) #else #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif diff --git a/Marlin/src/HAL/LPC1768/HAL.h b/Marlin/src/HAL/LPC1768/HAL.h index 0153bacf42dd..7ddad121ae4a 100644 --- a/Marlin/src/HAL/LPC1768/HAL.h +++ b/Marlin/src/HAL/LPC1768/HAL.h @@ -63,16 +63,14 @@ extern "C" volatile uint32_t _millis; #define ST7920_DELAY_3 DELAY_NS(750) #endif +#define _MSERIAL(X) Serial##X +#define MSERIAL(X) _MSERIAL(X) +#define MSerial0 MSerial + #if SERIAL_PORT == -1 #define MYSERIAL0 UsbSerial -#elif SERIAL_PORT == 0 - #define MYSERIAL0 MSerial -#elif SERIAL_PORT == 1 - #define MYSERIAL0 MSerial1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 MSerial2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 MSerial3 +#elif WITHIN(SERIAL_PORT, 0, 3) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #else #error "SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif @@ -82,14 +80,8 @@ extern "C" volatile uint32_t _millis; #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration." #elif SERIAL_PORT_2 == -1 #define MYSERIAL1 UsbSerial - #elif SERIAL_PORT_2 == 0 - #define MYSERIAL1 MSerial - #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 WITHIN(SERIAL_PORT_2, 0, 3) + #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #else #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." #endif @@ -105,14 +97,8 @@ extern "C" volatile uint32_t _millis; #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 == 0 - #define DGUS_SERIAL MSerial - #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 WITHIN(DGUS_SERIAL_PORT, 0, 3) + #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) #else #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif diff --git a/Marlin/src/HAL/SAMD51/HAL.h b/Marlin/src/HAL/SAMD51/HAL.h index ea0f694cdc02..7b1b693eadcb 100644 --- a/Marlin/src/HAL/SAMD51/HAL.h +++ b/Marlin/src/HAL/SAMD51/HAL.h @@ -35,16 +35,13 @@ // MYSERIAL0 required before MarlinSerial includes! + #define _MSERIAL(X) Serial##X + #define MSERIAL(X) _MSERIAL(INCREMENT(X)) + #if SERIAL_PORT == -1 #define MYSERIAL0 Serial - #elif SERIAL_PORT == 0 - #define MYSERIAL0 Serial1 - #elif SERIAL_PORT == 1 - #define MYSERIAL0 Serial2 - #elif SERIAL_PORT == 2 - #define MYSERIAL0 Serial3 - #elif SERIAL_PORT == 3 - #define MYSERIAL0 Serial4 + #elif WITHIN(SERIAL_PORT, 0, 3) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #else #error "SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif @@ -54,14 +51,8 @@ #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration." #elif SERIAL_PORT_2 == -1 #define MYSERIAL1 Serial - #elif SERIAL_PORT_2 == 0 - #define MYSERIAL1 Serial1 - #elif SERIAL_PORT_2 == 1 - #define MYSERIAL1 Serial2 - #elif SERIAL_PORT_2 == 2 - #define MYSERIAL1 Serial3 - #elif SERIAL_PORT_2 == 3 - #define MYSERIAL1 Serial4 + #elif WITHIN(SERIAL_PORT_2, 0, 3) + #define MYSERIAL0 MSERIAL(SERIAL_PORT_2) #else #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." #endif @@ -77,14 +68,8 @@ #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." #elif DGUS_SERIAL_PORT == -1 #define DGUS_SERIAL Serial - #elif DGUS_SERIAL_PORT == 0 - #define DGUS_SERIAL Serial1 - #elif DGUS_SERIAL_PORT == 1 - #define DGUS_SERIAL Serial2 - #elif DGUS_SERIAL_PORT == 2 - #define DGUS_SERIAL Serial3 - #elif DGUS_SERIAL_PORT == 2 - #define DGUS_SERIAL Serial4 + #elif WITHIN(DGUS_SERIAL_PORT, 0, 3) + #define MYSERIAL0 MSERIAL(DGUS_SERIAL_PORT) #else #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif diff --git a/Marlin/src/HAL/STM32_F4_F7/HAL.h b/Marlin/src/HAL/STM32_F4_F7/HAL.h index 5601400c5ac9..0f686c1c853e 100644 --- a/Marlin/src/HAL/STM32_F4_F7/HAL.h +++ b/Marlin/src/HAL/STM32_F4_F7/HAL.h @@ -46,24 +46,16 @@ // Serial override //extern HalSerial usb_serial; +#define _MSERIAL(X) SerialUART##X +#define MSERIAL(X) _MSERIAL(X) +#define SerialUART0 Serial1 + #if defined(STM32F4) && SERIAL_PORT == 0 #error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration." #elif SERIAL_PORT == -1 #define MYSERIAL0 SerialUSB -#elif SERIAL_PORT == 0 - #define MYSERIAL0 Serial1 -#elif SERIAL_PORT == 1 - #define MYSERIAL0 SerialUART1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 SerialUART2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 SerialUART3 -#elif SERIAL_PORT == 4 - #define MYSERIAL0 SerialUART4 -#elif SERIAL_PORT == 5 - #define MYSERIAL0 SerialUART5 -#elif SERIAL_PORT == 6 - #define MYSERIAL0 SerialUART6 +#elif WITHIN(SERIAL_PORT, 0, 6) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #else #error "SERIAL_PORT must be from -1 to 6. Please update your configuration." #endif @@ -75,20 +67,8 @@ #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration." #elif SERIAL_PORT_2 == -1 #define MYSERIAL1 SerialUSB - #elif SERIAL_PORT_2 == 0 - #define MYSERIAL1 Serial1 - #elif SERIAL_PORT_2 == 1 - #define MYSERIAL1 SerialUART1 - #elif SERIAL_PORT_2 == 2 - #define MYSERIAL1 SerialUART2 - #elif SERIAL_PORT_2 == 3 - #define MYSERIAL1 SerialUART3 - #elif SERIAL_PORT_2 == 4 - #define MYSERIAL1 SerialUART4 - #elif SERIAL_PORT_2 == 5 - #define MYSERIAL1 SerialUART5 - #elif SERIAL_PORT_2 == 6 - #define MYSERIAL1 SerialUART6 + #elif WITHIN(SERIAL_PORT_2, 0, 6) + #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #else #error "SERIAL_PORT_2 must be from -1 to 6. Please update your configuration." #endif @@ -106,20 +86,8 @@ #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." #elif DGUS_SERIAL_PORT == -1 #define DGUS_SERIAL SerialUSB - #elif DGUS_SERIAL_PORT == 0 - #define DGUS_SERIAL Serial1 - #elif DGUS_SERIAL_PORT == 1 - #define DGUS_SERIAL SerialUART1 - #elif DGUS_SERIAL_PORT == 2 - #define DGUS_SERIAL SerialUART2 - #elif DGUS_SERIAL_PORT == 3 - #define DGUS_SERIAL SerialUART3 - #elif DGUS_SERIAL_PORT == 4 - #define DGUS_SERIAL SerialUART4 - #elif DGUS_SERIAL_PORT == 5 - #define DGUS_SERIAL SerialUART5 - #elif DGUS_SERIAL_PORT == 6 - #define DGUS_SERIAL SerialUART6 + #elif WITHIN(DGUS_SERIAL_PORT, 0, 6) + #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) #else #error "DGUS_SERIAL_PORT must be from -1 to 6. Please update your configuration." #endif diff --git a/Marlin/src/HAL/TEENSY31_32/HAL.h b/Marlin/src/HAL/TEENSY31_32/HAL.h index ad095cba83cc..737579b25cc3 100644 --- a/Marlin/src/HAL/TEENSY31_32/HAL.h +++ b/Marlin/src/HAL/TEENSY31_32/HAL.h @@ -51,16 +51,14 @@ #define NUM_SERIAL 1 +#define _MSERIAL(X) Serial##X +#define MSERIAL(X) _MSERIAL(X) +#define Serial0 Serial + #if SERIAL_PORT == -1 #define MYSERIAL0 SerialUSB -#elif SERIAL_PORT == 0 - #define MYSERIAL0 Serial -#elif SERIAL_PORT == 1 - #define MYSERIAL0 Serial1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 Serial2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 Serial3 +#elif WITHIN(SERIAL_PORT, 0, 3) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #endif #define HAL_SERVO_LIB libServo diff --git a/Marlin/src/HAL/TEENSY35_36/HAL.h b/Marlin/src/HAL/TEENSY35_36/HAL.h index 96be08d7b7ca..75541d6f2a66 100644 --- a/Marlin/src/HAL/TEENSY35_36/HAL.h +++ b/Marlin/src/HAL/TEENSY35_36/HAL.h @@ -56,16 +56,14 @@ #define NUM_SERIAL 1 +#define _MSERIAL(X) Serial##X +#define MSERIAL(X) _MSERIAL(X) +#define Serial0 Serial + #if SERIAL_PORT == -1 #define MYSERIAL0 SerialUSB -#elif SERIAL_PORT == 0 - #define MYSERIAL0 Serial -#elif SERIAL_PORT == 1 - #define MYSERIAL0 Serial1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 Serial2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 Serial3 +#elif WITHIN(SERIAL_PORT, 0, 3) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #endif #define HAL_SERVO_LIB libServo diff --git a/Marlin/src/HAL/TEENSY40_41/HAL.h b/Marlin/src/HAL/TEENSY40_41/HAL.h index 0626d4ee9cda..2e0a7c049787 100644 --- a/Marlin/src/HAL/TEENSY40_41/HAL.h +++ b/Marlin/src/HAL/TEENSY40_41/HAL.h @@ -50,26 +50,14 @@ #define IS_TEENSY41 1 #endif +#define _MSERIAL(X) Serial##X +#define MSERIAL(X) _MSERIAL(X) +#define Serial0 Serial + #if SERIAL_PORT == -1 #define MYSERIAL0 SerialUSB -#elif SERIAL_PORT == 0 - #define MYSERIAL0 Serial -#elif SERIAL_PORT == 1 - #define MYSERIAL0 Serial1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 Serial2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 Serial3 -#elif SERIAL_PORT == 4 - #define MYSERIAL0 Serial4 -#elif SERIAL_PORT == 5 - #define MYSERIAL0 Serial5 -#elif SERIAL_PORT == 6 - #define MYSERIAL0 Serial6 -#elif SERIAL_PORT == 7 - #define MYSERIAL0 Serial7 -#elif SERIAL_PORT == 8 - #define MYSERIAL0 Serial8 +#elif WITHIN(SERIAL_PORT, 0, 8) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #else #error "The required SERIAL_PORT must be from -1 to 8. Please update your configuration." #endif @@ -79,24 +67,8 @@ #error "SERIAL_PORT_2 must be different from SERIAL_PORT. Please update your configuration." #elif SERIAL_PORT_2 == -1 #define MYSERIAL1 usbSerial - #elif SERIAL_PORT_2 == 0 - #define MYSERIAL1 Serial - #elif SERIAL_PORT_2 == 1 - #define MYSERIAL1 Serial1 - #elif SERIAL_PORT_2 == 2 - #define MYSERIAL1 Serial2 - #elif SERIAL_PORT_2 == 3 - #define MYSERIAL1 Serial3 - #elif SERIAL_PORT_2 == 4 - #define MYSERIAL1 Serial4 - #elif SERIAL_PORT_2 == 5 - #define MYSERIAL1 Serial5 - #elif SERIAL_PORT_2 == 6 - #define MYSERIAL1 Serial6 - #elif SERIAL_PORT_2 == 7 - #define MYSERIAL1 Serial7 - #elif SERIAL_PORT_2 == 8 - #define MYSERIAL1 Serial8 + #elif WITHIN(SERIAL_PORT_2, 0, 8) + #define MYSERIAL0 MSERIAL(SERIAL_PORT_2) #else #error "SERIAL_PORT_2 must be from -1 to 8. Please update your configuration." #endif From 60a7c2146dd2dd71b95a2f4c90fef25d78a67690 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 17:06:02 -0500 Subject: [PATCH 06/33] tweak option name --- Marlin/Configuration.h | 2 +- Marlin/src/HAL/STM32/HAL.h | 22 +++++++++++----------- Marlin/src/HAL/STM32F1/HAL.h | 24 ++++++++++++------------ Marlin/src/lcd/extui/malyan_lcd.cpp | 2 +- buildroot/tests/malyan_M300-tests | 2 +- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 14d4fa5355bf..ce767c7b0a85 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -2167,7 +2167,7 @@ //#define MALYAN_LCD #if ENABLED(MALYAN_LCD) // This will be 1 on a Malyan M200, but may differ on other boards. - #define MALYAN_LCD_SERIAL_PORT 1 + #define MALYAN_SERIAL_PORT 1 #endif // diff --git a/Marlin/src/HAL/STM32/HAL.h b/Marlin/src/HAL/STM32/HAL.h index 0c24fc984a3c..c9da8c137192 100644 --- a/Marlin/src/HAL/STM32/HAL.h +++ b/Marlin/src/HAL/STM32/HAL.h @@ -90,18 +90,18 @@ #define _FRAMEWORK_SERIAL(X) Serial##X #define FRAMEWORK_SERIAL(X) _FRAMEWORK_SERIAL(X) - #ifndef MALYAN_LCD_SERIAL_PORT - #error "MALYAN_LCD requires MALYAN_LCD_SERIAL_PORT to be defined in Configuration.h" - #elif MALYAN_LCD_SERIAL_PORT == SERIAL_PORT - #error "MALYAN_LCD_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration." - #elif defined(SERIAL_PORT_2) && MALYAN_LCD_SERIAL_PORT == SERIAL_PORT_2 - #error "MALYAN_LCD_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." - #elif defined(DGUS_SERIAL) && MALYAN_LCD_SERIAL_PORT == DGUS_SERIAL_PORT - #error "MALYAN_LCD_SERIAL_PORT must be different than DGUS_SERIAL_PORT. Please update your configuration." - #elif WITHIN(MALYAN_LCD_SERIAL_PORT, 1, 6) - #define MALYAN_LCD_SERIAL FRAMEWORK_SERIAL(MALYAN_LCD_SERIAL_PORT) + #ifndef MALYAN_SERIAL_PORT + #error "MALYAN_LCD requires MALYAN_SERIAL_PORT to be defined in Configuration.h" + #elif MALYAN_SERIAL_PORT == SERIAL_PORT + #error "MALYAN_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration." + #elif defined(SERIAL_PORT_2) && MALYAN_SERIAL_PORT == SERIAL_PORT_2 + #error "MALYAN_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." + #elif defined(DGUS_SERIAL) && MALYAN_SERIAL_PORT == DGUS_SERIAL_PORT + #error "MALYAN_SERIAL_PORT must be different than DGUS_SERIAL_PORT. Please update your configuration." + #elif WITHIN(MALYAN_SERIAL_PORT, 1, 6) + #define MALYAN_LCD_SERIAL FRAMEWORK_SERIAL(MALYAN_SERIAL_PORT) #else - #error "MALYAN_LCD_SERIAL_PORT must be from 1 to 6. Please update your configuration." + #error "MALYAN_SERIAL_PORT must be from 1 to 6. Please update your configuration." #endif #endif diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h index c744839ad0ef..273823001ea6 100644 --- a/Marlin/src/HAL/STM32F1/HAL.h +++ b/Marlin/src/HAL/STM32F1/HAL.h @@ -121,20 +121,20 @@ #endif #ifdef MALYAN_LCD - #ifndef MALYAN_LCD_SERIAL_PORT - #error "MALYAN_LCD requires MALYAN_LCD_SERIAL_PORT to be defined in Configuration.h" - #elif MALYAN_LCD_SERIAL_PORT == SERIAL_PORT - #error "MALYAN_LCD_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration." - #elif defined(SERIAL_PORT_2) && MALYAN_LCD_SERIAL_PORT == SERIAL_PORT_2 - #error "MALYAN_LCD_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." - #elif defined(DGUS_SERIAL) && MALYAN_LCD_SERIAL_PORT == DGUS_SERIAL_PORT - #error "MALYAN_LCD_SERIAL_PORT must be different than DGUS_SERIAL_PORT. Please update your configuration." - #elif WITHIN(MALYAN_LCD_SERIAL_PORT, 1, NUM_UARTS) - #define MALYAN_LCD_SERIAL MSERIAL(MALYAN_LCD_SERIAL_PORT) #elif defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) - #error "MALYAN_LCD_SERIAL_PORT must be from 1 to 5. Please update your configuration." + #ifndef MALYAN_SERIAL_PORT + #error "MALYAN_LCD requires MALYAN_SERIAL_PORT to be defined in Configuration.h" + #elif MALYAN_SERIAL_PORT == SERIAL_PORT + #error "MALYAN_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration." + #elif defined(SERIAL_PORT_2) && MALYAN_SERIAL_PORT == SERIAL_PORT_2 + #error "MALYAN_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." + #elif defined(DGUS_SERIAL) && MALYAN_SERIAL_PORT == DGUS_SERIAL_PORT + #error "MALYAN_SERIAL_PORT must be different than DGUS_SERIAL_PORT. Please update your configuration." + #elif WITHIN(MALYAN_SERIAL_PORT, 1, NUM_UARTS) + #define MALYAN_LCD_SERIAL MSERIAL(MALYAN_SERIAL_PORT) + #error "MALYAN_SERIAL_PORT must be from 1 to 5. Please update your configuration." #else - #error "MALYAN_LCD_SERIAL_PORT must be from 1 to 3. Please update your configuration." + #error "MALYAN_SERIAL_PORT must be from 1 to 3. Please update your configuration." #endif #endif diff --git a/Marlin/src/lcd/extui/malyan_lcd.cpp b/Marlin/src/lcd/extui/malyan_lcd.cpp index 8293e6280f77..32833f2a547f 100644 --- a/Marlin/src/lcd/extui/malyan_lcd.cpp +++ b/Marlin/src/lcd/extui/malyan_lcd.cpp @@ -64,7 +64,7 @@ // On the Malyan M200, this will be Serial1. On a RAMPS board, // it might not be. #ifndef MALYAN_LCD_SERIAL - #error "Must define MALYAN_LCD_SERIAL_PORT in Configuration.h to use MALYAN_LCD" + #error "Must define MALYAN_SERIAL_PORT in Configuration.h to use MALYAN_LCD" #endif // This is based on longest sys command + a filename, plus some buffer diff --git a/buildroot/tests/malyan_M300-tests b/buildroot/tests/malyan_M300-tests index 8b41114470eb..06c08d3a6c98 100755 --- a/buildroot/tests/malyan_M300-tests +++ b/buildroot/tests/malyan_M300-tests @@ -9,7 +9,7 @@ set -e restore_configs use_example_configs "delta/Malyan M300" opt_disable AUTO_BED_LEVELING_3POINT -opt_set MALYAN_LCD_SERIAL_PORT 1 +opt_set MALYAN_SERIAL_PORT 1 exec_test $1 $2 "Malyan M300 (delta)" # cleanup From d7986fa310be61844e44d2a40a343920f22eeba3 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 17:39:07 -0500 Subject: [PATCH 07/33] Misc fixes, adjustments --- Marlin/src/HAL/LPC1768/MarlinSerial.cpp | 2 +- Marlin/src/HAL/LPC1768/inc/SanityCheck.h | 36 ++++++++++++------- Marlin/src/HAL/STM32/HAL.h | 4 +-- Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h | 2 +- Marlin/src/HAL/STM32F1/HAL.h | 20 +++++------ Marlin/src/HAL/STM32F1/MarlinSerial.cpp | 23 ++++++------ Marlin/src/HAL/STM32F1/MarlinSerial.h | 2 +- Marlin/src/HAL/STM32F1/sdio.cpp | 2 +- Marlin/src/core/macros.h | 6 ++++ Marlin/src/inc/SanityCheck.h | 2 +- 10 files changed, 57 insertions(+), 42 deletions(-) diff --git a/Marlin/src/HAL/LPC1768/MarlinSerial.cpp b/Marlin/src/HAL/LPC1768/MarlinSerial.cpp index c3fb3bd0e4d2..6df5147e34da 100644 --- a/Marlin/src/HAL/LPC1768/MarlinSerial.cpp +++ b/Marlin/src/HAL/LPC1768/MarlinSerial.cpp @@ -24,7 +24,7 @@ #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 ANY_ZERO(SERIAL_PORT, SERIAL_PORT_2, DGUS_SERIAL_PORT) MarlinSerial MSerial(LPC_UART0); extern "C" void UART0_IRQHandler() { MSerial.IRQHandler(); diff --git a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h index 3fc1dd801a45..350a46b44312 100644 --- a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h +++ b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h @@ -89,7 +89,10 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o * Serial2 | P0_10 | P0_11 | * Serial3 | P0_00 | P0_01 | */ -#if (defined(SERIAL_PORT) && SERIAL_PORT == 0) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == 0) || (defined(DGUS_SERIAL_PORT) && DGUS_SERIAL_PORT == 0) +#define ANY_TX(N,V...) DO(IS_TX##N,||,V) +#define ANY_RX(N,V...) DO(IS_RX##N,||,V) + +#if ANY_ZERO(SERIAL_PORT, SERIAL_PORT_2, DGUS_SERIAL_PORT) #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,48 +109,56 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o #if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1 || DGUS_SERIAL_PORT == 1 #define IS_TX1(P) (P == P0_15) #define IS_RX1(P) (P == P0_16) + #define _IS_TX1_1 IS_TX1 + #define _IS_RX1_1 IS_RX1 #if IS_TX1(TMC_SW_SCK) #error "Serial port pins (1) conflict with other pins!" #elif HAS_SPI_LCD #if IS_TX1(BTN_EN2) || IS_RX1(BTN_EN1) #error "Serial port pins (1) conflict with Encoder Buttons!" - #elif IS_TX1(SCK_PIN) || IS_TX1(LCD_PINS_D4) || IS_TX1(DOGLCD_SCK) || IS_TX1(LCD_RESET_PIN) || IS_TX1(LCD_PINS_RS) || IS_TX1(SHIFT_CLK) \ - || IS_RX1(LCD_SDSS) || IS_RX1(LCD_PINS_RS) || IS_RX1(MISO_PIN) || IS_RX1(DOGLCD_A0) || IS_RX1(SS_PIN) || IS_RX1(LCD_SDSS) || IS_RX1(DOGLCD_CS) || IS_RX1(LCD_RESET_PIN) || IS_RX1(LCD_BACKLIGHT_PIN) + #elif ANY_TX(1, SCK_PIN, LCD_PINS_D4, DOGLCD_SCK, LCD_RESET_PIN, LCD_PINS_RS, SHIFT_CLK) \ + || ANY_RX(1, LCD_SDSS, LCD_PINS_RS, MISO_PIN, DOGLCD_A0, SS_PIN, LCD_SDSS, DOGLCD_CS, LCD_RESET_PIN, LCD_BACKLIGHT_PIN) #error "Serial port pins (1) conflict with LCD pins!" #endif #endif #undef IS_TX1 #undef IS_RX1 + #undef _IS_TX1_1 + #undef _IS_RX1_1 #endif #if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 || DGUS_SERIAL_PORT == 2 #define IS_TX2(P) (P == P0_10) #define IS_RX2(P) (P == P0_11) - #if IS_TX2(X2_ENABLE_PIN) || IS_RX2(X2_DIR_PIN) || IS_RX2(X2_STEP_PIN) || (AXIS_HAS_SPI(X2) && IS_TX2(X2_CS_PIN)) + #define _IS_TX2_1 IS_TX2 + #define _IS_RX2_1 IS_RX2 + #if IS_TX2(X2_ENABLE_PIN) || ANY_RX2(X2_DIR_PIN, X2_STEP_PIN) || (AXIS_HAS_SPI(X2) && IS_TX2(X2_CS_PIN)) #error "Serial port pins (2) conflict with X2 pins!" - #elif IS_TX2(Y2_ENABLE_PIN) || IS_RX2(Y2_DIR_PIN) || IS_RX2(Y2_STEP_PIN) || (AXIS_HAS_SPI(Y2) && IS_TX2(Y2_CS_PIN)) + #elif IS_TX2(Y2_ENABLE_PIN) || ANY_RX2(Y2_DIR_PIN, Y2_STEP_PIN) || (AXIS_HAS_SPI(Y2) && IS_TX2(Y2_CS_PIN)) #error "Serial port pins (2) conflict with Y2 pins!" - #elif IS_TX2(Z2_ENABLE_PIN) || IS_RX2(Z2_DIR_PIN) || IS_RX2(Z2_STEP_PIN) || (AXIS_HAS_SPI(Z2) && IS_TX2(Z2_CS_PIN)) + #elif IS_TX2(Z2_ENABLE_PIN) || ANY_RX2(Z2_DIR_PIN, Z2_STEP_PIN) || (AXIS_HAS_SPI(Z2) && IS_TX2(Z2_CS_PIN)) #error "Serial port pins (2) conflict with Z2 pins!" - #elif IS_TX2(Z3_ENABLE_PIN) || IS_RX2(Z3_DIR_PIN) || IS_RX2(Z3_STEP_PIN) || (AXIS_HAS_SPI(Z3) && IS_TX2(Z3_CS_PIN)) + #elif IS_TX2(Z3_ENABLE_PIN) || ANY_RX2(Z3_DIR_PIN, Z3_STEP_PIN) || (AXIS_HAS_SPI(Z3) && IS_TX2(Z3_CS_PIN)) #error "Serial port pins (2) conflict with Z3 pins!" - #elif IS_TX2(Z4_ENABLE_PIN) || IS_RX2(Z4_DIR_PIN) || IS_RX2(Z4_STEP_PIN) || (AXIS_HAS_SPI(Z4) && IS_TX2(Z4_CS_PIN)) + #elif IS_TX2(Z4_ENABLE_PIN) || ANY_RX2(Z4_DIR_PIN, Z4_STEP_PIN) || (AXIS_HAS_SPI(Z4) && IS_TX2(Z4_CS_PIN)) #error "Serial port pins (2) conflict with Z4 pins!" - #elif IS_RX2(X_DIR_PIN) || IS_RX2(Y_DIR_PIN) + #elif ANY_RX2(X_DIR_PIN, Y_DIR_PIN) #error "Serial port pins (2) conflict with other pins!" #elif Y_HOME_DIR < 0 && IS_TX2(Y_STOP_PIN) #error "Serial port pins (2) conflict with Y endstop pin!" #elif HAS_CUSTOM_PROBE_PIN && IS_TX2(Z_MIN_PROBE_PIN) #error "Serial port pins (2) conflict with probe pin!" - #elif IS_TX2(X_ENABLE_PIN) || IS_RX2(X_DIR_PIN) || IS_TX2(Y_ENABLE_PIN) || IS_RX2(Y_DIR_PIN) + #elif ANY_TX2(X_ENABLE_PIN, Y_ENABLE_PIN) || ANY_RX2(X_DIR_PIN, Y_DIR_PIN) #error "Serial port pins (2) conflict with X/Y stepper pins!" #elif HAS_MULTI_EXTRUDER && (IS_TX2(E1_ENABLE_PIN) || (AXIS_HAS_SPI(E1) && IS_TX2(E1_CS_PIN))) #error "Serial port pins (2) conflict with E1 stepper pins!" - #elif EXTRUDERS && (IS_RX2(E0_DIR_PIN) || IS_RX2(E0_STEP_PIN)) + #elif EXTRUDERS && ANY_RX2(E0_DIR_PIN, E0_STEP_PIN) #error "Serial port pins (2) conflict with E stepper pins!" #endif #undef IS_TX2 #undef IS_RX2 + #undef _IS_TX2_1 + #undef _IS_RX2_1 #endif #if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 || DGUS_SERIAL_PORT == 3 @@ -155,8 +166,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o #define PIN_IS_RX3(P) (P##_PIN == P0_01) #if PIN_IS_TX3(X_MIN) || PIN_IS_RX3(X_MAX) #error "Serial port pins (3) conflict with X endstop pins!" - #elif PIN_IS_TX3(Y_SERIAL_TX) || PIN_IS_TX3(Y_SERIAL_RX) \ - || PIN_IS_RX3(X_SERIAL_TX) || PIN_IS_RX3(X_SERIAL_RX) + #elif PIN_IS_TX3(Y_SERIAL_TX) || PIN_IS_TX3(Y_SERIAL_RX) || PIN_IS_RX3(X_SERIAL_TX) || PIN_IS_RX3(X_SERIAL_RX) #error "Serial port pins (3) conflict with X/Y axis UART pins!" #elif PIN_IS_TX3(X2_DIR) || PIN_IS_RX3(X2_STEP) #error "Serial port pins (3) conflict with X2 pins!" diff --git a/Marlin/src/HAL/STM32/HAL.h b/Marlin/src/HAL/STM32/HAL.h index c9da8c137192..46a538118ace 100644 --- a/Marlin/src/HAL/STM32/HAL.h +++ b/Marlin/src/HAL/STM32/HAL.h @@ -80,13 +80,13 @@ #elif WITHIN(DGUS_SERIAL_PORT, 1, 6) #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) #else - #error "DGUS_SERIAL must be -1 or from 1 to 6. Please update your configuration." + #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 -#ifdef MALYAN_LCD +#if ENABLED(MALYAN_LCD) #define _FRAMEWORK_SERIAL(X) Serial##X #define FRAMEWORK_SERIAL(X) _FRAMEWORK_SERIAL(X) diff --git a/Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h b/Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h index 5ff40debea5e..9069d9f7bd8a 100644 --- a/Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h +++ b/Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h @@ -98,7 +98,7 @@ static inline void pwm_details(const pin_t pin) { timer_dev * const tdev = PIN_MAP[pin].timer_device; const uint8_t channel = PIN_MAP[pin].timer_channel; const char num = ( - #if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) + #if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY) tdev == &timer8 ? '8' : tdev == &timer5 ? '5' : #endif diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h index 273823001ea6..6c9d98c4e7d5 100644 --- a/Marlin/src/HAL/STM32F1/HAL.h +++ b/Marlin/src/HAL/STM32F1/HAL.h @@ -53,7 +53,7 @@ // ------------------------ #ifndef STM32_FLASH_SIZE - #if defined(MCU_STM32F103RE) || defined(MCU_STM32F103VE) + #if EITHER(MCU_STM32F103RE, MCU_STM32F103VE) #define STM32_FLASH_SIZE 512 #else #define STM32_FLASH_SIZE 256 @@ -71,7 +71,7 @@ #define _MSERIAL(X) MSerial##X #define MSERIAL(X) _MSERIAL(X) -#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) +#if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY) #define NUM_UARTS 5 #else #define NUM_UARTS 3 @@ -81,7 +81,7 @@ #define MYSERIAL0 UsbSerial #elif WITHIN(SERIAL_PORT, 1, NUM_UARTS) #define MYSERIAL0 MSERIAL(SERIAL_PORT) -#elif defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) +#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." @@ -94,7 +94,7 @@ #define MYSERIAL1 UsbSerial #elif WITHIN(SERIAL_PORT_2, 1, NUM_UARTS) #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) - #elif defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) + #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 -1 or from 1 to 3. Please update your configuration." @@ -104,7 +104,7 @@ #define NUM_SERIAL 1 #endif -#ifdef DGUS_SERIAL +#ifdef DGUS_SERIAL_PORT #if 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 @@ -113,15 +113,14 @@ #define DGUS_SERIAL UsbSerial #elif WITHIN(DGUS_SERIAL_PORT, 1, NUM_UARTS) #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) - #elif defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) - #error "DGUS_SERIAL must be -1 or from 1 to 5. Please update your configuration." + #elif NUM_UARTS == 5 + #error "DGUS_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration." #else - #error "DGUS_SERIAL must be -1 or from 1 to 3. Please update your configuration." + #error "DGUS_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration." #endif #endif -#ifdef MALYAN_LCD - #elif defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) +#if ENABLED(MALYAN_LCD) #ifndef MALYAN_SERIAL_PORT #error "MALYAN_LCD requires MALYAN_SERIAL_PORT to be defined in Configuration.h" #elif MALYAN_SERIAL_PORT == SERIAL_PORT @@ -132,6 +131,7 @@ #error "MALYAN_SERIAL_PORT must be different than DGUS_SERIAL_PORT. Please update your configuration." #elif WITHIN(MALYAN_SERIAL_PORT, 1, NUM_UARTS) #define MALYAN_LCD_SERIAL MSERIAL(MALYAN_SERIAL_PORT) + #elif NUM_UARTS == 5 #error "MALYAN_SERIAL_PORT must be from 1 to 5. Please update your configuration." #else #error "MALYAN_SERIAL_PORT must be from 1 to 3. Please update your configuration." diff --git a/Marlin/src/HAL/STM32F1/MarlinSerial.cpp b/Marlin/src/HAL/STM32F1/MarlinSerial.cpp index c57fff81b656..8328c4930fa0 100644 --- a/Marlin/src/HAL/STM32F1/MarlinSerial.cpp +++ b/Marlin/src/HAL/STM32F1/MarlinSerial.cpp @@ -76,8 +76,7 @@ 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) -{ +constexpr bool serial_handles_emergency(int port) { return false #ifdef SERIAL_PORT || (SERIAL_PORT) == port @@ -85,10 +84,10 @@ constexpr bool serial_handles_emergency(int port) #ifdef SERIAL_PORT_2 || (SERIAL_PORT_2) == port #endif - #ifdef DGUS_SERIAL_PORT + #ifdef DGUS_SERIAL_PORT || (DGUS_SERIAL_PORT) == port #endif - ; + ; } #define DEFINE_HWSERIAL_MARLIN(name, n) \ @@ -101,13 +100,13 @@ constexpr bool serial_handles_emergency(int port) } #define DEFINE_HWSERIAL_UART_MARLIN(name, n) \ -MarlinSerial name(UART##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(UART##n->rb, UART##n->wb, UART##n##_BASE, MSerial##n); \ -} + MarlinSerial name(UART##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(UART##n->rb, UART##n->wb, UART##n##_BASE, MSerial##n); \ + } // Instantiate all UARTs even if they are not needed // This avoids a bunch of logic to figure out every serial @@ -115,7 +114,7 @@ extern "C" void __irq_usart##n(void) { \ DEFINE_HWSERIAL_MARLIN(MSerial1, 1); DEFINE_HWSERIAL_MARLIN(MSerial2, 2); DEFINE_HWSERIAL_MARLIN(MSerial3, 3); -#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) +#if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY) DEFINE_HWSERIAL_UART_MARLIN(MSerial4, 4); DEFINE_HWSERIAL_UART_MARLIN(MSerial5, 5); #endif diff --git a/Marlin/src/HAL/STM32F1/MarlinSerial.h b/Marlin/src/HAL/STM32F1/MarlinSerial.h index c99f5078cf79..3aae519ec93c 100644 --- a/Marlin/src/HAL/STM32F1/MarlinSerial.h +++ b/Marlin/src/HAL/STM32F1/MarlinSerial.h @@ -68,7 +68,7 @@ class MarlinSerial : public HardwareSerial { extern MarlinSerial MSerial1; extern MarlinSerial MSerial2; extern MarlinSerial MSerial3; -#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) +#if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY) extern MarlinSerial MSerial4; extern MarlinSerial MSerial5; #endif diff --git a/Marlin/src/HAL/STM32F1/sdio.cpp b/Marlin/src/HAL/STM32F1/sdio.cpp index 0e9a3b2d0450..ffa6db1206ae 100644 --- a/Marlin/src/HAL/STM32F1/sdio.cpp +++ b/Marlin/src/HAL/STM32F1/sdio.cpp @@ -26,7 +26,7 @@ #include "../../inc/MarlinConfig.h" // Allow pins/pins.h to set density -#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) +#if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY) #include "sdio.h" diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h index 5fc1081019b5..4a99c32e3602 100644 --- a/Marlin/src/core/macros.h +++ b/Marlin/src/core/macros.h @@ -201,6 +201,12 @@ #define BOTH(V1,V2) ALL(V1,V2) #define EITHER(V1,V2) ANY(V1,V2) +// Macros to test for '0' settings +#define SET_ZERO(D) (defined(D) && D == 0) +#define _ISZER_1 SET_ZERO +#define ALL_ZERO(V...) DO(ISZER,&&,V) +#define ANY_ZERO(V...) DO(ISZER,||,V) + // Macros to support pins/buttons exist testing #define PIN_EXISTS(PN) (defined(PN##_PIN) && PN##_PIN >= 0) #define _PINEX_1 PIN_EXISTS diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 8d68b33ece20..c6149050814c 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -395,7 +395,7 @@ #error "PARKING_EXTRUDER_SECURITY_RAISE is now TOOLCHANGE_ZRAISE. Please update your configuration." #elif defined(SWITCHING_TOOLHEAD_SECURITY_RAISE) #error "SWITCHING_TOOLHEAD_SECURITY_RAISE is now TOOLCHANGE_ZRAISE. Please update your configuration." -#elif defined(G0_FEEDRATE) && G0_FEEDRATE == 0 +#elif SET_ZERO(G0_FEEDRATE) #error "G0_FEEDRATE is now used to set the G0 feedrate. Please update your configuration." #elif defined(MBL_Z_STEP) #error "MBL_Z_STEP is now MESH_EDIT_Z_STEP. Please update your configuration." From 62b40627f2508fcd718c101ac1dc170495219883 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 17:46:57 -0500 Subject: [PATCH 08/33] Tweak ANY_RX --- Marlin/src/HAL/LPC1768/inc/SanityCheck.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h index 350a46b44312..52dcf1784f72 100644 --- a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h +++ b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h @@ -132,27 +132,27 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o #define IS_RX2(P) (P == P0_11) #define _IS_TX2_1 IS_TX2 #define _IS_RX2_1 IS_RX2 - #if IS_TX2(X2_ENABLE_PIN) || ANY_RX2(X2_DIR_PIN, X2_STEP_PIN) || (AXIS_HAS_SPI(X2) && IS_TX2(X2_CS_PIN)) + #if IS_TX2(X2_ENABLE_PIN) || ANY_RX(2, X2_DIR_PIN, X2_STEP_PIN) || (AXIS_HAS_SPI(X2) && IS_TX2(X2_CS_PIN)) #error "Serial port pins (2) conflict with X2 pins!" - #elif IS_TX2(Y2_ENABLE_PIN) || ANY_RX2(Y2_DIR_PIN, Y2_STEP_PIN) || (AXIS_HAS_SPI(Y2) && IS_TX2(Y2_CS_PIN)) + #elif IS_TX2(Y2_ENABLE_PIN) || ANY_RX(2, Y2_DIR_PIN, Y2_STEP_PIN) || (AXIS_HAS_SPI(Y2) && IS_TX2(Y2_CS_PIN)) #error "Serial port pins (2) conflict with Y2 pins!" - #elif IS_TX2(Z2_ENABLE_PIN) || ANY_RX2(Z2_DIR_PIN, Z2_STEP_PIN) || (AXIS_HAS_SPI(Z2) && IS_TX2(Z2_CS_PIN)) + #elif IS_TX2(Z2_ENABLE_PIN) || ANY_RX(2, Z2_DIR_PIN, Z2_STEP_PIN) || (AXIS_HAS_SPI(Z2) && IS_TX2(Z2_CS_PIN)) #error "Serial port pins (2) conflict with Z2 pins!" - #elif IS_TX2(Z3_ENABLE_PIN) || ANY_RX2(Z3_DIR_PIN, Z3_STEP_PIN) || (AXIS_HAS_SPI(Z3) && IS_TX2(Z3_CS_PIN)) + #elif IS_TX2(Z3_ENABLE_PIN) || ANY_RX(2, Z3_DIR_PIN, Z3_STEP_PIN) || (AXIS_HAS_SPI(Z3) && IS_TX2(Z3_CS_PIN)) #error "Serial port pins (2) conflict with Z3 pins!" - #elif IS_TX2(Z4_ENABLE_PIN) || ANY_RX2(Z4_DIR_PIN, Z4_STEP_PIN) || (AXIS_HAS_SPI(Z4) && IS_TX2(Z4_CS_PIN)) + #elif IS_TX2(Z4_ENABLE_PIN) || ANY_RX(2, Z4_DIR_PIN, Z4_STEP_PIN) || (AXIS_HAS_SPI(Z4) && IS_TX2(Z4_CS_PIN)) #error "Serial port pins (2) conflict with Z4 pins!" - #elif ANY_RX2(X_DIR_PIN, Y_DIR_PIN) + #elif ANY_RX(2, X_DIR_PIN, Y_DIR_PIN) #error "Serial port pins (2) conflict with other pins!" #elif Y_HOME_DIR < 0 && IS_TX2(Y_STOP_PIN) #error "Serial port pins (2) conflict with Y endstop pin!" #elif HAS_CUSTOM_PROBE_PIN && IS_TX2(Z_MIN_PROBE_PIN) #error "Serial port pins (2) conflict with probe pin!" - #elif ANY_TX2(X_ENABLE_PIN, Y_ENABLE_PIN) || ANY_RX2(X_DIR_PIN, Y_DIR_PIN) + #elif ANY_TX2(X_ENABLE_PIN, Y_ENABLE_PIN) || ANY_RX(2, X_DIR_PIN, Y_DIR_PIN) #error "Serial port pins (2) conflict with X/Y stepper pins!" #elif HAS_MULTI_EXTRUDER && (IS_TX2(E1_ENABLE_PIN) || (AXIS_HAS_SPI(E1) && IS_TX2(E1_CS_PIN))) #error "Serial port pins (2) conflict with E1 stepper pins!" - #elif EXTRUDERS && ANY_RX2(E0_DIR_PIN, E0_STEP_PIN) + #elif EXTRUDERS && ANY_RX(2, E0_DIR_PIN, E0_STEP_PIN) #error "Serial port pins (2) conflict with E stepper pins!" #endif #undef IS_TX2 @@ -185,6 +185,9 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o #undef PIN_IS_RX3 #endif +#undef ANY_TX +#undef ANY_RX + // // Flag any i2c pin conflicts // From 997cad7668db4399de9254b9ae3aeaba96ceb784 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 17:50:39 -0500 Subject: [PATCH 09/33] Update MarlinSerial.h --- Marlin/src/HAL/STM32F1/MarlinSerial.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Marlin/src/HAL/STM32F1/MarlinSerial.h b/Marlin/src/HAL/STM32F1/MarlinSerial.h index 3aae519ec93c..5c226882f702 100644 --- a/Marlin/src/HAL/STM32F1/MarlinSerial.h +++ b/Marlin/src/HAL/STM32F1/MarlinSerial.h @@ -35,17 +35,13 @@ class MarlinSerial : public HardwareSerial { public: - MarlinSerial(struct usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin, bool emergency_parser) : + MarlinSerial(struct usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin, bool TERN_(EMERGENCY_PARSER, emergency_parser)) : HardwareSerial(usart_device, tx_pin, rx_pin) #if ENABLED(EMERGENCY_PARSER) - , emergency_parser_enabled(emergency_parser), - emergency_state(EmergencyParser::State::EP_RESET) + , emergency_parser_enabled(emergency_parser) + , emergency_state(EmergencyParser::State::EP_RESET) #endif - { - #if DISABLED(EMERGENCY_PARSER) - UNUSED(emergency_parser); - #endif - } + { } #ifdef UART_IRQ_PRIO // shadow the parent methods to set irq priority after the begin From 4b0aa06ece96a30ab0217d05acc353389c754077 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 18:36:44 -0500 Subject: [PATCH 10/33] Fix, consolidate serial sanity-checking --- Marlin/Configuration.h | 2 +- Marlin/src/HAL/AVR/HAL.h | 11 -------- Marlin/src/HAL/AVR/MarlinSerial.cpp | 20 +++++++-------- Marlin/src/HAL/AVR/MarlinSerial.h | 6 ++--- Marlin/src/HAL/DUE/HAL.h | 10 ++------ Marlin/src/HAL/LPC1768/HAL.h | 10 ++------ Marlin/src/HAL/SAMD51/HAL.h | 10 ++------ Marlin/src/HAL/STM32/HAL.h | 30 +++++----------------- Marlin/src/HAL/STM32F1/HAL.h | 30 +++++++--------------- Marlin/src/HAL/STM32_F4_F7/HAL.h | 6 ----- Marlin/src/HAL/TEENSY40_41/HAL.h | 4 +-- Marlin/src/gcode/config/M575.cpp | 19 +++----------- Marlin/src/inc/SanityCheck.h | 40 ++++++++++++++++++++++++----- Marlin/src/lcd/extui/malyan_lcd.cpp | 8 +----- buildroot/tests/malyan_M300-tests | 2 +- 15 files changed, 76 insertions(+), 132 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index ce767c7b0a85..14d4fa5355bf 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -2167,7 +2167,7 @@ //#define MALYAN_LCD #if ENABLED(MALYAN_LCD) // This will be 1 on a Malyan M200, but may differ on other boards. - #define MALYAN_SERIAL_PORT 1 + #define MALYAN_LCD_SERIAL_PORT 1 #endif // diff --git a/Marlin/src/HAL/AVR/HAL.h b/Marlin/src/HAL/AVR/HAL.h index 9db3c22617b6..04d77c847c10 100644 --- a/Marlin/src/HAL/AVR/HAL.h +++ b/Marlin/src/HAL/AVR/HAL.h @@ -93,8 +93,6 @@ typedef int8_t pin_t; #ifdef SERIAL_PORT_2 #if !WITHIN(SERIAL_PORT_2, -1, 3) #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." - #elif SERIAL_PORT_2 == SERIAL_PORT - #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration." #endif #define MYSERIAL1 customizedSerial2 #define NUM_SERIAL 2 @@ -106,23 +104,14 @@ typedef int8_t pin_t; #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." - #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." #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." - #elif ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT - #error "ANYCUBIC_LCD_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration." - #elif defined(SERIAL_PORT_2) && ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT_2 - #error "ANYCUBIC_LCD_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." #endif #define ANYCUBIC_LCD_SERIAL anycubicLcdSerial #endif diff --git a/Marlin/src/HAL/AVR/MarlinSerial.cpp b/Marlin/src/HAL/AVR/MarlinSerial.cpp index 3d44a3f59ffc..838627001d14 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.cpp +++ b/Marlin/src/HAL/AVR/MarlinSerial.cpp @@ -712,11 +712,11 @@ } // Hookup ISR handlers - ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_RX_vect)) { + ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _RX_vect)) { MarlinSerial>::store_rxd_char(); } - ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_UDRE_vect)) { + ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _UDRE_vect)) { MarlinSerial>::_tx_udr_empty_irq(); } @@ -729,11 +729,11 @@ #ifdef SERIAL_PORT_2 // Hookup ISR handlers - ISR(SERIAL_REGNAME(USART,SERIAL_PORT_2,_RX_vect)) { + ISR(SERIAL_REGNAME(USART, SERIAL_PORT_2, _RX_vect)) { MarlinSerial>::store_rxd_char(); } - ISR(SERIAL_REGNAME(USART,SERIAL_PORT_2,_UDRE_vect)) { + ISR(SERIAL_REGNAME(USART, SERIAL_PORT_2, _UDRE_vect)) { MarlinSerial>::_tx_udr_empty_irq(); } @@ -749,11 +749,11 @@ #ifdef INTERNAL_SERIAL_PORT - ISR(SERIAL_REGNAME(USART,INTERNAL_SERIAL_PORT,_RX_vect)) { + ISR(SERIAL_REGNAME(USART, INTERNAL_SERIAL_PORT, _RX_vect)) { MarlinSerial>::store_rxd_char(); } - ISR(SERIAL_REGNAME(USART,INTERNAL_SERIAL_PORT,_UDRE_vect)) { + ISR(SERIAL_REGNAME(USART, INTERNAL_SERIAL_PORT, _UDRE_vect)) { MarlinSerial>::_tx_udr_empty_irq(); } @@ -776,11 +776,11 @@ return ret; } - ISR(SERIAL_REGNAME(USART,DGUS_SERIAL_PORT,_RX_vect)) { + ISR(SERIAL_REGNAME(USART, DGUS_SERIAL_PORT, _RX_vect)) { MarlinSerial>::store_rxd_char(); } - ISR(SERIAL_REGNAME(USART,DGUS_SERIAL_PORT,_UDRE_vect)) { + ISR(SERIAL_REGNAME(USART, DGUS_SERIAL_PORT, _UDRE_vect)) { MarlinSerial>::_tx_udr_empty_irq(); } @@ -794,11 +794,11 @@ #ifdef ANYCUBIC_LCD_SERIAL_PORT - ISR(SERIAL_REGNAME(USART,ANYCUBIC_LCD_SERIAL_PORT,_RX_vect)) { + ISR(SERIAL_REGNAME(USART, ANYCUBIC_LCD_SERIAL_PORT, _RX_vect)) { MarlinSerial>::store_rxd_char(); } - ISR(SERIAL_REGNAME(USART,ANYCUBIC_LCD_SERIAL_PORT,_UDRE_vect)) { + ISR(SERIAL_REGNAME(USART, ANYCUBIC_LCD_SERIAL_PORT, _UDRE_vect)) { MarlinSerial>::_tx_udr_empty_irq(); } diff --git a/Marlin/src/HAL/AVR/MarlinSerial.h b/Marlin/src/HAL/AVR/MarlinSerial.h index e8bfc5583a91..8dbed4d85be4 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.h +++ b/Marlin/src/HAL/AVR/MarlinSerial.h @@ -48,11 +48,11 @@ // These are macros to build serial port register names for the selected SERIAL_PORT (C preprocessor // requires two levels of indirection to expand macro values properly) - #define SERIAL_REGNAME(registerbase,number,suffix) SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) + #define SERIAL_REGNAME(registerbase,number,suffix) _SERIAL_REGNAME(registerbase,number,suffix) #if SERIAL_PORT == 0 && (!defined(UBRR0H) || !defined(UDR0)) // use un-numbered registers if necessary - #define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##suffix + #define _SERIAL_REGNAME(registerbase,number,suffix) registerbase##suffix #else - #define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##number##suffix + #define _SERIAL_REGNAME(registerbase,number,suffix) registerbase##number##suffix #endif // Registers used by MarlinSerial class (expanded depending on selected serial port) diff --git a/Marlin/src/HAL/DUE/HAL.h b/Marlin/src/HAL/DUE/HAL.h index 9b20b7363ac4..8eb8d2aa122c 100644 --- a/Marlin/src/HAL/DUE/HAL.h +++ b/Marlin/src/HAL/DUE/HAL.h @@ -52,9 +52,7 @@ #endif #ifdef SERIAL_PORT_2 - #if SERIAL_PORT_2 == SERIAL_PORT - #error "SERIAL_PORT_2 must be different from SERIAL_PORT. Please update your configuration." - #elif SERIAL_PORT_2 == -1 || ENABLED(EMERGENCY_PARSER) + #if SERIAL_PORT_2 == -1 || ENABLED(EMERGENCY_PARSER) #define MYSERIAL1 customizedSerial2 #elif WITHIN(SERIAL_PORT_2, 0, 3) #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) @@ -67,11 +65,7 @@ #endif #ifdef DGUS_SERIAL_PORT - #if DGUS_SERIAL_PORT == SERIAL_PORT - #error "DGUS_SERIAL_PORT must be different from 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 + #if DGUS_SERIAL_PORT == -1 #define DGUS_SERIAL internalDgusSerial #elif WITHIN(DGUS_SERIAL_PORT, 0, 3) #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) diff --git a/Marlin/src/HAL/LPC1768/HAL.h b/Marlin/src/HAL/LPC1768/HAL.h index 7ddad121ae4a..5dd0cd040937 100644 --- a/Marlin/src/HAL/LPC1768/HAL.h +++ b/Marlin/src/HAL/LPC1768/HAL.h @@ -76,9 +76,7 @@ extern "C" volatile uint32_t _millis; #endif #ifdef SERIAL_PORT_2 - #if 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 WITHIN(SERIAL_PORT_2, 0, 3) #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) @@ -91,11 +89,7 @@ extern "C" volatile uint32_t _millis; #endif #ifdef DGUS_SERIAL_PORT - #if 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 + #if DGUS_SERIAL_PORT == -1 #define DGUS_SERIAL UsbSerial #elif WITHIN(DGUS_SERIAL_PORT, 0, 3) #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) diff --git a/Marlin/src/HAL/SAMD51/HAL.h b/Marlin/src/HAL/SAMD51/HAL.h index 7b1b693eadcb..dc7eb16d681a 100644 --- a/Marlin/src/HAL/SAMD51/HAL.h +++ b/Marlin/src/HAL/SAMD51/HAL.h @@ -47,9 +47,7 @@ #endif #ifdef SERIAL_PORT_2 - #if 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 Serial #elif WITHIN(SERIAL_PORT_2, 0, 3) #define MYSERIAL0 MSERIAL(SERIAL_PORT_2) @@ -62,11 +60,7 @@ #endif #ifdef DGUS_SERIAL_PORT - #if 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 + #if DGUS_SERIAL_PORT == -1 #define DGUS_SERIAL Serial #elif WITHIN(DGUS_SERIAL_PORT, 0, 3) #define MYSERIAL0 MSERIAL(DGUS_SERIAL_PORT) diff --git a/Marlin/src/HAL/STM32/HAL.h b/Marlin/src/HAL/STM32/HAL.h index 46a538118ace..9435f37556a4 100644 --- a/Marlin/src/HAL/STM32/HAL.h +++ b/Marlin/src/HAL/STM32/HAL.h @@ -56,9 +56,7 @@ #ifdef SERIAL_PORT_2 #define NUM_SERIAL 2 - #if 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 SerialUSB #elif WITHIN(SERIAL_PORT_2, 1, 6) #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) @@ -71,37 +69,23 @@ #if HAS_DGUS_LCD - #if 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 + #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) - #define _FRAMEWORK_SERIAL(X) Serial##X - #define FRAMEWORK_SERIAL(X) _FRAMEWORK_SERIAL(X) - - #ifndef MALYAN_SERIAL_PORT - #error "MALYAN_LCD requires MALYAN_SERIAL_PORT to be defined in Configuration.h" - #elif MALYAN_SERIAL_PORT == SERIAL_PORT - #error "MALYAN_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration." - #elif defined(SERIAL_PORT_2) && MALYAN_SERIAL_PORT == SERIAL_PORT_2 - #error "MALYAN_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." - #elif defined(DGUS_SERIAL) && MALYAN_SERIAL_PORT == DGUS_SERIAL_PORT - #error "MALYAN_SERIAL_PORT must be different than DGUS_SERIAL_PORT. Please update your configuration." - #elif WITHIN(MALYAN_SERIAL_PORT, 1, 6) - #define MALYAN_LCD_SERIAL FRAMEWORK_SERIAL(MALYAN_SERIAL_PORT) + #if MALYAN_LCD_SERIAL_PORT == -1 + #define MALYAN_LCD_SERIAL SerialUSB + #elif WITHIN(MALYAN_LCD_SERIAL_PORT, 1, 6) + #define MALYAN_LCD_SERIAL MSERIAL(MALYAN_LCD_SERIAL_PORT) #else - #error "MALYAN_SERIAL_PORT must be from 1 to 6. Please update your configuration." + #error "MALYAN_LCD_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration." #endif #endif diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h index 6c9d98c4e7d5..415184e1c26b 100644 --- a/Marlin/src/HAL/STM32F1/HAL.h +++ b/Marlin/src/HAL/STM32F1/HAL.h @@ -88,9 +88,7 @@ #endif #ifdef SERIAL_PORT_2 - #if 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 WITHIN(SERIAL_PORT_2, 1, NUM_UARTS) #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) @@ -105,11 +103,7 @@ #endif #ifdef DGUS_SERIAL_PORT - #if 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 + #if DGUS_SERIAL_PORT == -1 #define DGUS_SERIAL UsbSerial #elif WITHIN(DGUS_SERIAL_PORT, 1, NUM_UARTS) #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) @@ -120,21 +114,15 @@ #endif #endif -#if ENABLED(MALYAN_LCD) - #ifndef MALYAN_SERIAL_PORT - #error "MALYAN_LCD requires MALYAN_SERIAL_PORT to be defined in Configuration.h" - #elif MALYAN_SERIAL_PORT == SERIAL_PORT - #error "MALYAN_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration." - #elif defined(SERIAL_PORT_2) && MALYAN_SERIAL_PORT == SERIAL_PORT_2 - #error "MALYAN_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." - #elif defined(DGUS_SERIAL) && MALYAN_SERIAL_PORT == DGUS_SERIAL_PORT - #error "MALYAN_SERIAL_PORT must be different than DGUS_SERIAL_PORT. Please update your configuration." - #elif WITHIN(MALYAN_SERIAL_PORT, 1, NUM_UARTS) - #define MALYAN_LCD_SERIAL MSERIAL(MALYAN_SERIAL_PORT) +#if ENABLED(MALYAN_LCD_SERIAL_PORT) + #if MALYAN_LCD_SERIAL_PORT == -1 + #define MALYAN_LCD_SERIAL UsbSerial + #if WITHIN(MALYAN_LCD_SERIAL_PORT, 1, NUM_UARTS) + #define MALYAN_LCD_SERIAL MSERIAL(MALYAN_LCD_SERIAL_PORT) #elif NUM_UARTS == 5 - #error "MALYAN_SERIAL_PORT must be from 1 to 5. Please update your configuration." + #error "MALYAN_LCD_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration." #else - #error "MALYAN_SERIAL_PORT must be from 1 to 3. Please update your configuration." + #error "MALYAN_LCD_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration." #endif #endif diff --git a/Marlin/src/HAL/STM32_F4_F7/HAL.h b/Marlin/src/HAL/STM32_F4_F7/HAL.h index 0f686c1c853e..dc46d49ca027 100644 --- a/Marlin/src/HAL/STM32_F4_F7/HAL.h +++ b/Marlin/src/HAL/STM32_F4_F7/HAL.h @@ -63,8 +63,6 @@ #ifdef SERIAL_PORT_2 #if defined(STM32F4) && 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 #define MYSERIAL1 SerialUSB #elif WITHIN(SERIAL_PORT_2, 0, 6) @@ -80,10 +78,6 @@ #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 == 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 SerialUSB #elif WITHIN(DGUS_SERIAL_PORT, 0, 6) diff --git a/Marlin/src/HAL/TEENSY40_41/HAL.h b/Marlin/src/HAL/TEENSY40_41/HAL.h index 2e0a7c049787..cbb32a6b5190 100644 --- a/Marlin/src/HAL/TEENSY40_41/HAL.h +++ b/Marlin/src/HAL/TEENSY40_41/HAL.h @@ -63,9 +63,7 @@ #endif #ifdef SERIAL_PORT_2 - #if SERIAL_PORT_2 == SERIAL_PORT - #error "SERIAL_PORT_2 must be different from SERIAL_PORT. Please update your configuration." - #elif SERIAL_PORT_2 == -1 + #if SERIAL_PORT_2 == -1 #define MYSERIAL1 usbSerial #elif WITHIN(SERIAL_PORT_2, 0, 8) #define MYSERIAL0 MSERIAL(SERIAL_PORT_2) diff --git a/Marlin/src/gcode/config/M575.cpp b/Marlin/src/gcode/config/M575.cpp index 3aa5844653c2..44723b7f2fe6 100644 --- a/Marlin/src/gcode/config/M575.cpp +++ b/Marlin/src/gcode/config/M575.cpp @@ -53,23 +53,10 @@ void GcodeSuite::M575() { case 115200: case 250000: case 500000: case 1000000: { const int8_t port = parser.intval('P', -99); const bool set0 = (port == -99 || port == 0); - if (set0) { - SERIAL_ECHO_START(); - SERIAL_ECHOLNPAIR(" Serial " - #if HAS_MULTI_SERIAL - , '0', - #else - "0" - #endif - " baud rate set to ", baud - ); - } + if (set0) SERIAL_ECHO_MSG(" Serial ", '0', " baud rate set to ", baud); #if HAS_MULTI_SERIAL const bool set1 = (port == -99 || port == 1); - if (set1) { - SERIAL_ECHO_START(); - SERIAL_ECHOLNPAIR(" Serial ", '1', " baud rate set to ", baud); - } + if (set1) SERIAL_ECHO_MSG(" Serial ", '1', " baud rate set to ", baud); #endif SERIAL_FLUSH(); @@ -85,4 +72,4 @@ void GcodeSuite::M575() { } } -#endif // NUM_SERIAL > 0 && BAUD_RATE_GCODE +#endif // BAUD_RATE_GCODE diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index c6149050814c..d32bca5a0400 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -582,12 +582,10 @@ #error "SERIAL_XON_XOFF and SERIAL_STATS_* features not supported on USB-native AVR devices." #endif -#if SERIAL_PORT > 7 - #error "Set SERIAL_PORT to the port on your board. Usually this is 0." -#endif - -#if defined(SERIAL_PORT_2) && NUM_SERIAL < 2 - #error "SERIAL_PORT_2 is not supported for your MOTHERBOARD. Disable it to continue." +#ifndef SERIAL_PORT + #error "SERIAL_PORT must be defined in Configuration.h" +#elif defined(SERIAL_PORT_2) && SERIAL_PORT_2 == SERIAL_PORT + #error "SERIAL_PORT_2 cannot be the same as SERIAL_PORT. Please update your configuration." #endif /** @@ -2280,6 +2278,36 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal #error "Please enable only one LCD_SCREEN_ROT_* option: 0, 90, 180, or 270." #endif +/** + * 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 MALYAN_LCD_SERIAL_PORT + #error "MALYAN_LCD requires MALYAN_LCD_SERIAL_PORT to be defined in Configuration.h" + #elif MALYAN_LCD_SERIAL_PORT == SERIAL_PORT + #error "MALYAN_LCD_SERIAL_PORT cannot be the same as SERIAL_PORT. Please update your configuration." + #elif defined(SERIAL_PORT_2) && MALYAN_LCD_SERIAL_PORT == SERIAL_PORT_2 + #error "MALYAN_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." + #endif + #define ANYCUBIC_LCD_SERIAL anycubicLcdSerial +#endif + /** * FYSETC Mini 12864 RGB backlighting required */ diff --git a/Marlin/src/lcd/extui/malyan_lcd.cpp b/Marlin/src/lcd/extui/malyan_lcd.cpp index 32833f2a547f..01b9a9c3ce4f 100644 --- a/Marlin/src/lcd/extui/malyan_lcd.cpp +++ b/Marlin/src/lcd/extui/malyan_lcd.cpp @@ -45,7 +45,7 @@ #if ENABLED(MALYAN_LCD) -#define DEBUG_MALYAN_LCD +//#define DEBUG_MALYAN_LCD #include "ui_api.h" @@ -61,12 +61,6 @@ #define DEBUG_OUT ENABLED(DEBUG_MALYAN_LCD) #include "../../core/debug_out.h" -// On the Malyan M200, this will be Serial1. On a RAMPS board, -// it might not be. -#ifndef MALYAN_LCD_SERIAL - #error "Must define MALYAN_SERIAL_PORT in Configuration.h to use MALYAN_LCD" -#endif - // This is based on longest sys command + a filename, plus some buffer // in case we encounter some data we don't recognize // There is no evidence a line will ever be this long, but better safe than sorry diff --git a/buildroot/tests/malyan_M300-tests b/buildroot/tests/malyan_M300-tests index 06c08d3a6c98..8b41114470eb 100755 --- a/buildroot/tests/malyan_M300-tests +++ b/buildroot/tests/malyan_M300-tests @@ -9,7 +9,7 @@ set -e restore_configs use_example_configs "delta/Malyan M300" opt_disable AUTO_BED_LEVELING_3POINT -opt_set MALYAN_SERIAL_PORT 1 +opt_set MALYAN_LCD_SERIAL_PORT 1 exec_test $1 $2 "Malyan M300 (delta)" # cleanup From 678799cda12a9f88d88453799eec6d33e228cd1f Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 18:42:25 -0500 Subject: [PATCH 11/33] Macro patch --- Marlin/src/HAL/LPC1768/HAL.h | 2 +- Marlin/src/HAL/LPC1768/inc/SanityCheck.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/HAL/LPC1768/HAL.h b/Marlin/src/HAL/LPC1768/HAL.h index 5dd0cd040937..c7764dcaa5f1 100644 --- a/Marlin/src/HAL/LPC1768/HAL.h +++ b/Marlin/src/HAL/LPC1768/HAL.h @@ -63,7 +63,7 @@ extern "C" volatile uint32_t _millis; #define ST7920_DELAY_3 DELAY_NS(750) #endif -#define _MSERIAL(X) Serial##X +#define _MSERIAL(X) MSerial##X #define MSERIAL(X) _MSERIAL(X) #define MSerial0 MSerial diff --git a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h index 52dcf1784f72..22d91e2bd75d 100644 --- a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h +++ b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h @@ -148,7 +148,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o #error "Serial port pins (2) conflict with Y endstop pin!" #elif HAS_CUSTOM_PROBE_PIN && IS_TX2(Z_MIN_PROBE_PIN) #error "Serial port pins (2) conflict with probe pin!" - #elif ANY_TX2(X_ENABLE_PIN, Y_ENABLE_PIN) || ANY_RX(2, X_DIR_PIN, Y_DIR_PIN) + #elif ANY_TX(2, X_ENABLE_PIN, Y_ENABLE_PIN) || ANY_RX(2, X_DIR_PIN, Y_DIR_PIN) #error "Serial port pins (2) conflict with X/Y stepper pins!" #elif HAS_MULTI_EXTRUDER && (IS_TX2(E1_ENABLE_PIN) || (AXIS_HAS_SPI(E1) && IS_TX2(E1_CS_PIN))) #error "Serial port pins (2) conflict with E1 stepper pins!" From 19abe2432e59f61f74642b8c5232e0d29e03f56e Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 18:43:52 -0500 Subject: [PATCH 12/33] prep for redo --- Marlin/src/HAL/STM32/HAL.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Marlin/src/HAL/STM32/HAL.h b/Marlin/src/HAL/STM32/HAL.h index 9435f37556a4..dae819a7921e 100644 --- a/Marlin/src/HAL/STM32/HAL.h +++ b/Marlin/src/HAL/STM32/HAL.h @@ -67,7 +67,6 @@ #define NUM_SERIAL 1 #endif - #if HAS_DGUS_LCD #if DGUS_SERIAL_PORT == -1 #define DGUS_SERIAL SerialUSB From 5cc87f9c3df6285921d7f1fe14327939c020cd87 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 18:52:16 -0500 Subject: [PATCH 13/33] Define NUM_SERIAL once --- Marlin/src/HAL/AVR/HAL.h | 4 ---- Marlin/src/HAL/DUE/HAL.h | 3 --- Marlin/src/HAL/ESP32/HAL.h | 3 --- Marlin/src/HAL/HAL.h | 6 ++++++ Marlin/src/HAL/LINUX/HAL.h | 1 - Marlin/src/HAL/LPC1768/HAL.h | 3 --- Marlin/src/HAL/SAMD51/HAL.h | 3 --- Marlin/src/HAL/STM32/HAL.h | 3 --- Marlin/src/HAL/STM32F1/HAL.h | 3 --- Marlin/src/HAL/STM32_F4_F7/HAL.h | 3 --- Marlin/src/HAL/TEENSY31_32/HAL.h | 2 -- Marlin/src/HAL/TEENSY35_36/HAL.h | 2 -- Marlin/src/HAL/TEENSY40_41/HAL.h | 3 --- Marlin/src/MarlinCore.cpp | 18 ++++++++---------- 14 files changed, 14 insertions(+), 43 deletions(-) diff --git a/Marlin/src/HAL/AVR/HAL.h b/Marlin/src/HAL/AVR/HAL.h index 04d77c847c10..fcaaf75c4a9e 100644 --- a/Marlin/src/HAL/AVR/HAL.h +++ b/Marlin/src/HAL/AVR/HAL.h @@ -82,7 +82,6 @@ typedef int8_t pin_t; // Serial ports #ifdef USBCON #define MYSERIAL0 TERN(BLUETOOTH, bluetoothSerial, Serial) - #define NUM_SERIAL 1 #else #if !WITHIN(SERIAL_PORT, -1, 3) #error "SERIAL_PORT must be from -1 to 3. Please update your configuration." @@ -95,9 +94,6 @@ typedef int8_t pin_t; #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." #endif #define MYSERIAL1 customizedSerial2 - #define NUM_SERIAL 2 - #else - #define NUM_SERIAL 1 #endif #endif diff --git a/Marlin/src/HAL/DUE/HAL.h b/Marlin/src/HAL/DUE/HAL.h index 8eb8d2aa122c..974f1ccc1649 100644 --- a/Marlin/src/HAL/DUE/HAL.h +++ b/Marlin/src/HAL/DUE/HAL.h @@ -59,9 +59,6 @@ #else #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." #endif - #define NUM_SERIAL 2 -#else - #define NUM_SERIAL 1 #endif #ifdef DGUS_SERIAL_PORT diff --git a/Marlin/src/HAL/ESP32/HAL.h b/Marlin/src/HAL/ESP32/HAL.h index c91f9efff0b9..5eb84fdc3021 100644 --- a/Marlin/src/HAL/ESP32/HAL.h +++ b/Marlin/src/HAL/ESP32/HAL.h @@ -58,9 +58,6 @@ extern portMUX_TYPE spinlock; #else #define MYSERIAL1 webSocketSerial #endif - #define NUM_SERIAL 2 -#else - #define NUM_SERIAL 1 #endif #define CRITICAL_SECTION_START() portENTER_CRITICAL(&spinlock) diff --git a/Marlin/src/HAL/HAL.h b/Marlin/src/HAL/HAL.h index c7b7531442db..8b6a978d2103 100644 --- a/Marlin/src/HAL/HAL.h +++ b/Marlin/src/HAL/HAL.h @@ -25,6 +25,12 @@ #include HAL_PATH(.,HAL.h) +#ifdef SERIAL_PORT_2 + #define NUM_SERIAL 2 +#else + #define NUM_SERIAL 1 +#endif + #define HAL_ADC_RANGE _BV(HAL_ADC_RESOLUTION) #ifndef I2C_ADDRESS diff --git a/Marlin/src/HAL/LINUX/HAL.h b/Marlin/src/HAL/LINUX/HAL.h index 96e121d9153e..778ba2db4d71 100644 --- a/Marlin/src/HAL/LINUX/HAL.h +++ b/Marlin/src/HAL/LINUX/HAL.h @@ -62,7 +62,6 @@ uint8_t _getc(); extern HalSerial usb_serial; #define MYSERIAL0 usb_serial -#define NUM_SERIAL 1 #define ST7920_DELAY_1 DELAY_NS(600) #define ST7920_DELAY_2 DELAY_NS(750) diff --git a/Marlin/src/HAL/LPC1768/HAL.h b/Marlin/src/HAL/LPC1768/HAL.h index c7764dcaa5f1..e9f05fcc617d 100644 --- a/Marlin/src/HAL/LPC1768/HAL.h +++ b/Marlin/src/HAL/LPC1768/HAL.h @@ -83,9 +83,6 @@ extern "C" volatile uint32_t _millis; #else #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." #endif - #define NUM_SERIAL 2 -#else - #define NUM_SERIAL 1 #endif #ifdef DGUS_SERIAL_PORT diff --git a/Marlin/src/HAL/SAMD51/HAL.h b/Marlin/src/HAL/SAMD51/HAL.h index dc7eb16d681a..b516cb769fb3 100644 --- a/Marlin/src/HAL/SAMD51/HAL.h +++ b/Marlin/src/HAL/SAMD51/HAL.h @@ -54,9 +54,6 @@ #else #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." #endif - #define NUM_SERIAL 2 - #else - #define NUM_SERIAL 1 #endif #ifdef DGUS_SERIAL_PORT diff --git a/Marlin/src/HAL/STM32/HAL.h b/Marlin/src/HAL/STM32/HAL.h index dae819a7921e..38605684a1fc 100644 --- a/Marlin/src/HAL/STM32/HAL.h +++ b/Marlin/src/HAL/STM32/HAL.h @@ -55,7 +55,6 @@ #endif #ifdef SERIAL_PORT_2 - #define NUM_SERIAL 2 #if SERIAL_PORT_2 == -1 #define MYSERIAL1 SerialUSB #elif WITHIN(SERIAL_PORT_2, 1, 6) @@ -63,8 +62,6 @@ #else #error "SERIAL_PORT_2 must be -1 or from 1 to 6. Please update your configuration." #endif -#else - #define NUM_SERIAL 1 #endif #if HAS_DGUS_LCD diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h index 415184e1c26b..8d4b0dee2780 100644 --- a/Marlin/src/HAL/STM32F1/HAL.h +++ b/Marlin/src/HAL/STM32F1/HAL.h @@ -97,9 +97,6 @@ #else #error "SERIAL_PORT_2 must be -1 or from 1 to 3. Please update your configuration." #endif - #define NUM_SERIAL 2 -#else - #define NUM_SERIAL 1 #endif #ifdef DGUS_SERIAL_PORT diff --git a/Marlin/src/HAL/STM32_F4_F7/HAL.h b/Marlin/src/HAL/STM32_F4_F7/HAL.h index dc46d49ca027..e132168205bb 100644 --- a/Marlin/src/HAL/STM32_F4_F7/HAL.h +++ b/Marlin/src/HAL/STM32_F4_F7/HAL.h @@ -70,9 +70,6 @@ #else #error "SERIAL_PORT_2 must be from -1 to 6. Please update your configuration." #endif - #define NUM_SERIAL 2 -#else - #define NUM_SERIAL 1 #endif #ifdef DGUS_SERIAL_PORT diff --git a/Marlin/src/HAL/TEENSY31_32/HAL.h b/Marlin/src/HAL/TEENSY31_32/HAL.h index 737579b25cc3..31ceb8b87c9a 100644 --- a/Marlin/src/HAL/TEENSY31_32/HAL.h +++ b/Marlin/src/HAL/TEENSY31_32/HAL.h @@ -49,8 +49,6 @@ #define IS_TEENSY32 1 #endif -#define NUM_SERIAL 1 - #define _MSERIAL(X) Serial##X #define MSERIAL(X) _MSERIAL(X) #define Serial0 Serial diff --git a/Marlin/src/HAL/TEENSY35_36/HAL.h b/Marlin/src/HAL/TEENSY35_36/HAL.h index 75541d6f2a66..11f0fb941e93 100644 --- a/Marlin/src/HAL/TEENSY35_36/HAL.h +++ b/Marlin/src/HAL/TEENSY35_36/HAL.h @@ -54,8 +54,6 @@ #define IS_TEENSY36 1 #endif -#define NUM_SERIAL 1 - #define _MSERIAL(X) Serial##X #define MSERIAL(X) _MSERIAL(X) #define Serial0 Serial diff --git a/Marlin/src/HAL/TEENSY40_41/HAL.h b/Marlin/src/HAL/TEENSY40_41/HAL.h index cbb32a6b5190..77f7af295668 100644 --- a/Marlin/src/HAL/TEENSY40_41/HAL.h +++ b/Marlin/src/HAL/TEENSY40_41/HAL.h @@ -70,9 +70,6 @@ #else #error "SERIAL_PORT_2 must be from -1 to 8. Please update your configuration." #endif - #define NUM_SERIAL 2 -#else - #define NUM_SERIAL 1 #endif #define HAL_SERVO_LIB libServo diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 22935c146073..e11439861bd4 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -912,17 +912,15 @@ void setup() { #endif #endif - #if NUM_SERIAL > 0 - MYSERIAL0.begin(BAUDRATE); - uint32_t serial_connect_timeout = millis() + 1000UL; - while (!MYSERIAL0 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } - #if HAS_MULTI_SERIAL - MYSERIAL1.begin(BAUDRATE); - serial_connect_timeout = millis() + 1000UL; - while (!MYSERIAL1 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } - #endif - SERIAL_ECHO_MSG("start"); + MYSERIAL0.begin(BAUDRATE); + uint32_t serial_connect_timeout = millis() + 1000UL; + while (!MYSERIAL0 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } + #if HAS_MULTI_SERIAL + MYSERIAL1.begin(BAUDRATE); + serial_connect_timeout = millis() + 1000UL; + while (!MYSERIAL1 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } #endif + SERIAL_ECHO_MSG("start"); #if BOTH(HAS_TFT_LVGL_UI, USE_WIFI_FUNCTION) mks_esp_wifi_init(); From 2d4d58225b4c322fa594b62772636b59e20ae2cb Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 18:56:19 -0500 Subject: [PATCH 14/33] keep feet on ground --- Marlin/src/HAL/LPC1768/MarlinSerial.cpp | 2 +- Marlin/src/HAL/LPC1768/inc/SanityCheck.h | 2 +- Marlin/src/core/macros.h | 7 ++----- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Marlin/src/HAL/LPC1768/MarlinSerial.cpp b/Marlin/src/HAL/LPC1768/MarlinSerial.cpp index 6df5147e34da..c9bca3be96ac 100644 --- a/Marlin/src/HAL/LPC1768/MarlinSerial.cpp +++ b/Marlin/src/HAL/LPC1768/MarlinSerial.cpp @@ -24,7 +24,7 @@ #include "../../inc/MarlinConfigPre.h" #include "MarlinSerial.h" -#if ANY_ZERO(SERIAL_PORT, SERIAL_PORT_2, DGUS_SERIAL_PORT) +#if IS_ZERO(SERIAL_PORT) || IS_ZERO(SERIAL_PORT_2) || IS_ZERO(DGUS_SERIAL_PORT) MarlinSerial MSerial(LPC_UART0); extern "C" void UART0_IRQHandler() { MSerial.IRQHandler(); diff --git a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h index 22d91e2bd75d..303d70bc434a 100644 --- a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h +++ b/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 ANY_ZERO(SERIAL_PORT, SERIAL_PORT_2, DGUS_SERIAL_PORT) +#if IS_ZERO(SERIAL_PORT) || IS_ZERO(SERIAL_PORT_2) || IS_ZERO(DGUS_SERIAL_PORT) #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) diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h index 4a99c32e3602..89e05fb4cb99 100644 --- a/Marlin/src/core/macros.h +++ b/Marlin/src/core/macros.h @@ -201,11 +201,8 @@ #define BOTH(V1,V2) ALL(V1,V2) #define EITHER(V1,V2) ANY(V1,V2) -// Macros to test for '0' settings -#define SET_ZERO(D) (defined(D) && D == 0) -#define _ISZER_1 SET_ZERO -#define ALL_ZERO(V...) DO(ISZER,&&,V) -#define ANY_ZERO(V...) DO(ISZER,||,V) +// Test for a '0' setting +#define IS_ZERO(D) (defined(D) && D == 0) // Macros to support pins/buttons exist testing #define PIN_EXISTS(PN) (defined(PN##_PIN) && PN##_PIN >= 0) From f16388b61515552560a5fea824aa819e751bfead Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 19:00:24 -0500 Subject: [PATCH 15/33] etc --- Marlin/src/HAL/LPC1768/MarlinSerial.cpp | 2 +- Marlin/src/HAL/LPC1768/inc/SanityCheck.h | 2 +- Marlin/src/core/macros.h | 3 --- Marlin/src/inc/SanityCheck.h | 2 +- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Marlin/src/HAL/LPC1768/MarlinSerial.cpp b/Marlin/src/HAL/LPC1768/MarlinSerial.cpp index c9bca3be96ac..c3fb3bd0e4d2 100644 --- a/Marlin/src/HAL/LPC1768/MarlinSerial.cpp +++ b/Marlin/src/HAL/LPC1768/MarlinSerial.cpp @@ -24,7 +24,7 @@ #include "../../inc/MarlinConfigPre.h" #include "MarlinSerial.h" -#if IS_ZERO(SERIAL_PORT) || IS_ZERO(SERIAL_PORT_2) || IS_ZERO(DGUS_SERIAL_PORT) +#if (defined(SERIAL_PORT) && SERIAL_PORT == 0) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == 0) || (defined(DGUS_SERIAL_PORT) && DGUS_SERIAL_PORT == 0) MarlinSerial MSerial(LPC_UART0); extern "C" void UART0_IRQHandler() { MSerial.IRQHandler(); diff --git a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h index 303d70bc434a..2ca8a29da4c6 100644 --- a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h +++ b/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 IS_ZERO(SERIAL_PORT) || IS_ZERO(SERIAL_PORT_2) || IS_ZERO(DGUS_SERIAL_PORT) +#if (defined(SERIAL_PORT) && SERIAL_PORT == 0) || (defined(SERIAL_PORT_2) && SERIAL_PORT_2 == 0) || (defined(DGUS_SERIAL_PORT) && DGUS_SERIAL_PORT == 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) diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h index 89e05fb4cb99..5fc1081019b5 100644 --- a/Marlin/src/core/macros.h +++ b/Marlin/src/core/macros.h @@ -201,9 +201,6 @@ #define BOTH(V1,V2) ALL(V1,V2) #define EITHER(V1,V2) ANY(V1,V2) -// Test for a '0' setting -#define IS_ZERO(D) (defined(D) && D == 0) - // Macros to support pins/buttons exist testing #define PIN_EXISTS(PN) (defined(PN##_PIN) && PN##_PIN >= 0) #define _PINEX_1 PIN_EXISTS diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index d32bca5a0400..c34fb3c951e8 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -395,7 +395,7 @@ #error "PARKING_EXTRUDER_SECURITY_RAISE is now TOOLCHANGE_ZRAISE. Please update your configuration." #elif defined(SWITCHING_TOOLHEAD_SECURITY_RAISE) #error "SWITCHING_TOOLHEAD_SECURITY_RAISE is now TOOLCHANGE_ZRAISE. Please update your configuration." -#elif SET_ZERO(G0_FEEDRATE) +#elif defined(G0_FEEDRATE) && G0_FEEDRATE == 0 #error "G0_FEEDRATE is now used to set the G0 feedrate. Please update your configuration." #elif defined(MBL_Z_STEP) #error "MBL_Z_STEP is now MESH_EDIT_Z_STEP. Please update your configuration." From 804d1b1015ed048372fd5ecfea470bfb8e4b2817 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 19:21:42 -0500 Subject: [PATCH 16/33] Update Configuration.h --- Marlin/Configuration.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 14d4fa5355bf..c1a9f248e500 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -2166,8 +2166,7 @@ // //#define MALYAN_LCD #if ENABLED(MALYAN_LCD) - // This will be 1 on a Malyan M200, but may differ on other boards. - #define MALYAN_LCD_SERIAL_PORT 1 + #define MALYAN_LCD_SERIAL_PORT 1 // Default is 1 for Malyan M200 #endif // From d6035bcb4e8246e4c717780e56b84d645cc708f5 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 19:20:24 -0500 Subject: [PATCH 17/33] HAL and serial cleanup --- Marlin/src/HAL/AVR/HAL.h | 21 +---- Marlin/src/HAL/AVR/MarlinSerial.cpp | 20 ++--- Marlin/src/HAL/AVR/MarlinSerial.h | 6 +- Marlin/src/HAL/DUE/HAL.h | 47 +++-------- Marlin/src/HAL/ESP32/HAL.h | 3 - Marlin/src/HAL/HAL.h | 6 ++ Marlin/src/HAL/LINUX/HAL.h | 1 - Marlin/src/HAL/LPC1768/HAL.h | 47 +++-------- Marlin/src/HAL/LPC1768/inc/SanityCheck.h | 37 ++++++--- Marlin/src/HAL/SAMD51/HAL.h | 46 +++-------- Marlin/src/HAL/STM32/HAL.h | 81 ++++++------------- Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h | 2 +- Marlin/src/HAL/STM32F1/HAL.h | 5 +- Marlin/src/HAL/STM32F1/MarlinSerial.h | 1 + Marlin/src/HAL/STM32F1/sdio.cpp | 2 +- Marlin/src/HAL/STM32_F4_F7/HAL.h | 61 +++----------- Marlin/src/HAL/TEENSY31_32/HAL.h | 14 ++-- Marlin/src/HAL/TEENSY35_36/HAL.h | 14 ++-- Marlin/src/HAL/TEENSY40_41/HAL.h | 51 +++--------- Marlin/src/MarlinCore.cpp | 18 ++--- Marlin/src/gcode/config/M575.cpp | 19 +---- Marlin/src/inc/SanityCheck.h | 40 +++++++-- Marlin/src/lcd/extui/malyan_lcd.cpp | 2 +- Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h | 8 +- .../pins/stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h | 8 +- .../pins/stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h | 8 +- Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h | 8 +- Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h | 16 ++-- .../pins/stm32f1/pins_MKS_ROBIN_E3_common.h | 8 +- .../src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h | 16 ++-- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h | 17 ++-- 31 files changed, 218 insertions(+), 415 deletions(-) diff --git a/Marlin/src/HAL/AVR/HAL.h b/Marlin/src/HAL/AVR/HAL.h index 609375e386e8..fcaaf75c4a9e 100644 --- a/Marlin/src/HAL/AVR/HAL.h +++ b/Marlin/src/HAL/AVR/HAL.h @@ -81,12 +81,7 @@ typedef int8_t pin_t; // Serial ports #ifdef USBCON - #if ENABLED(BLUETOOTH) - #define MYSERIAL0 bluetoothSerial - #else - #define MYSERIAL0 Serial - #endif - #define NUM_SERIAL 1 + #define MYSERIAL0 TERN(BLUETOOTH, bluetoothSerial, Serial) #else #if !WITHIN(SERIAL_PORT, -1, 3) #error "SERIAL_PORT must be from -1 to 3. Please update your configuration." @@ -97,36 +92,22 @@ typedef int8_t pin_t; #ifdef SERIAL_PORT_2 #if !WITHIN(SERIAL_PORT_2, -1, 3) #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." - #elif SERIAL_PORT_2 == SERIAL_PORT - #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration." #endif #define MYSERIAL1 customizedSerial2 - #define NUM_SERIAL 2 - #else - #define NUM_SERIAL 1 #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." - #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." #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." - #elif ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT - #error "ANYCUBIC_LCD_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration." - #elif defined(SERIAL_PORT_2) && ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT_2 - #error "ANYCUBIC_LCD_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration." #endif #define ANYCUBIC_LCD_SERIAL anycubicLcdSerial #endif diff --git a/Marlin/src/HAL/AVR/MarlinSerial.cpp b/Marlin/src/HAL/AVR/MarlinSerial.cpp index 3d44a3f59ffc..838627001d14 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.cpp +++ b/Marlin/src/HAL/AVR/MarlinSerial.cpp @@ -712,11 +712,11 @@ } // Hookup ISR handlers - ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_RX_vect)) { + ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _RX_vect)) { MarlinSerial>::store_rxd_char(); } - ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_UDRE_vect)) { + ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _UDRE_vect)) { MarlinSerial>::_tx_udr_empty_irq(); } @@ -729,11 +729,11 @@ #ifdef SERIAL_PORT_2 // Hookup ISR handlers - ISR(SERIAL_REGNAME(USART,SERIAL_PORT_2,_RX_vect)) { + ISR(SERIAL_REGNAME(USART, SERIAL_PORT_2, _RX_vect)) { MarlinSerial>::store_rxd_char(); } - ISR(SERIAL_REGNAME(USART,SERIAL_PORT_2,_UDRE_vect)) { + ISR(SERIAL_REGNAME(USART, SERIAL_PORT_2, _UDRE_vect)) { MarlinSerial>::_tx_udr_empty_irq(); } @@ -749,11 +749,11 @@ #ifdef INTERNAL_SERIAL_PORT - ISR(SERIAL_REGNAME(USART,INTERNAL_SERIAL_PORT,_RX_vect)) { + ISR(SERIAL_REGNAME(USART, INTERNAL_SERIAL_PORT, _RX_vect)) { MarlinSerial>::store_rxd_char(); } - ISR(SERIAL_REGNAME(USART,INTERNAL_SERIAL_PORT,_UDRE_vect)) { + ISR(SERIAL_REGNAME(USART, INTERNAL_SERIAL_PORT, _UDRE_vect)) { MarlinSerial>::_tx_udr_empty_irq(); } @@ -776,11 +776,11 @@ return ret; } - ISR(SERIAL_REGNAME(USART,DGUS_SERIAL_PORT,_RX_vect)) { + ISR(SERIAL_REGNAME(USART, DGUS_SERIAL_PORT, _RX_vect)) { MarlinSerial>::store_rxd_char(); } - ISR(SERIAL_REGNAME(USART,DGUS_SERIAL_PORT,_UDRE_vect)) { + ISR(SERIAL_REGNAME(USART, DGUS_SERIAL_PORT, _UDRE_vect)) { MarlinSerial>::_tx_udr_empty_irq(); } @@ -794,11 +794,11 @@ #ifdef ANYCUBIC_LCD_SERIAL_PORT - ISR(SERIAL_REGNAME(USART,ANYCUBIC_LCD_SERIAL_PORT,_RX_vect)) { + ISR(SERIAL_REGNAME(USART, ANYCUBIC_LCD_SERIAL_PORT, _RX_vect)) { MarlinSerial>::store_rxd_char(); } - ISR(SERIAL_REGNAME(USART,ANYCUBIC_LCD_SERIAL_PORT,_UDRE_vect)) { + ISR(SERIAL_REGNAME(USART, ANYCUBIC_LCD_SERIAL_PORT, _UDRE_vect)) { MarlinSerial>::_tx_udr_empty_irq(); } diff --git a/Marlin/src/HAL/AVR/MarlinSerial.h b/Marlin/src/HAL/AVR/MarlinSerial.h index e8bfc5583a91..8dbed4d85be4 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.h +++ b/Marlin/src/HAL/AVR/MarlinSerial.h @@ -48,11 +48,11 @@ // These are macros to build serial port register names for the selected SERIAL_PORT (C preprocessor // requires two levels of indirection to expand macro values properly) - #define SERIAL_REGNAME(registerbase,number,suffix) SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) + #define SERIAL_REGNAME(registerbase,number,suffix) _SERIAL_REGNAME(registerbase,number,suffix) #if SERIAL_PORT == 0 && (!defined(UBRR0H) || !defined(UDR0)) // use un-numbered registers if necessary - #define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##suffix + #define _SERIAL_REGNAME(registerbase,number,suffix) registerbase##suffix #else - #define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##number##suffix + #define _SERIAL_REGNAME(registerbase,number,suffix) registerbase##number##suffix #endif // Registers used by MarlinSerial class (expanded depending on selected serial port) diff --git a/Marlin/src/HAL/DUE/HAL.h b/Marlin/src/HAL/DUE/HAL.h index 31409c76dd56..974f1ccc1649 100644 --- a/Marlin/src/HAL/DUE/HAL.h +++ b/Marlin/src/HAL/DUE/HAL.h @@ -38,57 +38,34 @@ #include +#define _MSERIAL(X) Serial##X +#define MSERIAL(X) _MSERIAL(X) +#define Serial0 Serial + // Define MYSERIAL0/1 before MarlinSerial includes! #if SERIAL_PORT == -1 || ENABLED(EMERGENCY_PARSER) #define MYSERIAL0 customizedSerial1 -#elif SERIAL_PORT == 0 - #define MYSERIAL0 Serial -#elif SERIAL_PORT == 1 - #define MYSERIAL0 Serial1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 Serial2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 Serial3 +#elif WITHIN(SERIAL_PORT, 0, 3) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #else #error "The required SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif #ifdef SERIAL_PORT_2 - #if SERIAL_PORT_2 == SERIAL_PORT - #error "SERIAL_PORT_2 must be different from SERIAL_PORT. Please update your configuration." - #elif SERIAL_PORT_2 == -1 || ENABLED(EMERGENCY_PARSER) + #if SERIAL_PORT_2 == -1 || ENABLED(EMERGENCY_PARSER) #define MYSERIAL1 customizedSerial2 - #elif SERIAL_PORT_2 == 0 - #define MYSERIAL1 Serial - #elif SERIAL_PORT_2 == 1 - #define MYSERIAL1 Serial1 - #elif SERIAL_PORT_2 == 2 - #define MYSERIAL1 Serial2 - #elif SERIAL_PORT_2 == 3 - #define MYSERIAL1 Serial3 + #elif WITHIN(SERIAL_PORT_2, 0, 3) + #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #else #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." #endif - #define NUM_SERIAL 2 -#else - #define NUM_SERIAL 1 #endif #ifdef DGUS_SERIAL_PORT - #if DGUS_SERIAL_PORT == SERIAL_PORT - #error "DGUS_SERIAL_PORT must be different from 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 + #if DGUS_SERIAL_PORT == -1 #define DGUS_SERIAL internalDgusSerial - #elif DGUS_SERIAL_PORT == 0 - #define DGUS_SERIAL Serial - #elif DGUS_SERIAL_PORT == 1 - #define DGUS_SERIAL Serial1 - #elif DGUS_SERIAL_PORT == 2 - #define DGUS_SERIAL Serial2 - #elif DGUS_SERIAL_PORT == 3 - #define DGUS_SERIAL Serial3 + #elif WITHIN(DGUS_SERIAL_PORT, 0, 3) + #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) #else #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif diff --git a/Marlin/src/HAL/ESP32/HAL.h b/Marlin/src/HAL/ESP32/HAL.h index c91f9efff0b9..5eb84fdc3021 100644 --- a/Marlin/src/HAL/ESP32/HAL.h +++ b/Marlin/src/HAL/ESP32/HAL.h @@ -58,9 +58,6 @@ extern portMUX_TYPE spinlock; #else #define MYSERIAL1 webSocketSerial #endif - #define NUM_SERIAL 2 -#else - #define NUM_SERIAL 1 #endif #define CRITICAL_SECTION_START() portENTER_CRITICAL(&spinlock) diff --git a/Marlin/src/HAL/HAL.h b/Marlin/src/HAL/HAL.h index c7b7531442db..8b6a978d2103 100644 --- a/Marlin/src/HAL/HAL.h +++ b/Marlin/src/HAL/HAL.h @@ -25,6 +25,12 @@ #include HAL_PATH(.,HAL.h) +#ifdef SERIAL_PORT_2 + #define NUM_SERIAL 2 +#else + #define NUM_SERIAL 1 +#endif + #define HAL_ADC_RANGE _BV(HAL_ADC_RESOLUTION) #ifndef I2C_ADDRESS diff --git a/Marlin/src/HAL/LINUX/HAL.h b/Marlin/src/HAL/LINUX/HAL.h index 96e121d9153e..778ba2db4d71 100644 --- a/Marlin/src/HAL/LINUX/HAL.h +++ b/Marlin/src/HAL/LINUX/HAL.h @@ -62,7 +62,6 @@ uint8_t _getc(); extern HalSerial usb_serial; #define MYSERIAL0 usb_serial -#define NUM_SERIAL 1 #define ST7920_DELAY_1 DELAY_NS(600) #define ST7920_DELAY_2 DELAY_NS(750) diff --git a/Marlin/src/HAL/LPC1768/HAL.h b/Marlin/src/HAL/LPC1768/HAL.h index 0153bacf42dd..e9f05fcc617d 100644 --- a/Marlin/src/HAL/LPC1768/HAL.h +++ b/Marlin/src/HAL/LPC1768/HAL.h @@ -63,56 +63,33 @@ extern "C" volatile uint32_t _millis; #define ST7920_DELAY_3 DELAY_NS(750) #endif +#define _MSERIAL(X) MSerial##X +#define MSERIAL(X) _MSERIAL(X) +#define MSerial0 MSerial + #if SERIAL_PORT == -1 #define MYSERIAL0 UsbSerial -#elif SERIAL_PORT == 0 - #define MYSERIAL0 MSerial -#elif SERIAL_PORT == 1 - #define MYSERIAL0 MSerial1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 MSerial2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 MSerial3 +#elif WITHIN(SERIAL_PORT, 0, 3) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #else #error "SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif #ifdef SERIAL_PORT_2 - #if 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 == 0 - #define MYSERIAL1 MSerial - #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 WITHIN(SERIAL_PORT_2, 0, 3) + #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #else #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." #endif - #define NUM_SERIAL 2 -#else - #define NUM_SERIAL 1 #endif #ifdef DGUS_SERIAL_PORT - #if 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 + #if DGUS_SERIAL_PORT == -1 #define DGUS_SERIAL UsbSerial - #elif DGUS_SERIAL_PORT == 0 - #define DGUS_SERIAL MSerial - #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 WITHIN(DGUS_SERIAL_PORT, 0, 3) + #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) #else #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif diff --git a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h index 3fc1dd801a45..2ca8a29da4c6 100644 --- a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h +++ b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h @@ -89,6 +89,9 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o * Serial2 | P0_10 | P0_11 | * Serial3 | P0_00 | P0_01 | */ +#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) #define IS_TX0(P) (P == P0_02) #define IS_RX0(P) (P == P0_03) @@ -106,48 +109,56 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o #if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1 || DGUS_SERIAL_PORT == 1 #define IS_TX1(P) (P == P0_15) #define IS_RX1(P) (P == P0_16) + #define _IS_TX1_1 IS_TX1 + #define _IS_RX1_1 IS_RX1 #if IS_TX1(TMC_SW_SCK) #error "Serial port pins (1) conflict with other pins!" #elif HAS_SPI_LCD #if IS_TX1(BTN_EN2) || IS_RX1(BTN_EN1) #error "Serial port pins (1) conflict with Encoder Buttons!" - #elif IS_TX1(SCK_PIN) || IS_TX1(LCD_PINS_D4) || IS_TX1(DOGLCD_SCK) || IS_TX1(LCD_RESET_PIN) || IS_TX1(LCD_PINS_RS) || IS_TX1(SHIFT_CLK) \ - || IS_RX1(LCD_SDSS) || IS_RX1(LCD_PINS_RS) || IS_RX1(MISO_PIN) || IS_RX1(DOGLCD_A0) || IS_RX1(SS_PIN) || IS_RX1(LCD_SDSS) || IS_RX1(DOGLCD_CS) || IS_RX1(LCD_RESET_PIN) || IS_RX1(LCD_BACKLIGHT_PIN) + #elif ANY_TX(1, SCK_PIN, LCD_PINS_D4, DOGLCD_SCK, LCD_RESET_PIN, LCD_PINS_RS, SHIFT_CLK) \ + || ANY_RX(1, LCD_SDSS, LCD_PINS_RS, MISO_PIN, DOGLCD_A0, SS_PIN, LCD_SDSS, DOGLCD_CS, LCD_RESET_PIN, LCD_BACKLIGHT_PIN) #error "Serial port pins (1) conflict with LCD pins!" #endif #endif #undef IS_TX1 #undef IS_RX1 + #undef _IS_TX1_1 + #undef _IS_RX1_1 #endif #if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2 || DGUS_SERIAL_PORT == 2 #define IS_TX2(P) (P == P0_10) #define IS_RX2(P) (P == P0_11) - #if IS_TX2(X2_ENABLE_PIN) || IS_RX2(X2_DIR_PIN) || IS_RX2(X2_STEP_PIN) || (AXIS_HAS_SPI(X2) && IS_TX2(X2_CS_PIN)) + #define _IS_TX2_1 IS_TX2 + #define _IS_RX2_1 IS_RX2 + #if IS_TX2(X2_ENABLE_PIN) || ANY_RX(2, X2_DIR_PIN, X2_STEP_PIN) || (AXIS_HAS_SPI(X2) && IS_TX2(X2_CS_PIN)) #error "Serial port pins (2) conflict with X2 pins!" - #elif IS_TX2(Y2_ENABLE_PIN) || IS_RX2(Y2_DIR_PIN) || IS_RX2(Y2_STEP_PIN) || (AXIS_HAS_SPI(Y2) && IS_TX2(Y2_CS_PIN)) + #elif IS_TX2(Y2_ENABLE_PIN) || ANY_RX(2, Y2_DIR_PIN, Y2_STEP_PIN) || (AXIS_HAS_SPI(Y2) && IS_TX2(Y2_CS_PIN)) #error "Serial port pins (2) conflict with Y2 pins!" - #elif IS_TX2(Z2_ENABLE_PIN) || IS_RX2(Z2_DIR_PIN) || IS_RX2(Z2_STEP_PIN) || (AXIS_HAS_SPI(Z2) && IS_TX2(Z2_CS_PIN)) + #elif IS_TX2(Z2_ENABLE_PIN) || ANY_RX(2, Z2_DIR_PIN, Z2_STEP_PIN) || (AXIS_HAS_SPI(Z2) && IS_TX2(Z2_CS_PIN)) #error "Serial port pins (2) conflict with Z2 pins!" - #elif IS_TX2(Z3_ENABLE_PIN) || IS_RX2(Z3_DIR_PIN) || IS_RX2(Z3_STEP_PIN) || (AXIS_HAS_SPI(Z3) && IS_TX2(Z3_CS_PIN)) + #elif IS_TX2(Z3_ENABLE_PIN) || ANY_RX(2, Z3_DIR_PIN, Z3_STEP_PIN) || (AXIS_HAS_SPI(Z3) && IS_TX2(Z3_CS_PIN)) #error "Serial port pins (2) conflict with Z3 pins!" - #elif IS_TX2(Z4_ENABLE_PIN) || IS_RX2(Z4_DIR_PIN) || IS_RX2(Z4_STEP_PIN) || (AXIS_HAS_SPI(Z4) && IS_TX2(Z4_CS_PIN)) + #elif IS_TX2(Z4_ENABLE_PIN) || ANY_RX(2, Z4_DIR_PIN, Z4_STEP_PIN) || (AXIS_HAS_SPI(Z4) && IS_TX2(Z4_CS_PIN)) #error "Serial port pins (2) conflict with Z4 pins!" - #elif IS_RX2(X_DIR_PIN) || IS_RX2(Y_DIR_PIN) + #elif ANY_RX(2, X_DIR_PIN, Y_DIR_PIN) #error "Serial port pins (2) conflict with other pins!" #elif Y_HOME_DIR < 0 && IS_TX2(Y_STOP_PIN) #error "Serial port pins (2) conflict with Y endstop pin!" #elif HAS_CUSTOM_PROBE_PIN && IS_TX2(Z_MIN_PROBE_PIN) #error "Serial port pins (2) conflict with probe pin!" - #elif IS_TX2(X_ENABLE_PIN) || IS_RX2(X_DIR_PIN) || IS_TX2(Y_ENABLE_PIN) || IS_RX2(Y_DIR_PIN) + #elif ANY_TX(2, X_ENABLE_PIN, Y_ENABLE_PIN) || ANY_RX(2, X_DIR_PIN, Y_DIR_PIN) #error "Serial port pins (2) conflict with X/Y stepper pins!" #elif HAS_MULTI_EXTRUDER && (IS_TX2(E1_ENABLE_PIN) || (AXIS_HAS_SPI(E1) && IS_TX2(E1_CS_PIN))) #error "Serial port pins (2) conflict with E1 stepper pins!" - #elif EXTRUDERS && (IS_RX2(E0_DIR_PIN) || IS_RX2(E0_STEP_PIN)) + #elif EXTRUDERS && ANY_RX(2, E0_DIR_PIN, E0_STEP_PIN) #error "Serial port pins (2) conflict with E stepper pins!" #endif #undef IS_TX2 #undef IS_RX2 + #undef _IS_TX2_1 + #undef _IS_RX2_1 #endif #if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3 || DGUS_SERIAL_PORT == 3 @@ -155,8 +166,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o #define PIN_IS_RX3(P) (P##_PIN == P0_01) #if PIN_IS_TX3(X_MIN) || PIN_IS_RX3(X_MAX) #error "Serial port pins (3) conflict with X endstop pins!" - #elif PIN_IS_TX3(Y_SERIAL_TX) || PIN_IS_TX3(Y_SERIAL_RX) \ - || PIN_IS_RX3(X_SERIAL_TX) || PIN_IS_RX3(X_SERIAL_RX) + #elif PIN_IS_TX3(Y_SERIAL_TX) || PIN_IS_TX3(Y_SERIAL_RX) || PIN_IS_RX3(X_SERIAL_TX) || PIN_IS_RX3(X_SERIAL_RX) #error "Serial port pins (3) conflict with X/Y axis UART pins!" #elif PIN_IS_TX3(X2_DIR) || PIN_IS_RX3(X2_STEP) #error "Serial port pins (3) conflict with X2 pins!" @@ -175,6 +185,9 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o #undef PIN_IS_RX3 #endif +#undef ANY_TX +#undef ANY_RX + // // Flag any i2c pin conflicts // diff --git a/Marlin/src/HAL/SAMD51/HAL.h b/Marlin/src/HAL/SAMD51/HAL.h index ea0f694cdc02..b516cb769fb3 100644 --- a/Marlin/src/HAL/SAMD51/HAL.h +++ b/Marlin/src/HAL/SAMD51/HAL.h @@ -35,56 +35,32 @@ // MYSERIAL0 required before MarlinSerial includes! + #define _MSERIAL(X) Serial##X + #define MSERIAL(X) _MSERIAL(INCREMENT(X)) + #if SERIAL_PORT == -1 #define MYSERIAL0 Serial - #elif SERIAL_PORT == 0 - #define MYSERIAL0 Serial1 - #elif SERIAL_PORT == 1 - #define MYSERIAL0 Serial2 - #elif SERIAL_PORT == 2 - #define MYSERIAL0 Serial3 - #elif SERIAL_PORT == 3 - #define MYSERIAL0 Serial4 + #elif WITHIN(SERIAL_PORT, 0, 3) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #else #error "SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif #ifdef SERIAL_PORT_2 - #if 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 Serial - #elif SERIAL_PORT_2 == 0 - #define MYSERIAL1 Serial1 - #elif SERIAL_PORT_2 == 1 - #define MYSERIAL1 Serial2 - #elif SERIAL_PORT_2 == 2 - #define MYSERIAL1 Serial3 - #elif SERIAL_PORT_2 == 3 - #define MYSERIAL1 Serial4 + #elif WITHIN(SERIAL_PORT_2, 0, 3) + #define MYSERIAL0 MSERIAL(SERIAL_PORT_2) #else #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." #endif - #define NUM_SERIAL 2 - #else - #define NUM_SERIAL 1 #endif #ifdef DGUS_SERIAL_PORT - #if 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 + #if DGUS_SERIAL_PORT == -1 #define DGUS_SERIAL Serial - #elif DGUS_SERIAL_PORT == 0 - #define DGUS_SERIAL Serial1 - #elif DGUS_SERIAL_PORT == 1 - #define DGUS_SERIAL Serial2 - #elif DGUS_SERIAL_PORT == 2 - #define DGUS_SERIAL Serial3 - #elif DGUS_SERIAL_PORT == 2 - #define DGUS_SERIAL Serial4 + #elif WITHIN(DGUS_SERIAL_PORT, 0, 3) + #define MYSERIAL0 MSERIAL(DGUS_SERIAL_PORT) #else #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif diff --git a/Marlin/src/HAL/STM32/HAL.h b/Marlin/src/HAL/STM32/HAL.h index 08081331b736..9ec2d5c19e83 100644 --- a/Marlin/src/HAL/STM32/HAL.h +++ b/Marlin/src/HAL/STM32/HAL.h @@ -43,82 +43,47 @@ // ------------------------ // Defines // ------------------------ +#define _MSERIAL(X) MSerial##X +#define MSERIAL(X) _MSERIAL(X) -#if SERIAL_PORT == 0 - #error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration." -#elif SERIAL_PORT == -1 +#if SERIAL_PORT == -1 #define MYSERIAL0 SerialUSB -#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 SERIAL_PORT == 6 - #define MYSERIAL0 MSerial6 +#elif WITHIN(SERIAL_PORT, 1, 6) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #else - #error "SERIAL_PORT must be from -1 to 6. Please update your configuration." + #error "SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration." #endif #ifdef SERIAL_PORT_2 - #define NUM_SERIAL 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 SerialUSB - #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 SERIAL_PORT_2 == 6 - #define MYSERIAL1 MSerial6 + #elif WITHIN(SERIAL_PORT_2, 1, 6) + #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #else - #error "SERIAL_PORT_2 must be from -1 to 6. Please update your configuration." + #error "SERIAL_PORT_2 must be -1 or from 1 to 6. Please update your configuration." #endif -#else - #define NUM_SERIAL 1 #endif #if HAS_DGUS_LCD - #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 + #if DGUS_SERIAL_PORT == -1 #define DGUS_SERIAL SerialUSB - #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 - #elif DGUS_SERIAL_PORT == 6 - #define DGUS_SERIAL MSerial6 + #elif WITHIN(DGUS_SERIAL_PORT, 1, 6) + #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) #else - #error "DGUS_SERIAL_PORT must be from -1 to 6. Please update your configuration." + #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 + #define LCD_SERIAL SerialUSB + #elif WITHIN(LCD_SERIAL_PORT, 1, 6) + #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT) + #else + #error "LCD_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration." + #endif +#endif /** * TODO: review this to return 1 for pins that are not analog input diff --git a/Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h b/Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h index 5ff40debea5e..9069d9f7bd8a 100644 --- a/Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h +++ b/Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h @@ -98,7 +98,7 @@ static inline void pwm_details(const pin_t pin) { timer_dev * const tdev = PIN_MAP[pin].timer_device; const uint8_t channel = PIN_MAP[pin].timer_channel; const char num = ( - #if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) + #if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY) tdev == &timer8 ? '8' : tdev == &timer5 ? '5' : #endif diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h index f76d8c54a0e3..47414cb45e10 100644 --- a/Marlin/src/HAL/STM32F1/HAL.h +++ b/Marlin/src/HAL/STM32F1/HAL.h @@ -53,7 +53,7 @@ // ------------------------ #ifndef STM32_FLASH_SIZE - #if defined(MCU_STM32F103RE) || defined(MCU_STM32F103VE) + #if EITHER(MCU_STM32F103RE, MCU_STM32F103VE) #define STM32_FLASH_SIZE 512 #else #define STM32_FLASH_SIZE 256 @@ -106,9 +106,6 @@ #else #error "SERIAL_PORT_2 must be from -1 to 5. Please update your configuration." #endif - #define NUM_SERIAL 2 -#else - #define NUM_SERIAL 1 #endif #ifdef DGUS_SERIAL diff --git a/Marlin/src/HAL/STM32F1/MarlinSerial.h b/Marlin/src/HAL/STM32F1/MarlinSerial.h index eb0059bfbcae..b9248e50caff 100644 --- a/Marlin/src/HAL/STM32F1/MarlinSerial.h +++ b/Marlin/src/HAL/STM32F1/MarlinSerial.h @@ -30,6 +30,7 @@ #include "../../feature/e_parser.h" #endif +// Increase priority of serial interrupts, to reduce overflow errors #define UART_IRQ_PRIO 1 class MarlinSerial : public HardwareSerial { diff --git a/Marlin/src/HAL/STM32F1/sdio.cpp b/Marlin/src/HAL/STM32F1/sdio.cpp index 0e9a3b2d0450..ffa6db1206ae 100644 --- a/Marlin/src/HAL/STM32F1/sdio.cpp +++ b/Marlin/src/HAL/STM32F1/sdio.cpp @@ -26,7 +26,7 @@ #include "../../inc/MarlinConfig.h" // Allow pins/pins.h to set density -#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY) +#if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY) #include "sdio.h" diff --git a/Marlin/src/HAL/STM32_F4_F7/HAL.h b/Marlin/src/HAL/STM32_F4_F7/HAL.h index 5601400c5ac9..e132168205bb 100644 --- a/Marlin/src/HAL/STM32_F4_F7/HAL.h +++ b/Marlin/src/HAL/STM32_F4_F7/HAL.h @@ -46,24 +46,16 @@ // Serial override //extern HalSerial usb_serial; +#define _MSERIAL(X) SerialUART##X +#define MSERIAL(X) _MSERIAL(X) +#define SerialUART0 Serial1 + #if defined(STM32F4) && SERIAL_PORT == 0 #error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration." #elif SERIAL_PORT == -1 #define MYSERIAL0 SerialUSB -#elif SERIAL_PORT == 0 - #define MYSERIAL0 Serial1 -#elif SERIAL_PORT == 1 - #define MYSERIAL0 SerialUART1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 SerialUART2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 SerialUART3 -#elif SERIAL_PORT == 4 - #define MYSERIAL0 SerialUART4 -#elif SERIAL_PORT == 5 - #define MYSERIAL0 SerialUART5 -#elif SERIAL_PORT == 6 - #define MYSERIAL0 SerialUART6 +#elif WITHIN(SERIAL_PORT, 0, 6) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #else #error "SERIAL_PORT must be from -1 to 6. Please update your configuration." #endif @@ -71,55 +63,22 @@ #ifdef SERIAL_PORT_2 #if defined(STM32F4) && 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 #define MYSERIAL1 SerialUSB - #elif SERIAL_PORT_2 == 0 - #define MYSERIAL1 Serial1 - #elif SERIAL_PORT_2 == 1 - #define MYSERIAL1 SerialUART1 - #elif SERIAL_PORT_2 == 2 - #define MYSERIAL1 SerialUART2 - #elif SERIAL_PORT_2 == 3 - #define MYSERIAL1 SerialUART3 - #elif SERIAL_PORT_2 == 4 - #define MYSERIAL1 SerialUART4 - #elif SERIAL_PORT_2 == 5 - #define MYSERIAL1 SerialUART5 - #elif SERIAL_PORT_2 == 6 - #define MYSERIAL1 SerialUART6 + #elif WITHIN(SERIAL_PORT_2, 0, 6) + #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #else #error "SERIAL_PORT_2 must be from -1 to 6. Please update your configuration." #endif - #define NUM_SERIAL 2 -#else - #define NUM_SERIAL 1 #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 == 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 SerialUSB - #elif DGUS_SERIAL_PORT == 0 - #define DGUS_SERIAL Serial1 - #elif DGUS_SERIAL_PORT == 1 - #define DGUS_SERIAL SerialUART1 - #elif DGUS_SERIAL_PORT == 2 - #define DGUS_SERIAL SerialUART2 - #elif DGUS_SERIAL_PORT == 3 - #define DGUS_SERIAL SerialUART3 - #elif DGUS_SERIAL_PORT == 4 - #define DGUS_SERIAL SerialUART4 - #elif DGUS_SERIAL_PORT == 5 - #define DGUS_SERIAL SerialUART5 - #elif DGUS_SERIAL_PORT == 6 - #define DGUS_SERIAL SerialUART6 + #elif WITHIN(DGUS_SERIAL_PORT, 0, 6) + #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT) #else #error "DGUS_SERIAL_PORT must be from -1 to 6. Please update your configuration." #endif diff --git a/Marlin/src/HAL/TEENSY31_32/HAL.h b/Marlin/src/HAL/TEENSY31_32/HAL.h index ad095cba83cc..31ceb8b87c9a 100644 --- a/Marlin/src/HAL/TEENSY31_32/HAL.h +++ b/Marlin/src/HAL/TEENSY31_32/HAL.h @@ -49,18 +49,14 @@ #define IS_TEENSY32 1 #endif -#define NUM_SERIAL 1 +#define _MSERIAL(X) Serial##X +#define MSERIAL(X) _MSERIAL(X) +#define Serial0 Serial #if SERIAL_PORT == -1 #define MYSERIAL0 SerialUSB -#elif SERIAL_PORT == 0 - #define MYSERIAL0 Serial -#elif SERIAL_PORT == 1 - #define MYSERIAL0 Serial1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 Serial2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 Serial3 +#elif WITHIN(SERIAL_PORT, 0, 3) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #endif #define HAL_SERVO_LIB libServo diff --git a/Marlin/src/HAL/TEENSY35_36/HAL.h b/Marlin/src/HAL/TEENSY35_36/HAL.h index 96be08d7b7ca..11f0fb941e93 100644 --- a/Marlin/src/HAL/TEENSY35_36/HAL.h +++ b/Marlin/src/HAL/TEENSY35_36/HAL.h @@ -54,18 +54,14 @@ #define IS_TEENSY36 1 #endif -#define NUM_SERIAL 1 +#define _MSERIAL(X) Serial##X +#define MSERIAL(X) _MSERIAL(X) +#define Serial0 Serial #if SERIAL_PORT == -1 #define MYSERIAL0 SerialUSB -#elif SERIAL_PORT == 0 - #define MYSERIAL0 Serial -#elif SERIAL_PORT == 1 - #define MYSERIAL0 Serial1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 Serial2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 Serial3 +#elif WITHIN(SERIAL_PORT, 0, 3) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #endif #define HAL_SERVO_LIB libServo diff --git a/Marlin/src/HAL/TEENSY40_41/HAL.h b/Marlin/src/HAL/TEENSY40_41/HAL.h index 0626d4ee9cda..77f7af295668 100644 --- a/Marlin/src/HAL/TEENSY40_41/HAL.h +++ b/Marlin/src/HAL/TEENSY40_41/HAL.h @@ -50,59 +50,26 @@ #define IS_TEENSY41 1 #endif +#define _MSERIAL(X) Serial##X +#define MSERIAL(X) _MSERIAL(X) +#define Serial0 Serial + #if SERIAL_PORT == -1 #define MYSERIAL0 SerialUSB -#elif SERIAL_PORT == 0 - #define MYSERIAL0 Serial -#elif SERIAL_PORT == 1 - #define MYSERIAL0 Serial1 -#elif SERIAL_PORT == 2 - #define MYSERIAL0 Serial2 -#elif SERIAL_PORT == 3 - #define MYSERIAL0 Serial3 -#elif SERIAL_PORT == 4 - #define MYSERIAL0 Serial4 -#elif SERIAL_PORT == 5 - #define MYSERIAL0 Serial5 -#elif SERIAL_PORT == 6 - #define MYSERIAL0 Serial6 -#elif SERIAL_PORT == 7 - #define MYSERIAL0 Serial7 -#elif SERIAL_PORT == 8 - #define MYSERIAL0 Serial8 +#elif WITHIN(SERIAL_PORT, 0, 8) + #define MYSERIAL0 MSERIAL(SERIAL_PORT) #else #error "The required SERIAL_PORT must be from -1 to 8. Please update your configuration." #endif #ifdef SERIAL_PORT_2 - #if SERIAL_PORT_2 == SERIAL_PORT - #error "SERIAL_PORT_2 must be different from SERIAL_PORT. Please update your configuration." - #elif SERIAL_PORT_2 == -1 + #if SERIAL_PORT_2 == -1 #define MYSERIAL1 usbSerial - #elif SERIAL_PORT_2 == 0 - #define MYSERIAL1 Serial - #elif SERIAL_PORT_2 == 1 - #define MYSERIAL1 Serial1 - #elif SERIAL_PORT_2 == 2 - #define MYSERIAL1 Serial2 - #elif SERIAL_PORT_2 == 3 - #define MYSERIAL1 Serial3 - #elif SERIAL_PORT_2 == 4 - #define MYSERIAL1 Serial4 - #elif SERIAL_PORT_2 == 5 - #define MYSERIAL1 Serial5 - #elif SERIAL_PORT_2 == 6 - #define MYSERIAL1 Serial6 - #elif SERIAL_PORT_2 == 7 - #define MYSERIAL1 Serial7 - #elif SERIAL_PORT_2 == 8 - #define MYSERIAL1 Serial8 + #elif WITHIN(SERIAL_PORT_2, 0, 8) + #define MYSERIAL0 MSERIAL(SERIAL_PORT_2) #else #error "SERIAL_PORT_2 must be from -1 to 8. Please update your configuration." #endif - #define NUM_SERIAL 2 -#else - #define NUM_SERIAL 1 #endif #define HAL_SERVO_LIB libServo diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 22935c146073..e11439861bd4 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -912,17 +912,15 @@ void setup() { #endif #endif - #if NUM_SERIAL > 0 - MYSERIAL0.begin(BAUDRATE); - uint32_t serial_connect_timeout = millis() + 1000UL; - while (!MYSERIAL0 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } - #if HAS_MULTI_SERIAL - MYSERIAL1.begin(BAUDRATE); - serial_connect_timeout = millis() + 1000UL; - while (!MYSERIAL1 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } - #endif - SERIAL_ECHO_MSG("start"); + MYSERIAL0.begin(BAUDRATE); + uint32_t serial_connect_timeout = millis() + 1000UL; + while (!MYSERIAL0 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } + #if HAS_MULTI_SERIAL + MYSERIAL1.begin(BAUDRATE); + serial_connect_timeout = millis() + 1000UL; + while (!MYSERIAL1 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } #endif + SERIAL_ECHO_MSG("start"); #if BOTH(HAS_TFT_LVGL_UI, USE_WIFI_FUNCTION) mks_esp_wifi_init(); diff --git a/Marlin/src/gcode/config/M575.cpp b/Marlin/src/gcode/config/M575.cpp index 3aa5844653c2..44723b7f2fe6 100644 --- a/Marlin/src/gcode/config/M575.cpp +++ b/Marlin/src/gcode/config/M575.cpp @@ -53,23 +53,10 @@ void GcodeSuite::M575() { case 115200: case 250000: case 500000: case 1000000: { const int8_t port = parser.intval('P', -99); const bool set0 = (port == -99 || port == 0); - if (set0) { - SERIAL_ECHO_START(); - SERIAL_ECHOLNPAIR(" Serial " - #if HAS_MULTI_SERIAL - , '0', - #else - "0" - #endif - " baud rate set to ", baud - ); - } + if (set0) SERIAL_ECHO_MSG(" Serial ", '0', " baud rate set to ", baud); #if HAS_MULTI_SERIAL const bool set1 = (port == -99 || port == 1); - if (set1) { - SERIAL_ECHO_START(); - SERIAL_ECHOLNPAIR(" Serial ", '1', " baud rate set to ", baud); - } + if (set1) SERIAL_ECHO_MSG(" Serial ", '1', " baud rate set to ", baud); #endif SERIAL_FLUSH(); @@ -85,4 +72,4 @@ void GcodeSuite::M575() { } } -#endif // NUM_SERIAL > 0 && BAUD_RATE_GCODE +#endif // BAUD_RATE_GCODE diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 8d68b33ece20..4c0b68e8aec0 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -582,12 +582,10 @@ #error "SERIAL_XON_XOFF and SERIAL_STATS_* features not supported on USB-native AVR devices." #endif -#if SERIAL_PORT > 7 - #error "Set SERIAL_PORT to the port on your board. Usually this is 0." -#endif - -#if defined(SERIAL_PORT_2) && NUM_SERIAL < 2 - #error "SERIAL_PORT_2 is not supported for your MOTHERBOARD. Disable it to continue." +#ifndef SERIAL_PORT + #error "SERIAL_PORT must be defined in Configuration.h" +#elif defined(SERIAL_PORT_2) && SERIAL_PORT_2 == SERIAL_PORT + #error "SERIAL_PORT_2 cannot be the same as SERIAL_PORT. Please update your configuration." #endif /** @@ -2280,6 +2278,36 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal #error "Please enable only one LCD_SCREEN_ROT_* option: 0, 90, 180, or 270." #endif +/** + * 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 + #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." + #endif + #define ANYCUBIC_LCD_SERIAL anycubicLcdSerial +#endif + /** * FYSETC Mini 12864 RGB backlighting required */ diff --git a/Marlin/src/lcd/extui/malyan_lcd.cpp b/Marlin/src/lcd/extui/malyan_lcd.cpp index b5148065c7cc..986373f66c51 100644 --- a/Marlin/src/lcd/extui/malyan_lcd.cpp +++ b/Marlin/src/lcd/extui/malyan_lcd.cpp @@ -45,7 +45,7 @@ #if ENABLED(MALYAN_LCD) -#define DEBUG_MALYAN_LCD +//#define DEBUG_MALYAN_LCD #include "ui_api.h" diff --git a/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h b/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h index f018a40c3ef3..a3cb987fff0b 100644 --- a/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h +++ b/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h @@ -117,10 +117,10 @@ * Hardware serial communication ports. * If undefined software serial is used according to the pins below */ - //#define X_HARDWARE_SERIAL Serial1 - //#define Y_HARDWARE_SERIAL Serial1 - //#define Z_HARDWARE_SERIAL Serial1 - //#define E0_HARDWARE_SERIAL Serial1 + //#define X_HARDWARE_SERIAL MSerial1 + //#define Y_HARDWARE_SERIAL MSerial1 + //#define Z_HARDWARE_SERIAL MSerial1 + //#define E0_HARDWARE_SERIAL MSerial1 // // Software serial diff --git a/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h b/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h index b658f3d714b8..78751a6bac87 100644 --- a/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h +++ b/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V1_0.h @@ -30,8 +30,8 @@ * Hardware serial communication ports. */ #if HAS_TMC_UART - #define X_HARDWARE_SERIAL Serial4 - #define Y_HARDWARE_SERIAL Serial4 - #define Z_HARDWARE_SERIAL Serial4 - #define E0_HARDWARE_SERIAL Serial4 + #define X_HARDWARE_SERIAL MSerial4 + #define Y_HARDWARE_SERIAL MSerial4 + #define Z_HARDWARE_SERIAL MSerial4 + #define E0_HARDWARE_SERIAL MSerial4 #endif diff --git a/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h b/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h index cb94f0bdcacd..0a0d857db3f4 100644 --- a/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h +++ b/Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_V2_0.h @@ -52,8 +52,8 @@ * Hardware serial communication ports. */ #if HAS_TMC_UART - #define X_HARDWARE_SERIAL Serial4 - #define Y_HARDWARE_SERIAL Serial4 - #define Z_HARDWARE_SERIAL Serial4 - #define E0_HARDWARE_SERIAL Serial4 + #define X_HARDWARE_SERIAL MSerial4 + #define Y_HARDWARE_SERIAL MSerial4 + #define Z_HARDWARE_SERIAL MSerial4 + #define E0_HARDWARE_SERIAL MSerial4 #endif diff --git a/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h b/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h index b7db592e7809..a04d6d261f8c 100644 --- a/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h +++ b/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h @@ -93,10 +93,10 @@ // // Hardware serial with switch // - #define X_HARDWARE_SERIAL Serial1 - #define Y_HARDWARE_SERIAL Serial1 - #define Z_HARDWARE_SERIAL Serial1 - #define E0_HARDWARE_SERIAL Serial1 + #define X_HARDWARE_SERIAL MSerial1 + #define Y_HARDWARE_SERIAL MSerial1 + #define Z_HARDWARE_SERIAL MSerial1 + #define E0_HARDWARE_SERIAL MSerial1 // The 4xTMC2209 module doesn't have a serial multiplexer and // needs to set *_SLAVE_ADDRESS in Configuration_adv.h for X,Y,Z,E0 diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h index e39c8f234285..48da17adc5a9 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h @@ -188,17 +188,11 @@ * Hardware serial communication ports. * If undefined software serial is used according to the pins below */ - //#define X_HARDWARE_SERIAL Serial1 - //#define X2_HARDWARE_SERIAL Serial1 - //#define Y_HARDWARE_SERIAL Serial1 - //#define Y2_HARDWARE_SERIAL Serial1 - //#define Z_HARDWARE_SERIAL Serial1 - //#define Z2_HARDWARE_SERIAL Serial1 - //#define E0_HARDWARE_SERIAL Serial1 - //#define E1_HARDWARE_SERIAL Serial1 - //#define E2_HARDWARE_SERIAL Serial1 - //#define E3_HARDWARE_SERIAL Serial1 - //#define E4_HARDWARE_SERIAL Serial1 + //#define X_HARDWARE_SERIAL MSerial1 + //#define Y_HARDWARE_SERIAL MSerial1 + //#define Z_HARDWARE_SERIAL MSerial1 + //#define E0_HARDWARE_SERIAL MSerial1 + //#define E1_HARDWARE_SERIAL MSerial1 // Unused servo pins may be repurposed with SoftwareSerialM //#define X_SERIAL_TX_PIN PF8 // SERVO3_PIN -- XS2 - 6 diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h index f6a3b555c399..bbacbf5585d3 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h @@ -83,10 +83,10 @@ * Hardware serial communication ports. * If undefined software serial is used according to the pins below */ - //#define X_HARDWARE_SERIAL Serial1 - //#define Y_HARDWARE_SERIAL Serial1 - //#define Z_HARDWARE_SERIAL Serial1 - //#define E0_HARDWARE_SERIAL Serial1 + //#define X_HARDWARE_SERIAL MSerial1 + //#define Y_HARDWARE_SERIAL MSerial1 + //#define Z_HARDWARE_SERIAL MSerial1 + //#define E0_HARDWARE_SERIAL MSerial1 // // Software serial diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h index ccb07b35f88c..be3b130c858f 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h @@ -132,17 +132,11 @@ * Hardware serial communication ports. * If undefined software serial is used according to the pins below */ - //#define X_HARDWARE_SERIAL Serial1 - //#define X2_HARDWARE_SERIAL Serial1 - //#define Y_HARDWARE_SERIAL Serial1 - //#define Y2_HARDWARE_SERIAL Serial1 - //#define Z_HARDWARE_SERIAL Serial1 - //#define Z2_HARDWARE_SERIAL Serial1 - //#define E0_HARDWARE_SERIAL Serial1 - //#define E1_HARDWARE_SERIAL Serial1 - //#define E2_HARDWARE_SERIAL Serial1 - //#define E3_HARDWARE_SERIAL Serial1 - //#define E4_HARDWARE_SERIAL Serial1 + //#define X_HARDWARE_SERIAL MSerial1 + //#define Y_HARDWARE_SERIAL MSerial1 + //#define Z_HARDWARE_SERIAL MSerial1 + //#define E0_HARDWARE_SERIAL MSerial1 + //#define E1_HARDWARE_SERIAL MSerial1 // // Software serial diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h index 2e74b6b15f2b..e445b8169bb5 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h @@ -125,17 +125,12 @@ * Hardware serial communication ports. * If undefined software serial is used according to the pins below */ - //#define X_HARDWARE_SERIAL Serial1 - //#define X2_HARDWARE_SERIAL Serial1 - //#define Y_HARDWARE_SERIAL Serial1 - //#define Y2_HARDWARE_SERIAL Serial1 - //#define Z_HARDWARE_SERIAL Serial1 - //#define Z2_HARDWARE_SERIAL Serial1 - //#define E0_HARDWARE_SERIAL Serial1 - //#define E1_HARDWARE_SERIAL Serial1 - //#define E2_HARDWARE_SERIAL Serial1 - //#define E3_HARDWARE_SERIAL Serial1 - //#define E4_HARDWARE_SERIAL Serial1 + //#define X_HARDWARE_SERIAL MSerial1 + //#define Y_HARDWARE_SERIAL MSerial1 + //#define Z_HARDWARE_SERIAL MSerial1 + //#define E0_HARDWARE_SERIAL MSerial1 + //#define E1_HARDWARE_SERIAL MSerial1 + //#define E2_HARDWARE_SERIAL MSerial1 // // Software serial From 3732dd89c0466648dee44dbaebf7c577b75490f3 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 19:27:52 -0500 Subject: [PATCH 18/33] typo --- Marlin/src/HAL/STM32F1/HAL.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h index 8d4b0dee2780..e5974ae3ddbe 100644 --- a/Marlin/src/HAL/STM32F1/HAL.h +++ b/Marlin/src/HAL/STM32F1/HAL.h @@ -114,7 +114,7 @@ #if ENABLED(MALYAN_LCD_SERIAL_PORT) #if MALYAN_LCD_SERIAL_PORT == -1 #define MALYAN_LCD_SERIAL UsbSerial - #if WITHIN(MALYAN_LCD_SERIAL_PORT, 1, NUM_UARTS) + #elif WITHIN(MALYAN_LCD_SERIAL_PORT, 1, NUM_UARTS) #define MALYAN_LCD_SERIAL MSERIAL(MALYAN_LCD_SERIAL_PORT) #elif NUM_UARTS == 5 #error "MALYAN_LCD_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration." From d974f7ac477d9759c76631cd9276ccc2145d8517 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 19:32:44 -0500 Subject: [PATCH 19/33] fix test --- Marlin/src/HAL/STM32F1/HAL.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h index e5974ae3ddbe..428aa1d9aa27 100644 --- a/Marlin/src/HAL/STM32F1/HAL.h +++ b/Marlin/src/HAL/STM32F1/HAL.h @@ -111,7 +111,7 @@ #endif #endif -#if ENABLED(MALYAN_LCD_SERIAL_PORT) +#ifdef MALYAN_LCD_SERIAL_PORT #if MALYAN_LCD_SERIAL_PORT == -1 #define MALYAN_LCD_SERIAL UsbSerial #elif WITHIN(MALYAN_LCD_SERIAL_PORT, 1, NUM_UARTS) From e24ee2e6d5e8baa6cf004e9bf4997beba16e61cd Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 21:03:41 -0500 Subject: [PATCH 20/33] Consolidate LCD_SERIAL defines --- Marlin/Configuration.h | 4 +- Marlin/Configuration_adv.h | 10 +-- Marlin/src/HAL/AVR/HAL.h | 17 ++--- Marlin/src/HAL/AVR/MarlinSerial.cpp | 66 +++++++------------ Marlin/src/HAL/AVR/MarlinSerial.h | 65 +++++++++--------- Marlin/src/HAL/DUE/HAL.h | 12 ++-- Marlin/src/HAL/LPC1768/HAL.h | 12 ++-- Marlin/src/HAL/LPC1768/MarlinSerial.cpp | 8 +-- Marlin/src/HAL/LPC1768/inc/SanityCheck.h | 8 +-- Marlin/src/HAL/SAMD51/HAL.h | 12 ++-- Marlin/src/HAL/STM32/HAL.h | 24 +++---- Marlin/src/HAL/STM32/MarlinSerial.cpp | 4 +- Marlin/src/HAL/STM32F1/HAL.h | 28 ++++---- Marlin/src/HAL/STM32F1/MarlinSerial.cpp | 12 ++-- Marlin/src/HAL/STM32_F4_F7/HAL.h | 16 ++--- Marlin/src/inc/Conditionals_adv.h | 34 ++++++++++ Marlin/src/inc/SanityCheck.h | 43 +++++------- Marlin/src/lcd/extui/anycubic_chiron_lcd.cpp | 22 +++---- .../anycubic_i3mega/anycubic_i3mega_lcd.cpp | 20 +++--- Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp | 44 ++++++------- Marlin/src/lcd/extui/malyan_lcd.cpp | 10 +-- buildroot/tests/malyan_M300-tests | 2 +- 22 files changed, 232 insertions(+), 241 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index c1a9f248e500..93e2a0229a71 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -2166,7 +2166,7 @@ // //#define MALYAN_LCD #if ENABLED(MALYAN_LCD) - #define MALYAN_LCD_SERIAL_PORT 1 // Default is 1 for Malyan M200 + #define LCD_SERIAL_PORT 1 // Default is 1 for Malyan M200 #endif // @@ -2181,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 diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 65cbd21a947b..a8c9205538ad 100644 --- a/Marlin/Configuration_adv.h +++ b/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 diff --git a/Marlin/src/HAL/AVR/HAL.h b/Marlin/src/HAL/AVR/HAL.h index fcaaf75c4a9e..790ad872ac0b 100644 --- a/Marlin/src/HAL/AVR/HAL.h +++ b/Marlin/src/HAL/AVR/HAL.h @@ -97,19 +97,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 // ------------------------ diff --git a/Marlin/src/HAL/AVR/MarlinSerial.cpp b/Marlin/src/HAL/AVR/MarlinSerial.cpp index 838627001d14..4d654c0d8082 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.cpp +++ b/Marlin/src/HAL/AVR/MarlinSerial.cpp @@ -747,66 +747,50 @@ #endif // !USBCON && (UBRRH || UBRR0H || UBRR1H || UBRR2H || UBRR3H) -#ifdef INTERNAL_SERIAL_PORT +#ifdef MMU2_SERIAL_PORT - ISR(SERIAL_REGNAME(USART, INTERNAL_SERIAL_PORT, _RX_vect)) { - MarlinSerial>::store_rxd_char(); + ISR(SERIAL_REGNAME(USART, MMU2_SERIAL_PORT, _RX_vect)) { + MarlinSerial>::store_rxd_char(); } - ISR(SERIAL_REGNAME(USART, INTERNAL_SERIAL_PORT, _UDRE_vect)) { - MarlinSerial>::_tx_udr_empty_irq(); + ISR(SERIAL_REGNAME(USART, MMU2_SERIAL_PORT, _UDRE_vect)) { + MarlinSerial>::_tx_udr_empty_irq(); } // Preinstantiate - template class MarlinSerial>; + template class MarlinSerial>; // Instantiate - MarlinSerial> internalSerial; + MarlinSerial> mmuSerial; #endif -#ifdef DGUS_SERIAL_PORT +#ifdef LCD_SERIAL_PORT - template - typename MarlinSerial::ring_buffer_pos_t MarlinSerial::get_tx_buffer_free() { - const ring_buffer_pos_t t = tx_buffer.tail, // next byte to send. - h = tx_buffer.head; // next pos for queue. - int ret = t - h - 1; - if (ret < 0) ret += Cfg::TX_SIZE + 1; - return ret; - } - - ISR(SERIAL_REGNAME(USART, DGUS_SERIAL_PORT, _RX_vect)) { - MarlinSerial>::store_rxd_char(); - } - - ISR(SERIAL_REGNAME(USART, DGUS_SERIAL_PORT, _UDRE_vect)) { - MarlinSerial>::_tx_udr_empty_irq(); - } - - // Preinstantiate - template class MarlinSerial>; - - // Instantiate - MarlinSerial> internalDgusSerial; - -#endif - -#ifdef ANYCUBIC_LCD_SERIAL_PORT - - ISR(SERIAL_REGNAME(USART, ANYCUBIC_LCD_SERIAL_PORT, _RX_vect)) { - MarlinSerial>::store_rxd_char(); + ISR(SERIAL_REGNAME(USART, LCD_SERIAL_PORT, _RX_vect)) { + MarlinSerial>::store_rxd_char(); } - ISR(SERIAL_REGNAME(USART, ANYCUBIC_LCD_SERIAL_PORT, _UDRE_vect)) { - MarlinSerial>::_tx_udr_empty_irq(); + ISR(SERIAL_REGNAME(USART, LCD_SERIAL_PORT, _UDRE_vect)) { + MarlinSerial>::_tx_udr_empty_irq(); } // Preinstantiate - template class MarlinSerial>; + template class MarlinSerial>; // Instantiate - MarlinSerial> anycubicLcdSerial; + MarlinSerial> lcdSerial; + + #if HAS_DGUS_LCD + template + typename MarlinSerial::ring_buffer_pos_t MarlinSerial::get_tx_buffer_free() { + const ring_buffer_pos_t t = tx_buffer.tail, // next byte to send. + h = tx_buffer.head; // next pos for queue. + int ret = t - h - 1; + if (ret < 0) ret += Cfg::TX_SIZE + 1; + return ret; + } + #endif #endif diff --git a/Marlin/src/HAL/AVR/MarlinSerial.h b/Marlin/src/HAL/AVR/MarlinSerial.h index 8dbed4d85be4..3d581cac4bb9 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.h +++ b/Marlin/src/HAL/AVR/MarlinSerial.h @@ -217,7 +217,7 @@ static ring_buffer_pos_t available(); static void write(const uint8_t c); static void flushTX(); - #ifdef DGUS_SERIAL_PORT + #ifdef LCD_SERIAL_PORT static ring_buffer_pos_t get_tx_buffer_free(); #endif @@ -278,55 +278,50 @@ #endif // !USBCON -#ifdef INTERNAL_SERIAL_PORT +#ifdef MMU2_SERIAL_PORT template - 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> internalSerial; + extern MarlinSerial> mmuSerial; #endif -#ifdef DGUS_SERIAL_PORT - template - 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> internalDgusSerial; -#endif +#ifdef LCD_SERIAL_PORT -#ifdef ANYCUBIC_LCD_SERIAL_PORT template - 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> anycubicLcdSerial; + extern MarlinSerial> lcdSerial; + #endif // Use the UART for Bluetooth in AT90USB configurations diff --git a/Marlin/src/HAL/DUE/HAL.h b/Marlin/src/HAL/DUE/HAL.h index 974f1ccc1649..7a057fdae4fc 100644 --- a/Marlin/src/HAL/DUE/HAL.h +++ b/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 diff --git a/Marlin/src/HAL/LPC1768/HAL.h b/Marlin/src/HAL/LPC1768/HAL.h index e9f05fcc617d..3118aed1b246 100644 --- a/Marlin/src/HAL/LPC1768/HAL.h +++ b/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 diff --git a/Marlin/src/HAL/LPC1768/MarlinSerial.cpp b/Marlin/src/HAL/LPC1768/MarlinSerial.cpp index c3fb3bd0e4d2..5374e005d3da 100644 --- a/Marlin/src/HAL/LPC1768/MarlinSerial.cpp +++ b/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(); diff --git a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h index 2ca8a29da4c6..b6491368cd2a 100644 --- a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h +++ b/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) diff --git a/Marlin/src/HAL/SAMD51/HAL.h b/Marlin/src/HAL/SAMD51/HAL.h index b516cb769fb3..7b532cd59816 100644 --- a/Marlin/src/HAL/SAMD51/HAL.h +++ b/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 MYSERIAL0 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 diff --git a/Marlin/src/HAL/STM32/HAL.h b/Marlin/src/HAL/STM32/HAL.h index 38605684a1fc..60ab45374a56 100644 --- a/Marlin/src/HAL/STM32/HAL.h +++ b/Marlin/src/HAL/STM32/HAL.h @@ -64,24 +64,16 @@ #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) +#ifdef LCD_SERIAL_PORT + #if LCD_SERIAL_PORT == -1 + #define LCD_SERIAL SerialUSB + #elif WITHIN(LCD_SERIAL_PORT, 1, 6) + #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT) #else - #error "DGUS_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 - #define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.availableForWrite -#endif - -#if ENABLED(MALYAN_LCD) - #if MALYAN_LCD_SERIAL_PORT == -1 - #define MALYAN_LCD_SERIAL SerialUSB - #elif WITHIN(MALYAN_LCD_SERIAL_PORT, 1, 6) - #define MALYAN_LCD_SERIAL MSERIAL(MALYAN_LCD_SERIAL_PORT) - #else - #error "MALYAN_LCD_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration." + #if HAS_DGUS_LCD + #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite() #endif #endif diff --git a/Marlin/src/HAL/STM32/MarlinSerial.cpp b/Marlin/src/HAL/STM32/MarlinSerial.cpp index 2d799ea54db0..a146664366df 100644 --- a/Marlin/src/HAL/STM32/MarlinSerial.cpp +++ b/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) { diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h index 428aa1d9aa27..45da0fe962d3 100644 --- a/Marlin/src/HAL/STM32F1/HAL.h +++ b/Marlin/src/HAL/STM32F1/HAL.h @@ -99,27 +99,27 @@ #endif #endif -#ifdef DGUS_SERIAL_PORT - #if DGUS_SERIAL_PORT == -1 - #define DGUS_SERIAL UsbSerial - #elif WITHIN(DGUS_SERIAL_PORT, 1, NUM_UARTS) - #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, 1, NUM_UARTS) + #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT) #elif NUM_UARTS == 5 - #error "DGUS_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration." + #error "LCD_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration." #else - #error "DGUS_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration." + #error "LCD_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration." #endif #endif -#ifdef MALYAN_LCD_SERIAL_PORT - #if MALYAN_LCD_SERIAL_PORT == -1 - #define MALYAN_LCD_SERIAL UsbSerial - #elif WITHIN(MALYAN_LCD_SERIAL_PORT, 1, NUM_UARTS) - #define MALYAN_LCD_SERIAL MSERIAL(MALYAN_LCD_SERIAL_PORT) +#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 "MALYAN_LCD_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration." + #error "LCD_SERIAL_PORT must be -1 or from 1 to 5. Please update your configuration." #else - #error "MALYAN_LCD_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration." + #error "LCD_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration." #endif #endif diff --git a/Marlin/src/HAL/STM32F1/MarlinSerial.cpp b/Marlin/src/HAL/STM32F1/MarlinSerial.cpp index 8328c4930fa0..9418403c7a6d 100644 --- a/Marlin/src/HAL/STM32F1/MarlinSerial.cpp +++ b/Marlin/src/HAL/STM32F1/MarlinSerial.cpp @@ -84,8 +84,8 @@ constexpr bool serial_handles_emergency(int port) { #ifdef SERIAL_PORT_2 || (SERIAL_PORT_2) == port #endif - #ifdef DGUS_SERIAL_PORT - || (DGUS_SERIAL_PORT) == port + #ifdef LCD_SERIAL_PORT + || (LCD_SERIAL_PORT) == port #endif ; } @@ -138,11 +138,11 @@ constexpr bool IsSerialClassAllowed(const HardwareSerial&) { return false; } #ifdef MYSERIAL1 CHECK_CFG_SERIAL(MYSERIAL1); #endif -#ifdef DGUS_SERIAL - CHECK_CFG_SERIAL(DGUS_SERIAL); +#ifdef LCD_SERIAL + CHECK_CFG_SERIAL(LCD_SERIAL); #endif -#ifdef MALYAN_LCD_SERIAL - CHECK_CFG_SERIAL(MALYAN_LCD_SERIAL); +#ifdef LCD_SERIAL + CHECK_CFG_SERIAL(LCD_SERIAL); #endif #if AXIS_HAS_HW_SERIAL(X) CHECK_AXIS_SERIAL(X); diff --git a/Marlin/src/HAL/STM32_F4_F7/HAL.h b/Marlin/src/HAL/STM32_F4_F7/HAL.h index e132168205bb..88e48f0fa09d 100644 --- a/Marlin/src/HAL/STM32_F4_F7/HAL.h +++ b/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 diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index 73e034d05f2f..d3f608e0a476 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/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 diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index c34fb3c951e8..27bafe00485e 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/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 MALYAN_LCD_SERIAL_PORT - #error "MALYAN_LCD requires MALYAN_LCD_SERIAL_PORT to be defined in Configuration.h" - #elif MALYAN_LCD_SERIAL_PORT == SERIAL_PORT - #error "MALYAN_LCD_SERIAL_PORT cannot be the same as SERIAL_PORT. Please update your configuration." - #elif defined(SERIAL_PORT_2) && MALYAN_LCD_SERIAL_PORT == SERIAL_PORT_2 - #error "MALYAN_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." - #endif - #define ANYCUBIC_LCD_SERIAL anycubicLcdSerial +#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 +#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 #endif /** diff --git a/Marlin/src/lcd/extui/anycubic_chiron_lcd.cpp b/Marlin/src/lcd/extui/anycubic_chiron_lcd.cpp index 889a25b85950..96856c9e0b47 100644 --- a/Marlin/src/lcd/extui/anycubic_chiron_lcd.cpp +++ b/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,7 @@ namespace ExtUI { } void onStartup() { - ANYCUBIC_LCD_SERIAL.begin(115200); + LCD_SERIAL.begin(115200); sendNewLine(); SENDLINE_PGM("J17"); // Reset delay_ms(10); diff --git a/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp b/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp index a7173b1ad2a7..6f0146fdfe61 100644 --- a/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp +++ b/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) { @@ -113,7 +113,7 @@ static void sendLine_P(PGM_P str) { AnycubicTFTClass::AnycubicTFTClass() {} void AnycubicTFTClass::OnSetup() { - ANYCUBIC_LCD_SERIAL.begin(115200); + LCD_SERIAL.begin(115200); SENDLINE_DBG_PGM("J17", "TFT Serial Debug: Main board reset... J17"); // J17 Main board reset ExtUI::delay_ms(10); @@ -574,8 +574,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 == ':' || @@ -637,11 +637,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; diff --git a/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp b/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp index b788587c9412..340cb3dd8201 100644 --- a/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp +++ b/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp @@ -59,10 +59,8 @@ constexpr uint8_t DGUS_CMD_READVAR = 0x83; bool dguslcd_local_debug; // = false; #endif -#define dgusserial DGUS_SERIAL - void DGUSDisplay::InitDisplay() { - dgusserial.begin(DGUS_BAUDRATE); + LCD_SERIAL.begin(DGUS_BAUDRATE); if (true #if ENABLED(POWER_LOSS_RECOVERY) @@ -89,7 +87,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 +131,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 +173,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 +184,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 +227,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() { diff --git a/Marlin/src/lcd/extui/malyan_lcd.cpp b/Marlin/src/lcd/extui/malyan_lcd.cpp index 01b9a9c3ce4f..ece1b142355c 100644 --- a/Marlin/src/lcd/extui/malyan_lcd.cpp +++ b/Marlin/src/lcd/extui/malyan_lcd.cpp @@ -80,7 +80,7 @@ void write_to_lcd_P(PGM_P const message) { LOOP_L_N(i, message_length) encoded_message[i] = pgm_read_byte(&message[i]) | 0x80; - MALYAN_LCD_SERIAL.Print::write(encoded_message, message_length); + LCD_SERIAL.Print::write(encoded_message, message_length); } void write_to_lcd(const char * const message) { @@ -90,7 +90,7 @@ void write_to_lcd(const char * const message) { LOOP_L_N(i, message_length) encoded_message[i] = message[i] | 0x80; - MALYAN_LCD_SERIAL.Print::write(encoded_message, message_length); + LCD_SERIAL.Print::write(encoded_message, message_length); } // {E:} is for error states. @@ -428,7 +428,7 @@ namespace ExtUI { * it and translate into ExtUI operations where possible. */ inbound_count = 0; - MALYAN_LCD_SERIAL.begin(500000); + LCD_SERIAL.begin(500000); // Signal init write_to_lcd_P(PSTR("{SYS:STARTED}\r\n")); @@ -451,8 +451,8 @@ namespace ExtUI { update_usb_status(false); // now drain commands... - while (MALYAN_LCD_SERIAL.available()) - parse_lcd_byte((byte)MALYAN_LCD_SERIAL.read()); + while (LCD_SERIAL.available()) + parse_lcd_byte((byte)LCD_SERIAL.read()); #if ENABLED(SDSUPPORT) // The way last printing status works is simple: diff --git a/buildroot/tests/malyan_M300-tests b/buildroot/tests/malyan_M300-tests index 8b41114470eb..1955accaa5f6 100755 --- a/buildroot/tests/malyan_M300-tests +++ b/buildroot/tests/malyan_M300-tests @@ -9,7 +9,7 @@ set -e restore_configs use_example_configs "delta/Malyan M300" opt_disable AUTO_BED_LEVELING_3POINT -opt_set MALYAN_LCD_SERIAL_PORT 1 +opt_set LCD_SERIAL_PORT 1 exec_test $1 $2 "Malyan M300 (delta)" # cleanup From a2641dcb6b6831cb34c57f957c716e760dcab56e Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 21:21:54 -0500 Subject: [PATCH 21/33] lcd baudrate --- Marlin/src/lcd/extui/anycubic_chiron_lcd.cpp | 5 ++++- .../anycubic_i3mega/anycubic_i3mega_lcd.cpp | 12 ++++++----- Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp | 20 ++++++------------- .../extui/lib/mks_ui/printer_operation.cpp | 6 +++--- Marlin/src/lcd/extui/malyan_lcd.cpp | 6 +++++- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Marlin/src/lcd/extui/anycubic_chiron_lcd.cpp b/Marlin/src/lcd/extui/anycubic_chiron_lcd.cpp index 96856c9e0b47..4a8095b6e993 100644 --- a/Marlin/src/lcd/extui/anycubic_chiron_lcd.cpp +++ b/Marlin/src/lcd/extui/anycubic_chiron_lcd.cpp @@ -466,7 +466,10 @@ namespace ExtUI { } void onStartup() { - 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); diff --git a/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp b/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp index 6f0146fdfe61..c69fb8351a74 100644 --- a/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp +++ b/Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp @@ -113,18 +113,20 @@ static void sendLine_P(PGM_P str) { AnycubicTFTClass::AnycubicTFTClass() {} void AnycubicTFTClass::OnSetup() { - LCD_SERIAL.begin(115200); + #ifndef LCD_BAUDRATE + #define LCD_BAUDRATE 115200 + #endif + LCD_SERIAL.begin(LCD_BAUDRATE); + SENDLINE_DBG_PGM("J17", "TFT Serial Debug: Main board reset... J17"); // J17 Main board reset ExtUI::delay_ms(10); // initialise the state of the key pins running on the tft #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT) - pinMode(SD_DETECT_PIN, INPUT); - WRITE(SD_DETECT_PIN, HIGH); + SET_INPUT_PULLUP(SD_DETECT_PIN); #endif #if ENABLED(FILAMENT_RUNOUT_SENSOR) - pinMode(FIL_RUNOUT_PIN, INPUT); - WRITE(FIL_RUNOUT_PIN, HIGH); + SET_INPUT_PULLUP(FIL_RUNOUT_PIN); #endif mediaPrintingState = AMPRINTSTATE_NOT_PRINTING; diff --git a/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp b/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp index 340cb3dd8201..5181ba7cc454 100644 --- a/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp +++ b/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp @@ -60,20 +60,12 @@ constexpr uint8_t DGUS_CMD_READVAR = 0x83; #endif void DGUSDisplay::InitDisplay() { - LCD_SERIAL.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) { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/printer_operation.cpp b/Marlin/src/lcd/extui/lib/mks_ui/printer_operation.cpp index 0e4526734ca1..2b6f5f89f6ee 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/printer_operation.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/printer_operation.cpp @@ -161,13 +161,13 @@ void printer_state_polling() { void filament_pin_setup() { #if PIN_EXISTS(MT_DET_1) - pinMode(MT_DET_1_PIN, INPUT_PULLUP); + SET_INPUT_PULLUP(MT_DET_1_PIN); #endif #if PIN_EXISTS(MT_DET_2) - pinMode(MT_DET_2_PIN, INPUT_PULLUP); + SET_INPUT_PULLUP(MT_DET_2_PIN); #endif #if PIN_EXISTS(MT_DET_3) - pinMode(MT_DET_3_PIN, INPUT_PULLUP); + SET_INPUT_PULLUP(MT_DET_3_PIN); #endif } diff --git a/Marlin/src/lcd/extui/malyan_lcd.cpp b/Marlin/src/lcd/extui/malyan_lcd.cpp index ece1b142355c..79a5fb961aa1 100644 --- a/Marlin/src/lcd/extui/malyan_lcd.cpp +++ b/Marlin/src/lcd/extui/malyan_lcd.cpp @@ -428,7 +428,11 @@ namespace ExtUI { * it and translate into ExtUI operations where possible. */ inbound_count = 0; - LCD_SERIAL.begin(500000); + + #ifndef LCD_BAUDRATE + #define LCD_BAUDRATE 500000 + #endif + LCD_SERIAL.begin(LCD_BAUDRATE); // Signal init write_to_lcd_P(PSTR("{SYS:STARTED}\r\n")); From 69c6c3d71535dad0ddd6f149c12a03ecabf80fdf Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 21:26:06 -0500 Subject: [PATCH 22/33] Serial fixes --- Marlin/src/HAL/AVR/HAL.h | 1 - Marlin/src/HAL/SAMD51/HAL.h | 4 ++-- Marlin/src/HAL/TEENSY40_41/HAL.h | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Marlin/src/HAL/AVR/HAL.h b/Marlin/src/HAL/AVR/HAL.h index 790ad872ac0b..41f1acd32f68 100644 --- a/Marlin/src/HAL/AVR/HAL.h +++ b/Marlin/src/HAL/AVR/HAL.h @@ -86,7 +86,6 @@ typedef int8_t pin_t; #if !WITHIN(SERIAL_PORT, -1, 3) #error "SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif - #define MYSERIAL0 customizedSerial1 #ifdef SERIAL_PORT_2 diff --git a/Marlin/src/HAL/SAMD51/HAL.h b/Marlin/src/HAL/SAMD51/HAL.h index 7b532cd59816..7fd826a1b6a4 100644 --- a/Marlin/src/HAL/SAMD51/HAL.h +++ b/Marlin/src/HAL/SAMD51/HAL.h @@ -50,7 +50,7 @@ #if SERIAL_PORT_2 == -1 #define MYSERIAL1 Serial #elif WITHIN(SERIAL_PORT_2, 0, 3) - #define MYSERIAL0 MSERIAL(SERIAL_PORT_2) + #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #else #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration." #endif @@ -60,7 +60,7 @@ #if LCD_SERIAL_PORT == -1 #define LCD_SERIAL Serial #elif WITHIN(LCD_SERIAL_PORT, 0, 3) - #define MYSERIAL0 MSERIAL(LCD_SERIAL_PORT) + #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT) #else #error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration." #endif diff --git a/Marlin/src/HAL/TEENSY40_41/HAL.h b/Marlin/src/HAL/TEENSY40_41/HAL.h index 77f7af295668..b3b0144d134b 100644 --- a/Marlin/src/HAL/TEENSY40_41/HAL.h +++ b/Marlin/src/HAL/TEENSY40_41/HAL.h @@ -66,7 +66,7 @@ #if SERIAL_PORT_2 == -1 #define MYSERIAL1 usbSerial #elif WITHIN(SERIAL_PORT_2, 0, 8) - #define MYSERIAL0 MSERIAL(SERIAL_PORT_2) + #define MYSERIAL1 MSERIAL(SERIAL_PORT_2) #else #error "SERIAL_PORT_2 must be from -1 to 8. Please update your configuration." #endif From 824d31ace52c595f08157e8ec8cfcca4dca8702c Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 21:39:11 -0500 Subject: [PATCH 23/33] better --- Marlin/src/HAL/AVR/MarlinSerial.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/HAL/AVR/MarlinSerial.h b/Marlin/src/HAL/AVR/MarlinSerial.h index 3d581cac4bb9..6197308bb014 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.h +++ b/Marlin/src/HAL/AVR/MarlinSerial.h @@ -217,7 +217,7 @@ static ring_buffer_pos_t available(); static void write(const uint8_t c); static void flushTX(); - #ifdef LCD_SERIAL_PORT + #if HAS_DGUS_LCD static ring_buffer_pos_t get_tx_buffer_free(); #endif From ab550c8b2f5836311c6e9a5dc3909ee378e40a00 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 21:52:20 -0500 Subject: [PATCH 24/33] Shift MarlinSerial left --- Marlin/src/HAL/AVR/MarlinSerial.cpp | 1172 +++++++++++++-------------- 1 file changed, 586 insertions(+), 586 deletions(-) diff --git a/Marlin/src/HAL/AVR/MarlinSerial.cpp b/Marlin/src/HAL/AVR/MarlinSerial.cpp index 4d654c0d8082..63599efd4132 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.cpp +++ b/Marlin/src/HAL/AVR/MarlinSerial.cpp @@ -40,407 +40,370 @@ #if !defined(USBCON) && (defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)) - #include "MarlinSerial.h" - #include "../../MarlinCore.h" +#include "MarlinSerial.h" +#include "../../MarlinCore.h" + +#if ENABLED(DIRECT_STEPPING) + #include "../../feature/direct_stepping.h" +#endif + +template typename MarlinSerial::ring_buffer_r MarlinSerial::rx_buffer = { 0, 0, { 0 } }; +template typename MarlinSerial::ring_buffer_t MarlinSerial::tx_buffer = { 0 }; +template bool MarlinSerial::_written = false; +template uint8_t MarlinSerial::xon_xoff_state = MarlinSerial::XON_XOFF_CHAR_SENT | MarlinSerial::XON_CHAR; +template uint8_t MarlinSerial::rx_dropped_bytes = 0; +template uint8_t MarlinSerial::rx_buffer_overruns = 0; +template uint8_t MarlinSerial::rx_framing_errors = 0; +template typename MarlinSerial::ring_buffer_pos_t MarlinSerial::rx_max_enqueued = 0; + +// A SW memory barrier, to ensure GCC does not overoptimize loops +#define sw_barrier() asm volatile("": : :"memory"); + +#include "../../feature/e_parser.h" + +// "Atomically" read the RX head index value without disabling interrupts: +// This MUST be called with RX interrupts enabled, and CAN'T be called +// from the RX ISR itself! +template +FORCE_INLINE typename MarlinSerial::ring_buffer_pos_t MarlinSerial::atomic_read_rx_head() { + if (Cfg::RX_SIZE > 256) { + // Keep reading until 2 consecutive reads return the same value, + // meaning there was no update in-between caused by an interrupt. + // This works because serial RX interrupts happen at a slower rate + // than successive reads of a variable, so 2 consecutive reads with + // the same value means no interrupt updated it. + ring_buffer_pos_t vold, vnew = rx_buffer.head; + sw_barrier(); + do { + vold = vnew; + vnew = rx_buffer.head; + sw_barrier(); + } while (vold != vnew); + return vnew; + } + else { + // With an 8bit index, reads are always atomic. No need for special handling + return rx_buffer.head; + } +} + +template +volatile bool MarlinSerial::rx_tail_value_not_stable = false; +template +volatile uint16_t MarlinSerial::rx_tail_value_backup = 0; + +// Set RX tail index, taking into account the RX ISR could interrupt +// the write to this variable in the middle - So a backup strategy +// is used to ensure reads of the correct values. +// -Must NOT be called from the RX ISR - +template +FORCE_INLINE void MarlinSerial::atomic_set_rx_tail(typename MarlinSerial::ring_buffer_pos_t value) { + if (Cfg::RX_SIZE > 256) { + // Store the new value in the backup + rx_tail_value_backup = value; + sw_barrier(); + // Flag we are about to change the true value + rx_tail_value_not_stable = true; + sw_barrier(); + // Store the new value + rx_buffer.tail = value; + sw_barrier(); + // Signal the new value is completely stored into the value + rx_tail_value_not_stable = false; + sw_barrier(); + } + else + rx_buffer.tail = value; +} + +// Get the RX tail index, taking into account the read could be +// interrupting in the middle of the update of that index value +// -Called from the RX ISR - +template +FORCE_INLINE typename MarlinSerial::ring_buffer_pos_t MarlinSerial::atomic_read_rx_tail() { + if (Cfg::RX_SIZE > 256) { + // If the true index is being modified, return the backup value + if (rx_tail_value_not_stable) return rx_tail_value_backup; + } + // The true index is stable, return it + return rx_buffer.tail; +} + +// (called with RX interrupts disabled) +template +FORCE_INLINE void MarlinSerial::store_rxd_char() { + + static EmergencyParser::State emergency_state; // = EP_RESET + + // This must read the R_UCSRA register before reading the received byte to detect error causes + if (Cfg::DROPPED_RX && B_DOR && !++rx_dropped_bytes) --rx_dropped_bytes; + if (Cfg::RX_OVERRUNS && B_DOR && !++rx_buffer_overruns) --rx_buffer_overruns; + if (Cfg::RX_FRAMING_ERRORS && B_FE && !++rx_framing_errors) --rx_framing_errors; + + // Read the character from the USART + uint8_t c = R_UDR; #if ENABLED(DIRECT_STEPPING) - #include "../../feature/direct_stepping.h" + if (page_manager.maybe_store_rxd_char(c)) return; #endif - template typename MarlinSerial::ring_buffer_r MarlinSerial::rx_buffer = { 0, 0, { 0 } }; - template typename MarlinSerial::ring_buffer_t MarlinSerial::tx_buffer = { 0 }; - template bool MarlinSerial::_written = false; - template uint8_t MarlinSerial::xon_xoff_state = MarlinSerial::XON_XOFF_CHAR_SENT | MarlinSerial::XON_CHAR; - template uint8_t MarlinSerial::rx_dropped_bytes = 0; - template uint8_t MarlinSerial::rx_buffer_overruns = 0; - template uint8_t MarlinSerial::rx_framing_errors = 0; - template typename MarlinSerial::ring_buffer_pos_t MarlinSerial::rx_max_enqueued = 0; - - // A SW memory barrier, to ensure GCC does not overoptimize loops - #define sw_barrier() asm volatile("": : :"memory"); - - #include "../../feature/e_parser.h" - - // "Atomically" read the RX head index value without disabling interrupts: - // This MUST be called with RX interrupts enabled, and CAN'T be called - // from the RX ISR itself! - template - FORCE_INLINE typename MarlinSerial::ring_buffer_pos_t MarlinSerial::atomic_read_rx_head() { - if (Cfg::RX_SIZE > 256) { - // Keep reading until 2 consecutive reads return the same value, - // meaning there was no update in-between caused by an interrupt. - // This works because serial RX interrupts happen at a slower rate - // than successive reads of a variable, so 2 consecutive reads with - // the same value means no interrupt updated it. - ring_buffer_pos_t vold, vnew = rx_buffer.head; - sw_barrier(); - do { - vold = vnew; - vnew = rx_buffer.head; - sw_barrier(); - } while (vold != vnew); - return vnew; - } - else { - // With an 8bit index, reads are always atomic. No need for special handling - return rx_buffer.head; - } - } + // Get the tail - Nothing can alter its value while this ISR is executing, but there's + // a chance that this ISR interrupted the main process while it was updating the index. + // The backup mechanism ensures the correct value is always returned. + const ring_buffer_pos_t t = atomic_read_rx_tail(); - template - volatile bool MarlinSerial::rx_tail_value_not_stable = false; - template - volatile uint16_t MarlinSerial::rx_tail_value_backup = 0; - - // Set RX tail index, taking into account the RX ISR could interrupt - // the write to this variable in the middle - So a backup strategy - // is used to ensure reads of the correct values. - // -Must NOT be called from the RX ISR - - template - FORCE_INLINE void MarlinSerial::atomic_set_rx_tail(typename MarlinSerial::ring_buffer_pos_t value) { - if (Cfg::RX_SIZE > 256) { - // Store the new value in the backup - rx_tail_value_backup = value; - sw_barrier(); - // Flag we are about to change the true value - rx_tail_value_not_stable = true; - sw_barrier(); - // Store the new value - rx_buffer.tail = value; - sw_barrier(); - // Signal the new value is completely stored into the value - rx_tail_value_not_stable = false; - sw_barrier(); - } - else - rx_buffer.tail = value; - } + // Get the head pointer - This ISR is the only one that modifies its value, so it's safe to read here + ring_buffer_pos_t h = rx_buffer.head; - // Get the RX tail index, taking into account the read could be - // interrupting in the middle of the update of that index value - // -Called from the RX ISR - - template - FORCE_INLINE typename MarlinSerial::ring_buffer_pos_t MarlinSerial::atomic_read_rx_tail() { - if (Cfg::RX_SIZE > 256) { - // If the true index is being modified, return the backup value - if (rx_tail_value_not_stable) return rx_tail_value_backup; - } - // The true index is stable, return it - return rx_buffer.tail; - } + // Get the next element + ring_buffer_pos_t i = (ring_buffer_pos_t)(h + 1) & (ring_buffer_pos_t)(Cfg::RX_SIZE - 1); - // (called with RX interrupts disabled) - template - FORCE_INLINE void MarlinSerial::store_rxd_char() { + if (Cfg::EMERGENCYPARSER) emergency_parser.update(emergency_state, c); - static EmergencyParser::State emergency_state; // = EP_RESET + // If the character is to be stored at the index just before the tail + // (such that the head would advance to the current tail), the RX FIFO is + // full, so don't write the character or advance the head. + if (i != t) { + rx_buffer.buffer[h] = c; + h = i; + } + else if (Cfg::DROPPED_RX && !++rx_dropped_bytes) + --rx_dropped_bytes; - // This must read the R_UCSRA register before reading the received byte to detect error causes - if (Cfg::DROPPED_RX && B_DOR && !++rx_dropped_bytes) --rx_dropped_bytes; - if (Cfg::RX_OVERRUNS && B_DOR && !++rx_buffer_overruns) --rx_buffer_overruns; - if (Cfg::RX_FRAMING_ERRORS && B_FE && !++rx_framing_errors) --rx_framing_errors; + if (Cfg::MAX_RX_QUEUED) { + // Calculate count of bytes stored into the RX buffer + const ring_buffer_pos_t rx_count = (ring_buffer_pos_t)(h - t) & (ring_buffer_pos_t)(Cfg::RX_SIZE - 1); - // Read the character from the USART - uint8_t c = R_UDR; + // Keep track of the maximum count of enqueued bytes + NOLESS(rx_max_enqueued, rx_count); + } - #if ENABLED(DIRECT_STEPPING) - if (page_manager.maybe_store_rxd_char(c)) return; - #endif + if (Cfg::XONOFF) { + // If the last char that was sent was an XON + if ((xon_xoff_state & XON_XOFF_CHAR_MASK) == XON_CHAR) { - // Get the tail - Nothing can alter its value while this ISR is executing, but there's - // a chance that this ISR interrupted the main process while it was updating the index. - // The backup mechanism ensures the correct value is always returned. - const ring_buffer_pos_t t = atomic_read_rx_tail(); + // Bytes stored into the RX buffer + const ring_buffer_pos_t rx_count = (ring_buffer_pos_t)(h - t) & (ring_buffer_pos_t)(Cfg::RX_SIZE - 1); - // Get the head pointer - This ISR is the only one that modifies its value, so it's safe to read here - ring_buffer_pos_t h = rx_buffer.head; + // If over 12.5% of RX buffer capacity, send XOFF before running out of + // RX buffer space .. 325 bytes @ 250kbits/s needed to let the host react + // and stop sending bytes. This translates to 13mS propagation time. + if (rx_count >= (Cfg::RX_SIZE) / 8) { - // Get the next element - ring_buffer_pos_t i = (ring_buffer_pos_t)(h + 1) & (ring_buffer_pos_t)(Cfg::RX_SIZE - 1); + // At this point, definitely no TX interrupt was executing, since the TX ISR can't be preempted. + // Don't enable the TX interrupt here as a means to trigger the XOFF char, because if it happens + // to be in the middle of trying to disable the RX interrupt in the main program, eventually the + // enabling of the TX interrupt could be undone. The ONLY reliable thing this can do to ensure + // the sending of the XOFF char is to send it HERE AND NOW. - if (Cfg::EMERGENCYPARSER) emergency_parser.update(emergency_state, c); + // About to send the XOFF char + xon_xoff_state = XOFF_CHAR | XON_XOFF_CHAR_SENT; - // If the character is to be stored at the index just before the tail - // (such that the head would advance to the current tail), the RX FIFO is - // full, so don't write the character or advance the head. - if (i != t) { - rx_buffer.buffer[h] = c; - h = i; - } - else if (Cfg::DROPPED_RX && !++rx_dropped_bytes) - --rx_dropped_bytes; + // Wait until the TX register becomes empty and send it - Here there could be a problem + // - While waiting for the TX register to empty, the RX register could receive a new + // character. This must also handle that situation! + while (!B_UDRE) { - if (Cfg::MAX_RX_QUEUED) { - // Calculate count of bytes stored into the RX buffer - const ring_buffer_pos_t rx_count = (ring_buffer_pos_t)(h - t) & (ring_buffer_pos_t)(Cfg::RX_SIZE - 1); + if (B_RXC) { + // A char arrived while waiting for the TX buffer to be empty - Receive and process it! - // Keep track of the maximum count of enqueued bytes - NOLESS(rx_max_enqueued, rx_count); - } + i = (ring_buffer_pos_t)(h + 1) & (ring_buffer_pos_t)(Cfg::RX_SIZE - 1); - if (Cfg::XONOFF) { - // If the last char that was sent was an XON - if ((xon_xoff_state & XON_XOFF_CHAR_MASK) == XON_CHAR) { - - // Bytes stored into the RX buffer - const ring_buffer_pos_t rx_count = (ring_buffer_pos_t)(h - t) & (ring_buffer_pos_t)(Cfg::RX_SIZE - 1); - - // If over 12.5% of RX buffer capacity, send XOFF before running out of - // RX buffer space .. 325 bytes @ 250kbits/s needed to let the host react - // and stop sending bytes. This translates to 13mS propagation time. - if (rx_count >= (Cfg::RX_SIZE) / 8) { - - // At this point, definitely no TX interrupt was executing, since the TX ISR can't be preempted. - // Don't enable the TX interrupt here as a means to trigger the XOFF char, because if it happens - // to be in the middle of trying to disable the RX interrupt in the main program, eventually the - // enabling of the TX interrupt could be undone. The ONLY reliable thing this can do to ensure - // the sending of the XOFF char is to send it HERE AND NOW. - - // About to send the XOFF char - xon_xoff_state = XOFF_CHAR | XON_XOFF_CHAR_SENT; - - // Wait until the TX register becomes empty and send it - Here there could be a problem - // - While waiting for the TX register to empty, the RX register could receive a new - // character. This must also handle that situation! - while (!B_UDRE) { - - if (B_RXC) { - // A char arrived while waiting for the TX buffer to be empty - Receive and process it! - - i = (ring_buffer_pos_t)(h + 1) & (ring_buffer_pos_t)(Cfg::RX_SIZE - 1); - - // Read the character from the USART - c = R_UDR; - - if (Cfg::EMERGENCYPARSER) emergency_parser.update(emergency_state, c); - - // If the character is to be stored at the index just before the tail - // (such that the head would advance to the current tail), the FIFO is - // full, so don't write the character or advance the head. - if (i != t) { - rx_buffer.buffer[h] = c; - h = i; - } - else if (Cfg::DROPPED_RX && !++rx_dropped_bytes) - --rx_dropped_bytes; - } - sw_barrier(); - } + // Read the character from the USART + c = R_UDR; + + if (Cfg::EMERGENCYPARSER) emergency_parser.update(emergency_state, c); - R_UDR = XOFF_CHAR; - - // Clear the TXC bit -- "can be cleared by writing a one to its bit - // location". This makes sure flush() won't return until the bytes - // actually got written - B_TXC = 1; - - // At this point there could be a race condition between the write() function - // and this sending of the XOFF char. This interrupt could happen between the - // wait to be empty TX buffer loop and the actual write of the character. Since - // the TX buffer is full because it's sending the XOFF char, the only way to be - // sure the write() function will succeed is to wait for the XOFF char to be - // completely sent. Since an extra character could be received during the wait - // it must also be handled! - while (!B_UDRE) { - - if (B_RXC) { - // A char arrived while waiting for the TX buffer to be empty - Receive and process it! - - i = (ring_buffer_pos_t)(h + 1) & (ring_buffer_pos_t)(Cfg::RX_SIZE - 1); - - // Read the character from the USART - c = R_UDR; - - if (Cfg::EMERGENCYPARSER) - emergency_parser.update(emergency_state, c); - - // If the character is to be stored at the index just before the tail - // (such that the head would advance to the current tail), the FIFO is - // full, so don't write the character or advance the head. - if (i != t) { - rx_buffer.buffer[h] = c; - h = i; - } - else if (Cfg::DROPPED_RX && !++rx_dropped_bytes) - --rx_dropped_bytes; + // If the character is to be stored at the index just before the tail + // (such that the head would advance to the current tail), the FIFO is + // full, so don't write the character or advance the head. + if (i != t) { + rx_buffer.buffer[h] = c; + h = i; } - sw_barrier(); + else if (Cfg::DROPPED_RX && !++rx_dropped_bytes) + --rx_dropped_bytes; } - - // At this point everything is ready. The write() function won't - // have any issues writing to the UART TX register if it needs to! + sw_barrier(); } - } - } - // Store the new head value - The main loop will retry until the value is stable - rx_buffer.head = h; - } + R_UDR = XOFF_CHAR; - // (called with TX irqs disabled) - template - FORCE_INLINE void MarlinSerial::_tx_udr_empty_irq() { - if (Cfg::TX_SIZE > 0) { - // Read positions - uint8_t t = tx_buffer.tail; - const uint8_t h = tx_buffer.head; + // Clear the TXC bit -- "can be cleared by writing a one to its bit + // location". This makes sure flush() won't return until the bytes + // actually got written + B_TXC = 1; - if (Cfg::XONOFF) { - // If an XON char is pending to be sent, do it now - if (xon_xoff_state == XON_CHAR) { + // At this point there could be a race condition between the write() function + // and this sending of the XOFF char. This interrupt could happen between the + // wait to be empty TX buffer loop and the actual write of the character. Since + // the TX buffer is full because it's sending the XOFF char, the only way to be + // sure the write() function will succeed is to wait for the XOFF char to be + // completely sent. Since an extra character could be received during the wait + // it must also be handled! + while (!B_UDRE) { - // Send the character - R_UDR = XON_CHAR; + if (B_RXC) { + // A char arrived while waiting for the TX buffer to be empty - Receive and process it! - // clear the TXC bit -- "can be cleared by writing a one to its bit - // location". This makes sure flush() won't return until the bytes - // actually got written - B_TXC = 1; + i = (ring_buffer_pos_t)(h + 1) & (ring_buffer_pos_t)(Cfg::RX_SIZE - 1); - // Remember we sent it. - xon_xoff_state = XON_CHAR | XON_XOFF_CHAR_SENT; + // Read the character from the USART + c = R_UDR; - // If nothing else to transmit, just disable TX interrupts. - if (h == t) B_UDRIE = 0; // (Non-atomic, could be reenabled by the main program, but eventually this will succeed) + if (Cfg::EMERGENCYPARSER) + emergency_parser.update(emergency_state, c); - return; + // If the character is to be stored at the index just before the tail + // (such that the head would advance to the current tail), the FIFO is + // full, so don't write the character or advance the head. + if (i != t) { + rx_buffer.buffer[h] = c; + h = i; + } + else if (Cfg::DROPPED_RX && !++rx_dropped_bytes) + --rx_dropped_bytes; + } + sw_barrier(); } - } - // If nothing to transmit, just disable TX interrupts. This could - // happen as the result of the non atomicity of the disabling of RX - // interrupts that could end reenabling TX interrupts as a side effect. - if (h == t) { - B_UDRIE = 0; // (Non-atomic, could be reenabled by the main program, but eventually this will succeed) - return; + // At this point everything is ready. The write() function won't + // have any issues writing to the UART TX register if it needs to! } - - // There is something to TX, Send the next byte - const uint8_t c = tx_buffer.buffer[t]; - t = (t + 1) & (Cfg::TX_SIZE - 1); - R_UDR = c; - tx_buffer.tail = t; - - // Clear the TXC bit (by writing a one to its bit location). - // Ensures flush() won't return until the bytes are actually written/ - B_TXC = 1; - - // 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) } } - // Public Methods - template - void MarlinSerial::begin(const long baud) { - uint16_t baud_setting; - bool useU2X = true; - - #if F_CPU == 16000000UL && SERIAL_PORT == 0 - // Hard-coded exception for compatibility with the bootloader shipped - // with the Duemilanove and previous boards, and the firmware on the - // 8U2 on the Uno and Mega 2560. - if (baud == 57600) useU2X = false; - #endif - - R_UCSRA = 0; - if (useU2X) { - B_U2X = 1; - baud_setting = (F_CPU / 4 / baud - 1) / 2; - } - else - baud_setting = (F_CPU / 8 / baud - 1) / 2; - - // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register) - R_UBRRH = baud_setting >> 8; - R_UBRRL = baud_setting; - - B_RXEN = 1; - B_TXEN = 1; - B_RXCIE = 1; - if (Cfg::TX_SIZE > 0) B_UDRIE = 0; - _written = false; - } + // Store the new head value - The main loop will retry until the value is stable + rx_buffer.head = h; +} - template - void MarlinSerial::end() { - B_RXEN = 0; - B_TXEN = 0; - B_RXCIE = 0; - B_UDRIE = 0; - } +// (called with TX irqs disabled) +template +FORCE_INLINE void MarlinSerial::_tx_udr_empty_irq() { + if (Cfg::TX_SIZE > 0) { + // Read positions + uint8_t t = tx_buffer.tail; + const uint8_t h = tx_buffer.head; - template - int MarlinSerial::peek() { - const ring_buffer_pos_t h = atomic_read_rx_head(), t = rx_buffer.tail; - return h == t ? -1 : rx_buffer.buffer[t]; - } - - template - int MarlinSerial::read() { - const ring_buffer_pos_t h = atomic_read_rx_head(); + if (Cfg::XONOFF) { + // If an XON char is pending to be sent, do it now + if (xon_xoff_state == XON_CHAR) { - // Read the tail. Main thread owns it, so it is safe to directly read it - ring_buffer_pos_t t = rx_buffer.tail; + // Send the character + R_UDR = XON_CHAR; - // If nothing to read, return now - if (h == t) return -1; + // clear the TXC bit -- "can be cleared by writing a one to its bit + // location". This makes sure flush() won't return until the bytes + // actually got written + B_TXC = 1; - // Get the next char - const int v = rx_buffer.buffer[t]; - t = (ring_buffer_pos_t)(t + 1) & (Cfg::RX_SIZE - 1); + // Remember we sent it. + xon_xoff_state = XON_CHAR | XON_XOFF_CHAR_SENT; - // Advance tail - Making sure the RX ISR will always get an stable value, even - // if it interrupts the writing of the value of that variable in the middle. - atomic_set_rx_tail(t); + // If nothing else to transmit, just disable TX interrupts. + if (h == t) B_UDRIE = 0; // (Non-atomic, could be reenabled by the main program, but eventually this will succeed) - if (Cfg::XONOFF) { - // If the XOFF char was sent, or about to be sent... - if ((xon_xoff_state & XON_XOFF_CHAR_MASK) == XOFF_CHAR) { - // Get count of bytes in the RX buffer - const ring_buffer_pos_t rx_count = (ring_buffer_pos_t)(h - t) & (ring_buffer_pos_t)(Cfg::RX_SIZE - 1); - if (rx_count < (Cfg::RX_SIZE) / 10) { - if (Cfg::TX_SIZE > 0) { - // Signal we want an XON character to be sent. - xon_xoff_state = XON_CHAR; - // Enable TX ISR. Non atomic, but it will eventually enable them - B_UDRIE = 1; - } - else { - // If not using TX interrupts, we must send the XON char now - xon_xoff_state = XON_CHAR | XON_XOFF_CHAR_SENT; - while (!B_UDRE) sw_barrier(); - R_UDR = XON_CHAR; - } - } + return; } } - return v; - } + // If nothing to transmit, just disable TX interrupts. This could + // happen as the result of the non atomicity of the disabling of RX + // interrupts that could end reenabling TX interrupts as a side effect. + if (h == t) { + B_UDRIE = 0; // (Non-atomic, could be reenabled by the main program, but eventually this will succeed) + return; + } + + // There is something to TX, Send the next byte + const uint8_t c = tx_buffer.buffer[t]; + t = (t + 1) & (Cfg::TX_SIZE - 1); + R_UDR = c; + tx_buffer.tail = t; - template - typename MarlinSerial::ring_buffer_pos_t MarlinSerial::available() { - 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); + // Clear the TXC bit (by writing a one to its bit location). + // Ensures flush() won't return until the bytes are actually written/ + B_TXC = 1; + + // 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) } +} - template - void MarlinSerial::flush() { +// Public Methods +template +void MarlinSerial::begin(const long baud) { + uint16_t baud_setting; + bool useU2X = true; - // Set the tail to the head: - // - Read the RX head index in a safe way. (See atomic_read_rx_head.) - // - Set the tail, making sure the RX ISR will always get a stable value, even - // if it interrupts the writing of the value of that variable in the middle. - atomic_set_rx_tail(atomic_read_rx_head()); + #if F_CPU == 16000000UL && SERIAL_PORT == 0 + // Hard-coded exception for compatibility with the bootloader shipped + // with the Duemilanove and previous boards, and the firmware on the + // 8U2 on the Uno and Mega 2560. + if (baud == 57600) useU2X = false; + #endif - if (Cfg::XONOFF) { - // If the XOFF char was sent, or about to be sent... - if ((xon_xoff_state & XON_XOFF_CHAR_MASK) == XOFF_CHAR) { + R_UCSRA = 0; + if (useU2X) { + B_U2X = 1; + baud_setting = (F_CPU / 4 / baud - 1) / 2; + } + else + baud_setting = (F_CPU / 8 / baud - 1) / 2; + + // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register) + R_UBRRH = baud_setting >> 8; + R_UBRRL = baud_setting; + + B_RXEN = 1; + B_TXEN = 1; + B_RXCIE = 1; + if (Cfg::TX_SIZE > 0) B_UDRIE = 0; + _written = false; +} + +template +void MarlinSerial::end() { + B_RXEN = 0; + B_TXEN = 0; + B_RXCIE = 0; + B_UDRIE = 0; +} + +template +int MarlinSerial::peek() { + const ring_buffer_pos_t h = atomic_read_rx_head(), t = rx_buffer.tail; + return h == t ? -1 : rx_buffer.buffer[t]; +} + +template +int MarlinSerial::read() { + 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 + ring_buffer_pos_t t = rx_buffer.tail; + + // If nothing to read, return now + if (h == t) return -1; + + // Get the next char + const int v = rx_buffer.buffer[t]; + t = (ring_buffer_pos_t)(t + 1) & (Cfg::RX_SIZE - 1); + + // Advance tail - Making sure the RX ISR will always get an stable value, even + // if it interrupts the writing of the value of that variable in the middle. + atomic_set_rx_tail(t); + + if (Cfg::XONOFF) { + // If the XOFF char was sent, or about to be sent... + if ((xon_xoff_state & XON_XOFF_CHAR_MASK) == XOFF_CHAR) { + // Get count of bytes in the RX buffer + const ring_buffer_pos_t rx_count = (ring_buffer_pos_t)(h - t) & (ring_buffer_pos_t)(Cfg::RX_SIZE - 1); + if (rx_count < (Cfg::RX_SIZE) / 10) { if (Cfg::TX_SIZE > 0) { // Signal we want an XON character to be sent. xon_xoff_state = XON_CHAR; - // Enable TX ISR. Non atomic, but it will eventually enable it. + // Enable TX ISR. Non atomic, but it will eventually enable them B_UDRIE = 1; } else { @@ -453,299 +416,334 @@ } } - template - void MarlinSerial::write(const uint8_t c) { - if (Cfg::TX_SIZE == 0) { - - _written = true; - while (!B_UDRE) sw_barrier(); - R_UDR = c; - - } - else { - - _written = true; - - // If the TX interrupts are disabled and the data register - // is empty, just write the byte to the data register and - // be done. This shortcut helps significantly improve the - // effective datarate at high (>500kbit/s) bitrates, where - // interrupt overhead becomes a slowdown. - // Yes, there is a race condition between the sending of the - // XOFF char at the RX ISR, but it is properly handled there - if (!B_UDRIE && B_UDRE) { - R_UDR = c; - - // clear the TXC bit -- "can be cleared by writing a one to its bit - // location". This makes sure flush() won't return until the bytes - // actually got written - B_TXC = 1; - return; - } - - const uint8_t i = (tx_buffer.head + 1) & (Cfg::TX_SIZE - 1); - - // If global interrupts are disabled (as the result of being called from an ISR)... - if (!ISRS_ENABLED()) { - - // Make room by polling if it is possible to transmit, and do so! - while (i == tx_buffer.tail) { - - // If we can transmit another byte, do it. - if (B_UDRE) _tx_udr_empty_irq(); - - // Make sure compiler rereads tx_buffer.tail - sw_barrier(); - } + return v; +} + +template +typename MarlinSerial::ring_buffer_pos_t MarlinSerial::available() { + 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); +} + +template +void MarlinSerial::flush() { + + // Set the tail to the head: + // - Read the RX head index in a safe way. (See atomic_read_rx_head.) + // - Set the tail, making sure the RX ISR will always get a stable value, even + // if it interrupts the writing of the value of that variable in the middle. + atomic_set_rx_tail(atomic_read_rx_head()); + + if (Cfg::XONOFF) { + // If the XOFF char was sent, or about to be sent... + if ((xon_xoff_state & XON_XOFF_CHAR_MASK) == XOFF_CHAR) { + if (Cfg::TX_SIZE > 0) { + // Signal we want an XON character to be sent. + xon_xoff_state = XON_CHAR; + // Enable TX ISR. Non atomic, but it will eventually enable it. + B_UDRIE = 1; } else { - // Interrupts are enabled, just wait until there is space - while (i == tx_buffer.tail) sw_barrier(); + // If not using TX interrupts, we must send the XON char now + xon_xoff_state = XON_CHAR | XON_XOFF_CHAR_SENT; + while (!B_UDRE) sw_barrier(); + R_UDR = XON_CHAR; } - - // Store new char. head is always safe to move - tx_buffer.buffer[tx_buffer.head] = c; - tx_buffer.head = i; - - // Enable TX ISR - Non atomic, but it will eventually enable TX ISR - B_UDRIE = 1; } } +} - template - void MarlinSerial::flushTX() { +template +void MarlinSerial::write(const uint8_t c) { + 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 way to force the TXC (transmit complete) bit to 1 during initialization. - if (!_written) return; + _written = true; + while (!B_UDRE) sw_barrier(); + R_UDR = c; - // Wait until everything was transmitted - while (!B_TXC) sw_barrier(); + } + else { - // At this point nothing is queued anymore (DRIE is disabled) and - // the hardware finished transmission (TXC is set). + _written = true; - } - else { + // If the TX interrupts are disabled and the data register + // is empty, just write the byte to the data register and + // be done. This shortcut helps significantly improve the + // effective datarate at high (>500kbit/s) bitrates, where + // interrupt overhead becomes a slowdown. + // Yes, there is a race condition between the sending of the + // XOFF char at the RX ISR, but it is properly handled there + if (!B_UDRIE && B_UDRE) { + R_UDR = c; - // No bytes written, no need to flush. This special case is needed since there's - // no way to force the TXC (transmit complete) bit to 1 during initialization. - if (!_written) return; + // clear the TXC bit -- "can be cleared by writing a one to its bit + // location". This makes sure flush() won't return until the bytes + // actually got written + B_TXC = 1; + return; + } - // If global interrupts are disabled (as the result of being called from an ISR)... - if (!ISRS_ENABLED()) { + const uint8_t i = (tx_buffer.head + 1) & (Cfg::TX_SIZE - 1); - // Wait until everything was transmitted - We must do polling, as interrupts are disabled - while (tx_buffer.head != tx_buffer.tail || !B_TXC) { + // If global interrupts are disabled (as the result of being called from an ISR)... + if (!ISRS_ENABLED()) { - // If there is more space, send an extra character - if (B_UDRE) _tx_udr_empty_irq(); + // Make room by polling if it is possible to transmit, and do so! + while (i == tx_buffer.tail) { - sw_barrier(); - } + // If we can transmit another byte, do it. + if (B_UDRE) _tx_udr_empty_irq(); + // Make sure compiler rereads tx_buffer.tail + sw_barrier(); } - else { - // Wait until everything was transmitted - while (tx_buffer.head != tx_buffer.tail || !B_TXC) sw_barrier(); - } - - // At this point nothing is queued anymore (DRIE is disabled) and - // the hardware finished transmission (TXC is set). } - } + else { + // Interrupts are enabled, just wait until there is space + while (i == tx_buffer.tail) sw_barrier(); + } - /** - * Imports from print.h - */ + // Store new char. head is always safe to move + tx_buffer.buffer[tx_buffer.head] = c; + tx_buffer.head = i; - template - void MarlinSerial::print(char c, int base) { - print((long)c, base); + // Enable TX ISR - Non atomic, but it will eventually enable TX ISR + B_UDRIE = 1; } +} - template - void MarlinSerial::print(unsigned char b, int base) { - print((unsigned long)b, base); - } +template +void MarlinSerial::flushTX() { - template - void MarlinSerial::print(int n, int base) { - print((long)n, base); - } + if (Cfg::TX_SIZE == 0) { + // No bytes written, no need to flush. This special case is needed since there's + // no way to force the TXC (transmit complete) bit to 1 during initialization. + if (!_written) return; - template - void MarlinSerial::print(unsigned int n, int base) { - print((unsigned long)n, base); - } + // Wait until everything was transmitted + while (!B_TXC) sw_barrier(); - template - void MarlinSerial::print(long n, int base) { - if (base == 0) write(n); - else if (base == 10) { - if (n < 0) { print('-'); n = -n; } - printNumber(n, 10); - } - else - printNumber(n, base); - } + // At this point nothing is queued anymore (DRIE is disabled) and + // the hardware finished transmission (TXC is set). - template - void MarlinSerial::print(unsigned long n, int base) { - if (base == 0) write(n); - else printNumber(n, base); } + else { - template - void MarlinSerial::print(double n, int digits) { - printFloat(n, digits); - } + // No bytes written, no need to flush. This special case is needed since there's + // no way to force the TXC (transmit complete) bit to 1 during initialization. + if (!_written) return; - template - void MarlinSerial::println() { - print('\r'); - print('\n'); - } + // If global interrupts are disabled (as the result of being called from an ISR)... + if (!ISRS_ENABLED()) { - template - void MarlinSerial::println(const String& s) { - print(s); - println(); - } + // Wait until everything was transmitted - We must do polling, as interrupts are disabled + while (tx_buffer.head != tx_buffer.tail || !B_TXC) { - template - void MarlinSerial::println(const char c[]) { - print(c); - println(); - } + // If there is more space, send an extra character + if (B_UDRE) _tx_udr_empty_irq(); - template - void MarlinSerial::println(char c, int base) { - print(c, base); - println(); - } - - template - void MarlinSerial::println(unsigned char b, int base) { - print(b, base); - println(); - } + sw_barrier(); + } - template - void MarlinSerial::println(int n, int base) { - print(n, base); - println(); - } + } + else { + // Wait until everything was transmitted + while (tx_buffer.head != tx_buffer.tail || !B_TXC) sw_barrier(); + } - template - void MarlinSerial::println(unsigned int n, int base) { - print(n, base); - println(); + // At this point nothing is queued anymore (DRIE is disabled) and + // the hardware finished transmission (TXC is set). } +} - template - void MarlinSerial::println(long n, int base) { - print(n, base); - println(); - } +/** + * Imports from print.h + */ - template - void MarlinSerial::println(unsigned long n, int base) { - print(n, base); - println(); +template +void MarlinSerial::print(char c, int base) { + print((long)c, base); +} + +template +void MarlinSerial::print(unsigned char b, int base) { + print((unsigned long)b, base); +} + +template +void MarlinSerial::print(int n, int base) { + print((long)n, base); +} + +template +void MarlinSerial::print(unsigned int n, int base) { + print((unsigned long)n, base); +} + +template +void MarlinSerial::print(long n, int base) { + if (base == 0) write(n); + else if (base == 10) { + if (n < 0) { print('-'); n = -n; } + printNumber(n, 10); + } + else + printNumber(n, base); +} + +template +void MarlinSerial::print(unsigned long n, int base) { + if (base == 0) write(n); + else printNumber(n, base); +} + +template +void MarlinSerial::print(double n, int digits) { + printFloat(n, digits); +} + +template +void MarlinSerial::println() { + print('\r'); + print('\n'); +} + +template +void MarlinSerial::println(const String& s) { + print(s); + println(); +} + +template +void MarlinSerial::println(const char c[]) { + print(c); + println(); +} + +template +void MarlinSerial::println(char c, int base) { + print(c, base); + println(); +} + +template +void MarlinSerial::println(unsigned char b, int base) { + print(b, base); + println(); +} + +template +void MarlinSerial::println(int n, int base) { + print(n, base); + println(); +} + +template +void MarlinSerial::println(unsigned int n, int base) { + print(n, base); + println(); +} + +template +void MarlinSerial::println(long n, int base) { + print(n, base); + println(); +} + +template +void MarlinSerial::println(unsigned long n, int base) { + print(n, base); + println(); +} + +template +void MarlinSerial::println(double n, int digits) { + print(n, digits); + println(); +} + +// Private Methods + +template +void MarlinSerial::printNumber(unsigned long n, uint8_t base) { + if (n) { + unsigned char buf[8 * sizeof(long)]; // Enough space for base 2 + int8_t i = 0; + while (n) { + buf[i++] = n % base; + n /= base; + } + while (i--) + print((char)(buf[i] + (buf[i] < 10 ? '0' : 'A' - 10))); + } + else + print('0'); +} + +template +void MarlinSerial::printFloat(double number, uint8_t digits) { + // Handle negative numbers + if (number < 0.0) { + print('-'); + number = -number; + } + + // Round correctly so that print(1.999, 2) prints as "2.00" + double rounding = 0.5; + LOOP_L_N(i, digits) rounding *= 0.1; + number += rounding; + + // Extract the integer part of the number and print it + unsigned long int_part = (unsigned long)number; + double remainder = number - (double)int_part; + print(int_part); + + // Print the decimal point, but only if there are digits beyond + if (digits) { + print('.'); + // Extract digits from the remainder one at a time + while (digits--) { + remainder *= 10.0; + int toPrint = int(remainder); + print(toPrint); + remainder -= toPrint; + } } +} - template - void MarlinSerial::println(double n, int digits) { - print(n, digits); - println(); - } +// Hookup ISR handlers +ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _RX_vect)) { + MarlinSerial>::store_rxd_char(); +} - // Private Methods +ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _UDRE_vect)) { + MarlinSerial>::_tx_udr_empty_irq(); +} - template - void MarlinSerial::printNumber(unsigned long n, uint8_t base) { - if (n) { - unsigned char buf[8 * sizeof(long)]; // Enough space for base 2 - int8_t i = 0; - while (n) { - buf[i++] = n % base; - n /= base; - } - while (i--) - print((char)(buf[i] + (buf[i] < 10 ? '0' : 'A' - 10))); - } - else - print('0'); - } +// Preinstantiate +template class MarlinSerial>; - template - void MarlinSerial::printFloat(double number, uint8_t digits) { - // Handle negative numbers - if (number < 0.0) { - print('-'); - number = -number; - } +// Instantiate +MarlinSerial> customizedSerial1; - // Round correctly so that print(1.999, 2) prints as "2.00" - double rounding = 0.5; - LOOP_L_N(i, digits) rounding *= 0.1; - number += rounding; - - // Extract the integer part of the number and print it - unsigned long int_part = (unsigned long)number; - double remainder = number - (double)int_part; - print(int_part); - - // Print the decimal point, but only if there are digits beyond - if (digits) { - print('.'); - // Extract digits from the remainder one at a time - while (digits--) { - remainder *= 10.0; - int toPrint = int(remainder); - print(toPrint); - remainder -= toPrint; - } - } - } +#ifdef SERIAL_PORT_2 // Hookup ISR handlers - ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _RX_vect)) { - MarlinSerial>::store_rxd_char(); + ISR(SERIAL_REGNAME(USART, SERIAL_PORT_2, _RX_vect)) { + MarlinSerial>::store_rxd_char(); } - ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _UDRE_vect)) { - MarlinSerial>::_tx_udr_empty_irq(); + ISR(SERIAL_REGNAME(USART, SERIAL_PORT_2, _UDRE_vect)) { + MarlinSerial>::_tx_udr_empty_irq(); } // Preinstantiate - template class MarlinSerial>; + template class MarlinSerial>; // Instantiate - MarlinSerial> customizedSerial1; - - #ifdef SERIAL_PORT_2 + MarlinSerial> customizedSerial2; - // Hookup ISR handlers - ISR(SERIAL_REGNAME(USART, SERIAL_PORT_2, _RX_vect)) { - MarlinSerial>::store_rxd_char(); - } - - ISR(SERIAL_REGNAME(USART, SERIAL_PORT_2, _UDRE_vect)) { - MarlinSerial>::_tx_udr_empty_irq(); - } - - // Preinstantiate - template class MarlinSerial>; - - // Instantiate - MarlinSerial> customizedSerial2; - - #endif - -#endif // !USBCON && (UBRRH || UBRR0H || UBRR1H || UBRR2H || UBRR3H) +#endif #ifdef MMU2_SERIAL_PORT @@ -794,6 +792,8 @@ #endif +#endif // !USBCON && (UBRRH || UBRR0H || UBRR1H || UBRR2H || UBRR3H) + // For AT90USB targets use the UART for BT interfacing #if defined(USBCON) && ENABLED(BLUETOOTH) HardwareSerial bluetoothSerial; From 1bb005d969cb40ce1d3a4c3653aedb259ddfcd5a Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 23 Sep 2020 22:06:39 -0500 Subject: [PATCH 25/33] Ok to keep JTAG off? --- Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h b/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h index 188a3581e26a..a3cb987fff0b 100644 --- a/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h +++ b/Marlin/src/pins/stm32f1/pins_BTT_SKR_E3_DIP.h @@ -28,7 +28,7 @@ #define BOARD_INFO_NAME "BTT SKR E3 DIP V1.0" // Release PB3/PB4 (TMC_SW Pins) from JTAG pins -// #define DISABLE_JTAG +#define DISABLE_JTAG // Ignore temp readings during development. //#define BOGUS_TEMPERATURE_GRACE_PERIOD 2000 From d3d5f917960dcd0ae1b5a5510076670edd6268a2 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Thu, 24 Sep 2020 00:38:07 -0700 Subject: [PATCH 26/33] Remove duplicate LCD_SERIAL check --- Marlin/src/HAL/STM32F1/MarlinSerial.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/Marlin/src/HAL/STM32F1/MarlinSerial.cpp b/Marlin/src/HAL/STM32F1/MarlinSerial.cpp index 9418403c7a6d..3402f8b75826 100644 --- a/Marlin/src/HAL/STM32F1/MarlinSerial.cpp +++ b/Marlin/src/HAL/STM32F1/MarlinSerial.cpp @@ -141,9 +141,6 @@ constexpr bool IsSerialClassAllowed(const HardwareSerial&) { return false; } #ifdef LCD_SERIAL CHECK_CFG_SERIAL(LCD_SERIAL); #endif -#ifdef LCD_SERIAL - CHECK_CFG_SERIAL(LCD_SERIAL); -#endif #if AXIS_HAS_HW_SERIAL(X) CHECK_AXIS_SERIAL(X); #endif From f49dc6b1c0a7db186d64c979c9e739468883ad42 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 24 Sep 2020 19:37:36 -0500 Subject: [PATCH 27/33] Add MSerial::emergency_parser_enabled --- Marlin/src/HAL/AVR/MarlinSerial.cpp | 1 + Marlin/src/HAL/DUE/MarlinSerial.cpp | 1 + Marlin/src/HAL/LINUX/include/serial.h | 1 + Marlin/src/HAL/LPC1768/MarlinSerial.h | 1 + Marlin/src/HAL/LPC1768/usb_serial.cpp | 2 ++ Marlin/src/HAL/STM32/MarlinSerial.h | 4 ++++ Marlin/src/HAL/STM32F1/MarlinSerial.cpp | 14 +++++++------- Marlin/src/HAL/STM32F1/MarlinSerial.h | 15 ++++++++------- Marlin/src/HAL/STM32F1/msc_sd.h | 1 + buildroot/tests/mks_robin_pro-tests | 1 + 10 files changed, 27 insertions(+), 14 deletions(-) diff --git a/Marlin/src/HAL/AVR/MarlinSerial.cpp b/Marlin/src/HAL/AVR/MarlinSerial.cpp index 63599efd4132..a4980138774b 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.cpp +++ b/Marlin/src/HAL/AVR/MarlinSerial.cpp @@ -134,6 +134,7 @@ template FORCE_INLINE void MarlinSerial::store_rxd_char() { static EmergencyParser::State emergency_state; // = EP_RESET + static inline bool emergency_parser_enabled() { return Cfg::EMERGENCYPARSER; } // This must read the R_UCSRA register before reading the received byte to detect error causes if (Cfg::DROPPED_RX && B_DOR && !++rx_dropped_bytes) --rx_dropped_bytes; diff --git a/Marlin/src/HAL/DUE/MarlinSerial.cpp b/Marlin/src/HAL/DUE/MarlinSerial.cpp index c9a372eeb14f..2d53c623222d 100644 --- a/Marlin/src/HAL/DUE/MarlinSerial.cpp +++ b/Marlin/src/HAL/DUE/MarlinSerial.cpp @@ -52,6 +52,7 @@ template FORCE_INLINE void MarlinSerial::store_rxd_char() { static EmergencyParser::State emergency_state; // = EP_RESET + static inline bool emergency_parser_enabled() { return Cfg::EMERGENCYPARSER; } // Get the tail - Nothing can alter its value while we are at this ISR const ring_buffer_pos_t t = rx_buffer.tail; diff --git a/Marlin/src/HAL/LINUX/include/serial.h b/Marlin/src/HAL/LINUX/include/serial.h index 154e95aec262..94e0c758ee12 100644 --- a/Marlin/src/HAL/LINUX/include/serial.h +++ b/Marlin/src/HAL/LINUX/include/serial.h @@ -79,6 +79,7 @@ class HalSerial { #if ENABLED(EMERGENCY_PARSER) EmergencyParser::State emergency_state; + static inline bool emergency_parser_enabled() { return true; } #endif HalSerial() { host_connected = true; } diff --git a/Marlin/src/HAL/LPC1768/MarlinSerial.h b/Marlin/src/HAL/LPC1768/MarlinSerial.h index 98ce73d377a6..8d6b64378a0a 100644 --- a/Marlin/src/HAL/LPC1768/MarlinSerial.h +++ b/Marlin/src/HAL/LPC1768/MarlinSerial.h @@ -57,6 +57,7 @@ class MarlinSerial : public HardwareSerial { } EmergencyParser::State emergency_state; + static inline bool emergency_parser_enabled() { return true; } #endif }; diff --git a/Marlin/src/HAL/LPC1768/usb_serial.cpp b/Marlin/src/HAL/LPC1768/usb_serial.cpp index 63a570efdfa8..d225ce418860 100644 --- a/Marlin/src/HAL/LPC1768/usb_serial.cpp +++ b/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; diff --git a/Marlin/src/HAL/STM32/MarlinSerial.h b/Marlin/src/HAL/STM32/MarlinSerial.h index 5ab97ff3a993..3611cc78d7ce 100644 --- a/Marlin/src/HAL/STM32/MarlinSerial.h +++ b/Marlin/src/HAL/STM32/MarlinSerial.h @@ -35,6 +35,10 @@ class MarlinSerial : public HardwareSerial { #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); } diff --git a/Marlin/src/HAL/STM32F1/MarlinSerial.cpp b/Marlin/src/HAL/STM32F1/MarlinSerial.cpp index 3402f8b75826..ebf11cb429fa 100644 --- a/Marlin/src/HAL/STM32F1/MarlinSerial.cpp +++ b/Marlin/src/HAL/STM32F1/MarlinSerial.cpp @@ -53,7 +53,7 @@ static inline __always_inline void my_usart_irq(ring_buffer *rb, ring_buffer *wb rb_push_insert(rb, c); #endif #if ENABLED(EMERGENCY_PARSER) - if (serial.emergency_parser_enabled) + if (serial.emergency_parser_enabled()) emergency_parser.update(serial.emergency_state, c); #endif } @@ -90,12 +90,12 @@ constexpr bool serial_handles_emergency(int port) { ; } -#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) { \ +#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); \ } diff --git a/Marlin/src/HAL/STM32F1/MarlinSerial.h b/Marlin/src/HAL/STM32F1/MarlinSerial.h index 5c226882f702..f347dd43a046 100644 --- a/Marlin/src/HAL/STM32F1/MarlinSerial.h +++ b/Marlin/src/HAL/STM32F1/MarlinSerial.h @@ -35,10 +35,16 @@ class MarlinSerial : public HardwareSerial { public: - MarlinSerial(struct usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin, bool TERN_(EMERGENCY_PARSER, emergency_parser)) : + #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) - , emergency_parser_enabled(emergency_parser) + , ep_enabled(ep_capable) , emergency_state(EmergencyParser::State::EP_RESET) #endif { } @@ -54,11 +60,6 @@ class MarlinSerial : public HardwareSerial { nvic_irq_set_priority(c_dev()->irq_num, UART_IRQ_PRIO); } #endif - - #if ENABLED(EMERGENCY_PARSER) - bool emergency_parser_enabled; - EmergencyParser::State emergency_state; - #endif }; extern MarlinSerial MSerial1; diff --git a/Marlin/src/HAL/STM32F1/msc_sd.h b/Marlin/src/HAL/STM32F1/msc_sd.h index d9cdbe6bb3d1..1e4e4c44b1b5 100644 --- a/Marlin/src/HAL/STM32F1/msc_sd.h +++ b/Marlin/src/HAL/STM32F1/msc_sd.h @@ -32,6 +32,7 @@ class MarlinUSBCompositeSerial : public USBCompositeSerial { #if ENABLED(EMERGENCY_PARSER) EmergencyParser::State emergency_state; + inline bool emergency_parser_enabled() { return true; } #endif }; diff --git a/buildroot/tests/mks_robin_pro-tests b/buildroot/tests/mks_robin_pro-tests index cfd36832fdef..7ae4670fedac 100644 --- a/buildroot/tests/mks_robin_pro-tests +++ b/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 From 9428396943db923df55bd13d306b4080b45bf4c2 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 24 Sep 2020 19:44:38 -0500 Subject: [PATCH 28/33] Add a bunch of logic --- Marlin/src/HAL/STM32F1/MarlinSerial.cpp | 24 ++++++++++++++++-------- Marlin/src/HAL/STM32F1/MarlinSerial.h | 13 +++++++------ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Marlin/src/HAL/STM32F1/MarlinSerial.cpp b/Marlin/src/HAL/STM32F1/MarlinSerial.cpp index ebf11cb429fa..eaf29440c614 100644 --- a/Marlin/src/HAL/STM32F1/MarlinSerial.cpp +++ b/Marlin/src/HAL/STM32F1/MarlinSerial.cpp @@ -108,15 +108,23 @@ constexpr bool serial_handles_emergency(int port) { my_usart_irq(UART##n->rb, UART##n->wb, UART##n##_BASE, MSerial##n); \ } -// 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); +// Instantiate the required UARTs +#if USING_SERIAL_1 + DEFINE_HWSERIAL_MARLIN(MSerial1, 1); +#endif +#if USING_SERIAL_2 + DEFINE_HWSERIAL_MARLIN(MSerial2, 2); +#endif +#if USING_SERIAL_3 + DEFINE_HWSERIAL_MARLIN(MSerial3, 3); +#endif #if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY) - DEFINE_HWSERIAL_UART_MARLIN(MSerial4, 4); - DEFINE_HWSERIAL_UART_MARLIN(MSerial5, 5); + #if USING_SERIAL_4 + DEFINE_HWSERIAL_UART_MARLIN(MSerial4, 4); + #endif + #if USING_SERIAL_5 + DEFINE_HWSERIAL_UART_MARLIN(MSerial5, 5); + #endif #endif // Check the type of each serial port by passing it to a template function. diff --git a/Marlin/src/HAL/STM32F1/MarlinSerial.h b/Marlin/src/HAL/STM32F1/MarlinSerial.h index f347dd43a046..504593fb6bab 100644 --- a/Marlin/src/HAL/STM32F1/MarlinSerial.h +++ b/Marlin/src/HAL/STM32F1/MarlinSerial.h @@ -50,7 +50,7 @@ class MarlinSerial : public HardwareSerial { { } #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); } @@ -62,10 +62,11 @@ class MarlinSerial : public HardwareSerial { #endif }; -extern MarlinSerial MSerial1; -extern MarlinSerial MSerial2; -extern MarlinSerial MSerial3; +// Declare the required UARTs +TERN_(USING_SERIAL_1, extern MarlinSerial MSerial1); +TERN_(USING_SERIAL_2, extern MarlinSerial MSerial2); +TERN_(USING_SERIAL_3, extern MarlinSerial MSerial3); #if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY) - extern MarlinSerial MSerial4; - extern MarlinSerial MSerial5; + TERN_(USING_SERIAL_4, extern MarlinSerial MSerial4); + TERN_(USING_SERIAL_5, extern MarlinSerial MSerial5); #endif From d98d7d86daece80799bc815d74354bdfb2c037f6 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 24 Sep 2020 19:50:46 -0500 Subject: [PATCH 29/33] Apply to other HALs --- Marlin/src/HAL/LPC1768/MarlinSerial.h | 9 +++++---- Marlin/src/HAL/STM32/MarlinSerial.h | 23 ++++++++++++----------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Marlin/src/HAL/LPC1768/MarlinSerial.h b/Marlin/src/HAL/LPC1768/MarlinSerial.h index 8d6b64378a0a..fc99ce35417e 100644 --- a/Marlin/src/HAL/LPC1768/MarlinSerial.h +++ b/Marlin/src/HAL/LPC1768/MarlinSerial.h @@ -61,7 +61,8 @@ class MarlinSerial : public HardwareSerial { #endif }; -extern MarlinSerial MSerial; -extern MarlinSerial MSerial1; -extern MarlinSerial MSerial2; -extern MarlinSerial MSerial3; +// Declare the required UARTs +TERN_(USING_SERIAL_0, extern MarlinSerial MSerial); +TERN_(USING_SERIAL_1, extern MarlinSerial MSerial1); +TERN_(USING_SERIAL_2, extern MarlinSerial MSerial2); +TERN_(USING_SERIAL_3, extern MarlinSerial MSerial3); diff --git a/Marlin/src/HAL/STM32/MarlinSerial.h b/Marlin/src/HAL/STM32/MarlinSerial.h index 3611cc78d7ce..e28bb530db0f 100644 --- a/Marlin/src/HAL/STM32/MarlinSerial.h +++ b/Marlin/src/HAL/STM32/MarlinSerial.h @@ -51,14 +51,15 @@ class MarlinSerial : public HardwareSerial { #endif }; -extern MarlinSerial MSerial1; -extern MarlinSerial MSerial2; -extern MarlinSerial MSerial3; -extern MarlinSerial MSerial4; -extern MarlinSerial MSerial5; -extern MarlinSerial MSerial6; -extern MarlinSerial MSerial7; -extern MarlinSerial MSerial8; -extern MarlinSerial MSerial9; -extern MarlinSerial MSerial10; -extern MarlinSerial MSerialLP1; +// Declare the required UARTs +TERN_(USING_SERIAL_1, extern MarlinSerial MSerial1); +TERN_(USING_SERIAL_2, extern MarlinSerial MSerial2); +TERN_(USING_SERIAL_3, extern MarlinSerial MSerial3); +TERN_(USING_SERIAL_4, extern MarlinSerial MSerial4); +TERN_(USING_SERIAL_5, extern MarlinSerial MSerial5); +TERN_(USING_SERIAL_6, extern MarlinSerial MSerial6); +TERN_(USING_SERIAL_7, extern MarlinSerial MSerial7); +TERN_(USING_SERIAL_8, extern MarlinSerial MSerial8); +TERN_(USING_SERIAL_9, extern MarlinSerial MSerial9); +TERN_(USING_SERIAL_10, extern MarlinSerial MSerial10); +TERN_(USING_SERIAL_LP1, extern MarlinSerial MSerialLP1); // LPUART From f8d538dd12da6c0e0d1ef2f5fc6472da4490a9bf Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 24 Sep 2020 20:02:26 -0500 Subject: [PATCH 30/33] Fix ep-enabled --- Marlin/src/HAL/AVR/MarlinSerial.cpp | 1 - Marlin/src/HAL/AVR/MarlinSerial.h | 2 ++ Marlin/src/HAL/DUE/MarlinSerial.cpp | 1 - Marlin/src/HAL/DUE/MarlinSerial.h | 2 ++ 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Marlin/src/HAL/AVR/MarlinSerial.cpp b/Marlin/src/HAL/AVR/MarlinSerial.cpp index a4980138774b..63599efd4132 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.cpp +++ b/Marlin/src/HAL/AVR/MarlinSerial.cpp @@ -134,7 +134,6 @@ template FORCE_INLINE void MarlinSerial::store_rxd_char() { static EmergencyParser::State emergency_state; // = EP_RESET - static inline bool emergency_parser_enabled() { return Cfg::EMERGENCYPARSER; } // This must read the R_UCSRA register before reading the received byte to detect error causes if (Cfg::DROPPED_RX && B_DOR && !++rx_dropped_bytes) --rx_dropped_bytes; diff --git a/Marlin/src/HAL/AVR/MarlinSerial.h b/Marlin/src/HAL/AVR/MarlinSerial.h index 6197308bb014..cb906e2b6572 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.h +++ b/Marlin/src/HAL/AVR/MarlinSerial.h @@ -221,6 +221,8 @@ 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; } diff --git a/Marlin/src/HAL/DUE/MarlinSerial.cpp b/Marlin/src/HAL/DUE/MarlinSerial.cpp index 2d53c623222d..c9a372eeb14f 100644 --- a/Marlin/src/HAL/DUE/MarlinSerial.cpp +++ b/Marlin/src/HAL/DUE/MarlinSerial.cpp @@ -52,7 +52,6 @@ template FORCE_INLINE void MarlinSerial::store_rxd_char() { static EmergencyParser::State emergency_state; // = EP_RESET - static inline bool emergency_parser_enabled() { return Cfg::EMERGENCYPARSER; } // Get the tail - Nothing can alter its value while we are at this ISR const ring_buffer_pos_t t = rx_buffer.tail; diff --git a/Marlin/src/HAL/DUE/MarlinSerial.h b/Marlin/src/HAL/DUE/MarlinSerial.h index dfafa1514159..a194eba2f386 100644 --- a/Marlin/src/HAL/DUE/MarlinSerial.h +++ b/Marlin/src/HAL/DUE/MarlinSerial.h @@ -122,6 +122,8 @@ class MarlinSerial { 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; } From 9bfdbee8268365e28cbf23640059aa4ab261ce02 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 24 Sep 2020 20:12:56 -0500 Subject: [PATCH 31/33] Evaluate macro arg --- Marlin/src/inc/Conditionals_adv.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index d3f608e0a476..d8bb1f986b19 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -424,7 +424,8 @@ #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)) +#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)) +#define ANY_SERIAL_IS(N) _ANY_SERIAL_IS(N) #if ANY_SERIAL_IS(-1) #define USING_SERIAL_DEFAULT #endif @@ -455,4 +456,5 @@ #if ANY_SERIAL_IS(8) #define USING_SERIAL_8 1 #endif -#undef ANY_SERIAL_IS +#undef _ANY_SERIAL_IS +#undef ANY_SERIAL_IS From a830dbd4112e2e6f010b10777b981942c40712b2 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 24 Sep 2020 20:22:03 -0500 Subject: [PATCH 32/33] undo 1 --- Marlin/src/inc/Conditionals_adv.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index d8bb1f986b19..d3f608e0a476 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -424,8 +424,7 @@ #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)) -#define ANY_SERIAL_IS(N) _ANY_SERIAL_IS(N) +#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 @@ -456,5 +455,4 @@ #if ANY_SERIAL_IS(8) #define USING_SERIAL_8 1 #endif -#undef _ANY_SERIAL_IS -#undef ANY_SERIAL_IS +#undef ANY_SERIAL_IS From 4c54163fe81a986d0ade68fcd14c159b8ef37553 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 24 Sep 2020 20:22:39 -0500 Subject: [PATCH 33/33] Revert serial logic --- Marlin/src/HAL/LPC1768/MarlinSerial.h | 9 ++++----- Marlin/src/HAL/STM32/MarlinSerial.h | 23 +++++++++++------------ Marlin/src/HAL/STM32F1/MarlinSerial.cpp | 24 ++++++++---------------- Marlin/src/HAL/STM32F1/MarlinSerial.h | 11 +++++------ 4 files changed, 28 insertions(+), 39 deletions(-) diff --git a/Marlin/src/HAL/LPC1768/MarlinSerial.h b/Marlin/src/HAL/LPC1768/MarlinSerial.h index fc99ce35417e..8d6b64378a0a 100644 --- a/Marlin/src/HAL/LPC1768/MarlinSerial.h +++ b/Marlin/src/HAL/LPC1768/MarlinSerial.h @@ -61,8 +61,7 @@ class MarlinSerial : public HardwareSerial { #endif }; -// Declare the required UARTs -TERN_(USING_SERIAL_0, extern MarlinSerial MSerial); -TERN_(USING_SERIAL_1, extern MarlinSerial MSerial1); -TERN_(USING_SERIAL_2, extern MarlinSerial MSerial2); -TERN_(USING_SERIAL_3, extern MarlinSerial MSerial3); +extern MarlinSerial MSerial; +extern MarlinSerial MSerial1; +extern MarlinSerial MSerial2; +extern MarlinSerial MSerial3; diff --git a/Marlin/src/HAL/STM32/MarlinSerial.h b/Marlin/src/HAL/STM32/MarlinSerial.h index e28bb530db0f..3611cc78d7ce 100644 --- a/Marlin/src/HAL/STM32/MarlinSerial.h +++ b/Marlin/src/HAL/STM32/MarlinSerial.h @@ -51,15 +51,14 @@ class MarlinSerial : public HardwareSerial { #endif }; -// Declare the required UARTs -TERN_(USING_SERIAL_1, extern MarlinSerial MSerial1); -TERN_(USING_SERIAL_2, extern MarlinSerial MSerial2); -TERN_(USING_SERIAL_3, extern MarlinSerial MSerial3); -TERN_(USING_SERIAL_4, extern MarlinSerial MSerial4); -TERN_(USING_SERIAL_5, extern MarlinSerial MSerial5); -TERN_(USING_SERIAL_6, extern MarlinSerial MSerial6); -TERN_(USING_SERIAL_7, extern MarlinSerial MSerial7); -TERN_(USING_SERIAL_8, extern MarlinSerial MSerial8); -TERN_(USING_SERIAL_9, extern MarlinSerial MSerial9); -TERN_(USING_SERIAL_10, extern MarlinSerial MSerial10); -TERN_(USING_SERIAL_LP1, extern MarlinSerial MSerialLP1); // LPUART +extern MarlinSerial MSerial1; +extern MarlinSerial MSerial2; +extern MarlinSerial MSerial3; +extern MarlinSerial MSerial4; +extern MarlinSerial MSerial5; +extern MarlinSerial MSerial6; +extern MarlinSerial MSerial7; +extern MarlinSerial MSerial8; +extern MarlinSerial MSerial9; +extern MarlinSerial MSerial10; +extern MarlinSerial MSerialLP1; diff --git a/Marlin/src/HAL/STM32F1/MarlinSerial.cpp b/Marlin/src/HAL/STM32F1/MarlinSerial.cpp index eaf29440c614..ebf11cb429fa 100644 --- a/Marlin/src/HAL/STM32F1/MarlinSerial.cpp +++ b/Marlin/src/HAL/STM32F1/MarlinSerial.cpp @@ -108,23 +108,15 @@ constexpr bool serial_handles_emergency(int port) { my_usart_irq(UART##n->rb, UART##n->wb, UART##n##_BASE, MSerial##n); \ } -// Instantiate the required UARTs -#if USING_SERIAL_1 - DEFINE_HWSERIAL_MARLIN(MSerial1, 1); -#endif -#if USING_SERIAL_2 - DEFINE_HWSERIAL_MARLIN(MSerial2, 2); -#endif -#if USING_SERIAL_3 - DEFINE_HWSERIAL_MARLIN(MSerial3, 3); -#endif +// 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) - #if USING_SERIAL_4 - DEFINE_HWSERIAL_UART_MARLIN(MSerial4, 4); - #endif - #if USING_SERIAL_5 - DEFINE_HWSERIAL_UART_MARLIN(MSerial5, 5); - #endif + DEFINE_HWSERIAL_UART_MARLIN(MSerial4, 4); + DEFINE_HWSERIAL_UART_MARLIN(MSerial5, 5); #endif // Check the type of each serial port by passing it to a template function. diff --git a/Marlin/src/HAL/STM32F1/MarlinSerial.h b/Marlin/src/HAL/STM32F1/MarlinSerial.h index 504593fb6bab..6aa94b64fff7 100644 --- a/Marlin/src/HAL/STM32F1/MarlinSerial.h +++ b/Marlin/src/HAL/STM32F1/MarlinSerial.h @@ -62,11 +62,10 @@ class MarlinSerial : public HardwareSerial { #endif }; -// Declare the required UARTs -TERN_(USING_SERIAL_1, extern MarlinSerial MSerial1); -TERN_(USING_SERIAL_2, extern MarlinSerial MSerial2); -TERN_(USING_SERIAL_3, extern MarlinSerial MSerial3); +extern MarlinSerial MSerial1; +extern MarlinSerial MSerial2; +extern MarlinSerial MSerial3; #if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY) - TERN_(USING_SERIAL_4, extern MarlinSerial MSerial4); - TERN_(USING_SERIAL_5, extern MarlinSerial MSerial5); + extern MarlinSerial MSerial4; + extern MarlinSerial MSerial5; #endif