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