|
| 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 Ili9488. |
| 11 | + /// </summary> |
| 12 | + public static class Ili9488 |
| 13 | + { |
| 14 | + private static GraphicDriver _driver; |
| 15 | + |
| 16 | + // Those enums are left like this to match the native side |
| 17 | + private enum ILI9488_CMD |
| 18 | + { |
| 19 | + NOP = 0x00, |
| 20 | + SOFTWARE_RESET = 0x01, |
| 21 | + POWER_STATE = 0x10, |
| 22 | + Sleep_Out = 0x11, |
| 23 | + Noron = 0x13, |
| 24 | + Invert_On = 0x21, |
| 25 | + Invert_Off = 0x20, |
| 26 | + Gamma_Set = 0x26, |
| 27 | + Display_OFF = 0x28, |
| 28 | + Display_ON = 0x29, |
| 29 | + Column_Address_Set = 0x2A, |
| 30 | + Page_Address_Set = 0x2B, |
| 31 | + Memory_Write = 0x2C, |
| 32 | + Colour_Set = 0x2D, |
| 33 | + Memory_Read = 0x2E, |
| 34 | + Partial_Area = 0x30, |
| 35 | + Memory_Access_Control = 0x36, |
| 36 | + Pixel_Format_Set = 0x3A, |
| 37 | + Memory_Write_Continue = 0x3C, |
| 38 | + Write_Display_Brightness = 0x51, |
| 39 | + Interface_Signal_Control = 0xB0, |
| 40 | + Frame_Rate_Control_Normal = 0xB1, |
| 41 | + Inversion_Control = 0xB4, |
| 42 | + Display_Function_Control = 0xB6, |
| 43 | + Entry_Mode_Set = 0xB7, |
| 44 | + Power_Control_1 = 0xC0, |
| 45 | + Power_Control_2 = 0xC1, |
| 46 | + VCOM_Control_1 = 0xC5, |
| 47 | + VCOM_Control_2 = 0xC7, |
| 48 | + External_Command = 0xC8, |
| 49 | + Power_Control_A = 0xCB, |
| 50 | + Power_Control_B = 0xCF, |
| 51 | + Positive_Gamma_Correction = 0xE0, |
| 52 | + Negative_Gamma_Correction = 0XE1, |
| 53 | + Driver_Timing_Control_A = 0xE8, |
| 54 | + Driver_Timing_Control_B = 0xEA, |
| 55 | + Set_Image_Function = 0xE9, |
| 56 | + Power_On_Sequence = 0xED, |
| 57 | + Enable_3G = 0xF2, |
| 58 | + Interface_Control = 0xF6, |
| 59 | + Pump_Ratio_Control = 0xF7 |
| 60 | + }; |
| 61 | + |
| 62 | + private enum ILI9488_Orientation |
| 63 | + { |
| 64 | + MADCTL_MH = 0x04, // sets the Horizontal Refresh, 0=Left-Right and 1=Right-Left |
| 65 | + MADCTL_ML = 0x10, // sets the Vertical Refresh, 0=Top-Bottom and 1=Bottom-Top |
| 66 | + MADCTL_MV = 0x20, // sets the Row/Column Swap, 0=Normal and 1=Swapped |
| 67 | + MADCTL_MX = 0x40, // sets the Column Order, 0=Left-Right and 1=Right-Left |
| 68 | + MADCTL_MY = 0x80, // sets the Row Order, 0=Top-Bottom and 1=Bottom-Top |
| 69 | + |
| 70 | + MADCTL_BGR = 0x08, // Blue-Green-Red pixel order |
| 71 | + MADCTL_RGB = 0x00 // Red-Green-Blue pixel order |
| 72 | + }; |
| 73 | + |
| 74 | + /// <summary> |
| 75 | + /// Default width. Use to override the one you'll pass in the screen and add it to the driver. |
| 76 | + /// </summary> |
| 77 | + public static uint Width { get; } = 480; |
| 78 | + |
| 79 | + /// <summary> |
| 80 | + /// Default height. Use to override the one you'll pass in the screen and add it to the driver. |
| 81 | + /// </summary> |
| 82 | + public static uint Height { get; } = 320; |
| 83 | + |
| 84 | + /// <summary> |
| 85 | + /// Gets the graphic driver for the Ili9488 display. |
| 86 | + /// </summary> |
| 87 | + public static GraphicDriver GraphicDriver |
| 88 | + { |
| 89 | + get |
| 90 | + { |
| 91 | + if (_driver == null) |
| 92 | + { |
| 93 | + _driver = new GraphicDriver() |
| 94 | + { |
| 95 | + MemoryWrite = (byte)ILI9488_CMD.Memory_Write, |
| 96 | + SetColumnAddress = (byte)ILI9488_CMD.Column_Address_Set, |
| 97 | + SetRowAddress = (byte)ILI9488_CMD.Page_Address_Set, |
| 98 | + InitializationSequence = new byte[] |
| 99 | + { |
| 100 | + (byte)GraphicDriverCommandType.Command, 3, (byte)ILI9488_CMD.Power_Control_1, 0x17, 0x15, |
| 101 | + (byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Power_Control_2, 0x41, |
| 102 | + (byte)GraphicDriverCommandType.Command, 4, (byte)ILI9488_CMD.VCOM_Control_1, 0x00, 0x12, 0x80, |
| 103 | + (byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Memory_Access_Control, 0x40, // 0x40 = MADCTL_MX (0x40) + MADCTL_RGB (0x00) |
| 104 | + (byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Pixel_Format_Set, 0x66, // 18 bit SPI |
| 105 | + (byte)GraphicDriverCommandType.Command, 16, (byte)ILI9488_CMD.Positive_Gamma_Correction, 0x00, 0x03, 0x09, 0x08, 0x16, 0x0A, 0x3F, 0x78, 0x4C, 0x09, 0x0A, 0x08, 0x16, 0x1A, 0x0F, |
| 106 | + (byte)GraphicDriverCommandType.Command, 16, (byte)ILI9488_CMD.Negative_Gamma_Correction, 0x00, 0x16, 0x19, 0x03, 0x0F, 0x05, 0x32, 0x45, 0x46, 0x04, 0x0E, 0x0D, 0x35, 0x37, 0x0F, |
| 107 | + (byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Interface_Signal_Control, 0x80, |
| 108 | + (byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Frame_Rate_Control_Normal, 0xA0, |
| 109 | + (byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Inversion_Control, 0x02, |
| 110 | + (byte)GraphicDriverCommandType.Command, 4, (byte)ILI9488_CMD.Display_Function_Control, 0x02, 0x02, 0x3B, |
| 111 | + (byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Set_Image_Function, 0x00, |
| 112 | + (byte)GraphicDriverCommandType.Command, 5, (byte)ILI9488_CMD.Pump_Ratio_Control, 0xA9, 0x51, 0x2C, 0x82, |
| 113 | + (byte)GraphicDriverCommandType.Command, 1, (byte)ILI9488_CMD.Sleep_Out, |
| 114 | + (byte)GraphicDriverCommandType.Sleep, 12, // Sleep 120 ms |
| 115 | + (byte)GraphicDriverCommandType.Command, 1, (byte)ILI9488_CMD.Display_ON, |
| 116 | + (byte)GraphicDriverCommandType.Sleep, 20, // Sleep 200 ms |
| 117 | + (byte)GraphicDriverCommandType.Command, 1, (byte)ILI9488_CMD.NOP, |
| 118 | + (byte)GraphicDriverCommandType.Sleep, 2 // Sleep 20 ms |
| 119 | + }, |
| 120 | + OrientationLandscape = new byte[] |
| 121 | + { |
| 122 | + (byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Memory_Access_Control, |
| 123 | + (byte)( |
| 124 | + ILI9488_Orientation.MADCTL_MX | |
| 125 | + ILI9488_Orientation.MADCTL_MY | |
| 126 | + ILI9488_Orientation.MADCTL_MV | |
| 127 | + ILI9488_Orientation.MADCTL_RGB |
| 128 | + ), |
| 129 | + }, |
| 130 | + OrientationLandscape180 = new byte[] |
| 131 | + { |
| 132 | + (byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Memory_Access_Control, |
| 133 | + (byte)( |
| 134 | + ILI9488_Orientation.MADCTL_MV | |
| 135 | + ILI9488_Orientation.MADCTL_RGB |
| 136 | + ), |
| 137 | + }, |
| 138 | + OrientationPortrait = new byte[] |
| 139 | + { |
| 140 | + (byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Memory_Access_Control, |
| 141 | + (byte)( |
| 142 | + ILI9488_Orientation.MADCTL_MX | |
| 143 | + ILI9488_Orientation.MADCTL_RGB |
| 144 | + ), |
| 145 | + }, |
| 146 | + OrientationPortrait180 = new byte[] |
| 147 | + { |
| 148 | + (byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Memory_Access_Control, |
| 149 | + (byte)( |
| 150 | + ILI9488_Orientation.MADCTL_MY | |
| 151 | + ILI9488_Orientation.MADCTL_RGB |
| 152 | + ), |
| 153 | + }, |
| 154 | + PowerModeNormal = new byte[] |
| 155 | + { |
| 156 | + (byte)GraphicDriverCommandType.Command, 3, (byte)ILI9488_CMD.POWER_STATE, 0x00, 0x00, |
| 157 | + }, |
| 158 | + PowerModeSleep = new byte[] |
| 159 | + { |
| 160 | + (byte)GraphicDriverCommandType.Command, 3, (byte)ILI9488_CMD.POWER_STATE, 0x00, 0x01, |
| 161 | + }, |
| 162 | + DefaultOrientation = DisplayOrientation.Landscape, |
| 163 | + Brightness = (byte)ILI9488_CMD.Write_Display_Brightness, |
| 164 | + SetWindowType = SetWindowType.X16bitsY16Bit, |
| 165 | + BitsPerPixel = 18 |
| 166 | + }; |
| 167 | + } |
| 168 | + |
| 169 | + return _driver; |
| 170 | + } |
| 171 | + } |
| 172 | + } |
| 173 | +} |
0 commit comments