Add ESP32 SD support for smooth font plus performance updates

Added SD card storage for smooth fonts with ESP32
ESP32 will use PSRAM (if available and enabled) to hold smooth font
metrics
Improve performance of ESP32 Sprite shared functions
Add basic ST7789 driver option
Latent bug fixes for pin mask
This commit is contained in:
Bodmer
2019-04-15 12:23:16 +01:00
parent 652383b694
commit 9f17920115
20 changed files with 600 additions and 72 deletions
+55 -16
View File
@@ -8,9 +8,18 @@
/***************************************************************************************
** Function name: loadFont
** Description: loads parameters from a new font vlw file stored in SPIFFS
** Description: loads parameters from a new font vlw file
*************************************************************************************x*/
void TFT_eSPI::loadFont(String fontName)
void TFT_eSPI::loadFont(String fontName, fs::FS &ffs)
{
fontFS = ffs;
loadFont(fontName, false);
}
/***************************************************************************************
** Function name: loadFont
** Description: loads parameters from a new font vlw file
*************************************************************************************x*/
void TFT_eSPI::loadFont(String fontName, bool flash)
{
/*
The vlw font format does not appear to be documented anywhere, so some reverse
@@ -74,15 +83,19 @@ void TFT_eSPI::loadFont(String fontName)
*/
unloadFont();
spiffs = flash;
if(spiffs) fontFS = SPIFFS;
unloadFont();
// Avoid a crash on the ESP32 if the file does not exist
if (SPIFFS.exists("/" + fontName + ".vlw") == false) {
if (fontFS.exists("/" + fontName + ".vlw") == false) {
Serial.println("Font file " + fontName + " not found!");
return;
}
fontFile = SPIFFS.open( "/" + fontName + ".vlw", "r");
fontFile = fontFS.open( "/" + fontName + ".vlw", "r");
if(!fontFile) return;
@@ -120,13 +133,28 @@ void TFT_eSPI::loadMetrics(uint16_t gCount)
uint32_t headerPtr = 24;
uint32_t bitmapPtr = 24 + gCount * 28;
gUnicode = (uint16_t*)malloc( gCount * 2); // Unicode 16 bit Basic Multilingual Plane (0-FFFF)
gHeight = (uint8_t*)malloc( gCount ); // Height of glyph
gWidth = (uint8_t*)malloc( gCount ); // Width of glyph
gxAdvance = (uint8_t*)malloc( gCount ); // xAdvance - to move x cursor
gdY = (int16_t*)malloc( gCount * 2); // offset from bitmap top edge from lowest point in any character
gdX = (int8_t*)malloc( gCount ); // offset for bitmap left edge relative to cursor X
gBitmap = (uint32_t*)malloc( gCount * 4); // seek pointer to glyph bitmap in SPIFFS file
#if defined (ESP32) && defined (CONFIG_SPIRAM_SUPPORT)
if ( psramFound() )
{
gUnicode = (uint16_t*)ps_malloc( gCount * 2); // Unicode 16 bit Basic Multilingual Plane (0-FFFF)
gHeight = (uint8_t*)ps_malloc( gCount ); // Height of glyph
gWidth = (uint8_t*)ps_malloc( gCount ); // Width of glyph
gxAdvance = (uint8_t*)ps_malloc( gCount ); // xAdvance - to move x cursor
gdY = (int16_t*)ps_malloc( gCount * 2); // offset from bitmap top edge from lowest point in any character
gdX = (int8_t*)ps_malloc( gCount ); // offset for bitmap left edge relative to cursor X
gBitmap = (uint32_t*)ps_malloc( gCount * 4); // seek pointer to glyph bitmap in the file
}
else
#endif
{
gUnicode = (uint16_t*)malloc( gCount * 2); // Unicode 16 bit Basic Multilingual Plane (0-FFFF)
gHeight = (uint8_t*)malloc( gCount ); // Height of glyph
gWidth = (uint8_t*)malloc( gCount ); // Width of glyph
gxAdvance = (uint8_t*)malloc( gCount ); // xAdvance - to move x cursor
gdY = (int16_t*)malloc( gCount * 2); // offset from bitmap top edge from lowest point in any character
gdX = (int8_t*)malloc( gCount ); // offset for bitmap left edge relative to cursor X
gBitmap = (uint32_t*)malloc( gCount * 4); // seek pointer to glyph bitmap in the file
}
#ifdef SHOW_ASCENT_DESCENT
Serial.print("ascent = "); Serial.println(gFont.ascent);
@@ -456,7 +484,19 @@ void TFT_eSPI::drawGlyph(uint16_t code)
for (int y = 0; y < gHeight[gNum]; y++)
{
fontFile.read(pbuffer, gWidth[gNum]); //<//
if (spiffs)
{
fontFile.read(pbuffer, gWidth[gNum]);
//Serial.println("SPIFFS");
}
else
{
endWrite(); // Release SPI for SD card transaction
fontFile.read(pbuffer, gWidth[gNum]);
startWrite(); // Re-start SPI for TFT transaction
//Serial.println("Not SPIFFS");
}
for (int x = 0; x < gWidth[gNum]; x++)
{
uint8_t pixel = pbuffer[x]; //<//
@@ -486,6 +526,7 @@ void TFT_eSPI::drawGlyph(uint16_t code)
}
cursor_x += gxAdvance[gNum];
endWrite();
}
else
{
@@ -493,8 +534,6 @@ void TFT_eSPI::drawGlyph(uint16_t code)
drawRect(cursor_x, cursor_y + gFont.maxAscent - gFont.ascent, gFont.spaceWidth, gFont.ascent, fg);
cursor_x += gFont.spaceWidth + 1;
}
endWrite();
}
/***************************************************************************************