Darren Ulrich / UniGraphic

Dependents:   Bicycl_Computer_NUCLEO-F411RE Bicycl_Computer_NUCLEO-L476RG

Fork of UniGraphic by GraphicsDisplay

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ILI9341.cpp Source File

ILI9341.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 "ILI9341.h"
00008 
00009 //////////////////////////////////////////////////////////////////////////////////
00010 // display settings ///////////////////////////////////////////////////////
00011 /////////////////////////////////////////////////////////////////////////
00012 
00013 // put in constructor
00014 //#define LCDSIZE_X       240 // display X pixels, TFTs are usually portrait view
00015 //#define LCDSIZE_Y       320  // display Y pixels 
00016 
00017 
00018 
00019 ILI9341::ILI9341(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)
00020     : TFT(displayproto, port, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
00021 {
00022     hw_reset();
00023     BusEnable(true);
00024     identify(); // will collect tftID and set mipistd flag
00025     init();
00026     auto_gram_read_format();
00027     set_orientation(0);
00028     cls();
00029     FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. 
00030     locate(0,0); 
00031 }
00032 ILI9341::ILI9341(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)
00033     : TFT(displayproto, Hz, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, name)
00034 {
00035     hw_reset(); //TFT class forwards to Protocol class
00036     BusEnable(true); //TFT class forwards to Protocol class
00037     identify(); // will collect tftID and set mipistd flag
00038     init(); // per display custom init cmd sequence, implemented here
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); //TFT class does for MIPI standard and some ILIxxx
00041     FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. 
00042     cls();
00043     locate(0,0); 
00044 }
00045 // reset and init the lcd controller
00046 void ILI9341::init()
00047 {
00048     /* Start Initial Sequence ----------------------------------------------------*/
00049     
00050     wr_cmd8(0xCB);  // POWER_ON_SEQ_CONTROL             
00051      wr_data8(0x39);
00052      wr_data8(0x2C);
00053      wr_data8(0x00);
00054      wr_data8(0x34);
00055      wr_data8(0x02);
00056      
00057     wr_cmd8(0xCF);  // POWER_CONTROL_B              
00058      wr_data8(0x00);
00059      wr_data8(0xC1);  // Applic Notes 81, was 83, C1 enables PCEQ: PC and EQ operation for power saving
00060      wr_data8(0x30);
00061      
00062      wr_cmd8(0xE8);  // DRIVER_TIMING_CONTROL_A               
00063      wr_data8(0x85);
00064      wr_data8(0x00);  // AN 10, was 01
00065      wr_data8(0x78);  // AN 7A, was 79
00066      
00067      wr_cmd8(0xEA);  // DRIVER_TIMING_CONTROL_B                    
00068      wr_data8(0x00);
00069      wr_data8(0x00);
00070      
00071      wr_cmd8(0xED);                     
00072      wr_data8(0x64);
00073      wr_data8(0x03);
00074      wr_data8(0x12);
00075      wr_data8(0x81);
00076      
00077      wr_cmd8(0xF7);  // PUMP_RATIO_CONTROL                   
00078      wr_data8(0x20);
00079      
00080      wr_cmd8(0xC0);                     // POWER_CONTROL_1
00081      wr_data8(0x23);  // AN 21, was 26
00082      
00083      wr_cmd8(0xC1);                     // POWER_CONTROL_2
00084      wr_data8(0x10);  // AN 11, was 11
00085      
00086      wr_cmd8(0xC5);                     // VCOM_CONTROL_1
00087      wr_data8(0x3E);  // AN 3F, was 35
00088      wr_data8(0x28);  // AN 3C, was 3E
00089      
00090      wr_cmd8(0xC7);                     // VCOM_CONTROL_2
00091      wr_data8(0x86);  // AN A7, was BE
00092      
00093      
00094      
00095      wr_cmd8(0xB1);                     // Frame Rate
00096      wr_data8(0x00);
00097      wr_data8(0x18);  // AN 1B, was 1B  1B=70hz             
00098      
00099      wr_cmd8(0xB6);                       // display function control, INTERESTING
00100      wr_data8(0x08);  // AN 0A, was 0A
00101      wr_data8(0x82);  // AN A2
00102      wr_data8(0x27);  // AN not present
00103   //   wr_data8(0x00);  // was present
00104      
00105      wr_cmd8(0xF2);                     // Gamma Function Disable
00106      wr_data8(0x00);  // AN 00, was 08
00107      
00108      wr_cmd8(0x26);                     
00109      wr_data8(0x01);                 // gamma set for curve 01/2/04/08
00110      
00111      wr_cmd8(0xE0);                     // positive gamma correction
00112      wr_data8(0x0F); 
00113      wr_data8(0x31); 
00114      wr_data8(0x2B); 
00115      wr_data8(0x0C); 
00116      wr_data8(0x0E); 
00117      wr_data8(0x08); 
00118      wr_data8(0x4E); 
00119      wr_data8(0xF1); 
00120      wr_data8(0x37); 
00121      wr_data8(0x07); 
00122      wr_data8(0x10); 
00123      wr_data8(0x03); 
00124      wr_data8(0x0E);
00125      wr_data8(0x09); 
00126      wr_data8(0x00);
00127      
00128      wr_cmd8(0xE1);                     // negativ gamma correction
00129      wr_data8(0x00); 
00130      wr_data8(0x0E); 
00131      wr_data8(0x14); 
00132      wr_data8(0x03); 
00133      wr_data8(0x11); 
00134      wr_data8(0x07); 
00135      wr_data8(0x31); 
00136      wr_data8(0xC1); 
00137      wr_data8(0x48); 
00138      wr_data8(0x08); 
00139      wr_data8(0x0F); 
00140      wr_data8(0x0C); 
00141      wr_data8(0x31);
00142      wr_data8(0x36); 
00143      wr_data8(0x0F);
00144      
00145      //wr_cmd8(0x34);                     // tearing effect off
00146      
00147      //wr_cmd8(0x35);                     // tearing effect on
00148       
00149   //   wr_cmd8(0xB7);                       // ENTRY_MODE_SET
00150   //   wr_data8(0x07);
00151   
00152     wr_cmd8(0x36);      // MEMORY_ACCESS_CONTROL (orientation stuff)
00153     wr_data8(0x48);
00154      
00155     wr_cmd8(0x3A);      // COLMOD_PIXEL_FORMAT_SET
00156     wr_data8(0x55);     // 16 bit pixel 
00157 
00158     wr_cmd8(0x13); // Nomal Displaymode
00159     
00160      wr_cmd8(0x11);                     // sleep out
00161      wait_ms(150);
00162      
00163      wr_cmd8(0x29);                     // display on
00164      wait_ms(150);
00165 
00166 }