From 24fbfae0fdb08e5ab970c4b1f6d76d35ad26269b Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Sun, 6 Sep 2020 19:29:43 -0300 Subject: [PATCH] Fix STM32F1 SPI device init, MKS_LCD12864 (#19271) --- Marlin/src/HAL/STM32F1/SPI.cpp | 5 +- .../lcd/dogm/u8g_dev_uc1701_mini12864_HAL.cpp | 1 + Marlin/src/lcd/dogm/ultralcd_DOGM.cpp | 60 +++++++++---------- .../pins/stm32f1/pins_MKS_ROBIN_E3_common.h | 3 - .../src/pins/stm32f1/pins_MKS_ROBIN_LITE3.h | 2 - .../src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h | 4 -- 6 files changed, 33 insertions(+), 42 deletions(-) diff --git a/Marlin/src/HAL/STM32F1/SPI.cpp b/Marlin/src/HAL/STM32F1/SPI.cpp index 423772dbc9..0452cf6293 100644 --- a/Marlin/src/HAL/STM32F1/SPI.cpp +++ b/Marlin/src/HAL/STM32F1/SPI.cpp @@ -40,6 +40,9 @@ #include #include +#include "../../inc/MarlinConfig.h" +#include "spi_pins.h" + /** Time in ms for DMA receive timeout */ #define DMA_TIMEOUT 100 @@ -710,6 +713,6 @@ static spi_baud_rate determine_baud_rate(spi_dev *dev, uint32_t freq) { return baud_rates[i]; } -SPIClass SPI(1); +SPIClass SPI(SPI_DEVICE); #endif // __STM32F1__ diff --git a/Marlin/src/lcd/dogm/u8g_dev_uc1701_mini12864_HAL.cpp b/Marlin/src/lcd/dogm/u8g_dev_uc1701_mini12864_HAL.cpp index 85339e8349..e4e387c190 100644 --- a/Marlin/src/lcd/dogm/u8g_dev_uc1701_mini12864_HAL.cpp +++ b/Marlin/src/lcd/dogm/u8g_dev_uc1701_mini12864_HAL.cpp @@ -112,6 +112,7 @@ static const uint8_t u8g_dev_uc1701_mini12864_HAL_init_seq[] PROGMEM = { U8G_ESC_CS(1), // enable chip UC1701_ALL_PIX(0), // normal display U8G_ESC_CS(0), // disable chip + U8G_ESC_DLY(150), // delay 150 ms before sending any data U8G_ESC_END // end of sequence }; diff --git a/Marlin/src/lcd/dogm/ultralcd_DOGM.cpp b/Marlin/src/lcd/dogm/ultralcd_DOGM.cpp index 7ebabd6950..bf0edbb8de 100644 --- a/Marlin/src/lcd/dogm/ultralcd_DOGM.cpp +++ b/Marlin/src/lcd/dogm/ultralcd_DOGM.cpp @@ -240,39 +240,35 @@ bool MarlinUI::detected() { return true; } // Initialize or re-initialize the LCD void MarlinUI::init_lcd() { - #if DISABLED(MKS_LCD12864) - - #if PIN_EXISTS(LCD_BACKLIGHT) - OUT_WRITE(LCD_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT)); // Illuminate after reset or right away - #endif - - #if ANY(MKS_12864OLED, MKS_12864OLED_SSD1306, FYSETC_242_OLED_12864, ZONESTAR_12864OLED) - SET_OUTPUT(LCD_PINS_DC); - #ifndef LCD_RESET_PIN - #define LCD_RESET_PIN LCD_PINS_RS - #endif - #endif - - #if PIN_EXISTS(LCD_RESET) - // Perform a clean hardware reset with needed delays - OUT_WRITE(LCD_RESET_PIN, LOW); - _delay_ms(5); - WRITE(LCD_RESET_PIN, HIGH); - _delay_ms(5); - u8g.begin(); + #if PIN_EXISTS(LCD_BACKLIGHT) + OUT_WRITE(LCD_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT)); // Illuminate after reset or right away + #endif + + #if ANY(MKS_12864OLED, MKS_12864OLED_SSD1306, FYSETC_242_OLED_12864, ZONESTAR_12864OLED) + SET_OUTPUT(LCD_PINS_DC); + #ifndef LCD_RESET_PIN + #define LCD_RESET_PIN LCD_PINS_RS #endif - - #if PIN_EXISTS(LCD_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT) - WRITE(LCD_BACKLIGHT_PIN, HIGH); - #endif - - TERN_(HAS_LCD_CONTRAST, refresh_contrast()); - - TERN_(LCD_SCREEN_ROT_90, u8g.setRot90()); - TERN_(LCD_SCREEN_ROT_180, u8g.setRot180()); - TERN_(LCD_SCREEN_ROT_270, u8g.setRot270()); - - #endif // !MKS_LCD12864 + #endif + + #if PIN_EXISTS(LCD_RESET) + // Perform a clean hardware reset with needed delays + OUT_WRITE(LCD_RESET_PIN, LOW); + _delay_ms(5); + WRITE(LCD_RESET_PIN, HIGH); + _delay_ms(5); + u8g.begin(); + #endif + + #if PIN_EXISTS(LCD_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT) + WRITE(LCD_BACKLIGHT_PIN, HIGH); + #endif + + TERN_(HAS_LCD_CONTRAST, refresh_contrast()); + + TERN_(LCD_SCREEN_ROT_90, u8g.setRot90()); + TERN_(LCD_SCREEN_ROT_180, u8g.setRot180()); + TERN_(LCD_SCREEN_ROT_270, u8g.setRot270()); uxg_SetUtf8Fonts(g_fontinfo, COUNT(g_fontinfo)); } 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 1346e8099a..9461a828af 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h @@ -33,7 +33,6 @@ //#define DISABLE_DEBUG #define DISABLE_JTAG -#define ENABLE_SPI2 // // EEPROM @@ -152,8 +151,6 @@ #define DOGLCD_SCK PB13 #define DOGLCD_MOSI PB15 - #undef SHOW_BOOTSCREEN - #else #define LCD_PINS_D4 PA6 diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_LITE3.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_LITE3.h index 9cf8685dfa..6ce6c60105 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_LITE3.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_LITE3.h @@ -115,8 +115,6 @@ #define DOGLCD_SCK PB13 #define DOGLCD_MOSI PB15 - #undef SHOW_BOOTSCREEN - #else // !MKS_MINI_12864 #define LCD_PINS_D4 PA6 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 228049d139..1295c7c46b 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h @@ -351,10 +351,6 @@ #define DOGLCD_SCK PA5 #define DOGLCD_MOSI PA7 - // Required for MKS_MINI_12864 with this board - #define MKS_LCD12864B - #undef SHOW_BOOTSCREEN - #else // !MKS_MINI_12864 #define LCD_PINS_D4 PE14