2020-06-16 04:05:33 +02:00
|
|
|
/**
|
|
|
|
* 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
|
2020-07-23 05:20:14 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-06-16 04:05:33 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../../../../inc/MarlinConfigPre.h"
|
|
|
|
|
2020-07-25 07:52:07 +02:00
|
|
|
#if ENABLED(TFT_LVGL_UI_SPI)
|
2020-06-16 04:05:33 +02:00
|
|
|
|
2020-07-25 07:52:07 +02:00
|
|
|
#include "SPI_TFT.h"
|
|
|
|
#include "pic_manager.h"
|
2020-06-16 04:05:33 +02:00
|
|
|
|
2020-07-25 07:52:07 +02:00
|
|
|
#include "../../../../inc/MarlinConfig.h"
|
2020-06-16 04:05:33 +02:00
|
|
|
|
2020-07-25 07:52:07 +02:00
|
|
|
#include <SPI.h>
|
|
|
|
|
|
|
|
TFT SPI_TFT;
|
|
|
|
|
|
|
|
#ifndef SPI_TFT_MISO_PIN
|
|
|
|
#define SPI_TFT_MISO_PIN PA6
|
|
|
|
#endif
|
|
|
|
#ifndef SPI_TFT_MOSI_PIN
|
|
|
|
#define SPI_TFT_MOSI_PIN PA7
|
|
|
|
#endif
|
|
|
|
#ifndef SPI_TFT_SCK_PIN
|
|
|
|
#define SPI_TFT_SCK_PIN PA5
|
|
|
|
#endif
|
|
|
|
#ifndef SPI_TFT_CS_PIN
|
|
|
|
#define SPI_TFT_CS_PIN PD11
|
|
|
|
#endif
|
|
|
|
#ifndef SPI_TFT_DC_PIN
|
|
|
|
#define SPI_TFT_DC_PIN PD10
|
|
|
|
#endif
|
|
|
|
#ifndef SPI_TFT_RST_PIN
|
|
|
|
#define SPI_TFT_RST_PIN PC6
|
|
|
|
#endif
|
2020-06-16 04:05:33 +02:00
|
|
|
|
|
|
|
// use SPI1 for the spi tft.
|
2020-07-25 07:52:07 +02:00
|
|
|
void TFT::spi_init(uint8_t spiRate) {
|
2020-08-14 01:31:59 +02:00
|
|
|
tftio.Init();
|
2020-07-25 07:52:07 +02:00
|
|
|
}
|
2020-06-16 04:05:33 +02:00
|
|
|
|
2020-07-25 07:52:07 +02:00
|
|
|
void TFT::LCD_WR_REG(uint8_t cmd) {
|
2020-08-14 01:31:59 +02:00
|
|
|
tftio.WriteReg(cmd);
|
2020-07-25 07:52:07 +02:00
|
|
|
}
|
|
|
|
|
2020-08-14 01:31:59 +02:00
|
|
|
void TFT::LCD_WR_DATA(uint8_t data) {
|
|
|
|
tftio.WriteData(data);
|
2020-07-25 07:52:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TFT::SetPoint(uint16_t x, uint16_t y, uint16_t point) {
|
|
|
|
if ((x > 480) || (y > 320)) return;
|
|
|
|
|
2020-08-14 01:31:59 +02:00
|
|
|
SetWindows(x, y, 1, 1);
|
|
|
|
tftio.WriteMultiple(point, (uint16_t)1);
|
2020-07-25 07:52:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TFT::SetWindows(uint16_t x, uint16_t y, uint16_t with, uint16_t height) {
|
2020-08-14 01:31:59 +02:00
|
|
|
tftio.DataTransferBegin(DATASIZE_8BIT);
|
|
|
|
|
2020-07-25 07:52:07 +02:00
|
|
|
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);
|
2020-08-14 01:31:59 +02:00
|
|
|
|
|
|
|
LCD_WR_REG(0X2C);
|
|
|
|
|
|
|
|
tftio.DataTransferEnd();
|
2020-07-25 07:52:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TFT::LCD_init() {
|
|
|
|
SPI_TFT_RST_H;
|
|
|
|
delay(150);
|
|
|
|
SPI_TFT_RST_L;
|
|
|
|
delay(150);
|
|
|
|
SPI_TFT_RST_H;
|
|
|
|
|
2020-08-14 01:31:59 +02:00
|
|
|
tftio.DataTransferBegin(DATASIZE_8BIT);
|
|
|
|
|
2020-07-25 07:52:07 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-08-14 01:31:59 +02:00
|
|
|
tftio.DataTransferEnd();
|
|
|
|
|
2020-07-25 07:52:07 +02:00
|
|
|
LCD_clear(0x0000); //
|
|
|
|
LCD_Draw_Logo();
|
|
|
|
SPI_TFT_BLK_H;
|
|
|
|
delay(2000);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TFT::LCD_clear(uint16_t color) {
|
2020-08-14 01:31:59 +02:00
|
|
|
SetWindows(0, 0, (LCD_FULL_PIXEL_WIDTH) - 1, (LCD_FULL_PIXEL_HEIGHT) - 1);
|
|
|
|
tftio.WriteMultiple(color, (uint32_t)(LCD_FULL_PIXEL_WIDTH) * (LCD_FULL_PIXEL_HEIGHT));
|
2020-07-25 07:52:07 +02:00
|
|
|
}
|
2020-06-16 04:05:33 +02:00
|
|
|
|
2020-07-25 07:52:07 +02:00
|
|
|
extern unsigned char bmp_public_buf[17 * 1024];
|
|
|
|
|
|
|
|
void TFT::LCD_Draw_Logo() {
|
2020-08-14 01:31:59 +02:00
|
|
|
SetWindows(0, 0, LCD_FULL_PIXEL_WIDTH, LCD_FULL_PIXEL_HEIGHT);
|
|
|
|
for (uint16_t i = 0; i < (LCD_FULL_PIXEL_HEIGHT); i ++) {
|
|
|
|
Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, (LCD_FULL_PIXEL_WIDTH) * 2);
|
|
|
|
tftio.WriteSequence((uint16_t *)bmp_public_buf, LCD_FULL_PIXEL_WIDTH);
|
|
|
|
}
|
2020-07-25 07:52:07 +02:00
|
|
|
}
|
2020-06-16 04:05:33 +02:00
|
|
|
|
2020-07-25 07:52:07 +02:00
|
|
|
#endif // HAS_TFT_LVGL_UI_SPI
|