Skip to content

Commit dbf04d1

Browse files
authored
Surfacing screen memory allocation (#144)
1 parent 970fef3 commit dbf04d1

File tree

9 files changed

+53
-26
lines changed

9 files changed

+53
-26
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,14 @@ nanoFramework.Console.Write("This is white on black again and on 9th line");
133133

134134
> Note: You can change the default font as well, you need to provide it as a property. The Cursor positions are calculated with the largest possible character.
135135
136-
M5Core2 and Fire have SPRAM, so you can get a full screen buffer as well. Refer to the [Graphics samples](https://github.com/nanoframework/Samples#graphics-for-screens) to understand all you can do with it.
136+
M5Core2 and Fire have PSRAM, so you can get a full screen buffer as well. Refer to the [Graphics samples](https://github.com/nanoframework/Samples#graphics-for-screens) to understand all you can do with it.
137+
138+
If you have intensive graphic need with any of the M5Stack, you can adjust the memory requested. While both M5Core2 and Fire have PSRAM and can accommodate very large amount like 2 Mb or more, the ones without cannot go more than few Kb or tens of Kb.
139+
140+
```csharp
141+
// This will allocate 2 Mb of memory for the graphics
142+
M5Core2.InitializeScreen(2 * 1024 * 1024);
143+
```
137144

138145
### Buttons
139146

nanoFramework.Fire/Fire.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,15 @@ public static Buzzer Buzzer
122122
/// <summary>
123123
/// Gets the screen.
124124
/// </summary>
125+
/// <param name="memoryBitMapAllocation">The memory allocation.</param>
125126
/// <remarks>The screen initialization takes a little bit of time, if you need the screen consider using it as early as possible in your code.</remarks>
126-
public static void InitializeScreen()
127+
public static void InitializeScreen(int memoryBitMapAllocation = Screen.DefaultMemoryAllocationBitmap)
127128
{
128129
// If the screen is not needed, it's not going to be created
129130
// Note: initialization may take a little bit of time
130131
if (_screen == null)
131132
{
132-
_screen = new();
133+
_screen = new(memoryBitMapAllocation);
133134
Console.Font = Resource.GetFont(Resource.FontResources.consolas_regular_16);
134135
}
135136
}

nanoFramework.Fire/Screen.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ namespace nanoFramework.M5Stack
1111
/// </summary>
1212
public class Screen : ScreenBase
1313
{
14+
/// <summary>
15+
/// Default memory allocation
16+
/// </summary>
17+
public const int DefaultMemoryAllocationBitmap = 320 * 240 * 4;
18+
1419
private const int ChipSelect = 14;
1520
private const int DataCommand = 27;
1621
private const int Reset = 33;
@@ -19,18 +24,15 @@ public class Screen : ScreenBase
1924
/// <summary>
2025
/// Initializes the screen
2126
/// </summary>
22-
public Screen()
27+
/// <param name="memoryBitMapAllocation">The memory allocation.</param>
28+
public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap)
2329
{
2430
if (_isInitialized)
2531
{
2632
return;
2733
}
2834

29-
#if M5CORE2 || FIRE
30-
MemoryAllocationBitmap = 2 * 1024 * 1024;
31-
#else
32-
MemoryAllocationBitmap = 1024;
33-
#endif
35+
MemoryAllocationBitmap = memoryBitMapAllocation;
3436
BackLightPin = 32;
3537
Controller = new();
3638
Controller.OpenPin(BackLightPin, PinMode.Output);

nanoFramework.M5Core/M5Core.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,15 @@ public static Buzzer Buzzer
9595
/// <summary>
9696
/// Gets the screen.
9797
/// </summary>
98+
/// <param name="memoryBitMapAllocation">The memory allocation.</param>
9899
/// <remarks>The screen initialization takes a little bit of time, if you need the screen consider using it as early as possible in your code.</remarks>
99-
public static void InitializeScreen()
100+
public static void InitializeScreen(int memoryBitMapAllocation = Screen.DefaultMemoryAllocationBitmap)
100101
{
101102
// If the screen is not needed, it's not going to be created
102103
// Note: initialization may take a little bit of time
103104
if (_screen == null)
104105
{
105-
_screen = new();
106+
_screen = new(memoryBitMapAllocation);
106107
#if M5CORE2
107108
Console.Font = Resource.GetFont(Resource.FontResources.consolas_regular_16);
108109
#else

nanoFramework.M5Core/Screen.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ namespace nanoFramework.M5Stack
1111
/// </summary>
1212
public class Screen : ScreenBase
1313
{
14+
/// <summary>
15+
/// Default memory allocation
16+
/// </summary>
17+
public const int DefaultMemoryAllocationBitmap = 1024;
18+
1419
private const int ChipSelect = 14;
1520
private const int DataCommand = 27;
1621
private const int Reset = 33;
@@ -19,18 +24,15 @@ public class Screen : ScreenBase
1924
/// <summary>
2025
/// Initializes the screen
2126
/// </summary>
22-
public Screen()
27+
/// <param name="memoryBitMapAllocation">The memory allocation.</param>
28+
public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap)
2329
{
2430
if (_isInitialized)
2531
{
2632
return;
2733
}
2834

29-
#if M5CORE2 || FIRE
30-
MemoryAllocationBitmap = 2 * 1024 * 1024;
31-
#else
32-
MemoryAllocationBitmap = 1024;
33-
#endif
35+
MemoryAllocationBitmap = memoryBitMapAllocation;
3436
BackLightPin = 32;
3537
Controller = new();
3638
Controller.OpenPin(BackLightPin, PinMode.Output);

nanoFramework.M5Core2/M5Core2.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,15 @@ public static Ft6xx6x TouchController
101101
/// <summary>
102102
/// Gets the screen.
103103
/// </summary>
104+
/// <param name="memoryBitMapAllocation">The memory allocation.</param>
104105
/// <remarks>The screen initialization takes a little bit of time, if you need the screen consider using it as early as possible in your code.</remarks>
105-
public static void InitializeScreen()
106+
public static void InitializeScreen(int memoryBitMapAllocation = Screen.DefaultMemoryAllocationBitmap)
106107
{
107108
// If the screen is not needed, it's not going to be created
108109
// Note: initialization may take a little bit of time
109110
if (_screen == null)
110111
{
111-
_screen = new();
112+
_screen = new(memoryBitMapAllocation);
112113
Console.Font = Resource.GetFont(Resource.FontResources.consolas_regular_16);
113114
_touchController = new(I2cDevice.Create(new I2cConnectionSettings(1, Ft6xx6x.DefaultI2cAddress)));
114115
_touchController.SetInterruptMode(false);

nanoFramework.M5Core2/Screen.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ namespace nanoFramework.M5Stack
1515
/// </summary>
1616
public class Screen : ScreenBase
1717
{
18+
/// <summary>
19+
/// Default memory allocation
20+
/// </summary>
21+
public const int DefaultMemoryAllocationBitmap = 320 * 240 * 4;
22+
1823
private const int ChipSelect = 5;
1924
private const int DataCommand = 15;
2025
private const int Reset = -1;
@@ -25,15 +30,16 @@ public class Screen : ScreenBase
2530
/// <summary>
2631
/// Initializes the screen
2732
/// </summary>
28-
public Screen()
33+
/// <param name="memoryBitMapAllocation">The memory allocation.</param>
34+
public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap)
2935
{
3036
if (_isInitialized)
3137
{
3238
return;
3339
}
3440

3541
// We're allocating anough memory for the full screen as this is a SPRAM board
36-
MemoryAllocationBitmap = 320 * 240 * 4;
42+
MemoryAllocationBitmap = memoryBitMapAllocation;
3743
BackLightPin = -1;
3844
_power = M5Stack.M5Core2.Power;
3945
// Enable the screen

nanoFramework.M5StickCommon/M5StickCBase.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,15 @@ static M5StickCPlus()
222222
/// <summary>
223223
/// Gets the screen.
224224
/// </summary>
225+
/// <param name="memoryBitMapAllocation">The memory allocation.</param>
225226
/// <remarks>The screen initialization takes a little bit of time, if you need the screen consider using it as early as possible in your code.</remarks>
226-
public static void InitializeScreen()
227+
public static void InitializeScreen(int memoryBitMapAllocation = Screen.DefaultMemoryAllocationBitmap)
227228
{
228229
// If the screen is not needed, it's not going to be created
229230
// Note: initialization may take a little bit of time
230231
if (_screen == null)
231232
{
232-
_screen = new();
233+
_screen = new(memoryBitMapAllocation);
233234
Console.Font = Resources.GetFont(Resources.FontResources.consolas_regular_8);
234235
}
235236
}

nanoFramework.M5StickCommon/Screen.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,30 @@ namespace nanoFramework.M5Stack
1313
/// </summary>
1414
public class Screen : ScreenBase
1515
{
16+
/// <summary>
17+
/// Default memory allocation
18+
/// </summary>
19+
public const int DefaultMemoryAllocationBitmap = 1024;
20+
1621
private const int ChipSelect = 5;
1722
private const int DataCommand = 23;
1823
private const int Reset = 18;
1924
private static Axp192 _power;
2025
private static int _lumi;
2126
private static bool _isInitialized = false;
22-
27+
2328
/// <summary>
2429
/// Initializes the screen
2530
/// </summary>
26-
public Screen()
31+
/// <param name="memoryBitMapAllocation">The memory allocation.</param>
32+
public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap)
2733
{
2834
if (_isInitialized)
2935
{
3036
return;
3137
}
3238

33-
MemoryAllocationBitmap = 1024;
39+
MemoryAllocationBitmap = memoryBitMapAllocation;
3440
// Not used in Stick versions, AXP is doing this
3541
BackLightPin = -1;
3642
#if M5STICKC

0 commit comments

Comments
 (0)