diff options
author | Georgiy Bondarenko <69736697+nehilo@users.noreply.github.com> | 2021-03-04 20:54:23 +0300 |
---|---|---|
committer | Georgiy Bondarenko <69736697+nehilo@users.noreply.github.com> | 2021-03-04 20:54:23 +0300 |
commit | e8701195e66f2d27ffe17fb514eae8173795aaf7 (patch) | |
tree | 9f519c4abf6556b9ae7190a6210d87ead1dfadde /Marlin/src/lcd/tft_io | |
download | kp3s-lgvl-e8701195e66f2d27ffe17fb514eae8173795aaf7.tar.xz kp3s-lgvl-e8701195e66f2d27ffe17fb514eae8173795aaf7.zip |
Initial commit
Diffstat (limited to 'Marlin/src/lcd/tft_io')
-rw-r--r-- | Marlin/src/lcd/tft_io/ili9328.h | 173 | ||||
-rw-r--r-- | Marlin/src/lcd/tft_io/ili9341.h | 170 | ||||
-rw-r--r-- | Marlin/src/lcd/tft_io/ili9488.h | 164 | ||||
-rw-r--r-- | Marlin/src/lcd/tft_io/r65105.h | 176 | ||||
-rw-r--r-- | Marlin/src/lcd/tft_io/ssd1963.h | 131 | ||||
-rw-r--r-- | Marlin/src/lcd/tft_io/st7735.h | 136 | ||||
-rw-r--r-- | Marlin/src/lcd/tft_io/st7789v.h | 156 | ||||
-rw-r--r-- | Marlin/src/lcd/tft_io/st7796s.h | 183 | ||||
-rw-r--r-- | Marlin/src/lcd/tft_io/tft_io.cpp | 226 | ||||
-rw-r--r-- | Marlin/src/lcd/tft_io/tft_io.h | 144 | ||||
-rw-r--r-- | Marlin/src/lcd/tft_io/touch_calibration.cpp | 107 | ||||
-rw-r--r-- | Marlin/src/lcd/tft_io/touch_calibration.h | 92 |
12 files changed, 1858 insertions, 0 deletions
diff --git a/Marlin/src/lcd/tft_io/ili9328.h b/Marlin/src/lcd/tft_io/ili9328.h new file mode 100644 index 0000000..b50517a --- /dev/null +++ b/Marlin/src/lcd/tft_io/ili9328.h @@ -0,0 +1,173 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>. + * + */ +#pragma once + +#include "tft_io.h" + +#include "../../inc/MarlinConfig.h" + +#define ILI9328_DRVCTL_SM 0x0400 +#define ILI9328_DRVCTL_SS 0x0100 // Select the shift direction of outputs from the source driver. 0 - from S1 to S720 / 1 - from S720 to S1 + +#define ILI9328_GATE_SCANCTL_GS 0x8000 // Sets the direction of scan by the gate driver in the range determined by SCN[4:0] and NL[4:0]. + +#define ILI9328_ETMOD_TRI 0x8000 +#define ILI9328_ETMOD_DFM 0x4000 +#define ILI9328_ETMOD_BGR 0x1000 // RGB-BGR ORDER +#define ILI9328_ETMOD_RGB 0x0000 +#define ILI9328_ETMOD_ORG 0x0080 +#define ILI9328_ETMOD_ID1 0x0020 // 0 - Vertical Decrement / 1 - Vertical Increment +#define ILI9328_ETMOD_ID0 0x0010 // 0 - Horizontal Decrement / 1 - Horizontal Increment +#define ILI9328_ETMOD_AM 0x0008 // 0 - Horizontal / 1 - Vertical + +// MKS Robin TFT v1.1 - 320x240 ; Cable on the left side + +#if TFT_ROTATION == TFT_ROTATE_180 + #define ILI9328_DRVCTL_DATA 0x0000 + #define ILI9328_GATE_SCANCTL1_DATA 0xA700 +#else + #define ILI9328_DRVCTL_DATA ILI9328_DRVCTL_SS + #define ILI9328_GATE_SCANCTL1_DATA 0x2700 +#endif + +/* +#define ILI9328_ETMOD_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ILI9328_ETMOD_AM) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ILI9328_ETMOD_ID1) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ILI9328_ETMOD_ID0) +*/ + +#define ILI9328_ETMOD_ORIENTATION (ILI9328_ETMOD_AM | ILI9328_ETMOD_ID1 | ILI9328_ETMOD_ID0) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR + #define ILI9328_ETMOD_COLOR ILI9328_ETMOD_BGR +#elif TFT_COLOR == TFT_COLOR_RGB + #define ILI9328_ETMOD_COLOR ILI9328_ETMOD_RGB +#endif + +#define ILI9328_ETMOD_DATA (ILI9328_ETMOD_ORIENTATION) | (ILI9328_ETMOD_COLOR) + + +#define ILI9328_RDDID 0x00 // ID code - 0x9328 +#define ILI9328_DRVCTL 0x01 // Driver Output Control +#define ILI9328_LCDCTL 0x02 // LCD Driving Wave Control +#define ILI9328_ETMOD 0x03 // Entry Mode - Control the GRAM update direction +#define ILI9328_RESIZECTL 0x04 // Resizing Control Register +#define ILI9328_DISCTRL1 0x07 // Display Control 1 +#define ILI9328_DISCTRL2 0x08 // Display Control 2 +#define ILI9328_DISCTRL3 0x09 // Display Control 3 +#define ILI9328_DISCTRL4 0x0A // Display Control 4 +#define ILI9328_RGBCTRL1 0x0C // RGB Display Interface Control 1 +#define ILI9328_FMARKERPOS 0x0D // Frame Marker Position +#define ILI9328_RGBCTRL2 0x0F // RGB Display Interface Control 2 +#define ILI9328_PWCTRL1 0x10 // Power Control 1 +#define ILI9328_PWCTRL2 0x11 // Power Control 2 +#define ILI9328_PWCTRL3 0x12 // Power Control 3 +#define ILI9328_PWCTRL4 0x13 // Power Control 4 + +// With landscape screen orientation 'Horizontal' is Y and 'Vertical' is X +#define ILI9328_HASET 0x20 // GRAM Horizontal Address Set (0-255) +#define ILI9328_VASET 0x21 // GRAM Vertical Address Set (0-511) +#define ILI9328_RAMWR 0x22 // Write data to GRAM +#define ILI9328_RAMRD 0x22 // Read Data from GRAM + +#define ILI9328_PWCTRL7 0x29 // Power Control 7 +#define ILI9328_FRMCTR 0x2B // Frame Rate and Color Control +#define ILI9328_GAMCTRL1 0x30 // Gamma Control +#define ILI9328_GAMCTRL2 0x31 // Gamma Control +#define ILI9328_GAMCTRL3 0x32 // Gamma Control +#define ILI9328_GAMCTRL4 0x35 // Gamma Control +#define ILI9328_GAMCTRL5 0x36 // Gamma Control +#define ILI9328_GAMCTRL6 0x37 // Gamma Control +#define ILI9328_GAMCTRL7 0x38 // Gamma Control +#define ILI9328_GAMCTRL8 0x39 // Gamma Control +#define ILI9328_GAMCTRL9 0x3C // Gamma Control +#define ILI9328_GAMCTRLA 0x3D // Gamma Control + +// With landscape screen orientation 'Horizontal' is Y and 'Vertical' is X +#define ILI9328_HASTART 0x50 // Horizontal Address Start Position (0-255) +#define ILI9328_HAEND 0x51 // Horizontal Address End Position (0-255) +#define ILI9328_VASTART 0x52 // Vertical Address Start Position (0-511) +#define ILI9328_VAEND 0x53 // Vertical Address End Position (0-511) + +#define ILI9328_GATE_SCANCTL1 0x60 // Gate Scan Control +#define ILI9328_GATE_SCANCTL2 0x61 // Gate Scan Control +#define ILI9328_GATE_SCANCTL3 0x6A // Gate Scan Control + +#define ILI9328_PLTPOS1 0x80 // Partial Image 1 Display Position +#define ILI9328_PLTSTART1 0x81 // Partial Image 1 RAM Start Address +#define ILI9328_PLTEND1 0x82 // Partial Image 1 RAM End Address +#define ILI9328_PLTPOS2 0x83 // Partial Image 2 Display Position +#define ILI9328_PLTSTART2 0x84 // Partial Image 2 RAM Start Address +#define ILI9328_PLTEND2 0x85 // Partial Image 2 RAM End Address + +#define ILI9328_IFCTL1 0x90 // Panel Interface Control 1 +#define ILI9328_IFCTL2 0x92 // Panel Interface Control 2 +#define ILI9328_IFCTL4 0x95 // Panel Interface Control 4 +#define ILI9328_IFCTL5 0x97 // Panel Interface Control 5 + +#define ILI9328_OTPWR 0xA1 // OTP VCM Programming Control +#define ILI9328_RDOTP 0xA2 // OTP VCM Status and Enable +#define ILI9328_OTPPKEY 0xA5 // OTP Programming ID Key + + +static const uint16_t ili9328_init[] = { + DATASIZE_16BIT, + ESC_REG(ILI9328_DRVCTL), ILI9328_DRVCTL_DATA, + ESC_REG(ILI9328_LCDCTL), 0x0400, // LCD Driving Wave Control + ESC_REG(ILI9328_ETMOD), ILI9328_ETMOD_DATA, + + ESC_REG(ILI9328_RESIZECTL), 0x0000, + ESC_REG(ILI9328_DISCTRL2), 0x0202, + ESC_REG(ILI9328_DISCTRL3), 0x0000, + ESC_REG(ILI9328_DISCTRL4), 0x0000, + ESC_REG(ILI9328_RGBCTRL1), 0x0000, + ESC_REG(ILI9328_FMARKERPOS), 0x0000, + ESC_REG(ILI9328_RGBCTRL2), 0x0000, + ESC_REG(ILI9328_PWCTRL1), 0x0000, + ESC_REG(ILI9328_PWCTRL2), 0x0007, + ESC_REG(ILI9328_PWCTRL3), 0x0000, + ESC_REG(ILI9328_PWCTRL4), 0x0000, + ESC_REG(ILI9328_DISCTRL1), 0x0001, + ESC_DELAY(200), + ESC_REG(ILI9328_PWCTRL1), 0x1690, + ESC_REG(ILI9328_PWCTRL2), 0x0227, + ESC_DELAY(50), + ESC_REG(ILI9328_PWCTRL3), 0x008C, + ESC_DELAY(50), + ESC_REG(ILI9328_PWCTRL4), 0x1500, + ESC_REG(ILI9328_PWCTRL7), 0x0004, + ESC_REG(ILI9328_FRMCTR), 0x000D, + ESC_DELAY(50), + ESC_REG(ILI9328_GATE_SCANCTL1), ILI9328_GATE_SCANCTL1_DATA, + ESC_REG(ILI9328_GATE_SCANCTL2), 0x0001, + ESC_REG(ILI9328_GATE_SCANCTL3), 0x0000, + ESC_REG(ILI9328_PLTPOS1), 0x0000, + ESC_REG(ILI9328_PLTSTART1), 0x0000, + ESC_REG(ILI9328_PLTEND1), 0x0000, + ESC_REG(ILI9328_PLTPOS2), 0x0000, + ESC_REG(ILI9328_PLTSTART2), 0x0000, + ESC_REG(ILI9328_PLTEND2), 0x0000, + ESC_REG(ILI9328_IFCTL1), 0x0010, + ESC_REG(ILI9328_IFCTL2), 0x0600, + ESC_REG(ILI9328_DISCTRL1), 0x0133, + ESC_END +}; diff --git a/Marlin/src/lcd/tft_io/ili9341.h b/Marlin/src/lcd/tft_io/ili9341.h new file mode 100644 index 0000000..dda326d --- /dev/null +++ b/Marlin/src/lcd/tft_io/ili9341.h @@ -0,0 +1,170 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>. + * + */ +#pragma once + +#include "tft_io.h" + +#include "../../inc/MarlinConfig.h" + +#define ILI9341_MADCTL_MY 0x80 // Row Address Order +#define ILI9341_MADCTL_MX 0x40 // Column Address Order +#define ILI9341_MADCTL_MV 0x20 // Row/Column Exchange +#define ILI9341_MADCTL_ML 0x10 // Vertical Refresh Order +#define ILI9341_MADCTL_BGR 0x08 // RGB-BGR ORDER +#define ILI9341_MADCTL_RGB 0x00 +#define ILI9341_MADCTL_MH 0x04 // Horizontal Refresh Order + +#define ILI9341_ORIENTATION_UP ILI9341_MADCTL_MY // 240x320 ; Cable on the upper side +#define ILI9341_ORIENTATION_RIGHT ILI9341_MADCTL_MV // 320x240 ; Cable on the right side +#define ILI9341_ORIENTATION_LEFT ILI9341_MADCTL_MY | ILI9341_MADCTL_MX | ILI9341_MADCTL_MV // 320x240 ; Cable on the left side +#define ILI9341_ORIENTATION_DOWN ILI9341_MADCTL_MX // 240x320 ; Cable on the upper side + +#define ILI9341_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ILI9341_MADCTL_MV) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ILI9341_MADCTL_MX) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ILI9341_MADCTL_MY) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR + #define ILI9341_COLOR ILI9341_MADCTL_BGR +#elif TFT_COLOR == TFT_COLOR_RGB + #define ILI9341_COLOR ILI9341_MADCTL_RGB +#endif + +#define ILI9341_MADCTL_DATA (ILI9341_ORIENTATION) | (ILI9341_COLOR) + +#define ILI9341_NOP 0x00 // No Operation +#define ILI9341_SWRESET 0x01 // Software Reset +#define ILI9341_RDDIDIF 0x04 // Read display identification information +#define ILI9341_RDDST 0x09 // Read Display Status +#define ILI9341_RDDPM 0x0A // Read Display Power Mode +#define ILI9341_RDDMADCTL 0x0B // Read Display MADCTL +#define ILI9341_RDDCOLMOD 0x0C // Read Display Pixel Format +#define ILI9341_RDDIM 0x0D // Read Display Image Format +#define ILI9341_RDDSM 0x0E // Read Display Signal Mode +#define ILI9341_RDDSDR 0x0F // Read Display Self-Diagnostic Result +#define ILI9341_SPLIN 0x10 // Enter Sleep Mode +#define ILI9341_SLPOUT 0x11 // Sleep Out +#define ILI9341_PTLON 0x12 // Partial Mode ON +#define ILI9341_NORON 0x13 // Normal Display Mode ON +#define ILI9341_DINVOFF 0x20 // Display Inversion OFF +#define ILI9341_DINVON 0x21 // Display Inversion ON +#define ILI9341_GAMSET 0x26 // Gamma Set +#define ILI9341_DISPOFF 0x28 // Display OFF +#define ILI9341_DISPON 0x29 // Display ON +#define ILI9341_CASET 0x2A // Column Address Set +#define ILI9341_PASET 0x2B // Page Address Set +#define ILI9341_RAMWR 0x2C // Memory Write +#define ILI9341_RGBSET 0x2D // Color Set +#define ILI9341_RAMRD 0x2E // Memory Read +#define ILI9341_PLTAR 0x30 // Partial Area +#define ILI9341_VSCRDEF 0x33 // Vertical Scrolling Definition +#define ILI9341_TEOFF 0x34 // Tearing Effect Line OFF +#define ILI9341_TEON 0x35 // Tearing Effect Line ON +#define ILI9341_MADCTL 0x36 // Memory Access Control +#define ILI9341_VSCRSADD 0x37 // Vertical Scrolling Start Address +#define ILI9341_IDMOFF 0x38 // Idle Mode OFF +#define ILI9341_IDMON 0x39 // Idle Mode ON +#define ILI9341_PIXSET 0x3A // COLMOD: Pixel Format Set +#define ILI9341_WRMEMC 0x3C // Write Memory Continue +#define ILI9341_RDMEMC 0x3E // Read Memory Continue +#define ILI9341_STE 0x44 // Set Tear Scanline +#define ILI9341_GSCAN 0x45 // Get Scanline +#define ILI9341_WRDISBV 0x51 // Write Display Brightness +#define ILI9341_RDDISBV 0x52 // Read Display Brightness +#define ILI9341_WRCTRLD 0x53 // Write CTRL Display +#define ILI9341_RDCTRLD 0x54 // Read CTRL Display +#define ILI9341_WRCABC 0x55 // Write Content Adaptive Brightness Control +#define ILI9341_RDCABC 0x56 // Read Content Adaptive Brightness Control +#define ILI9341_WRCABCMB 0x5E // Write CABC Minimum Brightness / Backlight Control 1 +#define ILI9341_RDCABCMB 0x5F // Read CABC Minimum Brightness / Backlight Control 1 +#define ILI9341_RDID1 0xDA // Read ID1 +#define ILI9341_RDID2 0xDB // Read ID2 +#define ILI9341_RDID3 0xDC // Read ID3 + +#define ILI9341_IFMODE 0xB0 // RGB Interface Signal Control +#define ILI9341_FRMCTR1 0xB1 // Frame Rate Control (In Normal Mode/Full Colors) +#define ILI9341_FRMCTR2 0xB2 // Frame Rate Control (In Idle Mode/8 colors) +#define ILI9341_FRMCTR3 0xB3 // Frame Rate control (In Partial Mode/Full Colors) +#define ILI9341_INVTR 0xB4 // Display Inversion Control +#define ILI9341_PRCTR 0xB5 // Blanking Porch Control +#define ILI9341_DISCTRL 0xB6 // Display Function Control +#define ILI9341_ETMOD 0xB7 // Entry Mode Set +#define ILI9341_BLCTL1 0xB8 // Backlight Control 1 +#define ILI9341_BLCTL2 0xB9 // Backlight Control 2 +#define ILI9341_BLCTL3 0xBA // Backlight Control 3 +#define ILI9341_BLCTL4 0xBB // Backlight Control 4 +#define ILI9341_BLCTL5 0xBC // Backlight Control 5 +#define ILI9341_BLCTL7 0xBE // Backlight Control 7 +#define ILI9341_BLCTL8 0xBF // Backlight Control 8 +#define ILI9341_PWCTRL1 0xC0 // Power Control 1 +#define ILI9341_PWCTRL2 0xC1 // Power Control 2 +#define ILI9341_VMCTRL1 0xC5 // VCOM Control 1 +#define ILI9341_VMCTRL2 0xC7 // VCOM Control 2 +#define ILI9341_PWCTRLA 0xCB // Power control A +#define ILI9341_PWCTRLB 0xCF // Power control B +#define ILI9341_NVMWR 0xD0 // NV Memory Write +#define ILI9341_NVMPKEY 0xD1 // NV Memory Protection Key +#define ILI9341_RDNVM 0xD2 // NV Memory Status Read +#define ILI9341_RDID4 0xD3 // Read ID4 - 0x009341 +#define ILI9341_PGAMCTRL 0xE0 // Positive Gamma Correction +#define ILI9341_NGAMCTRL 0xE1 // Negative Gamma Correction +#define ILI9341_DGAMCTRL1 0xE2 // Digital Gamma Control 1 +#define ILI9341_DGAMCTRL2 0xE3 // Digital Gamma Control 2 +#define ILI9341_DRVTCTLA1 0xE8 // Driver timing control A +#define ILI9341_DRVTCTLA2 0xE9 // Driver timing control A +#define ILI9341_DRVTCTLB 0xEA // Driver timing control B +#define ILI9341_PONSEQCTL 0xED // Power on sequence control +#define ILI9341_EN3G 0xF2 // Enable 3G - 3 gamma control +#define ILI9341_IFCTL 0xF6 // Interface Control +#define ILI9341_PUMPRCTL 0xF7 // Pump ratio control + + +static const uint16_t ili9341_init[] = { + DATASIZE_8BIT, + ESC_REG(ILI9341_SWRESET), ESC_DELAY(100), + ESC_REG(ILI9341_SLPOUT), ESC_DELAY(20), +/* + ESC_REG(ILI9341_PWCTRLA), 0x0039, 0x002C, 0x0000, 0x0034, 0x0002, // Power control A + ESC_REG(ILI9341_PWCTRLB), 0x0000, 0x00C1, 0x0030, // Power control B + ESC_REG(ILI9341_DRVTCTLA1), 0x0085, 0x0000, 0x0078, // Driver timing control A + ESC_REG(ILI9341_DRVTCTLB), 0x0000, 0x0000, // Driver timing control B + ESC_REG(ILI9341_PONSEQCTL), 0x0064, 0x0003, 0x0012, 0x0081, // Power on sequence control + ESC_REG(ILI9341_DISCTRL), 0x0008, 0x0082, 0x0027, // Display Function Control + ESC_REG(ILI9341_PUMPRCTL), 0x0020, // Pump ratio control + ESC_REG(ILI9341_VMCTRL1), 0x003E, 0x0028, // VCOM Control 1 + ESC_REG(ILI9341_VMCTRL2), 0x0086, // VCOM Control 2 + ESC_REG(ILI9341_FRMCTR1), 0x0000, 0x0018, // Frame Rate Control (In Normal Mode/Full Colors) + ESC_REG(ILI9341_PWCTRL1), 0x0023, // Power Control 1 + ESC_REG(ILI9341_PWCTRL2), 0x0010, // Power Control 2 +*/ + ESC_REG(ILI9341_MADCTL), ILI9341_MADCTL_DATA, + ESC_REG(ILI9341_PIXSET), 0x0055, + + /* Gamma Correction */ + ESC_REG(ILI9341_EN3G), 0x0000, // 3Gamma Function Disable + ESC_REG(ILI9341_GAMSET), 0x0001, // Gamma curve selected + ESC_REG(ILI9341_PGAMCTRL), 0x000F, 0x0031, 0x002B, 0x000C, 0x000E, 0x0008, 0x004E, 0x00F1, 0x0037, 0x0007, 0x0010, 0x0003, 0x000E, 0x0009, 0x0000, + ESC_REG(ILI9341_NGAMCTRL), 0x0000, 0x000E, 0x0014, 0x0003, 0x0011, 0x0007, 0x0031, 0x00C1, 0x0048, 0x0008, 0x000F, 0x000C, 0x0031, 0x0036, 0x000F, + + ESC_REG(ILI9341_NORON), + ESC_REG(ILI9341_DISPON), + ESC_END +}; diff --git a/Marlin/src/lcd/tft_io/ili9488.h b/Marlin/src/lcd/tft_io/ili9488.h new file mode 100644 index 0000000..e71c0d1 --- /dev/null +++ b/Marlin/src/lcd/tft_io/ili9488.h @@ -0,0 +1,164 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>. + * + */ +#pragma once + +#include "tft_io.h" + +#include "../../inc/MarlinConfig.h" + +#define ILI9488_MADCTL_MY 0x80 // Row Address Order +#define ILI9488_MADCTL_MX 0x40 // Column Address Order +#define ILI9488_MADCTL_MV 0x20 // Row/Column Exchange +#define ILI9488_MADCTL_ML 0x10 // Vertical Refresh Order +#define ILI9488_MADCTL_BGR 0x08 // RGB-BGR ORDER +#define ILI9488_MADCTL_RGB 0x00 +#define ILI9488_MADCTL_MH 0x04 // Horizontal Refresh Order + +#define ILI9488_ORIENTATION_UP ILI9488_MADCTL_MY // 320x480 ; Cable on the upper side +#define ILI9488_ORIENTATION_RIGHT ILI9488_MADCTL_MV // 480x320 ; Cable on the right side +#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 + +#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 !defined(TFT_COLOR) || 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) | (ILI9488_COLOR) + +#define ILI9488_NOP 0x00 // No Operation +#define ILI9488_SWRESET 0x01 // Software Reset +#define ILI9488_RDDIDIF 0x04 // Read Display Identification Information +#define ILI9488_RDNUMED 0x05 // Read Number of the Errors on DSI +#define ILI9488_RDDST 0x09 // Read Display Status +#define ILI9488_RDDPM 0x0A // Read Display Power Mode +#define ILI9488_RDDMADCTL 0x0B // Read Display MADCTL +#define ILI9488_RDDCOLMOD 0x0C // Read Display COLMOD +#define ILI9488_RDDIM 0x0D // Read Display Image Mode +#define ILI9488_RDDSM 0x0E // Read Display Signal Mode +#define ILI9488_RDDSDR 0x0F // Read Display Self-Diagnostic Result +#define ILI9488_SLPIN 0x10 // Sleep IN +#define ILI9488_SLPOUT 0x11 // Sleep OUT +#define ILI9488_PTLON 0x12 // Partial Mode ON +#define ILI9488_NORON 0x13 // Normal Display Mode ON +#define ILI9488_INVOFF 0x20 // Display Inversion OFF +#define ILI9488_INVON 0x21 // Display Inversion ON +#define ILI9488_ALLPOFF 0x22 // All Pixels OFF +#define ILI9488_ALLPON 0x23 // All Pixels ON +#define ILI9488_DISOFF 0x28 // Display OFF +#define ILI9488_DISON 0x29 // Display ON +#define ILI9488_CASET 0x2A // Column Address Set +#define ILI9488_PASET 0x2B // Page Address Set +#define ILI9488_RAMWR 0x2C // Memory Write +#define ILI9488_RAMRD 0x2E // Memory Read +#define ILI9488_PLTAR 0x30 // Partial Area +#define ILI9488_VSCRDEF 0x33 // Vertical Scrolling Definition +#define ILI9488_TEOFF 0x34 // Tearing Effect Line OFF +#define ILI9488_TEON 0x35 // Tearing Effect Line ON +#define ILI9488_MADCTL 0x36 // Memory Access Control +#define ILI9488_VSCRSADD 0x37 // Vertical Scrolling Start Address +#define ILI9488_IDMOFF 0x38 // Idle Mode OFF +#define ILI9488_IDMON 0x39 // Idle Mode ON +#define ILI9488_COLMOD 0x3A // Interface Pixel Format +#define ILI9488_RAMWRC 0x3C // Memory Write Continue +#define ILI9488_RAMRDRC 0x3E // Memory Read Continue +#define ILI9488_TESLWR 0x44 // Write Tear Scan Line +#define ILI9488_TESLRD 0x45 // Read Scan Line +#define ILI9488_WRDISBV 0x51 // Write Display Brightness Value +#define ILI9488_RDDISBV 0x52 // Read Display Brightness Value +#define ILI9488_WRCTRLD 0x53 // Write Control Display Value +#define ILI9488_RDCTRLD 0x54 // Read Control Display Value +#define ILI9488_WRCABC 0x55 // Write Content Adaptive Brightness Control Value +#define ILI9488_RDCABC 0x56 // Read Content Adaptive Brightness Control Value +#define ILI9488_WRCABCMB 0x5E // Write CABC Minimum Brightness +#define ILI9488_RDCABCMB 0x5F // Read CABC Minimum Brightness +#define ILI9488_RDABCSDR 0x68 // Read Automatic Brightness Control Self-diagnostic Result +#define ILI9488_RDID1 0xDA // Read ID1 +#define ILI9488_RDID2 0xDB // Read ID2 +#define ILI9488_RDID3 0xDC // Read ID3 + +#define ILI9488_IFMODE 0xB0 // Interface Mode Control +#define ILI9488_FRMCTR1 0xB1 // Frame Rate Control (In Normal Mode/Full Colors) +#define ILI9488_FRMCTR2 0xB2 // Frame Rate Control (In Idle Mode/8 Colors) +#define ILI9488_FRMCTR3 0xB3 // Frame Rate Control (In Partial Mode/Full Colors) +#define ILI9488_INVTR 0xB4 // Display Inversion Control +#define ILI9488_PRCTR 0xB5 // Blanking Porch Control +#define ILI9488_DISCTRL 0xB6 // Display Function Control +#define ILI9488_ETMOD 0xB7 // Entry Mode Set +#define ILI9488_CECTRL1 0xB9 // Color Enhancement Control 1 +#define ILI9488_CECTRL2 0xBA // Color Enhancement Control 2 +#define ILI9488_HSLCTRL 0xBE // HS Lanes Control +#define ILI9488_PWCTRL1 0xC0 // Power Control 1 +#define ILI9488_PWCTRL2 0xC1 // Power Control 2 +#define ILI9488_PWCTRL3 0xC2 // Power Control 3 (For Normal Mode) +#define ILI9488_PWCTRL4 0xC3 // Power Control 4 (For Idle Mode) +#define ILI9488_PWCTRL5 0xC4 // Power Control 5 (For Partial Mode) +#define ILI9488_VMCTRL 0xC5 // VCOM Control +#define ILI9488_CABCCTRL1 0xC6 // CABC Control 1 +#define ILI9488_CABCCTRL2 0xC8 // CABC Control 2 +#define ILI9488_CABCCTRL3 0xC9 // CABC Control 3 +#define ILI9488_CABCCTRL4 0xCA // CABC Control 4 +#define ILI9488_CABCCTRL5 0xCB // CABC Control 5 +#define ILI9488_CABCCTRL6 0xCC // CABC Control 6 +#define ILI9488_CABCCTRL7 0xCD // CABC Control 7 +#define ILI9488_CABCCTRL8 0xCE // CABC Control 8 +#define ILI9488_CABCCTRL9 0xCF // CABC Control 9 +#define ILI9488_NVMWR 0xD0 // NV Memory Write +#define ILI9488_NVMPKEY 0xD1 // NV Memory Protection Key +#define ILI9488_RDNVM 0xD2 // NV Memory Status Read +#define ILI9488_RDID4 0xD3 // Read ID4 - 0x009488 +#define ILI9488_ADJCTL1 0xD7 // Adjust Control 1 +#define ILI9488_RDIDV 0xD8 // Read ID Version +#define ILI9488_PGAMCTRL 0xE0 // Positive Gamma Control +#define ILI9488_NGAMCTRL 0xE1 // Negative Gamma Control +#define ILI9488_DGAMCTRL1 0xE2 // Ditigal Gamma Control 1 +#define ILI9488_DGAMCTRL2 0xE3 // Ditigal Gamma Control 2 +#define ILI9488_SETIMAGE 0xE9 // Set Image Function +#define ILI9488_ADJCTL2 0xF2 // Adjust Control 2 +#define ILI9488_ADJCTL3 0xF7 // Adjust Control 3 +#define ILI9488_ADJCTL4 0xF8 // Adjust Control 4 +#define ILI9488_ADJCTL5 0xF9 // Adjust Control 5 +#define ILI9488_RDEXTC 0xFB // Read EXTC command is SPI mode +#define ILI9488_ADJCTL6 0xFC // Adjust Control 6 +#define ILI9488_ADJCTL7 0xFF // Adjust Control 7 + +static const uint16_t ili9488_init[] = { + DATASIZE_8BIT, + ESC_REG(ILI9488_SWRESET), ESC_DELAY(120), + ESC_REG(ILI9488_SLPOUT), ESC_DELAY(20), + + ESC_REG(ILI9488_MADCTL), ILI9488_MADCTL_DATA, + ESC_REG(ILI9488_COLMOD), 0x0055, + + /* Gamma Correction. */ + ESC_REG(ILI9488_PGAMCTRL), 0x0000, 0x0003, 0x0009, 0x0008, 0x0016, 0x000A, 0x003F, 0x0078, 0x004C, 0x0009, 0x000A, 0x0008, 0x0016, 0x001A, 0x000F, + ESC_REG(ILI9488_NGAMCTRL), 0x0000, 0x0016, 0x0019, 0x0003, 0x000F, 0x0005, 0x0032, 0x0045, 0x0046, 0x0004, 0x000E, 0x000D, 0x0035, 0x0037, 0x000F, + + ESC_REG(ILI9488_NORON), + ESC_REG(ILI9488_DISON), + ESC_END +}; diff --git a/Marlin/src/lcd/tft_io/r65105.h b/Marlin/src/lcd/tft_io/r65105.h new file mode 100644 index 0000000..8be2afe --- /dev/null +++ b/Marlin/src/lcd/tft_io/r65105.h @@ -0,0 +1,176 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>. + * + */ +#pragma once + +#include "tft_io.h" + +#include "../../inc/MarlinConfig.h" + +#define R61505_DRVCTL_SM 0x0400 +#define R61505_DRVCTL_SS 0x0100 // Select the shift direction of outputs from the source driver. 0 - from S1 to S720 / 1 - from S720 to S1 + +#define R61505_ETMOD_TRIGGER 0x8000 // 18-bit RAM when set; 16-bit RAM when not set +#define R61505_ETMOD_DFM 0x4000 +#define R61505_ETMOD_BGR 0x1000 // RGB-BGR ORDER +#define R61505_ETMOD_RGB 0x0000 + +#define R61505_ETMOD_HWM 0x0020 +#define R61505_ETMOD_ORG 0x0080 +#define R61505_ETMOD_ID1 0x0020 // 0 - Vertical Decrement / 1 - Vertical Increment +#define R61505_ETMOD_ID0 0x0010 // 0 - Horizontal Decrement / 1 - Horizontal Increment +#define R61505_ETMOD_AM 0x0008 // 0 - Horizontal / 1 - Vertical + +#define R61505_DRVCTRL_GS 0x8000 // Gate Scan direction + +// MKS Robin TFT v1.1 - 320x240 ; Cable on the left side + +#if TFT_ROTATION == TFT_ROTATE_180 + #define R61505_DRVCTL_DATA 0x0000 + #define R61505_DRVCTRL_DATA (0x2700 | R61505_DRVCTRL_GS) +#else + #define R61505_DRVCTL_DATA R61505_DRVCTL_SS + #define R61505_DRVCTRL_DATA 0x2700 +#endif + +/* +#define R61505_ETMOD_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, R61505_ETMOD_AM) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, R61505_ETMOD_ID0) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, R61505_ETMOD_ID1) +*/ + +#define R61505_ETMOD_ORIENTATION (R61505_ETMOD_AM | R61505_ETMOD_ID0 | R61505_ETMOD_ID1) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR + #define R61505_ETMOD_COLOR R61505_ETMOD_BGR +#elif TFT_COLOR == TFT_COLOR_RGB + #define R61505_ETMOD_COLOR R61505_ETMOD_RGB +#endif + +#define R61505_ETMOD_DATA (R61505_ETMOD_ORIENTATION) | (R61505_ETMOD_COLOR) + + +#define R61505_RDDID 0x00 // ID code - 0x1505 +#define R61505_DRVCTL 0x01 // Driver Output Control +#define R61505_LCDCTL 0x02 // LCD Driving Wave Control +#define R61505_ETMOD 0x03 // Entry Mode - Control the GRAM update direction +#define R61505_RESIZECTL 0x04 // Resizing Control Register +#define R61505_DISCTRL1 0x07 // Display Control 1 +#define R61505_DISCTRL2 0x08 // Display Control 2 +#define R61505_DISCTRL3 0x09 // Display Control 3 +#define R61505_DISCTRL4 0x0A // Display Control 4 +#define R61505_RGBCTRL1 0x0C // RGB Display Interface Control 1 +#define R61505_FMARKERPOS 0x0D // Frame Marker Position +#define R61505_RGBCTRL2 0x0F // RGB Display Interface Control 2 +#define R61505_PWCTRL1 0x10 // Power Control 1 +#define R61505_PWCTRL2 0x11 // Power Control 2 +#define R61505_PWCTRL3 0x12 // Power Control 3 +#define R61505_PWCTRL4 0x13 // Power Control 4 + +// With landscape screen orientation 'Horizontal' is Y and 'Vertical' is X +#define R61505_HASET 0x20 // GRAM Horizontal Address Set (0-255) +#define R61505_VASET 0x21 // GRAM Vertical Address Set (0-511) +#define R61505_RAMWR 0x22 // Write data to GRAM +#define R61505_RAMRD 0x22 // Read Data from GRAM + +#define R61505_PWCTRL7 0x29 // Power Control 7 +#define R61505_GAMCTRL1 0x30 // Gamma Control +#define R61505_GAMCTRL2 0x31 // Gamma Control +#define R61505_GAMCTRL3 0x32 // Gamma Control +#define R61505_GAMCTRL4 0x35 // Gamma Control +#define R61505_GAMCTRL5 0x36 // Gamma Control +#define R61505_GAMCTRL6 0x37 // Gamma Control +#define R61505_GAMCTRL7 0x38 // Gamma Control +#define R61505_GAMCTRL8 0x39 // Gamma Control +#define R61505_GAMCTRL9 0x3C // Gamma Control +#define R61505_GAMCTRLA 0x3D // Gamma Control + +// With landscape screen orientation 'Horizontal' is Y and 'Vertical' is X +#define R61505_HASTART 0x50 // Horizontal Address Start Position (0-255) +#define R61505_HAEND 0x51 // Horizontal Address End Position (0-255) +#define R61505_VASTART 0x52 // Vertical Address Start Position (0-511) +#define R61505_VAEND 0x53 // Vertical Address End Position (0-511) + +#define R61505_DRVCTRL 0x60 // Driver Output Control +#define R61505_BASE_IMAGE_CTRL 0x61 // Base Image Display Control +#define R61505_VSCROLL_CTRL 0x6A // Vertical Scroll Control + +#define R61505_PLTPOS1 0x80 // Partial Image 1 Display Position +#define R61505_PLTSTART1 0x81 // Partial Image 1 RAM Start Address +#define R61505_PLTEND1 0x82 // Partial Image 1 RAM End Address +#define R61505_PLTPOS2 0x83 // Partial Image 2 Display Position +#define R61505_PLTSTART2 0x84 // Partial Image 2 RAM Start Address +#define R61505_PLTEND2 0x85 // Partial Image 2 RAM End Address + +#define R61505_IFCTL1 0x90 // Panel Interface Control 1 +#define R61505_IFCTL2 0x92 // Panel Interface Control 2 +#define R61505_IFCTL3 0x93 // Panel Interface Control 3 +#define R61505_IFCTL4 0x95 // Panel Interface Control 4 +#define R61505_IFCTL5 0x97 // Panel Interface Control 5 +#define R61505_IFCTL6 0x98 // Panel Interface Control 6 + +#define R61505_OSC_CTRL 0xA4 // Oscillation Control + + +static const uint16_t r61505_init[] = { + DATASIZE_16BIT, + ESC_REG(R61505_DRVCTL), R61505_DRVCTL_DATA, + ESC_REG(R61505_LCDCTL), 0x0700, // LCD Driving Wave Control + ESC_REG(R61505_ETMOD), R61505_ETMOD_DATA, + + ESC_REG(R61505_RESIZECTL), 0x0000, + ESC_REG(R61505_DISCTRL1), 0x0173, + ESC_REG(R61505_DISCTRL2), 0x0202, + ESC_REG(R61505_DISCTRL3), 0x0000, + ESC_REG(R61505_DISCTRL4), 0x0000, + ESC_REG(R61505_RGBCTRL1), 0x0000, + ESC_REG(R61505_FMARKERPOS), 0x0000, + ESC_REG(R61505_RGBCTRL2), 0x0000, + + ESC_REG(R61505_PWCTRL1), 0x17B0, + ESC_REG(R61505_PWCTRL2), 0x0037, + ESC_REG(R61505_PWCTRL3), 0x0138, + ESC_REG(R61505_PWCTRL4), 0x1700, + ESC_REG(R61505_PWCTRL7), 0x000D, + + ESC_REG(R61505_GAMCTRL1), 0x0001, + ESC_REG(R61505_GAMCTRL2), 0x0606, + ESC_REG(R61505_GAMCTRL3), 0x0304, + ESC_REG(R61505_GAMCTRL4), 0x0103, + ESC_REG(R61505_GAMCTRL5), 0x011D, + ESC_REG(R61505_GAMCTRL6), 0x0404, + ESC_REG(R61505_GAMCTRL7), 0x0404, + ESC_REG(R61505_GAMCTRL8), 0x0404, + ESC_REG(R61505_GAMCTRL9), 0x0700, + ESC_REG(R61505_GAMCTRLA), 0x0A1F, + + ESC_REG(R61505_DRVCTRL), R61505_DRVCTRL_DATA, + ESC_REG(R61505_BASE_IMAGE_CTRL), 0x0001, + ESC_REG(R61505_VSCROLL_CTRL), 0x0000, + + ESC_REG(R61505_IFCTL1), 0x0010, + ESC_REG(R61505_IFCTL2), 0x0000, + ESC_REG(R61505_IFCTL3), 0x0003, + ESC_REG(R61505_IFCTL4), 0x0101, + ESC_REG(R61505_IFCTL5), 0x0000, + ESC_REG(R61505_IFCTL6), 0x0000, + ESC_END +}; diff --git a/Marlin/src/lcd/tft_io/ssd1963.h b/Marlin/src/lcd/tft_io/ssd1963.h new file mode 100644 index 0000000..8564b28 --- /dev/null +++ b/Marlin/src/lcd/tft_io/ssd1963.h @@ -0,0 +1,131 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>. + * + */ +#pragma once + +#include "tft_io.h" + +#include "../../inc/MarlinConfig.h" + +#define SSD1963_MADCTL_MY 0x80 // Row Address Order +#define SSD1963_MADCTL_MX 0x40 // Column Address Order +#define SSD1963_MADCTL_MV 0x20 // Row/Column Exchange +#define SSD1963_MADCTL_MH 0x10 // Horizontal Refresh Order +#define SSD1963_MADCTL_BGR 0x08 // RGB-BGR ORDER +#define SSD1963_MADCTL_RGB 0x00 +#define SSD1963_MADCTL_ML 0x04 // Vertical Refresh Order +#define SSD1963_MADCTL_FH 0x02 // Flip Horizontal +#define SSD1963_MADCTL_FV 0x01 // Flip Vertical + +#define SSD1963_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, SSD1963_MADCTL_MV) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, SSD1963_MADCTL_FH) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, SSD1963_MADCTL_FV) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_RGB + #define SSD1963_COLOR SSD1963_MADCTL_RGB +#elif TFT_COLOR == TFT_COLOR_BGR + #define SSD1963_COLOR SSD1963_MADCTL_BGR +#endif + +#define SSD1963_MADCTL_DATA (SSD1963_ORIENTATION) | (SSD1963_COLOR) + +#define SSD1963_NOP 0x00 // No Operation +#define SSD1963_SWRESET 0x01 // Software reset +#define SSD1963_RDDPM 0x0A // Read Display Power Mode +#define SSD1963_RDDMADCTL 0x0B // Read Display MADCTL +#define SSD1963_RDDCOLMOD 0x0C // Read Display Pixel Format +#define SSD1963_RDDIM 0x0D // Read Display Image Mode +#define SSD1963_RDDSM 0x0E // Read Display Signal Mode +#define SSD1963_SLPIN 0x10 // Sleep In +#define SSD1963_SLPOUT 0x11 // Sleep Out +#define SSD1963_PTLON 0x12 // Partial Display Mode On +#define SSD1963_NORON 0x13 // Normal Display Mode On +#define SSD1963_INVOFF 0x20 // Display Inversion Off +#define SSD1963_INVON 0x21 // Display Inversion On +#define SSD1963_GAMSET 0x26 // Gamma Set +#define SSD1963_DISPOFF 0x28 // Display Off +#define SSD1963_DISPON 0x29 // Display On +#define SSD1963_CASET 0x2A // Column Address Set +#define SSD1963_RASET 0x2B // Row Address Set +#define SSD1963_RAMWR 0x2C // Memory Write +#define SSD1963_RAMRD 0x2E // Memory Read +#define SSD1963_PTLAR 0x30 // Partial Area +#define SSD1963_VSCRDEF 0x33 // Vertical Scrolling Definition +#define SSD1963_TEOFF 0x34 // Tearing Effect Line OFF +#define SSD1963_TEON 0x35 // Tearing Effect Line ON +#define SSD1963_MADCTL 0x36 // Memory Data Access Control +#define SSD1963_VSCSAD 0x37 // Vertical Scroll Start Address of RAM +#define SSD1963_IDMOFF 0x38 // Idle Mode Off +#define SSD1963_IDMON 0x39 // Idle Mode On +#define SSD1963_WRMEMC 0x3C // Write Memory Continue +#define SSD1963_RDMEMC 0x3E // Read Memory Continue +#define SSD1963_STE 0x44 // Set Tear Scanline +#define SSD1963_GSCAN 0x45 // Get Scanline +#define SSD1963_WRDISBV 0x51 // Write Display Brightness +#define SSD1963_RDDISBV 0x52 // Read Display Brightness +#define SSD1963_WRCTRLD 0x53 // Write CTRL Display +#define SSD1963_RDCTRLD 0x54 // Read CTRL Value Display +#define SSD1963_WRCACE 0x55 // Write Content Adaptive Brightness Control and Color Enhancement +#define SSD1963_RDCABC 0x56 // Read Content Adaptive Brightness Control +#define SSD1963_WRCABCMB 0x5E // Write CABC Minimum Brightness +#define SSD1963_RDCABCMB 0x5F // Read CABC Minimum Brightness +#define SSD1963_RDABCSDR 0x68 // Read Automatic Brightness Control Self-Diagnostic Result +#define SSD1963_RDDDB 0xA1 // Read Device Descriptor Block +#define SSD1963_SLCDMODE 0xB0 // Set the LCD panel mode and resolution +#define SSD1963_SHSYNC 0xB4 // Set HSYNC +#define SSD1963_GHSYNC 0xB5 // Get HSYNC +#define SSD1963_SVSYNC 0xB6 // Set VSYNC +#define SSD1963_GVSYNC 0xB7 // Get VSYNC +#define SSD1963_SGPIOCFG 0xB8 // Set GPIO Conf +#define SSD1963_SGPIOV 0xBA // Set GPIO Value +#define SSD1963_SPWMCFG 0xBE // Set PWM Conf +#define SSD1963_GPWMCFG 0xBF // Get PWM Conf +#define SSD1963_SDBCCFG 0xD0 // Set Dynamic Back Light Config +#define SSD1963_GDBCCFG 0xD1 // Get Dynamic Back Light Config +#define SSD1963_PLLON 0xE0 // PLL Enable +#define SSD1963_PLLMN 0xE2 // Set PLL Multiplier +#define SSD1963_SLSHIFT 0xE6 // Set the LSHIFT (pixel clock) frequency +#define SSD1963_COLMOD 0xF0 // Interface Pixel Format + +static const uint16_t ssd1963_init[] = { + DATASIZE_8BIT, + ESC_REG(SSD1963_PLLMN), 0x0023, 0x0002, 0x0054, + ESC_REG(SSD1963_PLLON), 0x0001, ESC_DELAY(10), + ESC_REG(SSD1963_PLLON), 0x0003, ESC_DELAY(10), + ESC_REG(SSD1963_SWRESET), ESC_DELAY(100), + + ESC_REG(SSD1963_SLSHIFT), 0x0001, 0x001F, 0x00FF, + ESC_REG(SSD1963_SLCDMODE), 0x0020, 0x0000, 0x0001, 0x00DF, 0x0001, 0x000F, 0x0000, + ESC_REG(SSD1963_SHSYNC), 0x0002, 0x0013, 0x0000, 0x0008, 0x002B, 0x0000, 0x0002, 0x0000, + ESC_REG(SSD1963_SVSYNC), 0x0001, 0x0020, 0x0000, 0x0004, 0x000C, 0x0000, 0x0002, + ESC_REG(SSD1963_SGPIOV), 0x000F, + ESC_REG(SSD1963_SGPIOCFG), 0x0007, 0x0001, + + ESC_REG(SSD1963_MADCTL), SSD1963_MADCTL_DATA, + ESC_REG(SSD1963_COLMOD), 0x0003, ESC_DELAY(1),//RBG 565 + + ESC_REG(SSD1963_NORON), + ESC_REG(SSD1963_DISPON), + + ESC_REG(SSD1963_SPWMCFG), 0x0006, 0x00F0, 0x0001, 0x00F0, 0x0000, 0x0000, + ESC_REG(SSD1963_SDBCCFG), 0x000D, + ESC_END +}; diff --git a/Marlin/src/lcd/tft_io/st7735.h b/Marlin/src/lcd/tft_io/st7735.h new file mode 100644 index 0000000..1b0d23b --- /dev/null +++ b/Marlin/src/lcd/tft_io/st7735.h @@ -0,0 +1,136 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>. + * + */ +#pragma once + +#include "tft_io.h" + +#include "../../inc/MarlinConfig.h" + +#define ST7735_MADCTL_MY 0x80 // Row Address Order +#define ST7735_MADCTL_MX 0x40 // Column Address Order +#define ST7735_MADCTL_MV 0x20 // Row/Column Exchange +#define ST7735_MADCTL_ML 0x10 // Vertical Refresh Order +#define ST7735_MADCTL_BGR 0x08 // RGB-BGR ORDER +#define ST7735_MADCTL_RGB 0x00 +#define ST7735_MADCTL_MH 0x04 // Horizontal Refresh Order + +#define ST7735_ORIENTATION_UP 0x00 // 128x160 ; Cable on the upper side +#define ST7735_ORIENTATION_RIGHT ST7735_MADCTL_MV | ST7735_MADCTL_MY // 160x128 ; Cable on the right side +#define ST7735_ORIENTATION_LEFT ST7735_MADCTL_MV | ST7735_MADCTL_MX // 160x128 ; Cable on the left side +#define ST7735_ORIENTATION_DOWN ST7735_MADCTL_MX | ST7735_MADCTL_MY // 128x160 ; Cable on the lower side + +#define ST7735_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ST7735_MADCTL_MV) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ST7735_MADCTL_MX) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ST7735_MADCTL_MY) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_RGB + #define ST7735_COLOR ST7735_MADCTL_RGB +#elif TFT_COLOR == TFT_COLOR_BGR + #define ST7735_COLOR ST7735_MADCTL_BGR +#endif + +#define ST7735_MADCTL_DATA (ST7735_ORIENTATION) | (ST7735_COLOR) + +#define ST7735_NOP 0x00 // No Operation +#define ST7735_SWRESET 0x01 // Software reset +#define ST7735_RDDID 0x04 // Read Display ID +#define ST7735_RDDST 0x09 // Read Display Status +#define ST7735_RDDPM 0x0A // Read Display Power Mode +#define ST7735_RDDMADCTL 0x0B // Read Display MADCTL +#define ST7735_RDDCOLMOD 0x0C // Read Display Pixel Format +#define ST7735_RDDIM 0x0D // Read Display Image Mode +#define ST7735_RDDSM 0x0E // Read Display Signal Mode +#define ST7735_SLPIN 0x10 // Sleep In +#define ST7735_SLPOUT 0x11 // Sleep Out +#define ST7735_PTLON 0x12 // Partial Display Mode On +#define ST7735_NORON 0x13 // Normal Display Mode On +#define ST7735_INVOFF 0x20 // Display Inversion Off +#define ST7735_INVON 0x21 // Display Inversion On +#define ST7735_GAMSET 0x26 // Gamma Set +#define ST7735_DISPOFF 0x28 // Display Off // The delay time between DISPON and DISPOFF needs 120ms at least. +#define ST7735_DISPON 0x29 // Display On +#define ST7735_CASET 0x2A // Column Address Set +#define ST7735_RASET 0x2B // Row Address Set +#define ST7735_RAMWR 0x2C // Memory Write +#define ST7735_RAMRD 0x2E // Memory Read +#define ST7735_PTLAR 0x30 // Partial Area +#define ST7735_TEOFF 0x34 // Tearing Effect Line OFF +#define ST7735_TEON 0x35 // Tearing Effect Line ON +#define ST7735_MADCTL 0x36 // Memory Data Access Control +#define ST7735_IDMOFF 0x38 // Idle Mode Off +#define ST7735_IDMON 0x39 // Idle Mode On +#define ST7735_COLMOD 0x3A // Interface Pixel Format +#define ST7735_RDID1 0xDA // Read ID1 Value +#define ST7735_RDID2 0xDB // Read ID2 Value +#define ST7735_RDID3 0xDC // Read ID3 Value + +#define ST7735_FRMCTR1 0xB1 // Frame Rate Control (In normal mode/ Full colors) +#define ST7735_FRMCTR2 0xB2 // Frame Rate Control (In Idle mode/ 8-colors) +#define ST7735_FRMCTR3 0xB3 // Frame Rate Control (In Partial mode/ full colors) +#define ST7735_INVCTR 0xB4 // Display Inversion Control +#define ST7735_DISSET5 0xB6 // Display Function set 5 +#define ST7735_PWCTR1 0xC0 // Power Control 1 +#define ST7735_PWCTR2 0xC1 // Power Control 2 +#define ST7735_PWCTR3 0xC2 // Power Control 3 (in Normal mode/ Full colors) +#define ST7735_PWCTR4 0xC3 // Power Control 4 (in Idle mode/ 8-colors) +#define ST7735_PWCTR5 0xC4 // Power Control 5 (in Partial mode/ full-colors) +#define ST7735_VMCTR1 0xC5 // VCOM Control 1 +#define ST7735_VMOFCTR 0xC7 // VCOM Offset Control +#define ST7735_WRID2 0xD1 // Write ID2 Value +#define ST7735_WRID3 0xD2 // Write ID3 Value +#define ST7735_PWCTR6 0xFC // Power Control 5 (in Partial mode + Idle mode) +#define ST7735_NVFCTR1 0xD9 // EEPROM Control Status +#define ST7735_NVFCTR2 0xDE // EEPROM Read Command +#define ST7735_NVFCTR3 0xDF // EEPROM Write Command +#define ST7735_GMCTRP1 0xE0 // Gamma (‘+’polarity) Correction Characteristics Setting +#define ST7735_GMCTRN1 0xE1 // GMCTRN1 (E1h): Gamma ‘-’polarity Correction Characteristics Setting +#define ST7735_EXTCTRL 0xF0 // Extension Command Control +#define ST7735_VCOM4L 0xFF // Vcom 4 Level Control + +static const uint16_t st7735_init[] = { + DATASIZE_8BIT, + ESC_REG(ST7735_SWRESET), ESC_DELAY(100), + ESC_REG(ST7735_SLPOUT), ESC_DELAY(20), +/* + ESC_REG(ST7735_FRMCTR1), 0x0001, 0x002C, 0x002D, + ESC_REG(ST7735_FRMCTR2), 0x0001, 0x002C, 0x002D, + ESC_REG(ST7735_FRMCTR3), 0x0001, 0x002C, 0x002D, 0x0001, 0x002C, 0x002D, + ESC_REG(ST7735_INVCTR), 0x0007, + ESC_REG(ST7735_PWCTR1), 0x00A2, 0x0002, 0x0084, + ESC_REG(ST7735_PWCTR2), 0x00C5, + ESC_REG(ST7735_PWCTR3), 0x000A, 0x0000, + ESC_REG(ST7735_PWCTR4), 0x008A, 0x002A, + ESC_REG(ST7735_PWCTR5), 0x008A, 0x00EE, + ESC_REG(ST7735_VMCTR1), 0x000E, + ESC_REG(ST7735_INVOFF), +*/ + ESC_REG(ST7735_MADCTL), ST7735_MADCTL_DATA, + ESC_REG(ST7735_COLMOD), 0x0005, + + /* Gamma Correction. Colors with 'after-reset' settings are bleak */ + ESC_REG(ST7735_GMCTRP1), 0x0002, 0x001C, 0x0007, 0x0012, 0x0037, 0x0032, 0x0029, 0x002D, 0x0029, 0x0025, 0x002B, 0x0039, 0x0000, 0x0001, 0x0003, 0x0010, + ESC_REG(ST7735_GMCTRN1), 0x0003, 0x001D, 0x0007, 0x0006, 0x002E, 0x002C, 0x0029, 0x002D, 0x002E, 0x002E, 0x0037, 0x003F, 0x0000, 0x0000, 0x0002, 0x0010, + + ESC_REG(ST7735_NORON), + ESC_REG(ST7735_DISPON), + ESC_END +}; diff --git a/Marlin/src/lcd/tft_io/st7789v.h b/Marlin/src/lcd/tft_io/st7789v.h new file mode 100644 index 0000000..d0cf969 --- /dev/null +++ b/Marlin/src/lcd/tft_io/st7789v.h @@ -0,0 +1,156 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>. + * + */ +#pragma once + +#include "tft_io.h" + +#include "../../inc/MarlinConfig.h" + +#define ST7789V_MADCTL_MY 0x80 // Row Address Order +#define ST7789V_MADCTL_MX 0x40 // Column Address Order +#define ST7789V_MADCTL_MV 0x20 // Row/Column Exchange +#define ST7789V_MADCTL_ML 0x10 // Vertical Refresh Order +#define ST7789V_MADCTL_BGR 0x08 // RGB-BGR ORDER +#define ST7789V_MADCTL_RGB 0x00 +#define ST7789V_MADCTL_MH 0x04 // Horizontal Refresh Order + +#define ST7789V_ORIENTATION_UP ST7789V_MADCTL_MX | ST7789V_MADCTL_MY // 240x320 ; Cable on the upper side +#define ST7789V_ORIENTATION_RIGHT ST7789V_MADCTL_MX | ST7789V_MADCTL_MV // 320x240 ; Cable on the right side +#define ST7789V_ORIENTATION_LEFT ST7789V_MADCTL_MY | ST7789V_MADCTL_MV // 320x240 ; Cable on the left side +#define ST7789V_ORIENTATION_DOWN 0 // 240x320 ; Cable on the lower side + +#define ST7789V_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ST7789V_MADCTL_MV) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ST7789V_MADCTL_MX) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ST7789V_MADCTL_MY) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_RGB + #define ST7789V_COLOR ST7789V_MADCTL_RGB +#elif TFT_COLOR == TFT_COLOR_BGR + #define ST7789V_COLOR ST7789V_MADCTL_BGR +#endif + +#define ST7789V_MADCTL_DATA (ST7789V_ORIENTATION) | (ST7789V_COLOR) + +#define ST7789V_NOP 0x00 // No Operation +#define ST7789V_SWRESET 0x01 // Software reset +#define ST7789V_RDDID 0x04 // Read Display ID +#define ST7789V_RDDST 0x09 // Read Display Status +#define ST7789V_RDDPM 0x0A // Read Display Power Mode +#define ST7789V_RDDMADCTL 0x0B // Read Display MADCTL +#define ST7789V_RDDCOLMOD 0x0C // Read Display Pixel Format +#define ST7789V_RDDIM 0x0D // Read Display Image Mode +#define ST7789V_RDDSM 0x0E // Read Display Signal Mode +#define ST7789V_RDDSDR 0x0F // Read Display Self-Diagnostic Result +#define ST7789V_SLPIN 0x10 // Sleep In +#define ST7789V_SLPOUT 0x11 // Sleep Out +#define ST7789V_PTLON 0x12 // Partial Display Mode On +#define ST7789V_NORON 0x13 // Normal Display Mode On +#define ST7789V_INVOFF 0x20 // Display Inversion Off +#define ST7789V_INVON 0x21 // Display Inversion On +#define ST7789V_GAMSET 0x26 // Gamma Set +#define ST7789V_DISPOFF 0x28 // Display Off +#define ST7789V_DISPON 0x29 // Display On +#define ST7789V_CASET 0x2A // Column Address Set +#define ST7789V_RASET 0x2B // Row Address Set +#define ST7789V_RAMWR 0x2C // Memory Write +#define ST7789V_RAMRD 0x2E // Memory Read +#define ST7789V_PTLAR 0x30 // Partial Area +#define ST7789V_VSCRDEF 0x33 // Vertical Scrolling Definition +#define ST7789V_TEOFF 0x34 // Tearing Effect Line OFF +#define ST7789V_TEON 0x35 // Tearing Effect Line ON +#define ST7789V_MADCTL 0x36 // Memory Data Access Control +#define ST7789V_VSCSAD 0x37 // Vertical Scroll Start Address of RAM +#define ST7789V_IDMOFF 0x38 // Idle Mode Off +#define ST7789V_IDMON 0x39 // Idle Mode On +#define ST7789V_COLMOD 0x3A // Interface Pixel Format +#define ST7789V_WRMEMC 0x3C // Write Memory Continue +#define ST7789V_RDMEMC 0x3E // Read Memory Continue +#define ST7789V_STE 0x44 // Set Tear Scanline +#define ST7789V_GSCAN 0x45 // Get Scanline +#define ST7789V_WRDISBV 0x51 // Write Display Brightness +#define ST7789V_RDDISBV 0x52 // Read Display Brightness +#define ST7789V_WRCTRLD 0x53 // Write CTRL Display +#define ST7789V_RDCTRLD 0x54 // Read CTRL Value Display +#define ST7789V_WRCACE 0x55 // Write Content Adaptive Brightness Control and Color Enhancement +#define ST7789V_RDCABC 0x56 // Read Content Adaptive Brightness Control +#define ST7789V_WRCABCMB 0x5E // Write CABC Minimum Brightness +#define ST7789V_RDCABCMB 0x5F // Read CABC Minimum Brightness +#define ST7789V_RDABCSDR 0x68 // Read Automatic Brightness Control Self-Diagnostic Result +#define ST7789V_RDID1 0xDA // Read ID1 Value +#define ST7789V_RDID2 0xDB // Read ID2 Value +#define ST7789V_RDID3 0xDC // Read ID3 Value + +#define ST7789V_RAMCTRL 0xB0 // RAM Control +#define ST7789V_RGBCTRL 0xB1 // RGB Interface Control +#define ST7789V_PORCTRL 0xB2 // Porch Setting +#define ST7789V_FRCTRL1 0xB3 // Frame Rate Control 1 (In partial mode/ idle colors) +#define ST7789V_GCTRL 0xB7 // Gate Control +#define ST7789V_DGMEN 0xBA // Digital Gamma Enable +#define ST7789V_VCOMS 0xBB // VCOM Setting +#define ST7789V_LCMCTRL 0xC0 // LCM Control +#define ST7789V_IDSET 0xC1 // ID Code Setting +#define ST7789V_VDVVRHEN 0xC2 // VDV and VRH Command Enable +#define ST7789V_VRHS 0xC3 // VRH Set +#define ST7789V_VDVS 0xC4 // VDV Set +#define ST7789V_VCMOFSET 0xC5 // VCOM Offset Set +#define ST7789V_FRCTRL2 0xC6 // Frame Rate Control in Normal Mode +#define ST7789V_CABCCTRL 0xC7 // CABC Control +#define ST7789V_REGSEL1 0xC8 // Register Value Selection 1 +#define ST7789V_REGSEL2 0xCA // Register Value Selection 2 +#define ST7789V_PWMFRSEL 0xCC // PWM Frequency Selection +#define ST7789V_PWCTRL1 0xD0 // Power Control 1 +#define ST7789V_VAPVANEN 0xD2 // Enable VAP/VAN signal output +#define ST7789V_CMD2EN 0xDF // Command 2 Enable +#define ST7789V_PVGAMCTRL 0xE0 // Positive Voltage Gamma Control +#define ST7789V_NVGAMCTRL 0xE1 // Negative Voltage Gamma Control +#define ST7789V_DGMLUTR 0xE2 // Digital Gamma Look-up Table for Red +#define ST7789V_DGMLUTB 0xE3 // Digital Gamma Look-up Table for Blue +#define ST7789V_GATECTRL 0xE4 // Gate Control +#define ST7789V_SPI2EN 0xE7 // SPI2 Enable +#define ST7789V_PWCTRL2 0xE8 // Power Control 2 +#define ST7789V_EQCTRL 0xE9 // Equalize time control +#define ST7789V_PROMCTRL 0xEC // Program Mode Control +#define ST7789V_PROMEN 0xFA // Program Mode Enable +#define ST7789V_NVMSET 0xFC // NVM Setting +#define ST7789V_PROMACT 0xFE // Program action + +static const uint16_t st7789v_init[] = { + DATASIZE_8BIT, + ESC_REG(ST7789V_SWRESET), ESC_DELAY(100), + ESC_REG(ST7789V_SLPOUT), ESC_DELAY(20), + + ESC_REG(ST7789V_PORCTRL), 0x000C, 0x000C, 0x0000, 0x0033, 0x0033, + ESC_REG(ST7789V_GCTRL), 0x0035, + ESC_REG(ST7789V_VCOMS), 0x001F, + ESC_REG(ST7789V_LCMCTRL), 0x002C, + ESC_REG(ST7789V_VDVVRHEN), 0x0001, 0x00C3, + ESC_REG(ST7789V_VDVS), 0x0020, + ESC_REG(ST7789V_FRCTRL2), 0x000F, + ESC_REG(ST7789V_PWCTRL1), 0x00A4, 0x00A1, + + ESC_REG(ST7789V_MADCTL), ST7789V_MADCTL_DATA, + ESC_REG(ST7789V_COLMOD), 0x0055, + + ESC_REG(ST7789V_NORON), + ESC_REG(ST7789V_DISPON), + ESC_END +}; diff --git a/Marlin/src/lcd/tft_io/st7796s.h b/Marlin/src/lcd/tft_io/st7796s.h new file mode 100644 index 0000000..8653a49 --- /dev/null +++ b/Marlin/src/lcd/tft_io/st7796s.h @@ -0,0 +1,183 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>. + * + */ +#pragma once + +#include "tft_io.h" + +#include "../../inc/MarlinConfig.h" + +#define ST7796S_MADCTL_MY 0x80 // Row Address Order +#define ST7796S_MADCTL_MX 0x40 // Column Address Order +#define ST7796S_MADCTL_MV 0x20 // Row/Column Exchange +#define ST7796S_MADCTL_ML 0x10 // Vertical Refresh Order +#define ST7796S_MADCTL_BGR 0x08 // RGB-BGR ORDER +#define ST7796S_MADCTL_RGB 0x00 +#define ST7796S_MADCTL_MH 0x04 // Horizontal Refresh Order + +#define ST7796S_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ST7796S_MADCTL_MV) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ST7796S_MADCTL_MX) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ST7796S_MADCTL_MY) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR + #define ST7796S_COLOR ST7796S_MADCTL_BGR +#elif TFT_COLOR == TFT_COLOR_RGB + #define ST7796S_COLOR ST7796S_MADCTL_RGB +#endif + +#define ST7796S_MADCTL_DATA (ST7796S_ORIENTATION) | (ST7796S_COLOR) + +#define ST7796S_NOP 0x00 // No Operation +#define ST7796S_SWRESET 0x01 // Software reset +#define ST7796S_RDDID 0x04 // Read Display ID +#define ST7796S_RDNUMED 0x05 // Read Number of the Errors on DSI +#define ST7796S_RDDST 0x09 // Read Display Status +#define ST7796S_RDDPM 0x0A // Read Display Power Mode +#define ST7796S_RDDMADCTL 0x0B // Read Display MADCTL +#define ST7796S_RDDCOLMOD 0x0C // Read Display Pixel Format +#define ST7796S_RDDIM 0x0D // Read Display Image Mode +#define ST7796S_RDDSM 0x0E // Read Display Signal Status +#define ST7796S_RDDSDR 0x0F // Read Display Self-Diagnostic Result +#define ST7796S_SLPIN 0x10 // Sleep In +#define ST7796S_SLPOUT 0x11 // Sleep Out +#define ST7796S_PTLON 0x12 // Partial Display Mode On +#define ST7796S_NORON 0x13 // Normal Display Mode On +#define ST7796S_INVOFF 0x20 // Display Inversion Off +#define ST7796S_INVON 0x21 // Display Inversion On +#define ST7796S_DISPOFF 0x28 // Display Off +#define ST7796S_DISPON 0x29 // Display On +#define ST7796S_CASET 0x2A // Column Address Set +#define ST7796S_RASET 0x2B // Row Address Set +#define ST7796S_RAMWR 0x2C // Memory Write +#define ST7796S_RAMRD 0x2E // Memory Read +#define ST7796S_PTLAR 0x30 // Partial Area +#define ST7796S_VSCRDEF 0x33 // Vertical Scrolling Definition +#define ST7796S_TEOFF 0x34 // Tearing Effect Line OFF +#define ST7796S_TEON 0x35 // Tearing Effect Line On +#define ST7796S_MADCTL 0x36 // Memory Data Access Control +#define ST7796S_VSCSAD 0x37 // Vertical Scroll Start Address of RAM +#define ST7796S_IDMOFF 0x38 // Idle Mode Off +#define ST7796S_IDMON 0x39 // Idle Mode On +#define ST7796S_COLMOD 0x3A // Interface Pixel Format +#define ST7796S_WRMEMC 0x3C // Write Memory Continue +#define ST7796S_RDMEMC 0x3E // Read Memory Continue +#define ST7796S_STE 0x44 // Set Tear ScanLine +#define ST7796S_GSCAN 0x45 // Get ScanLine +#define ST7796S_WRDISBV 0x51 // Write Display Brightness +#define ST7796S_RDDISBV 0x52 // Read Display Brightness Value +#define ST7796S_WRCTRLD 0x53 // Write CTRL Display +#define ST7796S_RDCTRLD 0x54 // Read CTRL value Display +#define ST7796S_WRCABC 0x55 // Write Adaptive Brightness Control +#define ST7796S_RDCABC 0x56 // Read Content Adaptive Brightness Control +#define ST7796S_WRCABCMB 0x5E // Write CABC Minimum Brightness +#define ST7796S_RDCABCMB 0x5F // Read CABC Minimum Brightness +#define ST7796S_RDFCS 0xAA // Read First Checksum +#define ST7796S_RDCFCS 0xAF // Read Continue Checksum +#define ST7796S_RDID1 0xDA // Read ID1 +#define ST7796S_RDID2 0xDB // Read ID2 +#define ST7796S_RDID3 0xDC // Read ID3 + +#define ST7796S_IFMODE 0xB0 // Interface Mode Control +#define ST7796S_FRMCTR1 0xB1 // Frame Rate Control (In Normal Mode/Full Colors) +#define ST7796S_FRMCTR2 0xB2 // Frame Rate Control 2 (In Idle Mode/8 colors) +#define ST7796S_FRMCTR3 0xB3 // Frame Rate Control 3(In Partial Mode/Full Colors) +#define ST7796S_DIC 0xB4 // Display Inversion Control +#define ST7796S_BPC 0xB5 // Blanking Porch Control +#define ST7796S_DFC 0xB6 // Display Function Control +#define ST7796S_EM 0xB7 // Entry Mode Set +#define ST7796S_PWR1 0xC0 // Power Control 1 +#define ST7796S_PWR2 0xC1 // Power Control 2 +#define ST7796S_PWR3 0xC2 // Power Control 3 +#define ST7796S_VCMPCTL 0xC5 // VCOM Control +#define ST7796S_VCMOST 0xC6 // VCOM Offset Register +#define ST7796S_NVMADW 0xD0 // NVM Address/Data Write +#define ST7796S_NVMBPROG 0xD1 // NVM Byte Program +#define ST7796S_NVMSTRD 0xD2 // NVM Status Read +#define ST7796S_RDID4 0xD3 // Read ID4 +#define ST7796S_PGC 0xE0 // Positive Gamma Control +#define ST7796S_NGC 0xE1 // Negative Gamma Control +#define ST7796S_DGC1 0xE2 // Digital Gamma Control 1 +#define ST7796S_DGC2 0xE3 // Digital Gamma Control 2 +#define ST7796S_DOCA 0xE8 // Display Output Ctrl Adjust +#define ST7796S_CSCON 0xF0 // Command Set Control +#define ST7796S_SPIRC 0xFB // SPI Read Control + +static const uint16_t st7796s_init[] = { + DATASIZE_8BIT, + ESC_REG(ST7796S_SWRESET), ESC_DELAY(100), + ESC_REG(ST7796S_SLPOUT), ESC_DELAY(20), + + ESC_REG(ST7796S_CSCON), 0x00C3, // enable command 2 part I + ESC_REG(ST7796S_CSCON), 0x0096, // enable command 2 part II + + ESC_REG(ST7796S_MADCTL), ST7796S_MADCTL_DATA, + ESC_REG(ST7796S_COLMOD), 0x0055, + + ESC_REG(ST7796S_DIC), 0x0001, // 1-dot inversion + ESC_REG(ST7796S_EM), 0x00C6, + + ESC_REG(ST7796S_PWR2), 0x0015, + ESC_REG(ST7796S_PWR3), 0x00AF, + ESC_REG(ST7796S_VCMPCTL), 0x0022, + ESC_REG(ST7796S_VCMOST), 0x0000, + ESC_REG(ST7796S_DOCA), 0x0040, 0x008A, 0x0000, 0x0000, 0x0029, 0x0019, 0x00A5, 0x0033, + + /* Gamma Correction. */ + ESC_REG(ST7796S_PGC), 0x00F0, 0x0004, 0x0008, 0x0009, 0x0008, 0x0015, 0x002F, 0x0042, 0x0046, 0x0028, 0x0015, 0x0016, 0x0029, 0x002D, + ESC_REG(ST7796S_NGC), 0x00F0, 0x0004, 0x0009, 0x0009, 0x0008, 0x0015, 0x002E, 0x0046, 0x0046, 0x0028, 0x0015, 0x0015, 0x0029, 0x002D, + + ESC_REG(ST7796S_NORON), + ESC_REG(ST7796S_WRCTRLD), 0x0024, + ESC_REG(ST7796S_CSCON), 0x003C, // disable command 2 part I + ESC_REG(ST7796S_CSCON), 0x0069, // disable command 2 part II + ESC_REG(ST7796S_DISPON), + ESC_END +}; + +static const uint16_t lerdge_st7796s_init[] = { + DATASIZE_8BIT, + ESC_REG(ST7796S_CSCON), 0x00C3, // enable command 2 part I + ESC_REG(ST7796S_CSCON), 0x0096, // enable command 2 part II + + ESC_REG(ST7796S_MADCTL), ST7796S_MADCTL_DATA, + ESC_REG(ST7796S_COLMOD), 0x0055, + + ESC_REG(ST7796S_DIC), 0x0001, // 1-dot inversion + ESC_REG(ST7796S_EM), 0x00C6, + + ESC_REG(ST7796S_PWR2), 0x0015, + ESC_REG(ST7796S_PWR3), 0x00AF, + ESC_REG(0xC3), 0x0009, // Register not documented in datasheet + ESC_REG(ST7796S_VCMPCTL), 0x0022, + ESC_REG(ST7796S_VCMOST), 0x0000, + ESC_REG(ST7796S_DOCA), 0x0040, 0x008A, 0x0000, 0x0000, 0x0029, 0x0019, 0x00A5, 0x0033, + + /* Gamma Correction. */ + ESC_REG(ST7796S_PGC), 0x00F0, 0x0004, 0x0008, 0x0009, 0x0008, 0x0015, 0x002F, 0x0042, 0x0046, 0x0028, 0x0015, 0x0016, 0x0029, 0x002D, + ESC_REG(ST7796S_NGC), 0x00F0, 0x0004, 0x0009, 0x0009, 0x0008, 0x0015, 0x002E, 0x0046, 0x0046, 0x0028, 0x0015, 0x0015, 0x0029, 0x002D, + + ESC_REG(ST7796S_INVON), // Display inversion ON + ESC_REG(ST7796S_WRCTRLD), 0x0024, + ESC_REG(ST7796S_CSCON), 0x003C, // disable command 2 part I + ESC_REG(ST7796S_CSCON), 0x0069, // disable command 2 part II + ESC_REG(ST7796S_DISPON), + ESC_END +}; diff --git a/Marlin/src/lcd/tft_io/tft_io.cpp b/Marlin/src/lcd/tft_io/tft_io.cpp new file mode 100644 index 0000000..cd53545 --- /dev/null +++ b/Marlin/src/lcd/tft_io/tft_io.cpp @@ -0,0 +1,226 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>. + * + */ + +#include "tft_io.h" + +#if HAS_SPI_TFT || HAS_FSMC_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" + +#define DEBUG_OUT ENABLED(DEBUG_GRAPHICAL_TFT) +#include "../../core/debug_out.h" + +TFT_IO_DRIVER TFT_IO::io; +uint32_t TFT_IO::lcd_id = 0xFFFFFFFF; + +void TFT_IO::InitTFT() { +if (lcd_id != 0xFFFFFFFF) return; + + #if PIN_EXISTS(TFT_BACKLIGHT) + OUT_WRITE(TFT_BACKLIGHT_PIN, LOW); + #endif + + #if PIN_EXISTS(TFT_RESET) + OUT_WRITE(TFT_RESET_PIN, HIGH); + delay(10); + OUT_WRITE(TFT_RESET_PIN, LOW); + delay(10); + OUT_WRITE(TFT_RESET_PIN, HIGH); + #endif + + #if PIN_EXISTS(TFT_BACKLIGHT) + OUT_WRITE(TFT_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT)); + #endif + + // io.Init(); + delay(100); + + #if TFT_DRIVER != AUTO + lcd_id = TFT_DRIVER; + #endif + + #if TFT_DRIVER == ST7735 + write_esc_sequence(st7735_init); + #elif TFT_DRIVER == SSD1963 + write_esc_sequence(ssd1963_init); + #elif TFT_DRIVER == ST7789 + write_esc_sequence(st7789v_init); + #elif TFT_DRIVER == ST7796 + write_esc_sequence(st7796s_init); + #elif TFT_DRIVER == R61505 + write_esc_sequence(r61505_init); + #elif TFT_DRIVER == ILI9328 + write_esc_sequence(ili9328_init); + #elif TFT_DRIVER == ILI9341 + write_esc_sequence(ili9341_init); + #elif TFT_DRIVER == ILI9488 + write_esc_sequence(ili9488_init); + #elif TFT_DRIVER == LERDGE_ST7796 + lcd_id = ST7796; + write_esc_sequence(lerdge_st7796s_init); + + #elif TFT_DRIVER == AUTO // autodetect + + lcd_id = io.GetID() & 0xFFFF; + + switch (lcd_id) { + case ST7796: // ST7796S 480x320 + DEBUG_ECHO_MSG(" ST7796S"); + write_esc_sequence(st7796s_init); + break; + case ST7789: // ST7789V 320x240 + DEBUG_ECHO_MSG(" ST7789V"); + write_esc_sequence(st7789v_init); + break; + case SSD1963: // SSD1963 + DEBUG_ECHO_MSG(" SSD1963"); + write_esc_sequence(ssd1963_init); + break; + case ST7735: // ST7735 160x128 + DEBUG_ECHO_MSG(" ST7735"); + write_esc_sequence(st7735_init); + break; + case R61505: // R61505U 320x240 + DEBUG_ECHO_MSG(" R61505U"); + write_esc_sequence(r61505_init); + break; + case ILI9328: // ILI9328 320x240 + DEBUG_ECHO_MSG(" ILI9328"); + write_esc_sequence(ili9328_init); + break; + case ILI9341: // ILI9341 320x240 + DEBUG_ECHO_MSG(" ILI9341"); + write_esc_sequence(ili9341_init); + break; + case ILI9488: // ILI9488 480x320 + case ILI9488_ID1: // 0x8066 ILI9488 480x320 + DEBUG_ECHO_MSG(" ILI9488"); + write_esc_sequence(ili9488_init); + break; + default: + lcd_id = 0; + } + #else + #error Unsupported TFT driver + #endif + + #if PIN_EXISTS(TFT_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT) + OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH); + #endif +} + +void TFT_IO::set_window(uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) { + #ifdef OFFSET_X + Xmin += OFFSET_X; Xmax += OFFSET_X; + #endif + #ifdef OFFSET_Y + Ymin += OFFSET_Y; Ymax += OFFSET_Y; + #endif + + switch (lcd_id) { + case ST7735: // ST7735 160x128 + case ST7789: // ST7789V 320x240 + case ST7796: // ST7796 480x320 + case ILI9341: // ILI9341 320x240 + case ILI9488: // ILI9488 480x320 + case SSD1963: // SSD1963 + case ILI9488_ID1: // 0x8066 ILI9488 480x320 + io.DataTransferBegin(DATASIZE_8BIT); + + // CASET: Column Address Set + io.WriteReg(ILI9341_CASET); + io.WriteData((Xmin >> 8) & 0xFF); + io.WriteData(Xmin & 0xFF); + io.WriteData((Xmax >> 8) & 0xFF); + io.WriteData(Xmax & 0xFF); + + // RASET: Row Address Set + io.WriteReg(ILI9341_PASET); + io.WriteData((Ymin >> 8) & 0xFF); + io.WriteData(Ymin & 0xFF); + io.WriteData((Ymax >> 8) & 0xFF); + io.WriteData(Ymax & 0xFF); + + // RAMWR: Memory Write + io.WriteReg(ILI9341_RAMWR); + break; + case R61505: // R61505U 320x240 + case ILI9328: // ILI9328 320x240 + io.DataTransferBegin(DATASIZE_16BIT); + + // Mind the mess: with landscape screen orientation 'Horizontal' is Y and 'Vertical' is X + io.WriteReg(ILI9328_HASTART); + io.WriteData(Ymin); + io.WriteReg(ILI9328_HAEND); + io.WriteData(Ymax); + io.WriteReg(ILI9328_VASTART); + io.WriteData(Xmin); + io.WriteReg(ILI9328_VAEND); + io.WriteData(Xmax); + + io.WriteReg(ILI9328_HASET); + io.WriteData(Ymin); + io.WriteReg(ILI9328_VASET); + io.WriteData(Xmin); + + io.WriteReg(ILI9328_RAMWR); + break; + default: + break; + } + + io.DataTransferEnd(); +} + +void TFT_IO::write_esc_sequence(const uint16_t *Sequence) { + uint16_t dataWidth, data; + + dataWidth = *Sequence++; + io.DataTransferBegin(dataWidth); + + for (;;) { + data = *Sequence++; + if (data != 0xFFFF) { + io.WriteData(data); + continue; + } + data = *Sequence++; + if (data == 0x7FFF) return; + if (data == 0xFFFF) + io.WriteData(0xFFFF); + else if (data & 0x8000) + delay(data & 0x7FFF); + else if ((data & 0xFF00) == 0) + io.WriteReg(data); + } + + io.DataTransferEnd(); +} + +#endif // HAS_SPI_TFT || HAS_FSMC_TFT diff --git a/Marlin/src/lcd/tft_io/tft_io.h b/Marlin/src/lcd/tft_io/tft_io.h new file mode 100644 index 0000000..2456358 --- /dev/null +++ b/Marlin/src/lcd/tft_io/tft_io.h @@ -0,0 +1,144 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>. + * + */ +#pragma once + +#include "../../inc/MarlinConfig.h" + +#if HAS_SPI_TFT || HAS_FSMC_TFT + +#if HAS_SPI_TFT + #include HAL_PATH(../../HAL, tft/tft_spi.h) +#elif HAS_FSMC_TFT + #include HAL_PATH(../../HAL, tft/tft_fsmc.h) +#else + #error "TFT IO only supports SPI or FSMC interface" +#endif + +#define TFT_EXCHANGE_XY (1UL << 1) +#define TFT_INVERT_X (1UL << 2) +#define TFT_INVERT_Y (1UL << 3) + +#define TFT_NO_ROTATION (0x00) +#define TFT_ROTATE_90 (TFT_EXCHANGE_XY | TFT_INVERT_X) +#define TFT_ROTATE_180 (TFT_INVERT_X | TFT_INVERT_Y) +#define TFT_ROTATE_270 (TFT_EXCHANGE_XY | TFT_INVERT_Y) + +#define TFT_MIRROR_X (TFT_INVERT_Y) +#define TFT_MIRROR_Y (TFT_INVERT_X) + +#define TFT_ROTATE_90_MIRROR_X (TFT_ROTATE_90 ^ TFT_INVERT_Y) +#define TFT_ROTATE_90_MIRROR_Y (TFT_ROTATE_90 ^ TFT_INVERT_X) + +#define TFT_ROTATE_180_MIRROR_X (TFT_ROTATE_180 ^ TFT_INVERT_Y) +#define TFT_ROTATE_180_MIRROR_Y (TFT_ROTATE_180 ^ TFT_INVERT_X) + +#define TFT_ROTATE_270_MIRROR_X (TFT_ROTATE_270 ^ TFT_INVERT_Y) +#define TFT_ROTATE_270_MIRROR_Y (TFT_ROTATE_270 ^ TFT_INVERT_X) + +// TFT_ROTATION is user configurable +#ifndef TFT_ROTATION + #define TFT_ROTATION TFT_NO_ROTATION +#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) + +// Each TFT Driver is responsible for its default color mode. +// #ifndef TFT_COLOR +// #define TFT_COLOR TFT_COLOR_RGB +// #endif + +#define TOUCH_ORIENTATION_NONE 0 +#define TOUCH_LANDSCAPE 1 +#define TOUCH_PORTRAIT 2 + +#ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X 0 +#endif +#ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y 0 +#endif +#ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X 0 +#endif +#ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y 0 +#endif +#ifndef TOUCH_ORIENTATION + #define TOUCH_ORIENTATION TOUCH_LANDSCAPE +#endif + +#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 + +class TFT_IO { +public: + static TFT_IO_DRIVER io; + + static void InitTFT(); + static void set_window(uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax); + static void write_esc_sequence(const uint16_t *Sequence); + + // Deletaged methods + inline static void Init() { io.Init(); io.Abort(); }; + inline static bool isBusy() { return io.isBusy(); }; + inline static void Abort() { io.Abort(); }; + inline static uint32_t GetID() { return io.GetID(); }; + + inline static void DataTransferBegin(uint16_t DataWidth = DATASIZE_16BIT) { io.DataTransferBegin(DataWidth); } + inline static void DataTransferEnd() { io.DataTransferEnd(); }; + // inline static void DataTransferAbort() { io.DataTransferAbort(); }; + + inline static void WriteData(uint16_t Data) { io.WriteData(Data); }; + inline static void WriteReg(uint16_t Reg) { io.WriteReg(Reg); }; + + inline static void WriteSequence(uint16_t *Data, uint16_t Count) { io.WriteSequence(Data, Count); }; + // static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_MINC_DISABLE, &Data, Count); } + inline static void WriteMultiple(uint16_t Color, uint32_t Count) { io.WriteMultiple(Color, Count); }; + +protected: + static uint32_t lcd_id; +}; + +#endif // HAS_SPI_TFT || HAS_FSMC_TFT diff --git a/Marlin/src/lcd/tft_io/touch_calibration.cpp b/Marlin/src/lcd/tft_io/touch_calibration.cpp new file mode 100644 index 0000000..3c24d42 --- /dev/null +++ b/Marlin/src/lcd/tft_io/touch_calibration.cpp @@ -0,0 +1,107 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * 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 <https://www.gnu.org/licenses/>. + * + */ + +#include "../../inc/MarlinConfig.h" + +#if ENABLED(TOUCH_SCREEN_CALIBRATION) + +#include "touch_calibration.h" + +#define TOUCH_CALIBRATION_MAX_RETRIES 5 + +#define DEBUG_OUT ENABLED(DEBUG_TOUCH_CALIBRATION) +#include "../../core/debug_out.h" + +TouchCalibration touch_calibration; + +touch_calibration_t TouchCalibration::calibration; +calibrationState TouchCalibration::calibration_state = CALIBRATION_NONE; +touch_calibration_point_t TouchCalibration::calibration_points[4]; +uint8_t TouchCalibration::failed_count; + +void TouchCalibration::validate_calibration() { + #define VALIDATE_PRECISION(XY, A, B) validate_precision_##XY(CALIBRATION_##A, CALIBRATION_##B) + const bool landscape = VALIDATE_PRECISION(x, TOP_LEFT, BOTTOM_LEFT) + && VALIDATE_PRECISION(x, TOP_RIGHT, BOTTOM_RIGHT) + && VALIDATE_PRECISION(y, TOP_LEFT, TOP_RIGHT) + && VALIDATE_PRECISION(y, BOTTOM_LEFT, BOTTOM_RIGHT); + const bool portrait = VALIDATE_PRECISION(y, TOP_LEFT, BOTTOM_LEFT) + && VALIDATE_PRECISION(y, TOP_RIGHT, BOTTOM_RIGHT) + && VALIDATE_PRECISION(x, TOP_LEFT, TOP_RIGHT) + && VALIDATE_PRECISION(x, BOTTOM_LEFT, BOTTOM_RIGHT); + #undef VALIDATE_PRECISION + + #define CAL_PTS(N) calibration_points[CALIBRATION_##N] + if (landscape) { + calibration_state = CALIBRATION_SUCCESS; + calibration.x = ((CAL_PTS(TOP_RIGHT).x - CAL_PTS(TOP_LEFT).x) << 17) / (CAL_PTS(BOTTOM_RIGHT).raw_x + CAL_PTS(TOP_RIGHT).raw_x - CAL_PTS(BOTTOM_LEFT).raw_x - CAL_PTS(TOP_LEFT).raw_x); + calibration.y = ((CAL_PTS(BOTTOM_LEFT).y - CAL_PTS(TOP_LEFT).y) << 17) / (CAL_PTS(BOTTOM_RIGHT).raw_y - CAL_PTS(TOP_RIGHT).raw_y + CAL_PTS(BOTTOM_LEFT).raw_y - CAL_PTS(TOP_LEFT).raw_y); + calibration.offset_x = CAL_PTS(TOP_LEFT).x - int16_t(((CAL_PTS(TOP_LEFT).raw_x + CAL_PTS(BOTTOM_LEFT).raw_x) * calibration.x) >> 17); + calibration.offset_y = CAL_PTS(TOP_LEFT).y - int16_t(((CAL_PTS(TOP_LEFT).raw_y + CAL_PTS(TOP_RIGHT).raw_y) * calibration.y) >> 17); + calibration.orientation = TOUCH_LANDSCAPE; + } + else if (portrait) { + calibration_state = CALIBRATION_SUCCESS; + calibration.x = ((CAL_PTS(TOP_RIGHT).x - CAL_PTS(TOP_LEFT).x) << 17) / (CAL_PTS(BOTTOM_RIGHT).raw_y + CAL_PTS(TOP_RIGHT).raw_y - CAL_PTS(BOTTOM_LEFT).raw_y - CAL_PTS(TOP_LEFT).raw_y); + calibration.y = ((CAL_PTS(BOTTOM_LEFT).y - CAL_PTS(TOP_LEFT).y) << 17) / (CAL_PTS(BOTTOM_RIGHT).raw_x - CAL_PTS(TOP_RIGHT).raw_x + CAL_PTS(BOTTOM_LEFT).raw_x - CAL_PTS(TOP_LEFT).raw_x); + calibration.offset_x = CAL_PTS(TOP_LEFT).x - int16_t(((CAL_PTS(TOP_LEFT).raw_y + CAL_PTS(BOTTOM_LEFT).raw_y) * calibration.x) >> 17); + calibration.offset_y = CAL_PTS(TOP_LEFT).y - int16_t(((CAL_PTS(TOP_LEFT).raw_x + CAL_PTS(TOP_RIGHT).raw_x) * calibration.y) >> 17); + calibration.orientation = TOUCH_PORTRAIT; + } + else { + calibration_state = CALIBRATION_FAIL; + calibration_reset(); + if (need_calibration() && failed_count++ < TOUCH_CALIBRATION_MAX_RETRIES) calibration_state = CALIBRATION_TOP_LEFT; + } + #undef CAL_PTS + + if (calibration_state == CALIBRATION_SUCCESS) { + SERIAL_ECHOLNPGM("Touch screen calibration completed"); + SERIAL_ECHOLNPAIR("TOUCH_CALIBRATION_X ", calibration.x); + SERIAL_ECHOLNPAIR("TOUCH_CALIBRATION_Y ", calibration.y); + SERIAL_ECHOLNPAIR("TOUCH_OFFSET_X ", calibration.offset_x); + SERIAL_ECHOLNPAIR("TOUCH_OFFSET_Y ", calibration.offset_y); + SERIAL_ECHO_TERNARY(calibration.orientation == TOUCH_LANDSCAPE, "TOUCH_ORIENTATION ", "TOUCH_LANDSCAPE", "TOUCH_PORTRAIT", "\n"); + } +} + +bool TouchCalibration::handleTouch(uint16_t x, uint16_t y) { + static millis_t next_button_update_ms = 0; + const millis_t now = millis(); + if (PENDING(now, next_button_update_ms)) return false; + next_button_update_ms = now + BUTTON_DELAY_MENU; + + if (calibration_state < CALIBRATION_SUCCESS) { + calibration_points[calibration_state].raw_x = x; + calibration_points[calibration_state].raw_y = y; + DEBUG_ECHOLNPAIR("TouchCalibration - State: ", calibration_state, ", x: ", calibration_points[calibration_state].x, ", raw_x: ", x, ", y: ", calibration_points[calibration_state].y, ", raw_y: ", y); + } + + switch (calibration_state) { + case CALIBRATION_TOP_LEFT: calibration_state = CALIBRATION_BOTTOM_LEFT; break; + case CALIBRATION_BOTTOM_LEFT: calibration_state = CALIBRATION_TOP_RIGHT; break; + case CALIBRATION_TOP_RIGHT: calibration_state = CALIBRATION_BOTTOM_RIGHT; break; + case CALIBRATION_BOTTOM_RIGHT: validate_calibration(); break; + default: break; + } + + return true; +} + +#endif // TOUCH_SCREEN_CALIBRATION diff --git a/Marlin/src/lcd/tft_io/touch_calibration.h b/Marlin/src/lcd/tft_io/touch_calibration.h new file mode 100644 index 0000000..f8cbf99 --- /dev/null +++ b/Marlin/src/lcd/tft_io/touch_calibration.h @@ -0,0 +1,92 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * 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 <https://www.gnu.org/licenses/>. + * + */ +#pragma once + +#include "../../inc/MarlinConfigPre.h" +#include "tft_io.h" + +#ifndef TOUCH_SCREEN_CALIBRATION_PRECISION + #define TOUCH_SCREEN_CALIBRATION_PRECISION 80 +#endif + +#ifndef TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS + #define TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS 2500 +#endif + +typedef struct __attribute__((__packed__)) { + int32_t x, y; + int16_t offset_x, offset_y; + uint8_t orientation; +} touch_calibration_t; + +typedef struct __attribute__((__packed__)) { + uint16_t x, y; + int16_t raw_x, raw_y; +} touch_calibration_point_t; + +enum calibrationState : uint8_t { + CALIBRATION_TOP_LEFT = 0x00, + CALIBRATION_BOTTOM_LEFT, + CALIBRATION_TOP_RIGHT, + CALIBRATION_BOTTOM_RIGHT, + CALIBRATION_SUCCESS, + CALIBRATION_FAIL, + CALIBRATION_NONE, +}; + +class TouchCalibration { +public: + static calibrationState calibration_state; + static touch_calibration_point_t calibration_points[4]; + + static bool validate_precision(int32_t a, int32_t b) { return (a > b ? (100 * b) / a : (100 * a) / b) > TOUCH_SCREEN_CALIBRATION_PRECISION; } + static bool validate_precision_x(uint8_t a, uint8_t b) { return validate_precision(calibration_points[a].raw_x, calibration_points[b].raw_x); } + static bool validate_precision_y(uint8_t a, uint8_t b) { return validate_precision(calibration_points[a].raw_y, calibration_points[b].raw_y); } + static void validate_calibration(); + + static touch_calibration_t calibration; + static uint8_t failed_count; + static void calibration_reset() { calibration = { TOUCH_CALIBRATION_X, TOUCH_CALIBRATION_Y, TOUCH_OFFSET_X, TOUCH_OFFSET_Y, TOUCH_ORIENTATION }; } + static bool need_calibration() { return !calibration.offset_x && !calibration.offset_y && !calibration.x && !calibration.y; } + + static calibrationState calibration_start() { + calibration = { 0, 0, 0, 0, TOUCH_ORIENTATION_NONE }; + calibration_state = CALIBRATION_TOP_LEFT; + calibration_points[CALIBRATION_TOP_LEFT].x = 30; + calibration_points[CALIBRATION_TOP_LEFT].y = 30; + calibration_points[CALIBRATION_BOTTOM_LEFT].x = 30; + calibration_points[CALIBRATION_BOTTOM_LEFT].y = TFT_HEIGHT - 31; + calibration_points[CALIBRATION_TOP_RIGHT].x = TFT_WIDTH - 31; + calibration_points[CALIBRATION_TOP_RIGHT].y = 30; + calibration_points[CALIBRATION_BOTTOM_RIGHT].x = TFT_WIDTH - 31; + calibration_points[CALIBRATION_BOTTOM_RIGHT].y = TFT_HEIGHT - 31; + failed_count = 0; + return calibration_state; + } + static void calibration_end() { calibration_state = CALIBRATION_NONE; } + static calibrationState get_calibration_state() { return calibration_state; } + static bool calibration_loaded() { + if (need_calibration()) calibration_reset(); + return !need_calibration(); + } + + static bool handleTouch(uint16_t x, uint16_t y); +}; + +extern TouchCalibration touch_calibration; |