Skip to content

Commit 096de85

Browse files
committed
psram for sprites is now optional (default enabled)
1 parent b94cca2 commit 096de85

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/utility/Sprite.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void* TFT_eSprite::callocSprite(int16_t w, int16_t h, uint8_t frames)
107107
{
108108

109109
#if defined (ESP32) && defined (CONFIG_SPIRAM_SUPPORT)
110-
if ( psramFound() ) ptr8 = ( uint8_t*) ps_calloc(w * h + 1, sizeof(uint16_t));
110+
if ( psramFound() && _usePsram ) ptr8 = ( uint8_t*) ps_calloc(w * h + 1, sizeof(uint16_t));
111111
else
112112
#endif
113113
ptr8 = ( uint8_t*) calloc(w * h + 1, sizeof(uint16_t));
@@ -116,7 +116,7 @@ void* TFT_eSprite::callocSprite(int16_t w, int16_t h, uint8_t frames)
116116
else if (_bpp == 8)
117117
{
118118
#if defined (ESP32) && defined (CONFIG_SPIRAM_SUPPORT)
119-
if ( psramFound() ) ptr8 = ( uint8_t*) ps_calloc(w * h + 1, sizeof(uint8_t));
119+
if ( psramFound() && _usePsram) ptr8 = ( uint8_t*) ps_calloc(w * h + 1, sizeof(uint8_t));
120120
else
121121
#endif
122122
ptr8 = ( uint8_t*) calloc(w * h + 1, sizeof(uint8_t));
@@ -135,7 +135,7 @@ void* TFT_eSprite::callocSprite(int16_t w, int16_t h, uint8_t frames)
135135
if (frames > 2) frames = 2; // Currently restricted to 2 frame buffers
136136
if (frames < 1) frames = 1;
137137
#if defined (ESP32) && defined (CONFIG_SPIRAM_SUPPORT)
138-
if ( psramFound() ) ptr8 = ( uint8_t*) ps_calloc(frames * (w>>3) * h + frames, sizeof(uint8_t));
138+
if ( psramFound() && _usePsram) ptr8 = ( uint8_t*) ps_calloc(frames * (w>>3) * h + frames, sizeof(uint8_t));
139139
else
140140
#endif
141141
ptr8 = ( uint8_t*) calloc(frames * (w>>3) * h + frames, sizeof(uint8_t));
@@ -227,6 +227,17 @@ void TFT_eSprite::deleteSprite(void)
227227
}
228228

229229

230+
231+
/***************************************************************************************
232+
** Function name: setPsram
233+
** Description: Disable psRam (only if applicable)
234+
*************************************************************************************x*/
235+
void TFT_eSprite::setPsram( bool enabled ) {
236+
_usePsram = enabled;
237+
}
238+
239+
240+
230241
/***************************************************************************************
231242
** Function name: setPivot
232243
** Description: Set the pivot point in this Sprite

src/utility/Sprite.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class TFT_eSprite : public TFT_eSPI {
109109
void printToSprite(String string);
110110
void printToSprite(char *cbuffer, uint16_t len);
111111
int16_t printToSprite(int16_t x, int16_t y, uint16_t index);
112+
void setPsram( bool enabled );
112113

113114
private:
114115

@@ -130,6 +131,7 @@ class TFT_eSprite : public TFT_eSPI {
130131

131132
bool _created; // A Sprite has been created and memory reserved
132133
bool _gFont = false;
134+
bool _usePsram = true; // use Psram if available
133135

134136
// int32_t _icursor_x, _icursor_y;
135137
uint8_t _rotation = 0;

0 commit comments

Comments
 (0)