Add PSRAM switch
Typical use to disable use of PSRAM for the sprite storage: sprite.setAttribute(PSRAM_ENABLE, false); // true to enable Minor update for recent button class update
This commit is contained in:
		
							parent
							
								
									87aca91218
								
							
						
					
					
						commit
						443be934a7
					
				|  | @ -39,6 +39,8 @@ TFT_eSprite::TFT_eSprite(TFT_eSPI *tft) | ||||||
|   _colorMap = nullptr; |   _colorMap = nullptr; | ||||||
| 
 | 
 | ||||||
|   this->cursor_y = this->cursor_x = 0; // Text cursor position
 |   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 (_bpp == 16) | ||||||
|   { |   { | ||||||
| 
 |  | ||||||
| #if defined (ESP32) && defined (CONFIG_SPIRAM_SUPPORT) | #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 |     else | ||||||
| #endif | #endif | ||||||
|     ptr8 = ( uint8_t*) calloc(w * h + 1, sizeof(uint16_t)); |     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) |   else if (_bpp == 8) | ||||||
|   { |   { | ||||||
| #if defined (ESP32) && defined (CONFIG_SPIRAM_SUPPORT) | #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 |     else | ||||||
| #endif | #endif | ||||||
|     ptr8 = ( uint8_t*) calloc(w * h + 1, sizeof(uint8_t)); |     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
 |     w = (w+1) & 0xFFFE; // width needs to be multiple of 2, with an extra "off screen" pixel
 | ||||||
|     _iwidth = w; |     _iwidth = w; | ||||||
| #if defined (ESP32) && defined (CONFIG_SPIRAM_SUPPORT) | #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 |     else | ||||||
| #endif | #endif | ||||||
|     ptr8 = ( uint8_t*) calloc(((w * h) >> 1) + 1, sizeof(uint8_t)); |     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 > 2) frames = 2; // Currently restricted to 2 frame buffers
 | ||||||
|     if (frames < 1) frames = 1; |     if (frames < 1) frames = 1; | ||||||
| #if defined (ESP32) && defined (CONFIG_SPIRAM_SUPPORT) | #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 |     else | ||||||
| #endif | #endif | ||||||
|     ptr8 = ( uint8_t*) calloc(frames * (w>>3) * h + frames, sizeof(uint8_t)); |     ptr8 = ( uint8_t*) calloc(frames * (w>>3) * h + frames, sizeof(uint8_t)); | ||||||
|  |  | ||||||
|  | @ -160,8 +160,8 @@ class TFT_eSprite : public TFT_eSPI { | ||||||
| 
 | 
 | ||||||
|   uint16_t *_colorMap; // color map: 16 entries, used with 4 bit color map.
 |   uint16_t *_colorMap; // color map: 16 entries, used with 4 bit color map.
 | ||||||
| 
 | 
 | ||||||
|   int16_t _xpivot;   // x pivot point coordinate
 |   int16_t  _xpivot;   // x pivot point coordinate
 | ||||||
|   int16_t _ypivot;   // y pivot point coordinate
 |   int16_t  _ypivot;   // y pivot point coordinate
 | ||||||
| 
 | 
 | ||||||
|   bool     _created;    // A Sprite has been created and memory reserved
 |   bool     _created;    // A Sprite has been created and memory reserved
 | ||||||
|   bool     _gFont = false;  |   bool     _gFont = false;  | ||||||
|  | @ -173,7 +173,7 @@ class TFT_eSprite : public TFT_eSPI { | ||||||
|   uint32_t _sw, _sh; // w,h for scroll zone
 |   uint32_t _sw, _sh; // w,h for scroll zone
 | ||||||
|   uint32_t _scolor;  // gap fill colour 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  _iwidth, _iheight; // Sprite memory image bit width and height (swapped during rotations)
 | ||||||
|   int32_t  _dwidth, _dheight; // Real display width and height (for <8bpp Sprites)
 |   int32_t  _dwidth, _dheight; // Real display width and height (for <8bpp Sprites)
 | ||||||
|  |  | ||||||
							
								
								
									
										27
									
								
								TFT_eSPI.cpp
								
								
								
								
							
							
						
						
									
										27
									
								
								TFT_eSPI.cpp
								
								
								
								
							|  | @ -198,6 +198,12 @@ TFT_eSPI::TFT_eSPI(int16_t w, int16_t h) | ||||||
|   _cp437    = true; |   _cp437    = true; | ||||||
|   _utf8     = 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_row = 0xFFFF; | ||||||
|   addr_col = 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) { | void TFT_eSPI::setAttribute(uint8_t attr_id, uint8_t param) { | ||||||
|     switch (attr_id) { |     switch (attr_id) { | ||||||
|             break; |             break; | ||||||
|         case 1: |         case CP437_SWITCH: | ||||||
|             _cp437 = param; |             _cp437 = param; | ||||||
|             break; |             break; | ||||||
|         case 2: |         case UTF8_SWITCH: | ||||||
|             _utf8  = param; |             _utf8  = param; | ||||||
|             decoderState = 0; |             decoderState = 0; | ||||||
|             break; |             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;
 |         //    _tbd = param;
 | ||||||
|         //    break;
 |         //    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) { | uint8_t TFT_eSPI::getAttribute(uint8_t attr_id) { | ||||||
|     switch (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; |             return _cp437; | ||||||
|             break; |         case UTF8_SWITCH: // ON/OFF control of UTF-8 decoding
 | ||||||
|         case 2: // ON/OFF control of UTF-8 decoding
 |  | ||||||
|             return _utf8; |             return _utf8; | ||||||
|             break; |         case PSRAM_ENABLE: | ||||||
|  |             return _psram_enable; | ||||||
|         //case 3: // TBD future feature control
 |         //case 3: // TBD future feature control
 | ||||||
|         //    return _tbd;
 |         //    return _tbd;
 | ||||||
|         //    break;
 |         //    break;
 | ||||||
|  |  | ||||||
|  | @ -16,7 +16,7 @@ | ||||||
| #ifndef _TFT_eSPIH_ | #ifndef _TFT_eSPIH_ | ||||||
| #define _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 | **                         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 = 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 = 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 = 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 CP437_SWITCH 1 | ||||||
|            #define UTF8_SWITCH  2 |            #define UTF8_SWITCH  2 | ||||||
|  |            #define PSRAM_ENABLE 3 | ||||||
|   void     setAttribute(uint8_t id = 0, uint8_t a = 0); // Set attribute value
 |   void     setAttribute(uint8_t id = 0, uint8_t a = 0); // Set attribute value
 | ||||||
|   uint8_t  getAttribute(uint8_t id = 0);                // Get 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
 |   bool     _booted;    // init() or begin() has already run once
 | ||||||
|    |    | ||||||
|                        // User sketch manages these via set/getAttribute()
 |                        // User sketch manages these via set/getAttribute()
 | ||||||
|   bool     _cp437;     // If set, use correct CP437 charset (default is 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     _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
 |   uint32_t _lastColor; // Buffered value of last colour used
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -99,7 +99,7 @@ TFT_eSPI_Button	KEYWORD1 | ||||||
| initButton	KEYWORD2 | initButton	KEYWORD2 | ||||||
| textcolor	KEYWORD2 | textcolor	KEYWORD2 | ||||||
| initButtonUL	KEYWORD2 | initButtonUL	KEYWORD2 | ||||||
| setLabelDatum   KEYWORD2 | setLabelDatum	KEYWORD2 | ||||||
| drawButton	KEYWORD2 | drawButton	KEYWORD2 | ||||||
| contains	KEYWORD2 | contains	KEYWORD2 | ||||||
| press	KEYWORD2 | press	KEYWORD2 | ||||||
|  | @ -111,6 +111,7 @@ justReleased	KEYWORD2 | ||||||
| TFT_eSprite	KEYWORD1 | TFT_eSprite	KEYWORD1 | ||||||
| 
 | 
 | ||||||
| createSprite	KEYWORD2 | createSprite	KEYWORD2 | ||||||
|  | createPalette	KEYWORD2 | ||||||
| setColorDepth	KEYWORD2 | setColorDepth	KEYWORD2 | ||||||
| getColorDepth	KEYWORD2 | getColorDepth	KEYWORD2 | ||||||
| deleteSprite	KEYWORD2 | deleteSprite	KEYWORD2 | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| { | { | ||||||
|   "name": "TFT_eSPI", |   "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", |   "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", |   "description": "A TFT and ePaper SPI graphics library with optimisation for ESP8266, ESP32 and STM32", | ||||||
|   "repository": |   "repository": | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| name=TFT_eSPI | name=TFT_eSPI | ||||||
| version=2.0.3 | version=2.0.4 | ||||||
| author=Bodmer | author=Bodmer | ||||||
| maintainer=Bodmer | maintainer=Bodmer | ||||||
| sentence=TFT graphics library for Arduino processors with performance optimisation for STM32, ESP8266 and ESP32 | sentence=TFT graphics library for Arduino processors with performance optimisation for STM32, ESP8266 and ESP32 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Bodmer
						Bodmer