acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
Arduino_ILI9486_18bit.cpp (4543B)
1 /* 2 * start rewrite from: 3 * https://github.com/adafruit/Adafruit-GFX-Library.git 4 */ 5 #include "Arduino_ILI9486_18bit.h" 6 7 Arduino_ILI9486_18bit::Arduino_ILI9486_18bit(Arduino_DataBus *bus, int8_t rst, uint8_t r, bool ips) 8 : Arduino_TFT_18bit(bus, rst, r, ips, ILI9486_TFTWIDTH, ILI9486_TFTHEIGHT, 0, 0, 0, 0) 9 { 10 } 11 12 bool Arduino_ILI9486_18bit::begin(int32_t speed) 13 { 14 return Arduino_TFT::begin(speed); 15 } 16 17 // Companion code to the above tables. Reads and issues 18 // a series of LCD commands stored in PROGMEM byte array. 19 void Arduino_ILI9486_18bit::tftInit() 20 { 21 if (_rst != GFX_NOT_DEFINED) 22 { 23 pinMode(_rst, OUTPUT); 24 digitalWrite(_rst, HIGH); 25 delay(100); 26 digitalWrite(_rst, LOW); 27 delay(ILI9486_RST_DELAY); 28 digitalWrite(_rst, HIGH); 29 delay(ILI9486_RST_DELAY); 30 } 31 else 32 { 33 // Software Rest 34 _bus->sendCommand(ILI9486_SWRESET); 35 delay(ILI9486_RST_DELAY); 36 } 37 38 _bus->sendCommand(ILI9486_SLPOUT); // Exit Sleep 39 delay(ILI9486_SLPIN_DELAY); 40 41 _bus->sendCommand(0x3A); 42 _bus->sendData(0x66); // 18-bit color 43 44 _bus->sendCommand(0xC2); 45 _bus->sendData(0x44); 46 47 _bus->sendCommand(0xC5); 48 _bus->sendData(0x00); 49 _bus->sendData(0x00); 50 _bus->sendData(0x00); 51 _bus->sendData(0x00); 52 53 _bus->sendCommand(0xE0); 54 _bus->sendData(0x0F); 55 _bus->sendData(0x1F); 56 _bus->sendData(0x1C); 57 _bus->sendData(0x0C); 58 _bus->sendData(0x0F); 59 _bus->sendData(0x08); 60 _bus->sendData(0x48); 61 _bus->sendData(0x98); 62 _bus->sendData(0x37); 63 _bus->sendData(0x0A); 64 _bus->sendData(0x13); 65 _bus->sendData(0x04); 66 _bus->sendData(0x11); 67 _bus->sendData(0x0D); 68 _bus->sendData(0x00); 69 70 _bus->sendCommand(0xE1); 71 _bus->sendData(0x0F); 72 _bus->sendData(0x32); 73 _bus->sendData(0x2E); 74 _bus->sendData(0x0B); 75 _bus->sendData(0x0D); 76 _bus->sendData(0x05); 77 _bus->sendData(0x47); 78 _bus->sendData(0x75); 79 _bus->sendData(0x37); 80 _bus->sendData(0x06); 81 _bus->sendData(0x10); 82 _bus->sendData(0x03); 83 _bus->sendData(0x24); 84 _bus->sendData(0x20); 85 _bus->sendData(0x00); 86 87 if (_ips) 88 { 89 _bus->sendCommand(ILI9486_INVON); 90 } 91 else 92 { 93 _bus->sendCommand(ILI9486_INVOFF); 94 } 95 96 _bus->sendCommand(ILI9486_DISPON); // Display on 97 delay(25); 98 } 99 100 void Arduino_ILI9486_18bit::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) 101 { 102 if ((x != _currentX) || (w != _currentW)) 103 { 104 int16_t x_start = x + _xStart, x_end = x + w - 1 + _xStart; 105 106 _bus->writeCommand(ILI9486_CASET); // Column addr set 107 _bus->write(x_start >> 8); 108 _bus->write(x_start & 0xFF); // XSTART 109 _bus->write(x_end >> 8); 110 _bus->write(x_end & 0xFF); // XEND 111 112 _currentX = x; 113 _currentW = w; 114 } 115 if ((y != _currentY) || (h != _currentH)) 116 { 117 int16_t y_start = y + _yStart, y_end = y + h - 1 + _yStart; 118 119 _bus->writeCommand(ILI9486_PASET); // Row addr set 120 _bus->write(y_start >> 8); 121 _bus->write(y_start & 0xFF); // YSTART 122 _bus->write(y_end >> 8); 123 _bus->write(y_end & 0xFF); // YEND 124 125 _currentY = y; 126 _currentH = h; 127 } 128 129 _bus->writeCommand(ILI9486_RAMWR); // write to RAM 130 } 131 132 /**************************************************************************/ 133 /*! 134 @brief Set origin of (0,0) and orientation of TFT display 135 @param m The index for rotation, from 0-3 inclusive 136 */ 137 /**************************************************************************/ 138 void Arduino_ILI9486_18bit::setRotation(uint8_t r) 139 { 140 Arduino_TFT::setRotation(r); 141 switch (_rotation) 142 { 143 case 1: 144 r = (ILI9486_MADCTL_MV | ILI9486_MADCTL_BGR); 145 break; 146 case 2: 147 r = (ILI9486_MADCTL_MY | ILI9486_MADCTL_BGR); 148 break; 149 case 3: 150 r = (ILI9486_MADCTL_MY | ILI9486_MADCTL_MX | ILI9486_MADCTL_MV | ILI9486_MADCTL_BGR); 151 break; 152 case 4: 153 r = (ILI9486_MADCTL_BGR); 154 break; 155 case 5: 156 r = (ILI9486_MADCTL_MY | ILI9486_MADCTL_MV | ILI9486_MADCTL_BGR); 157 break; 158 case 6: 159 r = (ILI9486_MADCTL_MY | ILI9486_MADCTL_MX | ILI9486_MADCTL_BGR); 160 break; 161 case 7: 162 r = (ILI9486_MADCTL_MX | ILI9486_MADCTL_MV | ILI9486_MADCTL_BGR); 163 break; 164 default: // case 0: 165 r = (ILI9486_MADCTL_MX | ILI9486_MADCTL_BGR); 166 break; 167 } 168 _bus->beginWrite(); 169 _bus->writeCommand(ILI9486_MADCTL); 170 _bus->write(r); 171 _bus->endWrite(); 172 } 173 174 void Arduino_ILI9486_18bit::invertDisplay(bool i) 175 { 176 _bus->sendCommand(i ? ILI9486_INVON : ILI9486_INVOFF); 177 } 178 179 void Arduino_ILI9486_18bit::displayOn(void) 180 { 181 _bus->sendCommand(ILI9486_SLPOUT); 182 delay(ILI9486_SLPOUT_DELAY); 183 } 184 185 void Arduino_ILI9486_18bit::displayOff(void) 186 { 187 _bus->sendCommand(ILI9486_SLPIN); 188 delay(ILI9486_SLPIN_DELAY); 189 }