La Suno / UniGraphic

Dependents:   afero_poc15_180216 afero_poc15_180223 afero_poc15_180302 afero_poc15_180403R ... more

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