예제 #1
0
 private static void SetAddress(ILI9341Display display, UInt16 x0, UInt16 y0, UInt16 x1, UInt16 y1)
 {
     SendCommand(display, CMD_COLUMN_ADDRESS_SET);
     SendData(display, new byte[] { (byte)(x0 >> 8), (byte)(x0), (byte)(x1 >> 8), (byte)(x1) });
     SendCommand(display, CMD_PAGE_ADDRESS_SET);
     SendData(display, new byte[] { (byte)(y0 >> 8), (byte)(y0), (byte)(y1 >> 8), (byte)(y1) });
 }
예제 #2
0
        public static async Task Wakeup(ILI9341Display display)
        {
            SendCommand(display, CMD_SLEEP_OUT);
            await Task.Delay(60);

            SendCommand(display, CMD_POWER_CONTROL_A);              SendData(display, new byte[] { 0x39, 0x2C, 0x00, 0x34, 0x02 });
            SendCommand(display, CMD_POWER_CONTROL_B);              SendData(display, new byte[] { 0x00, 0xC1, 0x30 });
            SendCommand(display, CMD_DRIVER_TIMING_CONTROL_A);      SendData(display, new byte[] { 0x85, 0x00, 0x78 });
            SendCommand(display, CMD_DRIVER_TIMING_CONTROL_B);      SendData(display, new byte[] { 0x00, 0x00 });

            SendCommand(display, CMD_POWER_ON_SEQUENCE_CONTROL);    SendData(display, new byte[] { 0x64, 0x03, 0x12, 0x81 });
            SendCommand(display, CMD_PUMP_RATIO_CONTROL);           SendData(display, new byte[] { 0x20 });

            SendCommand(display, CMD_POWER_CONTROL_1);              SendData(display, new byte[] { 0x23 });
            SendCommand(display, CMD_POWER_CONTROL_2);              SendData(display, new byte[] { 0x10 });

            SendCommand(display, CMD_VCOM_CONTROL_1);               SendData(display, new byte[] { 0x3e, 0x28 });
            SendCommand(display, CMD_VCOM_CONTROL_2);               SendData(display, new byte[] { 0x86 });

            SendCommand(display, CMD_MEMORY_ACCESS_CONTROL);        SendData(display, new byte[] { 0x48 });
            SendCommand(display, CMD_PIXEL_FORMAT);                 SendData(display, new byte[] { 0x55 });
            SendCommand(display, CMD_FRAME_RATE_CONTROL);           SendData(display, new byte[] { 0x00, 0x18 });
            SendCommand(display, CMD_DISPLAY_FUNCTION_CONTROL);     SendData(display, new byte[] { 0x08, 0x82, 0x27 });
            SendCommand(display, CMD_ENABLE_3G);                    SendData(display, new byte[] { 0x00 });
            SendCommand(display, CMD_GAMMA_SET);                    SendData(display, new byte[] { 0x01 });
            SendCommand(display, CMD_POSITIVE_GAMMA_CORRECTION);    SendData(display, new byte[] { 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00 });
            SendCommand(display, CMD_NEGATIVE_GAMMA_CORRECTION);    SendData(display, new byte[] { 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F });

            SendCommand(display, CMD_SLEEP_OUT);
            await Task.Delay(120);

            SendCommand(display, CMD_DISPLAY_ON);
        }
예제 #3
0
 public static void InitializeDisplayBuffer(ILI9341Display display, UInt16 colour)
 {
     for (uint i = 0; i < display.LCD_HORIZONTAL_MAX * display.LCD_VERTICAL_MAX; i++)
     {
         display.DisplayBuffer[i * 2]     = (byte)(colour >> 8);
         display.DisplayBuffer[i * 2 + 1] = (byte)(colour & 0xFF);
     }
 }
예제 #4
0
        public static async Task PowerOnSequence(ILI9341Display display)
        {
            // assume power has just been turned on
            await Task.Delay(5);

            display.ResetPin.Write(GpioPinValue.Low);   // reset
            await Task.Delay(5);                        // wait 5 ms

            display.ResetPin.Write(GpioPinValue.High);  // out of reset
            await Task.Delay(20);
        }
