Skip to content

Commit 4fd9ffc

Browse files
authored
Add ESP32_C6 missing graphics (#2988)
1 parent b564781 commit 4fd9ffc

File tree

6 files changed

+132
-12
lines changed

6 files changed

+132
-12
lines changed

targets/ESP32/CMakePresets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@
293293
"API_nanoFramework.Device.Bluetooth": "ON",
294294
"API_nanoFramework.Networking.Thread": "ON",
295295
"THREAD_DEVICE_TYPE": "FTD",
296+
"API_nanoFramework.Graphics": "ON",
296297
"GRAPHICS_DISPLAY": "Generic_SPI.cpp",
297298
"TOUCHPANEL_DEVICE": "XPT2046.cpp",
298299
"GRAPHICS_DISPLAY_INTERFACE": "Spi_To_Display.cpp",
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
#ifndef GRAPHICS_MEMORY_SETUP_
7+
#define GRAPHICS_MEMORY_SETUP_
8+
9+
#include <nanoPAL.h>
10+
#include <target_platform.h>
11+
#include <esp32_idf.h>
12+
#include <Esp32_DeviceMapping.h>
13+
#include <GraphicsMemoryHeap.h>
14+
15+
struct GraphicsMemory g_GraphicsMemory;
16+
17+
// Choosing Integrate RAM into ESP32 memory map from CONFIG_SPIRAM_USE.
18+
// This is the most basic option for external SPI RAM integration
19+
// During the ESP IDF start-up, external RAM is mapped into the data address space,
20+
// starting at address 0x3F800000 (byte - accessible).
21+
// The length of this region is the same as the SPI RAM size(up to the limit of 4 MB).
22+
23+
// Applications can manually place data in external memory by creating pointers to this region.
24+
// So if an application uses external memory, it is responsible for all management of the external SPI RAM.
25+
// coordinating buffer usage, preventing corruption, etc.
26+
27+
static CLR_UINT8 *heapStartingAddress = 0;
28+
static CLR_UINT8 *heapEndingAddress = 0;
29+
30+
bool GraphicsMemory::GraphicsHeapLocation(
31+
CLR_UINT32 requested,
32+
CLR_UINT8 *&graphicsStartingAddress,
33+
CLR_UINT8 *&graphicsEndingAddress)
34+
{
35+
// requesting 2MB
36+
CLR_INT32 graphicsMemoryBlockSize = 2 * 1024 * 1024;
37+
38+
CLR_INT32 memoryCaps = MALLOC_CAP_8BIT | MALLOC_CAP_32BIT | MALLOC_CAP_SPIRAM;
39+
40+
if (heapStartingAddress != 0)
41+
{
42+
graphicsStartingAddress = heapStartingAddress;
43+
graphicsEndingAddress = heapEndingAddress;
44+
return true;
45+
}
46+
47+
// We don't want to allocate upfront
48+
if (requested == 0)
49+
{
50+
// We don't allocate anything here
51+
return false;
52+
}
53+
54+
// Get Largest free block in SPIRam
55+
CLR_INT32 spiramMaxSize = heap_caps_get_largest_free_block(memoryCaps);
56+
if (spiramMaxSize == 0)
57+
{
58+
// No SPIRAM, try and allocate small block in normal ram to keep allocator happy for
59+
// people trying to run graphics on boards without SPIRAM
60+
// Should be able to use with small screens
61+
memoryCaps ^= MALLOC_CAP_SPIRAM;
62+
63+
spiramMaxSize = requested;
64+
}
65+
66+
if (spiramMaxSize < graphicsMemoryBlockSize) // limit the size to what is available
67+
{
68+
graphicsMemoryBlockSize = spiramMaxSize;
69+
}
70+
graphicsStartingAddress = (CLR_UINT8 *)heap_caps_malloc(graphicsMemoryBlockSize, memoryCaps);
71+
ASSERT(graphicsStartingAddress != NULL);
72+
graphicsEndingAddress = (CLR_UINT8 *)(graphicsStartingAddress + graphicsMemoryBlockSize);
73+
74+
// Save where we allocated it for restarts
75+
heapStartingAddress = graphicsStartingAddress;
76+
heapEndingAddress = graphicsEndingAddress;
77+
78+
return true;
79+
}
80+
81+
#endif // GRAPHICS_MEMORY_SETUP_
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// Copyright (c) 2017 The nanoFramework project contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
#define UNUSED(x) (void)x
7+
8+
#ifndef SPI_TO_TOUCHPANEL_H
9+
#define SPI_TO_TOUCHPANEL_H
10+
11+
#include "nanoCLR_Types.h"
12+
#include <nanoPAL.h>
13+
#include <target_platform.h>
14+
#include <esp32_idf.h>
15+
16+
#include "TouchInterface.h"
17+
18+
bool TouchInterface::Initialize()
19+
{
20+
// Setup SPI configuration
21+
22+
return true;
23+
}
24+
25+
CLR_UINT8 *TouchInterface::Write_Read(
26+
CLR_UINT8 *valuesToSend,
27+
CLR_UINT16 numberOfValuesToSend,
28+
CLR_UINT16 numberValuesExpected)
29+
{
30+
31+
UNUSED(valuesToSend);
32+
UNUSED(numberOfValuesToSend);
33+
UNUSED(numberValuesExpected);
34+
35+
return 0;
36+
}
37+
38+
#endif // SPI_TO_TOUCHPANEL_H

targets/ESP32/_IDF/esp32c6/partitions_nanoclr_16mb.csv

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
###############################################################################################################################
77
nvs, data, nvs, 0x9000, 0x6000,
88
phy_init, data, phy, 0xf000, 0x1000,
9-
# Factory area for NanoCLR - 1664k
10-
factory, app, factory, 0x10000, 0x220000,
11-
# Deployment area for Managed code 2432k
12-
deploy, data, 0x84, 0x230000, 0x260000,
9+
# Factory area for NanoCLR - 2240k
10+
factory, app, factory, 0x10000, 0x230000,
11+
# Deployment area for Managed code 2368k
12+
deploy, data, 0x84, 0x240000, 0x250000,
1313
# Config data for Network, Wireless, certificates, user data 3MB
1414
config, data, littlefs, 0x490000, 0x300000,
1515
##########################################

targets/ESP32/_IDF/esp32c6/partitions_nanoclr_4mb.csv

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
###############################################################################################################################
77
nvs, data, nvs, 0x9000, 0x6000,
88
phy_init, data, phy, 0xf000, 0x1000,
9-
# Factory area for nanoCLR - 1664k
10-
factory, app, factory, 0x10000, 0x220000,
11-
# Deployment area for Managed code 1600k
12-
deploy, data, 0x84, 0x230000, 0x190000,
9+
# Factory area for nanoCLR - 2240k
10+
factory, app, factory, 0x10000, 0x230000,
11+
# Deployment area for Managed code 1536k
12+
deploy, data, 0x84, 0x240000, 0x180000,
1313
# Config data for Network, Wireless, certificates, user data 256k
1414
config, data, littlefs, 0x3C0000, 0x40000,
1515
#################################

targets/ESP32/_IDF/esp32c6/partitions_nanoclr_8mb.csv

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
###############################################################################################################################
77
nvs, data, nvs, 0x9000, 0x6000,
88
phy_init, data, phy, 0xf000, 0x1000,
9-
# Factory area for NanoCLR - 1664k
10-
factory, app, factory, 0x10000, 0x220000,
11-
# Deployment area for Managed code 2432k
12-
deploy, data, 0x84, 0x230000, 0x260000,
9+
# Factory area for NanoCLR - 2240k
10+
factory, app, factory, 0x10000, 0x230000,
11+
# Deployment area for Managed code 2368k
12+
deploy, data, 0x84, 0x240000, 0x250000,
1313
# Config data for Network, Wireless, certificates, user data 2Mb
1414
config, data, littlefs, 0x490000, 0x200000,
1515
##########################################

0 commit comments

Comments
 (0)