Tasmota/tasmota/xdsp_08_ILI9488.ino

168 lines
4.3 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
2021-01-01 12:44:04 +00:00
Copyright (C) 2021 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;
bool ili9488_init_done = false;
2019-08-19 12:21:54 +01:00
// currently fixed
#define BACKPLANE_PIN 2
extern uint8_t color_type;
ILI9488 *ili9488;
extern const uint16_t picture[];
/*********************************************************************************************/
void ILI9488_InitDriver(void) {
if (PinUsed(GPIO_ILI9488_CS) && (TasmotaGlobal.spi_enabled & SPI_MOSI)) {
2019-08-19 12:21:54 +01:00
2021-06-11 17:14:12 +01:00
Settings->display_model = XDSP_08;
2019-08-19 12:21:54 +01:00
2021-06-11 17:14:12 +01:00
if (Settings->display_width != ILI9488_TFTWIDTH) {
Settings->display_width = ILI9488_TFTWIDTH;
2019-08-19 12:21:54 +01:00
}
2021-06-11 17:14:12 +01:00
if (Settings->display_height != ILI9488_TFTHEIGHT) {
Settings->display_height = ILI9488_TFTHEIGHT;
2019-08-19 12:21:54 +01:00
}
// default colors
fg_color = ILI9488_WHITE;
bg_color = ILI9488_BLACK;
int8_t bppin = BACKPLANE_PIN;
if (PinUsed(GPIO_BACKLIGHT)) {
bppin = Pin(GPIO_BACKLIGHT);
2019-08-19 12:21:54 +01:00
}
2020-05-29 18:29:03 +01:00
// init renderer, must use hardware spi
ili9488 = new ILI9488(Pin(GPIO_ILI9488_CS), Pin(GPIO_SPI_MOSI), Pin(GPIO_SPI_CLK), bppin);
2019-08-19 12:21:54 +01:00
ili9488->begin();
renderer = ili9488;
2021-06-11 17:14:12 +01:00
renderer->DisplayInit(DISPLAY_INIT_MODE,Settings->display_size,Settings->display_rotate,Settings->display_font);
renderer->dim(GetDisplayDimmer16());
2019-08-19 12:21:54 +01:00
#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
2021-04-21 10:01:40 +01:00
FT5206_Touch_Init(Wire);
2020-09-03 11:26:03 +01:00
#endif
ili9488_init_done = true;
2021-01-23 16:10:06 +00:00
AddLog(LOG_LEVEL_INFO, PSTR("DSP: ILI9488"));
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();
}
2021-06-11 17:14:12 +01:00
else if (ili9488_init_done && (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
if (FT5206_found) {
ILI9488_CheckTouch();
}
2019-08-19 12:38:14 +01:00
#endif
break;
2019-08-19 12:21:54 +01:00
}
}
2019-08-19 12:21:54 +01:00
return result;
}
#endif // USE_DISPLAY_ILI9488
#endif // USE_DISPLAY
#endif // USE_SPI