Commit 9f179201 authored by Bodmer's avatar Bodmer

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
parent 652383b6
......@@ -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();
}
/***************************************************************************************
......
......@@ -4,7 +4,8 @@
public:
// These are for the new antialiased fonts
void loadFont(String fontName);
void loadFont(String fontName, fs::FS &ffs);
void loadFont(String fontName, bool flash = true);
void unloadFont( void );
bool getUnicodeIndex(uint16_t unicode, uint16_t *index);
......@@ -14,9 +15,7 @@
void showFont(uint32_t td);
fs::File fontFile;
// This is for the whole font
// This is for the whole font
typedef struct
{
uint16_t gCount; // Total number of characters
......@@ -40,8 +39,12 @@ fontMetrics gFont = { 0, 0, 0, 0, 0, 0, 0 };
uint32_t* gBitmap = NULL; //file pointer to greyscale bitmap
bool fontLoaded = false; // Flags when a anti-aliased font is loaded
fs::File fontFile;
private:
private:
void loadMetrics(uint16_t gCount);
uint32_t readInt32(void);
fs::FS &fontFS = SPIFFS;
bool spiffs = true;
\ No newline at end of file
// Change the width and height if required (defined in portrait mode)
// or use the constructor to over-ride defaults
#ifndef TFT_WIDTH
#define TFT_WIDTH 240
#endif
#ifndef TFT_HEIGHT
#define TFT_HEIGHT 320
#endif
#if (TFT_HEIGHT == 240) && (TFT_WIDTH == 240)
#define CGRAM_OFFSET
#endif
// Delay between some initialisation commands
#define TFT_INIT_DELAY 0x80 // Not used unless commandlist invoked
// Generic commands used by TFT_eSPI.cpp
#define TFT_NOP 0x00
#define TFT_SWRST 0x01
#define TFT_SLPIN 0x10
#define TFT_SLPOUT 0x11
#define TFT_NORON 0x13
#define TFT_INVOFF 0x20
#define TFT_INVON 0x21
#define TFT_DISPOFF 0x28
#define TFT_DISPON 0x29
#define TFT_CASET 0x2A
#define TFT_PASET 0x2B
#define TFT_RAMWR 0x2C
#define TFT_RAMRD 0x2E
#define TFT_MADCTL 0x36
#define TFT_COLMOD 0x3A
// Flags for TFT_MADCTL
#define TFT_MAD_MY 0x80
#define TFT_MAD_MX 0x40
#define TFT_MAD_MV 0x20
#define TFT_MAD_ML 0x10
#define TFT_MAD_RGB 0x00
#define TFT_MAD_BGR 0x08
#define TFT_MAD_MH 0x04
#define TFT_MAD_SS 0x02
#define TFT_MAD_GS 0x01
#ifdef TFT_RGB_ORDER
#if (TFT_RGB_ORDER == 1)
#define TFT_MAD_COLOR_ORDER TFT_MAD_RGB
#else
#define TFT_MAD_COLOR_ORDER TFT_MAD_BGR
#endif
#else
#ifdef CGRAM_OFFSET
#define TFT_MAD_COLOR_ORDER TFT_MAD_BGR
#else
#define TFT_MAD_COLOR_ORDER TFT_MAD_RGB
#endif
#endif
#define TFT_IDXRD 0x00 // ILI9341 only, indexed control register read
#define ST_CMD_DELAY 0x80 // special signifier for command lists
#define ST7789_240x240_XSTART 0
#define ST7789_240x240_YSTART 0
// ST7789 specific commands used in init
#define ST7789_NOP 0x00
#define ST7789_SWRESET 0x01
#define ST7789_RDDID 0x04
#define ST7789_RDDST 0x09
#define ST7789_RDDPM 0x0A // Read display power mode
#define ST7789_RDD_MADCTL 0x0B // Read display MADCTL
#define ST7789_RDD_COLMOD 0x0C // Read display pixel format
#define ST7789_RDDIM 0x0D // Read display image mode
#define ST7789_RDDSM 0x0E // Read display signal mode
#define ST7789_RDDSR 0x0F // Read display self-diagnostic result (ST7789V)
#define ST7789_SLPIN 0x10
#define ST7789_SLPOUT 0x11
#define ST7789_PTLON 0x12
#define ST7789_NORON 0x13
#define ST7789_INVOFF 0x20
#define ST7789_INVON 0x21
#define ST7789_GAMSET 0x26 // Gamma set
#define ST7789_DISPOFF 0x28
#define ST7789_DISPON 0x29
#define ST7789_CASET 0x2A
#define ST7789_RASET 0x2B
#define ST7789_RAMWR 0x2C
#define ST7789_RGBSET 0x2D // Color setting for 4096, 64K and 262K colors
#define ST7789_RAMRD 0x2E
#define ST7789_PTLAR 0x30
#define ST7789_VSCRDEF 0x33 // Vertical scrolling definition (ST7789V)
#define ST7789_TEOFF 0x34 // Tearing effect line off
#define ST7789_TEON 0x35 // Tearing effect line on
#define ST7789_MADCTL 0x36 // Memory data access control
#define ST7789_IDMOFF 0x38 // Idle mode off
#define ST7789_IDMON 0x39 // Idle mode on
#define ST7789_RAMWRC 0x3C // Memory write continue (ST7789V)
#define ST7789_RAMRDC 0x3E // Memory read continue (ST7789V)
#define ST7789_COLMOD 0x3A
#define ST7789_RAMCTRL 0xB0 // RAM control
#define ST7789_RGBCTRL 0xB1 // RGB control
#define ST7789_PORCTRL 0xB2 // Porch control
#define ST7789_FRCTRL1 0xB3 // Frame rate control
#define ST7789_PARCTRL 0xB5 // Partial mode control
#define ST7789_GCTRL 0xB7 // Gate control
#define ST7789_GTADJ 0xB8 // Gate on timing adjustment
#define ST7789_DGMEN 0xBA // Digital gamma enable
#define ST7789_VCOMS 0xBB // VCOMS setting
#define ST7789_LCMCTRL 0xC0 // LCM control
#define ST7789_IDSET 0xC1 // ID setting
#define ST7789_VDVVRHEN 0xC2 // VDV and VRH command enable
#define ST7789_VRHS 0xC3 // VRH set
#define ST7789_VDVSET 0xC4 // VDV setting
#define ST7789_VCMOFSET 0xC5 // VCOMS offset set
#define ST7789_FRCTR2 0xC6 // FR Control 2
#define ST7789_CABCCTRL 0xC7 // CABC control
#define ST7789_REGSEL1 0xC8 // Register value section 1
#define ST7789_REGSEL2 0xCA // Register value section 2
#define ST7789_PWMFRSEL 0xCC // PWM frequency selection
#define ST7789_PWCTRL1 0xD0 // Power control 1
#define ST7789_VAPVANEN 0xD2 // Enable VAP/VAN signal output
#define ST7789_CMD2EN 0xDF // Command 2 enable
#define ST7789_PVGAMCTRL 0xE0 // Positive voltage gamma control
#define ST7789_NVGAMCTRL 0xE1 // Negative voltage gamma control
#define ST7789_DGMLUTR 0xE2 // Digital gamma look-up table for red
#define ST7789_DGMLUTB 0xE3 // Digital gamma look-up table for blue
#define ST7789_GATECTRL 0xE4 // Gate control
#define ST7789_SPI2EN 0xE7 // SPI2 enable
#define ST7789_PWCTRL2 0xE8 // Power control 2
#define ST7789_EQCTRL 0xE9 // Equalize time control
#define ST7789_PROMCTRL 0xEC // Program control
#define ST7789_PROMEN 0xFA // Program mode enable
#define ST7789_NVMSET 0xFC // NVM setting
#define ST7789_PROMACT 0xFE // Program action
// This is the command sequence that initialises the ST7789 driver
// Configure ST7789 display
{
static const uint8_t PROGMEM
st7789[] = {
8,
TFT_SLPOUT, TFT_INIT_DELAY, 255,
TFT_COLMOD, 1+TFT_INIT_DELAY, 0x55, 10,
TFT_MADCTL, 1, 0x00,
TFT_CASET, 4, 0x00, 0x00, 0x00, 0xF0,
TFT_PASET, 4, 0x00, 0x00, 0x00, 0xF0,
TFT_INVON, TFT_INIT_DELAY, 10,
TFT_NORON, TFT_INIT_DELAY, 10,
TFT_DISPON, TFT_INIT_DELAY, 255
};
commandList(st7789);
}
// End of ST7789 display configuration
\ No newline at end of file
// This is the command sequence that rotates the ST7789 driver coordinate frame
writecommand(TFT_MADCTL);
rotation = m % 4;
switch (rotation) {
case 0: // Portrait
#ifdef CGRAM_OFFSET
colstart = 0;
rowstart = 0;
#endif
writedata(TFT_MAD_COLOR_ORDER);
_width = _init_width;
_height = _init_height;
break;
case 1: // Landscape (Portrait + 90)
#ifdef CGRAM_OFFSET
colstart = 0;
rowstart = 0;
#endif
writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_COLOR_ORDER);
_width = _init_height;
_height = _init_width;
break;
case 2: // Inverter portrait
#ifdef CGRAM_OFFSET
colstart = 0;
rowstart = 80;
#endif
writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_COLOR_ORDER);
_width = _init_width;
_height = _init_height;
break;
case 3: // Inverted landscape
#ifdef CGRAM_OFFSET
colstart = 80;
rowstart = 0;
#endif
writedata(TFT_MAD_MV | TFT_MAD_MY | TFT_MAD_COLOR_ORDER);
_width = _init_height;
_height = _init_width;
break;
}
......@@ -23,6 +23,7 @@
writecommand(ST7789_COLMOD);
writedata(0x55);
delay(10);
//--------------------------------ST7789V Frame rate setting----------------------------------//
writecommand(ST7789_PORCTRL);
......@@ -92,7 +93,7 @@
writedata(0x1b);
writedata(0x1e);
writecommand(ST7789_INVOFF);
writecommand(ST7789_INVON);
writecommand(ST7789_CASET); // Column address set
writedata(0x00);
......@@ -113,6 +114,7 @@
spi_begin();
writecommand(ST7789_DISPON); //Display on
delay(120);
#ifdef TFT_BL
// Turn on the back-light LED
......
This diff is collapsed.
......@@ -37,7 +37,7 @@
#define SPI_READ_FREQUENCY SPI_FREQUENCY
#endif
#ifdef ST7789_DRIVER
#if defined(ST7789_DRIVER) || defined(ST7789_2_DRIVER)
#define TFT_SPI_MODE SPI_MODE3
#else
#define TFT_SPI_MODE SPI_MODE0
......@@ -831,6 +831,8 @@ class TFT_eSPI : public Print {
void getSetup(setup_t& tft_settings); // Sketch provides the instance to populate
static SPIClass& getSPIinstance(void);
int32_t cursor_x, cursor_y, padX;
uint32_t textcolor, textbgcolor;
......
......@@ -25,14 +25,15 @@
//#define ILI9481_DRIVER
//#define ILI9486_DRIVER
//#define ILI9488_DRIVER // WARNING: Do not connect ILI9488 display SDO to MISO if other devices share the SPI bus (TFT SDO does NOT tristate when CS is high)
//#define ST7789_DRIVER // Define additional parameters below for this display
//#define ST7789_DRIVER // Full configuration option, define additional parameters below for this display
//#define ST7789_2_DRIVER // Minimal configuration option, define additional parameters below for this display
//#define R61581_DRIVER
// Some displays support SPI reads via the MISO pin, other displays have a single
// bi-directional SDA pin and the library will try to read this via the MOSI line.
// To use the SDA line for reading data from the TFT uncomment the following line:
// #define TFT_SDA_READ // This option if for ESP32 ONLY, tested with ST7789 display only
// #define TFT_SDA_READ // This option is for ESP32 ONLY, tested with ST7789 display only
// For ST7789 ONLY, define the colour order IF the blue and red are swapped on your display
// Try ONE option at a time to find the correct colour order for your display
......
......@@ -39,13 +39,14 @@
//#include <User_Setups/Setup15_HX8357D.h> // Setup file configured for HX8357D (untested)
//#include <User_Setups/Setup16_ILI9488_Parallel.h> // Setup file for the ESP32 with parallel bus TFT
//#include <User_Setups/Setup17_ePaper.h> // Setup file for any Waveshare ePaper display
//#include <User_Setups/Setup18_ST7789.h> // Setup file configured for HX8357D (untested)
//#include <User_Setups/Setup18_ST7789.h> // Setup file configured for ST7789
//#include <User_Setups/Setup20_ILI9488.h> // Setup file for ESP8266 and ILI9488 SPI bus TFT
//#include <User_Setups/Setup21_ILI9488.h> // Setup file for ESP32 and ILI9488 SPI bus TFT
//#include <User_Setups/Setup22_TTGO_T4.h> // Setup file for ESP32 and TTGO T4 (BTC) ILI9341 SPI bus TFT
//#include <User_Setups/Setup23_TTGO_TM.h> // Setup file for ESP32 and TTGO TM ST7789 SPI bus TFT
//#include <User_Setups/Setup24_ST7789.h> // Setup file configured for ST7789 240 x 240
//#include <User_Setups/Setup43_ST7735.h> // Setup file configured for my ST7735S 80x160
......@@ -106,6 +107,9 @@
#elif defined (R61581_DRIVER)
#include "TFT_Drivers/R61581_Defines.h"
#define TFT_DRIVER 0x6158
#elif defined (ST7789_2_DRIVER)
#include "TFT_Drivers/ST7789_2_Defines.h"
#define TFT_DRIVER 0x778B
#elif defined (XYZZY_DRIVER) // <<<<<<<<<<<<<<<<<<<<<<<< ADD NEW DRIVER HERE
#include "TFT_Drivers/XYZZY_Defines.h"
#define TFT_DRIVER 0x0000
......
......@@ -23,7 +23,7 @@
#define SMOOTH_FONT
#define SPI_FREQUENCY 20000000
#define SPI_FREQUENCY 16000000
#define SPI_TOUCH_FREQUENCY 2500000
......
......@@ -2,8 +2,17 @@
#define ST7789_DRIVER
// #define TFT_SDA_READ // This option is for ESP32 ONLY, tested with ST7789 display only
#define TFT_SDA_READ
// If colours are inverted (white shows as black) then uncomment one of the next
// 2 lines try both options, one of the options should correct the inversion.
// #define TFT_INVERSION_ON
// #define TFT_INVERSION_OFF
// For ST7789 ONLY, define the colour order IF the blue and red are swapped on your display
// Try ONE option at a time to find the correct colour order for your display
// #define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue
// #define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red
// My ST7789 display has TCT_CS wired permananently low so the pin is not defined here
......
......@@ -2,6 +2,7 @@
#define ILI9488_DRIVER
//#define TFT_INVERSION_OFF
#define TFT_MISO 19 // (leave TFT SDO disconnected if other SPI devices share MISO)
#define TFT_MOSI 23
......@@ -27,4 +28,7 @@
// #define SPI_FREQUENCY 40000000
// #define SPI_FREQUENCY 80000000
// Optional reduced SPI frequency for reading TFT
#define SPI_READ_FREQUENCY 16000000
#define SPI_TOUCH_FREQUENCY 2500000
// ST7789 240 x 240 display with no chip select line
#define ST7789_DRIVER // Configure all registers
#define TFT_WIDTH 240
#define TFT_HEIGHT 240
//#define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue
//#define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red
//#define TFT_INVERSION_ON
//#define TFT_INVERSION_OFF
// DSTIKE stepup
//#define TFT_DC 23
//#define TFT_RST 32
//#define TFT_MOSI 26
//#define TFT_SCLK 27
// Generic ESP32 setup
//#define TFT_MISO 19
//#define TFT_MOSI 23
//#define TFT_SCLK 18
//#define TFT_CS -1 // Not connected
//#define TFT_DC 2
//#define TFT_RST 4 // Connect reset to ensure display initialises
// For NodeMCU - use pin numbers in the form PIN_Dx where Dx is the NodeMCU pin designation
#define TFT_CS -1 // Define as not used
#define TFT_DC PIN_D3 // Data Command control pin
#define TFT_RST PIN_D4 // Reset pin (could connect to NodeMCU RST, see next line)
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
//#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
#define SMOOTH_FONT
// #define SPI_FREQUENCY 27000000
#define SPI_FREQUENCY 40000000
#define SPI_READ_FREQUENCY 20000000
#define SPI_TOUCH_FREQUENCY 2500000
// #define SUPPORT_TRANSACTIONS
\ No newline at end of file
......@@ -25,7 +25,8 @@
//#define ILI9481_DRIVER
//#define ILI9486_DRIVER
//#define ILI9488_DRIVER // WARNING: Do not connect ILI9488 display SDO to MISO if other devices share the SPI bus (TFT SDO does NOT tristate when CS is high)
//#define ST7789_DRIVER // Define additional parameters below for this display
//#define ST7789_DRIVER // Full configuration option, define additional parameters below for this display
//#define ST7789_2_DRIVER // Minimal configuration option, define additional parameters below for this display
//#define R61581_DRIVER
// Some displays support SPI reads via the MISO pin, other displays have a single
......@@ -37,8 +38,8 @@
// For ST7789 ONLY, define the colour order IF the blue and red are swapped on your display
// Try ONE option at a time to find the correct colour order for your display
// #define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue
// #define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red
// #define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue
// #define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red
// For M5Stack ESP32 module with integrated ILI9341 display ONLY, remove // in line below
......
/*
Sketch to demonstrate using the print class with smooth fonts
that are saved onto an SD Card accessed by the SD library.
For ESP32 only, GPIO 5 must be used for SD chip select.
This method of storing the fonts is NOT compatible with the ESP8266.
Sketch is written for a 240 x 320 display
Load the font file onto the root directory of the SD Card. The font files
used by this sketch can be found in the Data folder, press Ctrl+K to see it.
The library supports 16 bit unicode characters:
https://en.wikipedia.org/wiki/Unicode_font
The characters supported are in the in the Basic Multilingal Plane:
https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane
Make sure all the display driver and pin connenctions are correct by
editting the User_Setup.h file in the TFT_eSPI library folder.
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
#########################################################################
*/
// Font file is stored on SD card
#include <SD.h>
// Graphics and font library
#include <TFT_eSPI.h>
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke library
// -------------------------------------------------------------------------
// Setup
// -------------------------------------------------------------------------
void setup(void) {
Serial.begin(115200); // Used for messages
// Initialise the SD library before the TFT so the chip select is defined
if (!SD.begin()) {
Serial.println("Card Mount Failed");
return;
}
uint8_t cardType = SD.cardType();
if (cardType == CARD_NONE) {
Serial.println("No SD card attached");
return;
}
Serial.print("SD Card Type: ");
if (cardType == CARD_MMC) {
Serial.println("MMC");
} else if (cardType == CARD_SD) {
Serial.println("SDSC");
} else if (cardType == CARD_SDHC) {
Serial.println("SDHC");
} else {
Serial.println("UNKNOWN");
}
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
Serial.printf("SD Card Size: %lluMB\n", cardSize);
// Initialise the TFT after the SD card!
tft.init();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
listDir(SD, "/", 0);
Serial.println("SD and TFT initialisation done.");
}
// -------------------------------------------------------------------------
// Main loop
// -------------------------------------------------------------------------
void loop() {
// Wrap test at right and bottom of screen
tft.setTextWrap(true, true);
// Name of font file (library adds leading / and .vlw)
String fileName = "Final-Frontier-28";
// Font and background colour, background colour is used for anti-alias blending
tft.setTextColor(TFT_WHITE, TFT_BLACK);
// Load the font
tft.loadFont(fileName, SD); // Use font stored on SD
// Display all characters of the font
tft.showFont(2000);
uint32_t dt = millis();
int count = 100;
while (count--)
{
// Set "cursor" at top left corner of display (0,0)
// (cursor will move to next line automatically during printing with 'tft.println'
// or stay on the line is there is room for the text with tft.print)
tft.setCursor(0, 0);
// Set the font colour to be white with a black background, set text size multiplier to 1
tft.setTextColor(TFT_WHITE, TFT_BLACK);
// We can now plot text on screen using the "print" class
tft.println("Hello World!");
// Set the font colour to be yellow
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
tft.println(1234.56);
// Set the font colour to be red
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.println((uint32_t)3735928559, HEX); // Should print DEADBEEF
// Set the font colour to be green with black background
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.println("Anti-aliased font!");
tft.println("");
// Test some print formatting functions
float fnumber = 123.45;
// Set the font colour to be blue
tft.setTextColor(TFT_BLUE, TFT_BLACK);
tft.print("Float = "); tft.println(fnumber); // Print floating point number
tft.print("Binary = "); tft.println((int)fnumber, BIN); // Print as integer value in binary
tft.print("Hexadecimal = "); tft.println((int)fnumber, HEX); // Print as integer number in Hexadecimal
}
Serial.println(millis()-dt);
// Unload the font to recover used RAM
tft.unloadFont();
delay(10000);
}
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
Serial.printf("Listing directory: %s\n", dirname);
File root = fs.open(dirname);
if(!root){
Serial.println("Failed to open directory");
return;
}
if(!root.isDirectory()){
Serial.println("Not a directory");
return;
}
File file = root.openNextFile();
while(file){
if(file.isDirectory()){
Serial.print(" DIR : ");
Serial.println(file.name());
if(levels){
listDir(fs, file.name(), levels -1);
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
}
......@@ -78,7 +78,7 @@ void setup(void) {
tft.setTextColor(TFT_BLUE, TFT_BLACK);
tft.println("Blue text");
delay(10000);
delay(5000);
}
......@@ -104,7 +104,7 @@ void loop() {
tft.setTextColor(TFT_BLUE, TFT_BLACK);
tft.println("Blue text");
delay(10000);
delay(5000);
// Binary inversion of colours
......@@ -128,5 +128,5 @@ void loop() {
tft.setTextColor(TFT_BLUE, TFT_BLACK);
tft.println("Blue text");
delay(10000);
delay(5000);
}
{
"name": "TFT_eSPI",
"version": "1.4.8",
"version": "1.4.9",
"keywords": "tft, ePaper, display, ESP8266, NodeMCU, ESP32, M5Stack, ILI9341, ST7735, ILI9163, S6D02A1, ILI9486, ST7789",
"description": "A TFT and ePaper SPI graphics library for ESP8266 and ESP32",
"repository":
......
name=TFT_eSPI
version=1.4.8
version=1.4.9
author=Bodmer
maintainer=Bodmer
sentence=A fast TFT graphics library for ESP8266 and ESP32 processors for the Arduino IDE
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment