TFT Refactoring (#19192)

* 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 a071ebbfad30e28855a4a5695ec8a726542a1a65.

* 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>
This commit is contained in:
Victor Oliveira
2020-10-12 18:38:07 -03:00
committed by Scott Lahteine
parent f163f1940d
commit 9b1ed45b3e
56 changed files with 1000 additions and 1476 deletions

View File

@ -22,7 +22,7 @@
#include "../../../../inc/MarlinConfigPre.h"
#if ENABLED(TFT_LVGL_UI_SPI)
#if HAS_TFT_LVGL_UI
#include "SPI_TFT.h"
#include "pic_manager.h"
@ -32,6 +32,8 @@
#include <SPI.h>
#include "draw_ui.h"
TFT SPI_TFT;
// use SPI1 for the spi tft.
@ -39,142 +41,48 @@ void TFT::spi_init(uint8_t spiRate) {
tftio.Init();
}
void TFT::LCD_WR_REG(uint8_t cmd) {
tftio.WriteReg(cmd);
}
void TFT::LCD_WR_DATA(uint8_t data) {
tftio.WriteData(data);
}
void TFT::SetPoint(uint16_t x, uint16_t y, uint16_t point) {
if ((x > 480) || (y > 320)) return;
SetWindows(x, y, 1, 1);
setWindow(x, y, 1, 1);
tftio.WriteMultiple(point, (uint16_t)1);
}
void TFT::SetWindows(uint16_t x, uint16_t y, uint16_t with, uint16_t height) {
tftio.DataTransferBegin(DATASIZE_8BIT);
LCD_WR_REG(0x2A);
LCD_WR_DATA(x >> 8);
LCD_WR_DATA(x);
LCD_WR_DATA((x + with - 1) >> 8);
LCD_WR_DATA((x + with - 1));
LCD_WR_REG(0x2B);
LCD_WR_DATA(y >> 8);
LCD_WR_DATA(y);
LCD_WR_DATA((y + height - 1) >> 8);
LCD_WR_DATA(y + height - 1);
LCD_WR_REG(0X2C);
tftio.DataTransferEnd();
void TFT::setWindow(uint16_t x, uint16_t y, uint16_t with, uint16_t height) {
tftio.set_window(x, y, (x + with - 1), (y + height - 1));
}
void TFT::LCD_init() {
TFT_BLK_L;
TFT_RST_H;
delay(150);
TFT_RST_L;
delay(150);
TFT_RST_H;
tftio.DataTransferBegin(DATASIZE_8BIT);
delay(120);
LCD_WR_REG(0x11);
delay(120);
LCD_WR_REG(0xF0);
LCD_WR_DATA(0xC3);
LCD_WR_REG(0xF0);
LCD_WR_DATA(0x96);
LCD_WR_REG(0x36);
LCD_WR_DATA(0x28 + TERN0(GRAPHICAL_TFT_ROTATE_180, 0x80));
LCD_WR_REG(0x3A);
LCD_WR_DATA(0x55);
LCD_WR_REG(0xB4);
LCD_WR_DATA(0x01);
LCD_WR_REG(0xB7);
LCD_WR_DATA(0xC6);
LCD_WR_REG(0xE8);
LCD_WR_DATA(0x40);
LCD_WR_DATA(0x8A);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x29);
LCD_WR_DATA(0x19);
LCD_WR_DATA(0xA5);
LCD_WR_DATA(0x33);
LCD_WR_REG(0xC1);
LCD_WR_DATA(0x06);
LCD_WR_REG(0xC2);
LCD_WR_DATA(0xA7);
LCD_WR_REG(0xC5);
LCD_WR_DATA(0x18);
LCD_WR_REG(0xE0); // Positive Voltage Gamma Control
LCD_WR_DATA(0xF0);
LCD_WR_DATA(0x09);
LCD_WR_DATA(0x0B);
LCD_WR_DATA(0x06);
LCD_WR_DATA(0x04);
LCD_WR_DATA(0x15);
LCD_WR_DATA(0x2F);
LCD_WR_DATA(0x54);
LCD_WR_DATA(0x42);
LCD_WR_DATA(0x3C);
LCD_WR_DATA(0x17);
LCD_WR_DATA(0x14);
LCD_WR_DATA(0x18);
LCD_WR_DATA(0x1B);
LCD_WR_REG(0xE1); // Negative Voltage Gamma Control
LCD_WR_DATA(0xF0);
LCD_WR_DATA(0x09);
LCD_WR_DATA(0x0B);
LCD_WR_DATA(0x06);
LCD_WR_DATA(0x04);
LCD_WR_DATA(0x03);
LCD_WR_DATA(0x2D);
LCD_WR_DATA(0x43);
LCD_WR_DATA(0x42);
LCD_WR_DATA(0x3B);
LCD_WR_DATA(0x16);
LCD_WR_DATA(0x14);
LCD_WR_DATA(0x17);
LCD_WR_DATA(0x1B);
LCD_WR_REG(0xF0);
LCD_WR_DATA(0x3C);
LCD_WR_REG(0xF0);
LCD_WR_DATA(0x69);
delay(120); // Delay 120ms
LCD_WR_REG(0x29); // Display ON
tftio.DataTransferEnd();
LCD_clear(0x0000); //
tftio.InitTFT();
#if PIN_EXISTS(TFT_BACKLIGHT)
OUT_WRITE(TFT_BACKLIGHT_PIN, LOW);
#endif
delay(100);
LCD_clear(0x0000);
LCD_Draw_Logo();
TFT_BLK_H;
delay(2000);
#if PIN_EXISTS(TFT_BACKLIGHT)
OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH);
#endif
#if HAS_LOGO_IN_FLASH
delay(2000);
#endif
}
void TFT::LCD_clear(uint16_t color) {
SetWindows(0, 0, (TFT_WIDTH) - 1, (TFT_HEIGHT) - 1);
setWindow(0, 0, (TFT_WIDTH), (TFT_HEIGHT));
tftio.WriteMultiple(color, (uint32_t)(TFT_WIDTH) * (TFT_HEIGHT));
}
extern unsigned char bmp_public_buf[17 * 1024];
void TFT::LCD_Draw_Logo() {
SetWindows(0, 0, TFT_WIDTH, TFT_HEIGHT);
for (uint16_t i = 0; i < (TFT_HEIGHT); i ++) {
Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, (TFT_WIDTH) * 2);
tftio.WriteSequence((uint16_t *)bmp_public_buf, TFT_WIDTH);
}
#if HAS_LOGO_IN_FLASH
setWindow(0, 0, TFT_WIDTH, TFT_HEIGHT);
for (uint16_t i = 0; i < (TFT_HEIGHT); i ++) {
Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, (TFT_WIDTH) * 2);
tftio.WriteSequence((uint16_t *)bmp_public_buf, TFT_WIDTH);
}
#endif
}
#endif // HAS_TFT_LVGL_UI_SPI
#endif // HAS_TFT_LVGL_UI

View File

@ -23,29 +23,21 @@
#include "../../inc/MarlinConfigPre.h"
#if ENABLED(TFT_LVGL_UI_SPI)
#include HAL_PATH(../../HAL, tft/tft_spi.h)
#elif ENABLED(TFT_LVGL_UI_FSMC)
#include HAL_PATH(../../HAL, tft/tft_fsmc.h)
#endif
#if HAS_TFT_LVGL_UI
#define TFT_RST_H OUT_WRITE(TFT_RESET_PIN, HIGH)
#define TFT_RST_L OUT_WRITE(TFT_RESET_PIN, LOW)
#define TFT_BLK_H OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH)
#define TFT_BLK_L OUT_WRITE(LCD_BACKLIGHT_PIN, LOW)
#include "../../../tft_io/tft_io.h"
class TFT {
public:
TFT_IO tftio;
void spi_init(uint8_t spiRate);
void LCD_WR_REG(uint8_t cmd);
void LCD_WR_DATA(uint8_t data);
void SetPoint(uint16_t x, uint16_t y, uint16_t point);
void SetWindows(uint16_t x, uint16_t y, uint16_t with, uint16_t height);
void setWindow(uint16_t x, uint16_t y, uint16_t with, uint16_t height);
void LCD_init();
void LCD_clear(uint16_t color);
void LCD_Draw_Logo();
};
extern TFT SPI_TFT;
#endif // HAS_TFT_LVGL_UI

View File

