Tasmota/tasmota/xdsp_08_ILI9488.ino

196 lines
4.8 KiB
Arduino
Raw Normal View History

2019-08-19 12:21:54 +01:00
/*
xdsp_08_ILI9488.ino - Display ILI9488 support for Tasmota
2019-08-19 12:21:54 +01:00
2019-12-31 13:23:34 +00:00
Copyright (C) 2020 Theo Arends, Gerhard Mutz
2019-08-19 12:21:54 +01:00
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 <http://www.gnu.org/licenses/>.
*/
#ifdef USE_SPI
#ifdef USE_DISPLAY
#ifdef USE_DISPLAY_ILI9488
#define XDSP_08 8
2019-11-07 15:56:05 +00:00
#define XI2C_38 38 // See I2CDEVICES.md
2019-08-19 12:21:54 +01:00
#define COLORED 1
#define UNCOLORED 0
// using font 8 is opional (num=3)
// very badly readable, but may be useful for graphs
#define USE_TINY_FONT
#include <ILI9488.h>
2019-08-23 09:26:09 +01:00
uint8_t ili9488_ctouch_counter = 0;
2019-08-19 12:21:54 +01:00
// currently fixed
#define BACKPLANE_PIN 2
extern uint8_t *buffer;
extern uint8_t color_type;
ILI9488 *ili9488;
extern const uint16_t picture[];
/*********************************************************************************************/
void ILI9488_InitDriver()
{
if (!Settings.display_model) {
Settings.display_model = XDSP_08;
}
if (XDSP_08 == Settings.display_model) {
if (Settings.display_width != ILI9488_TFTWIDTH) {
Settings.display_width = ILI9488_TFTWIDTH;
}
if (Settings.display_height != ILI9488_TFTHEIGHT) {
Settings.display_height = ILI9488_TFTHEIGHT;
}
// disable screen buffer
buffer=NULL;
// default colors
fg_color = ILI9488_WHITE;
bg_color = ILI9488_BLACK;
uint8_t bppin=BACKPLANE_PIN;
2020-04-27 11:54:07 +01:00
if (PinUsed(GPIO_BACKLIGHT)) {
2020-04-27 10:54:23 +01:00
bppin=Pin(GPIO_BACKLIGHT);
2019-08-19 12:21:54 +01:00
}
2020-05-29 18:29:03 +01:00
#ifdef ESP32
#undef HW_SPI_MOSI
#define HW_SPI_MOSI 23
#undef HW_SPI_MISO
#define HW_SPI_MISO 19
#undef HW_SPI_CLK
#define HW_SPI_CLK 18
#else
#undef HW_SPI_MOSI
#define HW_SPI_MOSI 13
#undef HW_SPI_MISO
#define HW_SPI_MISO 12
#undef HW_SPI_CLK
#define HW_SPI_CLK 14
#endif
// init renderer, must use hardware spi
if (PinUsed(GPIO_SSPI_CS) && (Pin(GPIO_SSPI_MOSI)==HW_SPI_MOSI) && (Pin(GPIO_SSPI_SCLK)==HW_SPI_CLK)) {
ili9488 = new ILI9488(Pin(GPIO_SSPI_CS),Pin(GPIO_SSPI_MOSI),Pin(GPIO_SSPI_SCLK),bppin);
2019-08-19 12:21:54 +01:00
} else {
2020-05-29 18:29:03 +01:00
if (PinUsed(GPIO_SPI_CS) && (Pin(GPIO_SPI_MOSI)==HW_SPI_MOSI) && (Pin(GPIO_SPI_CLK)==HW_SPI_CLK)) {
2020-04-27 10:54:23 +01:00
ili9488 = new ILI9488(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_MOSI),Pin(GPIO_SPI_CLK),bppin);
2019-08-19 12:21:54 +01:00
} else {
return;
}
}
ili9488->begin();
renderer = ili9488;
renderer->DisplayInit(DISPLAY_INIT_MODE,Settings.display_size,Settings.display_rotate,Settings.display_font);
#ifdef SHOW_SPLASH
// Welcome text
renderer->setTextFont(2);
renderer->setTextColor(ILI9488_WHITE,ILI9488_BLACK);
renderer->DrawStringAt(50, 50, "ILI9488 TFT Display!", ILI9488_WHITE,0);
delay(1000);
//renderer->drawRGBBitmap(100,100, picture,51,34);
#endif
color_type = COLOR_COLOR;
2020-09-03 11:26:03 +01:00
// start digitizer
#ifdef USE_FT5206
Touch_Init(Wire);
#endif
2019-08-19 12:21:54 +01:00
}
}
2020-09-03 11:26:03 +01:00
#ifdef USE_FT5206
2019-08-19 12:38:14 +01:00
#ifdef USE_TOUCH_BUTTONS
2020-09-03 11:26:03 +01:00
void ILI9488_RotConvert(int16_t *x, int16_t *y) {
int16_t temp;
if (renderer) {
uint8_t rot=renderer->getRotation();
switch (rot) {
case 0:
temp=*y;
*y=renderer->height()-*x;
*x=temp;
break;
case 1:
break;
case 2:
break;
case 3:
temp=*y;
*y=*x;
*x=renderer->width()-temp;
break;
}
}
2019-08-19 12:21:54 +01:00
}
2020-09-03 11:26:03 +01:00
// check digitizer hit
void ILI9488_CheckTouch(void) {
ili9488_ctouch_counter++;
if (2 == ili9488_ctouch_counter) {
// every 100 ms should be enough
ili9488_ctouch_counter = 0;
Touch_Check(ILI9488_RotConvert);
}
}
2020-09-03 11:26:03 +01:00
#endif // USE_TOUCH_BUTTONS
#endif // USE_FT5206
2019-08-19 12:21:54 +01:00
/*********************************************************************************************/
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
2019-08-23 09:26:09 +01:00
bool Xdsp08(uint8_t function)
2019-08-19 12:21:54 +01:00
{
bool result = false;
if (FUNC_DISPLAY_INIT_DRIVER == function) {
ILI9488_InitDriver();
}
else if (XDSP_08 == Settings.display_model) {
switch (function) {
case FUNC_DISPLAY_MODEL:
result = true;
break;
case FUNC_DISPLAY_EVERY_50_MSECOND:
2019-08-19 12:38:14 +01:00
#ifdef USE_TOUCH_BUTTONS
2020-09-03 11:26:03 +01:00
if (FT5206_found) {
ILI9488_CheckTouch();
}
2019-08-19 12:38:14 +01:00
#endif
2019-08-19 12:21:54 +01:00
break;
}
}
//}
return result;
}
#endif // USE_DISPLAY_ILI9488
#endif // USE_DISPLAY
#endif // USE_SPI