Driver Library for our displays
Dependents: dm_bubbles dm_calc dm_paint dm_sdcard_with_adapter ... more
DmTftSsd2119.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 //Tested on NUCLEO-F401RE, LPCXpresso11U68, LPCXpresso824-MAX platform. 00014 00015 #include "DmTftSsd2119.h" 00016 #if defined (DM_TOOLCHAIN_ARDUINO) 00017 DmTftSsd2119::DmTftSsd2119(uint8_t cs, uint8_t dc) 00018 :DmTftBase(320, 240) 00019 #elif defined (DM_TOOLCHAIN_MBED) 00020 DmTftSsd2119::DmTftSsd2119(PinName cs, PinName dc, PinName mosi, PinName miso, PinName clk) 00021 :DmTftBase(320, 240), spi(mosi, miso, clk) 00022 #endif 00023 { 00024 _cs = cs; 00025 _dc = dc; 00026 } 00027 00028 DmTftSsd2119::~DmTftSsd2119() { 00029 #if defined (DM_TOOLCHAIN_MBED) 00030 delete _pinCS; 00031 delete _pinDC; 00032 00033 _pinCS = NULL; 00034 _pinDC = NULL; 00035 #endif 00036 } 00037 00038 void DmTftSsd2119::writeBus(uint8_t data) { 00039 #if defined (DM_TOOLCHAIN_ARDUINO) 00040 SPCR = _spiSettings; // SPI Control Register 00041 SPDR = data; // SPI Data Register 00042 while(!(SPSR & _BV(SPIF))); // SPI Status Register Wait for transmission to finish 00043 #elif defined (DM_TOOLCHAIN_MBED) 00044 spi.write(data); 00045 #endif 00046 } 00047 00048 void DmTftSsd2119::sendCommand(uint8_t index) { 00049 cbi(_pinDC, _bitmaskDC); 00050 writeBus(0x00); 00051 writeBus(index); 00052 } 00053 00054 void DmTftSsd2119::send8BitData(uint8_t data) { 00055 sbi(_pinDC, _bitmaskDC); 00056 writeBus(data); 00057 } 00058 00059 void DmTftSsd2119::sendData(uint16_t data) { 00060 uint8_t dh = data>>8; 00061 uint8_t dl = data&0xff; 00062 00063 sbi(_pinDC, _bitmaskDC); 00064 writeBus(dh); 00065 writeBus(dl); 00066 } 00067 00068 void DmTftSsd2119::setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { 00069 // Set Start and End Vertical RAM address position 00070 uint16_t verticalStartEndAddress; 00071 verticalStartEndAddress = y0&0xff; // Start vertical RAM address 00072 verticalStartEndAddress += (y1&0xff)<<8; // End vertical RAM address 00073 00074 sendCommand(0x44); 00075 sendData(verticalStartEndAddress); 00076 00077 sendCommand(0x45); // Set Start Horizontal RAM address position 00078 sendData(x0); 00079 00080 sendCommand(0x46); // Set End Horizontal RAM address position 00081 sendData(x1); 00082 00083 // Set start position 00084 sendCommand(0x4e); // Set Column, RAM address X (max 320) 00085 sendData(x0); 00086 sendCommand(0x4f); // Set Page, RAM address Y (max 240) 00087 sendData(y0); 00088 sendCommand(0x22); // RAM data write 00089 } 00090 00091 // Separate setPixel, because setAddress is to many instructions 00092 void DmTftSsd2119::setPixel(uint16_t x, uint16_t y, uint16_t color) { 00093 cbi(_pinCS, _bitmaskCS); 00094 00095 // setAddress(x, y, x, y); 00096 sendCommand(0x4e); // Set Column, RAM address X (max 320) 00097 sendData(x); 00098 00099 sendCommand(0x4f); // Set Page, RAM address Y (max 240) 00100 sendData(y); 00101 00102 sendCommand(0x22); 00103 sendData(color); 00104 00105 sbi(_pinCS, _bitmaskCS); 00106 } 00107 00108 void DmTftSsd2119::init(void) { 00109 setTextColor(BLACK, WHITE); 00110 #if defined (DM_TOOLCHAIN_ARDUINO) 00111 _pinCS = portOutputRegister(digitalPinToPort(_cs)); 00112 _bitmaskCS = digitalPinToBitMask(_cs); 00113 _pinDC = portOutputRegister(digitalPinToPort(_dc)); 00114 _bitmaskDC = digitalPinToBitMask(_dc); 00115 pinMode(_cs,OUTPUT); 00116 pinMode(_dc,OUTPUT); 00117 00118 sbi(_pinCS, _bitmaskCS); 00119 00120 SPI.begin(); 00121 SPI.setClockDivider(SPI_CLOCK_DIV2); // 8 MHz (full! speed!) 00122 SPI.setBitOrder(MSBFIRST); 00123 SPI.setDataMode(SPI_MODE0); 00124 _spiSettings = SPCR; 00125 #elif defined (DM_TOOLCHAIN_MBED) 00126 _pinCS = new DigitalOut(_cs); 00127 _pinDC = new DigitalOut(_dc); 00128 sbi(_pinCS, _bitmaskCS); 00129 00130 spi.format(8,0); 00131 spi.frequency(6000000); 00132 #endif 00133 cbi(_pinCS, _bitmaskCS); 00134 delay(135); // This much delay needed?? 00135 00136 delay(120); 00137 00138 sendCommand(0x28); // VCOM OTP 00139 sendData(0x0006); 00140 00141 sendCommand(0x00); // Start Oscillator 00142 sendData(0x0001); 00143 00144 sendCommand(0x10); // Set Sleep mode 00145 sendData(0x0000); // Sleep out 00146 delay(30); 00147 00148 sendCommand(0x11); // Entry Mode ,SET LCM interface Mode. 00149 sendData(0x6870); // SET 65K colors,MCU interface Mode.TypeB ,ID=11 AM=0 the address counter is updated in the horizontal direction. 00150 00151 sendCommand(0x15); // Generic Interface Control. DOCLK,HSYNC,VSYNC,DE 00152 sendData(0x0000); 00153 00154 sendCommand(0x01); // Driver Output Control 00155 sendData(0x72EF); // Set REV,GD,BGR,SM,RL,TB 00156 00157 sendCommand(0x02); // LCD Driving Waveform Control,LCD 00158 sendData(0x0600); 00159 00160 sendCommand(0x08); // Set the scanning starting position of the gate driver. 00161 sendData(0x0000); // The valid range is from 1 to 240 00162 00163 // LCD POWER CONTROL 00164 sendCommand(0x03); // Power Control 1, VGH,VGL 00165 sendData(0x6A38); // Set dct=fline*4, VGH=2 x VCIX2 + VCI,VGL=-(VGH) + VCix2, DC=Fline × 8, AP=Medium to large 00166 00167 sendCommand(0X0B); // Frame Cycle Control. 00168 sendData(0x5308); // SET NO SDT=1 clock cycle (POR) ,Sets the equalizing period, 00169 00170 sendCommand(0x0C); // Power Control 2 VCIX2 00171 sendData(0x0003); // Adjust VCIX2 output voltage=5.7V 00172 00173 sendCommand(0x0D); // Set amplitude magnification of VLCD63 00174 sendData(0x000A); // vlcd63=VREF(2.0V)* 2.335V 00175 00176 sendCommand(0x0E); // SET VCOMG VDV .VCOM 00177 sendData(0x2B00); // SET VCOMG=1,VCOM=VLCD63* //2A 00178 00179 sendCommand(0X0F); // Gate Scan Position. 00180 sendData(0x0000); // The valid range is from 1 to 240. 00181 00182 sendCommand(0x1E); // SET nOTP VCOMH ,VCOMH 00183 sendData(0x00B7); // SET nOTP=0, VCOMH=VLCD63* //B8 00184 00185 sendCommand(0x25); // Frame Frequency Control 00186 sendData(0x8000); // SET OSC 65Hz //0A-70hz 00187 00188 sendCommand(0x26); // Analog setting 00189 sendData(0x3800); 00190 00191 sendCommand(0x27); // Analog setting 00192 sendData(0x0078); 00193 00194 //sendCommand(0x12); // Sleep mode 00195 //sendData(0xD999); 00196 00197 // SET WINDOW 00198 sendCommand(0x4E); // Ram Address Set 00199 sendData(0x0000); 00200 00201 sendCommand(0x4F); // Ram Address Set 00202 sendData(0x0000); 00203 00204 // Gamma Control 00205 sendCommand(0x30); 00206 sendData(0x0000);//1 00207 00208 sendCommand(0x31); 00209 sendData(0x0104);//2 00210 00211 sendCommand(0x32); 00212 sendData(0x0100);//3 00213 00214 sendCommand(0x33); 00215 sendData(0x0305);//4 00216 00217 sendCommand(0x34); 00218 sendData(0x0505);//4 00219 00220 sendCommand(0x35); 00221 sendData(0x0305);//5 00222 00223 sendCommand(0x36); 00224 sendData(0x0707);//6 00225 00226 sendCommand(0x37); 00227 sendData(0x0300);//7 00228 00229 sendCommand(0x3A); 00230 sendData(0x1200);//8 00231 00232 sendCommand(0x3B); 00233 sendData(0x0800);//9 00234 00235 // Final init 00236 delay(300); 00237 sendCommand(0x07); // Display Control 00238 00239 sendData(0x0033); // Display on 00240 delay(100); 00241 00242 sendCommand(0x22); // RAM data write/read 00243 00244 delay(50); 00245 sbi(_pinCS, _bitmaskCS); 00246 clearScreen(); 00247 } 00248 00249 /********************************************************************************************************* 00250 END FILE 00251 *********************************************************************************************************/
Generated on Wed Jul 13 2022 04:21:40 by 1.7.2