Remove warning

This commit is contained in:
Luc 2023-10-18 20:44:46 +08:00
parent 73ccc7932d
commit 4c5c21653c

View File

@ -32,7 +32,8 @@
#include <SPI.h>
/***************************************************************************************
** Section 2: Load library and processor specific header files
** Section 2: Load library and processor specific header
*files
***************************************************************************************/
// Include header file that defines the fonts loaded, the TFT drivers
// available and the pins to be used, etc, etc
@ -46,12 +47,14 @@
#undef pgm_read_byte
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
#undef pgm_read_word
#define pgm_read_word(addr) ({ \
#define pgm_read_word(addr) \
({ \
typeof(addr) _addr = (addr); \
*(const unsigned short *)(_addr); \
})
#undef pgm_read_dword
#define pgm_read_dword(addr) ({ \
#define pgm_read_dword(addr) \
({ \
typeof(addr) _addr = (addr); \
*(const unsigned long *)(_addr); \
})
@ -253,7 +256,8 @@ const PROGMEM fontinfo fontdata [] = {
#define BL_DATUM 6 // Bottom left
#define BC_DATUM 7 // Bottom centre
#define BR_DATUM 8 // Bottom right
#define L_BASELINE 9 // Left character baseline (Line the 'A' character would sit on)
#define L_BASELINE \
9 // Left character baseline (Line the 'A' character would sit on)
#define C_BASELINE 10 // Centre character baseline
#define R_BASELINE 11 // Right character baseline
@ -314,13 +318,14 @@ static const uint16_t default_4bit_palette[] PROGMEM = {
/***************************************************************************************
** Section 7: Diagnostic support
***************************************************************************************/
// #define TFT_eSPI_DEBUG // Switch on debug support serial messages (not used yet)
// #define TFT_eSPI_FNx_DEBUG // Switch on debug support for function "x" (not used yet)
// #define TFT_eSPI_DEBUG // Switch on debug support serial messages (not
// used yet) #define TFT_eSPI_FNx_DEBUG // Switch on debug support for function
// "x" (not used yet)
// This structure allows sketches to retrieve the user setup parameters at runtime
// by calling getSetup(), zero impact on code size unless used, mainly for diagnostics
typedef struct
{
// This structure allows sketches to retrieve the user setup parameters at
// runtime by calling getSetup(), zero impact on code size unless used, mainly
// for diagnostics
typedef struct {
String version = TFT_ESPI_VERSION;
String setup_info; // Setup reference name available to use in a user setup
uint32_t setup_id; // ID available to use in a user setup
@ -377,41 +382,49 @@ int16_t tch_spi_freq;// Touch controller read/write SPI frequency
** Section 8: Class member and support functions
***************************************************************************************/
// Swap any type
template <typename T> static inline void
swap_coord(T& a, T& b) { T t = a; a = b; b = t; }
template <typename T>
static inline void swap_coord(T &a, T &b) {
T t = a;
a = b;
b = t;
}
// Callback prototype for smooth font pixel colour read
typedef uint16_t (*getColorCallback)(uint16_t x, uint16_t y);
// Class functions and variables
class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has access to protected members
class TFT_eSPI : public Print {
friend class TFT_eSprite; // Sprite class has access to protected members
//--------------------------------------- public ------------------------------------//
//--------------------------------------- public
//------------------------------------//
public:
TFT_eSPI(int16_t _W = TFT_WIDTH, int16_t _H = TFT_HEIGHT);
// init() and begin() are equivalent, begin() included for backwards compatibility
// Sketch defined tab colour option is for ST7735 displays only
// init() and begin() are equivalent, begin() included for backwards
// compatibility Sketch defined tab colour option is for ST7735 displays only
void init(uint8_t tc = TAB_COLOUR), begin(uint8_t tc = TAB_COLOUR);
// These are virtual so the TFT_eSprite class can override them with sprite specific functions
// These are virtual so the TFT_eSprite class can override them with sprite
// specific functions
virtual void drawPixel(int32_t x, int32_t y, uint32_t color),
drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32_t bg, uint8_t size),
drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32_t bg,
uint8_t size),
drawLine(int32_t xs, int32_t ys, int32_t xe, int32_t ye, uint32_t color),
drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color),
drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color),
fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
virtual int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font),
drawChar(uint16_t uniCode, int32_t x, int32_t y),
height(void),
virtual int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y,
uint8_t font),
drawChar(uint16_t uniCode, int32_t x, int32_t y), height(void),
width(void);
// Read the colour of a pixel at x,y and return value in 565 format
virtual uint16_t readPixel(int32_t x, int32_t y);
virtual void setWindow(int32_t xs, int32_t ys, int32_t xe, int32_t ye); // Note: start + end coordinates
virtual void setWindow(int32_t xs, int32_t ys, int32_t xe,
int32_t ye); // Note: start + end coordinates
// Push (aka write pixel) colours to the set window
virtual void pushColor(uint16_t color);
@ -420,17 +433,20 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
virtual void begin_nin_write();
virtual void end_nin_write();
void setRotation(uint8_t r); // Set the display image orientation to 0, 1, 2 or 3
void setRotation(
uint8_t r); // Set the display image orientation to 0, 1, 2 or 3
uint8_t getRotation(void); // Read the current rotation
void invertDisplay(bool i); // Tell TFT to invert all displayed colours
// The TFT_eSprite class inherits the following functions (not all are useful to Sprite class
void setAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h); // Note: start coordinates + width and height
// The TFT_eSprite class inherits the following functions (not all are useful
// to Sprite class
void setAddrWindow(int32_t xs, int32_t ys, int32_t w,
int32_t h); // Note: start coordinates + width and height
// Viewport commands, see "Viewport_Demo" sketch
void setViewport(int32_t x, int32_t y, int32_t w, int32_t h, bool vpDatum = true);
void setViewport(int32_t x, int32_t y, int32_t w, int32_t h,
bool vpDatum = true);
bool checkViewport(int32_t x, int32_t y, int32_t w, int32_t h);
int32_t getViewportX(void);
int32_t getViewportY(void);
@ -440,73 +456,99 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
void frameViewport(uint16_t color, int32_t w);
void resetViewport(void);
// Clip input window to viewport bounds, return false if whole area is out of bounds
// Clip input window to viewport bounds, return false if whole area is out of
// bounds
bool clipAddrWindow(int32_t *x, int32_t *y, int32_t *w, int32_t *h);
// Clip input window area to viewport bounds, return false if whole area is out of bounds
// Clip input window area to viewport bounds, return false if whole area is
// out of bounds
bool clipWindow(int32_t *xs, int32_t *ys, int32_t *xe, int32_t *ye);
// Push (aka write pixel) colours to the TFT (use setAddrWindow() first)
void pushColor(uint16_t color, uint32_t len), // Deprecated, use pushBlock()
pushColors(uint16_t *data, uint32_t len, bool swap = true), // With byte swap option
pushColors(uint16_t *data, uint32_t len,
bool swap = true), // With byte swap option
pushColors(uint8_t *data, uint32_t len); // Deprecated, use pushPixels()
// Write a solid block of a single colour
void pushBlock(uint16_t color, uint32_t len);
// Write a set of pixels stored in memory, use setSwapBytes(true/false) function to correct endianess
// Write a set of pixels stored in memory, use setSwapBytes(true/false)
// function to correct endianess
void pushPixels(const void *data_in, uint32_t len);
// Support for half duplex (bi-directional SDA) SPI bus where MOSI must be switched to input
// Support for half duplex (bi-directional SDA) SPI bus where MOSI must be
// switched to input
#ifdef TFT_SDA_READ
#if defined(TFT_eSPI_ENABLE_8_BIT_READ)
uint8_t tft_Read_8(void); // Read 8 bit value from TFT command register
#endif
void begin_SDA_Read(void); // Begin a read on a half duplex (bi-directional SDA) SPI bus - sets MOSI to input
void begin_SDA_Read(void); // Begin a read on a half duplex (bi-directional
// SDA) SPI bus - sets MOSI to input
void end_SDA_Read(void); // Restore MOSI to output
#endif
// Graphics drawing
void fillScreen(uint32_t color),
drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color),
drawRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color),
fillRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color);
drawRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius,
uint32_t color),
fillRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius,
uint32_t color);
void fillRectVGradient(int16_t x, int16_t y, int16_t w, int16_t h, uint32_t color1, uint32_t color2);
void fillRectHGradient(int16_t x, int16_t y, int16_t w, int16_t h, uint32_t color1, uint32_t color2);
void fillRectVGradient(int16_t x, int16_t y, int16_t w, int16_t h,
uint32_t color1, uint32_t color2);
void fillRectHGradient(int16_t x, int16_t y, int16_t w, int16_t h,
uint32_t color1, uint32_t color2);
// Draw a pixel blended with the pixel colour on the TFT or sprite, return blended colour
// If bg_color is not included the background pixel colour will be read from TFT or sprite
uint16_t drawPixel(int32_t x, int32_t y, uint32_t color, uint8_t alpha, uint32_t bg_color = 0x00FFFFFF);
// Draw a pixel blended with the pixel colour on the TFT or sprite, return
// blended colour If bg_color is not included the background pixel colour will
// be read from TFT or sprite
uint16_t drawPixel(int32_t x, int32_t y, uint32_t color, uint8_t alpha,
uint32_t bg_color = 0x00FFFFFF);
// Draw a small anti-aliased filled circle at ax,ay with radius r (uses drawWideLine)
// If bg_color is not included the background pixel colour will be read from TFT or sprite
void drawSpot(float ax, float ay, float r, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF);
// Draw a small anti-aliased filled circle at ax,ay with radius r (uses
// drawWideLine) If bg_color is not included the background pixel colour will
// be read from TFT or sprite
void drawSpot(float ax, float ay, float r, uint32_t fg_color,
uint32_t bg_color = 0x00FFFFFF);
// Draw an anti-aliased filled circle at x, y with radius r
// If bg_color is not included the background pixel colour will be read from TFT or sprite
void fillSmoothCircle(int32_t x, int32_t y, int32_t r, uint32_t color, uint32_t bg_color = 0x00FFFFFF);
// If bg_color is not included the background pixel colour will be read from
// TFT or sprite
void fillSmoothCircle(int32_t x, int32_t y, int32_t r, uint32_t color,
uint32_t bg_color = 0x00FFFFFF);
void fillSmoothRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color, uint32_t bg_color = 0x00FFFFFF);
void fillSmoothRoundRect(int32_t x, int32_t y, int32_t w, int32_t h,
int32_t radius, uint32_t color,
uint32_t bg_color = 0x00FFFFFF);
// Draw an anti-aliased wide line from ax,ay to bx,by width wd with radiused ends (radius is wd/2)
// If bg_color is not included the background pixel colour will be read from TFT or sprite
void drawWideLine(float ax, float ay, float bx, float by, float wd, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF);
// Draw an anti-aliased wide line from ax,ay to bx,by width wd with radiused
// ends (radius is wd/2) If bg_color is not included the background pixel
// colour will be read from TFT or sprite
void drawWideLine(float ax, float ay, float bx, float by, float wd,
uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF);
// Draw an anti-aliased wide line from ax,ay to bx,by with different width at each end aw, bw and with radiused ends
// If bg_color is not included the background pixel colour will be read from TFT or sprite
void drawWedgeLine(float ax, float ay, float bx, float by, float aw, float bw, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF);
// Draw an anti-aliased wide line from ax,ay to bx,by with different width at
// each end aw, bw and with radiused ends If bg_color is not included the
// background pixel colour will be read from TFT or sprite
void drawWedgeLine(float ax, float ay, float bx, float by, float aw, float bw,
uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF);
void drawCircle(int32_t x, int32_t y, int32_t r, uint32_t color),
drawCircleHelper(int32_t x, int32_t y, int32_t r, uint8_t cornername, uint32_t color),
drawCircleHelper(int32_t x, int32_t y, int32_t r, uint8_t cornername,
uint32_t color),
fillCircle(int32_t x, int32_t y, int32_t r, uint32_t color),
fillCircleHelper(int32_t x, int32_t y, int32_t r, uint8_t cornername, int32_t delta, uint32_t color),
fillCircleHelper(int32_t x, int32_t y, int32_t r, uint8_t cornername,
int32_t delta, uint32_t color),
drawEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_t color),
fillEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_t color),
// Corner 1 Corner 2 Corner 3
drawTriangle(int32_t x1,int32_t y1, int32_t x2,int32_t y2, int32_t x3,int32_t y3, uint32_t color),
fillTriangle(int32_t x1,int32_t y1, int32_t x2,int32_t y2, int32_t x3,int32_t y3, uint32_t color);
drawTriangle(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3,
int32_t y3, uint32_t color),
fillTriangle(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3,
int32_t y3, uint32_t color);
// Image rendering
// Swap the byte order for pushImage() and pushPixels() - corrects endianness
@ -514,127 +556,190 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
bool getSwapBytes(void);
// Draw bitmap
void drawBitmap( int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor),
drawBitmap( int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor, uint16_t bgcolor),
drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor),
drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor, uint16_t bgcolor),
setBitmapColor(uint16_t fgcolor, uint16_t bgcolor); // Define the 2 colours for 1bpp sprites
void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w,
int16_t h, uint16_t fgcolor),
drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w,
int16_t h, uint16_t fgcolor, uint16_t bgcolor),
drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w,
int16_t h, uint16_t fgcolor),
drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w,
int16_t h, uint16_t fgcolor, uint16_t bgcolor),
setBitmapColor(
uint16_t fgcolor,
uint16_t bgcolor); // Define the 2 colours for 1bpp sprites
// Set TFT pivot point (use when rendering rotated sprites)
void setPivot(int16_t x, int16_t y);
int16_t getPivotX(void), // Get pivot x
getPivotY(void); // Get pivot y
// 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 size must be at least w * h
// 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 size must be at least w * h
void readRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data);
// Write a block of pixels to the screen which have been read by readRect()
void pushRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data);
// These are used to render images or sprites stored in RAM arrays (used by Sprite class for 16bpp Sprites)
// These are used to render images or sprites stored in RAM arrays (used by
// Sprite class for 16bpp Sprites)
void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data);
void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data, uint16_t transparent);
void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data,
uint16_t transparent);
// These are used to render images stored in FLASH (PROGMEM)
void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data, uint16_t transparent);
void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data);
void pushImage(int32_t x, int32_t y, int32_t w, int32_t h,
const uint16_t *data, uint16_t transparent);
void pushImage(int32_t x, int32_t y, int32_t w, int32_t h,
const uint16_t *data);
// These are used by Sprite class pushSprite() member function for 1, 4 and 8 bits per pixel (bpp) colours
// They are not intended to be used with user sketches (but could be)
// Set bpp8 true for 8bpp sprites, false otherwise. The cmap pointer must be specified for 4bpp
void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data, bool bpp8 = true, uint16_t *cmap = nullptr);
void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data, uint8_t transparent, bool bpp8 = true, uint16_t *cmap = nullptr);
// These are used by Sprite class pushSprite() member function for 1, 4 and 8
// bits per pixel (bpp) colours They are not intended to be used with user
// sketches (but could be) Set bpp8 true for 8bpp sprites, false otherwise.
// The cmap pointer must be specified for 4bpp
void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data,
bool bpp8 = true, uint16_t *cmap = nullptr);
void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data,
uint8_t transparent, bool bpp8 = true,
uint16_t *cmap = nullptr);
// FLASH version
void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint8_t *data, bool bpp8, uint16_t *cmap = nullptr);
// This next function has been used successfully to dump the TFT screen to a PC for documentation purposes
// It reads a screen area and returns the 3 RGB 8 bit colour values of each pixel in the buffer
// Set w and h to 1 to read 1 pixel's colour. The data buffer must be at least w * h * 3 bytes
void pushImage(int32_t x, int32_t y, int32_t w, int32_t h,
const uint8_t *data, bool bpp8, uint16_t *cmap = nullptr);
// This next function has been used successfully to dump the TFT screen to a
// PC for documentation purposes It reads a screen area and returns the 3 RGB
// 8 bit colour values of each pixel in the buffer Set w and h to 1 to read 1
// pixel's colour. The data buffer must be at least w * h * 3 bytes
void readRectRGB(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data);
// Text rendering - value returned is the pixel width of the rendered text
int16_t drawNumber(long intNumber, int32_t x, int32_t y, uint8_t font), // Draw integer using specified font number
drawNumber(long intNumber, int32_t x, int32_t y), // Draw integer using current font
int16_t drawNumber(long intNumber, int32_t x, int32_t y,
uint8_t font), // Draw integer using specified font number
drawNumber(long intNumber, int32_t x,
int32_t y), // Draw integer using current font
// Decimal is the number of decimal places to render
// Use with setTextDatum() to position values on TFT, and setTextPadding() to blank old displayed values
drawFloat(float floatNumber, uint8_t decimal, int32_t x, int32_t y, uint8_t font), // Draw float using specified font number
drawFloat(float floatNumber, uint8_t decimal, int32_t x, int32_t y), // Draw float using current font
// Use with setTextDatum() to position values on TFT, and setTextPadding()
// to blank old displayed values
drawFloat(float floatNumber, uint8_t decimal, int32_t x, int32_t y,
uint8_t font), // Draw float using specified font number
drawFloat(float floatNumber, uint8_t decimal, int32_t x,
int32_t y), // Draw float using current font
// Handle char arrays
// Use with setTextDatum() to position string on TFT, and setTextPadding() to blank old displayed strings
drawString(const char *string, int32_t x, int32_t y, uint8_t font), // Draw string using specified font number
drawString(const char *string, int32_t x, int32_t y), // Draw string using current font
drawString(const String& string, int32_t x, int32_t y, uint8_t font),// Draw string using specified font number
drawString(const String& string, int32_t x, int32_t y), // Draw string using current font
// Use with setTextDatum() to position string on TFT, and setTextPadding()
// to blank old displayed strings
drawString(const char *string, int32_t x, int32_t y,
uint8_t font), // Draw string using specified font number
drawString(const char *string, int32_t x,
int32_t y), // Draw string using current font
drawString(const String &string, int32_t x, int32_t y,
uint8_t font), // Draw string using specified font number
drawString(const String &string, int32_t x,
int32_t y), // Draw string using current font
drawCentreString(const char *string, int32_t x, int32_t y, uint8_t font), // Deprecated, use setTextDatum() and drawString()
drawRightString(const char *string, int32_t x, int32_t y, uint8_t font), // Deprecated, use setTextDatum() and drawString()
drawCentreString(const String& string, int32_t x, int32_t y, uint8_t font),// Deprecated, use setTextDatum() and drawString()
drawRightString(const String& string, int32_t x, int32_t y, uint8_t font); // Deprecated, use setTextDatum() and drawString()
drawCentreString(
const char *string, int32_t x, int32_t y,
uint8_t font), // Deprecated, use setTextDatum() and drawString()
drawRightString(
const char *string, int32_t x, int32_t y,
uint8_t font), // Deprecated, use setTextDatum() and drawString()
drawCentreString(
const String &string, int32_t x, int32_t y,
uint8_t font), // Deprecated, use setTextDatum() and drawString()
drawRightString(
const String &string, int32_t x, int32_t y,
uint8_t font); // Deprecated, use setTextDatum() and drawString()
// Text rendering and font handling support funtions
void setCursor(int16_t x, int16_t y), // Set cursor for tft.print()
setCursor(int16_t x, int16_t y, uint8_t font); // Set cursor and font number for tft.print()
setCursor(int16_t x, int16_t y,
uint8_t font); // Set cursor and font number for tft.print()
int16_t getCursorX(void), // Read current cursor x position (moves with tft.print())
int16_t getCursorX(
void), // Read current cursor x position (moves with tft.print())
getCursorY(void); // Read current cursor y position
void setTextColor(uint16_t color), // Set character (glyph) color only (background not over-written)
setTextColor(uint16_t fgcolor, uint16_t bgcolor, bool bgfill = false), // Set character (glyph) foreground and background colour, optional background fill for smooth fonts
setTextSize(uint8_t size); // Set character size multiplier (this increases pixel size)
void setTextColor(uint16_t color), // Set character (glyph) color only
// (background not over-written)
setTextColor(uint16_t fgcolor, uint16_t bgcolor,
bool bgfill = false), // Set character (glyph) foreground
// and background colour, optional
// background fill for smooth fonts
setTextSize(uint8_t size); // Set character size multiplier (this
// increases pixel size)
void setTextWrap(bool wrapX, bool wrapY = false); // Turn on/off wrapping of text in TFT width and/or height
void setTextWrap(bool wrapX,
bool wrapY = false); // Turn on/off wrapping of text in TFT
// width and/or height
void setTextDatum(uint8_t datum); // Set text datum position (default is top left), see Section 6 above
void setTextDatum(uint8_t datum); // Set text datum position (default is top
// left), see Section 6 above
uint8_t getTextDatum(void);
void setTextPadding(uint16_t x_width); // Set text padding (background blanking/over-write) width in pixels
void setTextPadding(
uint16_t x_width); // Set text padding (background blanking/over-write)
// width in pixels
uint16_t getTextPadding(void); // Get text padding
#ifdef LOAD_GFXFF
void setFreeFont(const GFXfont *f = NULL), // Select the GFX Free Font
setTextFont(uint8_t font); // Set the font number to use in future
#else
void setFreeFont(uint8_t font), // Not used, historical fix to prevent an error
void setFreeFont(
uint8_t font), // Not used, historical fix to prevent an error
setTextFont(uint8_t font); // Set the font number to use in future
#endif
int16_t textWidth(const char *string, uint8_t font), // Returns pixel width of string in specified font
textWidth(const char *string), // Returns pixel width of string in current font
textWidth(const String& string, uint8_t font), // As above for String types
int16_t textWidth(
const char *string,
uint8_t font), // Returns pixel width of string in specified font
textWidth(
const char *string), // Returns pixel width of string in current font
textWidth(const String &string,
uint8_t font), // As above for String types
textWidth(const String &string),
fontHeight(int16_t font), // Returns pixel height of string in specified font
fontHeight(
int16_t font), // Returns pixel height of string in specified font
fontHeight(void); // Returns pixel width of string in current font
// Used by library and Smooth font class to extract Unicode point codes from a UTF8 encoded string
// Used by library and Smooth font class to extract Unicode point codes from a
// UTF8 encoded string
uint16_t decodeUTF8(uint8_t *buf, uint16_t *index, uint16_t remaining),
decodeUTF8(uint8_t c);
// Support function to UTF8 decode and draw characters piped through print stream
// Support function to UTF8 decode and draw characters piped through print
// stream
size_t write(uint8_t);
// size_t write(const uint8_t *buf, size_t len);
// Used by Smooth font class to fetch a pixel colour for the anti-aliasing
void setCallback(getColorCallback getCol);
uint16_t fontsLoaded(void); // Each bit in returned value represents a font type that is loaded - used for debug/error handling only
uint16_t fontsLoaded(
void); // Each bit in returned value represents a font type that is
// loaded - used for debug/error handling only
// Low level read/write
void spiwrite(uint8_t); // legacy support only
#ifndef RM68120_DRIVER
void writecommand(uint8_t c); // Send a command, function resets DC/RS high ready for data
void writecommand(
uint8_t c); // Send a command, function resets DC/RS high ready for data
#else
void writecommand(uint16_t c); // Send a command, function resets DC/RS high ready for data
void writeRegister(uint16_t c, uint8_t d); // Write data to 16 bit command register
void writecommand(
uint16_t c); // Send a command, function resets DC/RS high ready for data
void writeRegister(uint16_t c,
uint8_t d); // Write data to 16 bit command register
#endif
void writedata(uint8_t d); // Send data with DC/RS set high
void commandList(const uint8_t *addr); // Send a initialisation sequence to TFT stored in FLASH
uint8_t readcommand8( uint8_t cmd_function, uint8_t index = 0); // read 8 bits from TFT
uint16_t readcommand16(uint8_t cmd_function, uint8_t index = 0); // read 16 bits from TFT
uint32_t readcommand32(uint8_t cmd_function, uint8_t index = 0); // read 32 bits from TFT
void commandList(const uint8_t *addr); // Send a initialisation sequence to
// TFT stored in FLASH
uint8_t readcommand8(uint8_t cmd_function,
uint8_t index = 0); // read 8 bits from TFT
uint16_t readcommand16(uint8_t cmd_function,
uint8_t index = 0); // read 16 bits from TFT
uint32_t readcommand32(uint8_t cmd_function,
uint8_t index = 0); // read 32 bits from TFT
// Colour conversion
// Convert 8 bit red, green and blue to 16 bits
@ -654,52 +759,68 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
// alpha = 255 = 100% foreground colour
uint16_t alphaBlend(uint8_t alpha, uint16_t fgc, uint16_t bgc);
// 16 bit colour alphaBlend with alpha dither (dither reduces colour banding)
uint16_t alphaBlend(uint8_t alpha, uint16_t fgc, uint16_t bgc, uint8_t dither);
uint16_t alphaBlend(uint8_t alpha, uint16_t fgc, uint16_t bgc,
uint8_t dither);
// 24 bit colour alphaBlend with optional alpha dither
uint32_t alphaBlend24(uint8_t alpha, uint32_t fgc, uint32_t bgc, uint8_t dither = 0);
uint32_t alphaBlend24(uint8_t alpha, uint32_t fgc, uint32_t bgc,
uint8_t dither = 0);
// DMA support functions - these are currently just for SPI writes when using the ESP32 or STM32 processors
// Bear in mind DMA will only be of benefit in particular circumstances and can be tricky
// to manage by noobs. The functions have however been designed to be noob friendly and
// avoid a few DMA behaviour "gotchas".
// DMA support functions - these are currently just for SPI writes when using
// the ESP32 or STM32 processors Bear in mind DMA will only be of benefit in
// particular circumstances and can be tricky to manage by noobs. The
// functions have however been designed to be noob friendly and avoid a few
// DMA behaviour "gotchas".
//
// At best you will get a 2x TFT rendering performance improvement when using DMA because
// this library handles the SPI bus so efficiently during normal (non DMA) transfers. The best
// performance improvement scenario is the DMA transfer time is exactly the same as the time it
// takes for the processor to prepare the next image buffer and initiate another DMA transfer.
// At best you will get a 2x TFT rendering performance improvement when using
// DMA because this library handles the SPI bus so efficiently during normal
// (non DMA) transfers. The best performance improvement scenario is the DMA
// transfer time is exactly the same as the time it takes for the processor to
// prepare the next image buffer and initiate another DMA transfer.
//
// DMA transfer to the TFT is done while the processor moves on to handle other tasks. Bear
// this in mind and watch out for "gotchas" like the image buffer going out of scope as the
// processor leaves a function or its content being changed while the DMA engine is reading it.
// DMA transfer to the TFT is done while the processor moves on to handle
// other tasks. Bear this in mind and watch out for "gotchas" like the image
// buffer going out of scope as the processor leaves a function or its content
// being changed while the DMA engine is reading it.
//
// The compiler MAY change the implied scope of a buffer which has been set aside by creating
// an array. For example a buffer defined before a "for-next" loop may get de-allocated when
// the loop ends. To avoid this use, for example, malloc() and free() to take control of when
// the buffer space is available and ensure it is not released until DMA is complete.
// The compiler MAY change the implied scope of a buffer which has been set
// aside by creating an array. For example a buffer defined before a
// "for-next" loop may get de-allocated when the loop ends. To avoid this use,
// for example, malloc() and free() to take control of when the buffer space
// is available and ensure it is not released until DMA is complete.
//
// Clearly you should not modify a buffer that is being DMA'ed to the TFT until the DMA is over.
// Use the dmaBusy() function to check this. Use tft.startWrite() before invoking DMA so the
// TFT chip select stays low. If you use tft.endWrite() before DMA is complete then the endWrite
// function will wait for the DMA to complete, so this may defeat any DMA performance benefit.
// Clearly you should not modify a buffer that is being DMA'ed to the TFT
// until the DMA is over. Use the dmaBusy() function to check this. Use
// tft.startWrite() before invoking DMA so the TFT chip select stays low. If
// you use tft.endWrite() before DMA is complete then the endWrite function
// will wait for the DMA to complete, so this may defeat any DMA performance
// benefit.
//
bool initDMA(bool ctrl_cs = false); // Initialise the DMA engine and attach to SPI bus - typically used in setup()
// Parameter "true" enables DMA engine control of TFT chip select (ESP32 only)
// For ESP32 only, TFT reads will not work if parameter is true
void deInitDMA(void); // De-initialise the DMA engine and detach from SPI bus - typically not used
bool initDMA(
bool ctrl_cs =
false); // Initialise the DMA engine and attach to SPI bus -
// typically used in setup() Parameter "true" enables DMA
// engine control of TFT chip select (ESP32 only) For ESP32
// only, TFT reads will not work if parameter is true
void deInitDMA(void); // De-initialise the DMA engine and detach from SPI bus
// - typically not used
// Push an image to the TFT using DMA, buffer is optional and grabs (double buffers) a copy of the image
// Use the buffer if the image data will get over-written or destroyed while DMA is in progress
// If swapping colour bytes is defined, and the double buffer option is NOT used, then the bytes
// in the original data image will be swapped by the function before DMA is initiated.
// The function will wait for the last DMA to complete if it is called while a previous DMA is still
// in progress, this simplifies the sketch and helps avoid "gotchas".
void pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t* data, uint16_t* buffer = nullptr);
// Push an image to the TFT using DMA, buffer is optional and grabs (double
// buffers) a copy of the image Use the buffer if the image data will get
// over-written or destroyed while DMA is in progress If swapping colour bytes
// is defined, and the double buffer option is NOT used, then the bytes in the
// original data image will be swapped by the function before DMA is
// initiated. The function will wait for the last DMA to complete if it is
// called while a previous DMA is still in progress, this simplifies the
// sketch and helps avoid "gotchas".
void pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data,
uint16_t *buffer = nullptr);
#if defined(ESP32) // ESP32 only at the moment
// For case where pointer is a const and the image data must not be modified (clipped or byte swapped)
void pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t const* data);
// For case where pointer is a const and the image data must not be modified
// (clipped or byte swapped)
void pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h,
uint16_t const *data);
#endif
// Push a block of pixels into a window set up using setAddrWindow()
void pushPixelsDMA(uint16_t *image, uint32_t len);
@ -717,19 +838,22 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
void endWrite(void); // End SPI transaction
// Set/get an arbitrary library configuration attribute or option
// Use to switch ON/OFF capabilities such as UTF8 decoding - each attribute has a unique ID
// id = 0: reserved - may be used in future to reset all attributes to a default state
// id = 1: Turn on (a=true) or off (a=false) GLCD cp437 font character error correction
// id = 2: Turn on (a=true) or off (a=false) UTF8 decoding
// id = 3: Enable or disable use of ESP32 PSRAM (if available)
// Use to switch ON/OFF capabilities such as UTF8 decoding - each
// attribute has a unique ID id = 0: reserved - may be used in future to
// reset all attributes to a default state id = 1: Turn on (a=true) or
// off (a=false) GLCD cp437 font character error correction id = 2: Turn
// on (a=true) or off (a=false) UTF8 decoding id = 3: Enable or disable
// use of ESP32 PSRAM (if available)
#define CP437_SWITCH 1
#define UTF8_SWITCH 2
#define PSRAM_ENABLE 3
void setAttribute(uint8_t id = 0, uint8_t a = 0); // Set attribute value
uint8_t getAttribute(uint8_t id = 0); // Get attribute value
// Used for diagnostic sketch to see library setup adopted by compiler, see Section 7 above
void getSetup(setup_t& tft_settings); // Sketch provides the instance to populate
// Used for diagnostic sketch to see library setup adopted by compiler, see
// Section 7 above
void getSetup(
setup_t &tft_settings); // Sketch provides the instance to populate
bool verifySetupID(uint32_t id);
// Global variables
@ -737,7 +861,8 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
uint32_t textcolor, textbgcolor; // Text foreground and background colours
uint32_t bitmap_fg, bitmap_bg; // Bitmap foreground (bit=1) and background (bit=0) colours
uint32_t bitmap_fg,
bitmap_bg; // Bitmap foreground (bit=1) and background (bit=0) colours
uint8_t textfont, // Current selected font number
textsize, // Current font size multiplier
@ -747,7 +872,8 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
uint8_t decoderState = 0; // UTF8 decoder state - not for user access
uint16_t decoderBuffer; // Unicode code-point buffer - not for user access
//--------------------------------------- private ------------------------------------//
//--------------------------------------- private
//------------------------------------//
private:
// Legacy begin and end prototypes - deprecated TODO: delete
void spi_begin();
@ -763,7 +889,8 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
inline void end_tft_write() __attribute__((always_inline));
// begin/end a TFT read transaction
// For SPI bus: begin lowers SPI clock rate, end reinstates transmit clock rate
// For SPI bus: begin lowers SPI clock rate, end reinstates transmit clock
// rate
inline void begin_tft_read() __attribute__((always_inline));
inline void end_tft_read() __attribute__((always_inline));
@ -785,14 +912,17 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
// Single GPIO input/output direction control
void gpioMode(uint8_t gpio, uint8_t mode);
// Helper function: calculate distance of a point from a finite length line between two points
// Helper function: calculate distance of a point from a finite length line
// between two points
float wedgeLineDistance(float pax, float pay, float bax, float bay, float dr);
// Display variant settings
uint8_t tabcolor, // ST7735 screen protector "tab" colour (now invalid)
colstart = 0, rowstart = 0; // Screen display area to CGRAM area coordinate offsets
colstart = 0,
rowstart = 0; // Screen display area to CGRAM area coordinate offsets
// Port and pin masks for control signals (ESP826 only) - TODO: remove need for this
// Port and pin masks for control signals (ESP826 only) - TODO: remove need
// for this
volatile uint32_t *dcport, *csport;
uint32_t cspinmask, dcpinmask, wrpinmask, sclkpinmask;
@ -801,30 +931,36 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
uint32_t xclr_mask, xdir_mask; // Port set/clear and direction control masks
// Lookup table for ESP32 parallel bus interface uses 1kbyte RAM,
uint32_t xset_mask[256]; // Makes Sprite rendering test 33% faster, for slower macro equivalent
// see commented out #define set_mask(C) within TFT_eSPI_ESP32.h
uint32_t xset_mask[256]; // Makes Sprite rendering test 33% faster, for
// slower macro equivalent see commented out #define
// set_mask(C) within TFT_eSPI_ESP32.h
#endif
//uint32_t lastColor = 0xFFFF; // Last colour - used to minimise bit shifting overhead
// uint32_t lastColor = 0xFFFF; // Last colour - used to minimise bit shifting
// overhead
getColorCallback getColor = nullptr; // Smooth font callback function pointer
bool locked, inTransaction, lockTransaction; // SPI transaction and mutex lock flags
bool locked, inTransaction,
lockTransaction; // SPI transaction and mutex lock flags
//-------------------------------------- protected ----------------------------------//
//-------------------------------------- protected
//----------------------------------//
protected:
// int32_t win_xe, win_ye; // Window end coords - not needed
int32_t _init_width, _init_height; // Display w/h as input, used by setRotation()
int32_t _init_width,
_init_height; // Display w/h as input, used by setRotation()
int32_t _width, _height; // Display w/h as modified by current rotation
int32_t addr_row, addr_col; // Window position - used to minimise window commands
int32_t addr_row,
addr_col; // Window position - used to minimise window commands
int16_t _xPivot; // TFT x pivot point coordinate for rotated Sprites
int16_t _yPivot; // TFT x pivot point coordinate for rotated Sprites
// Viewport variables
int32_t _vpX, _vpY, _vpW, _vpH; // Note: x start, y start, x end + 1, y end + 1
int32_t _vpX, _vpY, _vpW,
_vpH; // Note: x start, y start, x end + 1, y end + 1
int32_t _xDatum;
int32_t _yDatum;
int32_t _xWidth;
@ -842,19 +978,23 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
glyph_bb; // Smooth font glyph delta Y (height) below baseline
bool isDigits; // adjust bounding box for numbers to reduce visual jiggling
bool textwrapX, textwrapY; // If set, 'wrap' text at right and optionally bottom edge of display
bool textwrapX, textwrapY; // If set, 'wrap' text at right and optionally
// bottom edge of display
bool _swapBytes; // Swap the byte order for TFT pushImage()
bool _booted; // init() or begin() has already run once
// User sketch manages these via set/getAttribute()
bool _cp437; // If set, use correct CP437 charset (default is ON)
bool _utf8; // If set, use UTF-8 decoder in print stream 'write()' function (default ON)
bool _psram_enable; // Enable PSRAM use for library functions (TBD) and Sprites
bool _utf8; // If set, use UTF-8 decoder in print stream 'write()' function
// (default ON)
bool _psram_enable; // Enable PSRAM use for library functions (TBD) and
// Sprites
uint32_t _lastColor; // Buffered value of last colour used
bool _fillbg; // Fill background flag (just for for smooth fonts at the moment)
bool _fillbg; // Fill background flag (just for for smooth fonts at the
// moment)
#if defined(SSD1963_DRIVER)
uint16_t Cswap; // Swap buffer for SSD1963
@ -879,7 +1019,8 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
#endif
#else
#if !defined(DISABLE_ALL_LIBRARY_WARNINGS)
#warning >>>>------>> TOUCH_CS pin not defined, TFT_eSPI touch functions will not be available!
// #warning >>>>------>> TOUCH_CS pin not defined, TFT_eSPI
// touch functions will not be available!
#endif
#endif