[P095] Enable support for configurable SPI bus

This commit is contained in:
Ton Huisman
2025-08-12 22:20:26 +02:00
parent cac4500f6a
commit 0c2f09df87
5 changed files with 43 additions and 13 deletions
+13 -4
View File
@@ -111,6 +111,9 @@
@param cs Chip select pin # (OK to pass -1 if CS tied to GND). @param cs Chip select pin # (OK to pass -1 if CS tied to GND).
@param dc Data/Command pin # (required). @param dc Data/Command pin # (required).
@param rst Reset pin # (optional, pass -1 if unused). @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 @param cs Chip select pin # (optional, pass -1 if unused and
CS is tied to GND). CS is tied to GND).
@param rst Reset pin # (optional, pass -1 if unused). @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, Adafruit_ILI9341::Adafruit_ILI9341(SPIClass *spiClass, int8_t dc, int8_t cs,
// int8_t rst) int8_t rst, uint8_t model, uint16_t w, uint16_t h)
// : Adafruit_SPITFT(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT, spiClass, cs, dc, : Adafruit_SPITFT(w, h, spiClass, cs, dc, rst) {
// rst) {} _model = model;
_w = w;
_h = h;
}
#endif // end !ESP8266 #endif // end !ESP8266
/**************************************************************************/ /**************************************************************************/
+2 -2
View File
@@ -163,8 +163,8 @@ public:
#if !defined(ESP8266) #if !defined(ESP8266)
// Adafruit_ILI9341(SPIClass *spiClass, int8_t dc, int8_t cs = -1, Adafruit_ILI9341(SPIClass *spiClass, int8_t dc, int8_t cs = -1,
// int8_t rst = -1); int8_t rst = -1, uint8_t model = 0, uint16_t w = 0, uint16_t h = 0);
#endif // end !ESP8266 #endif // end !ESP8266
// Adafruit_ILI9341(tftBusWidth busWidth, int8_t d0, int8_t wr, int8_t dc, // 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); // int8_t cs = -1, int8_t rst = -1, int8_t rd = -1);
+6 -1
View File
@@ -15,6 +15,7 @@
/** /**
* Changelog: * 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, * 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...) * 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) * 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.ValueCount = 2;
dev.TimerOption = true; dev.TimerOption = true;
dev.TimerOptional = true; dev.TimerOptional = true;
dev.SpiBusSelect = true;
break; break;
} }
@@ -451,6 +453,8 @@ boolean Plugin_095(uint8_t function, struct EventStruct *event, String& string)
case PLUGIN_INIT: case PLUGIN_INIT:
{ {
const uint8_t spi_bus = Settings.getSPIBusForTask(event->TaskIndex);
if (Settings.InitSPI != 0) { if (Settings.InitSPI != 0) {
# if P095_ENABLE_ILI948X # 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_FLAG_GET_CMD_TRIGGER)),
P095_CONFIG_GET_COLOR_FOREGROUND, P095_CONFIG_GET_COLOR_FOREGROUND,
P095_CONFIG_GET_COLOR_BACKGROUND, 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 # if ADAGFX_FONTS_INCLUDED
, ,
P095_CONFIG_DEFAULT_FONT P095_CONFIG_DEFAULT_FONT
+14 -2
View File
@@ -99,7 +99,8 @@ P095_data_struct::P095_data_struct(ILI9xxx_type_e displayType,
String commandTrigger, String commandTrigger,
uint16_t fgcolor, uint16_t fgcolor,
uint16_t bgcolor, uint16_t bgcolor,
bool textBackFill bool textBackFill,
uint8_t spi_bus
# if ADAGFX_FONTS_INCLUDED # if ADAGFX_FONTS_INCLUDED
, ,
const uint8_t defaultFontId 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), : _displayType(displayType), _rotation(rotation), _fontscaling(fontscaling), _textmode(textmode),
_backlightPin(backlightPin), _backlightPercentage(backlightPercentage), _displayTimer(displayTimer), _backlightPin(backlightPin), _backlightPercentage(backlightPercentage), _displayTimer(displayTimer),
_displayTimeout(displayTimer), _commandTrigger(commandTrigger), _fgcolor(fgcolor), _bgcolor(bgcolor), _displayTimeout(displayTimer), _commandTrigger(commandTrigger), _fgcolor(fgcolor), _bgcolor(bgcolor),
_textBackFill(textBackFill) _textBackFill(textBackFill), _spi_bus(spi_bus)
# if ADAGFX_FONTS_INCLUDED # if ADAGFX_FONTS_INCLUDED
, _defaultFontId(defaultFontId) , _defaultFontId(defaultFontId)
# endif // if ADAGFX_FONTS_INCLUDED # endif // if ADAGFX_FONTS_INCLUDED
@@ -165,7 +166,18 @@ bool P095_data_struct::plugin_init(struct EventStruct *event) {
} else } else
# endif // if P095_ENABLE_ILI948X # 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<uint8_t>(_displayType),
_xpix,
_ypix);
# endif // ifdef ESP32
# ifdef ESP8266
tft = new (std::nothrow) Adafruit_ILI9341(PIN(0), PIN(1), PIN(2), static_cast<uint8_t>(_displayType), _xpix, _ypix); tft = new (std::nothrow) Adafruit_ILI9341(PIN(0), PIN(1), PIN(2), static_cast<uint8_t>(_displayType), _xpix, _ypix);
# endif // ifdef ESP8266
if (nullptr != tft) { if (nullptr != tft) {
tft->begin(); tft->begin();
+8 -4
View File
@@ -4,8 +4,10 @@
#include "../../_Plugin_Helper.h" #include "../../_Plugin_Helper.h"
#ifdef USES_P095 #ifdef USES_P095
# include <Adafruit_GFX.h> // include Adafruit graphics library # include <Adafruit_GFX.h> // include Adafruit graphics library
# include <Adafruit_ILI9341.h> // include Adafruit ILI9341 TFT library # include <Adafruit_ILI9341.h> // include Adafruit ILI9341 TFT library
# include "../Globals/SPI1.h"
# include "../Helpers/AdafruitGFX_helper.h" // Use Adafruit graphics helper object # include "../Helpers/AdafruitGFX_helper.h" // Use Adafruit graphics helper object
# include "../CustomBuild/StorageLayout.h" # include "../CustomBuild/StorageLayout.h"
@@ -137,10 +139,11 @@ public:
String commandTrigger, String commandTrigger,
uint16_t fgcolor = ADAGFX_WHITE, uint16_t fgcolor = ADAGFX_WHITE,
uint16_t bgcolor = ADAGFX_BLACK, uint16_t bgcolor = ADAGFX_BLACK,
bool textBackFill = true bool textBackFill = true,
uint8_t spi_bus = 0
# if ADAGFX_FONTS_INCLUDED # if ADAGFX_FONTS_INCLUDED
, ,
const uint8_t defaultFontId = 0 const uint8_t defaultFontId = 0
# endif // if ADAGFX_FONTS_INCLUDED # endif // if ADAGFX_FONTS_INCLUDED
); );
P095_data_struct() = delete; P095_data_struct() = delete;
@@ -208,6 +211,7 @@ private:
uint16_t _fgcolor = ADAGFX_WHITE; uint16_t _fgcolor = ADAGFX_WHITE;
uint16_t _bgcolor = ADAGFX_BLACK; uint16_t _bgcolor = ADAGFX_BLACK;
bool _textBackFill = false; bool _textBackFill = false;
uint8_t _spi_bus;
# if ADAGFX_FONTS_INCLUDED # if ADAGFX_FONTS_INCLUDED
uint8_t _defaultFontId; uint8_t _defaultFontId;
# endif // if ADAGFX_FONTS_INCLUDED # endif // if ADAGFX_FONTS_INCLUDED