예제 #5
0
        public static async Task landscapeMode(ILI9341Display display)
        {
            try {
                SendCommand(display, CMD_MEMORY_ACCESS_CONTROL); SendData(display, new byte[] { 0xE8 });
                display.LCD_HORIZONTAL_MAX = ILI9341Display.VERTICAL_MAX_DEFAULT;
                display.LCD_VERTICAL_MAX   = ILI9341Display.HORIZONTAL_MAX_DEFAULT;
                await LoadBitmap(display, display.currentImage);

                Flush(display);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #6
0
        public static async Task LoadBitmap(ILI9341Display display, string name)
        {
            try
            {
                StorageFile srcfile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(name));

                using (IRandomAccessStream fileStream = await srcfile.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream);

                    BitmapTransform transform = new BitmapTransform()
                    {
                        ScaledWidth  = Convert.ToUInt32(display.LCD_HORIZONTAL_MAX),
                        ScaledHeight = Convert.ToUInt32(display.LCD_VERTICAL_MAX)
                    };
                    PixelDataProvider pixelData = await decoder.GetPixelDataAsync(
                        BitmapPixelFormat.Bgra8,
                        BitmapAlphaMode.Straight,
                        transform,
                        ExifOrientationMode.RespectExifOrientation,
                        ColorManagementMode.DoNotColorManage
                        );

                    byte[] sourcePixels = pixelData.DetachPixelData();
                    if (sourcePixels.Length != display.LCD_HORIZONTAL_MAX * display.LCD_VERTICAL_MAX * 4)
                    {
                        return;
                    }
                    int pi = 0;
                    for (UInt32 x = 0; x < sourcePixels.Length - 1; x += 4)
                    {
                        // we ignore the alpha value [3]
                        ushort temp = ILI9341.RGB24ToRGB565(sourcePixels[x + 2], sourcePixels[x + 1], sourcePixels[x]);
                        display.DisplayBuffer[pi * 2]     = (byte)((temp >> 8) & 0xFF);
                        display.DisplayBuffer[pi * 2 + 1] = (byte)(temp & 0xFF);
                        pi++;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            display.currentImage = name;
        }
예제 #7
0
        public static void Flush(ILI9341Display display)
        {
            if (display.DisplayBuffer.Length != display.LCD_VERTICAL_MAX * display.LCD_HORIZONTAL_MAX * 2)
            {
                return;
            }
            SetAddress(display, 0, 0, (UInt16)(display.LCD_HORIZONTAL_MAX - 1), (UInt16)(display.LCD_VERTICAL_MAX - 1));
            int block_size = 51200; // limits of the SPI interface is 64K but this is an even block for display ???

            byte[] buffer = new byte[block_size];
            // now we start to write the buffer out
            SendCommand(display, CMD_MEMORY_WRITE_MODE);
            Array.Copy(display.DisplayBuffer, 0, buffer, 0, 51200);
            SendData(display, buffer);
            Array.Copy(display.DisplayBuffer, 51200, buffer, 0, 51200);
            SendData(display, buffer);
            Array.Copy(display.DisplayBuffer, 51200 * 2, buffer, 0, 51200);
            SendData(display, buffer);
        }
예제 #8
0
        public static async Task InitILI9341DisplaySPI(ILI9341Display display, int SPIDisplaypin, int speed, SpiMode mode, string SPI_CONTROLLER_NAME, string DefaultDisplay)
        {
            var displaySettings = new SpiConnectionSettings(SPIDisplaypin);

            displaySettings.ClockFrequency = speed; // 500kHz;
            displaySettings.Mode           = mode;  //Mode0,1,2,3;  MCP23S17 needs mode 0
            string DispspiAqs     = SpiDevice.GetDeviceSelector(SPI_CONTROLLER_NAME);
            var    DispdeviceInfo = await DeviceInformation.FindAllAsync(DispspiAqs);

            display.SpiDisplay = await SpiDevice.FromIdAsync(DispdeviceInfo[0].Id, displaySettings);

            if (String.IsNullOrEmpty(DefaultDisplay))
            {
                InitializeDisplayBuffer(display, ILI9341Display.BLACK);
            }
            else
            {
                await LoadBitmap(display, DefaultDisplay);
            }
            await PowerOnSequence(display);
            await Wakeup(display);

            Flush(display);
        }
예제 #9
0
 private static void SendCommand(ILI9341Display display, byte[] Command)
 {
     display.DCPin.Write(GpioPinValue.Low);
     display.SpiDisplay.Write(Command);
 }
예제 #10
0
 private static void SendData(ILI9341Display display, byte[] Data)
 {
     display.DCPin.Write(GpioPinValue.High);
     display.SpiDisplay.Write(Data);
 }
예제 #11
0
 public static void Sleep(ILI9341Display display)
 {
     SendCommand(display, CMD_DISPLAY_OFF);
     SendCommand(display, CMD_ENTER_SLEEP);
 }