Framebuffer::GFX
After writing my 3rd backend glue driver (SSD1331 SPI TFTs) that supports Adafruit::GFX, FastLED CRGB's primitives (nblend, dim, etc...) and matrix mapping via XY() function, and LEDMatrix which is another GFX like API on top of FastLED, I realized that I had to factor that out into a new base class I called Framebuffer::GFX:https://github.com/marcmerlin/Framebuffer_GFX That new base class takes all the GFX glue and color support I mixed (GFX RGB565, FastLED CRGB structs (RGB888 24bit), and uint32_t backed 24bit RGB888 colors, and creates a virtual framebuffer compatible with FastLED and SmartMatrix (which thankfully can use the same 3 byte per pixel array type).
Framebuffer::GFX in itself is only a framebuffer storage and method holder, but it contains so much common code that my 3 drivers that use it are only a few dozen lines of code after inheriting from it. Here is the list of drivers I've written against Framebuffer::GFX:
FastLED_SPITFT::GFX
SSD1331
FastLED_SPITFT_GFX, the last driver I wrote, takes any Adafruit SPI TFT object (like SSD1331 and ILI9341), and a FastLED CRGB array. You then tell it the size of each (it's up to you not to make mistakes or you can create buffer overruns), and the overloaded show() method will send the framebuffer to the TFT (it is done line by line with an SPI copy method):
rotating 3D cube with temporal fade
ST7735 or ILI9341
Thankfully Adafruit wrote other TFT drivers like ST7735 and ILI9341 against the same Adafruit_SPITFT object from Adafruit-GFX, so I was able to target that tft object in FastLED_SPITFT::GFX and get the same code to work with other TFTs without any modifications. As a result, all you need to do is to pass the different tft object, display size, and everything else works.Adafruit_ILI9341 *tft = new Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST); or Adafruit_ST7735 *tft = new Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); FastLED_SPITFT_GFX *matrix = new FastLED_SPITFT_GFX(matrixleds, mw, mh, mw, mh, tft, 0);For comparison, SSD1331 vs ST7735 128x128, ST7735 128x160 from 2 different vendors and slightly different chips, and ILI9341 with a full 320x240 which stretches the limit of this library since it requires 225KB for that many pixels and that only fits on a teensy 3.5/3.6:
the SSD1331 screen is off as it's not compatible and requires different code to turn on
ST7735R vs ST7735S chip revisions show a few differences
code for the 128x128 ST7735 doesn't mis-display the same on the two 128x160 displays
ILI9341 is slightly compatible with the ST7735 screens, shown for scale here
ESP32 Pro with PSRAM needed to store the ILI9341 framebuffer. Display not too compatible with ST7735