Surfacing screen memory allocation (#144)

This commit is contained in:
Laurent Ellerbach 2022-04-22 17:15:07 +02:00 коммит произвёл GitHub
Родитель 970fef34d7
Коммит dbf04d19a5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 53 добавлений и 26 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -122,14 +122,15 @@ namespace nanoFramework.M5Stack
/// <summary>
/// Gets the screen.
/// </summary>
/// <param name="memoryBitMapAllocation">The memory allocation.</param>
/// <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>
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);
}
}

Просмотреть файл

@ -11,6 +11,11 @@ namespace nanoFramework.M5Stack
/// </summary>
public class Screen : ScreenBase
{
/// <summary>
/// Default memory allocation
/// </summary>
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 @@ namespace nanoFramework.M5Stack
/// <summary>
/// Initializes the screen
/// </summary>
public Screen()
/// <param name="memoryBitMapAllocation">The memory allocation.</param>
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);

Просмотреть файл

@ -95,14 +95,15 @@ namespace nanoFramework.M5Stack
/// <summary>
/// Gets the screen.
/// </summary>
/// <param name="memoryBitMapAllocation">The memory allocation.</param>
/// <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>
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

Просмотреть файл

@ -11,6 +11,11 @@ namespace nanoFramework.M5Stack
/// </summary>
public class Screen : ScreenBase
{
/// <summary>
/// Default memory allocation
/// </summary>
public const int DefaultMemoryAllocationBitmap = 1024;
private const int ChipSelect = 14;
private const int DataCommand = 27;
private const int Reset = 33;
@ -19,18 +24,15 @@ namespace nanoFramework.M5Stack
/// <summary>
/// Initializes the screen
/// </summary>
public Screen()
/// <param name="memoryBitMapAllocation">The memory allocation.</param>
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);

Просмотреть файл

@ -101,14 +101,15 @@ namespace nanoFramework.M5Stack
/// <summary>
/// Gets the screen.
/// </summary>
/// <param name="memoryBitMapAllocation">The memory allocation.</param>
/// <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>
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);

Просмотреть файл

@ -15,6 +15,11 @@ namespace nanoFramework.M5Stack
/// </summary>
public class Screen : ScreenBase
{
/// <summary>
/// Default memory allocation
/// </summary>
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 @@ namespace nanoFramework.M5Stack
/// <summary>
/// Initializes the screen
/// </summary>
public Screen()
/// <param name="memoryBitMapAllocation">The memory allocation.</param>
public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap)
{
if (_isInitialized)
{
@ -33,7 +39,7 @@ namespace nanoFramework.M5Stack
}
// 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

Просмотреть файл

@ -222,14 +222,15 @@ namespace nanoFramework.M5Stack
/// <summary>
/// Gets the screen.
/// </summary>
/// <param name="memoryBitMapAllocation">The memory allocation.</param>
/// <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>
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);
}
}

Просмотреть файл

@ -13,24 +13,30 @@ namespace nanoFramework.M5Stack
/// </summary>
public class Screen : ScreenBase
{
/// <summary>
/// Default memory allocation
/// </summary>
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;
/// <summary>
/// Initializes the screen
/// </summary>
public Screen()
/// <param name="memoryBitMapAllocation">The memory allocation.</param>
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