acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
TFT_eSPI.h (46916B)
1 /*************************************************** 2 Arduino TFT graphics library targeted at ESP8266 3 and ESP32 based boards. 4 5 This is a stand-alone library that contains the 6 hardware driver, the graphics functions and the 7 proportional fonts. 8 9 The built-in fonts 4, 6, 7 and 8 are Run Length 10 Encoded (RLE) to reduce the FLASH footprint. 11 12 Last review/edit by Bodmer: 04/02/22 13 ****************************************************/ 14 15 // Stop fonts etc being loaded multiple times 16 #ifndef _TFT_eSPIH_ 17 #define _TFT_eSPIH_ 18 19 #define TFT_ESPI_VERSION "2.5.22" 20 21 // Bit level feature flags 22 // Bit 0 set: viewport capability 23 #define TFT_ESPI_FEATURES 1 24 25 /*************************************************************************************** 26 ** Section 1: Load required header files 27 ***************************************************************************************/ 28 29 //Standard support 30 #include <Arduino.h> 31 #include <Print.h> 32 #include <SPI.h> 33 34 /*************************************************************************************** 35 ** Section 2: Load library and processor specific header files 36 ***************************************************************************************/ 37 // Include header file that defines the fonts loaded, the TFT drivers 38 // available and the pins to be used, etc, etc 39 #ifdef CONFIG_TFT_eSPI_ESPIDF 40 #include "TFT_config.h" 41 #endif 42 43 // New ESP8266 board package uses ARDUINO_ARCH_ESP8266 44 // old package defined ESP8266 45 #if defined (ESP8266) 46 #ifndef ARDUINO_ARCH_ESP8266 47 #define ARDUINO_ARCH_ESP8266 48 #endif 49 #endif 50 51 // The following lines allow the user setup to be included in the sketch folder, see 52 // "Sketch_with_tft_setup" generic example. 53 #if !defined __has_include 54 #if !defined(DISABLE_ALL_LIBRARY_WARNINGS) 55 #warning Compiler does not support __has_include, so sketches cannot define the setup 56 #endif 57 #else 58 #if __has_include(<tft_setup.h>) 59 // Include the sketch setup file 60 #include <tft_setup.h> 61 #ifndef USER_SETUP_LOADED 62 // Prevent loading further setups 63 #define USER_SETUP_LOADED 64 #endif 65 #endif 66 #endif 67 68 #include <User_Setup_Select.h> 69 70 // Handle FLASH based storage e.g. PROGMEM 71 #if defined(ARDUINO_ARCH_RP2040) 72 #undef pgm_read_byte 73 #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) 74 #undef pgm_read_word 75 #define pgm_read_word(addr) ({ \ 76 typeof(addr) _addr = (addr); \ 77 *(const unsigned short *)(_addr); \ 78 }) 79 #undef pgm_read_dword 80 #define pgm_read_dword(addr) ({ \ 81 typeof(addr) _addr = (addr); \ 82 *(const unsigned long *)(_addr); \ 83 }) 84 #elif defined(__AVR__) 85 #include <avr/pgmspace.h> 86 #elif defined(ARDUINO_ARCH_ESP8266) || defined(ESP32) 87 #include <pgmspace.h> 88 #else 89 #ifndef PROGMEM 90 #define PROGMEM 91 #endif 92 #endif 93 94 // Include the processor specific drivers 95 #if defined(CONFIG_IDF_TARGET_ESP32S3) 96 #include "Processors/TFT_eSPI_ESP32_S3.h" 97 #elif defined(CONFIG_IDF_TARGET_ESP32C3) 98 #include "Processors/TFT_eSPI_ESP32_C3.h" 99 #elif defined (ESP32) 100 #include "Processors/TFT_eSPI_ESP32.h" 101 #elif defined (ARDUINO_ARCH_ESP8266) 102 #include "Processors/TFT_eSPI_ESP8266.h" 103 #elif defined (STM32) 104 #include "Processors/TFT_eSPI_STM32.h" 105 #elif defined(ARDUINO_ARCH_RP2040) 106 #include "Processors/TFT_eSPI_RP2040.h" 107 #else 108 #include "Processors/TFT_eSPI_Generic.h" 109 #define GENERIC_PROCESSOR 110 #endif 111 112 /*************************************************************************************** 113 ** Section 3: Interface setup 114 ***************************************************************************************/ 115 #ifndef TAB_COLOUR 116 #define TAB_COLOUR 0 117 #endif 118 119 // If the SPI frequency is not defined, set a default 120 #ifndef SPI_FREQUENCY 121 #define SPI_FREQUENCY 20000000 122 #endif 123 124 // If the SPI read frequency is not defined, set a default 125 #ifndef SPI_READ_FREQUENCY 126 #define SPI_READ_FREQUENCY 10000000 127 #endif 128 129 // Some ST7789 boards do not work with Mode 0 130 #ifndef TFT_SPI_MODE 131 #if defined(ST7789_DRIVER) || defined(ST7789_2_DRIVER) 132 #define TFT_SPI_MODE SPI_MODE3 133 #else 134 #define TFT_SPI_MODE SPI_MODE0 135 #endif 136 #endif 137 138 // If the XPT2046 SPI frequency is not defined, set a default 139 #ifndef SPI_TOUCH_FREQUENCY 140 #define SPI_TOUCH_FREQUENCY 2500000 141 #endif 142 143 #ifndef SPI_BUSY_CHECK 144 #define SPI_BUSY_CHECK 145 #endif 146 147 // If half duplex SDA mode is defined then MISO pin should be -1 148 #ifdef TFT_SDA_READ 149 #ifdef TFT_MISO 150 #if TFT_MISO != -1 151 #undef TFT_MISO 152 #define TFT_MISO -1 153 #warning TFT_MISO set to -1 154 #endif 155 #endif 156 #endif 157 158 /*************************************************************************************** 159 ** Section 4: Setup fonts 160 ***************************************************************************************/ 161 // Use GLCD font in error case where user requests a smooth font file 162 // that does not exist (this is a temporary fix to stop ESP32 reboot) 163 #ifdef SMOOTH_FONT 164 #ifndef LOAD_GLCD 165 #define LOAD_GLCD 166 #endif 167 #endif 168 169 // Only load the fonts defined in User_Setup.h (to save space) 170 // Set flag so RLE rendering code is optionally compiled 171 #ifdef LOAD_GLCD 172 #include <Fonts/glcdfont.c> 173 #endif 174 175 #ifdef LOAD_FONT2 176 #include <Fonts/Font16.h> 177 #endif 178 179 #ifdef LOAD_FONT4 180 #include <Fonts/Font32rle.h> 181 #define LOAD_RLE 182 #endif 183 184 #ifdef LOAD_FONT6 185 #include <Fonts/Font64rle.h> 186 #ifndef LOAD_RLE 187 #define LOAD_RLE 188 #endif 189 #endif 190 191 #ifdef LOAD_FONT7 192 #include <Fonts/Font7srle.h> 193 #ifndef LOAD_RLE 194 #define LOAD_RLE 195 #endif 196 #endif 197 198 #ifdef LOAD_FONT8 199 #include <Fonts/Font72rle.h> 200 #ifndef LOAD_RLE 201 #define LOAD_RLE 202 #endif 203 #elif defined LOAD_FONT8N // Optional narrower version 204 #define LOAD_FONT8 205 #include <Fonts/Font72x53rle.h> 206 #ifndef LOAD_RLE 207 #define LOAD_RLE 208 #endif 209 #endif 210 211 #ifdef LOAD_GFXFF 212 // We can include all the free fonts and they will only be built into 213 // the sketch if they are used 214 #include <Fonts/GFXFF/gfxfont.h> 215 // Call up any user custom fonts 216 #include <User_Setups/User_Custom_Fonts.h> 217 #endif // #ifdef LOAD_GFXFF 218 219 // Create a null default font in case some fonts not used (to prevent crash) 220 const uint8_t widtbl_null[1] = {0}; 221 PROGMEM const uint8_t chr_null[1] = {0}; 222 PROGMEM const uint8_t* const chrtbl_null[1] = {chr_null}; 223 224 // This is a structure to conveniently hold information on the default fonts 225 // Stores pointer to font character image address table, width table and height 226 typedef struct { 227 const uint8_t *chartbl; 228 const uint8_t *widthtbl; 229 uint8_t height; 230 uint8_t baseline; 231 } fontinfo; 232 233 // Now fill the structure 234 const PROGMEM fontinfo fontdata [] = { 235 #ifdef LOAD_GLCD 236 { (const uint8_t *)font, widtbl_null, 0, 0 }, 237 #else 238 { (const uint8_t *)chrtbl_null, widtbl_null, 0, 0 }, 239 #endif 240 // GLCD font (Font 1) does not have all parameters 241 { (const uint8_t *)chrtbl_null, widtbl_null, 8, 7 }, 242 243 #ifdef LOAD_FONT2 244 { (const uint8_t *)chrtbl_f16, widtbl_f16, chr_hgt_f16, baseline_f16}, 245 #else 246 { (const uint8_t *)chrtbl_null, widtbl_null, 0, 0 }, 247 #endif 248 249 // Font 3 current unused 250 { (const uint8_t *)chrtbl_null, widtbl_null, 0, 0 }, 251 252 #ifdef LOAD_FONT4 253 { (const uint8_t *)chrtbl_f32, widtbl_f32, chr_hgt_f32, baseline_f32}, 254 #else 255 { (const uint8_t *)chrtbl_null, widtbl_null, 0, 0 }, 256 #endif 257 258 // Font 5 current unused 259 { (const uint8_t *)chrtbl_null, widtbl_null, 0, 0 }, 260 261 #ifdef LOAD_FONT6 262 { (const uint8_t *)chrtbl_f64, widtbl_f64, chr_hgt_f64, baseline_f64}, 263 #else 264 { (const uint8_t *)chrtbl_null, widtbl_null, 0, 0 }, 265 #endif 266 267 #ifdef LOAD_FONT7 268 { (const uint8_t *)chrtbl_f7s, widtbl_f7s, chr_hgt_f7s, baseline_f7s}, 269 #else 270 { (const uint8_t *)chrtbl_null, widtbl_null, 0, 0 }, 271 #endif 272 273 #ifdef LOAD_FONT8 274 { (const uint8_t *)chrtbl_f72, widtbl_f72, chr_hgt_f72, baseline_f72} 275 #else 276 { (const uint8_t *)chrtbl_null, widtbl_null, 0, 0 } 277 #endif 278 }; 279 280 /*************************************************************************************** 281 ** Section 5: Font datum enumeration 282 ***************************************************************************************/ 283 //These enumerate the text plotting alignment (reference datum point) 284 #define TL_DATUM 0 // Top left (default) 285 #define TC_DATUM 1 // Top centre 286 #define TR_DATUM 2 // Top right 287 #define ML_DATUM 3 // Middle left 288 #define CL_DATUM 3 // Centre left, same as above 289 #define MC_DATUM 4 // Middle centre 290 #define CC_DATUM 4 // Centre centre, same as above 291 #define MR_DATUM 5 // Middle right 292 #define CR_DATUM 5 // Centre right, same as above 293 #define BL_DATUM 6 // Bottom left 294 #define BC_DATUM 7 // Bottom centre 295 #define BR_DATUM 8 // Bottom right 296 #define L_BASELINE 9 // Left character baseline (Line the 'A' character would sit on) 297 #define C_BASELINE 10 // Centre character baseline 298 #define R_BASELINE 11 // Right character baseline 299 300 /*************************************************************************************** 301 ** Section 6: Colour enumeration 302 ***************************************************************************************/ 303 // Default color definitions 304 #define TFT_BLACK 0x0000 /* 0, 0, 0 */ 305 #define TFT_NAVY 0x000F /* 0, 0, 128 */ 306 #define TFT_DARKGREEN 0x03E0 /* 0, 128, 0 */ 307 #define TFT_DARKCYAN 0x03EF /* 0, 128, 128 */ 308 #define TFT_MAROON 0x7800 /* 128, 0, 0 */ 309 #define TFT_PURPLE 0x780F /* 128, 0, 128 */ 310 #define TFT_OLIVE 0x7BE0 /* 128, 128, 0 */ 311 #define TFT_LIGHTGREY 0xD69A /* 211, 211, 211 */ 312 #define TFT_DARKGREY 0x7BEF /* 128, 128, 128 */ 313 #define TFT_BLUE 0x001F /* 0, 0, 255 */ 314 #define TFT_GREEN 0x07E0 /* 0, 255, 0 */ 315 #define TFT_CYAN 0x07FF /* 0, 255, 255 */ 316 #define TFT_RED 0xF800 /* 255, 0, 0 */ 317 #define TFT_MAGENTA 0xF81F /* 255, 0, 255 */ 318 #define TFT_YELLOW 0xFFE0 /* 255, 255, 0 */ 319 #define TFT_WHITE 0xFFFF /* 255, 255, 255 */ 320 #define TFT_ORANGE 0xFDA0 /* 255, 180, 0 */ 321 #define TFT_GREENYELLOW 0xB7E0 /* 180, 255, 0 */ 322 #define TFT_PINK 0xFE19 /* 255, 192, 203 */ //Lighter pink, was 0xFC9F 323 #define TFT_BROWN 0x9A60 /* 150, 75, 0 */ 324 #define TFT_GOLD 0xFEA0 /* 255, 215, 0 */ 325 #define TFT_SILVER 0xC618 /* 192, 192, 192 */ 326 #define TFT_SKYBLUE 0x867D /* 135, 206, 235 */ 327 #define TFT_VIOLET 0x915C /* 180, 46, 226 */ 328 329 // Next is a special 16 bit colour value that encodes to 8 bits 330 // and will then decode back to the same 16 bit value. 331 // Convenient for 8 bit and 16 bit transparent sprites. 332 #define TFT_TRANSPARENT 0x0120 // This is actually a dark green 333 334 // Default palette for 4 bit colour sprites 335 static const uint16_t default_4bit_palette[] PROGMEM = { 336 TFT_BLACK, // 0 ^ 337 TFT_BROWN, // 1 | 338 TFT_RED, // 2 | 339 TFT_ORANGE, // 3 | 340 TFT_YELLOW, // 4 Colours 0-9 follow the resistor colour code! 341 TFT_GREEN, // 5 | 342 TFT_BLUE, // 6 | 343 TFT_PURPLE, // 7 | 344 TFT_DARKGREY, // 8 | 345 TFT_WHITE, // 9 v 346 TFT_CYAN, // 10 Blue+green mix 347 TFT_MAGENTA, // 11 Blue+red mix 348 TFT_MAROON, // 12 Darker red colour 349 TFT_DARKGREEN,// 13 Darker green colour 350 TFT_NAVY, // 14 Darker blue colour 351 TFT_PINK // 15 352 }; 353 354 /*************************************************************************************** 355 ** Section 7: Diagnostic support 356 ***************************************************************************************/ 357 // #define TFT_eSPI_DEBUG // Switch on debug support serial messages (not used yet) 358 // #define TFT_eSPI_FNx_DEBUG // Switch on debug support for function "x" (not used yet) 359 360 // This structure allows sketches to retrieve the user setup parameters at runtime 361 // by calling getSetup(), zero impact on code size unless used, mainly for diagnostics 362 typedef struct 363 { 364 String version = TFT_ESPI_VERSION; 365 String setup_info; // Setup reference name available to use in a user setup 366 uint32_t setup_id; // ID available to use in a user setup 367 int32_t esp; // Processor code 368 uint8_t trans; // SPI transaction support 369 uint8_t serial; // Serial (SPI) or parallel 370 #ifndef GENERIC_PROCESSOR 371 uint8_t port; // SPI port 372 #endif 373 uint8_t overlap; // ESP8266 overlap mode 374 uint8_t interface; // Interface type 375 376 uint16_t tft_driver; // Hexadecimal code 377 uint16_t tft_width; // Rotation 0 width and height 378 uint16_t tft_height; 379 380 uint8_t r0_x_offset; // Display offsets, not all used yet 381 uint8_t r0_y_offset; 382 uint8_t r1_x_offset; 383 uint8_t r1_y_offset; 384 uint8_t r2_x_offset; 385 uint8_t r2_y_offset; 386 uint8_t r3_x_offset; 387 uint8_t r3_y_offset; 388 389 int8_t pin_tft_mosi; // SPI pins 390 int8_t pin_tft_miso; 391 int8_t pin_tft_clk; 392 int8_t pin_tft_cs; 393 394 int8_t pin_tft_dc; // Control pins 395 int8_t pin_tft_rd; 396 int8_t pin_tft_wr; 397 int8_t pin_tft_rst; 398 399 int8_t pin_tft_d0; // Parallel port pins 400 int8_t pin_tft_d1; 401 int8_t pin_tft_d2; 402 int8_t pin_tft_d3; 403 int8_t pin_tft_d4; 404 int8_t pin_tft_d5; 405 int8_t pin_tft_d6; 406 int8_t pin_tft_d7; 407 408 int8_t pin_tft_led; 409 int8_t pin_tft_led_on; 410 411 int8_t pin_tch_cs; // Touch chip select pin 412 413 int16_t tft_spi_freq;// TFT write SPI frequency 414 int16_t tft_rd_freq; // TFT read SPI frequency 415 int16_t tch_spi_freq;// Touch controller read/write SPI frequency 416 } setup_t; 417 418 /*************************************************************************************** 419 ** Section 8: Class member and support functions 420 ***************************************************************************************/ 421 422 // Callback prototype for smooth font pixel colour read 423 typedef uint16_t (*getColorCallback)(uint16_t x, uint16_t y); 424 425 // Class functions and variables 426 class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has access to protected members 427 428 //--------------------------------------- public ------------------------------------// 429 public: 430 431 TFT_eSPI(int16_t _W = TFT_WIDTH, int16_t _H = TFT_HEIGHT); 432 433 // init() and begin() are equivalent, begin() included for backwards compatibility 434 // Sketch defined tab colour option is for ST7735 displays only 435 void init(uint8_t tc = TAB_COLOUR), begin(uint8_t tc = TAB_COLOUR); 436 437 // These are virtual so the TFT_eSprite class can override them with sprite specific functions 438 virtual void drawPixel(int32_t x, int32_t y, uint32_t color), 439 drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32_t bg, uint8_t size), 440 drawLine(int32_t xs, int32_t ys, int32_t xe, int32_t ye, uint32_t color), 441 drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color), 442 drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color), 443 fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color); 444 445 virtual int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font), 446 drawChar(uint16_t uniCode, int32_t x, int32_t y), 447 height(void), 448 width(void); 449 450 // Read the colour of a pixel at x,y and return value in 565 format 451 virtual uint16_t readPixel(int32_t x, int32_t y); 452 453 virtual void setWindow(int32_t xs, int32_t ys, int32_t xe, int32_t ye); // Note: start + end coordinates 454 455 // Push (aka write pixel) colours to the set window 456 virtual void pushColor(uint16_t color); 457 458 // These are non-inlined to enable override 459 virtual void begin_nin_write(); 460 virtual void end_nin_write(); 461 462 void setRotation(uint8_t r); // Set the display image orientation to 0, 1, 2 or 3 463 uint8_t getRotation(void); // Read the current rotation 464 465 // Change the origin position from the default top left 466 // Note: setRotation, setViewport and resetViewport will revert origin to top left corner of screen/sprite 467 void setOrigin(int32_t x, int32_t y); 468 int32_t getOriginX(void); 469 int32_t getOriginY(void); 470 471 void invertDisplay(bool i); // Tell TFT to invert all displayed colours 472 473 474 // The TFT_eSprite class inherits the following functions (not all are useful to Sprite class 475 void setAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h); // Note: start coordinates + width and height 476 477 // Viewport commands, see "Viewport_Demo" sketch 478 void setViewport(int32_t x, int32_t y, int32_t w, int32_t h, bool vpDatum = true); 479 bool checkViewport(int32_t x, int32_t y, int32_t w, int32_t h); 480 int32_t getViewportX(void); 481 int32_t getViewportY(void); 482 int32_t getViewportWidth(void); 483 int32_t getViewportHeight(void); 484 bool getViewportDatum(void); 485 void frameViewport(uint16_t color, int32_t w); 486 void resetViewport(void); 487 488 // Clip input window to viewport bounds, return false if whole area is out of bounds 489 bool clipAddrWindow(int32_t* x, int32_t* y, int32_t* w, int32_t* h); 490 // Clip input window area to viewport bounds, return false if whole area is out of bounds 491 bool clipWindow(int32_t* xs, int32_t* ys, int32_t* xe, int32_t* ye); 492 493 // Push (aka write pixel) colours to the TFT (use setAddrWindow() first) 494 void pushColor(uint16_t color, uint32_t len), // Deprecated, use pushBlock() 495 pushColors(uint16_t *data, uint32_t len, bool swap = true), // With byte swap option 496 pushColors(uint8_t *data, uint32_t len); // Deprecated, use pushPixels() 497 498 // Write a solid block of a single colour 499 void pushBlock(uint16_t color, uint32_t len); 500 501 // Write a set of pixels stored in memory, use setSwapBytes(true/false) function to correct endianess 502 void pushPixels(const void * data_in, uint32_t len); 503 504 // Support for half duplex (bi-directional SDA) SPI bus where MOSI must be switched to input 505 #ifdef TFT_SDA_READ 506 #if defined (TFT_eSPI_ENABLE_8_BIT_READ) 507 uint8_t tft_Read_8(void); // Read 8 bit value from TFT command register 508 #endif 509 void begin_SDA_Read(void); // Begin a read on a half duplex (bi-directional SDA) SPI bus - sets MOSI to input 510 void end_SDA_Read(void); // Restore MOSI to output 511 #endif 512 513 514 // Graphics drawing 515 void fillScreen(uint32_t color), 516 drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color), 517 drawRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color), 518 fillRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color); 519 520 void fillRectVGradient(int16_t x, int16_t y, int16_t w, int16_t h, uint32_t color1, uint32_t color2); 521 void fillRectHGradient(int16_t x, int16_t y, int16_t w, int16_t h, uint32_t color1, uint32_t color2); 522 523 void drawCircle(int32_t x, int32_t y, int32_t r, uint32_t color), 524 drawCircleHelper(int32_t x, int32_t y, int32_t r, uint8_t cornername, uint32_t color), 525 fillCircle(int32_t x, int32_t y, int32_t r, uint32_t color), 526 fillCircleHelper(int32_t x, int32_t y, int32_t r, uint8_t cornername, int32_t delta, uint32_t color), 527 528 drawEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_t color), 529 fillEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_t color), 530 531 // Corner 1 Corner 2 Corner 3 532 drawTriangle(int32_t x1,int32_t y1, int32_t x2,int32_t y2, int32_t x3,int32_t y3, uint32_t color), 533 fillTriangle(int32_t x1,int32_t y1, int32_t x2,int32_t y2, int32_t x3,int32_t y3, uint32_t color); 534 535 536 // Smooth (anti-aliased) graphics drawing 537 // Draw a pixel blended with the background pixel colour (bg_color) specified, return blended colour 538 // If the bg_color is not specified, the background pixel colour will be read from TFT or sprite 539 uint16_t drawPixel(int32_t x, int32_t y, uint32_t color, uint8_t alpha, uint32_t bg_color = 0x00FFFFFF); 540 541 // Draw an anti-aliased (smooth) arc between start and end angles. Arc ends are anti-aliased. 542 // By default the arc is drawn with square ends unless the "roundEnds" parameter is included and set true 543 // Angle = 0 is at 6 o'clock position, 90 at 9 o'clock etc. The angles must be in range 0-360 or they will be clipped to these limits 544 // The start angle may be larger than the end angle. Arcs are always drawn clockwise from the start angle. 545 void drawSmoothArc(int32_t x, int32_t y, int32_t r, int32_t ir, uint32_t startAngle, uint32_t endAngle, uint32_t fg_color, uint32_t bg_color, bool roundEnds = false); 546 547 // As per "drawSmoothArc" except the ends of the arc are NOT anti-aliased, this facilitates dynamic arc length changes with 548 // arc segments and ensures clean segment joints. 549 // The sides of the arc are anti-aliased by default. If smoothArc is false sides will NOT be anti-aliased 550 void drawArc(int32_t x, int32_t y, int32_t r, int32_t ir, uint32_t startAngle, uint32_t endAngle, uint32_t fg_color, uint32_t bg_color, bool smoothArc = true); 551 552 // Draw an anti-aliased filled circle at x, y with radius r 553 // Note: The thickness of line is 3 pixels to reduce the visible "braiding" effect of anti-aliasing narrow lines 554 // this means the inner anti-alias zone is always at r-1 and the outer zone at r+1 555 void drawSmoothCircle(int32_t x, int32_t y, int32_t r, uint32_t fg_color, uint32_t bg_color); 556 557 // Draw an anti-aliased filled circle at x, y with radius r 558 // If bg_color is not included the background pixel colour will be read from TFT or sprite 559 void fillSmoothCircle(int32_t x, int32_t y, int32_t r, uint32_t color, uint32_t bg_color = 0x00FFFFFF); 560 561 // Draw a rounded rectangle that has a line thickness of r-ir+1 and bounding box defined by x,y and w,h 562 // The outer corner radius is r, inner corner radius is ir 563 // The inside and outside of the border are anti-aliased 564 void drawSmoothRoundRect(int32_t x, int32_t y, int32_t r, int32_t ir, int32_t w, int32_t h, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF, uint8_t quadrants = 0xF); 565 566 // Draw a filled rounded rectangle , corner radius r and bounding box defined by x,y and w,h 567 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); 568 569 // Draw a small anti-aliased filled circle at ax,ay with radius r (uses drawWideLine) 570 // If bg_color is not included the background pixel colour will be read from TFT or sprite 571 void drawSpot(float ax, float ay, float r, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF); 572 573 // Draw an anti-aliased wide line from ax,ay to bx,by width wd with radiused ends (radius is wd/2) 574 // If bg_color is not included the background pixel colour will be read from TFT or sprite 575 void drawWideLine(float ax, float ay, float bx, float by, float wd, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF); 576 577 // Draw an anti-aliased wide line from ax,ay to bx,by with different width at each end aw, bw and with radiused ends 578 // If bg_color is not included the background pixel colour will be read from TFT or sprite 579 void drawWedgeLine(float ax, float ay, float bx, float by, float aw, float bw, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF); 580 581 582 // Image rendering 583 // Swap the byte order for pushImage() and pushPixels() - corrects endianness 584 void setSwapBytes(bool swap); 585 bool getSwapBytes(void); 586 587 // Draw bitmap 588 void drawBitmap( int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor), 589 drawBitmap( int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor, uint16_t bgcolor), 590 drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor), 591 drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor, uint16_t bgcolor), 592 setBitmapColor(uint16_t fgcolor, uint16_t bgcolor); // Define the 2 colours for 1bpp sprites 593 594 // Set TFT pivot point (use when rendering rotated sprites) 595 void setPivot(int16_t x, int16_t y); 596 int16_t getPivotX(void), // Get pivot x 597 getPivotY(void); // Get pivot y 598 599 // The next functions can be used as a pair to copy screen blocks (or horizontal/vertical lines) to another location 600 // Read a block of pixels to a data buffer, buffer is 16 bit and the size must be at least w * h 601 void readRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data); 602 // Write a block of pixels to the screen which have been read by readRect() 603 void pushRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data); 604 605 // These are used to render images or sprites stored in RAM arrays (used by Sprite class for 16bpp Sprites) 606 void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data); 607 void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data, uint16_t transparent); 608 609 // These are used to render images stored in FLASH (PROGMEM) 610 void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data, uint16_t transparent); 611 void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data); 612 613 // These are used by Sprite class pushSprite() member function for 1, 4 and 8 bits per pixel (bpp) colours 614 // They are not intended to be used with user sketches (but could be) 615 // Set bpp8 true for 8bpp sprites, false otherwise. The cmap pointer must be specified for 4bpp 616 void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data, bool bpp8 = true, uint16_t *cmap = nullptr); 617 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); 618 // FLASH version 619 void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint8_t *data, bool bpp8, uint16_t *cmap = nullptr); 620 621 // Render a 16 bit colour image with a 1bpp mask 622 void pushMaskedImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *img, uint8_t *mask); 623 624 // This next function has been used successfully to dump the TFT screen to a PC for documentation purposes 625 // It reads a screen area and returns the 3 RGB 8 bit colour values of each pixel in the buffer 626 // Set w and h to 1 to read 1 pixel's colour. The data buffer must be at least w * h * 3 bytes 627 void readRectRGB(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data); 628 629 630 // Text rendering - value returned is the pixel width of the rendered text 631 int16_t drawNumber(long intNumber, int32_t x, int32_t y, uint8_t font), // Draw integer using specified font number 632 drawNumber(long intNumber, int32_t x, int32_t y), // Draw integer using current font 633 634 // Decimal is the number of decimal places to render 635 // Use with setTextDatum() to position values on TFT, and setTextPadding() to blank old displayed values 636 drawFloat(float floatNumber, uint8_t decimal, int32_t x, int32_t y, uint8_t font), // Draw float using specified font number 637 drawFloat(float floatNumber, uint8_t decimal, int32_t x, int32_t y), // Draw float using current font 638 639 // Handle char arrays 640 // Use with setTextDatum() to position string on TFT, and setTextPadding() to blank old displayed strings 641 drawString(const char *string, int32_t x, int32_t y, uint8_t font), // Draw string using specified font number 642 drawString(const char *string, int32_t x, int32_t y), // Draw string using current font 643 drawString(const String& string, int32_t x, int32_t y, uint8_t font),// Draw string using specified font number 644 drawString(const String& string, int32_t x, int32_t y), // Draw string using current font 645 646 drawCentreString(const char *string, int32_t x, int32_t y, uint8_t font), // Deprecated, use setTextDatum() and drawString() 647 drawRightString(const char *string, int32_t x, int32_t y, uint8_t font), // Deprecated, use setTextDatum() and drawString() 648 drawCentreString(const String& string, int32_t x, int32_t y, uint8_t font),// Deprecated, use setTextDatum() and drawString() 649 drawRightString(const String& string, int32_t x, int32_t y, uint8_t font); // Deprecated, use setTextDatum() and drawString() 650 651 652 // Text rendering and font handling support funtions 653 void setCursor(int16_t x, int16_t y), // Set cursor for tft.print() 654 setCursor(int16_t x, int16_t y, uint8_t font); // Set cursor and font number for tft.print() 655 656 int16_t getCursorX(void), // Read current cursor x position (moves with tft.print()) 657 getCursorY(void); // Read current cursor y position 658 659 void setTextColor(uint16_t color), // Set character (glyph) color only (background not over-written) 660 setTextColor(uint16_t fgcolor, uint16_t bgcolor, bool bgfill = false), // Set character (glyph) foreground and background colour, optional background fill for smooth fonts 661 setTextSize(uint8_t size); // Set character size multiplier (this increases pixel size) 662 663 void setTextWrap(bool wrapX, bool wrapY = false); // Turn on/off wrapping of text in TFT width and/or height 664 665 void setTextDatum(uint8_t datum); // Set text datum position (default is top left), see Section 6 above 666 uint8_t getTextDatum(void); 667 668 void setTextPadding(uint16_t x_width); // Set text padding (background blanking/over-write) width in pixels 669 uint16_t getTextPadding(void); // Get text padding 670 671 #ifdef LOAD_GFXFF 672 void setFreeFont(const GFXfont *f = NULL), // Select the GFX Free Font 673 setTextFont(uint8_t font); // Set the font number to use in future 674 #else 675 void setFreeFont(uint8_t font), // Not used, historical fix to prevent an error 676 setTextFont(uint8_t font); // Set the font number to use in future 677 #endif 678 679 int16_t textWidth(const char *string, uint8_t font), // Returns pixel width of string in specified font 680 textWidth(const char *string), // Returns pixel width of string in current font 681 textWidth(const String& string, uint8_t font), // As above for String types 682 textWidth(const String& string), 683 fontHeight(int16_t font), // Returns pixel height of string in specified font 684 fontHeight(void); // Returns pixel width of string in current font 685 686 // Used by library and Smooth font class to extract Unicode point codes from a UTF8 encoded string 687 uint16_t decodeUTF8(uint8_t *buf, uint16_t *index, uint16_t remaining), 688 decodeUTF8(uint8_t c); 689 690 // Support function to UTF8 decode and draw characters piped through print stream 691 size_t write(uint8_t); 692 // size_t write(const uint8_t *buf, size_t len); 693 694 // Used by Smooth font class to fetch a pixel colour for the anti-aliasing 695 void setCallback(getColorCallback getCol); 696 697 uint16_t fontsLoaded(void); // Each bit in returned value represents a font type that is loaded - used for debug/error handling only 698 699 700 // Low level read/write 701 void spiwrite(uint8_t); // legacy support only 702 #ifdef RM68120_DRIVER 703 void writecommand(uint16_t c); // Send a 16 bit command, function resets DC/RS high ready for data 704 void writeRegister8(uint16_t c, uint8_t d); // Write 8 bit data data to 16 bit command register 705 void writeRegister16(uint16_t c, uint16_t d); // Write 16 bit data data to 16 bit command register 706 #else 707 void writecommand(uint8_t c); // Send an 8 bit command, function resets DC/RS high ready for data 708 #endif 709 void writedata(uint8_t d); // Send data with DC/RS set high 710 711 void commandList(const uint8_t *addr); // Send a initialisation sequence to TFT stored in FLASH 712 713 uint8_t readcommand8( uint8_t cmd_function, uint8_t index = 0); // read 8 bits from TFT 714 uint16_t readcommand16(uint8_t cmd_function, uint8_t index = 0); // read 16 bits from TFT 715 uint32_t readcommand32(uint8_t cmd_function, uint8_t index = 0); // read 32 bits from TFT 716 717 718 // Colour conversion 719 // Convert 8 bit red, green and blue to 16 bits 720 uint16_t color565(uint8_t red, uint8_t green, uint8_t blue); 721 722 // Convert 8 bit colour to 16 bits 723 uint16_t color8to16(uint8_t color332); 724 // Convert 16 bit colour to 8 bits 725 uint8_t color16to8(uint16_t color565); 726 727 // Convert 16 bit colour to/from 24 bit, R+G+B concatenated into LS 24 bits 728 uint32_t color16to24(uint16_t color565); 729 uint32_t color24to16(uint32_t color888); 730 731 // Alpha blend 2 colours, see generic "alphaBlend_Test" example 732 // alpha = 0 = 100% background colour 733 // alpha = 255 = 100% foreground colour 734 inline uint16_t alphaBlend(uint8_t alpha, uint16_t fgc, uint16_t bgc); 735 // 16 bit colour alphaBlend with alpha dither (dither reduces colour banding) 736 uint16_t alphaBlend(uint8_t alpha, uint16_t fgc, uint16_t bgc, uint8_t dither); 737 // 24 bit colour alphaBlend with optional alpha dither 738 uint32_t alphaBlend24(uint8_t alpha, uint32_t fgc, uint32_t bgc, uint8_t dither = 0); 739 740 // Direct Memory Access (DMA) support functions 741 // These can be used for SPI writes when using the ESP32 (original) or STM32 processors. 742 // DMA also works on a RP2040 processor with PIO based SPI and parallel (8 and 16 bit) interfaces 743 // Bear in mind DMA will only be of benefit in particular circumstances and can be tricky 744 // to manage by noobs. The functions have however been designed to be noob friendly and 745 // avoid a few DMA behaviour "gotchas". 746 // 747 // At best you will get a 2x TFT rendering performance improvement when using DMA because 748 // this library handles the SPI bus so efficiently during normal (non DMA) transfers. The best 749 // performance improvement scenario is the DMA transfer time is exactly the same as the time it 750 // takes for the processor to prepare the next image buffer and initiate another DMA transfer. 751 // 752 // DMA transfer to the TFT is done while the processor moves on to handle other tasks. Bear 753 // this in mind and watch out for "gotchas" like the image buffer going out of scope as the 754 // processor leaves a function or its content being changed while the DMA engine is reading it. 755 // 756 // The compiler MAY change the implied scope of a buffer which has been set aside by creating 757 // an array. For example a buffer defined before a "for-next" loop may get de-allocated when 758 // the loop ends. To avoid this use, for example, malloc() and free() to take control of when 759 // the buffer space is available and ensure it is not released until DMA is complete. 760 // 761 // Clearly you should not modify a buffer that is being DMA'ed to the TFT until the DMA is over. 762 // Use the dmaBusy() function to check this. Use tft.startWrite() before invoking DMA so the 763 // TFT chip select stays low. If you use tft.endWrite() before DMA is complete then the endWrite 764 // function will wait for the DMA to complete, so this may defeat any DMA performance benefit. 765 // 766 767 bool initDMA(bool ctrl_cs = false); // Initialise the DMA engine and attach to SPI bus - typically used in setup() 768 // Parameter "true" enables DMA engine control of TFT chip select (ESP32 only) 769 // For ESP32 only, TFT reads will not work if parameter is true 770 void deInitDMA(void); // De-initialise the DMA engine and detach from SPI bus - typically not used 771 772 // Push an image to the TFT using DMA, buffer is optional and grabs (double buffers) a copy of the image 773 // Use the buffer if the image data will get over-written or destroyed while DMA is in progress 774 // 775 // Note 1: If swapping colour bytes is defined, and the double buffer option is NOT used, then the bytes 776 // in the original image buffer content will be byte swapped by the function before DMA is initiated. 777 // 778 // Note 2: If part of the image will be off screen or outside of a set viewport, then the the original 779 // image buffer content will be altered to a correctly clipped image before DMA is initiated. 780 // 781 // The function will wait for the last DMA to complete if it is called while a previous DMA is still 782 // in progress, this simplifies the sketch and helps avoid "gotchas". 783 void pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t* data, uint16_t* buffer = nullptr); 784 785 #if defined (ESP32) // ESP32 only at the moment 786 // For case where pointer is a const and the image data must not be modified (clipped or byte swapped) 787 void pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t const* data); 788 #endif 789 // Push a block of pixels into a window set up using setAddrWindow() 790 void pushPixelsDMA(uint16_t* image, uint32_t len); 791 792 // Check if the DMA is complete - use while(tft.dmaBusy); for a blocking wait 793 bool dmaBusy(void); // returns true if DMA is still in progress 794 void dmaWait(void); // wait until DMA is complete 795 796 bool DMA_Enabled = false; // Flag for DMA enabled state 797 uint8_t spiBusyCheck = 0; // Number of ESP32 transfer buffers to check 798 799 // Bare metal functions 800 void startWrite(void); // Begin SPI transaction 801 void writeColor(uint16_t color, uint32_t len); // Deprecated, use pushBlock() 802 void endWrite(void); // End SPI transaction 803 804 // Set/get an arbitrary library configuration attribute or option 805 // Use to switch ON/OFF capabilities such as UTF8 decoding - each attribute has a unique ID 806 // id = 0: reserved - may be used in future to reset all attributes to a default state 807 // id = 1: Turn on (a=true) or off (a=false) GLCD cp437 font character error correction 808 // id = 2: Turn on (a=true) or off (a=false) UTF8 decoding 809 // id = 3: Enable or disable use of ESP32 PSRAM (if available) 810 #define CP437_SWITCH 1 811 #define UTF8_SWITCH 2 812 #define PSRAM_ENABLE 3 813 void setAttribute(uint8_t id = 0, uint8_t a = 0); // Set attribute value 814 uint8_t getAttribute(uint8_t id = 0); // Get attribute value 815 816 // Used for diagnostic sketch to see library setup adopted by compiler, see Section 7 above 817 void getSetup(setup_t& tft_settings); // Sketch provides the instance to populate 818 bool verifySetupID(uint32_t id); 819 820 // Global variables 821 static SPIClass& getSPIinstance(void); // Get SPI class handle 822 823 uint32_t textcolor, textbgcolor; // Text foreground and background colours 824 825 uint32_t bitmap_fg, bitmap_bg; // Bitmap foreground (bit=1) and background (bit=0) colours 826 827 uint8_t textfont, // Current selected font number 828 textsize, // Current font size multiplier 829 textdatum, // Text reference datum 830 rotation; // Display rotation (0-3) 831 832 uint8_t decoderState = 0; // UTF8 decoder state - not for user access 833 uint16_t decoderBuffer; // Unicode code-point buffer - not for user access 834 835 //--------------------------------------- private ------------------------------------// 836 private: 837 // Legacy begin and end prototypes - deprecated TODO: delete 838 void spi_begin(); 839 void spi_end(); 840 841 void spi_begin_read(); 842 void spi_end_read(); 843 844 // New begin and end prototypes 845 // begin/end a TFT write transaction 846 // For SPI bus the transmit clock rate is set 847 inline void begin_tft_write() __attribute__((always_inline)); 848 inline void end_tft_write() __attribute__((always_inline)); 849 850 // begin/end a TFT read transaction 851 // For SPI bus: begin lowers SPI clock rate, end reinstates transmit clock rate 852 inline void begin_tft_read() __attribute__((always_inline)); 853 inline void end_tft_read() __attribute__((always_inline)); 854 855 // Initialise the data bus GPIO and hardware interfaces 856 void initBus(void); 857 858 // Temporary library development function TODO: remove need for this 859 void pushSwapBytePixels(const void* data_in, uint32_t len); 860 861 // Same as setAddrWindow but exits with CGRAM in read mode 862 void readAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h); 863 864 // Byte read prototype 865 uint8_t readByte(void); 866 867 // GPIO parallel bus input/output direction control 868 void busDir(uint32_t mask, uint8_t mode); 869 870 // Single GPIO input/output direction control 871 void gpioMode(uint8_t gpio, uint8_t mode); 872 873 // Smooth graphics helper 874 uint8_t sqrt_fraction(uint32_t num); 875 876 // Helper function: calculate distance of a point from a finite length line between two points 877 float wedgeLineDistance(float pax, float pay, float bax, float bay, float dr); 878 879 // Display variant settings 880 uint8_t tabcolor, // ST7735 screen protector "tab" colour (now invalid) 881 colstart = 0, rowstart = 0; // Screen display area to CGRAM area coordinate offsets 882 883 // Port and pin masks for control signals (ESP826 only) - TODO: remove need for this 884 volatile uint32_t *dcport, *csport; 885 uint32_t cspinmask, dcpinmask, wrpinmask, sclkpinmask; 886 887 #if defined(ESP32_PARALLEL) 888 // Bit masks for ESP32 parallel bus interface 889 uint32_t xclr_mask, xdir_mask; // Port set/clear and direction control masks 890 891 // Lookup table for ESP32 parallel bus interface uses 1kbyte RAM, 892 uint32_t xset_mask[256]; // Makes Sprite rendering test 33% faster, for slower macro equivalent 893 // see commented out #define set_mask(C) within TFT_eSPI_ESP32.h 894 #endif 895 896 //uint32_t lastColor = 0xFFFF; // Last colour - used to minimise bit shifting overhead 897 898 getColorCallback getColor = nullptr; // Smooth font callback function pointer 899 900 bool locked, inTransaction, lockTransaction; // SPI transaction and mutex lock flags 901 902 //-------------------------------------- protected ----------------------------------// 903 protected: 904 905 //int32_t win_xe, win_ye; // Window end coords - not needed 906 907 int32_t _init_width, _init_height; // Display w/h as input, used by setRotation() 908 int32_t _width, _height; // Display w/h as modified by current rotation 909 int32_t addr_row, addr_col; // Window position - used to minimise window commands 910 911 int16_t _xPivot; // TFT x pivot point coordinate for rotated Sprites 912 int16_t _yPivot; // TFT x pivot point coordinate for rotated Sprites 913 914 // Viewport variables 915 int32_t _vpX, _vpY, _vpW, _vpH; // Note: x start, y start, x end + 1, y end + 1 916 int32_t _xDatum; 917 int32_t _yDatum; 918 int32_t _xWidth; 919 int32_t _yHeight; 920 bool _vpDatum; 921 bool _vpOoB; 922 923 int32_t cursor_x, cursor_y, padX; // Text cursor x,y and padding setting 924 int32_t bg_cursor_x; // Background fill cursor 925 int32_t last_cursor_x; // Previous text cursor position when fill used 926 927 uint32_t fontsloaded; // Bit field of fonts loaded 928 929 uint8_t glyph_ab, // Smooth font glyph delta Y (height) above baseline 930 glyph_bb; // Smooth font glyph delta Y (height) below baseline 931 932 bool isDigits; // adjust bounding box for numbers to reduce visual jiggling 933 bool textwrapX, textwrapY; // If set, 'wrap' text at right and optionally bottom edge of display 934 bool _swapBytes; // Swap the byte order for TFT pushImage() 935 936 bool _booted; // init() or begin() has already run once 937 938 // User sketch manages these via set/getAttribute() 939 bool _cp437; // If set, use correct CP437 charset (default is ON) 940 bool _utf8; // If set, use UTF-8 decoder in print stream 'write()' function (default ON) 941 bool _psram_enable; // Enable PSRAM use for library functions (TBD) and Sprites 942 943 uint32_t _lastColor; // Buffered value of last colour used 944 945 bool _fillbg; // Fill background flag (just for for smooth fonts at the moment) 946 947 #if defined (SSD1963_DRIVER) 948 uint16_t Cswap; // Swap buffer for SSD1963 949 uint8_t r6, g6, b6; // RGB buffer for SSD1963 950 #endif 951 952 #ifdef LOAD_GFXFF 953 GFXfont *gfxFont; 954 #endif 955 956 /*************************************************************************************** 957 ** Section 9: TFT_eSPI class conditional extensions 958 ***************************************************************************************/ 959 // Load the Touch extension 960 #ifdef TOUCH_CS 961 #if defined (TFT_PARALLEL_8_BIT) || defined (RP2040_PIO_INTERFACE) 962 #if !defined(DISABLE_ALL_LIBRARY_WARNINGS) 963 #error >>>>------>> Touch functions not supported in 8/16 bit parallel mode or with RP2040 PIO. 964 #endif 965 #else 966 #include "Extensions/Touch.h" // Loaded if TOUCH_CS is defined by user 967 #endif 968 #else 969 #if !defined(DISABLE_ALL_LIBRARY_WARNINGS) 970 #warning >>>>------>> TOUCH_CS pin not defined, TFT_eSPI touch functions will not be available! 971 #endif 972 #endif 973 974 // Load the Anti-aliased font extension 975 #ifdef SMOOTH_FONT 976 #include "Extensions/Smooth_font.h" // Loaded if SMOOTH_FONT is defined by user 977 #endif 978 979 }; // End of class TFT_eSPI 980 981 // Swap any type 982 template <typename T> static inline void 983 transpose(T& a, T& b) { T t = a; a = b; b = t; } 984 985 /*************************************************************************************** 986 ** Section 10: Additional extension classes 987 ***************************************************************************************/ 988 // Load the Button Class 989 #include "Extensions/Button.h" 990 991 // Load the Sprite Class 992 #include "Extensions/Sprite.h" 993 994 #endif // ends #ifndef _TFT_eSPIH_