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 Display Module

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DmTftSsd2119.cpp Source File

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