From 5ec8e0204470ec46098df7c2cc58c096ceb619a1 Mon Sep 17 00:00:00 2001 From: mverch67 Date: Wed, 1 May 2024 22:13:19 +0200 Subject: [PATCH] add spi_host + missing rotation --- src/graphics/TFTDisplay.cpp | 27 +++++++++++++++++++-------- src/main.cpp | 7 ++----- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index 725041bb2..fac38bf9f 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -338,7 +338,7 @@ static TFT_eSPI *tft = nullptr; // Invoke library, pins defined in User_Setup.h class LGFX : public lgfx::LGFX_Device { - lgfx::Panel_LCD *_panel_instance; + lgfx::Panel_Device *_panel_instance; lgfx::Bus_SPI _bus_instance; lgfx::ITouch *_touch_instance; @@ -352,8 +352,19 @@ class LGFX : public lgfx::LGFX_Device _panel_instance = new lgfx::Panel_ST7735; else if (settingsMap[displayPanel] == st7735s) _panel_instance = new lgfx::Panel_ST7735S; + else if (settingsMap[displayPanel] == st7796) + _panel_instance = new lgfx::Panel_ST7796; else if (settingsMap[displayPanel] == ili9341) _panel_instance = new lgfx::Panel_ILI9341; + else if (settingsMap[displayPanel] == ili9488) + _panel_instance = new lgfx::Panel_ILI9488; + else if (settingsMap[displayPanel] == hx8357d) + _panel_instance = new lgfx::Panel_HX8357D; + else { + _panel_instance = new lgfx::Panel_NULL; + LOG_ERROR("Unknown display panel configured!\n"); + } + auto buscfg = _bus_instance.config(); buscfg.spi_mode = 0; buscfg.spi_host = settingsMap[displayspidev]; @@ -367,12 +378,12 @@ class LGFX : public lgfx::LGFX_Device LOG_DEBUG("Height: %d, Width: %d \n", settingsMap[displayHeight], settingsMap[displayWidth]); cfg.pin_cs = settingsMap[displayCS]; // Pin number where CS is connected (-1 = disable) cfg.pin_rst = settingsMap[displayReset]; - cfg.panel_width = settingsMap[displayWidth]; // actual displayable width - cfg.panel_height = settingsMap[displayHeight]; // actual displayable height - cfg.offset_x = settingsMap[displayOffsetX]; // Panel offset amount in X direction - cfg.offset_y = settingsMap[displayOffsetY]; // Panel offset amount in Y direction - cfg.offset_rotation = 0; // Rotation direction value offset 0~7 (4~7 is mirrored) - cfg.invert = settingsMap[displayInvert]; // Set to true if the light/darkness of the panel is reversed + cfg.panel_width = settingsMap[displayWidth]; // actual displayable width + cfg.panel_height = settingsMap[displayHeight]; // actual displayable height + cfg.offset_x = settingsMap[displayOffsetX]; // Panel offset amount in X direction + cfg.offset_y = settingsMap[displayOffsetY]; // Panel offset amount in Y direction + cfg.offset_rotation = settingsMap[displayOffsetRotate]; // Rotation direction value offset 0~7 (4~7 is mirrored) + cfg.invert = settingsMap[displayInvert]; // Set to true if the light/darkness of the panel is reversed _panel_instance->config(cfg); @@ -394,7 +405,7 @@ class LGFX : public lgfx::LGFX_Device touch_cfg.y_max = settingsMap[displayWidth] - 1; touch_cfg.pin_int = settingsMap[touchscreenIRQ]; touch_cfg.bus_shared = true; - touch_cfg.offset_rotation = 1; + touch_cfg.offset_rotation = settingsMap[touchscreenRotate]; if (settingsMap[touchscreenI2CAddr] != -1) { touch_cfg.i2c_addr = settingsMap[touchscreenI2CAddr]; } else { diff --git a/src/main.cpp b/src/main.cpp index 35899e328..b93bf365d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -679,9 +679,6 @@ void setup() } else #endif { - auto spiHost = [](const std::string &spidev) { - return spidev.empty() ? 0 : (spidev[11] - '0') | (spidev[13] - '0') << 4; - }; displayConfig.device(DisplayDriverConfig::device_t::CUSTOM_TFT) .panel(DisplayDriverConfig::panel_config_t{.type = panels[settingsMap[displayPanel]], .panel_width = (uint16_t)settingsMap[displayWidth], @@ -698,13 +695,13 @@ void setup() .freq_read = 16000000, .spi{.pin_dc = (int8_t)settingsMap[displayDC], .use_lock = true, - .spi_host = (uint16_t)spiHost(settingsStrings[displayspidev])}}) + .spi_host = (uint16_t)settingsMap[displayspidev]}}) .touch(DisplayDriverConfig::touch_config_t{.type = touch[settingsMap[touchscreenModule]], .freq = (uint32_t)settingsMap[touchscreenBusFrequency], .pin_int = (int16_t)settingsMap[touchscreenIRQ], .offset_rotation = (uint8_t)settingsMap[touchscreenRotate], .spi{ - .spi_host = (int8_t)spiHost(settingsStrings[touchscreenspidev]), + .spi_host = (int8_t)settingsMap[touchscreenspidev], }, .pin_cs = (int16_t)settingsMap[touchscreenCS]}) .light(DisplayDriverConfig::light_config_t{.pin_bl = (int16_t)settingsMap[displayBacklight],