Skip to content

Commit fbb210a

Browse files
committed
Update Graphics_Memory.cpp code to same version for all ESP targets
1 parent 95e59c8 commit fbb210a

File tree

5 files changed

+29
-21
lines changed

5 files changed

+29
-21
lines changed

targets/ESP32/ESP32_C6/nanoCLR/nanoFramework.Graphics/Graphics_Memory.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ bool GraphicsMemory::GraphicsHeapLocation(
3232
CLR_UINT8 *&graphicsStartingAddress,
3333
CLR_UINT8 *&graphicsEndingAddress)
3434
{
35-
// requesting 2MB
36-
CLR_INT32 graphicsMemoryBlockSize = 2 * 1024 * 1024;
35+
CLR_UINT32 graphicsMemoryBlockSize = requested;
3736

3837
CLR_INT32 memoryCaps = MALLOC_CAP_8BIT | MALLOC_CAP_32BIT | MALLOC_CAP_SPIRAM;
3938

@@ -45,29 +44,32 @@ bool GraphicsMemory::GraphicsHeapLocation(
4544
}
4645

4746
// We don't want to allocate upfront
48-
if (requested == 0)
47+
if (graphicsMemoryBlockSize == 0)
4948
{
5049
// We don't allocate anything here
5150
return false;
5251
}
5352

5453
// Get Largest free block in SPIRam
55-
CLR_INT32 spiramMaxSize = heap_caps_get_largest_free_block(memoryCaps);
54+
CLR_UINT32 spiramMaxSize = heap_caps_get_largest_free_block(memoryCaps);
55+
5656
if (spiramMaxSize == 0)
5757
{
5858
// No SPIRAM, try and allocate small block in normal ram to keep allocator happy for
5959
// people trying to run graphics on boards without SPIRAM
6060
// Should be able to use with small screens
6161
memoryCaps ^= MALLOC_CAP_SPIRAM;
6262

63-
spiramMaxSize = requested;
63+
spiramMaxSize = heap_caps_get_largest_free_block(memoryCaps);
6464
}
6565

6666
if (spiramMaxSize < graphicsMemoryBlockSize) // limit the size to what is available
6767
{
6868
graphicsMemoryBlockSize = spiramMaxSize;
6969
}
70+
7071
graphicsStartingAddress = (CLR_UINT8 *)heap_caps_malloc(graphicsMemoryBlockSize, memoryCaps);
72+
7173
ASSERT(graphicsStartingAddress != NULL);
7274
graphicsEndingAddress = (CLR_UINT8 *)(graphicsStartingAddress + graphicsMemoryBlockSize);
7375

targets/ESP32/ESP32_P4/nanoCLR/nanoFramework.Graphics/Graphics_Memory.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ bool GraphicsMemory::GraphicsHeapLocation(
3232
CLR_UINT8 *&graphicsStartingAddress,
3333
CLR_UINT8 *&graphicsEndingAddress)
3434
{
35-
// requesting 2MB
36-
CLR_INT32 graphicsMemoryBlockSize = 2 * 1024 * 1024;
35+
CLR_UINT32 graphicsMemoryBlockSize = requested;
3736

3837
CLR_INT32 memoryCaps = MALLOC_CAP_8BIT | MALLOC_CAP_32BIT | MALLOC_CAP_SPIRAM;
3938

@@ -45,29 +44,32 @@ bool GraphicsMemory::GraphicsHeapLocation(
4544
}
4645

4746
// We don't want to allocate upfront
48-
if (requested == 0)
47+
if (graphicsMemoryBlockSize == 0)
4948
{
5049
// We don't allocate anything here
5150
return false;
5251
}
5352

5453
// Get Largest free block in SPIRam
55-
CLR_INT32 spiramMaxSize = heap_caps_get_largest_free_block(memoryCaps);
54+
CLR_UINT32 spiramMaxSize = heap_caps_get_largest_free_block(memoryCaps);
55+
5656
if (spiramMaxSize == 0)
5757
{
5858
// No SPIRAM, try and allocate small block in normal ram to keep allocator happy for
5959
// people trying to run graphics on boards without SPIRAM
6060
// Should be able to use with small screens
6161
memoryCaps ^= MALLOC_CAP_SPIRAM;
6262

63-
spiramMaxSize = requested;
63+
spiramMaxSize = heap_caps_get_largest_free_block(memoryCaps);
6464
}
6565

6666
if (spiramMaxSize < graphicsMemoryBlockSize) // limit the size to what is available
6767
{
6868
graphicsMemoryBlockSize = spiramMaxSize;
6969
}
70+
7071
graphicsStartingAddress = (CLR_UINT8 *)heap_caps_malloc(graphicsMemoryBlockSize, memoryCaps);
72+
7173
ASSERT(graphicsStartingAddress != NULL);
7274
graphicsEndingAddress = (CLR_UINT8 *)(graphicsStartingAddress + graphicsMemoryBlockSize);
7375

targets/ESP32/ESP32_P4/target_BlockStorage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef TARGETPAL_BLOCKSTORAGE_H
77
#define TARGETPAL_BLOCKSTORAGE_H
88

9-
// this device has 1 block storage devices
9+
// this device has 1 block storage device
1010
#define TARGET_BLOCKSTORAGE_COUNT 1
1111

1212
#endif // TARGETPAL_BLOCKSTORAGE_H

targets/ESP32/ESP32_S2/nanoCLR/nanoFramework.Graphics/Graphics_Memory.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ bool GraphicsMemory::GraphicsHeapLocation(
3232
CLR_UINT8 *&graphicsStartingAddress,
3333
CLR_UINT8 *&graphicsEndingAddress)
3434
{
35-
// requesting 2MB
36-
CLR_INT32 graphicsMemoryBlockSize = 2 * 1024 * 1024;
35+
CLR_UINT32 graphicsMemoryBlockSize = requested;
3736

3837
CLR_INT32 memoryCaps = MALLOC_CAP_8BIT | MALLOC_CAP_32BIT | MALLOC_CAP_SPIRAM;
3938

@@ -45,29 +44,32 @@ bool GraphicsMemory::GraphicsHeapLocation(
4544
}
4645

4746
// We don't want to allocate upfront
48-
if (requested == 0)
47+
if (graphicsMemoryBlockSize == 0)
4948
{
5049
// We don't allocate anything here
5150
return false;
5251
}
5352

5453
// Get Largest free block in SPIRam
55-
CLR_INT32 spiramMaxSize = heap_caps_get_largest_free_block(memoryCaps);
54+
CLR_UINT32 spiramMaxSize = heap_caps_get_largest_free_block(memoryCaps);
55+
5656
if (spiramMaxSize == 0)
5757
{
5858
// No SPIRAM, try and allocate small block in normal ram to keep allocator happy for
5959
// people trying to run graphics on boards without SPIRAM
6060
// Should be able to use with small screens
6161
memoryCaps ^= MALLOC_CAP_SPIRAM;
6262

63-
spiramMaxSize = requested;
63+
spiramMaxSize = heap_caps_get_largest_free_block(memoryCaps);
6464
}
6565

6666
if (spiramMaxSize < graphicsMemoryBlockSize) // limit the size to what is available
6767
{
6868
graphicsMemoryBlockSize = spiramMaxSize;
6969
}
70+
7071
graphicsStartingAddress = (CLR_UINT8 *)heap_caps_malloc(graphicsMemoryBlockSize, memoryCaps);
72+
7173
ASSERT(graphicsStartingAddress != NULL);
7274
graphicsEndingAddress = (CLR_UINT8 *)(graphicsStartingAddress + graphicsMemoryBlockSize);
7375

targets/ESP32/ESP32_S3/nanoCLR/nanoFramework.Graphics/Graphics_Memory.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ bool GraphicsMemory::GraphicsHeapLocation(
3232
CLR_UINT8 *&graphicsStartingAddress,
3333
CLR_UINT8 *&graphicsEndingAddress)
3434
{
35-
// requesting 2MB
36-
CLR_INT32 graphicsMemoryBlockSize = 2 * 1024 * 1024;
35+
CLR_UINT32 graphicsMemoryBlockSize = requested;
3736

3837
CLR_INT32 memoryCaps = MALLOC_CAP_8BIT | MALLOC_CAP_32BIT | MALLOC_CAP_SPIRAM;
3938

@@ -45,29 +44,32 @@ bool GraphicsMemory::GraphicsHeapLocation(
4544
}
4645

4746
// We don't want to allocate upfront
48-
if (requested == 0)
47+
if (graphicsMemoryBlockSize == 0)
4948
{
5049
// We don't allocate anything here
5150
return false;
5251
}
5352

5453
// Get Largest free block in SPIRam
55-
CLR_INT32 spiramMaxSize = heap_caps_get_largest_free_block(memoryCaps);
54+
CLR_UINT32 spiramMaxSize = heap_caps_get_largest_free_block(memoryCaps);
55+
5656
if (spiramMaxSize == 0)
5757
{
5858
// No SPIRAM, try and allocate small block in normal ram to keep allocator happy for
5959
// people trying to run graphics on boards without SPIRAM
6060
// Should be able to use with small screens
6161
memoryCaps ^= MALLOC_CAP_SPIRAM;
6262

63-
spiramMaxSize = requested;
63+
spiramMaxSize = heap_caps_get_largest_free_block(memoryCaps);
6464
}
6565

6666
if (spiramMaxSize < graphicsMemoryBlockSize) // limit the size to what is available
6767
{
6868
graphicsMemoryBlockSize = spiramMaxSize;
6969
}
70+
7071
graphicsStartingAddress = (CLR_UINT8 *)heap_caps_malloc(graphicsMemoryBlockSize, memoryCaps);
72+
7173
ASSERT(graphicsStartingAddress != NULL);
7274
graphicsEndingAddress = (CLR_UINT8 *)(graphicsStartingAddress + graphicsMemoryBlockSize);
7375

0 commit comments

Comments
 (0)