The SmartMatrix Library ESP32 port at a low level is based on Sprite_TM's ESP32 I2S Parallel example. The ESP32 can continuously shift data from RAM through the I2S peripheral in parallel to GPIO pins, without using up CPU cycles. It was a challenge to move from the example with 21-bit color refresh to approaching the SmartMatrix Library's performance on the Teensy with up to 48-bit color and high refresh rates. The example code didn't scale well in RAM usage or refresh rate when increasing color depth. The architecture of the ESP32 and the Freescale processors used in the Teensy 3 family are so different a lot of the tricks I used on the Teensy 3 wouldn't port over. There are some significant changes from the Teensy Platform, but in general, sketches that used the Teensy SmartMatrix Library should work with the ESP32 SmartMatrix Library.
Big progress today in reducing the amount of DMA RAM used by the SmartMatrix Library: the RAM required for holding the I2S data is cut in half by changing I2S to 8-bit mode and storing each clock's data in 8 bits instead of 16. For a 64x64 32-bit panel, the refresh buffer used to take 99kB of RAM, and now takes 49.5kB. This only works with the SmartMatrix Shield (circuit) as there's an external latch used to reduce the number of GPIO needed for the I2S data down to 8.
This DMA RAM savings should hopefully allow for more applications that use WiFi and other peripherals to work with the SmartMatrix Library. I have a sketch that uses WiFi to get the time and the SD library to play Animated GIFs, and it was too much RAM to drive a 64x64 panel even with only 24-bit color before. Now it works with 64x64 and 36-bit color.
I was trying to track down some memory issues, that turned out to be cache access errors from the ISR accessing memory it's not supposed to. After dramatically simplifying the ISR and creating a new task to handle calculating the data sent to the panel, that error - which was seen when trying to work with more Arduino libraries - is gone and I was able to put together a quick demo of SmartMatrix Library working with WiFi.
I took Jason Coon's awesome ESP32 FastLED Web Server sketch, stripped out the FastLED driver code (as it uses WS2812 LEDs) and merged in the FastLED_Functions sketch from the SmartMatrix Library examples. Even after initializing SmartMatrix at the end of the sketch, it requires ~30kB memory free for mallocs used by the WiFi and web server portions of the code.
The sketch is here. If you want to try this, make sure you have the latest code downloaded from the SmartMatrix Library github (TeensyLC branch), and follow the instructions in Jason's README:
I pushed some ESP32 updates over the last few days:
Added code to automatically lower Frame Rate (the number of times per second the refresh buffer is loaded with a new frame) to leave CPU left for the Sketch to use. Refresh Rate can stay the same. No more blank screen when trying to drive too large of a panel with too high refresh rate or too high color depth.
Accurate Frame rate is now shared with layers (so scrolling text should scroll the intended speed regardless of frame rate), and is returned from matrix.getFrameRate()
Added argument to matrix.begin() to leave DMA-capable RAM free for other libraries to use
AnimatedGIFs improvements
now can call matrix.begin(28000) before SD.begin(), leaving 28000 bytes of DMA-capable RAM free for the SD library to use.
Added notes on how to use with ESP32 and how to improve performance with large panels on ESP32
There's still some things being worked out, see the ESP32 section at the top of the README on GitHub. Biggest issue is probably dealing with memory management on the ESP32. When adding other libraries to the project, e.g. SD or WiFi, memory issues can lead to the other libraries not working, or getting into a rolling reboot situation. Moving matrix.begin() later in the sketch, so the SmartMatrix mallocs are the last things called is a decent workaround for now.