Gustavo D. Serafim / UniGraphicILI9486GraphicsTest

Dependents:   mbed_ili9486

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ILI9486.cpp Source File

ILI9486.cpp

00001  /* mbed UniGraphic library - Device specific class
00002  * Copyright (c) 2015 Giuliano Dianda
00003  * Released under the MIT License: http://mbed.org/license/mit
00004  */
00005 #include "Protocols.h "
00006 #include "ILI9486.h"
00007 
00008 //////////////////////////////////////////////////////////////////////////////////
00009 // display settings ///////////////////////////////////////////////////////
00010 /////////////////////////////////////////////////////////////////////////
00011 
00012 // put in constructor
00013 //#define LCDSIZE_X       320 // display X pixels, TFTs are usually portrait view
00014 //#define LCDSIZE_Y       480  // display Y pixels
00015 
00016 
00017 
00018 ILI9486::ILI9486(proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char *name , unsigned int LCDSIZE_X, unsigned  int LCDSIZE_Y)
00019     : TFT(displayproto, port, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
00020 {
00021     hw_reset();
00022     BusEnable(true);
00023     identify(); // will collect tftID and set mipistd flag
00024     init();
00025     auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
00026     set_orientation(0);
00027  //   FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. ILI9486 does not, at least in par mode
00028     cls();
00029     locate(0,0); 
00030 }
00031 
00032 ILI9486::ILI9486(proto_t displayproto, PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char *name , unsigned int LCDSIZE_X, unsigned  int LCDSIZE_Y)
00033     : TFT(displayproto, buspins, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
00034 {
00035     hw_reset();
00036     BusEnable(true);
00037     identify(); // will collect tftID and set mipistd flag
00038     init();
00039     auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
00040     set_orientation(0);
00041  //   FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. ILI9486 does not, at least in par mode
00042     cls();
00043     locate(0,0); 
00044 }
00045 
00046 ILI9486::ILI9486(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char *name, unsigned int LCDSIZE_X, unsigned  int LCDSIZE_Y)
00047     : TFT(displayproto, Hz, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, name)
00048 {
00049     hw_reset(); //TFT class forwards to Protocol class
00050     BusEnable(true); //TFT class forwards to Protocol class
00051     identify(); // will collect tftID and set mipistd flag
00052     init(); // per display custom init cmd sequence, implemented here
00053     auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
00054     set_orientation(0); //TFT class does for MIPI standard and some ILIxxx
00055  //   FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. ILI9486 does not, at least in par mode
00056     cls();
00057     locate(0,0); 
00058 }
00059 
00060 // reset and init the lcd controller
00061 void ILI9486::init()
00062 {
00063     /* Start Initial Sequence ----------------------------------------------------*/
00064     
00065     wr_cmd8(0xF1);
00066     wr_data8(0x36);
00067     wr_data8(0x04);
00068     wr_data8(0x00);
00069     wr_data8(0x3C);
00070     wr_data8(0x0F);
00071     wr_data8(0x8F);
00072 
00073 
00074     wr_cmd8(0xF2);
00075     wr_data8(0x18);
00076     wr_data8(0xA3);
00077     wr_data8(0x12);
00078     wr_data8(0x02);
00079     wr_data8(0xb2);
00080     wr_data8(0x12);
00081     wr_data8(0xFF);
00082     wr_data8(0x10);
00083     wr_data8(0x00);
00084 
00085     wr_cmd8(0xF8);
00086     wr_data8(0x21);
00087     wr_data8(0x04);
00088 
00089     wr_cmd8(0xF9);
00090     wr_data8(0x00);
00091     wr_data8(0x08);  
00092 
00093     wr_cmd8(0xC0);
00094     wr_data8(0x0f); //13
00095     wr_data8(0x0f); //10
00096 
00097     wr_cmd8(0xC1);
00098     wr_data8(0x42); //43
00099 
00100     wr_cmd8(0xC2);
00101     wr_data8(0x22);
00102 
00103     wr_cmd8(0xC5);
00104     wr_data8(0x01); //00
00105     wr_data8(0x29); //4D
00106     wr_data8(0x80);
00107 
00108     wr_cmd8(0xB6);
00109     wr_data8(0x00);
00110     wr_data8(0x02); //42
00111     wr_data8(0x3b);
00112 
00113     wr_cmd8(0xB1);
00114     wr_data8(0xB0); //C0
00115     wr_data8(0x11);
00116 
00117     wr_cmd8(0xB4);
00118     wr_data8(0x02); //01
00119 
00120     wr_cmd8(0xE0);
00121     wr_data8(0x0F);
00122     wr_data8(0x18);
00123     wr_data8(0x15);
00124     wr_data8(0x09);
00125     wr_data8(0x0B);
00126     wr_data8(0x04);
00127     wr_data8(0x49);
00128     wr_data8(0x64);
00129     wr_data8(0x3D);
00130     wr_data8(0x08);
00131     wr_data8(0x15);
00132     wr_data8(0x06);
00133     wr_data8(0x12);
00134     wr_data8(0x07);
00135     wr_data8(0x00);
00136 
00137     wr_cmd8(0xE1);
00138     wr_data8(0x0F);
00139     wr_data8(0x38);
00140     wr_data8(0x35);
00141     wr_data8(0x0a);
00142     wr_data8(0x0c);
00143     wr_data8(0x03);
00144     wr_data8(0x4A);
00145     wr_data8(0x42);
00146     wr_data8(0x36);
00147     wr_data8(0x04);
00148     wr_data8(0x0F);
00149     wr_data8(0x03);
00150     wr_data8(0x1F);
00151     wr_data8(0x1B);
00152     wr_data8(0x00);
00153 
00154     wr_cmd8(0x20);                     // display inversion OFF
00155   
00156     wr_cmd8(0x36);      // MEMORY_ACCESS_CONTROL (orientation stuff)
00157     wr_data8(0x48);
00158      
00159     wr_cmd8(0x3A);      // COLMOD_PIXEL_FORMAT_SET
00160     wr_data8(0x55);     // 16 bit pixel 
00161 
00162     wr_cmd8(0x13); // Nomal Displaymode
00163     
00164     wr_cmd8(0x11);                     // sleep out
00165     wait_ms(150);
00166      
00167     wr_cmd8(0x29);                     // display on
00168     wait_ms(150);
00169 }