Skip to content

Commit e7a471b

Browse files
authored
Adding managed drivers (#119)
1 parent 8654bb0 commit e7a471b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2672
-6
lines changed

ManagedDrivers/Gc9A01/Gc9A01.cs

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
4+
// See LICENSE file in the project root for full license information.
5+
//
6+
7+
namespace nanoFramework.UI.GraphicDrivers
8+
{
9+
/// <summary>
10+
/// Managed driver for GC9A01.
11+
/// </summary>
12+
public static class Gc9A01
13+
{
14+
private static GraphicDriver _driver;
15+
16+
// Those enums are left like this to match the native side
17+
private enum GC9A01_CMD
18+
{
19+
ReadDisplayInfo = 0x04,
20+
ReadDisplayStatus = 0x09,
21+
EnterSleepMode = 0x10,
22+
SleepOut = 0x11,
23+
PartialModeOn = 0x12,
24+
NormalDisplayMode = 0x13,
25+
DisplayInversionOff = 0x20,
26+
DisplayInversionOn = 0x21,
27+
DisplayOff = 0x28,
28+
DisplayOn = 0x29,
29+
ColumnAddressSet = 0x2A,
30+
PageAddressSet = 0x2B,
31+
MemoryWrite = 0x2C,
32+
PartialArea = 0x30,
33+
VerticalScrollingDefinition = 0x33,
34+
TearingEffectLineOff = 0x34,
35+
TearingEffectLineOn = 0x34,
36+
MemoryAccessControl = 0x36,
37+
VerticalScrollingStartAddress = 0x37,
38+
IdleModeOff = 0x38,
39+
IdleModeOn = 0x39,
40+
PixelFormatSet = 0x3A,
41+
WriteMemoryContinue = 0x3C,
42+
SetTearScanline = 0x44,
43+
GetScanline = 0x45,
44+
WriteDisplayBrightness = 0x51,
45+
WriteCtrlDisplay = 0x53,
46+
ReadId1 = 0xDA,
47+
ReadId2 = 0xDB,
48+
ReadId3 = 0xDC,
49+
RgbInterfaceSignalControl = 0xB0,
50+
BlankingPorchControl = 0xB5,
51+
DisplayFunctionControl = 0xB6,
52+
TeControl = 0xBA,
53+
InterfaceControl = 0xF6,
54+
PowerCriterionControl = 0xC1,
55+
VcoreVoltageControl = 0xA7,
56+
Vreg1aVoltageControl = 0xC3,
57+
Vreg2aVoltageControl = 0xC9,
58+
FrameRate = 0xE8,
59+
Spi2DataControl = 0xE9,
60+
ChargePumpFrequentControl = 0xEC,
61+
InnerRegisterEnable1 = 0xFE,
62+
InnerRegisterEnable2 = 0xEF,
63+
SetGamma1 = 0xF0,
64+
SetGamma2 = 0xF1,
65+
SetGamma3 = 0xF2,
66+
SetGamma4 = 0xF3
67+
};
68+
69+
private enum GC9A01_PIXEL_FORMAT
70+
{
71+
Pixel12Bit = 0x03,
72+
Pixel16Bit = 0x05,
73+
Pixel18Bit = 0x06
74+
};
75+
76+
private enum GC9A01_MEMORY_ACCESS_CTRL
77+
{
78+
Portrait = 0x18,
79+
Portrait180 = 0x28,
80+
Landscape = 0x48,
81+
Landscape180 = 0x88
82+
};
83+
84+
/// <summary>
85+
/// Default weight. Use to overrride the one you'll pass in the screen and add it to the driver.
86+
/// </summary>
87+
public static ushort Width { get; } = 240;
88+
89+
/// <summary>
90+
/// Default height. Use to overrride the one you'll pass in the screen and add it to the driver.
91+
/// </summary>
92+
public static ushort Height { get; } = 240;
93+
94+
/// <summary>
95+
/// Gets the graphic driver for the Gc9A01 display.
96+
/// </summary>
97+
public static GraphicDriver GraphicDriver
98+
{
99+
get
100+
{
101+
if (_driver == null)
102+
{
103+
_driver = new GraphicDriver()
104+
{
105+
MemoryWrite = (byte)GC9A01_CMD.MemoryWrite,
106+
SetColumnAddress = (byte)GC9A01_CMD.ColumnAddressSet,
107+
SetRowAddress = (byte)GC9A01_CMD.PageAddressSet,
108+
BitsPerPixel = 16,
109+
InitializationSequence = new byte[]
110+
{
111+
(byte)GraphicDriverCommandType.Command, 1, (byte)GC9A01_CMD.InnerRegisterEnable2,
112+
(byte)GraphicDriverCommandType.Command, 2, 0xEB, 0x14,
113+
(byte)GraphicDriverCommandType.Command, 1, (byte)GC9A01_CMD.InnerRegisterEnable1,
114+
(byte)GraphicDriverCommandType.Command, 1, (byte)GC9A01_CMD.InnerRegisterEnable2,
115+
(byte)GraphicDriverCommandType.Command, 2, 0xEB, 0x14,
116+
(byte)GraphicDriverCommandType.Command, 2, 0x84, 0x40,
117+
(byte)GraphicDriverCommandType.Command, 2, 0x85, 0xFF,
118+
(byte)GraphicDriverCommandType.Command, 2, 0x86, 0xFF,
119+
(byte)GraphicDriverCommandType.Command, 2, 0x87, 0xFF,
120+
(byte)GraphicDriverCommandType.Command, 2, 0x88, 0x0A,
121+
(byte)GraphicDriverCommandType.Command, 2, 0x89, 0x21,
122+
(byte)GraphicDriverCommandType.Command, 2, 0x8A, 0x00,
123+
(byte)GraphicDriverCommandType.Command, 2, 0x8B, 0x80,
124+
(byte)GraphicDriverCommandType.Command, 2, 0x8C, 0x01,
125+
(byte)GraphicDriverCommandType.Command, 2, 0x8D, 0x01,
126+
(byte)GraphicDriverCommandType.Command, 2, 0x8E, 0xFF,
127+
(byte)GraphicDriverCommandType.Command, 2, 0x8F, 0xFF,
128+
(byte)GraphicDriverCommandType.Command, 3, (byte)GC9A01_CMD.DisplayFunctionControl, 0x00, 0x20,
129+
(byte)GraphicDriverCommandType.Command, 2, (byte)GC9A01_CMD.PixelFormatSet, (byte)GC9A01_PIXEL_FORMAT.Pixel16Bit,
130+
(byte)GraphicDriverCommandType.Command, 5, 0x90, 0x08, 0x08, 0x08, 0x08,
131+
(byte)GraphicDriverCommandType.Command, 2, 0xBD, 0x06,
132+
(byte)GraphicDriverCommandType.Command, 2, 0xBC, 0x00,
133+
(byte)GraphicDriverCommandType.Command, 4, 0xFF, 0x60, 0x01, 0x04,
134+
(byte)GraphicDriverCommandType.Command, 2, (byte)GC9A01_CMD.Vreg1aVoltageControl, 0x13,
135+
(byte)GraphicDriverCommandType.Command, 2, 0xC4, 0x13,
136+
(byte)GraphicDriverCommandType.Command, 2, (byte)GC9A01_CMD.Vreg2aVoltageControl, 0x22,
137+
(byte)GraphicDriverCommandType.Command, 2, 0xBE, 0x11,
138+
(byte)GraphicDriverCommandType.Command, 3, 0xE1, 0x10, 0x0E,
139+
(byte)GraphicDriverCommandType.Command, 4, 0xDF, 0x21, 0x0C, 0x02,
140+
(byte)GraphicDriverCommandType.Command, 7, 0xF0, 0x45, 0x09, 0x08, 0x08, 0x26, 0x2A,
141+
(byte)GraphicDriverCommandType.Command, 7, 0xF1, 0x43, 0x70, 0x72, 0x36, 0x37, 0x6F,
142+
(byte)GraphicDriverCommandType.Command, 7, 0xF2, 0x45, 0x09, 0x08, 0x08, 0x26, 0x2A,
143+
(byte)GraphicDriverCommandType.Command, 7, 0xF3, 0x43, 0x70, 0x72, 0x36, 0x37, 0x6F,
144+
(byte)GraphicDriverCommandType.Command, 3, 0xED, 0x1B, 0x0B,
145+
(byte)GraphicDriverCommandType.Command, 2, 0xAE, 0x77,
146+
(byte)GraphicDriverCommandType.Command, 2, 0xCD, 0x63,
147+
(byte)GraphicDriverCommandType.Command, 10, 0x70, 0x07, 0x07, 0x04, 0x0E, 0x0F, 0x09, 0x07, 0x08, 0x03,
148+
(byte)GraphicDriverCommandType.Command, 2, (byte)GC9A01_CMD.FrameRate, 0x34,
149+
(byte)GraphicDriverCommandType.Command, 13, 0x62, 0x18, 0x0D, 0x71, 0xED, 0x70, 0x70, 0x18, 0x0F, 0x71, 0xEF, 0x70, 0x70,
150+
(byte)GraphicDriverCommandType.Command, 13, 0x63, 0x18, 0x11, 0x71, 0xF1, 0x70, 0x70, 0x18, 0x13, 0x71, 0xF3, 0x70, 0x70,
151+
(byte)GraphicDriverCommandType.Command, 8, 0x64, 0x28, 0x29, 0xF1, 0x01, 0xF1, 0x00, 0x07,
152+
(byte)GraphicDriverCommandType.Command, 11, 0x66, 0x3C, 0x00, 0xCD, 0x67, 0x45, 0x45, 0x10, 0x00, 0x00, 0x00,
153+
(byte)GraphicDriverCommandType.Command, 11, 0x67, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x01, 0x54, 0x10, 0x32, 0x98,
154+
(byte)GraphicDriverCommandType.Command, 8, 0x74, 0x10, 0x85, 0x80, 0x00, 0x00, 0x4E, 0x00,
155+
(byte)GraphicDriverCommandType.Command, 3, 0x98, 0x3E, 0x07,
156+
(byte)GraphicDriverCommandType.Command, 1, 0x35,
157+
(byte)GraphicDriverCommandType.Command, 1, (byte)GC9A01_CMD.DisplayInversionOn,
158+
(byte)GraphicDriverCommandType.Command, 1, (byte)GC9A01_CMD.SleepOut,
159+
// Sleep 120 ms
160+
(byte)GraphicDriverCommandType.Sleep, 12,
161+
(byte)GraphicDriverCommandType.Command, 1, (byte)GC9A01_CMD.DisplayOn,
162+
// Sleep 2 ms
163+
(byte)GraphicDriverCommandType.Sleep, 2,
164+
},
165+
OrientationLandscape = new byte[]
166+
{
167+
(byte)GraphicDriverCommandType.Command, 2, (byte)GC9A01_CMD.MemoryAccessControl, (byte)GC9A01_MEMORY_ACCESS_CTRL.Landscape,
168+
},
169+
OrientationLandscape180 = new byte[]
170+
{
171+
(byte)GraphicDriverCommandType.Command, 2, (byte)GC9A01_CMD.MemoryAccessControl, (byte)GC9A01_MEMORY_ACCESS_CTRL.Landscape180,
172+
},
173+
OrientationPortrait = new byte[]
174+
{
175+
(byte)GraphicDriverCommandType.Command, 2, (byte)GC9A01_CMD.MemoryAccessControl, (byte)GC9A01_MEMORY_ACCESS_CTRL.Portrait,
176+
},
177+
OrientationPortrait180 = new byte[]
178+
{
179+
(byte)GraphicDriverCommandType.Command, 2, (byte)GC9A01_CMD.MemoryAccessControl, (byte)GC9A01_MEMORY_ACCESS_CTRL.Portrait180,
180+
},
181+
PowerModeNormal = new byte[]
182+
{
183+
(byte)GraphicDriverCommandType.Command, 1, (byte)GC9A01_CMD.SleepOut,
184+
},
185+
PowerModeSleep = new byte[]
186+
{
187+
(byte)GraphicDriverCommandType.Command, 1, (byte)GC9A01_CMD.EnterSleepMode,
188+
},
189+
DefaultOrientation = DisplayOrientation.Landscape,
190+
Brightness = (byte)GC9A01_CMD.WriteDisplayBrightness,
191+
SetWindowType = SetWindowType.X16bitsY16Bit,
192+
};
193+
}
194+
195+
return _driver;
196+
}
197+
}
198+
}
199+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
// General Information about an assembly is controlled through the following
5+
// set of attributes. Change these attribute values to modify the information
6+
// associated with an assembly.
7+
[assembly: AssemblyTitle("nanoFramework.Graphics.Gc9A01")]
8+
[assembly: AssemblyCompany("nanoFramework Contributors")]
9+
[assembly: AssemblyProduct("nanoFramework.System.Text")]
10+
[assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2023")]
11+
12+
// Setting ComVisible to false makes the types in this assembly not visible
13+
// to COM components. If you need to access a type in this assembly from
14+
// COM, set the ComVisible attribute to true on that type.
15+
[assembly: ComVisible(false)]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Label="Globals">
4+
<NanoFrameworkProjectSystemPath>$(MSBuildExtensionsPath)\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
5+
</PropertyGroup>
6+
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props')" />
7+
<PropertyGroup>
8+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
9+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
10+
<ProjectTypeGuids>{11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
11+
<ProjectGuid>ae73f7ac-81cd-49f9-b6cf-e43747c49a6d</ProjectGuid>
12+
<OutputType>Library</OutputType>
13+
<AppDesignerFolder>Properties</AppDesignerFolder>
14+
<FileAlignment>512</FileAlignment>
15+
<RootNamespace>nanoFramework.UI.GraphicDrivers</RootNamespace>
16+
<AssemblyName>nanoFramework.Graphics.Gc9A01</AssemblyName>
17+
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
18+
<DocumentationFile>bin\$(Configuration)\nanoFramework.Graphics.Gc9A01.xml</DocumentationFile>
19+
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
20+
</PropertyGroup>
21+
<PropertyGroup>
22+
<SignAssembly>true</SignAssembly>
23+
</PropertyGroup>
24+
<PropertyGroup>
25+
<AssemblyOriginatorKeyFile>..\..\key.snk</AssemblyOriginatorKeyFile>
26+
</PropertyGroup>
27+
<PropertyGroup>
28+
<DelaySign>false</DelaySign>
29+
</PropertyGroup>
30+
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
31+
<ItemGroup>
32+
<Compile Include="Gc9A01.cs" />
33+
<Compile Include="Properties\AssemblyInfo.cs" />
34+
</ItemGroup>
35+
<ItemGroup>
36+
<Reference Include="mscorlib">
37+
<HintPath>..\..\packages\nanoFramework.CoreLibrary.1.14.2\lib\mscorlib.dll</HintPath>
38+
</Reference>
39+
</ItemGroup>
40+
<ItemGroup>
41+
<None Include="packages.config" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<ProjectReference Include="..\..\nanoFramework.Graphics\nanoFramework.Graphics.nfproj" />
45+
</ItemGroup>
46+
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
47+
<ProjectExtensions>
48+
<ProjectCapabilities>
49+
<ProjectConfigurationsDeclaredAsItems />
50+
</ProjectCapabilities>
51+
</ProjectExtensions>
52+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="nanoFramework.CoreLibrary" version="1.14.2" targetFramework="netnano1.0" />
4+
</packages>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": 1,
3+
"dependencies": {
4+
".NETnanoFramework,Version=v1.0": {
5+
"nanoFramework.CoreLibrary": {
6+
"type": "Direct",
7+
"requested": "[1.14.2, 1.14.2]",
8+
"resolved": "1.14.2",
9+
"contentHash": "j1mrz4mitl5LItvmHMsw1aHzCAfvTTgIkRxA0mhs5mSpctJ/BBcuNwua5j3MspfRNKreCQPy/qZy/D9ADLL/PA=="
10+
}
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)