From 76d4a395d1a3d9d24f308ce6deb19c8767f04105 Mon Sep 17 00:00:00 2001 From: ellensp Date: Sun, 6 Jun 2021 21:21:14 +1200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Fallback=20ID=20for=20MKS=20TS35?= =?UTF-8?q?=20V2.0=20(#22031)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/HAL/STM32/tft/tft_spi.cpp | 12 ++++++-- Marlin/src/HAL/STM32F1/tft/tft_spi.cpp | 12 ++++++-- Marlin/src/inc/Conditionals_LCD.h | 31 ++++++++++---------- Marlin/src/lcd/tft_io/tft_ids.h | 35 +++++++++++++++++++++++ Marlin/src/lcd/tft_io/tft_io.cpp | 39 +++++++++++++++++++------- Marlin/src/lcd/tft_io/tft_io.h | 35 ++++++----------------- 6 files changed, 109 insertions(+), 55 deletions(-) create mode 100644 Marlin/src/lcd/tft_io/tft_ids.h diff --git a/Marlin/src/HAL/STM32/tft/tft_spi.cpp b/Marlin/src/HAL/STM32/tft/tft_spi.cpp index 32af67d15..6bfce81f1 100644 --- a/Marlin/src/HAL/STM32/tft/tft_spi.cpp +++ b/Marlin/src/HAL/STM32/tft/tft_spi.cpp @@ -125,12 +125,20 @@ void TFT_SPI::DataTransferBegin(uint16_t DataSize) { WRITE(TFT_CS_PIN, LOW); } +#ifdef TFT_DEFAULT_DRIVER + #include "../../../lcd/tft_io/tft_ids.h" +#endif + uint32_t TFT_SPI::GetID() { uint32_t id; id = ReadID(LCD_READ_ID); - - if ((id & 0xFFFF) == 0 || (id & 0xFFFF) == 0xFFFF) + if ((id & 0xFFFF) == 0 || (id & 0xFFFF) == 0xFFFF) { id = ReadID(LCD_READ_ID4); + #ifdef TFT_DEFAULT_DRIVER + if ((id & 0xFFFF) == 0 || (id & 0xFFFF) == 0xFFFF) + id = TFT_DEFAULT_DRIVER; + #endif + } return id; } diff --git a/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp b/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp index 109538994..5edf96fe5 100644 --- a/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp +++ b/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp @@ -90,12 +90,20 @@ void TFT_SPI::DataTransferBegin(uint16_t DataSize) { TFT_CS_L; } +#ifdef TFT_DEFAULT_DRIVER + #include "../../../lcd/tft_io/tft_ids.h" +#endif + uint32_t TFT_SPI::GetID() { uint32_t id; id = ReadID(LCD_READ_ID); - - if ((id & 0xFFFF) == 0 || (id & 0xFFFF) == 0xFFFF) + if ((id & 0xFFFF) == 0 || (id & 0xFFFF) == 0xFFFF) { id = ReadID(LCD_READ_ID4); + #ifdef TFT_DEFAULT_DRIVER + if ((id & 0xFFFF) == 0 || (id & 0xFFFF) == 0xFFFF) + id = TFT_DEFAULT_DRIVER; + #endif + } return id; } diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 07c0439e2..445cc3c06 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -1166,29 +1166,38 @@ * - TFT_COLOR * - GRAPHICAL_TFT_UPSCALE */ -#if ENABLED(MKS_TS35_V2_0) // Most common: ST7796 +#if ENABLED(MKS_TS35_V2_0) // ST7796 + #define TFT_DEFAULT_DRIVER ST7796 #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY) #define TFT_RES_480x320 #define TFT_INTERFACE_SPI -#elif ENABLED(MKS_ROBIN_TFT24) // Most common: ST7789 +#elif ENABLED(ANET_ET5_TFT35) // ST7796 + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY) + #define TFT_RES_480x320 + #define TFT_INTERFACE_FSMC +#elif ENABLED(ANET_ET4_TFT28) // ST7789 #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_Y) #define TFT_RES_320x240 #define TFT_INTERFACE_FSMC -#elif ENABLED(MKS_ROBIN_TFT28) // Most common: ST7789 +#elif ENABLED(MKS_ROBIN_TFT24) // ST7789 #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_Y) #define TFT_RES_320x240 #define TFT_INTERFACE_FSMC -#elif ENABLED(MKS_ROBIN_TFT32) // Most common: ST7789 +#elif ENABLED(MKS_ROBIN_TFT28) // ST7789 #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_Y) #define TFT_RES_320x240 #define TFT_INTERFACE_FSMC -#elif ENABLED(MKS_ROBIN_TFT35) // Most common: ILI9488 +#elif ENABLED(MKS_ROBIN_TFT32) // ST7789 + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_Y) + #define TFT_RES_320x240 + #define TFT_INTERFACE_FSMC +#elif ENABLED(MKS_ROBIN_TFT35) // ILI9488 #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y) #define TFT_RES_480x320 #define TFT_INTERFACE_FSMC #elif ENABLED(MKS_ROBIN_TFT43) - #define TFT_DEFAULT_ORIENTATION 0 #define TFT_DRIVER SSD1963 + #define TFT_DEFAULT_ORIENTATION 0 #define TFT_RES_480x272 #define TFT_INTERFACE_FSMC #elif ENABLED(MKS_ROBIN_TFT_V1_1R) // ILI9328 or R61505 @@ -1196,22 +1205,14 @@ #define TFT_RES_320x240 #define TFT_INTERFACE_FSMC #elif EITHER(TFT_TRONXY_X5SA, ANYCUBIC_TFT35) // ILI9488 - #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y) #define TFT_DRIVER ILI9488 + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y) #define TFT_RES_480x320 #define TFT_INTERFACE_FSMC #elif ENABLED(LONGER_LK_TFT28) #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y) #define TFT_RES_320x240 #define TFT_INTERFACE_FSMC -#elif ENABLED(ANET_ET4_TFT28) // ST7789 - #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_Y) - #define TFT_RES_320x240 - #define TFT_INTERFACE_FSMC -#elif ENABLED(ANET_ET5_TFT35) // ST7796 - #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY) - #define TFT_RES_480x320 - #define TFT_INTERFACE_FSMC #elif ENABLED(BIQU_BX_TFT70) // RGB #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY) #define TFT_RES_1024x600 diff --git a/Marlin/src/lcd/tft_io/tft_ids.h b/Marlin/src/lcd/tft_io/tft_ids.h new file mode 100644 index 000000000..c4f6127c6 --- /dev/null +++ b/Marlin/src/lcd/tft_io/tft_ids.h @@ -0,0 +1,35 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#define LTDC_RGB 0xABAB +#define SSD1963 0x5761 +#define ST7735 0x89F0 +#define ST7789 0x8552 +#define ST7796 0x7796 +#define R61505 0x1505 +#define ILI9328 0x9328 +#define ILI9341 0x9341 +#define ILI9488 0x9488 +#define ILI9488_ID1 0x8066 // Some ILI9488 have 0x8066 in the 0x04 +#define LERDGE_ST7796 0xFFFE +#define AUTO 0xFFFF diff --git a/Marlin/src/lcd/tft_io/tft_io.cpp b/Marlin/src/lcd/tft_io/tft_io.cpp index fa81d95a4..c06e86b28 100644 --- a/Marlin/src/lcd/tft_io/tft_io.cpp +++ b/Marlin/src/lcd/tft_io/tft_io.cpp @@ -20,18 +20,37 @@ * */ -#include "tft_io.h" +#include "../../inc/MarlinConfigPre.h" #if HAS_SPI_TFT || HAS_FSMC_TFT || HAS_LTDC_TFT -#include "st7735.h" -#include "st7789v.h" -#include "st7796s.h" -#include "r65105.h" -#include "ili9328.h" -#include "ili9341.h" -#include "ili9488.h" -#include "ssd1963.h" +#include "tft_io.h" +#include "tft_ids.h" + +#if TFT_DRIVER == ST7735 || TFT_DRIVER == AUTO + #include "st7735.h" +#endif +#if TFT_DRIVER == ST7789 || TFT_DRIVER == AUTO + #include "st7789v.h" +#endif +#if TFT_DRIVER == ST7796 || TFT_DRIVER == AUTO + #include "st7796s.h" +#endif +#if TFT_DRIVER == R61505 || TFT_DRIVER == AUTO + #include "r65105.h" +#endif +#if TFT_DRIVER == ILI9328 || TFT_DRIVER == AUTO + #include "ili9328.h" +#endif +#if TFT_DRIVER == ILI9341 || TFT_DRIVER == AUTO + #include "ili9341.h" +#endif +#if TFT_DRIVER == ILI9488 || TFT_DRIVER == ILI9488_ID1 || TFT_DRIVER == AUTO + #include "ili9488.h" +#endif +#if TFT_DRIVER == SSD1963 || TFT_DRIVER == AUTO + #include "ssd1963.h" +#endif #define DEBUG_OUT ENABLED(DEBUG_GRAPHICAL_TFT) #include "../../core/debug_out.h" @@ -236,4 +255,4 @@ void TFT_IO::write_esc_sequence(const uint16_t *Sequence) { io.DataTransferEnd(); } -#endif // HAS_SPI_TFT || HAS_FSMC_TFT +#endif // HAS_SPI_TFT || HAS_FSMC_TFT || HAS_LTDC_TFT diff --git a/Marlin/src/lcd/tft_io/tft_io.h b/Marlin/src/lcd/tft_io/tft_io.h index 846b45e8e..0e4322f0d 100644 --- a/Marlin/src/lcd/tft_io/tft_io.h +++ b/Marlin/src/lcd/tft_io/tft_io.h @@ -23,8 +23,6 @@ #include "../../inc/MarlinConfig.h" -#if HAS_SPI_TFT || HAS_FSMC_TFT || HAS_LTDC_TFT - #if HAS_SPI_TFT #include HAL_PATH(../../HAL, tft/tft_spi.h) #elif HAS_FSMC_TFT @@ -35,9 +33,9 @@ #error "TFT IO only supports SPI, FSMC or LTDC interface" #endif -#define TFT_EXCHANGE_XY (1UL << 1) -#define TFT_INVERT_X (1UL << 2) -#define TFT_INVERT_Y (1UL << 3) +#define TFT_EXCHANGE_XY _BV32(1) +#define TFT_INVERT_X _BV32(2) +#define TFT_INVERT_Y _BV32(3) #define TFT_NO_ROTATION (0x00) #define TFT_ROTATE_90 (TFT_EXCHANGE_XY | TFT_INVERT_X) @@ -65,8 +63,8 @@ // TFT_ORIENTATION is the "sum" of TFT_DEFAULT_ORIENTATION plus user TFT_ROTATION #define TFT_ORIENTATION ((TFT_DEFAULT_ORIENTATION) ^ (TFT_ROTATION)) -#define TFT_COLOR_RGB (1UL << 3) -#define TFT_COLOR_BGR (1UL << 4) +#define TFT_COLOR_RGB _BV32(3) +#define TFT_COLOR_BGR _BV32(4) // Each TFT Driver is responsible for its default color mode. // #ifndef TFT_COLOR @@ -93,27 +91,14 @@ #define TOUCH_ORIENTATION TOUCH_LANDSCAPE #endif -#define LTDC_RGB 0xABAB -#define SSD1963 0x5761 -#define ST7735 0x89F0 -#define ST7789 0x8552 -#define ST7796 0x7796 -#define R61505 0x1505 -#define ILI9328 0x9328 -#define ILI9341 0x9341 -#define ILI9488 0x9488 -#define ILI9488_ID1 0x8066 //Some ILI9488 have 0x8066 in the 0x04 -#define LERDGE_ST7796 0xFFFE -#define AUTO 0xFFFF - #ifndef TFT_DRIVER #define TFT_DRIVER AUTO #endif -#define ESC_REG(x) 0xFFFF, 0x00FF & (uint16_t)x -#define ESC_DELAY(x) 0xFFFF, 0x8000 | (x & 0x7FFF) -#define ESC_END 0xFFFF, 0x7FFF -#define ESC_FFFF 0xFFFF, 0xFFFF +#define ESC_REG(x) 0xFFFF, 0x00FF & (uint16_t)x +#define ESC_DELAY(x) 0xFFFF, 0x8000 | (x & 0x7FFF) +#define ESC_END 0xFFFF, 0x7FFF +#define ESC_FFFF 0xFFFF, 0xFFFF class TFT_IO { public: @@ -143,5 +128,3 @@ public: protected: static uint32_t lcd_id; }; - -#endif // HAS_SPI_TFT || HAS_FSMC_TFT