My controller identifies as an ILI9328, but only works if initialised as an ILI9325. This fork includes a fix to force 9325 initialization when a 9328 is detected.

Dependents:   TouchScreenCalibrate TouchScreenGUIDemo

Fork of UniGraphic by GraphicsDisplay

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ILI932x.cpp Source File

ILI932x.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  
00006 #include "Protocols.h "
00007 #include "ILI932x.h"
00008 
00009 //////////////////////////////////////////////////////////////////////////////////
00010 // display settings ///////////////////////////////////////////////////////
00011 /////////////////////////////////////////////////////////////////////////
00012 
00013 
00014 ILI932x::ILI932x(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)
00015     : TFT932x(displayproto, port, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
00016 {
00017     hw_reset();
00018     BusEnable(true);  //set CS low, will stay low untill manually set high with BusEnable(false);
00019     identify(); // will collect tftID
00020     if(tftID==0x9325) init9325();
00021     else if(tftID==0x9320) init9320();
00022     auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
00023     set_orientation(0);
00024     FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. 
00025     cls();
00026     locate(0,0); 
00027 }
00028 ILI932x::ILI932x(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)
00029     : TFT932x(displayproto, buspins, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
00030 {
00031     hw_reset();
00032     BusEnable(true);  //set CS low, will stay low untill manually set high with BusEnable(false);
00033     identify(); // will collect tftID
00034     if(tftID==0x9325) init9325();
00035     else if(tftID==0x9320) init9320();
00036     auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
00037     set_orientation(0);
00038     FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. 
00039     cls();
00040     locate(0,0); 
00041 }
00042 ILI932x::ILI932x(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, const char *name, unsigned int LCDSIZE_X, unsigned  int LCDSIZE_Y)
00043     : TFT932x(displayproto, Hz, mosi, miso, sclk, CS, reset, LCDSIZE_X, LCDSIZE_Y, name)
00044 {
00045     hw_reset(); //TFT class forwards to Protocol class
00046     BusEnable(true); //set CS low, TFT932x class will toggle CS every transfer
00047     identify(); // will collect tftID
00048     if(tftID==0x9325) init9325();
00049     else if(tftID==0x9320) init9320();
00050     auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
00051     set_orientation(0); 
00052     FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. 
00053     cls();
00054     locate(0,0); 
00055 }
00056 
00057 ILI932x::ILI932x(const char *name)
00058     : TFT932x(name)
00059 {
00060     hw_reset(); //TFT class forwards to Protocol class
00061     BusEnable(true); //set CS low, TFT932x class will toggle CS every transfer
00062     identify(); // will collect tftID
00063     if(tftID==0x9325) init9325();
00064     else if(tftID==0x9320) init9320();
00065     auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
00066     set_orientation(0); 
00067     FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. 
00068     cls();
00069     locate(0,0); 
00070 }
00071 
00072 // reset and init the lcd controller
00073 
00074 void ILI932x::init9325()
00075 {
00076     /* Example for ILI9325 ----------------------------------------------------*/
00077 
00078  flipped=FLIP_NONE; // FLIP_NONE, FLIP_X, FLIP_Y, FLIP_X|FLIP_Y
00079  
00080  reg_write(0x0001,0x0100); 
00081  reg_write(0x0002,0x0700); 
00082  reg_write(0x0003,0x1030); 
00083  reg_write(0x0004,0x0000); 
00084  reg_write(0x0008,0x0207);  
00085  reg_write(0x0009,0x0000);
00086  reg_write(0x000A,0x0000); 
00087  reg_write(0x000C,0x0000); 
00088  reg_write(0x000D,0x0000);
00089  reg_write(0x000F,0x0000);
00090 //power on sequence VGHVGL
00091  reg_write(0x0010,0x0000);   
00092  reg_write(0x0011,0x0007);  
00093  reg_write(0x0012,0x0000);  
00094  reg_write(0x0013,0x0000); 
00095  reg_write(0x0007,0x0001);
00096 ThisThread::sleep_for(200ms);
00097 //vgh 
00098  reg_write(0x0010,0x1290);   
00099  reg_write(0x0011,0x0227);
00100 ThisThread::sleep_for(50ms);
00101  //vregiout 
00102  reg_write(0x0012,0x001d); //0x001b
00103  ThisThread::sleep_for(50ms);
00104  //vom amplitude
00105  reg_write(0x0013,0x1500);
00106  ThisThread::sleep_for(50ms); 
00107  //vom H
00108  reg_write(0x0029,0x0018); 
00109  reg_write(0x002B,0x000D); 
00110 ThisThread::sleep_for(50ms);
00111 //gamma
00112  reg_write(0x0030,0x0004);
00113  reg_write(0x0031,0x0307);
00114  reg_write(0x0032,0x0002);// 0006
00115  reg_write(0x0035,0x0206);
00116  reg_write(0x0036,0x0408);
00117  reg_write(0x0037,0x0507); 
00118  reg_write(0x0038,0x0204);//0200
00119  reg_write(0x0039,0x0707); 
00120  reg_write(0x003C,0x0405);// 0504
00121  reg_write(0x003D,0x0F02); 
00122  //ram
00123  reg_write(0x0050,0x0000); 
00124  reg_write(0x0051,0x00EF);
00125  reg_write(0x0052,0x0000); 
00126  reg_write(0x0053,0x013F);  
00127  reg_write(0x0060,0xA700); 
00128  reg_write(0x0061,0x0001); 
00129  reg_write(0x006A,0x0000); 
00130  //
00131  reg_write(0x0080,0x0000); 
00132  reg_write(0x0081,0x0000); 
00133  reg_write(0x0082,0x0000); 
00134  reg_write(0x0083,0x0000); 
00135  reg_write(0x0084,0x0000); 
00136  reg_write(0x0085,0x0000); 
00137  //
00138  reg_write(0x0090,0x0010); 
00139  reg_write(0x0092,0x0600); 
00140  reg_write(0x0093,0x0003); 
00141  reg_write(0x0095,0x0110); 
00142  reg_write(0x0097,0x0000); 
00143  reg_write(0x0098,0x0000);
00144  
00145  reg_write(0x0007,0x0133); // display on
00146 
00147 }
00148 void ILI932x::init9320()
00149 {
00150     /* Example for ILI9320 ----------------------------------------------------*/
00151 
00152  flipped=FLIP_X; // FLIP_NONE, FLIP_X, FLIP_Y, FLIP_X|FLIP_Y
00153  
00154  reg_write(0x0001,0x0100); 
00155  reg_write(0x0002,0x0700); 
00156  reg_write(0x0003,0x1030); 
00157  reg_write(0x0004,0x0000); 
00158  reg_write(0x0008,0x0202);  
00159  reg_write(0x0009,0x0000);
00160  reg_write(0x000A,0x0000); 
00161  reg_write(0x000C,0x0000); 
00162  reg_write(0x000D,0x0000);
00163  reg_write(0x000F,0x0000);
00164 //power on sequence
00165  reg_write(0x0010,0x0000);   
00166  reg_write(0x0011,0x0007);  
00167  reg_write(0x0012,0x0000);  
00168  reg_write(0x0013,0x0000); 
00169  reg_write(0x0007,0x0001);
00170 ThisThread::sleep_for(200ms);
00171 
00172  reg_write(0x0010,0x10C0);   
00173  reg_write(0x0011,0x0007);
00174 ThisThread::sleep_for(50ms);
00175 
00176  reg_write(0x0012,0x0110);
00177  ThisThread::sleep_for(50ms);
00178 
00179  reg_write(0x0013,0x0b00);
00180  ThisThread::sleep_for(50ms); 
00181 
00182  reg_write(0x0029,0x0000); 
00183  reg_write(0x002B,0x4010); // bit 14???
00184 ThisThread::sleep_for(50ms);
00185 //gamma
00186 /*
00187  reg_write(0x0030,0x0004);
00188  reg_write(0x0031,0x0307);
00189  reg_write(0x0032,0x0002);// 0006
00190  reg_write(0x0035,0x0206);
00191  reg_write(0x0036,0x0408);
00192  reg_write(0x0037,0x0507); 
00193  reg_write(0x0038,0x0204);//0200
00194  reg_write(0x0039,0x0707); 
00195  reg_write(0x003C,0x0405);// 0504
00196  reg_write(0x003D,0x0F02);
00197  */
00198  //ram
00199  reg_write(0x0050,0x0000); 
00200  reg_write(0x0051,0x00EF);
00201  reg_write(0x0052,0x0000); 
00202  reg_write(0x0053,0x013F);  
00203  reg_write(0x0060,0x2700); 
00204  reg_write(0x0061,0x0001); 
00205  reg_write(0x006A,0x0000); 
00206  //
00207  reg_write(0x0080,0x0000); 
00208  reg_write(0x0081,0x0000); 
00209  reg_write(0x0082,0x0000); 
00210  reg_write(0x0083,0x0000); 
00211  reg_write(0x0084,0x0000); 
00212  reg_write(0x0085,0x0000); 
00213  //
00214  reg_write(0x0090,0x0000); 
00215  reg_write(0x0092,0x0000); 
00216  reg_write(0x0093,0x0001); 
00217  reg_write(0x0095,0x0110); 
00218  reg_write(0x0097,0x0000); 
00219  reg_write(0x0098,0x0000);
00220  
00221  reg_write(0x0007,0x0133); // display on
00222 
00223 }