@ -23,9 +23,7 @@
#if HAS_TFT_LVGL_UI
#if ENABLED(TFT_LVGL_UI_SPI)
#include "SPI_TFT.h"
#endif
#include "SPI_TFT.h"
#include "lv_conf.h"
#include "draw_ui.h"
@ -77,7 +75,7 @@ void lv_draw_error_message(PGM_P const msg) {
lv_task_handler();
#endif
TERN(TFT_LVGL_UI_SPI, SPI_TFT.LCD_clear, LCD_Clear)(0x0000);
SPI_TFT.LCD_clear(0x0000);
if (msg) disp_string((TFT_WIDTH - strlen(msg) * 16) / 2, 100, msg, 0xFFFF, 0x0000);
disp_string((TFT_WIDTH - strlen("PRINTER HALTED") * 16) / 2, 140, "PRINTER HALTED", 0xFFFF, 0x0000);
disp_string((TFT_WIDTH - strlen("Please Reset") * 16) / 2, 180, "Please Reset", 0xFFFF, 0x0000);

View File

@ -23,9 +23,7 @@
#if HAS_TFT_LVGL_UI
#if ENABLED(TFT_LVGL_UI_SPI)
#include "SPI_TFT.h"
#endif
#include "SPI_TFT.h"
#include "tft_lvgl_configuration.h"
@ -165,7 +163,7 @@ void gCfgItems_init() {
W25QXX.SPI_FLASH_BufferWrite((uint8_t *)&custom_gcode_command[4], OTHERS_COMMAND_ADDR_4, 100);
}
const byte rot = TERN0(GRAPHICAL_TFT_ROTATE_180, 0xEE);
const byte rot = (TFT_ROTATION & TFT_ROTATE_180) ? 0xEE : 0x00;
if (gCfgItems.disp_rotation_180 != rot) {
gCfgItems.disp_rotation_180 = rot;
update_spi_flash();
@ -655,12 +653,7 @@ char *creat_title_text() {
}
card.setIndex((gPicturePreviewStart + To_pre_view) + size * row + 8);
#if ENABLED(TFT_LVGL_UI_SPI)
SPI_TFT.SetWindows(xpos_pixel, ypos_pixel + row, 200, 1);
#else
LCD_setWindowArea(xpos_pixel, ypos_pixel + row, 200, 1);
LCD_WriteRAM_Prepare();
#endif
SPI_TFT.setWindow(xpos_pixel, ypos_pixel + row, 200, 1);
j = i = 0;
@ -673,20 +666,11 @@ char *creat_title_text() {
}
if (j >= 400) break;
}
#if ENABLED(TFT_LVGL_UI_SPI)
for (i = 0; i < 400; i += 2) {
p_index = (uint16_t *)(&bmp_public_buf[i]);
if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full;
}
SPI_TFT.tftio.WriteSequence((uint16_t*)bmp_public_buf, 200);
#else
for (i = 0; i < 400;) {
p_index = (uint16_t *)(&bmp_public_buf[i]);
if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full; //gCfgItems.preview_bk_color;
LCD_IO_WriteData(*p_index);
i += 2;
}
#endif
for (i = 0; i < 400; i += 2) {
p_index = (uint16_t *)(&bmp_public_buf[i]);
if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full;
}
SPI_TFT.tftio.WriteSequence((uint16_t*)bmp_public_buf, 200);
#if HAS_BAK_VIEW_IN_FLASH
W25QXX.init(SPI_QUARTER_SPEED);
if (row < 20) W25QXX.SPI_FLASH_SectorErase(BAK_VIEW_ADDR_TFT35 + row * 4096);
@ -768,7 +752,7 @@ char *creat_title_text() {
card.setIndex((PREVIEW_LITTLE_PIC_SIZE + To_pre_view) + size * row + 8);
#if ENABLED(TFT_LVGL_UI_SPI)
SPI_TFT.SetWindows(xpos_pixel, ypos_pixel + row, 200, 1);
SPI_TFT.setWindow(xpos_pixel, ypos_pixel + row, 200, 1);
#else
LCD_setWindowArea(xpos_pixel, ypos_pixel + row, 200, 1);
LCD_WriteRAM_Prepare();
@ -901,34 +885,9 @@ char *creat_title_text() {
default_view_Read(bmp_public_buf, DEFAULT_VIEW_MAX_SIZE / 10); // 8k
#endif
#if ENABLED(TFT_LVGL_UI_SPI)
SPI_TFT.SetWindows(xpos_pixel, y_off * 20 + ypos_pixel, 200, 20); // 200*200
SPI_TFT.tftio.WriteSequence((uint16_t*)(bmp_public_buf), DEFAULT_VIEW_MAX_SIZE / 20);
#else
int x_off = 0;
uint16_t temp_p;
int i = 0;
uint16_t *p_index;
LCD_setWindowArea(xpos_pixel, y_off * 20 + ypos_pixel, 200, 20); // 200*200
SPI_TFT.setWindow(xpos_pixel, y_off * 20 + ypos_pixel, 200, 20); // 200*200
SPI_TFT.tftio.WriteSequence((uint16_t*)(bmp_public_buf), DEFAULT_VIEW_MAX_SIZE / 20);
LCD_WriteRAM_Prepare();
for (int _y = y_off * 20; _y < (y_off + 1) * 20; _y++) {
for (x_off = 0; x_off < 200; x_off++) {
if (sel == 1) {
temp_p = (uint16_t)(bmp_public_buf[i] | bmp_public_buf[i + 1] << 8);
p_index = &temp_p;
}
else {
p_index = (uint16_t *)(&bmp_public_buf[i]);
}
if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full; //gCfgItems.preview_bk_color;
LCD_IO_WriteData(*p_index);
i += 2;
}
if (i >= 8000) break;
}
#endif // TFT_LVGL_UI_SPI
y_off++;
}
W25QXX.init(SPI_QUARTER_SPEED);

View File

@ -23,9 +23,7 @@
#if HAS_TFT_LVGL_UI
#if ENABLED(TFT_LVGL_UI_SPI)
#include "SPI_TFT.h"
#endif
#include "SPI_TFT.h"
#include "tft_lvgl_configuration.h"
#include "draw_ready_print.h"
@ -626,10 +624,8 @@ static const uint16_t ASCII_Table_16x24[] PROGMEM = {
void disp_char_1624(uint16_t x, uint16_t y, uint8_t c, uint16_t charColor, uint16_t bkColor) {
for (uint16_t i = 0; i < 24; i++) {
const uint16_t tmp_char = pgm_read_word(&ASCII_Table_16x24[((c - 0x20) * 24) + i]);
for (uint16_t j = 0; j < 16; j++) {
TERN(TFT_LVGL_UI_SPI, SPI_TFT.SetPoint, tft_set_point)
(x + j, y + i, ((tmp_char >> j) & 0x01) ? charColor : bkColor);
}
for (uint16_t j = 0; j < 16; j++)
SPI_TFT.SetPoint(x + j, y + i, ((tmp_char >> j) & 0x01) ? charColor : bkColor);
}
}
@ -643,7 +639,7 @@ void disp_string(uint16_t x, uint16_t y, const char * string, uint16_t charColor
//static lv_obj_t * scr_test;
void disp_assets_update() {
TERN(TFT_LVGL_UI_SPI,, LCD_Clear(0x0000));
SPI_TFT.LCD_clear(0x0000);
disp_string(100, 140, "Assets Updating...", 0xFFFF, 0x0000);
}

View File

@ -1,60 +0,0 @@
/**
* 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 "../../../../inc/MarlinConfig.h"
#if ENABLED(TFT_LVGL_UI_FSMC)
#include HAL_PATH(../../HAL, tft/tft_fsmc.h)
TFT_IO tftio;
void LCD_IO_Init(uint8_t cs, uint8_t rs);
void LCD_IO_WriteData(uint16_t RegValue);
void LCD_IO_WriteReg(uint16_t Reg);
#ifdef LCD_USE_DMA_FSMC
void LCD_IO_WriteMultiple(uint16_t data, uint32_t count);
void LCD_IO_WriteSequence(uint16_t *data, uint16_t length);
#endif
void LCD_IO_Init(uint8_t cs, uint8_t rs) {
tftio.Init();
}
void LCD_IO_WriteData(uint16_t RegValue) {
tftio.WriteData(RegValue);
}
void LCD_IO_WriteReg(uint16_t Reg) {
tftio.WriteReg(Reg);
}
#ifdef LCD_USE_DMA_FSMC
void LCD_IO_WriteMultiple(uint16_t color, uint32_t count) {
tftio.WriteMultiple(color, count);
}
void LCD_IO_WriteSequence(uint16_t *data, uint16_t length) {
tftio.WriteSequence(data, length);
}
#endif // LCD_USE_DMA_FSMC
#endif // HAS_TFT_LVGL_UI

View File

@ -1,30 +0,0 @@
/**
* 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
#ifdef __cplusplus
extern "C" { /* C-declarations for C++ */
#endif
#ifdef __cplusplus
} /* C-declarations for C++ */
#endif

View File

@ -29,9 +29,7 @@
#if HAS_TFT_LVGL_UI
#if ENABLED(TFT_LVGL_UI_SPI)
#include "SPI_TFT.h"
#endif
#include "SPI_TFT.h"
#include "tft_lvgl_configuration.h"
#include "draw_ready_print.h"
@ -74,24 +72,6 @@ lv_group_t* g;
uint16_t DeviceCode = 0x9488;
extern uint8_t sel_id;
#define SetCs
#define ClrCs
#define HDP 799 // Horizontal Display Period
#define HT 1000 // Horizontal Total
#define HPS 51 // LLINE Pulse Start Position
#define LPS 3 // Horizontal Display Period Start Position
#define HPW 8 // LLINE Pulse Width
#define VDP 479 // Vertical Display Period
#define VT 530 // Vertical Total
#define VPS 24 // LFRAME Pulse Start Position
#define FPS 23 // Vertical Display Period Start Positio
#define VPW 3 // LFRAME Pulse Width
#define MAX_HZ_POSX HDP+1
#define MAX_HZ_POSY VDP+1
extern uint8_t gcode_preview_over, flash_preview_begin, default_preview_flg;
uint8_t bmp_public_buf[17 * 1024];
@ -125,317 +105,7 @@ void SysTick_Callback() {
}
}
#if DISABLED(TFT_LVGL_UI_SPI)
extern void LCD_IO_Init(uint8_t cs, uint8_t rs);
extern void LCD_IO_WriteData(uint16_t RegValue);
extern void LCD_IO_WriteReg(uint16_t Reg);
extern void LCD_IO_WriteMultiple(uint16_t color, uint32_t count);
void tft_set_cursor(uint16_t x, uint16_t y) {
LCD_IO_WriteReg(0x002A);
LCD_IO_WriteData(x >> 8);
LCD_IO_WriteData(x & 0x00FF);
LCD_IO_WriteData(x >> 8);
LCD_IO_WriteData(x & 0x00FF);
//ILI9488_WriteData(0x01);
//ILI9488_WriteData(0xDF);
LCD_IO_WriteReg(0x002B);
LCD_IO_WriteData(y >> 8);
LCD_IO_WriteData(y & 0x00FF);
LCD_IO_WriteData(y >> 8);
LCD_IO_WriteData(y & 0x00FF);
//ILI9488_WriteData(0x01);
//ILI9488_WriteData(0x3F);
}
void LCD_WriteRAM_Prepare(void) {
#if 0
switch (DeviceCode) {
case 0x9325: case 0x9328: case 0x8989: {
ClrCs
LCD->LCD_REG = R34;
SetCs
} break;
default: LCD_WrtReg(0x002C);
}
#else
LCD_IO_WriteReg(0x002C);
#endif
}
void tft_set_point(uint16_t x, uint16_t y, uint16_t point) {
//if (DeviceCode == 0x9488) {
if (x > (TFT_WIDTH) || y > (TFT_HEIGHT)) return;
//}
tft_set_cursor(x, y);
LCD_WriteRAM_Prepare();
//LCD_WriteRAM(point);
LCD_IO_WriteData(point);
}
void LCD_WriteReg(uint16_t LCD_Reg, uint16_t LCD_RegValue) {
/* Write 16-bit Index, then Write Reg */
ClrCs
LCD_IO_WriteReg(LCD_Reg);
/* Write 16-bit Reg */
LCD_IO_WriteData(LCD_RegValue);
SetCs
}
void LCD_setWindowArea(uint16_t StartX, uint16_t StartY, uint16_t width, uint16_t heigh) {
uint16_t s_h, s_l, e_h, e_l;
uint16_t xEnd, yEnd;
xEnd = StartX + width;
yEnd = StartY + heigh - 1;
if (DeviceCode == 0x8989) {
/*LCD_WriteReg(0x0044, (StartX & 0xFF) | (xEnd << 8));
LCD_WriteReg(0x0045, StartY);
LCD_WriteReg(0x0046, yEnd);*/
LCD_WriteReg(0x0044, (StartY & 0xFF) | (yEnd << 8));
LCD_WriteReg(0x0045, StartX);
LCD_WriteReg(0x0046, xEnd);
}
else if (DeviceCode == 0x9488) {
s_h = (StartX >> 8) & 0x00FF;
s_l = StartX & 0x00FF;
e_h = ((StartX + width - 1) >> 8) & 0x00FF;
e_l = (StartX + width - 1) & 0x00FF;
LCD_IO_WriteReg(0x002A);
LCD_IO_WriteData(s_h);
LCD_IO_WriteData(s_l);
LCD_IO_WriteData(e_h);
LCD_IO_WriteData(e_l);
s_h = (StartY >> 8) & 0x00FF;
s_l = StartY & 0x00FF;
e_h = ((StartY + heigh - 1) >> 8) & 0x00FF;
e_l = (StartY + heigh - 1) & 0x00FF;
LCD_IO_WriteReg(0x002B);
LCD_IO_WriteData(s_h);
LCD_IO_WriteData(s_l);
LCD_IO_WriteData(e_h);
LCD_IO_WriteData(e_l);
}
else if ((DeviceCode == 0x9325) || (DeviceCode == 0x9328) || (DeviceCode == 0x1505)) {
/* LCD_WriteReg(0x0050, StartX);
LCD_WriteReg(0x0052, StartY);
LCD_WriteReg(0x0051, xEnd);
LCD_WriteReg(0x0053, yEnd);*/
LCD_WriteReg(0x0050, StartY); // Specify the start/end positions of the window address in the horizontal direction by an address unit
LCD_WriteReg(0x0051, yEnd); // Specify the start positions of the window address in the vertical direction by an address unit
LCD_WriteReg(0x0052, (TFT_HEIGHT) - xEnd);
LCD_WriteReg(0x0053, (TFT_HEIGHT) - StartX - 1); // Specify the end positions of the window address in the vertical direction by an address unit
}
else {
s_h = (StartX >> 8) & 0xFF;
s_l = StartX & 0xFF;
e_h = ((StartX + width - 1) >> 8) & 0xFF;
e_l = (StartX + width - 1) & 0xFF;
LCD_IO_WriteReg(0x2A);
LCD_IO_WriteData(s_h);
LCD_IO_WriteData(s_l);
LCD_IO_WriteData(e_h);
LCD_IO_WriteData(e_l);
s_h = (StartY >> 8) & 0xFF;
s_l = StartY & 0xFF;
e_h = ((StartY + heigh - 1) >> 8) & 0xFF;
e_l = (StartY + heigh - 1) & 0xFF;
LCD_IO_WriteReg(0x2B);
LCD_IO_WriteData(s_h);
LCD_IO_WriteData(s_l);
LCD_IO_WriteData(e_h);
LCD_IO_WriteData(e_l);
}
}
void LCD_Clear(uint16_t Color) {
uint32_t index = 0;
unsigned int count;
if (DeviceCode == 0x9488) {
tft_set_cursor(0, 0);
LCD_setWindowArea(0, 0, TFT_WIDTH, TFT_HEIGHT);
LCD_WriteRAM_Prepare();
#ifdef LCD_USE_DMA_FSMC
LCD_IO_WriteMultiple(Color, (TFT_WIDTH) * (TFT_HEIGHT));
#else
//index = (TFT_HEIGHT) / 2 * (TFT_WIDTH);
for (index = 0; index < (TFT_HEIGHT) * (TFT_WIDTH); index++)
LCD_IO_WriteData(Color);
#endif
//LCD_IO_WriteMultiple(Color, (TFT_WIDTH) * (TFT_HEIGHT));
//while(index --) LCD_IO_WriteData(Color);
}
else if (DeviceCode == 0x5761) {
LCD_IO_WriteReg(0x002A);
LCD_IO_WriteData(0);
LCD_IO_WriteData(0);
LCD_IO_WriteData(HDP >> 8);
LCD_IO_WriteData(HDP & 0x00FF);
LCD_IO_WriteReg(0x002B);
LCD_IO_WriteData(0);
LCD_IO_WriteData(0);
LCD_IO_WriteData(VDP >> 8);
LCD_IO_WriteData(VDP & 0x00FF);
LCD_IO_WriteReg(0x002C);
LCD_IO_WriteReg(0x002C);
for (count = 0; count < (HDP + 1) * (VDP + 1); count++)
LCD_IO_WriteData(Color);
}
else {
tft_set_cursor(0, 0);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
for (index = 0; index < 76800; index++)
LCD_IO_WriteData(Color);
}
}
#include HAL_PATH(../../HAL, tft/tft_fsmc.h)
extern TFT_IO tftio;
void fsmc_tft_init() {
uint16_t i;
TERN_(HAS_LCD_CONTRAST, refresh_contrast());
#ifdef LCD_USE_DMA_FSMC
dma_init(FSMC_DMA_DEV);
dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
dma_set_priority(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, DMA_PRIORITY_MEDIUM);
#endif
LCD_IO_Init(FSMC_CS_PIN, FSMC_RS_PIN);
_delay_ms(5);
DeviceCode = tftio.GetID() & 0xFFFF;
// Chitu and others
if (DeviceCode == 0x8066) DeviceCode = 0x9488;
if (DeviceCode == 0x9488) {
LCD_IO_WriteReg(0x00E0);
LCD_IO_WriteData(0x0000);
LCD_IO_WriteData(0x0007);
LCD_IO_WriteData(0x000F);
LCD_IO_WriteData(0x000D);
LCD_IO_WriteData(0x001B);
LCD_IO_WriteData(0x000A);
LCD_IO_WriteData(0x003C);
LCD_IO_WriteData(0x0078);
LCD_IO_WriteData(0x004A);
LCD_IO_WriteData(0x0007);
LCD_IO_WriteData(0x000E);
LCD_IO_WriteData(0x0009);
LCD_IO_WriteData(0x001B);
LCD_IO_WriteData(0x001E);
LCD_IO_WriteData(0x000F);
LCD_IO_WriteReg(0x00E1);
LCD_IO_WriteData(0x0000);
LCD_IO_WriteData(0x0022);
LCD_IO_WriteData(0x0024);
LCD_IO_WriteData(0x0006);
LCD_IO_WriteData(0x0012);
LCD_IO_WriteData(0x0007);
LCD_IO_WriteData(0x0036);
LCD_IO_WriteData(0x0047);
LCD_IO_WriteData(0x0047);
LCD_IO_WriteData(0x0006);
LCD_IO_WriteData(0x000A);
LCD_IO_WriteData(0x0007);
LCD_IO_WriteData(0x0030);
LCD_IO_WriteData(0x0037);
LCD_IO_WriteData(0x000F);
LCD_IO_WriteReg(0x00C0);
LCD_IO_WriteData(0x0010);
LCD_IO_WriteData(0x0010);
LCD_IO_WriteReg(0x00C1);
LCD_IO_WriteData(0x0041);
LCD_IO_WriteReg(0x00C5);
LCD_IO_WriteData(0x0000);
LCD_IO_WriteData(0x0022);
LCD_IO_WriteData(0x0080);
LCD_IO_WriteReg(0x0036);
LCD_IO_WriteData(TERN(GRAPHICAL_TFT_ROTATE_180, 0xE8, 0x0068));
LCD_IO_WriteReg(0x003A); //Interface Mode Control
LCD_IO_WriteData(0x0055);
LCD_IO_WriteReg(0x00B0); //Interface Mode Control
LCD_IO_WriteData(0x0000);
LCD_IO_WriteReg(0x00B1); //Frame rate 70HZ
LCD_IO_WriteData(0x00B0);
LCD_IO_WriteData(0x0011);
LCD_IO_WriteReg(0x00B4);
LCD_IO_WriteData(0x0002);
LCD_IO_WriteReg(0x00B6); //RGB/MCU Interface Control
LCD_IO_WriteData(0x0002);
LCD_IO_WriteData(0x0042);
LCD_IO_WriteReg(0x00B7);
LCD_IO_WriteData(0x00C6);
//WriteComm(0xBE);
//WriteData(0x00);
//WriteData(0x04);
LCD_IO_WriteReg(0x00E9);
LCD_IO_WriteData(0x0000);
LCD_IO_WriteReg(0x00F7);
LCD_IO_WriteData(0x00A9);
LCD_IO_WriteData(0x0051);
LCD_IO_WriteData(0x002C);
LCD_IO_WriteData(0x0082);
LCD_IO_WriteReg(0x0011);
for (i = 0; i < 65535; i++) { /* do nothing */ }
LCD_IO_WriteReg(0x0029);
LCD_setWindowArea(0, 0, TFT_WIDTH, TFT_HEIGHT);
OUT_WRITE(LCD_BACKLIGHT_PIN, LOW);
LCD_Clear(0x0000);
TERN_(HAS_LOGO_IN_FLASH, lcd_draw_logo());
OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH);
delay(2000);
}
}
extern void LCD_IO_WriteSequence(uint16_t *data, uint16_t length);
void lcd_draw_logo() {
LCD_setWindowArea(0, 0, TFT_WIDTH, TFT_HEIGHT);
LCD_WriteRAM_Prepare();
for (uint16_t i = 0; i < (TFT_HEIGHT); i ++) {
Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, (TFT_WIDTH) * 2);
#ifdef LCD_USE_DMA_FSMC
LCD_IO_WriteSequence((uint16_t *)bmp_public_buf, TFT_WIDTH);
#else
int index = 0;,x_off = 0;
for (x_off = 0; x_off < TFT_WIDTH; x_off++) {
LCD_IO_WriteData((uint16_t)bmp_public_buf[index]);
index += 2;
}
#endif
}
}
#endif // !TFT_LVGL_UI_SPI
extern uint8_t bmp_public_buf[17 * 1024];
void tft_lvgl_init() {
@ -448,12 +118,8 @@ void tft_lvgl_init() {
disp_language_init();
//init tft first!
#if ENABLED(TFT_LVGL_UI_SPI)
SPI_TFT.spi_init(SPI_FULL_SPEED);
SPI_TFT.LCD_init();
#else
fsmc_tft_init();
#endif
SPI_TFT.spi_init(SPI_FULL_SPEED);
SPI_TFT.LCD_init();
//spi_flash_read_test();
#if ENABLED(SDSUPPORT)
@ -548,41 +214,18 @@ void tft_lvgl_init() {
}
void my_disp_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) {
#if ENABLED(TFT_LVGL_UI_SPI)
uint16_t i, width, height;
uint16_t i, width, height;
width = area->x2 - area->x1 + 1;
height = area->y2 - area->y1 + 1;
width = area->x2 - area->x1 + 1;
height = area->y2 - area->y1 + 1;
SPI_TFT.SetWindows((uint16_t)area->x1, (uint16_t)area->y1, width, height);
for (i = 0; i < height; i++) {
SPI_TFT.tftio.WriteSequence((uint16_t*)(color_p + width * i), width);
}
lv_disp_flush_ready(disp); /* Indicate you are ready with the flushing*/
SPI_TFT.setWindow((uint16_t)area->x1, (uint16_t)area->y1, width, height);
for (i = 0; i < height; i++) {
SPI_TFT.tftio.WriteSequence((uint16_t*)(color_p + width * i), width);
}
lv_disp_flush_ready(disp); /* Indicate you are ready with the flushing*/
W25QXX.init(SPI_QUARTER_SPEED);
#else // !TFT_LVGL_UI_SPI
#if 1
uint16_t i, width, height;
//uint16_t clr_temp;
width = area->x2 - area->x1 + 1;
height = area->y2 - area->y1 + 1;
LCD_setWindowArea((uint16_t)area->x1, (uint16_t)area->y1, width, height);
LCD_WriteRAM_Prepare();
for (i = 0; i < width * height - 2; i++) {
//clr_temp = (uint16_t)(((uint16_t)color_p->ch.red << 11)
//| ((uint16_t)color_p->ch.green << 5)
//| ((uint16_t)color_p->ch.blue));
LCD_IO_WriteData(color_p->full);
color_p++;
}
lv_disp_flush_ready(disp); /* Indicate you are ready with the flushing*/
#endif
#endif // !TFT_LVGL_UI_SPI
W25QXX.init(SPI_QUARTER_SPEED);
}
#define TICK_CYCLE 1
@ -599,7 +242,7 @@ static bool get_point(int16_t *x, int16_t *y) {
*y = int16_t((int32_t(*y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET;
}
#if ENABLED(GRAPHICAL_TFT_ROTATE_180)
#if (TFT_ROTATION & TFT_ROTATE_180)
*x = int16_t((TFT_WIDTH) - (int)(*x));
*y = int16_t((TFT_HEIGHT) - (int)(*y));
#endif

View File

@ -32,7 +32,7 @@
#include <lvgl.h>
//#define GRAPHICAL_TFT_ROTATE_180
//#define TFT_ROTATION TFT_ROTATE_180
#define USE_WIFI_FUNCTION 0
extern void tft_lvgl_init();