diff --git a/Extensions/Sprite.cpp b/Extensions/Sprite.cpp index 8cc0773..1d7fb77 100644 --- a/Extensions/Sprite.cpp +++ b/Extensions/Sprite.cpp @@ -39,6 +39,8 @@ TFT_eSprite::TFT_eSprite(TFT_eSPI *tft) _colorMap = nullptr; this->cursor_y = this->cursor_x = 0; // Text cursor position + + this->_psram_enable = true; } @@ -120,9 +122,8 @@ void* TFT_eSprite::callocSprite(int16_t w, int16_t h, uint8_t frames) if (_bpp == 16) { - #if defined (ESP32) && defined (CONFIG_SPIRAM_SUPPORT) - if ( psramFound() ) ptr8 = ( uint8_t*) ps_calloc(w * h + 1, sizeof(uint16_t)); + if ( psramFound() && this->_psram_enable ) ptr8 = ( uint8_t*) ps_calloc(w * h + 1, sizeof(uint16_t)); else #endif ptr8 = ( uint8_t*) calloc(w * h + 1, sizeof(uint16_t)); @@ -131,7 +132,7 @@ void* TFT_eSprite::callocSprite(int16_t w, int16_t h, uint8_t frames) else if (_bpp == 8) { #if defined (ESP32) && defined (CONFIG_SPIRAM_SUPPORT) - if ( psramFound() ) ptr8 = ( uint8_t*) ps_calloc(w * h + 1, sizeof(uint8_t)); + if ( psramFound() && this->_psram_enable ) ptr8 = ( uint8_t*) ps_calloc(w * h + 1, sizeof(uint8_t)); else #endif ptr8 = ( uint8_t*) calloc(w * h + 1, sizeof(uint8_t)); @@ -142,7 +143,7 @@ void* TFT_eSprite::callocSprite(int16_t w, int16_t h, uint8_t frames) w = (w+1) & 0xFFFE; // width needs to be multiple of 2, with an extra "off screen" pixel _iwidth = w; #if defined (ESP32) && defined (CONFIG_SPIRAM_SUPPORT) - if ( psramFound() ) ptr8 = ( uint8_t*) ps_calloc(((w * h) >> 1) + 1, sizeof(uint8_t)); + if ( psramFound() && this->_psram_enable ) ptr8 = ( uint8_t*) ps_calloc(((w * h) >> 1) + 1, sizeof(uint8_t)); else #endif ptr8 = ( uint8_t*) calloc(((w * h) >> 1) + 1, sizeof(uint8_t)); @@ -161,7 +162,7 @@ void* TFT_eSprite::callocSprite(int16_t w, int16_t h, uint8_t frames) if (frames > 2) frames = 2; // Currently restricted to 2 frame buffers if (frames < 1) frames = 1; #if defined (ESP32) && defined (CONFIG_SPIRAM_SUPPORT) - if ( psramFound() ) ptr8 = ( uint8_t*) ps_calloc(frames * (w>>3) * h + frames, sizeof(uint8_t)); + if ( psramFound() && this->_psram_enable ) ptr8 = ( uint8_t*) ps_calloc(frames * (w>>3) * h + frames, sizeof(uint8_t)); else #endif ptr8 = ( uint8_t*) calloc(frames * (w>>3) * h + frames, sizeof(uint8_t)); diff --git a/Extensions/Sprite.h b/Extensions/Sprite.h index 8c9d1dd..457f731 100644 --- a/Extensions/Sprite.h +++ b/Extensions/Sprite.h @@ -160,8 +160,8 @@ class TFT_eSprite : public TFT_eSPI { uint16_t *_colorMap; // color map: 16 entries, used with 4 bit color map. - int16_t _xpivot; // x pivot point coordinate - int16_t _ypivot; // y pivot point coordinate + int16_t _xpivot; // x pivot point coordinate + int16_t _ypivot; // y pivot point coordinate bool _created; // A Sprite has been created and memory reserved bool _gFont = false; @@ -173,7 +173,7 @@ class TFT_eSprite : public TFT_eSPI { uint32_t _sw, _sh; // w,h for scroll zone uint32_t _scolor; // gap fill colour for scroll zone - bool _iswapBytes; // Swap the byte order for Sprite pushImage() + bool _iswapBytes; // Swap the byte order for Sprite pushImage() int32_t _iwidth, _iheight; // Sprite memory image bit width and height (swapped during rotations) int32_t _dwidth, _dheight; // Real display width and height (for <8bpp Sprites) diff --git a/TFT_eSPI.cpp b/TFT_eSPI.cpp index 8244980..3e580b1 100644 --- a/TFT_eSPI.cpp +++ b/TFT_eSPI.cpp @@ -198,6 +198,12 @@ TFT_eSPI::TFT_eSPI(int16_t w, int16_t h) _cp437 = true; _utf8 = true; +#if defined (ESP32) && defined (CONFIG_SPIRAM_SUPPORT) + if (psramFound()) _psram_enable = true; // Enable the use of PSRAM (if available) + else +#endif + _psram_enable = false; + addr_row = 0xFFFF; addr_col = 0xFFFF; @@ -2989,14 +2995,21 @@ void TFT_eSPI::invertDisplay(bool i) void TFT_eSPI::setAttribute(uint8_t attr_id, uint8_t param) { switch (attr_id) { break; - case 1: + case CP437_SWITCH: _cp437 = param; break; - case 2: + case UTF8_SWITCH: _utf8 = param; decoderState = 0; break; - //case 3: // TBD future feature control + case PSRAM_ENABLE: +#if defined (ESP32) && defined (CONFIG_SPIRAM_SUPPORT) + if (psramFound()) _psram_enable = param; // Enable the use of PSRAM (if available) + else +#endif + _psram_enable = false; + break; + //case 4: // TBD future feature control // _tbd = param; // break; } @@ -3009,12 +3022,12 @@ void TFT_eSPI::setAttribute(uint8_t attr_id, uint8_t param) { **************************************************************************/ uint8_t TFT_eSPI::getAttribute(uint8_t attr_id) { switch (attr_id) { - case 1: // ON/OFF control of full CP437 character set + case CP437_SWITCH: // ON/OFF control of full CP437 character set return _cp437; - break; - case 2: // ON/OFF control of UTF-8 decoding + case UTF8_SWITCH: // ON/OFF control of UTF-8 decoding return _utf8; - break; + case PSRAM_ENABLE: + return _psram_enable; //case 3: // TBD future feature control // return _tbd; // break; diff --git a/TFT_eSPI.h b/TFT_eSPI.h index 113e2e5..4e513da 100644 --- a/TFT_eSPI.h +++ b/TFT_eSPI.h @@ -16,7 +16,7 @@ #ifndef _TFT_eSPIH_ #define _TFT_eSPIH_ -#define TFT_ESPI_VERSION "2.0.3" +#define TFT_ESPI_VERSION "2.0.4" /*************************************************************************************** ** Section 1: Load required header files @@ -629,8 +629,10 @@ class TFT_eSPI : public Print { // id = 0: reserved - may be used in fuuture to reset all attributes to a default state // id = 1: Turn on (a=true) or off (a=false) GLCD cp437 font character error correction // id = 2: Turn on (a=true) or off (a=false) UTF8 decoding + // id = 3: Enable or disable use of ESP32 PSRAM (if available) #define CP437_SWITCH 1 #define UTF8_SWITCH 2 + #define PSRAM_ENABLE 3 void setAttribute(uint8_t id = 0, uint8_t a = 0); // Set attribute value uint8_t getAttribute(uint8_t id = 0); // Get attribute value @@ -734,8 +736,9 @@ class TFT_eSPI : public Print { bool _booted; // init() or begin() has already run once // User sketch manages these via set/getAttribute() - bool _cp437; // If set, use correct CP437 charset (default is ON) - bool _utf8; // If set, use UTF-8 decoder in print stream 'write()' function (default ON) + bool _cp437; // If set, use correct CP437 charset (default is ON) + bool _utf8; // If set, use UTF-8 decoder in print stream 'write()' function (default ON) + bool _psram_enable; // Enable PSRAM use for library functions (TBD) and Sprites uint32_t _lastColor; // Buffered value of last colour used diff --git a/keywords.txt b/keywords.txt index 507b457..6f8fb9d 100644 --- a/keywords.txt +++ b/keywords.txt @@ -99,7 +99,7 @@ TFT_eSPI_Button KEYWORD1 initButton KEYWORD2 textcolor KEYWORD2 initButtonUL KEYWORD2 -setLabelDatum KEYWORD2 +setLabelDatum KEYWORD2 drawButton KEYWORD2 contains KEYWORD2 press KEYWORD2 @@ -111,6 +111,7 @@ justReleased KEYWORD2 TFT_eSprite KEYWORD1 createSprite KEYWORD2 +createPalette KEYWORD2 setColorDepth KEYWORD2 getColorDepth KEYWORD2 deleteSprite KEYWORD2 diff --git a/library.json b/library.json index 09b7503..665a409 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TFT_eSPI", - "version": "2.0.3", + "version": "2.0.4", "keywords": "Arduino, tft, ePaper, display, STM32, ESP8266, NodeMCU, ESP32, M5Stack, ILI9341, ST7735, ILI9163, S6D02A1, ILI9486, ST7789, RM68140", "description": "A TFT and ePaper SPI graphics library with optimisation for ESP8266, ESP32 and STM32", "repository": diff --git a/library.properties b/library.properties index 7ca1c51..22cb1a2 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TFT_eSPI -version=2.0.3 +version=2.0.4 author=Bodmer maintainer=Bodmer sentence=TFT graphics library for Arduino processors with performance optimisation for STM32, ESP8266 and ESP32