2020-08-05 19:21:21 +01:00
|
|
|
/*
|
|
|
|
xdsp_12_ST7789.ino - Display ST7789 support for Tasmota
|
|
|
|
|
2021-01-01 12:44:04 +00:00
|
|
|
Copyright (C) 2021 Gerhard Mutz and Theo Arends
|
2020-08-05 19:21:21 +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/>.
|
|
|
|
*/
|
|
|
|
|
2020-09-03 11:26:03 +01:00
|
|
|
//#ifdef USE_SPI
|
2020-08-05 19:21:21 +01:00
|
|
|
#ifdef USE_SPI
|
|
|
|
#ifdef USE_DISPLAY
|
|
|
|
#ifdef USE_DISPLAY_ST7789
|
|
|
|
|
|
|
|
#define XDSP_12 12
|
|
|
|
#define XI2C_38 38 // See I2CDEVICES.md
|
|
|
|
|
|
|
|
#undef COLORED
|
|
|
|
#define COLORED 1
|
|
|
|
#undef UNCOLORED
|
|
|
|
#define UNCOLORED 0
|
|
|
|
|
|
|
|
// touch panel controller
|
|
|
|
#undef FT5206_address
|
|
|
|
#define FT5206_address 0x38
|
|
|
|
|
|
|
|
// using font 8 is opional (num=3)
|
|
|
|
// very badly readable, but may be useful for graphs
|
|
|
|
#undef USE_TINY_FONT
|
|
|
|
#define USE_TINY_FONT
|
|
|
|
|
|
|
|
|
|
|
|
#include <Arduino_ST7789.h>
|
|
|
|
#include <FT5206.h>
|
|
|
|
|
|
|
|
// currently fixed
|
|
|
|
#define BACKPLANE_PIN 2
|
2021-01-03 07:08:03 +00:00
|
|
|
#ifdef USE_LANBON_L8
|
|
|
|
#undef BACKPLANE_PIN
|
|
|
|
#define BACKPLANE_PIN 5
|
|
|
|
#endif // USE_LANBON_L8
|
2020-08-05 19:21:21 +01:00
|
|
|
|
|
|
|
extern uint8_t color_type;
|
|
|
|
Arduino_ST7789 *st7789;
|
|
|
|
|
|
|
|
#ifdef USE_FT5206
|
|
|
|
uint8_t st7789_ctouch_counter = 0;
|
|
|
|
#endif // USE_FT5206
|
2020-12-31 15:17:30 +00:00
|
|
|
bool st7789_init_done = false;
|
2020-08-05 19:21:21 +01:00
|
|
|
|
|
|
|
/*********************************************************************************************/
|
|
|
|
|
2020-12-31 15:17:30 +00:00
|
|
|
void ST7789_InitDriver(void) {
|
2021-01-01 14:05:58 +00:00
|
|
|
if (PinUsed(GPIO_ST7789_DC) && // This device does not need CS which breaks SPI bus usage
|
2020-12-31 15:17:30 +00:00
|
|
|
((TasmotaGlobal.soft_spi_enabled & SPI_MOSI) || (TasmotaGlobal.spi_enabled & SPI_MOSI))) {
|
2020-08-05 19:21:21 +01:00
|
|
|
|
2021-06-11 17:14:12 +01:00
|
|
|
Settings->display_model = XDSP_12;
|
2020-08-05 19:21:21 +01:00
|
|
|
|
2021-06-11 17:14:12 +01:00
|
|
|
if (!Settings->display_width) {
|
|
|
|
Settings->display_width = 240;
|
2020-08-05 19:21:21 +01:00
|
|
|
}
|
2021-06-11 17:14:12 +01:00
|
|
|
if (!Settings->display_height) {
|
|
|
|
Settings->display_height = 240;
|
2020-08-05 19:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// default colors
|
|
|
|
fg_color = ST7789_WHITE;
|
|
|
|
bg_color = ST7789_BLACK;
|
|
|
|
|
2020-12-31 15:17:30 +00:00
|
|
|
int8_t bppin = BACKPLANE_PIN;
|
|
|
|
if (PinUsed(GPIO_BACKLIGHT)) {
|
|
|
|
bppin = Pin(GPIO_BACKLIGHT);
|
2020-08-05 19:21:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// init renderer, may use hardware spi
|
2020-12-31 15:17:30 +00:00
|
|
|
if (TasmotaGlobal.soft_spi_enabled) {
|
2021-02-14 12:06:19 +00:00
|
|
|
st7789 = new Arduino_ST7789(Pin(GPIO_ST7789_DC), Pin(GPIO_OLED_RESET), Pin(GPIO_SSPI_MOSI), Pin(GPIO_SSPI_SCLK), Pin(GPIO_ST7789_CS), bppin);
|
2020-08-05 19:21:21 +01:00
|
|
|
}
|
2020-12-31 15:17:30 +00:00
|
|
|
else if (TasmotaGlobal.spi_enabled) {
|
2021-02-14 12:06:19 +00:00
|
|
|
st7789 = new Arduino_ST7789(Pin(GPIO_ST7789_DC), Pin(GPIO_OLED_RESET), Pin(GPIO_ST7789_CS), bppin);
|
2020-12-31 15:17:30 +00:00
|
|
|
}
|
|
|
|
|
2021-06-11 17:14:12 +01:00
|
|
|
st7789->init(Settings->display_width,Settings->display_height);
|
2020-08-05 19:21:21 +01:00
|
|
|
renderer = st7789;
|
2021-06-11 17:14:12 +01:00
|
|
|
renderer->DisplayInit(DISPLAY_INIT_MODE,Settings->display_size,Settings->display_rotate,Settings->display_font);
|
2021-09-14 21:40:26 +01:00
|
|
|
renderer->dim(GetDisplayDimmer16());
|
2020-08-05 19:21:21 +01:00
|
|
|
|
|
|
|
#ifdef SHOW_SPLASH
|
|
|
|
// Welcome text
|
|
|
|
renderer->setTextColor(ST7789_WHITE,ST7789_BLACK);
|
2020-12-29 16:42:36 +00:00
|
|
|
renderer->setTextFont(2);
|
2021-06-11 17:14:12 +01:00
|
|
|
renderer->DrawStringAt(30, (Settings->display_height-12)/2, "ST7789 TFT!", ST7789_WHITE,0);
|
2020-08-05 19:21:21 +01:00
|
|
|
delay(1000);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
color_type = COLOR_COLOR;
|
|
|
|
|
|
|
|
#ifdef ESP32
|
|
|
|
#ifdef USE_FT5206
|
|
|
|
// start digitizer with fixed adress and pins for esp32
|
2021-04-21 10:01:40 +01:00
|
|
|
#undef SDA_2
|
|
|
|
#undef SCL_2
|
2020-08-05 19:21:21 +01:00
|
|
|
#define SDA_2 23
|
|
|
|
#define SCL_2 32
|
2021-01-03 07:08:03 +00:00
|
|
|
#ifdef USE_LANBON_L8
|
2021-01-04 15:34:44 +00:00
|
|
|
#undef SDA_2
|
|
|
|
#undef SCL_2
|
2021-01-03 07:08:03 +00:00
|
|
|
#define SDA_2 4
|
|
|
|
#define SCL_2 0
|
|
|
|
#endif // USE_LANBON_L8
|
2022-02-07 10:40:35 +00:00
|
|
|
Wire1.begin(SDA_2, SCL_2, (uint32_t)400000);
|
2021-04-21 10:01:40 +01:00
|
|
|
FT5206_Touch_Init(Wire1);
|
2020-08-05 19:21:21 +01:00
|
|
|
#endif // USE_FT5206
|
|
|
|
#endif // ESP32
|
|
|
|
|
2020-12-31 15:17:30 +00:00
|
|
|
st7789_init_done = true;
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("DSP: ST7789"));
|
2020-08-05 19:21:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ESP32
|
|
|
|
#ifdef USE_FT5206
|
|
|
|
#ifdef USE_TOUCH_BUTTONS
|
|
|
|
|
2020-09-03 11:26:03 +01:00
|
|
|
void ST7789_RotConvert(int16_t *x, int16_t *y) {
|
|
|
|
int16_t temp;
|
|
|
|
if (renderer) {
|
|
|
|
uint8_t rot=renderer->getRotation();
|
|
|
|
switch (rot) {
|
2020-08-29 10:30:23 +01:00
|
|
|
case 0:
|
2020-09-03 11:26:03 +01:00
|
|
|
break;
|
2020-08-29 10:30:23 +01:00
|
|
|
case 1:
|
2020-09-03 11:26:03 +01:00
|
|
|
temp=*y;
|
|
|
|
*y=renderer->height()-*x;
|
|
|
|
*x=temp;
|
|
|
|
break;
|
2020-08-29 10:30:23 +01:00
|
|
|
case 2:
|
2020-09-03 11:26:03 +01:00
|
|
|
*x=renderer->width()-*x;
|
|
|
|
*y=renderer->height()-*y;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
temp=*y;
|
|
|
|
*y=*x;
|
|
|
|
*x=renderer->width()-temp;
|
|
|
|
break;
|
2020-08-29 10:30:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-05 19:21:21 +01:00
|
|
|
// check digitizer hit
|
2020-09-03 11:26:03 +01:00
|
|
|
void ST7789_CheckTouch() {
|
2020-08-05 19:21:21 +01:00
|
|
|
st7789_ctouch_counter++;
|
2020-09-03 11:26:03 +01:00
|
|
|
if (2 == st7789_ctouch_counter) {
|
|
|
|
// every 100 ms should be enough
|
|
|
|
st7789_ctouch_counter = 0;
|
|
|
|
Touch_Check(ST7789_RotConvert);
|
2020-08-05 19:21:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // USE_TOUCH_BUTTONS
|
|
|
|
#endif // USE_FT5206
|
|
|
|
#endif // ESP32
|
|
|
|
|
|
|
|
/*********************************************************************************************/
|
|
|
|
/*********************************************************************************************\
|
|
|
|
* Interface
|
|
|
|
\*********************************************************************************************/
|
|
|
|
bool Xdsp12(uint8_t function)
|
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
|
2021-01-23 16:10:06 +00:00
|
|
|
//AddLog(LOG_LEVEL_INFO, PSTR("touch %d - %d"), FT5206_found, function);
|
2020-08-05 19:21:21 +01:00
|
|
|
|
|
|
|
if (FUNC_DISPLAY_INIT_DRIVER == function) {
|
|
|
|
ST7789_InitDriver();
|
|
|
|
}
|
2021-06-11 17:14:12 +01:00
|
|
|
else if (st7789_init_done && (XDSP_12 == Settings->display_model)) {
|
2020-08-05 19:21:21 +01:00
|
|
|
switch (function) {
|
|
|
|
case FUNC_DISPLAY_MODEL:
|
|
|
|
result = true;
|
|
|
|
break;
|
|
|
|
case FUNC_DISPLAY_EVERY_50_MSECOND:
|
|
|
|
#ifdef USE_FT5206
|
|
|
|
#ifdef USE_TOUCH_BUTTONS
|
|
|
|
if (FT5206_found) {
|
2020-09-03 11:26:03 +01:00
|
|
|
ST7789_CheckTouch();
|
2020-08-05 19:21:21 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif // USE_FT5206
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_DISPLAY_ST7789
|
|
|
|
#endif // USE_DISPLAY
|
|
|
|
#endif // USE_SPI
|