Skip to content

Commit

Permalink
TFT Refactoring (MarlinFirmware#19192)
Browse files Browse the repository at this point in the history
* split tft folder in two: tft for color ui; tft_io for shared tft code

* after the files got moved, now the code was moved to the right place

* classic ui using TFT IO init lcd codes

* feature to compile tft_io when enabled

* compiling fix

* lvgl spi tft working with tft io init codes

* there is no need for separeted fsmc and spi class in lvgl anymore, as tft io handle everything

* remove debug

* base for TFT rotation and mirroring API, and ILI9488 support

* ST7796S rotate and mirror support

* ST7789V rotate and mirror support

* ST7735 rotate and mirror support

* ILI9341 rotate and mirror support

* ILI9328 rotate and mirror support

* R61505 rotate and mirror support

* MKS TFT definitions

* more configs for mks tfts

* update config

* naming typo

* to configure the user interface

* ANYCUBIC_TFT35

* tft configs

* support for SSD1963

* tft display types

* updated conditionals lcd; first board fully working with the new code - all 3 ui!

* compatiblity

* changed name

* move classic ui file name

* rename TURN -> ROTATE

* GRAPHICAL_TFT_ROTATE_180 deprecated

* first fsmc board fully working - chitu v5

* mks robin nano v1.2 + tft 35 ok!

* right pin name

* anycubic tft tested in a TRIGORILLA_PRO

* chitu v6

* nano 32 tft orientation

* mks tft43

* mks tft43 rotation

* fixed LONGER LK tft setup

* GRAPHICAL_TFT_UPSCALE defined by the display type

* better offsets defaults

* Update Configuration.h

* Update tft_fsmc.cpp

* Update Conditionals_LCD.h

* Tweak comments

* update nano tests

* Revert "update nano tests"

This reverts commit a071ebb.

* default tft

* outdated comments

* to not break non-vscode builds

* upscale tft 35

* support tft 180 rotation for color ui

* Each TFT Driver is responsible for its default color mode.

* use auto detect in mks displays, because some of them could be shipped with diferent drivers

* extra s

* unused code

* wrong -1

* missing mirror options

* Smaller regex pattern

* Comment updates

* Clean up old defines

* Apply pins formatting

* GRAPHICAL_TFT_ROTATE_180 => TFT_ROTATE_180

* MKS_ROBIN_TFT_V1_1R

* merge fix

* correct resolution

* auto is default, dont need be there, and it will allow the user to configure it even for named displays

* to not use rotation with MKS_ROBIN_TFT_V1_1R

* i like () in macros

* avoid sleepy commits

* default for st7789 is rgb

* nano follow up

* to allow ili9328 rotation

* default is rgb

* boards merge follow up

* to match bootloader orientation

* HAS_TOUCH_XPT2046 is not hal specific anymore

* lets not forget LPC

* 180 rotation for ili9328 and R61505

* Clean up whitespace

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
Co-authored-by: Scott Lahteine <github@thinkyhead.com>
  • Loading branch information
3 people authored and walterp1982 committed Aug 15, 2022
1 parent cc5063e commit 3e32344
Show file tree
Hide file tree
Showing 39 changed files with 3,768 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -3005,10 +3005,54 @@
//=============================== Graphical TFTs ==============================
//=============================================================================

<<<<<<< HEAD
//
// FSMC display (MKS Robin, Alfawise U20, JGAurora A5S, REXYZ A1, etc.)
//
//#define FSMC_GRAPHICAL_TFT
=======
/**
* TFT Type - Select your Display type
*
* Available options are:
* MKS_TS35_V2_0,
* MKS_ROBIN_TFT24, MKS_ROBIN_TFT28, MKS_ROBIN_TFT32, MKS_ROBIN_TFT35,
* MKS_ROBIN_TFT43, MKS_ROBIN_TFT_V1_1R
* TFT_TRONXY_X5SA, ANYCUBIC_TFT35, LONGER_LK_TFT28
* TFT_GENERIC
*
* For TFT_GENERIC, you need to configure these 3 options:
* Driver: TFT_DRIVER
* Current Drivers are: AUTO, ST7735, ST7789, ST7796, R61505, ILI9328, ILI9341, ILI9488
* Resolution: TFT_WIDTH and TFT_HEIGHT
* Interface: TFT_INTERFACE_FSMC or TFT_INTERFACE_SPI
*/
//#define TFT_GENERIC

/**
* TFT UI - User Interface Selection. Enable one of the following options:
*
* TFT_CLASSIC_UI - Emulated DOGM - 128x64 Upscaled
* TFT_COLOR_UI - Marlin Default Menus, Touch Friendly, using full TFT capabilities
* TFT_LVGL_UI - A Modern UI using LVGL
*
* For LVGL_UI also copy the 'assets' folder from the build directory to the
* root of your SD card, together with the compiled firmware.
*/
//#define TFT_CLASSIC_UI
//#define TFT_COLOR_UI
//#define TFT_LVGL_UI

/**
* TFT Rotation. Set to one of the following values:
*
* TFT_ROTATE_90, TFT_ROTATE_90_MIRROR_X, TFT_ROTATE_90_MIRROR_Y,
* TFT_ROTATE_180, TFT_ROTATE_180_MIRROR_X, TFT_ROTATE_180_MIRROR_Y,
* TFT_ROTATE_270, TFT_ROTATE_270_MIRROR_X, TFT_ROTATE_270_MIRROR_Y,
* TFT_MIRROR_X, TFT_MIRROR_Y, TFT_NO_ROTATION
*/
//#define TFT_ROTATION TFT_NO_ROTATION
>>>>>>> faae900747 (TFT Refactoring (#19192))

//=============================================================================
//============================ Other Controllers ============================
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/HAL/STM32/tft/tft_fsmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@
#define LCD_READ_ID4 0xD3 // Read display identification information (0xD3 on ILI9341)
#endif

<<<<<<< HEAD
#define DATASIZE_8BIT SPI_DATASIZE_8BIT
#define DATASIZE_16BIT SPI_DATASIZE_16BIT
#define TFT_IO_DRIVER TFT_FSMC
=======
#define DATASIZE_8BIT SPI_DATASIZE_8BIT
#define DATASIZE_16BIT SPI_DATASIZE_16BIT
#define TFT_IO_DRIVER TFT_FSMC
>>>>>>> faae900747 (TFT Refactoring (#19192))

#define TFT_DATASIZE TERN(TFT_INTERFACE_FSMC_8BIT, DATASIZE_8BIT, DATASIZE_16BIT)
typedef TERN(TFT_INTERFACE_FSMC_8BIT, uint8_t, uint16_t) tft_data_t;
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/HAL/STM32/tft/tft_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@
#define LCD_READ_ID4 0xD3 // Read display identification information (0xD3 on ILI9341)
#endif

<<<<<<< HEAD
#define DATASIZE_8BIT SPI_DATASIZE_8BIT
#define DATASIZE_16BIT SPI_DATASIZE_16BIT
#define TFT_IO_DRIVER TFT_SPI
=======
#define DATASIZE_8BIT SPI_DATASIZE_8BIT
#define DATASIZE_16BIT SPI_DATASIZE_16BIT
#define TFT_IO_DRIVER TFT_SPI
>>>>>>> faae900747 (TFT Refactoring (#19192))

class TFT_SPI {
private:
Expand Down
8 changes: 8 additions & 0 deletions Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@
*
*/
#pragma once
<<<<<<< HEAD
=======

#if ENABLED(USE_USB_COMPOSITE)
//#warning "SD_CHECK_AND_RETRY isn't needed with USE_USB_COMPOSITE."
#undef SD_CHECK_AND_RETRY
#endif
>>>>>>> faae900747 (TFT Refactoring (#19192))
6 changes: 6 additions & 0 deletions Marlin/src/HAL/STM32F1/tft/tft_fsmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@

#include <libmaple/dma.h>

<<<<<<< HEAD
#define DATASIZE_8BIT DMA_SIZE_8BITS
#define DATASIZE_16BIT DMA_SIZE_16BITS
#define TFT_IO_DRIVER TFT_FSMC
=======
#define DATASIZE_8BIT DMA_SIZE_8BITS
#define DATASIZE_16BIT DMA_SIZE_16BITS
#define TFT_IO_DRIVER TFT_FSMC
>>>>>>> faae900747 (TFT Refactoring (#19192))

typedef struct {
__IO uint16_t REG;
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/core/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,10 @@
#define HAS_ARGS(V...) _BOOL(FIRST(_END_OF_ARGUMENTS_ V)())
#define _END_OF_ARGUMENTS_() 0

<<<<<<< HEAD
=======

>>>>>>> faae900747 (TFT Refactoring (#19192))
// Simple Inline IF Macros, friendly to use in other macro definitions
#define IF(O, A, B) ((O) ? (A) : (B))
#define IF_0(O, A) IF(O, A, 0)
Expand Down
160 changes: 160 additions & 0 deletions Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,33 @@
#define TFT_LVGL_UI
#endif

// Compatibility
#if ENABLED(FSMC_GRAPHICAL_TFT)
#define TFT_CLASSIC_UI
#define TFT_INTERFACE_FSMC
#define TFT_GENERIC
#elif ENABLED(SPI_GRAPHICAL_TFT)
#define TFT_CLASSIC_UI
#define TFT_INTERFACE_SPI
#define TFT_GENERIC
#elif EITHER(TFT_320x240, TFT_480x320)
#define TFT_COLOR_UI
#define TFT_INTERFACE_FSMC
#define TFT_GENERIC
#elif EITHER(TFT_320x240_SPI, TFT_480x320_SPI)
#define TFT_COLOR_UI
#define TFT_INTERFACE_SPI
#define TFT_GENERIC
#elif ENABLED(TFT_LVGL_UI_FSMC)
#define TFT_LVGL_UI
#define TFT_INTERFACE_FSMC
#define TFT_GENERIC
#elif ENABLED(TFT_LVGL_UI_SPI)
#define TFT_LVGL_UI
#define TFT_INTERFACE_SPI
#define TFT_GENERIC
#endif

// FSMC/SPI TFT Panels (LVGL)
#if ENABLED(TFT_LVGL_UI)
#define HAS_TFT_LVGL_UI 1
Expand All @@ -347,14 +374,22 @@
#define DOGLCD
#define IS_ULTIPANEL 1
#define DELAYED_BACKLIGHT_INIT
<<<<<<< HEAD
#elif HAS_TFT_LVGL_UI
=======
#elif ENABLED(TFT_LVGL_UI)
>>>>>>> faae900747 (TFT Refactoring (#19192))
#define DELAYED_BACKLIGHT_INIT
#endif

// Color UI
#if ENABLED(TFT_COLOR_UI)
#define HAS_GRAPHICAL_TFT 1
<<<<<<< HEAD
#define IS_ULTIPANEL 1
=======
#define IS_ULTIPANEL
>>>>>>> faae900747 (TFT Refactoring (#19192))
#endif

/**
Expand Down Expand Up @@ -1452,8 +1487,133 @@
#endif

/**
<<<<<<< HEAD
* To check if we need the folder src/features/leds
*/
#if ANY(TEMP_STAT_LEDS, HAS_COLOR_LEDS, HAS_CASE_LIGHT, PRINTER_EVENT_LEDS, LED_BACKLIGHT_TIMEOUT, PCA9632_BUZZER, LED_CONTROL_MENU)
#define HAS_LED_FEATURE 1
=======
* TFT Displays
*
* Configure parameters for TFT displays:
* - TFT_DEFAULT_ORIENTATION
* - TFT_DRIVER
* - TFT_WIDTH
* - TFT_HEIGHT
* - TFT_INTERFACE_(SPI|FSMC)
* - TFT_COLOR
* - GRAPHICAL_TFT_UPSCALE
*/
#if ENABLED(MKS_TS35_V2_0)
// Most common: ST7796
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY)
#define TFT_WIDTH 480
#define TFT_HEIGHT 320
#define TFT_INTERFACE_SPI
#define GRAPHICAL_TFT_UPSCALE 3
#elif ENABLED(MKS_ROBIN_TFT24)
// Most common: ST7789
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_Y)
#define TFT_WIDTH 320
#define TFT_HEIGHT 240
#define TFT_INTERFACE_FSMC
#define GRAPHICAL_TFT_UPSCALE 2
#elif ENABLED(MKS_ROBIN_TFT28)
// Most common: ST7789
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_Y)
#define TFT_WIDTH 320
#define TFT_HEIGHT 240
#define TFT_INTERFACE_FSMC
#define GRAPHICAL_TFT_UPSCALE 2
#elif ENABLED(MKS_ROBIN_TFT32)
// Most common: ST7789
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_Y)
#define TFT_WIDTH 320
#define TFT_HEIGHT 240
#define TFT_INTERFACE_FSMC
#define GRAPHICAL_TFT_UPSCALE 2
#elif ENABLED(MKS_ROBIN_TFT35)
// Most common: ILI9488
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y)
#define TFT_WIDTH 480
#define TFT_HEIGHT 320
#define TFT_INTERFACE_FSMC
#define GRAPHICAL_TFT_UPSCALE 3
#elif ENABLED(MKS_ROBIN_TFT43)
#define TFT_DEFAULT_ORIENTATION 0
#define TFT_DRIVER SSD1963
#define TFT_WIDTH 480
#define TFT_HEIGHT 272
#define TFT_INTERFACE_FSMC
#define GRAPHICAL_TFT_UPSCALE 2
#elif ENABLED(MKS_ROBIN_TFT_V1_1R)
// ILI9328 or R61505
#define TFT_DEFAULT_ORIENTATION (TFT_INVERT_X | TFT_INVERT_Y | TFT_EXCHANGE_XY)
#define TFT_WIDTH 320
#define TFT_HEIGHT 240
#define TFT_INTERFACE_FSMC
#define GRAPHICAL_TFT_UPSCALE 2
#elif EITHER(TFT_TRONXY_X5SA, ANYCUBIC_TFT35)
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y)
#define TFT_DRIVER ILI9488
#define TFT_WIDTH 480
#define TFT_HEIGHT 320
#define TFT_INTERFACE_FSMC
#define GRAPHICAL_TFT_UPSCALE 3
#elif ENABLED(LONGER_LK_TFT28)
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y)
#define TFT_WIDTH 320
#define TFT_HEIGHT 240
#define TFT_INTERFACE_FSMC
#define GRAPHICAL_TFT_UPSCALE 2
#elif ENABLED(TFT_GENERIC)
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y)
#endif

// FSMC/SPI TFT Panels using standard HAL/tft/tft_(fsmc|spi).h
#if ENABLED(TFT_INTERFACE_FSMC)
#define HAS_FSMC_TFT 1
#if ENABLED(TFT_CLASSIC_UI)
#define FSMC_GRAPHICAL_TFT
#elif ENABLED(TFT_LVGL_UI)
#define TFT_LVGL_UI_FSMC
#endif
#elif ENABLED(TFT_INTERFACE_SPI)
#define HAS_SPI_TFT 1
#if ENABLED(TFT_CLASSIC_UI)
#define SPI_GRAPHICAL_TFT
#elif ENABLED(TFT_LVGL_UI)
#define TFT_LVGL_UI_SPI
#endif
#endif

#if ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 240
#if ENABLED(TFT_INTERFACE_SPI)
#define TFT_320x240_SPI
#elif ENABLED(TFT_INTERFACE_FSMC)
#define TFT_320x240
#endif
#elif ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 320
#if ENABLED(TFT_INTERFACE_SPI)
#define TFT_480x320_SPI
#elif ENABLED(TFT_INTERFACE_FSMC)
#define TFT_480x320
#endif
#endif

// Fewer lines with touch buttons on-screen
#if EITHER(TFT_320x240, TFT_320x240_SPI)
#define HAS_UI_320x240 1
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7)
#elif EITHER(TFT_480x320, TFT_480x320_SPI)
#define HAS_UI_480x320 1
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7)
#endif

// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046'
#if ENABLED(TOUCH_SCREEN) && !HAS_GRAPHICAL_TFT
#undef TOUCH_SCREEN
#undef TOUCH_SCREEN_CALIBRATION
#define HAS_TOUCH_XPT2046 1
>>>>>>> faae900747 (TFT Refactoring (#19192))
#endif
10 changes: 10 additions & 0 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,11 @@
#elif defined(POWER_SUPPLY)
#error "POWER_SUPPLY is now obsolete. Please remove it."
#elif defined(MKS_ROBIN_TFT)
<<<<<<< HEAD
#error "MKS_ROBIN_TFT is now FSMC_GRAPHICAL_TFT."
=======
#error "MKS_ROBIN_TFT is now FSMC_GRAPHICAL_TFT. Please update your configuration."
>>>>>>> faae900747 (TFT Refactoring (#19192))
#elif defined(SDPOWER)
#error "SDPOWER is now SDPOWER_PIN."
#elif defined(STRING_SPLASH_LINE1) || defined(STRING_SPLASH_LINE2)
Expand Down Expand Up @@ -559,6 +563,7 @@
#elif defined(ANYCUBIC_TFT_MODEL)
#error "ANYCUBIC_TFT_MODEL is now ANYCUBIC_LCD_I3MEGA."
#elif defined(EVENT_GCODE_SD_STOP)
<<<<<<< HEAD
#error "EVENT_GCODE_SD_STOP is now EVENT_GCODE_SD_ABORT."
#elif defined(GRAPHICAL_TFT_ROTATE_180)
#error "GRAPHICAL_TFT_ROTATE_180 is now TFT_ROTATION set to TFT_ROTATE_180."
Expand All @@ -568,6 +573,11 @@
#error "POWER_LOSS_PULL is now specifically POWER_LOSS_PULL(UP|DOWN)."
#elif defined(SHORT_MANUAL_Z_MOVE)
#error "SHORT_MANUAL_Z_MOVE is now FINE_MANUAL_MOVE, applying to Z on most printers."
=======
#error "EVENT_GCODE_SD_STOP is now EVENT_GCODE_SD_ABORT. Please update your Configuration.h."
#elif defined(GRAPHICAL_TFT_ROTATE_180)
#error "GRAPHICAL_TFT_ROTATE_180 is now TFT_ROTATION set to TFT_ROTATE_180. Please update your Configuration.h."
>>>>>>> faae900747 (TFT Refactoring (#19192))
#elif defined(FIL_RUNOUT_INVERTING)
#if FIL_RUNOUT_INVERTING
#error "FIL_RUNOUT_INVERTING true is now FIL_RUNOUT_STATE HIGH."
Expand Down
15 changes: 15 additions & 0 deletions Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ static void setWindow(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin,
tftio.set_window(Xmin, Ymin, Xmax, Ymax);
}

<<<<<<< HEAD
#if HAS_TOUCH_BUTTONS
=======
#if HAS_TOUCH_XPT2046
>>>>>>> faae900747 (TFT Refactoring (#19192))

static const uint8_t buttonD[] = {
B01111111,B11111111,B11111111,B11111110,
Expand Down Expand Up @@ -373,7 +377,13 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u

switch (msg) {
case U8G_DEV_MSG_INIT:
<<<<<<< HEAD
dev->com_fn(u8g, U8G_COM_MSG_INIT, U8G_SPI_CLK_CYCLE_NONE, nullptr);
=======
dev->com_fn(u8g, U8G_COM_MSG_INIT, U8G_SPI_CLK_CYCLE_NONE, NULL);
tftio.Init();
tftio.InitTFT();
>>>>>>> faae900747 (TFT Refactoring (#19192))

if (preinit) {
preinit = false;
Expand Down Expand Up @@ -458,6 +468,11 @@ uint8_t u8g_com_hal_tft_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_p
switch (msg) {
case U8G_COM_MSG_STOP: break;
case U8G_COM_MSG_INIT:
<<<<<<< HEAD
=======
u8g_SetPIOutput(u8g, U8G_PI_RESET);
u8g_Delay(50);
>>>>>>> faae900747 (TFT Refactoring (#19192))
isCommand = 0;
break;

Expand Down
Loading

0 comments on commit 3e32344

Please sign in to comment.