diff --git a/README.md b/README.md index 571dca1c..432d72cf 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,14 @@ nanoFramework.Console.Write("This is white on black again and on 9th line"); > 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. -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. +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. + +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. + +```csharp +// This will allocate 2 Mb of memory for the graphics +M5Core2.InitializeScreen(2 * 1024 * 1024); +``` ### Buttons diff --git a/nanoFramework.Fire/Fire.cs b/nanoFramework.Fire/Fire.cs index cfd8e840..9102d3a8 100644 --- a/nanoFramework.Fire/Fire.cs +++ b/nanoFramework.Fire/Fire.cs @@ -122,14 +122,15 @@ public static Buzzer Buzzer /// /// Gets the screen. /// + /// The memory allocation. /// The screen initialization takes a little bit of time, if you need the screen consider using it as early as possible in your code. - public static void InitializeScreen() + public static void InitializeScreen(int memoryBitMapAllocation = Screen.DefaultMemoryAllocationBitmap) { // If the screen is not needed, it's not going to be created // Note: initialization may take a little bit of time if (_screen == null) { - _screen = new(); + _screen = new(memoryBitMapAllocation); Console.Font = Resource.GetFont(Resource.FontResources.consolas_regular_16); } } diff --git a/nanoFramework.Fire/Screen.cs b/nanoFramework.Fire/Screen.cs index 4c74ea9e..b2440354 100644 --- a/nanoFramework.Fire/Screen.cs +++ b/nanoFramework.Fire/Screen.cs @@ -11,6 +11,11 @@ namespace nanoFramework.M5Stack /// public class Screen : ScreenBase { + /// + /// Default memory allocation + /// + public const int DefaultMemoryAllocationBitmap = 320 * 240 * 4; + private const int ChipSelect = 14; private const int DataCommand = 27; private const int Reset = 33; @@ -19,18 +24,15 @@ public class Screen : ScreenBase /// /// Initializes the screen /// - public Screen() + /// The memory allocation. + public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap) { if (_isInitialized) { return; } -#if M5CORE2 || FIRE - MemoryAllocationBitmap = 2 * 1024 * 1024; -#else - MemoryAllocationBitmap = 1024; -#endif + MemoryAllocationBitmap = memoryBitMapAllocation; BackLightPin = 32; Controller = new(); Controller.OpenPin(BackLightPin, PinMode.Output); diff --git a/nanoFramework.M5Core/M5Core.cs b/nanoFramework.M5Core/M5Core.cs index ea4a32bf..c9c22af4 100644 --- a/nanoFramework.M5Core/M5Core.cs +++ b/nanoFramework.M5Core/M5Core.cs @@ -95,14 +95,15 @@ public static Buzzer Buzzer /// /// Gets the screen. /// + /// The memory allocation. /// The screen initialization takes a little bit of time, if you need the screen consider using it as early as possible in your code. - public static void InitializeScreen() + public static void InitializeScreen(int memoryBitMapAllocation = Screen.DefaultMemoryAllocationBitmap) { // If the screen is not needed, it's not going to be created // Note: initialization may take a little bit of time if (_screen == null) { - _screen = new(); + _screen = new(memoryBitMapAllocation); #if M5CORE2 Console.Font = Resource.GetFont(Resource.FontResources.consolas_regular_16); #else diff --git a/nanoFramework.M5Core/Screen.cs b/nanoFramework.M5Core/Screen.cs index 4c74ea9e..46a55c3f 100644 --- a/nanoFramework.M5Core/Screen.cs +++ b/nanoFramework.M5Core/Screen.cs @@ -11,6 +11,11 @@ namespace nanoFramework.M5Stack /// public class Screen : ScreenBase { + /// + /// Default memory allocation + /// + public const int DefaultMemoryAllocationBitmap = 1024; + private const int ChipSelect = 14; private const int DataCommand = 27; private const int Reset = 33; @@ -19,18 +24,15 @@ public class Screen : ScreenBase /// /// Initializes the screen /// - public Screen() + /// The memory allocation. + public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap) { if (_isInitialized) { return; } -#if M5CORE2 || FIRE - MemoryAllocationBitmap = 2 * 1024 * 1024; -#else - MemoryAllocationBitmap = 1024; -#endif + MemoryAllocationBitmap = memoryBitMapAllocation; BackLightPin = 32; Controller = new(); Controller.OpenPin(BackLightPin, PinMode.Output); diff --git a/nanoFramework.M5Core2/M5Core2.cs b/nanoFramework.M5Core2/M5Core2.cs index b6a11c58..49fe15c8 100644 --- a/nanoFramework.M5Core2/M5Core2.cs +++ b/nanoFramework.M5Core2/M5Core2.cs @@ -101,14 +101,15 @@ public static Ft6xx6x TouchController /// /// Gets the screen. /// + /// The memory allocation. /// The screen initialization takes a little bit of time, if you need the screen consider using it as early as possible in your code. - public static void InitializeScreen() + public static void InitializeScreen(int memoryBitMapAllocation = Screen.DefaultMemoryAllocationBitmap) { // If the screen is not needed, it's not going to be created // Note: initialization may take a little bit of time if (_screen == null) { - _screen = new(); + _screen = new(memoryBitMapAllocation); Console.Font = Resource.GetFont(Resource.FontResources.consolas_regular_16); _touchController = new(I2cDevice.Create(new I2cConnectionSettings(1, Ft6xx6x.DefaultI2cAddress))); _touchController.SetInterruptMode(false); diff --git a/nanoFramework.M5Core2/Screen.cs b/nanoFramework.M5Core2/Screen.cs index 20a177d9..d67df78c 100644 --- a/nanoFramework.M5Core2/Screen.cs +++ b/nanoFramework.M5Core2/Screen.cs @@ -15,6 +15,11 @@ namespace nanoFramework.M5Stack /// public class Screen : ScreenBase { + /// + /// Default memory allocation + /// + public const int DefaultMemoryAllocationBitmap = 320 * 240 * 4; + private const int ChipSelect = 5; private const int DataCommand = 15; private const int Reset = -1; @@ -25,7 +30,8 @@ public class Screen : ScreenBase /// /// Initializes the screen /// - public Screen() + /// The memory allocation. + public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap) { if (_isInitialized) { @@ -33,7 +39,7 @@ public Screen() } // We're allocating anough memory for the full screen as this is a SPRAM board - MemoryAllocationBitmap = 320 * 240 * 4; + MemoryAllocationBitmap = memoryBitMapAllocation; BackLightPin = -1; _power = M5Stack.M5Core2.Power; // Enable the screen diff --git a/nanoFramework.M5StickCommon/M5StickCBase.cs b/nanoFramework.M5StickCommon/M5StickCBase.cs index 0de77c7e..56a3ca7f 100644 --- a/nanoFramework.M5StickCommon/M5StickCBase.cs +++ b/nanoFramework.M5StickCommon/M5StickCBase.cs @@ -222,14 +222,15 @@ static M5StickCPlus() /// /// Gets the screen. /// + /// The memory allocation. /// The screen initialization takes a little bit of time, if you need the screen consider using it as early as possible in your code. - public static void InitializeScreen() + public static void InitializeScreen(int memoryBitMapAllocation = Screen.DefaultMemoryAllocationBitmap) { // If the screen is not needed, it's not going to be created // Note: initialization may take a little bit of time if (_screen == null) { - _screen = new(); + _screen = new(memoryBitMapAllocation); Console.Font = Resources.GetFont(Resources.FontResources.consolas_regular_8); } } diff --git a/nanoFramework.M5StickCommon/Screen.cs b/nanoFramework.M5StickCommon/Screen.cs index 37b7e039..015521df 100644 --- a/nanoFramework.M5StickCommon/Screen.cs +++ b/nanoFramework.M5StickCommon/Screen.cs @@ -13,24 +13,30 @@ namespace nanoFramework.M5Stack /// public class Screen : ScreenBase { + /// + /// Default memory allocation + /// + public const int DefaultMemoryAllocationBitmap = 1024; + private const int ChipSelect = 5; private const int DataCommand = 23; private const int Reset = 18; private static Axp192 _power; private static int _lumi; private static bool _isInitialized = false; - + /// /// Initializes the screen /// - public Screen() + /// The memory allocation. + public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap) { if (_isInitialized) { return; } - MemoryAllocationBitmap = 1024; + MemoryAllocationBitmap = memoryBitMapAllocation; // Not used in Stick versions, AXP is doing this BackLightPin = -1; #if M5STICKC