forked from nanoframework/Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
109 lines (87 loc) · 3.15 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
// Copyright (c) .NET Foundation and Contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//
using System;
using System.Diagnostics;
using System.Drawing;
using System.Threading;
using nanoFramework.Hardware.Esp32;
using nanoFramework.Presentation.Media;
using nanoFramework.Runtime.Native;
using nanoFramework.UI;
using nanoFramework.UI.GraphicDrivers;
namespace UsingGenericDriver
{
/// <summary>
/// You **MUST** have a build of nanoFramework with a generic graphic driver
/// </summary>
public class Program
{
private const int ChipSelect = 5;
private const int DataCommand = 23;
private const int Reset = 18;
public static void Main()
{
Debug.WriteLine("Hello from and generic grahic drivers!");
// You **MUST** have a build of nanoFramework with a generic graphic driver
// If you're using an ESP32, don't forget to set the pins for the screen
// Set the pins for the screen
Configuration.SetPinFunction(15, DeviceFunction.SPI1_MOSI);
Configuration.SetPinFunction(13, DeviceFunction.SPI1_CLOCK);
// This is not used but must be defined
Configuration.SetPinFunction(4, DeviceFunction.SPI1_MISO);
var displaySpiConfig = new SpiConfiguration(
1,
ChipSelect,
DataCommand,
Reset,
-1);
// Get the generic driver
GraphicDriver graphicDriver = St7735.GraphicDriver;
// As optional, you can adjust anything
graphicDriver.OrientationPortrait = new byte[]
{
(byte)GraphicDriverCommandType.Command, 2, 0x36, 0x88,
};
var screenConfig = new ScreenConfiguration(
26,
1,
80,
160,
graphicDriver);
var init = DisplayControl.Initialize(
displaySpiConfig,
screenConfig,
1024);
Debug.WriteLine($"Screen initialized");
ushort[] toSend = new ushort[100];
var blue = Color.Blue.ToBgr565();
var red = Color.Red.ToBgr565();
var green = Color.Green.ToBgr565();
var white = Color.White.ToBgr565();
for (int i = 0; i < toSend.Length; i++)
{
toSend[i] = blue;
}
DisplayControl.Write(0, 0, 10, 10, toSend);
for (int i = 0; i < toSend.Length; i++)
{
toSend[i] = red;
}
DisplayControl.Write(69, 0, 10, 10, toSend);
for (int i = 0; i < toSend.Length; i++)
{
toSend[i] = green;
}
DisplayControl.Write(0, 149, 10, 10, toSend);
for (int i = 0; i < toSend.Length; i++)
{
toSend[i] = white;
}
DisplayControl.Write(69, 149, 10, 10, toSend);
Thread.Sleep(Timeout.Infinite);
}
}
}