Adding support for larger fonts has been a popular feature request for years, and I never took on the project as I thought it might be a difficult project. Turns out I was right, but now at least most of the work is done, and you can now run sketches like this using the “teensy4” branch, and this will be coming in the upcoming SmartMatrix Library 4.0 release.
There is now a new SMLayerBackgroundGFX
layer (equivalent to SMLayerBackground) and new SMLayerGFXMono
layer (equivalent to SMLayerIndexed and SMLayerScrolling combined). Both layers inherit from Adafruit_GFX, so you can use any of the Adafruit_GFX library functions with the new layers. I made both layers backward compatible with the SmartMatrix Library main layer functions, so you should be able to use existing sketches and the new layers with little or no changes. Adafruit_GFX uses uint16_t
(equivalent to rgb16 or rgb565) to store colors, which is a downgrade if you’re using rgb24
or rgb48
in SmartMatrix Library to store your colors, so there are wrapper functions in the layers that take the rgb24/48 color, store it while Adafruit_GFX is doing the drawing, and pass it through to the actual drawPixel(rgb24)
/drawPixel(rgb48)
functions. The layers themselves are overhauled especially the SMLayerGFXMono
layer which was rewritten to be much more efficient during refresh.
The examples were updated to show how to use the new layers:
- Updated example
MultipleTextLayers
: optionally use Adafruit_GFX layers, improving refresh rate - Updated
FeatureDemo
: add “GFX” layer support option - Updated
FastLED_Functions
: add explicit cast from CRGB to rgb24. With new uint16_t conversions for Adafruit_GFX, the compiler gets confused as to which type we want, even though this sketch doesn’t use the new layers - New example
Adafruit_GFX
: shows how to use Adafruit_GFX functions with the new layers - New example
MultipleTextLayersGFX
: Improved version ofMultipleTextLayers
, includes Adafruit_GFX fonts (featured in video above)
Backwards Compatibility:
The only change that needs to be made (as of now) is adding explicit casts between FastLED’s CRGB
type and rgb24
. I’m not sure why this is needed. I merged in some really helpful code from @mrwastl to convert between different rgb types, and this was a side effect. It’s beyond my level of C++ understanding to fix this, but the explicit cast seems to work. See FastLED_Functions
for an example.
Testing:
I tested the new code with the above examples on a Teensy 4. I didn’t test Teensy 3 (which I expect to work no problem), and I didn’t test with ESP32. ESP32 could have issues as it uses malloc instead of static allocation of buffers, and I may have made a mistake in the malloc calls. I’d appreciate if you’re using ESP32 if you’d let me know if your sketches are running fine with the latest from teensy4
, or if you see any errors.
I tested Adafruit_GFX functions that are included in the Adafruit_GFX
sketch (adapted from Adafruit’s own examples), but I don’t think this tests Adafruit_GFX functions 100%. There’s probably some things to fix, please let me know if you run into errors, and include a sample sketch to reproduce it and I’ll try to get a fix done ASAP.