diff --git a/lib/Adafruit_ILI9341/Adafruit_ILI9341.cpp b/lib/Adafruit_ILI9341/Adafruit_ILI9341.cpp index 88c0e2ae5..ce52a44d5 100644 --- a/lib/Adafruit_ILI9341/Adafruit_ILI9341.cpp +++ b/lib/Adafruit_ILI9341/Adafruit_ILI9341.cpp @@ -111,6 +111,9 @@ @param cs Chip select pin # (OK to pass -1 if CS tied to GND). @param dc Data/Command pin # (required). @param rst Reset pin # (optional, pass -1 if unused). + @param model The display model to initiailize. + @param w Widht of the display in pixels. + @param h Height of the display in pixels. */ /**************************************************************************/ @@ -133,14 +136,20 @@ Adafruit_ILI9341::Adafruit_ILI9341(int8_t cs, int8_t dc, int8_t rst, uint8_t mod @param cs Chip select pin # (optional, pass -1 if unused and CS is tied to GND). @param rst Reset pin # (optional, pass -1 if unused). + @param model The display model to initiailize. + @param w Widht of the display in pixels. + @param h Height of the display in pixels. */ /**************************************************************************/ -// Adafruit_ILI9341::Adafruit_ILI9341(SPIClass *spiClass, int8_t dc, int8_t cs, -// int8_t rst) -// : Adafruit_SPITFT(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT, spiClass, cs, dc, -// rst) {} +Adafruit_ILI9341::Adafruit_ILI9341(SPIClass *spiClass, int8_t dc, int8_t cs, + int8_t rst, uint8_t model, uint16_t w, uint16_t h) + : Adafruit_SPITFT(w, h, spiClass, cs, dc, rst) { + _model = model; + _w = w; + _h = h; +} #endif // end !ESP8266 /**************************************************************************/ diff --git a/lib/Adafruit_ILI9341/Adafruit_ILI9341.h b/lib/Adafruit_ILI9341/Adafruit_ILI9341.h index 349323700..68735d225 100644 --- a/lib/Adafruit_ILI9341/Adafruit_ILI9341.h +++ b/lib/Adafruit_ILI9341/Adafruit_ILI9341.h @@ -163,8 +163,8 @@ public: #if !defined(ESP8266) - // Adafruit_ILI9341(SPIClass *spiClass, int8_t dc, int8_t cs = -1, - // int8_t rst = -1); + Adafruit_ILI9341(SPIClass *spiClass, int8_t dc, int8_t cs = -1, + int8_t rst = -1, uint8_t model = 0, uint16_t w = 0, uint16_t h = 0); #endif // end !ESP8266 // Adafruit_ILI9341(tftBusWidth busWidth, int8_t d0, int8_t wr, int8_t dc, // int8_t cs = -1, int8_t rst = -1, int8_t rd = -1); diff --git a/src/_P095_ILI9341.ino b/src/_P095_ILI9341.ino index 9f7ae8a03..4e01d2018 100644 --- a/src/_P095_ILI9341.ino +++ b/src/_P095_ILI9341.ino @@ -15,6 +15,7 @@ /** * Changelog: + * 2025-08-12 tonhuisman: Enable use of secondary SPI bus * 2024-07-07 tonhuisman: Remove explicit support for ILI9486 as all ILI9486 displays tested so far work with the ILI9488 driver, * sometimes with Invert display setting enabled (or they are actually ILI9488 displays...) * 2024-06-23 tonhuisman: Add support for ILI9488 displays by implementing an adapted library (jaretburkett/ILI9488) @@ -153,6 +154,7 @@ boolean Plugin_095(uint8_t function, struct EventStruct *event, String& string) dev.ValueCount = 2; dev.TimerOption = true; dev.TimerOptional = true; + dev.SpiBusSelect = true; break; } @@ -451,6 +453,8 @@ boolean Plugin_095(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_INIT: { + const uint8_t spi_bus = Settings.getSPIBusForTask(event->TaskIndex); + if (Settings.InitSPI != 0) { # if P095_ENABLE_ILI948X @@ -470,7 +474,8 @@ boolean Plugin_095(uint8_t function, struct EventStruct *event, String& string) P095_CONFIG_FLAG_GET_CMD_TRIGGER)), P095_CONFIG_GET_COLOR_FOREGROUND, P095_CONFIG_GET_COLOR_BACKGROUND, - bitRead(P095_CONFIG_FLAGS, P095_CONFIG_FLAG_BACK_FILL) == 0 + bitRead(P095_CONFIG_FLAGS, P095_CONFIG_FLAG_BACK_FILL) == 0, + spi_bus # if ADAGFX_FONTS_INCLUDED , P095_CONFIG_DEFAULT_FONT diff --git a/src/src/PluginStructs/P095_data_struct.cpp b/src/src/PluginStructs/P095_data_struct.cpp index 927b4e36c..954387be5 100644 --- a/src/src/PluginStructs/P095_data_struct.cpp +++ b/src/src/PluginStructs/P095_data_struct.cpp @@ -99,7 +99,8 @@ P095_data_struct::P095_data_struct(ILI9xxx_type_e displayType, String commandTrigger, uint16_t fgcolor, uint16_t bgcolor, - bool textBackFill + bool textBackFill, + uint8_t spi_bus # if ADAGFX_FONTS_INCLUDED , const uint8_t defaultFontId @@ -108,7 +109,7 @@ P095_data_struct::P095_data_struct(ILI9xxx_type_e displayType, : _displayType(displayType), _rotation(rotation), _fontscaling(fontscaling), _textmode(textmode), _backlightPin(backlightPin), _backlightPercentage(backlightPercentage), _displayTimer(displayTimer), _displayTimeout(displayTimer), _commandTrigger(commandTrigger), _fgcolor(fgcolor), _bgcolor(bgcolor), - _textBackFill(textBackFill) + _textBackFill(textBackFill), _spi_bus(spi_bus) # if ADAGFX_FONTS_INCLUDED , _defaultFontId(defaultFontId) # endif // if ADAGFX_FONTS_INCLUDED @@ -165,7 +166,18 @@ bool P095_data_struct::plugin_init(struct EventStruct *event) { } else # endif // if P095_ENABLE_ILI948X { + # ifdef ESP32 // PIN(0) and PIN(1) swapped! + tft = new (std::nothrow) Adafruit_ILI9341(0 == _spi_bus ? &SPI : &SPI1, + PIN(1), + PIN(0), + PIN(2), + static_cast(_displayType), + _xpix, + _ypix); + # endif // ifdef ESP32 + # ifdef ESP8266 tft = new (std::nothrow) Adafruit_ILI9341(PIN(0), PIN(1), PIN(2), static_cast(_displayType), _xpix, _ypix); + # endif // ifdef ESP8266 if (nullptr != tft) { tft->begin(); diff --git a/src/src/PluginStructs/P095_data_struct.h b/src/src/PluginStructs/P095_data_struct.h index dec258d0e..04930d989 100644 --- a/src/src/PluginStructs/P095_data_struct.h +++ b/src/src/PluginStructs/P095_data_struct.h @@ -4,8 +4,10 @@ #include "../../_Plugin_Helper.h" #ifdef USES_P095 -# include // include Adafruit graphics library -# include // include Adafruit ILI9341 TFT library +# include // include Adafruit graphics library +# include // include Adafruit ILI9341 TFT library + +# include "../Globals/SPI1.h" # include "../Helpers/AdafruitGFX_helper.h" // Use Adafruit graphics helper object # include "../CustomBuild/StorageLayout.h" @@ -137,10 +139,11 @@ public: String commandTrigger, uint16_t fgcolor = ADAGFX_WHITE, uint16_t bgcolor = ADAGFX_BLACK, - bool textBackFill = true + bool textBackFill = true, + uint8_t spi_bus = 0 # if ADAGFX_FONTS_INCLUDED , - const uint8_t defaultFontId = 0 + const uint8_t defaultFontId = 0 # endif // if ADAGFX_FONTS_INCLUDED ); P095_data_struct() = delete; @@ -208,6 +211,7 @@ private: uint16_t _fgcolor = ADAGFX_WHITE; uint16_t _bgcolor = ADAGFX_BLACK; bool _textBackFill = false; + uint8_t _spi_bus; # if ADAGFX_FONTS_INCLUDED uint8_t _defaultFontId; # endif // if ADAGFX_FONTS_INCLUDED