From 55709b9d2cebdea036761925c8f42da305c4efd3 Mon Sep 17 00:00:00 2001 From: Johan van der Vyver <9843081+jvandervyver@users.noreply.github.com> Date: Wed, 13 Jan 2021 02:05:49 +0200 Subject: [PATCH] Multi-platform DWIN_CREALITY_LCD support (#20738) Co-authored-by: Scott Lahteine --- Marlin/src/HAL/STM32F1/HAL.h | 5 ++- Marlin/src/MarlinCore.cpp | 3 +- Marlin/src/inc/Conditionals_LCD.h | 3 ++ Marlin/src/lcd/dwin/dwin_lcd.cpp | 15 +++++-- Marlin/src/lcd/dwin/e3v2/dwin.cpp | 21 ++++++---- Marlin/src/lcd/dwin/e3v2/dwin.h | 3 +- .../anycubic_i3mega/anycubic_i3mega_lcd.cpp | 15 +++---- .../src/lcd/extui/lib/mks_ui/wifi_module.cpp | 39 +++++++++---------- Marlin/src/module/settings.cpp | 4 -- Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h | 15 ++++++- 10 files changed, 73 insertions(+), 50 deletions(-) diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h index 7163db43a2..a193fe05c8 100644 --- a/Marlin/src/HAL/STM32F1/HAL.h +++ b/Marlin/src/HAL/STM32F1/HAL.h @@ -109,8 +109,9 @@ #else #error "LCD_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration." #endif - - #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite() + #if HAS_DGUS_LCD + #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite() + #endif #endif // Set interrupt grouping for this MCU diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 343700e9f7..f994e2e32c 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -995,8 +995,9 @@ void setup() { #endif MYSERIAL0.begin(BAUDRATE); - uint32_t serial_connect_timeout = millis() + 1000UL; + millis_t serial_connect_timeout = millis() + 1000UL; while (!MYSERIAL0 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } + #if HAS_MULTI_SERIAL && !HAS_ETHERNET MYSERIAL1.begin(BAUDRATE); serial_connect_timeout = millis() + 1000UL; diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 79b65e7a9b..a5bb24f27c 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -651,6 +651,9 @@ #if ENABLED(DWIN_CREALITY_LCD) #define SERIAL_CATCHALL 0 + #ifndef LCD_SERIAL_PORT + #define LCD_SERIAL_PORT 3 // Creality 4.x board + #endif #endif /** diff --git a/Marlin/src/lcd/dwin/dwin_lcd.cpp b/Marlin/src/lcd/dwin/dwin_lcd.cpp index 7d1528bed1..1978c6a4f8 100644 --- a/Marlin/src/lcd/dwin/dwin_lcd.cpp +++ b/Marlin/src/lcd/dwin/dwin_lcd.cpp @@ -82,20 +82,27 @@ inline void DWIN_String(size_t &i, const __FlashStringHelper * string) { // Send the data in the buffer and the packet end inline void DWIN_Send(size_t &i) { ++i; - LOOP_L_N(n, i) { MYSERIAL1.write(DWIN_SendBuf[n]); delayMicroseconds(1); } - LOOP_L_N(n, 4) { MYSERIAL1.write(DWIN_BufTail[n]); delayMicroseconds(1); } + LOOP_L_N(n, i) { LCD_SERIAL.write(DWIN_SendBuf[n]); delayMicroseconds(1); } + LOOP_L_N(n, 4) { LCD_SERIAL.write(DWIN_BufTail[n]); delayMicroseconds(1); } } /*-------------------------------------- System variable function --------------------------------------*/ // Handshake (1: Success, 0: Fail) bool DWIN_Handshake(void) { + #ifndef LCD_BAUDRATE + #define LCD_BAUDRATE 115200 + #endif + LCD_SERIAL.begin(LCD_BAUDRATE); + const millis_t serial_connect_timeout = millis() + 1000UL; + while (!LCD_SERIAL && PENDING(millis(), serial_connect_timeout)) { /*nada*/ } + size_t i = 0; DWIN_Byte(i, 0x00); DWIN_Send(i); - while (MYSERIAL1.available() > 0 && recnum < (signed)sizeof(databuf)) { - databuf[recnum] = MYSERIAL1.read(); + while (LCD_SERIAL.available() > 0 && recnum < (signed)sizeof(databuf)) { + databuf[recnum] = LCD_SERIAL.read(); // ignore the invalid data if (databuf[0] != FHONE) { // prevent the program from running. if (recnum > 0) { diff --git a/Marlin/src/lcd/dwin/e3v2/dwin.cpp b/Marlin/src/lcd/dwin/e3v2/dwin.cpp index 5a9d555970..5adf6e8abb 100644 --- a/Marlin/src/lcd/dwin/e3v2/dwin.cpp +++ b/Marlin/src/lcd/dwin/e3v2/dwin.cpp @@ -497,14 +497,21 @@ inline void Draw_Back_First(const bool is_sel=true) { if (is_sel) Draw_Menu_Cursor(0); } -inline bool Apply_Encoder(const ENCODER_DiffState &encoder_diffState, auto &valref) { - if (encoder_diffState == ENCODER_DIFF_CW) - valref += EncoderRate.encoderMoveValue; - else if (encoder_diffState == ENCODER_DIFF_CCW) - valref -= EncoderRate.encoderMoveValue; - else if (encoder_diffState == ENCODER_DIFF_ENTER) - return true; +#define APPLY_ENCODER_F \ + if (encoder_diffState == ENCODER_DIFF_CW) \ + valref += EncoderRate.encoderMoveValue; \ + else if (encoder_diffState == ENCODER_DIFF_CCW) \ + valref -= EncoderRate.encoderMoveValue; \ + else if (encoder_diffState == ENCODER_DIFF_ENTER) \ + return true; \ return false; + +inline bool Apply_Encoder(const ENCODER_DiffState &encoder_diffState, int16_t &valref) { + APPLY_ENCODER_F +} + +inline bool Apply_Encoder(const ENCODER_DiffState &encoder_diffState, float &valref) { + APPLY_ENCODER_F } // diff --git a/Marlin/src/lcd/dwin/e3v2/dwin.h b/Marlin/src/lcd/dwin/e3v2/dwin.h index 8f17c30609..80bc93dcc5 100644 --- a/Marlin/src/lcd/dwin/e3v2/dwin.h +++ b/Marlin/src/lcd/dwin/e3v2/dwin.h @@ -249,7 +249,8 @@ typedef struct { float Move_E_scale = 0; #endif float offset_value = 0; - char show_mode = 0; // -1: Temperature control 0: Printing temperature + TERN_(__STM32F1__, signed) + char show_mode = 0; // -1: Temperature control 0: Printing temperature } HMI_value_t; #define DWIN_CHINESE 123 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 6d15d937b9..72e5f1d14d 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 @@ -592,15 +592,12 @@ void AnycubicTFTClass::GetCommandFromTFT() { } break; case 5: { // A5 GET CURRENT COORDINATE - float xPostition = ExtUI::getAxisPosition_mm(ExtUI::X); - float yPostition = ExtUI::getAxisPosition_mm(ExtUI::Y); - float zPostition = ExtUI::getAxisPosition_mm(ExtUI::Z); - SEND_PGM("A5V X: "); - LCD_SERIAL.print(xPostition); - SEND_PGM(" Y: "); - LCD_SERIAL.print(yPostition); - SEND_PGM(" Z: "); - LCD_SERIAL.print(zPostition); + const float xPosition = ExtUI::getAxisPosition_mm(ExtUI::X), + yPosition = ExtUI::getAxisPosition_mm(ExtUI::Y), + zPosition = ExtUI::getAxisPosition_mm(ExtUI::Z); + SEND_PGM("A5V X: "); LCD_SERIAL.print(xPosition); + SEND_PGM( " Y: "); LCD_SERIAL.print(yPosition); + SEND_PGM( " Z: "); LCD_SERIAL.print(zPosition); SENDLINE_PGM(""); } break; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/wifi_module.cpp b/Marlin/src/lcd/extui/lib/mks_ui/wifi_module.cpp index eeeff4fa31..f38145aa80 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/wifi_module.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/wifi_module.cpp @@ -282,27 +282,24 @@ void esp_port_begin(uint8_t interrupt) { dma_init(); } #endif - if (interrupt) { - #if ENABLED(MKS_WIFI_MODULE) - WIFISERIAL.end(); - for (uint16_t i = 0; i < 65535; i++); - WIFISERIAL.begin(WIFI_BAUDRATE); - uint32_t serial_connect_timeout = millis() + 1000UL; - while (/*!WIFISERIAL && */PENDING(millis(), serial_connect_timeout)) { /*nada*/ } - //for (uint8_t i=0;i<100;i++)WIFISERIAL.write(0x33); - #endif - } - else { - #if ENABLED(MKS_WIFI_MODULE) - WIFISERIAL.end(); - for (uint16_t i = 0; i < 65535; i++); - WIFISERIAL.begin(WIFI_UPLOAD_BAUDRATE); - uint32_t serial_connect_timeout = millis() + 1000UL; - while (/*!WIFISERIAL && */PENDING(millis(), serial_connect_timeout)) { /*nada*/ } - //for (uint16_t i=0;i<65535;i++);//WIFISERIAL.write(0x33); - #endif - dma_init(); - } + + #if ENABLED(MKS_WIFI_MODULE) + WIFISERIAL.end(); + for (uint16_t i = 0; i < 65535; i++) { /*nada*/ } + WIFISERIAL.begin(interrupt ? WIFI_BAUDRATE : WIFI_UPLOAD_BAUDRATE); + + const millis_t serial_connect_timeout = millis() + 1000UL; + while (/*!WIFISERIAL && */PENDING(millis(), serial_connect_timeout)) { /*nada*/ } + + if (interrupt) { + //for (uint8_t i=0;i<100;i++) WIFISERIAL.write(0x33); + } + else { + //for (uint16_t i=0;i<65535;i++); //WIFISERIAL.write(0x33); + } + #endif + + if (!interrupt) dma_init(); } #if ENABLED(MKS_WIFI_MODULE) diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index e667696007..0728840f5b 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -50,10 +50,6 @@ #include "stepper.h" #include "temperature.h" -#if ENABLED(DWIN_CREALITY_LCD) - #include "../lcd/dwin/e3v2/dwin.h" -#endif - #include "../lcd/marlinui.h" #include "../libs/vector_3.h" // for matrix_3x3 #include "../gcode/gcode.h" diff --git a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h index 7500431d54..2e9aba02cf 100644 --- a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h +++ b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h @@ -258,7 +258,20 @@ * EXP2 EXP1 */ -#if HAS_WIRED_LCD && !HAS_BTT_EXP_MOT +#if ENABLED(DWIN_CREALITY_LCD) + + // RET6 DWIN ENCODER LCD + #define BTN_ENC P1_20 + #define BTN_EN1 P1_23 + #define BTN_EN2 P1_22 + + #ifndef BEEPER_PIN + #define BEEPER_PIN P1_21 + #undef SPEAKER + #endif + +#elif HAS_WIRED_LCD && !HAS_BTT_EXP_MOT + #if ENABLED(ANET_FULL_GRAPHICS_LCD_ALT_WIRING) #error "CAUTION! ANET_FULL_GRAPHICS_LCD_ALT_WIRING requires wiring modifications. See 'pins_BTT_SKR_V1_4.h' for details. Comment out this line to continue."