Update LovyanGFX driver for Lanbon L8 #220

This commit is contained in:
fvanroie 2022-04-06 00:45:56 +02:00
parent c26570c13e
commit 10ec121143
5 changed files with 103 additions and 78 deletions

View File

@ -63,7 +63,7 @@
- Prepare support for ESP32-S2
- **Breaking:** Removed support for ESP8266!
Updated libraries to ArduinoJson 6.19.3, ArduinoStreamUtils 1.6.2, TFT_eSPI 2.4.42, LovyanGFX 0.4.14 and Adafruit STMPE610 1.1.4
Updated libraries to ArduinoJson 6.19.3, ArduinoStreamUtils 1.6.2, TFT_eSPI 2.4.43, LovyanGFX 0.4.15 and Adafruit STMPE610 1.1.4
## v0.6.2

View File

@ -98,11 +98,11 @@ src_filter = +<*> -<.git/> -<examples/> -<test/> -<tests/> -<stm32f4/> -<lv_font
[lovyangfx]
lib_deps =
lovyan03/LovyanGFX @ ^0.4.14
lovyan03/LovyanGFX @ ^0.4.15
[tft_espi]
lib_deps =
bodmer/TFT_eSPI @ 2.4.42
bodmer/TFT_eSPI @ 2.4.43
[goodix]
lib_deps =

View File

