Skip to content

Commit 4ed38fe

Browse files
authored
Activated setPsram() support for Sprites
Activated setPsram() support for Sprites
2 parents 1d62f63 + 6de3d73 commit 4ed38fe

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

src/utility/Sprite.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ TFT_eSprite::TFT_eSprite(TFT_eSPI *tft) {
3838
this->cursor_y = this->cursor_x = 0; // Text cursor position
3939
}
4040

41+
/**************************************************************************************\
42+
** Function name: setPsram
43+
** Description: Enable/disable psram for the current sprite
44+
\**************************************************************************************/
45+
46+
void TFT_eSprite::setPsram( bool enable )
47+
{
48+
_usePsram = enable;
49+
}
50+
51+
52+
4153
/***************************************************************************************
4254
** Function name: createSprite
4355
** Description: Create a sprite (bitmap) of defined width and height
@@ -96,23 +108,21 @@ void *TFT_eSprite::callocSprite(int16_t w, int16_t h, uint8_t frames) {
96108
uint8_t *ptr8 = NULL;
97109

98110
if (_bpp == 16) {
99-
#if defined(ESP32) && defined(CONFIG_SPIRAM_SUPPORT)
100111
if (psramFound() && _usePsram)
101112
ptr8 = (uint8_t *)ps_calloc(w * h + 1, sizeof(uint16_t));
102113
else
103-
#endif
104-
ptr8 = (uint8_t *)calloc(w * h + 1, sizeof(uint16_t));
114+
// Since it's a M5Core2, disabled psram for this sprite **is** a user choice,
115+
// using heap_caps_calloc instead of calloc prevents auto assignation to psram
116+
ptr8 = (uint8_t *)heap_caps_calloc(w * h + 1, sizeof(uint16_t), MALLOC_CAP_8BIT);
105117
}
106-
107118
else if (_bpp == 8) {
108-
#if defined(ESP32) && defined(CONFIG_SPIRAM_SUPPORT)
109119
if (psramFound() && _usePsram)
110120
ptr8 = (uint8_t *)ps_calloc(w * h + 1, sizeof(uint8_t));
111121
else
112-
#endif
113-
ptr8 = (uint8_t *)calloc(w * h + 1, sizeof(uint8_t));
122+
// Since it's a M5Core2, disabled psram for this sprite **is** a user choice,
123+
// using heap_caps_calloc instead of calloc prevents auto assignation to psram
124+
ptr8 = (uint8_t *)heap_caps_calloc(w * h + 1, sizeof(uint8_t), MALLOC_CAP_8BIT);
114125
}
115-
116126
else // Must be 1 bpp
117127
{
118128
//_dwidth Display width+height in pixels always in rotation 0 orientation
@@ -127,13 +137,13 @@ void *TFT_eSprite::callocSprite(int16_t w, int16_t h, uint8_t frames) {
127137

128138
if (frames > 2) frames = 2; // Currently restricted to 2 frame buffers
129139
if (frames < 1) frames = 1;
130-
#if defined(ESP32) && defined(CONFIG_SPIRAM_SUPPORT)
131140
if (psramFound() && _usePsram)
132141
ptr8 =
133142
(uint8_t *)ps_calloc(frames * (w >> 3) * h + frames, sizeof(uint8_t));
134143
else
135-
#endif
136-
ptr8 = (uint8_t *)calloc(frames * (w >> 3) * h + frames, sizeof(uint8_t));
144+
// Since it's a M5Core2, disabled psram for this sprite **is** a user choice,
145+
// using heap_caps_calloc instead of calloc prevents auto assignation to psram
146+
ptr8 = (uint8_t *)heap_caps_calloc(frames * (w >> 3) * h + frames, sizeof(uint8_t), MALLOC_CAP_8BIT);
137147
}
138148

139149
return ptr8;
@@ -512,7 +522,7 @@ uint16_t TFT_eSprite::readPixel(int32_t x, int32_t y) {
512522

513523
/***************************************************************************************
514524
** Function name: pushImage
515-
** Description: push 565 colour image into a defined area of a sprite
525+
** Description: push 565 colour image into a defined area of a sprite
516526
*************************************************************************************x*/
517527
void TFT_eSprite::pushImage(int32_t x, int32_t y, int32_t w, int32_t h,
518528
uint16_t *data) {

0 commit comments

Comments
 (0)