Caiou
Dependents: LCD_Proj LCD_imagetest LCD_Proj_rtc
Fork of DmTftLibrary by
DmTftIli9325.cpp@7:6cd8c36cbdb3, 2014-07-04 (annotated)
- Committer:
- displaymodule
- Date:
- Fri Jul 04 09:26:32 2014 +0000
- Revision:
- 7:6cd8c36cbdb3
- Parent:
- 4:92d019216e28
- Child:
- 14:2db7065edbec
Improved handling of touch calibration
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 | 0:d6ff5fa503e8 | 12 | #include "DmTftIli9325.h" |
displaymodule | 0:d6ff5fa503e8 | 13 | |
displaymodule | 0:d6ff5fa503e8 | 14 | DmTftIli9325::DmTftIli9325(uint8_t wr, uint8_t cs, uint8_t dc, uint8_t rst) : DmTftBase(240, 320) { |
displaymodule | 0:d6ff5fa503e8 | 15 | _wr = wr; |
displaymodule | 0:d6ff5fa503e8 | 16 | _cs = cs; |
displaymodule | 0:d6ff5fa503e8 | 17 | _dc = dc; |
displaymodule | 0:d6ff5fa503e8 | 18 | _rst = rst; |
displaymodule | 0:d6ff5fa503e8 | 19 | } |
displaymodule | 0:d6ff5fa503e8 | 20 | |
displaymodule | 0:d6ff5fa503e8 | 21 | DmTftIli9325::~DmTftIli9325() { |
displaymodule | 0:d6ff5fa503e8 | 22 | #if defined (DM_TOOLCHAIN_MBED) |
displaymodule | 0:d6ff5fa503e8 | 23 | delete _pinRST; |
displaymodule | 0:d6ff5fa503e8 | 24 | delete _pinCS; |
displaymodule | 0:d6ff5fa503e8 | 25 | delete _pinWR; |
displaymodule | 0:d6ff5fa503e8 | 26 | delete _pinDC; |
displaymodule | 0:d6ff5fa503e8 | 27 | delete _virtualPortD; |
displaymodule | 0:d6ff5fa503e8 | 28 | _pinRST = NULL; |
displaymodule | 0:d6ff5fa503e8 | 29 | _pinCS = NULL; |
displaymodule | 0:d6ff5fa503e8 | 30 | _pinWR = NULL; |
displaymodule | 0:d6ff5fa503e8 | 31 | _pinDC = NULL; |
displaymodule | 0:d6ff5fa503e8 | 32 | _virtualPortD = NULL; |
displaymodule | 0:d6ff5fa503e8 | 33 | #endif |
displaymodule | 0:d6ff5fa503e8 | 34 | } |
displaymodule | 0:d6ff5fa503e8 | 35 | |
displaymodule | 0:d6ff5fa503e8 | 36 | void DmTftIli9325::writeBus(uint8_t data) { |
displaymodule | 0:d6ff5fa503e8 | 37 | #if defined (DM_TOOLCHAIN_ARDUINO) |
displaymodule | 0:d6ff5fa503e8 | 38 | PORTD = data; |
displaymodule | 0:d6ff5fa503e8 | 39 | #elif defined (DM_TOOLCHAIN_MBED) |
displaymodule | 0:d6ff5fa503e8 | 40 | *_virtualPortD = data; |
displaymodule | 0:d6ff5fa503e8 | 41 | #endif |
displaymodule | 0:d6ff5fa503e8 | 42 | pulse_low(_pinWR, _bitmaskWR); |
displaymodule | 0:d6ff5fa503e8 | 43 | } |
displaymodule | 0:d6ff5fa503e8 | 44 | |
displaymodule | 0:d6ff5fa503e8 | 45 | void DmTftIli9325::sendCommand(uint8_t index) { |
displaymodule | 0:d6ff5fa503e8 | 46 | cbi(_pinDC, _bitmaskDC); |
displaymodule | 0:d6ff5fa503e8 | 47 | writeBus(0x00); |
displaymodule | 0:d6ff5fa503e8 | 48 | writeBus(index); |
displaymodule | 0:d6ff5fa503e8 | 49 | } |
displaymodule | 0:d6ff5fa503e8 | 50 | |
displaymodule | 0:d6ff5fa503e8 | 51 | void DmTftIli9325::sendData(uint16_t data) { |
displaymodule | 0:d6ff5fa503e8 | 52 | sbi(_pinDC, _bitmaskDC); |
displaymodule | 0:d6ff5fa503e8 | 53 | writeBus(data>>8); |
displaymodule | 0:d6ff5fa503e8 | 54 | writeBus(data); |
displaymodule | 0:d6ff5fa503e8 | 55 | } |
displaymodule | 0:d6ff5fa503e8 | 56 | |
displaymodule | 0:d6ff5fa503e8 | 57 | void DmTftIli9325::setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { |
displaymodule | 0:d6ff5fa503e8 | 58 | sendCommand(0x50); // Set Column |
displaymodule | 0:d6ff5fa503e8 | 59 | sendData(x0); |
displaymodule | 0:d6ff5fa503e8 | 60 | sendCommand(0x51); |
displaymodule | 0:d6ff5fa503e8 | 61 | sendData(x1); |
displaymodule | 0:d6ff5fa503e8 | 62 | |
displaymodule | 0:d6ff5fa503e8 | 63 | sendCommand(0x52); // Set Page |
displaymodule | 0:d6ff5fa503e8 | 64 | sendData(y0); |
displaymodule | 0:d6ff5fa503e8 | 65 | sendCommand(0x53); |
displaymodule | 0:d6ff5fa503e8 | 66 | sendData(y1); |
displaymodule | 0:d6ff5fa503e8 | 67 | |
displaymodule | 0:d6ff5fa503e8 | 68 | sendCommand(0x20); |
displaymodule | 0:d6ff5fa503e8 | 69 | sendData(x0); |
displaymodule | 0:d6ff5fa503e8 | 70 | sendCommand(0x21); |
displaymodule | 0:d6ff5fa503e8 | 71 | sendData(y0); |
displaymodule | 0:d6ff5fa503e8 | 72 | sendCommand(0x22); |
displaymodule | 0:d6ff5fa503e8 | 73 | } |
displaymodule | 0:d6ff5fa503e8 | 74 | |
displaymodule | 0:d6ff5fa503e8 | 75 | void DmTftIli9325::init(void) { |
displaymodule | 0:d6ff5fa503e8 | 76 | setTextColor(BLACK, WHITE); |
displaymodule | 0:d6ff5fa503e8 | 77 | #if defined (DM_TOOLCHAIN_ARDUINO) |
displaymodule | 0:d6ff5fa503e8 | 78 | /************************************** |
displaymodule | 0:d6ff5fa503e8 | 79 | DM-DmTftIli932522-102 Arduino UNO NUM |
displaymodule | 0:d6ff5fa503e8 | 80 | |
displaymodule | 0:d6ff5fa503e8 | 81 | RST A2 16 |
displaymodule | 0:d6ff5fa503e8 | 82 | CS A3 17 |
displaymodule | 0:d6ff5fa503e8 | 83 | WR A4 18 |
displaymodule | 0:d6ff5fa503e8 | 84 | RS A5 19 |
displaymodule | 0:d6ff5fa503e8 | 85 | |
displaymodule | 0:d6ff5fa503e8 | 86 | DB8 0 0 |
displaymodule | 0:d6ff5fa503e8 | 87 | DB9 1 1 |
displaymodule | 0:d6ff5fa503e8 | 88 | DB10 2 2 |
displaymodule | 0:d6ff5fa503e8 | 89 | DB11 3 3 |
displaymodule | 0:d6ff5fa503e8 | 90 | DB12 4 4 |
displaymodule | 0:d6ff5fa503e8 | 91 | DB13 5 5 |
displaymodule | 0:d6ff5fa503e8 | 92 | DB14 6 6 |
displaymodule | 0:d6ff5fa503e8 | 93 | DB15 7 7 |
displaymodule | 0:d6ff5fa503e8 | 94 | |
displaymodule | 0:d6ff5fa503e8 | 95 | ***************************************/ |
displaymodule | 0:d6ff5fa503e8 | 96 | DDRD = DDRD | B11111111; // SET PORT D AS OUTPUT |
displaymodule | 0:d6ff5fa503e8 | 97 | |
displaymodule | 0:d6ff5fa503e8 | 98 | _pinRST = portOutputRegister(digitalPinToPort(_rst)); |
displaymodule | 0:d6ff5fa503e8 | 99 | _bitmaskRST = digitalPinToBitMask(_rst); |
displaymodule | 0:d6ff5fa503e8 | 100 | _pinCS = portOutputRegister(digitalPinToPort(_cs)); |
displaymodule | 0:d6ff5fa503e8 | 101 | _bitmaskCS = digitalPinToBitMask(_cs); |
displaymodule | 0:d6ff5fa503e8 | 102 | _pinWR = portOutputRegister(digitalPinToPort(_wr)); |
displaymodule | 0:d6ff5fa503e8 | 103 | _bitmaskWR = digitalPinToBitMask(_wr); |
displaymodule | 0:d6ff5fa503e8 | 104 | _pinDC = portOutputRegister(digitalPinToPort(_dc)); |
displaymodule | 0:d6ff5fa503e8 | 105 | _bitmaskDC = digitalPinToBitMask(_dc); |
displaymodule | 0:d6ff5fa503e8 | 106 | |
displaymodule | 0:d6ff5fa503e8 | 107 | pinMode(_rst, OUTPUT); |
displaymodule | 0:d6ff5fa503e8 | 108 | pinMode(_cs, OUTPUT); |
displaymodule | 0:d6ff5fa503e8 | 109 | pinMode(_wr, OUTPUT); |
displaymodule | 0:d6ff5fa503e8 | 110 | pinMode(_dc,OUTPUT); |
displaymodule | 0:d6ff5fa503e8 | 111 | #elif defined (DM_TOOLCHAIN_MBED) |
displaymodule | 0:d6ff5fa503e8 | 112 | _pinRST = new DigitalOut((PinName)_rst); |
displaymodule | 0:d6ff5fa503e8 | 113 | _pinCS = new DigitalOut((PinName)_cs); |
displaymodule | 0:d6ff5fa503e8 | 114 | _pinWR = new DigitalOut((PinName)_wr); |
displaymodule | 0:d6ff5fa503e8 | 115 | _pinDC = new DigitalOut((PinName)_dc); |
displaymodule | 4:92d019216e28 | 116 | _virtualPortD = new BusOut(D0, D1, D2, D3, D4, SPECIAL_D5, D6, D7); |
displaymodule | 0:d6ff5fa503e8 | 117 | #endif |
displaymodule | 0:d6ff5fa503e8 | 118 | |
displaymodule | 0:d6ff5fa503e8 | 119 | sbi(_pinRST, _bitmaskRST); |
displaymodule | 0:d6ff5fa503e8 | 120 | delay(5); |
displaymodule | 0:d6ff5fa503e8 | 121 | cbi(_pinRST, _bitmaskRST); |
displaymodule | 0:d6ff5fa503e8 | 122 | delay(15); |
displaymodule | 0:d6ff5fa503e8 | 123 | sbi(_pinRST, _bitmaskRST); |
displaymodule | 0:d6ff5fa503e8 | 124 | sbi(_pinCS, _bitmaskCS); |
displaymodule | 0:d6ff5fa503e8 | 125 | sbi(_pinWR, _bitmaskWR); |
displaymodule | 0:d6ff5fa503e8 | 126 | delay(15); |
displaymodule | 0:d6ff5fa503e8 | 127 | cbi(_pinCS, _bitmaskCS); |
displaymodule | 0:d6ff5fa503e8 | 128 | |
displaymodule | 0:d6ff5fa503e8 | 129 | sendCommand(0xE5); sendData(0x78F0); |
displaymodule | 0:d6ff5fa503e8 | 130 | sendCommand(0x01); sendData(0x0100); |
displaymodule | 0:d6ff5fa503e8 | 131 | sendCommand(0x02); sendData(0x0700); |
displaymodule | 0:d6ff5fa503e8 | 132 | sendCommand(0x03); sendData(0x1030); |
displaymodule | 0:d6ff5fa503e8 | 133 | sendCommand(0x04); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 134 | sendCommand(0x08); sendData(0x0207); |
displaymodule | 0:d6ff5fa503e8 | 135 | sendCommand(0x09); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 136 | sendCommand(0x0A); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 137 | sendCommand(0x0C); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 138 | sendCommand(0x0D); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 139 | sendCommand(0x0F); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 140 | |
displaymodule | 0:d6ff5fa503e8 | 141 | sendCommand(0x10); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 142 | sendCommand(0x11); sendData(0x0007); |
displaymodule | 0:d6ff5fa503e8 | 143 | sendCommand(0x12); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 144 | sendCommand(0x13); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 145 | |
displaymodule | 0:d6ff5fa503e8 | 146 | sendCommand(0x10); sendData(0x1290); |
displaymodule | 0:d6ff5fa503e8 | 147 | sendCommand(0x11); sendData(0x0227); |
displaymodule | 0:d6ff5fa503e8 | 148 | sendCommand(0x12); sendData(0x001D); |
displaymodule | 0:d6ff5fa503e8 | 149 | sendCommand(0x13); sendData(0x1500); |
displaymodule | 0:d6ff5fa503e8 | 150 | |
displaymodule | 0:d6ff5fa503e8 | 151 | sendCommand(0x29); sendData(0x0018); |
displaymodule | 0:d6ff5fa503e8 | 152 | sendCommand(0x2B); sendData(0x000D); |
displaymodule | 0:d6ff5fa503e8 | 153 | |
displaymodule | 0:d6ff5fa503e8 | 154 | sendCommand(0x30); sendData(0x0004); |
displaymodule | 0:d6ff5fa503e8 | 155 | sendCommand(0x31); sendData(0x0307); |
displaymodule | 0:d6ff5fa503e8 | 156 | sendCommand(0x32); sendData(0x0002); |
displaymodule | 0:d6ff5fa503e8 | 157 | sendCommand(0x35); sendData(0x0206); |
displaymodule | 0:d6ff5fa503e8 | 158 | sendCommand(0x36); sendData(0x0408); |
displaymodule | 0:d6ff5fa503e8 | 159 | sendCommand(0x37); sendData(0x0507); |
displaymodule | 0:d6ff5fa503e8 | 160 | sendCommand(0x38); sendData(0x0204); |
displaymodule | 0:d6ff5fa503e8 | 161 | sendCommand(0x39); sendData(0x0707); |
displaymodule | 0:d6ff5fa503e8 | 162 | sendCommand(0x3C); sendData(0x0405); |
displaymodule | 0:d6ff5fa503e8 | 163 | sendCommand(0x3D); sendData(0x0f02); |
displaymodule | 0:d6ff5fa503e8 | 164 | |
displaymodule | 0:d6ff5fa503e8 | 165 | sendCommand(0x50); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 166 | sendCommand(0x51); sendData(0x00EF); |
displaymodule | 0:d6ff5fa503e8 | 167 | sendCommand(0x52); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 168 | sendCommand(0x53); sendData(0x013F); |
displaymodule | 0:d6ff5fa503e8 | 169 | sendCommand(0x60); sendData(0xA700); |
displaymodule | 0:d6ff5fa503e8 | 170 | sendCommand(0x61); sendData(0x0001); |
displaymodule | 0:d6ff5fa503e8 | 171 | sendCommand(0x6A); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 172 | |
displaymodule | 0:d6ff5fa503e8 | 173 | sendCommand(0x80); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 174 | sendCommand(0x81); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 175 | sendCommand(0x82); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 176 | sendCommand(0x83); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 177 | sendCommand(0x84); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 178 | sendCommand(0x85); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 179 | |
displaymodule | 0:d6ff5fa503e8 | 180 | sendCommand(0x90); sendData(0x0010); |
displaymodule | 0:d6ff5fa503e8 | 181 | sendCommand(0x92); sendData(0x0600); |
displaymodule | 0:d6ff5fa503e8 | 182 | sendCommand(0x93); sendData(0x0003); |
displaymodule | 0:d6ff5fa503e8 | 183 | sendCommand(0x95); sendData(0x0110); |
displaymodule | 0:d6ff5fa503e8 | 184 | sendCommand(0x97); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 185 | sendCommand(0x98); sendData(0x0000); |
displaymodule | 0:d6ff5fa503e8 | 186 | sendCommand(0x07); sendData(0x0133); |
displaymodule | 0:d6ff5fa503e8 | 187 | sbi(_pinCS, _bitmaskCS); |
displaymodule | 7:6cd8c36cbdb3 | 188 | delay(500); |
displaymodule | 0:d6ff5fa503e8 | 189 | clearScreen(); |
displaymodule | 0:d6ff5fa503e8 | 190 | } |
displaymodule | 0:d6ff5fa503e8 | 191 | |
displaymodule | 0:d6ff5fa503e8 | 192 | /********************************************************************************************************* |
displaymodule | 0:d6ff5fa503e8 | 193 | END FILE |
displaymodule | 0:d6ff5fa503e8 | 194 | *********************************************************************************************************/ |
displaymodule | 0:d6ff5fa503e8 | 195 |