Remove fonts to conserve memory

What started as a hunt for demo code turned into me working on getting the Aurora patterns to work on a 64x64 matrix. No audio, weather, IR, etc. just gorgeous eye candy. I basically started with the sm3 branch of Aurora and gutted the functionality that wasn’t relevant. Here’s what the file list looks like

Attractor.h
Boid.h
Drawable.h
Effects.h
Geometry.h
Menu.h
MenuItem.h
PatternAnalogClock.h
PatternAttract.h
PatternBounce.h
PatternCube.h
PatternElectricMandala.h
PatternFire.h
PatternFlock.h
PatternFlowField.h
PatternIncrementalDrift.h
PatternIncrementalDrift2.h
PatternInfinity.h
PatternInvaders.h
PatternLife.h
PatternMaze.h
PatternMunch.h
PatternNoiseSmearing.h
PatternPendulumWave.h
PatternPlasma.h
PatternPongClock.h
PatternPulse.h
PatternRadar.h
PatternRainbowSmoke.h
Patterns.h
PatternSimplexNoise.h
PatternSnake.h
PatternSpark.h
PatternSpin.h
PatternSpiral.h
PatternSpiro.h
PatternSwirl.h
PatternWave.h
Playlist.h
Runnable.h
Vector.h

Relevant includes from the main sketch

#include <SmartMatrix3.h>
#include <FastLED.h>

Not too surprisingly, I’m overflowing .bss by 17K (down from about 28K).
Here’s the gcc invocation

C:\Program Files (x86)\Arduino/hardware/tools/arm/bin/arm-none-eabi-gcc -O -Wl,--gc-sections,--relax,--defsym=__rtc_localtime=1443091078 
  -TC:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/mk20dx256.ld -mthumb -mcpu=cortex-m4 -fsingle-precision-constant -o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp/NorthernLights.cpp.elf
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\NorthernLights.cpp.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\SmartMatrix3\Font_apple4x6_256.c.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\SmartMatrix3\Font_apple5x7_256.c.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\SmartMatrix3\Font_apple6x10.c.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\SmartMatrix3\Font_apple8x13.c.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\SmartMatrix3\Font_gohufont6x11.c.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\SmartMatrix3\Font_gohufont6x11b.c.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\SmartMatrix3\Font_tom_thumb.c.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\SmartMatrix3\CircularBuffer.cpp.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\SmartMatrix3\Layer.cpp.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\SmartMatrix3\MatrixFont.cpp.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\SmartMatrix3\SmartMatrix.cpp.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\FastLED\colorpalettes.cpp.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\FastLED\colorutils.cpp.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\FastLED\FastLED.cpp.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\FastLED\hsv2rgb.cpp.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\FastLED\lib8tion.cpp.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\FastLED\noise.cpp.o
 C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\FastLED\power_mgt.cpp.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp\FastLED\wiring.cpp.o
   C:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp/core.a 
   -LC:\Users\rhett\AppData\Local\Temp\build2745775725840725466.tmp -larm_cortexM4l_math -lm  

I’m interested in seeing how much closer I can get if I can cut out all or most of the fonts since I’m not interested in using them. I’m new to this toolchain and it seems my naive attempts at changing the font code to only reference the apple3x5 (or similar) font isn’t doing the trick?

Oh I have also removed the scrolling and indexed layers and poked around at a few of the parameters to the ALLOCATE_XXXX macros.

Would appreciate any guidance you may have on trying to trim the fat.

PS: There are a few object files created that I don’t think I “need” like various USB items, AudioStream, etc.

Update:
I did some digging with avr-nm and I saw the patterns object was huge . I removed all static instances of the patterns and left only spiral. This allowed me to compile and upload the sketch despite complaining about only having 15k for locals.

What’s a good strategy for dynamically instantiating the patterns as needed at run-time? Let me throw out a naive idea to illustrate:
Have a function that is periodically called (I don’t have the playlist working as intended right now) and uses a static int as an index into a case statement that instantiates a pattern and returns it to the caller.

For a little more context, here’s the tail end of my setup, and my loop function in my sketch

     patterns.setPattern("Spiral");
  
}

  
void loop()
{
   effects.PrepareFrame();
   effects.ShowFrame();
   patterns.drawFrame();
}

Edit:
Ohhh ok dynamic allocation is a can of worms

Hi @rhettc, sorry you’re unlikely to get a detailed response for at least a few days. I’m prepping for Maker Faire NYC, and I believe @Jason is out for the weekend.

Just a caution up front: you may find that the patterns don’t play very well at 64x64 because they take a lot more CPU power per frame (probably 4x at a minimum), and there’s less CPU available for the sketch when the SmartMatrix Library is refreshing is refreshing a 64x64 display.

I think @Jason is the only person who can answer your questions about stripping down Aurora to just patterns and scaling up. My suggestion is to try a simple pattern sketch first at 64x64 and see how it performs before trying to convert a bunch more patterns.

e.g. GitHub - jasoncoon/NoiseSmearing: NoiseSmearing, by Stefan Petrick, originally shared at: https://gist.github.com/StefanPetrick/9ee2f677dbff64e3ba7a

Yeah, I have not yet taken the time to investigate dynamically allocating anything in Arduino/C. That was my first impulse, coming from desktop and web development, but then I’m also used to garbage-collected languages/frameworks like C# and Java. :slight_smile:

I have the hardware for a 64x64 matrix now, hope to get it assembled in the next few days and start working on getting Aurora working.

I’m not sure how much RAM/Flash the fonts take, or what it would take to remove them. It’d be nice if they didn’t get included if they’re not used.

Here are more of my standalone patterns that I plan to test and support dynamic display sizes:

I’m pretty sure the fonts for the most part are in flash not RAM. There is an open issue in GitHub for improving the fonts, including compiling in only those fonts that are needed: