Caiou
Dependents: LCD_Proj LCD_imagetest LCD_Proj_rtc
Fork of DmTftLibrary by
DmTftIli9325.cpp@17:67d1b918afe2, 2015-12-21 (annotated)
- Committer:
- Nikolas
- Date:
- Mon Dec 21 14:29:20 2015 +0000
- Revision:
- 17:67d1b918afe2
- Parent:
- 14:2db7065edbec
,jggfjlf;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
displaymodule | 0:d6ff5fa503e8 | 1 | /********************************************************************************************** |
displaymodule | 0:d6ff5fa503e8 | 2 | Copyright (c) 2014 DisplayModule. All rights reserved. |
displaymodule | 0:d6ff5fa503e8 | 3 | |
displaymodule | 0:d6ff5fa503e8 | 4 | Redistribution and use of this source code, part of this source code or any compiled binary |
displaymodule | 0:d6ff5fa503e8 | 5 | based on this source code is permitted as long as the above copyright notice and following |
displaymodule | 0:d6ff5fa503e8 | 6 | disclaimer is retained. |
displaymodule | 0:d6ff5fa503e8 | 7 | |
displaymodule | 0:d6ff5fa503e8 | 8 | DISCLAIMER: |
displaymodule | 0:d6ff5fa503e8 | 9 | THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES |
displaymodule | 0:d6ff5fa503e8 | 10 | NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. |
displaymodule | 0:d6ff5fa503e8 | 11 | ********************************************************************************************/ |
displaymodule | 14:2db7065edbec | 12 | |
displaymodule | 14:2db7065edbec | 13 | //Tested on NUCLEO-F401RE, LPCXpresso11U68 platform. |
displaymodule | 14:2db7065edbec | 14 | |
displaymodule | 0:d6ff5fa503e8 | 15 | #include "DmTftIli9325.h" |
displaymodule | 0:d6ff5fa503e8 | 16 | |
displaymodule | 14:2db7065edbec | 17 | #if defined (DM_TOOLCHAIN_ARDUINO) |
displaymodule | 14:2db7065edbec | 18 | DmTftIli9325::DmTftIli9325(uint8_t wr, uint8_t cs, uint8_t dc, uint8_t rst) : DmTftBase(240, 320) |
displaymodule | 14:2db7065edbec | 19 | #elif defined (DM_TOOLCHAIN_MBED) |
displaymodule | 14:2db7065edbec | 20 | DmTftIli9325::DmTftIli9325(PinName wr, PinName cs, PinName dc, PinName rst) : DmTftBase(240, 320) |
displaymodule | 14:2db7065edbec | 21 | #endif |
displaymodule | 14:2db7065edbec | 22 | { |
displaymodule | 14:2db7065edbec | 23 | _wr = wr; |
displaymodule | 14:2db7065edbec | 24 | _cs = cs; |
displaymodule | 14:2db7065edbec | 25 | _dc = dc; |
displaymodule | 14:2db7065edbec | 26 | _rst = rst; |
displaymodule | 0:d6ff5fa503e8 | 27 | } |
displaymodule | 0:d6ff5fa503e8 | 28 | |
displaymodule | 0:d6ff5fa503e8 | 29 | DmTftIli9325::~DmTftIli9325() { |
displaymodule | 14:2db7065edbec | 30 | #if defined (DM_TOOLCHAIN_MBED) |
displaymodule | 0:d6ff5fa503e8 | 31 | delete _pinRST; |
displaymodule | 0:d6ff5fa503e8 | 32 | delete _pinCS; |
displaymodule | 0:d6ff5fa503e8 | 33 | delete _pinWR; |
displaymodule | 0:d6ff5fa503e8 | 34 | delete _pinDC; |
displaymodule | 0:d6ff5fa503e8 | 35 | delete _virtualPortD; |
displaymodule | 0:d6ff5fa503e8 | 36 | _pinRST = NULL; |
displaymodule | 0:d6ff5fa503e8 | 37 | _pinCS = NULL; |
displaymodule | 0:d6ff5fa503e8 | 38 | _pinWR = NULL; |
displaymodule | 0:d6ff5fa503e8 | 39 | _pinDC = NULL; |
displaymodule | 0:d6ff5fa503e8 | 40 | _virtualPortD = NULL; |
displaymodule | 14:2db7065edbec | 41 | #endif |
displaymodule | 0:d6ff5fa503e8 | 42 | } |
displaymodule | 0:d6ff5fa503e8 | 43 | |
displaymodule | 0:d6ff5fa503e8 | 44 | void DmTftIli9325::writeBus(uint8_t data) { |
displaymodule | 0:d6ff5fa503e8 | 45 | #if defined (DM_TOOLCHAIN_ARDUINO) |
displaymodule | 0:d6ff5fa503e8 | 46 | PORTD = data; |
displaymodule | 0:d6ff5fa503e8 | 47 | #elif defined (DM_TOOLCHAIN_MBED) |
displaymodule | 14:2db7065edbec | 48 | *_virtualPortD = data; |
displaymodule | 14:2db7065edbec | 49 | //if(data & 0x10) |
displaymodule | 0:d6ff5fa503e8 | 50 | #endif |
displaymodule | 0:d6ff5fa503e8 | 51 | pulse_low(_pinWR, _bitmaskWR); |
displaymodule | 0:d6ff5fa503e8 | 52 | } |
displaymodule | 0:d6ff5fa503e8 | 53 | |
displaymodule | 0:d6ff5fa503e8 | 54 | void DmTftIli9325::sendCommand(uint8_t index) { |
displaymodule | 0:d6ff5fa503e8 | 55 | cbi(_pinDC, _bitmaskDC); |
displaymodule | 0:d6ff5fa503e8 | 56 | writeBus(0x00); |
displaymodule | 0:d6ff5fa503e8 | 57 | writeBus(index); |
displaymodule | 0:d6ff5fa503e8 | 58 | } |
displaymodule | 0:d6ff5fa503e8 | 59 | |
displaymodule | 0:d6ff5fa503e8 | 60 | void DmTftIli9325::sendData(uint16_t data) { |
displaymodule | 0:d6ff5fa503e8 | 61 | sbi(_pinDC, _bitmaskDC); |
displaymodule | 0:d6ff5fa503e8 | 62 | writeBus(data>>8); |
displaymodule | 0:d6ff5fa503e8 | 63 | writeBus(data); |
displaymodule | 0:d6ff5fa503e8 | 64 | } |
displaymodule | 0:d6ff5fa503e8 | 65 | |
displaymodule | 0:d6ff5fa503e8 | 66 | void DmTftIli9325::setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { |
displaymodule | 0:d6ff5fa503e8 | 67 | sendCommand(0x50); // Set Column |
displaymodule | 0:d6ff5fa503e8 | 68 | sendData(x0); |
displaymodule | 0:d6ff5fa503e8 | 69 | sendCommand(0x51); |
displaymodule | 0:d6ff5fa503e8 | 70 | sendData(x1); |
displaymodule | 0:d6ff5fa503e8 | 71 | |
displaymodule | 0:d6ff5fa503e8 | 72 | sendCommand(0x52); // Set Page |
displaymodule | 0:d6ff5fa503e8 | 73 | sendData(y0); |
displaymodule | 0:d6ff5fa503e8 | 74 | sendCommand(0x53); |
displaymodule | 0:d6ff5fa503e8 | 75 | sendData(y1); |
displaymodule | 0:d6ff5fa503e8 | 76 | |
displaymodule | 0:d6ff5fa503e8 | 77 | sendCommand(0x20); |
displaymodule | 0:d6ff5fa503e8 | 78 | sendData(x0); |
displaymodule | 0:d6ff5fa503e8 | 79 | sendCommand(0x21); |
displaymodule | 0:d6ff5fa503e8 | 80 | sendData(y0); |
displaymodule | 0:d6ff5fa503e8 | 81 | sendCommand(0x22); |
displaymodule | 0:d6ff5fa503e8 | 82 | } |
displaymodule | 0:d6ff5fa503e8 | 83 | |
displaymodule | 0:d6ff5fa503e8 | 84 | void DmTftIli9325::init(void) { |
displaymodule | 0:d6ff5fa503e8 | 85 | setTextColor(BLACK, WHITE); |
displaymodule | 0:d6ff5fa503e8 | 86 | #if defined (DM_TOOLCHAIN_ARDUINO) |
displaymodule | 0:d6ff5fa503e8 | 87 | /************************************** |
displaymodule | 0:d6ff5fa503e8 | 88 | DM-DmTftIli932522-102 Arduino UNO NUM |
displaymodule | 0:d6ff5fa503e8 | 89 | |
displaymodule | 0:d6ff5fa503e8 | 90 | RST A2 16 |
displaymodule | 0:d6ff5fa503e8 | 91 | CS A3 17 |
displaymodule | 0:d6ff5fa503e8 | 92 | WR A4 18 |
displaymodule | 0:d6ff5fa503e8 | 93 | RS A5 19 |
displaymodule | 0:d6ff5fa503e8 | 94 | |
displaymodule | 0:d6ff5fa503e8 | 95 | DB8 0 0 |
displaymodule | 0:d6ff5fa503e8 | 96 | DB9 1 1 |
displaymodule | 0:d6ff5fa503e8 | 97 | DB10 2 2 |
displaymodule | 0:d6ff5fa503e8 | 98 | DB11 3 3 |
displaymodule | 0:d6ff5fa503e8 | 99 | DB12 4 4 |
displaymodule | 0:d6ff5fa503e8 | 100 | DB13 5 5 |
displaymodule | 0:d6ff5fa503e8 | 101 | DB14 6 6 |
displaymodule | 0:d6ff5fa503e8 | 102 | DB15 7 7 |
displaymodule | 0:d6ff5fa503e8 | 103 | |
displaymodule | 0:d6ff5fa503e8 | 104 | ***************************************/ |
displaymodule | 0:d6ff5fa503e8 | 105 | DDRD = DDRD | B11111111; // SET PORT D AS OUTPUT |
displaymodule | 0:d6ff5fa503e8 | 106 | |
displaymodule | 0:d6ff5fa503e8 | 107 | _pinRST = portOutputRegister(digitalPinToPort(_rst)); |
displaymodule | 0:d6ff5fa503e8 | 108 | _bitmaskRST = digitalPinToBitMask(_rst); |
displaymodule | 0:d6ff5fa503e8 | 109 | _pinCS = portOutputRegister(digitalPinToPort(_cs)); |
displaymodule | 0:d6ff5fa503e8 | 110 | _bitmaskCS = digitalPinToBitMask(_cs); |
displaymodule | 0:d6ff5fa503e8 | 111 | _pinWR = portOutputRegister(digitalPinToPort(_wr)); |
displaymodule | 0:d6ff5fa503e8 | 112 | _bitmaskWR = digitalPinToBitMask(_wr); |
displaymodule | 0:d6ff5fa503e8 | 113 | _pinDC = portOutputRegister(digitalPinToPort(_dc)); |
displaymodule | 0:d6ff5fa503e8 | 114 | _bitmaskDC = digitalPinToBitMask(_dc); |
displaymodule | 0:d6ff5fa503e8 | 115 | |
displaymodule | 0:d6ff5fa503e8 | 116 | pinMode(_rst, OUTPUT); |
displaymodule | 0:d6ff5fa503e8 | 117 | pinMode(_cs, OUTPUT); |
displaymodule | 0:d6ff5fa503e8 | 118 | pinMode(_wr, OUTPUT); |
displaymodule | 0:d6ff5fa503e8 | 119 | pinMode(_dc,OUTPUT); |
displaymodule | 0:d6ff5fa503e8 | 120 | #elif defined (DM_TOOLCHAIN_MBED) |
displaymodule | 14:2db7065edbec | 121 | _pinRST = new DigitalOut(_rst); |
displaymodule | 14:2db7065edbec | 122 | _pinCS = new DigitalOut(_cs); |
displaymodule | 14:2db7065edbec | 123 | _pinWR = new DigitalOut(_wr); |
displaymodule | 14:2db7065edbec | 124 | _pinDC = new DigitalOut(_dc); |
displaymodule | 14:2db7065edbec | 125 | _virtualPortD = new BusOut(D0, D1, D2, D3, D4, SPECIAL_D5, D6, D7); // LPC15XX_H |
displaymodule | 0:d6ff5fa503e8 | 126 | #endif |
displaymodule | 0:d6ff5fa503e8 | 127 | |
displaymodule | 0:d6ff5fa503e8 | 128 | sbi(_pinRST, _bitmaskRST); |
displaymodule | 14:2db7065edbec | 129 | |
displaymodule | 0:d6ff5fa503e8 | 130 | delay(5); |
displaymodule | 0:d6ff5fa503e8 | 131 | cbi(_pinRST, _bitmaskRST); |
displaymodule | 14:2db7065edbec | 132 | |
displaymodule | 0:d6ff5fa503e8 | 133 | delay(15); |
displaymodule | 0:d6ff5fa503e8 | 134 | sbi(_pinRST, _bitmaskRST); |
displaymodule | 0:d6ff5fa503e8 | 135 | sbi(_pinCS, _bitmaskCS); |
displaymodule | 0:d6ff5fa503e8 | 136 | sbi(_pinWR, _bitmaskWR); |
displaymodule | 14:2db7065edbec | 137 | |
displaymodule | 0:d6ff5fa503e8 | 138 | delay(15); |
displaymodule | 0:d6ff5fa503e8 | 139 | cbi(_pinCS, _bitmaskCS); |
displaymodule | 0:d6ff5fa503e8 | 140 | |
displaymodule | 14:2db7065edbec | 141 | |
displaymodule | 14:2db7065edbec | 142 | |
displaymodule | 0:d6ff5fa503e8 | 143 | sendCommand(0xE5); sendData(0x78F0); |
displaymodule | 0:d6ff5fa503e8 | 144 | sendCommand(0x01); sendData(0x0100); |
displaymodule | 0:d6ff5fa503e8 | 145 | sendCommand(0x02); sendData(0x0700); |
displaymodule | 0:d6ff5fa503e8 | 146 | sendCommand(0x03); sendData(0x1030); |
displaymodule | 0:d6ff5fa503e8 | 147 | sendCommand(0x04); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 148 | sendCommand(0x08); sendData(0x0207); |
displaymodule | 0:d6ff5fa503e8 | 149 | sendCommand(0x09); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 150 | sendCommand(0x0A); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 151 | sendCommand(0x0C); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 152 | sendCommand(0x0D); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 153 | sendCommand(0x0F); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 154 | |
displaymodule | 0:d6ff5fa503e8 | 155 | sendCommand(0x10); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 156 | sendCommand(0x11); sendData(0x0007); |
displaymodule | 0:d6ff5fa503e8 | 157 | sendCommand(0x12); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 158 | sendCommand(0x13); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 159 | |
displaymodule | 0:d6ff5fa503e8 | 160 | sendCommand(0x10); sendData(0x1290); |
displaymodule | 0:d6ff5fa503e8 | 161 | sendCommand(0x11); sendData(0x0227); |
displaymodule | 0:d6ff5fa503e8 | 162 | sendCommand(0x12); sendData(0x001D); |
displaymodule | 0:d6ff5fa503e8 | 163 | sendCommand(0x13); sendData(0x1500); |
displaymodule | 0:d6ff5fa503e8 | 164 | |
displaymodule | 0:d6ff5fa503e8 | 165 | sendCommand(0x29); sendData(0x0018); |
displaymodule | 0:d6ff5fa503e8 | 166 | sendCommand(0x2B); sendData(0x000D); |
displaymodule | 0:d6ff5fa503e8 | 167 | |
displaymodule | 0:d6ff5fa503e8 | 168 | sendCommand(0x30); sendData(0x0004); |
displaymodule | 0:d6ff5fa503e8 | 169 | sendCommand(0x31); sendData(0x0307); |
displaymodule | 0:d6ff5fa503e8 | 170 | sendCommand(0x32); sendData(0x0002); |
displaymodule | 0:d6ff5fa503e8 | 171 | sendCommand(0x35); sendData(0x0206); |
displaymodule | 0:d6ff5fa503e8 | 172 | sendCommand(0x36); sendData(0x0408); |
displaymodule | 0:d6ff5fa503e8 | 173 | sendCommand(0x37); sendData(0x0507); |
displaymodule | 0:d6ff5fa503e8 | 174 | sendCommand(0x38); sendData(0x0204); |
displaymodule | 0:d6ff5fa503e8 | 175 | sendCommand(0x39); sendData(0x0707); |
displaymodule | 0:d6ff5fa503e8 | 176 | sendCommand(0x3C); sendData(0x0405); |
displaymodule | 0:d6ff5fa503e8 | 177 | sendCommand(0x3D); sendData(0x0f02); |
displaymodule | 0:d6ff5fa503e8 | 178 | |
displaymodule | 0:d6ff5fa503e8 | 179 | sendCommand(0x50); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 180 | sendCommand(0x51); sendData(0x00EF); |
displaymodule | 0:d6ff5fa503e8 | 181 | sendCommand(0x52); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 182 | sendCommand(0x53); sendData(0x013F); |
displaymodule | 0:d6ff5fa503e8 | 183 | sendCommand(0x60); sendData(0xA700); |
displaymodule | 0:d6ff5fa503e8 | 184 | sendCommand(0x61); sendData(0x0001); |
displaymodule | 0:d6ff5fa503e8 | 185 | sendCommand(0x6A); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 186 | |
displaymodule | 0:d6ff5fa503e8 | 187 | sendCommand(0x80); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 188 | sendCommand(0x81); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 189 | sendCommand(0x82); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 190 | sendCommand(0x83); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 191 | sendCommand(0x84); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 192 | sendCommand(0x85); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 193 | |
displaymodule | 0:d6ff5fa503e8 | 194 | sendCommand(0x90); sendData(0x0010); |
displaymodule | 0:d6ff5fa503e8 | 195 | sendCommand(0x92); sendData(0x0600); |
displaymodule | 0:d6ff5fa503e8 | 196 | sendCommand(0x93); sendData(0x0003); |
displaymodule | 0:d6ff5fa503e8 | 197 | sendCommand(0x95); sendData(0x0110); |
displaymodule | 0:d6ff5fa503e8 | 198 | sendCommand(0x97); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 199 | sendCommand(0x98); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 200 | sendCommand(0x07); sendData(0x0133); |
displaymodule | 0:d6ff5fa503e8 | 201 | sbi(_pinCS, _bitmaskCS); |
displaymodule | 7:6cd8c36cbdb3 | 202 | delay(500); |
displaymodule | 0:d6ff5fa503e8 | 203 | clearScreen(); |
displaymodule | 0:d6ff5fa503e8 | 204 | } |
displaymodule | 0:d6ff5fa503e8 | 205 | |
displaymodule | 0:d6ff5fa503e8 | 206 | /********************************************************************************************************* |
displaymodule | 0:d6ff5fa503e8 | 207 | END FILE |
displaymodule | 0:d6ff5fa503e8 | 208 | *********************************************************************************************************/ |
displaymodule | 0:d6ff5fa503e8 | 209 |