Merge pull request #2 from Bodmer/master

refresh
This commit is contained in:
kostuch 2019-11-28 10:52:45 +01:00 committed by GitHub
commit 0f10a58e47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 468 additions and 90 deletions

View File

@ -52,7 +52,7 @@ void TFT_eSPI_Button::drawButton(boolean inverted) {
_gfx->fillRoundRect(_x1, _y1, _w, _h, r, fill);
_gfx->drawRoundRect(_x1, _y1, _w, _h, r, outline);
_gfx->setTextColor(text);
_gfx->setTextColor(text, fill);
_gfx->setTextSize(_textsize);
uint8_t tempdatum = _gfx->getTextDatum();

View File

@ -370,7 +370,6 @@ uint16_t TFT_eSPI::decodeUTF8(uint8_t c)
*/
/***************************************************************************************
** Function name: alphaBlend
** Description: Blend foreground and background and return new colour
@ -509,6 +508,7 @@ void TFT_eSPI::drawGlyph(uint16_t code)
else drawFastHLine( xs, y + cy, dl, fg);
dl = 0;
}
if (getColor) bg = getColor(x + cx, y + cy);
drawPixel(x + cx, y + cy, alphaBlend(pixel, fg, bg));
}
else

View File

@ -91,6 +91,16 @@ void* TFT_eSprite::createSprite(int16_t w, int16_t h, uint8_t frames)
}
/***************************************************************************************
** Function name: ~TFT_eSprite
** Description: Class destructor
*************************************************************************************x*/
TFT_eSprite::~TFT_eSprite()
{
deleteSprite();
}
/***************************************************************************************
** Function name: callocSprite
** Description: Allocate a memory area for the Sprite and return pointer
@ -566,21 +576,21 @@ void TFT_eSprite::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_
int32_t xs = x;
int32_t ys = y;
uint32_t ws = w;
uint32_t hs = h;
int32_t ws = w;
int32_t hs = h;
if (x < 0) { xo = -x; ws += x; xs = 0; }
if (y < 0) { yo = -y; hs += y; ys = 0; }
if (xs + ws >= _iwidth) ws = _iwidth - xs;
if (ys + hs >= _iheight) hs = _iheight - ys;
if (xs + ws >= (int32_t)_iwidth) ws = _iwidth - xs;
if (ys + hs >= (int32_t)_iheight) hs = _iheight - ys;
if (_bpp == 16) // Plot a 16 bpp image into a 16 bpp Sprite
{
for (uint32_t yp = yo; yp < yo + hs; yp++)
for (int32_t yp = yo; yp < yo + hs; yp++)
{
x = xs;
for (uint32_t xp = xo; xp < xo + ws; xp++)
for (int32_t xp = xo; xp < xo + ws; xp++)
{
uint16_t color = data[xp + yp * w];
if(!_iswapBytes) color = color<<8 | color>>8;
@ -592,10 +602,10 @@ void TFT_eSprite::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_
}
else if (_bpp == 8) // Plot a 16 bpp image into a 8 bpp Sprite
{
for (uint32_t yp = yo; yp < yo + hs; yp++)
for (int32_t yp = yo; yp < yo + hs; yp++)
{
x = xs;
for (uint32_t xp = xo; xp < xo + ws; xp++)
for (int32_t xp = xo; xp < xo + ws; xp++)
{
uint16_t color = data[xp + yp * w];
if(_iswapBytes) color = color<<8 | color>>8;
@ -662,21 +672,21 @@ void TFT_eSprite::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const u
int32_t xs = x;
int32_t ys = y;
uint32_t ws = w;
uint32_t hs = h;
int32_t ws = w;
int32_t hs = h;
if (x < 0) { xo = -x; ws += x; xs = 0; }
if (y < 0) { yo = -y; hs += y; ys = 0; }
if (xs + ws >= _iwidth) ws = _iwidth - xs;
if (ys + hs >= _iheight) hs = _iheight - ys;
if (xs + ws >= (int32_t)_iwidth) ws = _iwidth - xs;
if (ys + hs >= (int32_t)_iheight) hs = _iheight - ys;
if (_bpp == 16) // Plot a 16 bpp image into a 16 bpp Sprite
{
for (uint32_t yp = yo; yp < yo + hs; yp++)
for (int32_t yp = yo; yp < yo + hs; yp++)
{
x = xs;
for (uint32_t xp = xo; xp < xo + ws; xp++)
for (int32_t xp = xo; xp < xo + ws; xp++)
{
uint16_t color = pgm_read_word(data + xp + yp * w);
if(!_iswapBytes) color = color<<8 | color>>8;
@ -689,10 +699,10 @@ void TFT_eSprite::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const u
else if (_bpp == 8) // Plot a 16 bpp image into a 8 bpp Sprite
{
for (uint32_t yp = yo; yp < yo + hs; yp++)
for (int32_t yp = yo; yp < yo + hs; yp++)
{
x = xs;
for (uint32_t xp = xo; xp < xo + ws; xp++)
for (int32_t xp = xo; xp < xo + ws; xp++)
{
uint16_t color = pgm_read_word(data + xp + yp * w);
if(_iswapBytes) color = color<<8 | color>>8;
@ -733,7 +743,7 @@ void TFT_eSprite::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const u
uint8_t pbyte = pgm_read_byte(pdata++);
for (uint8_t xc = 0; xc < 8; xc++)
{
if (xp+xc<w) drawPixel(x+xp+xc, y+yp, (pbyte<<xc) & 0x80);
if (xp+xc<(uint32_t)w) drawPixel(x+xp+xc, y+yp, (pbyte<<xc) & 0x80);
}
}
}

View File

@ -10,6 +10,7 @@ class TFT_eSprite : public TFT_eSPI {
public:
TFT_eSprite(TFT_eSPI *tft);
virtual ~TFT_eSprite();
// Create a sprite of width x height pixels, return a pointer to the RAM area
// Sketch can cast returned value to (uint16_t*) for 16 bit depth if needed

View File

@ -1,5 +1,12 @@
// Font 2
// Comment out for £ sign for character 24
#define TFT_ESPI_FONT2_DOLLAR
// The grave ( ` ) diacritical mark will show as a degree ( ° ) symbol
// Comment out next line to return character 0x60 to the grave accent:
#define TFT_ESPI_GRAVE_IS_DEGREE
#include <pgmspace.h>
// Width has been increased by 1 pixel so pixel lengths are calculated correctly
@ -15,8 +22,11 @@ PROGMEM const unsigned char widtbl_f16[96] = // character width table
8, 4, 8, 8, 7, 10, 8, 8, // char 72 - 79
8, 8, 8, 8, 8, 8, 8, 10, // char 80 - 87
8, 8, 8, 4, 7, 4, 7, 9, // char 88 - 95
// 4, 7, 7, 7, 7, 7, 6, 7, // char 96 - 103 grave see lines 411-414
5, 7, 7, 7, 7, 7, 6, 7, // char 96 - 103 celcius
#ifdef TFT_ESPI_GRAVE_IS_DEGREE
5, 7, 7, 7, 7, 7, 6, 7, // char 96 - 103 0x60 is degree symbol
#else
4, 7, 7, 7, 7, 7, 6, 7, // char 96 - 103 0x60 is grave
#endif
7, 4, 5, 6, 4, 8, 7, 8, // char 104 - 111
7, 8, 6, 6, 5, 7, 8, 8, // char 112 - 119
6, 7, 7, 5, 3, 5, 8, 6 // char 120 - 127
@ -50,8 +60,13 @@ PROGMEM const unsigned char chr_f16_23[16] = // 1 unsigned char per row
PROGMEM const unsigned char chr_f16_24[16] = // 1 unsigned char per row
{
#ifdef TFT_ESPI_FONT2_DOLLAR
0x00, 0x00, 0x28, 0x38, 0x6C, 0xAA, 0xA8, 0x68, 0x3C, 0x2A, 0xAA, // row 1 - 11
0x6C, 0x38, 0x28, 0x00, 0x00 // row 12 - 16
#else // GBP sign
0x00, 0x00, 0x00, 0x3C, 0x42, 0x40, 0x40, 0x70, 0x40, 0x70, 0x40, // row 1 - 11
0x40, 0xFE, 0x00, 0x00, 0x00 // row 12 - 16
#endif
};
PROGMEM const unsigned char chr_f16_25[16] = // 1 unsigned char per row
@ -384,8 +399,8 @@ PROGMEM const unsigned char chr_f16_5B[16] = // 1 unsigned char per row
PROGMEM const unsigned char chr_f16_5C[16] = // 1 unsigned char per row
{
0x00, 0x00, 0x04, 0x04, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x40, // row 1 - 11
0x40, 0x80, 0x80, 0x00, 0x00 // row 12 - 16
0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x10, 0x08, // row 1 - 11
0x08, 0x04, 0x04, 0x00, 0x00 // row 12 - 16
};
PROGMEM const unsigned char chr_f16_5D[16] = // 1 unsigned char per row
@ -408,10 +423,13 @@ PROGMEM const unsigned char chr_f16_5F[32] = // 1 unsigned chars per row
PROGMEM const unsigned char chr_f16_60[16] = // 1 unsigned char per row
{
// 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, // row 1 - 11 grave
// 0x00, 0x00, 0x00, 0x00, 0x00 // row 12 - 16
0x00, 0x00, 0x00, 0x60, 0x90, 0x90, 0x60, 0x00, 0x00, 0x00, 0x00, // row 1 - 11 Celcius
0x00, 0x00, 0x00, 0x00, 0x00
#ifdef TFT_ESPI_GRAVE_IS_DEGREE
0x00, 0x00, 0x00, 0x60, 0x90, 0x90, 0x60, 0x00, 0x00, 0x00, 0x00, // row 1 - 11 Degree symbol
0x00, 0x00, 0x00, 0x00, 0x00
#else
0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, // row 1 - 11 Grave accent
0x00, 0x00, 0x00, 0x00, 0x00 // row 12 - 16
#endif
};
PROGMEM const unsigned char chr_f16_61[16] = // 1 unsigned char per row

View File

@ -1,22 +1,26 @@
# News
1. Sprites can now by pushed to the screen (or another Sprite) with a rotation angle. The new function is pushRotated(). Three new examples (Rotate_Sprite_1/2/3) have been added to show how the functions can be used to rotate text, images and to draw animated dials with moving needles.
1. A callback function has been added, this allows antialiased fonts to be rendered over colour gradients or images. Two new examples have been added to illustrate this new capability:
2. A new TFT_eFEX support library has been created which includes extra functions such as drawing a BMP or Jpeg to the screen. This library will simplify the examples. It will be expanded at a future date to include meters, dials and GUI elements like progress bars, graphs and animated buttons:
"Smooth_font_reading_TFT"
"Smooth_font_gradient"
![AA_gradien](https://i.imgur.com/YMBcPHp.png)
2. Sprites can now by pushed to the screen (or another Sprite) with a rotation angle. The new function is pushRotated(). Three new examples (Rotate_Sprite_1/2/3) have been added to show how the functions can be used to rotate text, images and to draw animated dials with moving needles.
3. A new TFT_eFEX support library has been created which includes extra functions such as drawing a BMP or Jpeg to the screen. This library will simplify the examples. It will be expanded at a future date to include meters, dials and GUI elements like progress bars, graphs and animated buttons:
https://github.com/Bodmer/TFT_eFEX
3. androdlang has published a really nice companion library to extend the graphics capabilities of TFT_eSPI, you can find this here:
4. androdlang has published a really nice companion library to extend the graphics capabilities of TFT_eSPI, you can find this here:
https://github.com/androdlang/TFTShape
4. I have created a user updateable graphics extension library template that can be used to create your own graphics extensions. The Library contains examples and is commented so it should be clear what you need to do to add functions. You can find it here:
5. I have created a user updateable graphics extension library template that can be used to create your own graphics extensions. The Library contains examples and is commented so it should be clear what you need to do to add functions. You can find it here:
https://github.com/Bodmer/TFT_eFX
5. The capability to read from an ST7789V TFT with a single bidirectional SDA pin has been added. At the moment this **ONLY** works with an ESP32. It is enabled with a #define TFT_SDA_READ in the setup file.
6. ST7789V and ILI9341 displays are manufactured in two variants that have the red and blue pixels swapped, this is catered for by a new option in the setup file:
//#define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue
//#define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red
6. The capability to read from an ST7789V TFT with a single bidirectional SDA pin has been added. At the moment this **ONLY** works with an ESP32. It is enabled with a #define TFT_SDA_READ in the setup file.
# TFT_eSPI
@ -73,7 +77,7 @@ Here is an example screenshot showing the anti-aliased Hiragana character Unicod
![Hiragana glyphs](https://i.imgur.com/jeXf2st.png)
Antialiased fonts can also be drawn over a gradient background with a callback to fetch the background colour of each pixel. This pixel colour can be set by the gradient algorithm or by reading back the TFT screen memory (if reading the display is supported).
# ESP32 with 8 bit Mcufriend UNO shields

View File

@ -84,8 +84,8 @@
rowstart = 0;
} else if(tabcolor == INITR_GREENTAB160x80) {
writedata(TFT_MAD_BGR);
colstart = 0;
rowstart = 0;
colstart = 26;
rowstart = 1;
} else if(tabcolor == INITR_REDTAB160x80) {
writedata(TFT_MAD_BGR);
colstart = 24;

View File

@ -49,6 +49,8 @@ uint8_t readByte(void);
// GPIO parallel input/output control
void busDir(uint32_t mask, uint8_t mode);
void gpioMode(uint8_t gpio, uint8_t mode);
inline void TFT_eSPI::spi_begin(void){
#if defined (SPI_HAS_TRANSACTION) && defined (SUPPORT_TRANSACTIONS) && !defined(ESP32_PARALLEL)
if (locked) {locked = false; spi.beginTransaction(SPISettings(SPI_FREQUENCY, MSBFIRST, TFT_SPI_MODE)); CS_L;}
@ -393,6 +395,8 @@ void TFT_eSPI::init(uint8_t tc)
spi_begin();
tc = tc; // Supress warning
// This loads the driver specific initialisation code <<<<<<<<<<<<<<<<<<<<< ADD NEW DRIVERS TO THE LIST HERE <<<<<<<<<<<<<<<<<<<<<<<
#if defined (ILI9341_DRIVER)
#include "TFT_Drivers/ILI9341_Init.h"
@ -727,6 +731,11 @@ uint16_t TFT_eSPI::readPixel(int32_t x0, int32_t y0)
#else // Not ESP32_PARALLEL
// This function can get called during antialiased font rendering
// so a transaction may be in progress
bool wasInTransaction = inTransaction;
if (inTransaction) { inTransaction= false; spi_end();}
spi_begin_read();
readAddrWindow(x0, y0, 1, 1); // Sets CS low
@ -764,11 +773,19 @@ uint16_t TFT_eSPI::readPixel(int32_t x0, int32_t y0)
spi_end_read();
// Reinstate the transaction if one was in progress
if(wasInTransaction) { spi_begin(); inTransaction = true; }
return color565(r, g, b);
#endif
}
void TFT_eSPI::setCallback(getColorCallback getCol)
{
getColor = getCol;
}
/***************************************************************************************
** Function name: read byte - supports class functions
** Description: Read a byte from ESP32 8 bit data port
@ -801,29 +818,45 @@ uint8_t readByte(void)
}
/***************************************************************************************
** Function name: masked GPIO direction control - supports class functions
** Description: Set masked ESP32 GPIO pins to input or output
** Function name: GPIO direction control - supports class functions
** Description: Set parallel bus to input or output
***************************************************************************************/
void busDir(uint32_t mask, uint8_t mode)
{
#ifdef ESP32_PARALLEL
void busDir(uint32_t mask, uint8_t mode)
{//*
gpioMode(TFT_D0, mode);
gpioMode(TFT_D1, mode);
gpioMode(TFT_D2, mode);
gpioMode(TFT_D3, mode);
gpioMode(TFT_D4, mode);
gpioMode(TFT_D5, mode);
gpioMode(TFT_D6, mode);
gpioMode(TFT_D7, mode);
return; //*/
// Supports GPIO 0 - 31 on ESP32 only
gpio_config_t gpio;
gpio.pin_bit_mask = mask;
gpio.mode = GPIO_MODE_INPUT;
gpio.pull_up_en = GPIO_PULLUP_ENABLE;
gpio.pull_down_en = GPIO_PULLDOWN_DISABLE;
gpio.intr_type = GPIO_INTR_DISABLE;
if (mode == OUTPUT) gpio.mode = GPIO_MODE_OUTPUT;
gpio_config(&gpio);
#endif
/*
// Arduino generic native function, but slower
pinMode(TFT_D0, mode);
pinMode(TFT_D1, mode);
pinMode(TFT_D2, mode);
pinMode(TFT_D3, mode);
pinMode(TFT_D4, mode);
pinMode(TFT_D5, mode);
pinMode(TFT_D6, mode);
pinMode(TFT_D7, mode);
return; //*/
}
// Set ESP32 GPIO pin to input or output
void gpioMode(uint8_t gpio, uint8_t mode)
{
if(mode == INPUT) GPIO.enable_w1tc = ((uint32_t)1 << gpio);
else GPIO.enable_w1ts = ((uint32_t)1 << gpio);
ESP_REG(DR_REG_IO_MUX_BASE + esp32_gpioMux[gpio].reg) = ((uint32_t)2 << FUN_DRV_S) | (FUN_IE) | ((uint32_t)2 << MCU_SEL_S);
GPIO.pin[gpio].val = 0;
}
#endif
/***************************************************************************************
** Function name: read rectangle (for SPI Interface II i.e. IM [3:0] = "1101")
** Description: Read 565 pixel colours from a defined area

View File

@ -15,7 +15,7 @@
#ifndef _TFT_eSPIH_
#define _TFT_eSPIH_
#define TFT_ESPI_VERSION "1.4.20"
#define TFT_ESPI_VERSION "1.4.21"
//#define ESP32 //Just used to test ESP32 options
@ -656,6 +656,7 @@ const PROGMEM fontinfo fontdata [] = {
#endif
};
typedef uint16_t (*getColorCallback)(uint16_t x, uint16_t y);
// Class functions and variables
class TFT_eSPI : public Print {
@ -741,6 +742,7 @@ class TFT_eSPI : public Print {
// Read the colour of a pixel at x,y and return value in 565 format
uint16_t readPixel(int32_t x0, int32_t y0);
void setCallback(getColorCallback getCol);
// The next functions can be used as a pair to copy screen blocks (or horizontal/vertical lines) to another location
// Read a block of pixels to a data buffer, buffer is 16 bit and the array size must be at least w * h
@ -877,6 +879,7 @@ class TFT_eSPI : public Print {
uint32_t lastColor = 0xFFFF;
getColorCallback getColor = nullptr;
protected:

View File

@ -140,10 +140,12 @@
// ###### FOR ESP8266 OVERLAP MODE EDIT THE PIN NUMBERS IN THE FOLLOWING LINES ######
// Overlap mode shares the ESP8266 FLASH SPI bus with the TFT so has a performance impact
// but saves pins for other functions.
// Use NodeMCU SD0=MISO, SD1=MOSI, CLK=SCLK to connect to TFT in overlap mode
// but saves pins for other functions. It is best not to connect MISO as some displays
// do not tristate that line wjen chip select is high!
// On NodeMCU 1.0 SD0=MISO, SD1=MOSI, CLK=SCLK to connect to TFT in overlap mode
// On NodeMCU V3 S0 =MISO, S1 =MOSI, S2 =SCLK
// In ESP8266 overlap mode the following must be defined
//#define TFT_SPI_OVERLAP
// In ESP8266 overlap mode the TFT chip select MUST connect to pin D3

View File

@ -126,15 +126,15 @@
// These are the pins for ESP8266 boards
// Name GPIO NodeMCU Function
#define PIN_D0 D0 // GPIO16 WAKE
#define PIN_D1 D1 // GPIO5 User purpose
#define PIN_D2 D2 // GPIO4 User purpose
#define PIN_D3 D3 // GPIO0 Low on boot means enter FLASH mode
#define PIN_D4 D4 // GPIO2 TXD1 (must be high on boot to go to UART0 FLASH mode)
#define PIN_D5 D5 // GPIO14 HSCLK
#define PIN_D6 D6 // GPIO12 HMISO
#define PIN_D7 D7 // GPIO13 HMOSI RXD2
#define PIN_D8 D8 // GPIO15 HCS TXD0 (must be low on boot to enter UART0 FLASH mode)
#define PIN_D0 16 // GPIO16 WAKE
#define PIN_D1 5 // GPIO5 User purpose
#define PIN_D2 4 // GPIO4 User purpose
#define PIN_D3 0 // GPIO0 Low on boot means enter FLASH mode
#define PIN_D4 2 // GPIO2 TXD1 (must be high on boot to go to UART0 FLASH mode)
#define PIN_D5 14 // GPIO14 HSCLK
#define PIN_D6 12 // GPIO12 HMISO
#define PIN_D7 13 // GPIO13 HMOSI RXD2
#define PIN_D8 15 // GPIO15 HCS TXD0 (must be low on boot to enter UART0 FLASH mode)
#define PIN_D9 3 // RXD0
#define PIN_D10 1 // TXD0

View File

@ -11,7 +11,7 @@
#define ST7735_GREENTAB160x80
#ifdef ESP32
#define TFT_MISO 19
#define TFT_MOSI 23
#define TFT_SCLK 18
@ -19,7 +19,16 @@
#define TFT_DC 2 // Data Command control pin
#define TFT_RST 4 // Reset pin (could connect to RST pin)
//#define TFT_RST -1 // Set TFT_RST to -1 if display RESET is connected to ESP32 board RST
#else
// Display GND to NodeMCU pin GND (0V)
// Display VCC to NodeMCU 5V or 3.3V
// Display SCK to NodeMCU pin D5
// Display SDI/MOSI to NodeMCU pin D7
// Display BLK to NodeMCU pin VIN
#define TFT_CS PIN_D8 // Chip select control pin D8
#define TFT_DC PIN_D3 // Data Command control pin
#define TFT_RST PIN_D4 // Reset pin (could connect to NodeMCU RST, see next line)
#endif
#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

View File

@ -9,6 +9,13 @@
#define ST7735_REDTAB
// Overlap mode shares the ESP8266 FLASH SPI bus with the TFT so has a performance impact
// but saves pins for other functions. It is best not to connect MISO as some displays
// do not tristate that line wjen chip select is high!
// On NodeMCU 1.0 SD0=MISO, SD1=MOSI, CLK=SCLK to connect to TFT in overlap mode
// On NodeMCU V3 S0 =MISO, S1 =MOSI, S2 =SCLK
// In ESP8266 overlap mode the following must be defined
#define TFT_SPI_OVERLAP
// In ESP8266 overlap mode the TFT chip select MUST connect to pin D3
#define TFT_CS PIN_D3
@ -16,8 +23,7 @@
#define TFT_RST PIN_D4 // Reset pin (could connect to NodeMCU RST, see next line)
//#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V
// In ESP8266 overlap mode the following must be defined
#define TFT_SPI_OVERLAP
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH

View File

@ -28,18 +28,19 @@
//#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
//#define RM68140_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 and ILI9341 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
@ -139,10 +140,12 @@
// ###### FOR ESP8266 OVERLAP MODE EDIT THE PIN NUMBERS IN THE FOLLOWING LINES ######
// Overlap mode shares the ESP8266 FLASH SPI bus with the TFT so has a performance impact
// but saves pins for other functions.
// Use NodeMCU SD0=MISO, SD1=MOSI, CLK=SCLK to connect to TFT in overlap mode
// but saves pins for other functions. It is best not to connect MISO as some displays
// do not tristate that line wjen chip select is high!
// On NodeMCU 1.0 SD0=MISO, SD1=MOSI, CLK=SCLK to connect to TFT in overlap mode
// On NodeMCU V3 S0 =MISO, S1 =MOSI, S2 =SCLK
// In ESP8266 overlap mode the following must be defined
//#define TFT_SPI_OVERLAP
// In ESP8266 overlap mode the TFT chip select MUST connect to pin D3
@ -264,7 +267,7 @@
// The ESP32 has 2 free SPI ports i.e. VSPI and HSPI, the VSPI is the default.
// If the VSPI port is in use and pins are not accessible (e.g. TTGO T-Beam)
// then uncomment the following line to use the HSPI port:
// then uncomment the following line:
//#define USE_HSPI_PORT
// Comment out the following #define if "SPI Transactions" do not need to be

View File

@ -38,11 +38,11 @@
#########################################################################
*/
#include "Free_Fonts.h" // Include the header file attached to this sketch
#include "SPI.h"
#include "TFT_eSPI.h"
#include "Free_Fonts.h" // Include the header file attached to this sketch
// Use hardware SPI
TFT_eSPI tft = TFT_eSPI();

View File

@ -39,8 +39,6 @@
//
// tft.setFreeFont(NULL); // Set font to GLCD
#define LOAD_GFXFF
#ifdef LOAD_GFXFF // Only include the fonts if LOAD_GFXFF is defined in User_Setup.h
// Use these when printing or drawing text in GLCD and high rendering speed fonts
@ -264,6 +262,8 @@
#define FONT7 7
#define FONT8 8
#define TT1 1
#define FF0 1
#define FF1 1
#define FF2 1

View File

@ -23,11 +23,11 @@
#########################################################################
*/
#include "Free_Fonts.h" // Include the header file attached to this sketch
#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
#include "Free_Fonts.h" // Include the header file attached to this sketch
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library with default width and height
unsigned long drawTime = 0;

View File

@ -39,7 +39,6 @@
//
// tft.setFreeFont(NULL); // Set font to GLCD
#define LOAD_GFXFF
#ifdef LOAD_GFXFF // Only include the fonts if LOAD_GFXFF is defined in User_Setup.h
@ -265,6 +264,8 @@
#define FONT7 7
#define FONT8 8
#define TT1 1
#define FF0 1
#define FF1 1
#define FF2 1

View File

@ -34,6 +34,7 @@ void drawBmp(const char *filename, int16_t x, int16_t y) {
{
y += h - 1;
bool oldSwapBytes = tft.getSwapBytes();
tft.setSwapBytes(true);
bmpFS.seek(seekOffset);
@ -58,6 +59,7 @@ void drawBmp(const char *filename, int16_t x, int16_t y) {
// y is decremented as the BMP image is drawn bottom up
tft.pushImage(x, y--, w, 1, (uint16_t*)lineBuffer);
}
tft.setSwapBytes(oldSwapBytes);
Serial.print("Loaded in "); Serial.print(millis() - startTime);
Serial.println(" ms");
}

View File

@ -0,0 +1,121 @@
/*
This sketch is based on Font Demo 1. It introduces a method for rendering
anti-aliased fonts on a graded background. This is acheived by telling the
TFT_eSPI library the pixel color at each point on the screen. In this sketch
a graded background is drawn, the color of each pixel can therefore be
determined. The TFT does not need to support reading of the graphics memory.
The sketch could be adapted so only part of the screen is gas a color gradient.
The TFT_eSPI library must be given the name of the function in the sketch
that will return the pixel xolor at a position x,y on the TFT. In this
sketch that function is called gradientColor, so this line is included:
tft.setCallback(gradientColor);
TFT_eSPI will call this function during the rendering of the anti-aliased
font to blend the edges of each character with the returned color.
If the TFT supports reading the screen RAM then the returned value can be
tft.readPixel(x,y) and anti-aliased text can the be drawn over any screen
image. See "Smooth_font_over_image" example.
*/
// The fonts used are in the sketch data folder, press Ctrl+K to view.
// Upload the fonts and icons to SPIFFS (must set at least 1M for SPIFFS) using the
// "Tools" "ESP8266 (or ESP32) Sketch Data Upload" menu option in the IDE.
// To add this option follow instructions here for the ESP8266:
// https://github.com/esp8266/arduino-esp8266fs-plugin
// or for the ESP32:
// https://github.com/me-no-dev/arduino-esp32fs-plugin
// Close the IDE and open again to see the new menu option.
// A processing sketch to create new fonts can be found in the Tools folder of TFT_eSPI
// https://github.com/Bodmer/TFT_eSPI/tree/master/Tools/Create_Smooth_Font/Create_font
// This sketch uses font files created from the Noto family of fonts:
// https://www.google.com/get/noto/
#define AA_FONT_SMALL "NotoSansBold15"
#define AA_FONT_LARGE "NotoSansBold36"
// Font files are stored in SPIFFS, so load the library
#include <FS.h>
#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI();
#define TOP_COLOR TFT_RED
#define BOTTOM_COLOR TFT_BLACK
#define GRADIENT_HEIGHT (9 + tft.fontHeight() * 5) // Gradient over 5 lines
#define OUTSIDE_GRADIENT TFT_BLUE
uint16_t gradientColor(uint16_t x, uint16_t y)
{
if (y > GRADIENT_HEIGHT) return OUTSIDE_GRADIENT; // Outside gradient area
uint8_t alpha = (255 * y) / GRADIENT_HEIGHT; // alpha is a value in the range 0-255
return tft.alphaBlend(alpha, BOTTOM_COLOR, TOP_COLOR);
}
void fillGradient() {
uint16_t w = tft.width();
for (uint16_t y = 0; y < tft.height(); ++y) {
uint16_t color = gradientColor(0, y); // x not used here
tft.drawFastHLine(0, y, w, color);
}
}
void setup(void) {
Serial.begin(115200);
tft.begin();
tft.setCallback(gradientColor); // Switch on color callback for anti-aliased fonts
//tft.setCallback(nullptr); // Switch off callback (off by default)
tft.setRotation(1);
if (!SPIFFS.begin()) {
Serial.println("SPIFFS initialisation failed!");
while (1) yield(); // Stay here twiddling thumbs waiting
}
Serial.println("\r\nSPIFFS available!");
// ESP32 will crash if any of the fonts are missing
bool font_missing = false;
if (SPIFFS.exists("/NotoSansBold15.vlw") == false) font_missing = true;
if (SPIFFS.exists("/NotoSansBold36.vlw") == false) font_missing = true;
if (font_missing)
{
Serial.println("\r\nFont missing in SPIFFS, did you upload it?");
while (1) yield();
}
else Serial.println("\r\nFonts found OK.");
}
void loop() {
// Select a font size comensurate with screen size
if (tft.width()>= 320)
tft.loadFont(AA_FONT_LARGE);
else
tft.loadFont(AA_FONT_SMALL);
fillGradient(); // Put here after selecting the font so fontHeight() is already set
tft.setTextColor(TFT_WHITE); // Background color is ignored in gradient area
tft.setCursor(0, 10); // Set cursor at top left of screen
uint32_t t = millis();
tft.println(" Ode to a small\n lump of green\n putty I found\n in my armpit\n one midsummer\n morning ");
Serial.println(t = millis()-t);
tft.unloadFont(); // Remove the font to recover memory used
delay(2000);
}

View File

@ -0,0 +1,165 @@
/*
This sketch is based on Font Demo 1. It introduces a method for rendering
anti-aliased fonts on an arbitrary background. This is acheived by reading
the pixel color at each point on the screen. The TFT must support reading
the graphics RAM of the screen memory. This sketch has been tested with
ILI9241 and ILI9481 serial and parallel screens. Other screens may or may
not work!
The TFT_eSPI library must be given the name of the function in the sketch
that will return the pixel color at a position x,y on the TFT. In this
sketch that function is called pixelColor, so this line is included:
tft.setCallback(pixelColor);
TFT_eSPI will call this function during the rendering of the anti-aliased
font and use it to blend the edges of each character with the screen color.
*/
// The fonts used are in the sketch data folder, press Ctrl+K to view.
// Upload the fonts and icons to SPIFFS (must set at least 1M for SPIFFS) using the
// "Tools" "ESP8266 (or ESP32) Sketch Data Upload" menu option in the IDE.
// To add this option follow instructions here for the ESP8266:
// https://github.com/esp8266/arduino-esp8266fs-plugin
// or for the ESP32:
// https://github.com/me-no-dev/arduino-esp32fs-plugin
// Close the IDE and open again to see the new menu option.
// A processing sketch to create new fonts can be found in the Tools folder of TFT_eSPI
// https://github.com/Bodmer/TFT_eSPI/tree/master/Tools/Create_Smooth_Font/Create_font
// This sketch uses font files created from the Noto family of fonts:
// https://www.google.com/get/noto/
#define AA_FONT_SMALL "NotoSansBold15"
#define AA_FONT_LARGE "NotoSansBold36"
// Font files are stored in SPIFFS, so load the library
#include <FS.h>
#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI();
// Callback function to provide the pixel color at x,y
uint16_t pixelColor(uint16_t x, uint16_t y) { return tft.readPixel(x, y); }
void setup(void) {
Serial.begin(115200);
tft.begin();
tft.setCallback(pixelColor); // The callback is only used durung font rendering
//tft.setCallback(nullptr); // Switch off callback (off by default)
tft.setRotation(1);
if (!SPIFFS.begin()) {
Serial.println("SPIFFS initialisation failed!");
while (1) yield(); // Stay here twiddling thumbs waiting
}
Serial.println("\r\nSPIFFS available!");
// ESP32 will crash if any of the fonts are missing, so check
bool font_missing = false;
if (SPIFFS.exists("/NotoSansBold15.vlw") == false) font_missing = true;
if (SPIFFS.exists("/NotoSansBold36.vlw") == false) font_missing = true;
if (font_missing)
{
Serial.println("\r\nFont missing in SPIFFS, did you upload it?");
while (1) yield();
}
else Serial.println("\r\nFonts found OK.");
}
void loop() {
rainbow_fill(); // Fill the screen with rainbow colours
// Select a font size comensurate with screen size
if (tft.width()>= 320)
tft.loadFont(AA_FONT_LARGE);
else
tft.loadFont(AA_FONT_SMALL);
tft.setTextColor(TFT_BLACK, TFT_WHITE); // Background color is ignored if callback is set
tft.setCursor(0, 10); // Set cursor at top left of screen
uint32_t t = millis();
tft.println(" Ode to a small\n lump of green\n putty I found\n in my armpit\n one midsummer\n morning ");
Serial.println(t = millis()-t);
tft.unloadFont(); // Remove the font to recover memory used
delay(2000);
}
// #########################################################################
// Fill screen with a rainbow pattern
// #########################################################################
byte red = 31;
byte green = 0;
byte blue = 0;
byte state = 0;
unsigned int colour = red << 11; // Colour order is RGB 5+6+5 bits each
void rainbow_fill()
{
// The colours and state are not initialised so the start colour changes each time the funtion is called
for (int i = 319; i >= 0; i--) {
// Draw a vertical line 1 pixel wide in the selected colour
tft.drawFastHLine(0, i, tft.width(), colour); // in this example tft.width() returns the pixel width of the display
// This is a "state machine" that ramps up/down the colour brightnesses in sequence
switch (state) {
case 0:
green ++;
if (green == 64) {
green = 63;
state = 1;
}
break;
case 1:
red--;
if (red == 255) {
red = 0;
state = 2;
}
break;
case 2:
blue ++;
if (blue == 32) {
blue = 31;
state = 3;
}
break;
case 3:
green --;
if (green == 255) {
green = 0;
state = 4;
}
break;
case 4:
red ++;
if (red == 32) {
red = 31;
state = 5;
}
break;
case 5:
blue --;
if (blue == 255) {
blue = 0;
state = 0;
}
break;
}
colour = red << 11 | green << 5 | blue;
}
}

View File

@ -1,6 +1,6 @@
{
"name": "TFT_eSPI",
"version": "1.4.20",
"version": "1.4.21",
"keywords": "tft, ePaper, display, ESP8266, NodeMCU, ESP32, M5Stack, ILI9341, ST7735, ILI9163, S6D02A1, ILI9486, ST7789, RM68140",
"description": "A TFT and ePaper SPI graphics library for ESP8266 and ESP32",
"repository":

View File

@ -1,5 +1,5 @@
name=TFT_eSPI
version=1.4.20
version=1.4.21
author=Bodmer
maintainer=Bodmer
sentence=A fast TFT graphics library for ESP8266 and ESP32 processors for the Arduino IDE