@ -54,7 +54,7 @@ static lgfx::Bus_Parallel16* init_parallel_16_bus(Preferences* prefs, int8_t dat
cfg.pin_wr = prefs->getInt("wr", TFT_WR);
cfg.pin_rs = prefs->getInt("rs", TFT_DC);
cfg.freq_write = prefs->getUInt("write_freq", SPI_FREQUENCY);
uint8_t port = prefs->getUInt("port", 0);
uint8_t port = prefs->getUInt("i2s_port", 0);
switch(port) {
#if SOC_I2S_NUM > 1
case 1:
@ -81,7 +81,7 @@ static lgfx::Bus_Parallel8* init_parallel_8_bus(Preferences* prefs, int8_t data_
cfg.pin_wr = prefs->getInt("wr", TFT_WR);
cfg.pin_rs = prefs->getInt("rs", TFT_DC);
cfg.freq_write = prefs->getUInt("write_freq", SPI_FREQUENCY);
uint8_t port = prefs->getUInt("port", 0);
uint8_t port = prefs->getUInt("i2s_port", 0);
switch(port) {
#if SOC_I2S_NUM > 1
case 1:
@ -169,7 +169,7 @@ static lgfx::Bus_SPI* init_spi_bus(Preferences* prefs)
return bus;
}
static void init_panel(lgfx::Panel_Device* panel, Preferences* prefs)
static void configure_panel(lgfx::Panel_Device* panel, Preferences* prefs)
{
auto cfg = panel->config(); // Get the structure for display panel settings.
@ -194,14 +194,15 @@ static void init_panel(lgfx::Panel_Device* panel, Preferences* prefs)
prefs->getUInt("dummy_read_bits", 1); // bits of dummy read before reading data other than pixels
cfg.readable = prefs->getBool("readable", false); // true if data can be read
// #ifdef INVERT_COLORS // This is configurable un Web UI
// cfg.invert =
// prefs->getBool("invert", INVERT_COLORS != 0); // true if the light and darkness of the panel is reversed
// #else
cfg.invert = prefs->getBool("invert", false); // true if the light and darkness of the panel is reversed
// #ifdef INVERT_COLORS // This is configurable un Web UI
// cfg.invert =
// prefs->getBool("invert", INVERT_COLORS != 0); // true if the light and darkness of the panel is reversed
// #else
cfg.invert = prefs->getBool("invert", false); // true if the light and darkness of the panel is reversed
// #endif
#ifdef TFT_RGB_ORDER
cfg.rgb_order = prefs->getBool("rgb_order", true); // true if the red and blue of the panel are swapped
cfg.rgb_order =
prefs->getBool("rgb_order", TFT_RGB_ORDER != 0); // true if the red and blue of the panel are swapped
#else
cfg.rgb_order = prefs->getBool("rgb_order", false); // true if the red and blue of the panel are swapped
#endif
@ -211,94 +212,80 @@ static void init_panel(lgfx::Panel_Device* panel, Preferences* prefs)
panel->config(cfg);
}
void LovyanGfx::init(int w, int h)
// Initialize the bus
lgfx::IBus* _init_bus(Preferences* preferences)
{
LOG_TRACE(TAG_TFT, F(D_SERVICE_STARTING));
if(!preferences) return nullptr;
Preferences preferences;
preferences.begin("tft", false);
lgfx::IBus* bus;
{ // Initialize the bus
char key[8];
int8_t data_pins[16] = {TFT_D0, TFT_D1, TFT_D2, TFT_D3, TFT_D4, TFT_D5, TFT_D6, TFT_D7,
TFT_D8, TFT_D9, TFT_D10, TFT_D11, TFT_D12, TFT_D13, TFT_D14, TFT_D15};
for(uint8_t i = 0; i < 16; i++) {
snprintf(key, sizeof(key), "d%d", i + 1);
data_pins[i] = preferences.getInt(key, data_pins[i]);
LOG_DEBUG(TAG_TFT, F("D%d: %d"), i + 1, data_pins[i]);
}
LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__);
bool is_8bit = true;
bool is_16bit = true;
for(uint8_t i = 0; i < 16; i++) {
if(i < 8) is_8bit = is_8bit && (data_pins[i] >= 0);
is_16bit = is_16bit && (data_pins[i] >= 0);
}
LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__);
#if defined(ESP32S2)
if(is_16bit) {
is_8bit = false;
bus = init_parallel_16_bus(&preferences, data_pins, 16);
} else
#endif // ESP32S2
if(is_8bit) {
is_16bit = false;
bus = init_parallel_8_bus(&preferences, data_pins, 8);
} else {
bus = init_spi_bus(&preferences);
}
char key[8];
int8_t data_pins[16] = {TFT_D0, TFT_D1, TFT_D2, TFT_D3, TFT_D4, TFT_D5, TFT_D6, TFT_D7,
TFT_D8, TFT_D9, TFT_D10, TFT_D11, TFT_D12, TFT_D13, TFT_D14, TFT_D15};
for(uint8_t i = 0; i < 16; i++) {
snprintf(key, sizeof(key), "d%d", i + 1);
data_pins[i] = preferences->getInt(key, data_pins[i]);
LOG_DEBUG(TAG_TFT, F("D%d: %d"), i + 1, data_pins[i]);
}
uint32_t tft_driver = preferences.getUInt("DRIVER", get_tft_driver());
LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__);
bool is_8bit = true;
bool is_16bit = true;
for(uint8_t i = 0; i < 16; i++) {
if(i < 8) is_8bit = is_8bit && (data_pins[i] >= 0);
is_16bit = is_16bit && (data_pins[i] >= 0);
}
LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__);
#if defined(ESP32S2)
if(is_16bit) {
is_8bit = false;
return init_parallel_16_bus(preferences, data_pins, 16);
} else
#endif // ESP32S2
if(is_8bit) {
is_16bit = false;
return init_parallel_8_bus(preferences, data_pins, 8);
} else {
return init_spi_bus(preferences);
}
return nullptr;
}
lgfx::Panel_Device* LovyanGfx::_init_panel(lgfx::IBus* bus)
{
lgfx::Panel_Device* panel = nullptr;
switch(tft_driver) {
case 0x9341: {
auto panel = new lgfx::Panel_ILI9341();
panel->setBus(bus);
init_panel(panel, &preferences);
tft.setPanel(panel);
panel = new lgfx::Panel_ILI9341();
LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__);
break;
}
case 0x9342: {
auto panel = new lgfx::Panel_ILI9342();
panel->setBus(bus);
init_panel(panel, &preferences);
tft.setPanel(panel);
panel = new lgfx::Panel_ILI9342();
LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__);
break;
}
case 0x9481: {
auto panel = new lgfx::Panel_ILI9481();
panel->setBus(bus);
init_panel(panel, &preferences);
tft.setPanel(panel);
panel = new lgfx::Panel_ILI9481();
LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__);
break;
}
case 0x9488: {
auto panel = new lgfx::Panel_ILI9488();
panel->setBus(bus);
init_panel(panel, &preferences);
tft.setPanel(panel);
panel = new lgfx::Panel_ILI9488();
LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__);
break;
}
case 0x7789: {
panel = new lgfx::Panel_ST7789();
LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__);
break;
}
case 0x7796: {
auto panel = new lgfx::Panel_ST7796();
panel->setBus(bus);
init_panel(panel, &preferences);
tft.setPanel(panel);
panel = new lgfx::Panel_ST7796();
LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__);
break;
}
case 0x8357D: {
auto panel = new lgfx::Panel_HX8357D();
panel->setBus(bus);
init_panel(panel, &preferences);
tft.setPanel(panel);
panel = new lgfx::Panel_HX8357D();
LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__);
break;
}
@ -306,6 +293,26 @@ void LovyanGfx::init(int w, int h)
LOG_FATAL(TAG_TFT, F(D_SERVICE_START_FAILED ": %s line %d"), __FILE__, __LINE__);
}
}
return panel;
}
void LovyanGfx::init(int w, int h)
{
LOG_TRACE(TAG_TFT, F(D_SERVICE_STARTING));
Preferences preferences;
preferences.begin("tft", false);
lgfx::IBus* bus = _init_bus(&preferences);
this->tft_driver = preferences.getUInt("DRIVER", get_tft_driver());
lgfx::Panel_Device* panel = _init_panel(bus);
if(panel != nullptr) {
panel->setBus(bus);
configure_panel(panel, &preferences);
}
tft.setPanel(panel);
LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__);
/* TFT init */
@ -589,10 +596,10 @@ uint32_t LovyanGfx::get_tft_driver()
return 0xED;
#elif defined(ST7789_DRIVER)
return 0x7789;
#elif defined(R61581_DRIVER)
return 0x61581;
#elif defined(ST7789_2_DRIVER)
return 0x77892;
#elif defined(R61581_DRIVER)
return 0x61581;
#elif defined(RM68140_DRIVER)
return 0x68140;
#else

View File

@ -137,9 +137,13 @@ class LovyanGfx : BaseTft {
}
private:
uint32_t tft_driver;
uint32_t get_tft_driver();
uint32_t get_touch_driver();
lgfx::Panel_Device* _init_panel(lgfx::IBus* bus);
void tftOffsetInfo(uint8_t pin, uint8_t x_offset, uint8_t y_offset)
{
if(x_offset != 0) {

View File

@ -16,8 +16,21 @@ build_flags =
-D HASP_MODEL="Lanbon L8"
;region -- TFT_eSPI build options ------------------------
${lcd.st7789v}
-D LANBONL8
; -D USER_SETUP_LOADED=1
-D LGFX_USE_V1=1
-D ST7789_DRIVER=1
;-D CGRAM_OFFSET=1 ; Library will add offsets required
-D TFT_SDA_READ ; Read from display, it only provides an SDA pin
-D TFT_WIDTH=240
-D TFT_HEIGHT=320
-D TFT_ROTATION=2 ; see TFT_ROTATION values
; -D TFT_INVERSION_OFF ; for normal colors
; -D TFT_RGB_ORDER=1 ; Colour order Red-Green-Blue
-D TFT_RGB_ORDER=0 ; Colour order Blue-Green-Red
-D SPI_FREQUENCY=60000000
-D SPI_READ_FREQUENCY=6000000
-D SUPPORT_TRANSACTIONS
-D TFT_RST=18 ; FCP pin2 RESET
-D TFT_SCLK=19 ; FCP pin3 SCL
-D TFT_DC=21 ; FCP pin4 D/C
@ -44,7 +57,8 @@ build_flags =
lib_deps =
${env.lib_deps}
${esp32.lib_deps}
${tft_espi.lib_deps}
${lovyangfx.lib_deps}
;${tft_espi.lib_deps}
; FT6336U is 6x faster then FocalTech Library
;git+https://github.com/lewisxhe/FocalTech_Library.git
${ft6336.lib_deps}