Skip to content

Commit

Permalink
base for TFT rotation and mirroring API, and ILI9488 support
Browse files Browse the repository at this point in the history
  • Loading branch information
rhapsodyv committed Sep 2, 2020
1 parent e447d9b commit 46e5a64
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 6 deletions.
21 changes: 21 additions & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,27 @@
//#define TFT_LVGL_UI_FSMC // Robin nano v1.2 uses FSMC
//#define TFT_LVGL_UI_SPI // Robin nano v2.0 uses SPI

//
// TFT Type
//
// Select your TFT. It will do some presets for you.
//
// Available optoions are: TFT_MKS_TS32_V2_0, TFT_TRONXY_X5SA, TFT_GENERIC
//
//#define TFT_GENERIC

//
// TFT Rotation
//
// Available options are: TFT_TURN_90, TFT_TURN_180, TFT_TURN_270,
// TFT_TURN_90_MIRROR_X, TFT_TURN_90_MIRROR_Y,
// TFT_TURN_180_MIRROR_X, TFT_TURN_180_MIRROR_Y,
// TFT_TURN_270_MIRROR_X, TFT_TURN_270_MIRROR_Y,
// TFT_NO_ROTATION
//
//#define TFT_ROTATION TFT_NO_ROTATION


//=============================================================================
//============================ Other Controllers ============================
//=============================================================================
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/core/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,12 @@
#define HAS_ARGS(V...) _BOOL(FIRST(_END_OF_ARGUMENTS_ V)())
#define _END_OF_ARGUMENTS_() 0


// 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)
#define IF_1(O, A) IF(O, A, 1)

//
// REPEAT core macros. Recurse N times with ascending I.
//
Expand Down
16 changes: 10 additions & 6 deletions Marlin/src/lcd/tft_io/ili9488.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@
#define ILI9488_ORIENTATION_LEFT ILI9488_MADCTL_MY | ILI9488_MADCTL_MX | ILI9488_MADCTL_MV // 480x320 ; Cable on the left side
#define ILI9488_ORIENTATION_DOWN ILI9488_MADCTL_MX // 320x480 ; Cable on the upper side

#ifndef ILI9488_COLOR_RGB
#define ILI9488_COLOR_BGR
#endif
#ifndef ILI9488_ORIENTATION
#define ILI9488_ORIENTATION ILI9488_ORIENTATION_LEFT
#define ILI9488_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ILI9488_MADCTL_MV) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ILI9488_MADCTL_MX) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ILI9488_MADCTL_MY)

#if TFT_COLOR == TFT_COLOR_BGR
#define ILI9488_COLOR ILI9488_MADCTL_BGR
#elif TFT_COLOR == TFT_COLOR_RGB
#define ILI9488_COLOR ILI9488_MADCTL_RGB
#endif
#define ILI9488_MADCTL_DATA (ILI9488_ORIENTATION | TERN(ILI9488_COLOR_BGR, ILI9488_MADCTL_BGR, ILI9488_MADCTL_RGB))

#define ILI9488_MADCTL_DATA (ILI9488_ORIENTATION) | (ILI9488_COLOR)

#define ILI9488_NOP 0x00 // No Operation
#define ILI9488_SWRESET 0x01 // Software Reset
Expand Down
41 changes: 41 additions & 0 deletions Marlin/src/lcd/tft_io/tft_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,47 @@
#include HAL_PATH(../../HAL, tft/tft_fsmc.h)
#endif

#define TFT_EXCHANGE_XY (1UL << 1)
#define TFT_INVERT_X (1UL << 2)
#define TFT_INVERT_Y (1UL << 3)

#define TFT_TURN_90 (TFT_EXCHANGE_XY | TFT_INVERT_X)
#define TFT_TURN_180 (TFT_INVERT_X | TFT_INVERT_Y)
#define TFT_TURN_270 (TFT_EXCHANGE_XY | TFT_INVERT_Y)

#define TFT_TURN_90_MIRROR_X (TFT_TURN_90 ^ TFT_INVERT_Y)
#define TFT_TURN_90_MIRROR_Y (TFT_TURN_90 ^ TFT_INVERT_X)

#define TFT_TURN_180_MIRROR_X (TFT_TURN_180 ^ TFT_INVERT_Y)
#define TFT_TURN_180_MIRROR_Y (TFT_TURN_180 ^ TFT_INVERT_X)

#define TFT_TURN_270_MIRROR_X (TFT_TURN_270 ^ TFT_INVERT_Y)
#define TFT_TURN_270_MIRROR_Y (TFT_TURN_270 ^ TFT_INVERT_X)

// TFT_ROTATION is user configurable
#ifndef TFT_ROTATION
#define TFT_ROTATION 0xFF
#endif

// TFT_DEFAULT_ORIENTATION is configurable by each TFT type
#if defined(TFT_MKS_TS32_V2_0)
#define TFT_DEFAULT_ORIENTATION TFT_EXCHANGE_XY | TFT_INVERT_X
#elif defined(TFT_TRONXY_X5SA)
#define TFT_DEFAULT_ORIENTATION TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y
#else // generic TFT?!
#define TFT_DEFAULT_ORIENTATION TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y
#endif

// 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)

#ifndef TFT_COLOR
#define TFT_COLOR TFT_COLOR_RGB
#endif

#define ST7735 0x89F0
#define ST7789 0x8552
#define ST7796 0x7796
Expand Down

0 comments on commit 46e5a64

Please sign in to comment.