|
| 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 | +} |
0 commit comments