A question that often arises is how to ‘save program memory’ when the MD_Parola and MD_MAX72xx libraries are used in an application. In this article we’ll cover how you can do this using the facilities already built into the library code.
Optimize Font Data
Font data is by far the biggest opportunity to save program memory space. Every font table takes up space, so minimizing the amount of font data being compiled in the application is an easy way to free up memory.
If you are never using the standard font supplied with the libraries and are always replacing it with your own, you should consider replacing the standard font in the MD_MAX72xx library with your usual font, and make that the standard. This way there is only one font file needed and you can save many kilobytes of memory.
From MD_MAX72xx version 3, the font data header can also specify that it contains a contiguous subset of the ASCII character set. This allows unused character placeholder data to be removed from the font definition. The header format is defined in the MD_MAX72xx documentation and changing older fonts to be compatible is a simple step that could save quite a few bytes of wasted space.
Eliminate Unnecessary Code
Quite often applications will use only a subset of all the possible text effects. The unused effects can be eliminated by editing the appropriate ENA_* C++ preprocessor values in the MD_Parola.h header file. The capability is disabled by setting the value to 0.
#define ENA_MISC 1 ///< Enable miscellaneous animations #define ENA_WIPE 1 ///< Enable wipe type animations #define ENA_SCAN 1 ///< Enable scanning animations #define ENA_SCR_DIA 1 ///< Enable diagonal scrolling animation #define ENA_OPNCLS 1 ///< Enable open and close scan effects #define ENA_GROW 1 ///< Enable grow effects #define ENA_SPRITE 1 ///< Enable sprite effects
The PRINT, SCROLL_LEFT, SCROLL_RIGHT, SCROLL_UP and SCROLL_DOWN effects cannot be disabled as they are the core functions used by most applications.
If text and graphics won’t be mixed in the displays, then the graphics handling parts of the library can be eliminated by using this setting
#define ENA_GRAPHICS 1 ///< Enable graphics functionality
The MD_MAX72xx library can also remove all support for fonts by editing the MD_MAX72XX.h header file and setting the USE_LOCAL_FONT preprocessor define to 0. This will disable the local font data file and all related methods.
#define USE_LOCAL_FONT 1
Note that this also means that MD_Parola cannot be used over the top of MD_MAX72xx, as it relies on these font support functions.