Driver Library for our displays

Dependents:   dm_bubbles dm_calc dm_paint dm_sdcard_with_adapter ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DmTftS6D0164.cpp Source File

DmTftS6D0164.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 platform.
00014 
00015 #include "DmTftS6D0164.h"
00016 
00017 #if defined (DM_TOOLCHAIN_ARDUINO)
00018 DmTftS6D0164::DmTftS6D0164(uint8_t wr, uint8_t cs, uint8_t dc, uint8_t rst) : DmTftBase(176, 220) 
00019 #elif defined (DM_TOOLCHAIN_MBED)  
00020 DmTftS6D0164::DmTftS6D0164(PinName wr, PinName cs, PinName dc, PinName rst) : DmTftBase(176, 220) 
00021 #endif
00022 {
00023   _wr = wr;
00024   _cs = cs;
00025   _dc = dc;
00026   _rst = rst;
00027 }
00028 
00029 DmTftS6D0164::~DmTftS6D0164() {
00030 #if defined (DM_TOOLCHAIN_MBED)
00031   delete _pinRST;
00032   delete _pinCS;
00033   delete _pinWR;
00034   delete _pinDC;
00035   delete _virtualPortD;
00036   _pinRST = NULL;
00037   _pinCS = NULL;
00038   _pinWR = NULL;
00039   _pinDC = NULL;
00040   _virtualPortD = NULL;
00041 #endif
00042 }
00043 
00044 void DmTftS6D0164::writeBus(uint8_t data) {
00045 #if defined (DM_TOOLCHAIN_ARDUINO)
00046   PORTD = data;
00047 #elif defined (DM_TOOLCHAIN_MBED)
00048   *_virtualPortD = data;
00049 #endif
00050   pulse_low(_pinWR, _bitmaskWR);
00051 }
00052 
00053 void DmTftS6D0164::sendCommand(uint8_t index) {
00054   cbi(_pinDC, _bitmaskDC);
00055   writeBus(index);
00056 }
00057 
00058 void DmTftS6D0164::sendData(uint16_t data) {
00059   sbi(_pinDC, _bitmaskDC);
00060   writeBus(data>>8);
00061   writeBus(data);
00062 }
00063 
00064 void DmTftS6D0164::setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
00065   sendCommand(0x37); // Set Column
00066   sendData(x0);
00067   sendCommand(0x36);
00068   sendData(x1);
00069 
00070 
00071   sendCommand(0x39);  // Set Page
00072   sendData(y0);
00073   sendCommand(0x38);
00074   sendData(y1);
00075 
00076   sendCommand(0x20);
00077   sendData(x0);
00078   sendCommand(0x21);
00079   sendData(y0);
00080   sendCommand(0x22);
00081 }
00082 
00083 void DmTftS6D0164::init(void) {
00084   setTextColor(BLACK, WHITE);
00085 #if defined (DM_TOOLCHAIN_ARDUINO)
00086 /**************************************
00087       DM-DmTftS6D016422-102     Arduino UNO             NUM
00088 
00089       RST                       A2                      16
00090       CS                        A3                      17
00091       WR                        A4                      18
00092       RS                        A5                      19
00093 
00094       DB8                       0                       0
00095       DB9                       1                       1
00096       DB10                      2                       2
00097       DB11                      3                       3
00098       DB12                      4                       4
00099       DB13                      5                       5
00100       DB14                      6                       6
00101       DB15                      7                       7
00102 
00103 ***************************************/
00104   DDRD = DDRD | B11111111;  // SET PORT D AS OUTPUT
00105 
00106   _pinRST = portOutputRegister(digitalPinToPort(_rst));
00107   _bitmaskRST = digitalPinToBitMask(_rst);
00108   _pinCS = portOutputRegister(digitalPinToPort(_cs));
00109   _bitmaskCS = digitalPinToBitMask(_cs);
00110   _pinWR = portOutputRegister(digitalPinToPort(_wr));
00111   _bitmaskWR = digitalPinToBitMask(_wr);
00112   _pinDC = portOutputRegister(digitalPinToPort(_dc));
00113   _bitmaskDC = digitalPinToBitMask(_dc);
00114 
00115   pinMode(_rst, OUTPUT);
00116   pinMode(_cs, OUTPUT);
00117   pinMode(_wr, OUTPUT);
00118   pinMode(_dc,OUTPUT);
00119 #elif defined (DM_TOOLCHAIN_MBED)
00120   _pinRST = new DigitalOut(_rst);
00121   _pinCS = new DigitalOut(_cs);
00122   _pinWR = new DigitalOut(_wr);
00123   _pinDC = new DigitalOut(_dc);
00124   _virtualPortD = new BusOut(D0, D1, D2, D3, D4, SPECIAL_D5, D6, D7);
00125 #endif
00126 
00127   sbi(_pinRST, _bitmaskRST);
00128   delay(5);
00129   cbi(_pinRST, _bitmaskRST);
00130   delay(15);
00131   sbi(_pinRST, _bitmaskRST);
00132   sbi(_pinCS, _bitmaskCS);
00133   sbi(_pinWR, _bitmaskWR);
00134   delay(15);
00135   cbi(_pinCS, _bitmaskCS);
00136 
00137   // Power up sequence
00138   sendCommand(0x11); sendData(0x001A);            // S6D0164 INIT
00139   sendCommand(0x12); sendData(0x3121);
00140   sendCommand(0x13); sendData(0x006C);
00141   sendCommand(0x14); sendData(0x4249);
00142   sendCommand(0x10); sendData(0x0800);
00143   delay(10);
00144   sendCommand(0x11); sendData(0x011A);
00145   delay(10);
00146   sendCommand(0x11); sendData(0x031A);
00147   delay(10);
00148   sendCommand(0x11); sendData(0x071A);
00149   delay(10);
00150   sendCommand(0x11); sendData(0x0F1A);
00151   delay(20);
00152   sendCommand(0x11); sendData(0x0F3A);
00153   delay(30);
00154   // Initialization set sequence
00155   sendCommand(0x01); sendData(0x011C);
00156   sendCommand(0x02); sendData(0x0100);
00157   sendCommand(0x03); sendData(0x1030);
00158   sendCommand(0x07); sendData(0x0000);
00159   sendCommand(0x08); sendData(0x0808);
00160   sendCommand(0x0B); sendData(0x1100);
00161   sendCommand(0x0C); sendData(0x0000);
00162   sendCommand(0x0F); sendData(0x1401);
00163   sendCommand(0x15); sendData(0x0000);
00164   sendCommand(0x20); sendData(0x0000);
00165   sendCommand(0x21); sendData(0x0000);
00166 
00167   sendCommand(0x38); sendData(0x00DB);
00168   sendCommand(0x39); sendData(0x0000);
00169   sendCommand(0x50); sendData(0x0001);
00170   sendCommand(0x51); sendData(0x020B);
00171   sendCommand(0x52); sendData(0x0805);
00172   sendCommand(0x53); sendData(0x0404);
00173   sendCommand(0x54); sendData(0x0C0C);
00174   sendCommand(0x55); sendData(0x000C);
00175   sendCommand(0x56); sendData(0x0101);
00176   sendCommand(0x57); sendData(0x0400);
00177   sendCommand(0x58); sendData(0x1108);
00178   sendCommand(0x59); sendData(0x050C);
00179   sendCommand(0x36); sendData(0x00AF);
00180   sendCommand(0x37); sendData(0x0000);
00181   sendCommand(0x38); sendData(0x00DB);
00182   sendCommand(0x39); sendData(0x0000);
00183   sendCommand(0x0F); sendData(0x0B01);
00184   sendCommand(0x07); sendData(0x0016);
00185   delay(2);
00186   sendCommand(0x07); sendData(0x0017);
00187   sendCommand(0x22);
00188   delay(10);
00189   sbi(_pinCS, _bitmaskCS);
00190 
00191   clearScreen();
00192 }
00193 
00194 /*********************************************************************************************************
00195   END FILE
00196 *********************************************************************************************************/
00197 
00198