I looked at your "Font" and changed some weirdos. e.g.
typedef struct {
char* character_NG20ptLightRed;
// uint16_t charData_NG20ptLightRed; //your inits do not have this field
byte height_NG20ptLightRed;
byte width_NG20ptLightRed;
} charData_NG20ptLightRed;
// you had a multi-dimensional array of structs
const charData_NG20ptLightRed NG20ptLightRed_coords[69] = {
{"+", 19, 17}, {",", 19, 4}, {"-", 19, 7}, {".", 19, 4},
...
And then I amended your sketch to :
#include <TFT_eSPI.h>
#include "NG20ptLightRed.h"
#include "header.h"
#include "frost.h"
#include "car.h"
TFT_eSPI tft = TFT_eSPI();
byte printLetter(char c, byte startX, byte startY)
{
byte idx;
// look up the character. Find index of the bitmap etc.
// most fonts have sequences e.g. ascii ' ' to ascii '}'
// this means you can calculate the index immediately
for (idx = 0; idx < 69; idx++) {
if (NG20ptLightRed_coords[idx].character_NG20ptLightRed[0] == c)
break;
}
byte x_width = NG20ptLightRed_coords[idx].width_NG20ptLightRed;
byte y_height = NG20ptLightRed_coords[idx].height_NG20ptLightRed;
uint16_t *imageData = (uint16_t*)NG20ptLightRed[idx];
tft.setAddrWindow(startX, startY, startX + x_width - 1, startY + y_height - 1);
tft.pushColors(imageData, x_width * y_height);
return x_width;
}
byte printString(char *p, byte x_start, byte y_start)
{
char c;
while (c = *p++) {
x_start += printLetter(c, x_start, y_start);
}
}
#define dimmerPin 33
uint16_t buf[128 * 70]; //so we can build bitmaps in the correct endian
void pushImage(uint32_t x0, uint32_t y0, uint32_t w, uint32_t h, uint16_t *data)
{
for (uint32_t i = 0; i < w * h; i++) {
uint16_t x = data[i];
buf[i] = (x >> 8) | (x << 8);
}
tft.pushRect(x0, y0, w, h, buf);
}
void setup()
{
Serial.begin(115200);
Serial.println("Serial connection OK.");
tft.init();
tft.setRotation(2);
tft.fillScreen(0x20c0);
ledcSetup(0, 5000, 8);
ledcAttachPin(dimmerPin, 0);
ledcWrite(0, 255);
delay(2000);
// your bitmaps are in the wrong endian
tft.pushRect(0, 0, 128, 33, (uint16_t*)header);
// tft.pushRect(0, 34, 128, 24, (uint16_t*)frost);
tft.pushRect(0, 58, 128, 70, (uint16_t*)car);
tft.fillRect(8, 130, 112, 2, 0xfa28);
printString("Frost", 40, 28);
delay(5000);
// call helper function to change endian
pushImage(0, 0, 128, 33, (uint16_t*)header);
pushImage(0, 58, 128, 70, (uint16_t*)car);
}
void loop()
{
}
I know that the ESP32 has got oodles of Flash. But your "Font" is unbelievably inefficient for storage.
Oh, and the text rendering is not that impressive.
Yes, I could tidy up the Font access and make it understand AVR PROGMEM.
David.