Modified version of the DmTftLibrary, optimized for the LPC4088 Experiment Base Board
Dependents: lpc4088_ebb_dm_calc lpc4088_ebb_dm_bubbles
Fork of DmTftLibrary by
DmTftIli9341.cpp
00001 /********************************************************************************************** 00002 Copyright (c) 2014 DisplayModule. All rights reserved. 00003 00004 Redistribution and use of this source code, part of this source code or any compiled binary 00005 based on this source code is permitted as long as the above copyright notice and following 00006 disclaimer is retained. 00007 00008 DISCLAIMER: 00009 THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES 00010 NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. 00011 ********************************************************************************************/ 00012 00013 #include "DmTftIli9341.h" 00014 #if defined (DM_TOOLCHAIN_ARDUINO) 00015 DmTftIli9341::DmTftIli9341(uint8_t cs, uint8_t dc) 00016 #elif defined (DM_TOOLCHAIN_MBED) 00017 DmTftIli9341::DmTftIli9341(uint8_t cs, uint8_t dc, uint8_t miso, uint8_t mosi, uint8_t clk) 00018 #endif 00019 : DmTftBase(240, 320){ 00020 _cs = cs; 00021 _dc = dc; 00022 #if defined (DM_TOOLCHAIN_MBED) 00023 _miso = miso; 00024 _mosi = mosi; 00025 _clk = clk; 00026 #endif 00027 } 00028 00029 DmTftIli9341::~DmTftIli9341() { 00030 #if defined (DM_TOOLCHAIN_MBED) 00031 delete _pinCS; 00032 delete _pinDC; 00033 delete _spi; 00034 00035 _pinCS = NULL; 00036 _pinDC = NULL; 00037 _spi = NULL; 00038 #endif 00039 } 00040 00041 void DmTftIli9341::writeBus(uint8_t data) { 00042 #if defined (DM_TOOLCHAIN_ARDUINO) 00043 SPCR = _spiSettings; // SPI Control Register 00044 SPDR = data; // SPI Data Register 00045 while(!(SPSR & _BV(SPIF))); // SPI Status Register Wait for transmission to finish 00046 #elif defined (DM_TOOLCHAIN_MBED) 00047 _spi->write(data); 00048 #endif 00049 } 00050 00051 void DmTftIli9341::sendCommand(uint8_t index) { 00052 // cbi(_pinCS, _bitmaskCS); 00053 cbi(_pinDC, _bitmaskDC); 00054 00055 writeBus(index); 00056 // sbi(_pinCS, _bitmaskCS); 00057 } 00058 00059 void DmTftIli9341::send8BitData(uint8_t data) { 00060 //cbi(_pinCS, _bitmaskCS); 00061 sbi(_pinDC, _bitmaskDC); 00062 writeBus(data); 00063 //sbi(_pinCS, _bitmaskCS); 00064 } 00065 00066 void DmTftIli9341::sendData(uint16_t data) { 00067 uint8_t dh = data>>8; 00068 uint8_t dl = data&0xff; 00069 00070 //cbi(_pinCS, _bitmaskCS); 00071 sbi(_pinDC, _bitmaskDC); 00072 writeBus(dh); 00073 writeBus(dl); 00074 //sbi(_pinCS, _bitmaskCS); 00075 } 00076 00077 void DmTftIli9341::setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { 00078 sendCommand(0x2A); // Set Column 00079 sendData(x0); 00080 sendData(x1); 00081 00082 sendCommand(0x2B); // Set Page 00083 sendData(y0); 00084 sendData(y1); 00085 00086 sendCommand(0x2c); 00087 } 00088 00089 void DmTftIli9341::init(void) { 00090 setTextColor(BLACK, WHITE); 00091 #if defined (DM_TOOLCHAIN_ARDUINO) 00092 _pinCS = portOutputRegister(digitalPinToPort(_cs)); 00093 _bitmaskCS = digitalPinToBitMask(_cs); 00094 _pinDC = portOutputRegister(digitalPinToPort(_dc)); 00095 _bitmaskDC = digitalPinToBitMask(_dc); 00096 pinMode(_cs,OUTPUT); 00097 pinMode(_dc,OUTPUT); 00098 00099 sbi(_pinCS, _bitmaskCS); 00100 00101 SPI.begin(); 00102 SPI.setClockDivider(SPI_CLOCK_DIV2); // 8 MHz (full! speed!) 00103 SPI.setBitOrder(MSBFIRST); 00104 SPI.setDataMode(SPI_MODE0); 00105 _spiSettings = SPCR; 00106 #elif defined (DM_TOOLCHAIN_MBED) 00107 _pinCS = new DigitalOut((PinName)_cs); 00108 _pinDC = new DigitalOut((PinName)_dc); 00109 sbi(_pinCS, _bitmaskCS); 00110 00111 _spi = new SPI((PinName)_mosi, (PinName)_miso, (PinName)_clk); 00112 _spi->format(8,0); 00113 _spi->frequency(8000000); // Max SPI speed for display is 10 and for 17 for LPC15xx 00114 #endif 00115 cbi(_pinCS, _bitmaskCS); 00116 delay(135); // This much delay needed?? 00117 00118 // ILI9341 init 00119 sendCommand(0x11); 00120 delay(120); 00121 00122 sendCommand(0xCF); 00123 send8BitData(0x00); 00124 send8BitData(0xc3); 00125 send8BitData(0X30); 00126 00127 sendCommand(0xED); 00128 send8BitData(0x64); 00129 send8BitData(0x03); 00130 send8BitData(0X12); 00131 send8BitData(0X81); 00132 00133 sendCommand(0xE8); 00134 send8BitData(0x85); 00135 send8BitData(0x10); 00136 send8BitData(0x79); 00137 00138 sendCommand(0xCB); 00139 send8BitData(0x39); 00140 send8BitData(0x2C); 00141 send8BitData(0x00); 00142 send8BitData(0x34); 00143 send8BitData(0x02); 00144 00145 sendCommand(0xF7); 00146 send8BitData(0x20); 00147 00148 sendCommand(0xEA); 00149 send8BitData(0x00); 00150 send8BitData(0x00); 00151 00152 sendCommand(0xC0); //Power control 00153 send8BitData(0x22); //VRH[5:0] 00154 00155 sendCommand(0xC1); //Power control 00156 send8BitData(0x11); //SAP[2:0];BT[3:0] 00157 00158 sendCommand(0xC5); //VCM control 00159 send8BitData(0x3d); 00160 send8BitData(0x20); 00161 00162 sendCommand(0xC7); //VCM control2 00163 send8BitData(0xAA); //0xB0 00164 00165 sendCommand(0x36); // Memory Access Control 00166 send8BitData(0x08); 00167 00168 sendCommand(0x3A); 00169 send8BitData(0x55); 00170 00171 sendCommand(0xB1); 00172 send8BitData(0x00); 00173 send8BitData(0x13); 00174 00175 sendCommand(0xB6); // Display Function Control 00176 send8BitData(0x0A); 00177 send8BitData(0xA2); 00178 00179 sendCommand(0xF6); 00180 send8BitData(0x01); 00181 send8BitData(0x30); 00182 00183 sendCommand(0xF2); // 3Gamma Function Disable 00184 send8BitData(0x00); 00185 00186 sendCommand(0x26); //Gamma curve selected 00187 send8BitData(0x01); 00188 00189 sendCommand(0xE0); //Set Gamma 00190 send8BitData(0x0F); 00191 send8BitData(0x3F); 00192 send8BitData(0x2F); 00193 send8BitData(0x0C); 00194 send8BitData(0x10); 00195 send8BitData(0x0A); 00196 send8BitData(0x53); 00197 send8BitData(0XD5); 00198 send8BitData(0x40); 00199 send8BitData(0x0A); 00200 send8BitData(0x13); 00201 send8BitData(0x03); 00202 send8BitData(0x08); 00203 send8BitData(0x03); 00204 send8BitData(0x00); 00205 00206 sendCommand(0XE1); //Set Gamma 00207 send8BitData(0x00); 00208 send8BitData(0x00); 00209 00210 send8BitData(0x10); 00211 send8BitData(0x03); 00212 send8BitData(0x0F); 00213 send8BitData(0x05); 00214 send8BitData(0x2C); 00215 send8BitData(0xA2); 00216 send8BitData(0x3F); 00217 send8BitData(0x05); 00218 send8BitData(0x0E); 00219 send8BitData(0x0C); 00220 send8BitData(0x37); 00221 send8BitData(0x3C); 00222 send8BitData(0x0F); 00223 00224 sendCommand(0x11); //Exit Sleep 00225 delay(120); 00226 sendCommand(0x29); //Display on 00227 delay(50); 00228 sbi(_pinCS, _bitmaskCS); 00229 clearScreen(); 00230 } 00231 00232 /********************************************************************************************************* 00233 END FILE 00234 *********************************************************************************************************/ 00235 00236
Generated on Tue Jul 12 2022 19:30:31 by 1.7.2