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.cpp (2901B)
1 /* 2 * start rewrite from: 3 * https://github.com/nopnop2002/esp-idf-parallel-tft 4 */ 5 #include "Arduino_ILI9486.h" 6 7 Arduino_ILI9486::Arduino_ILI9486(Arduino_DataBus *bus, int8_t rst, uint8_t r, bool ips) 8 : Arduino_TFT(bus, rst, r, ips, ILI9486_TFTWIDTH, ILI9486_TFTHEIGHT, 0, 0, 0, 0) 9 { 10 } 11 12 bool Arduino_ILI9486::begin(int32_t speed) 13 { 14 return Arduino_TFT::begin(speed); 15 } 16 17 /**************************************************************************/ 18 /*! 19 @brief Set origin of (0,0) and orientation of TFT display 20 @param m The index for rotation, from 0-3 inclusive 21 */ 22 /**************************************************************************/ 23 void Arduino_ILI9486::setRotation(uint8_t r) 24 { 25 Arduino_TFT::setRotation(r); 26 switch (_rotation) 27 { 28 case 1: 29 r = (ILI9486_MADCTL_MV | ILI9486_MADCTL_BGR); 30 break; 31 case 2: 32 r = (ILI9486_MADCTL_MY | ILI9486_MADCTL_BGR); 33 break; 34 case 3: 35 r = (ILI9486_MADCTL_MY | ILI9486_MADCTL_MX | ILI9486_MADCTL_MV | ILI9486_MADCTL_BGR); 36 break; 37 case 4: 38 r = (ILI9486_MADCTL_BGR); 39 break; 40 case 5: 41 r = (ILI9486_MADCTL_MY | ILI9486_MADCTL_MV | ILI9486_MADCTL_BGR); 42 break; 43 case 6: 44 r = (ILI9486_MADCTL_MY | ILI9486_MADCTL_MX | ILI9486_MADCTL_BGR); 45 break; 46 case 7: 47 r = (ILI9486_MADCTL_MX | ILI9486_MADCTL_MV | ILI9486_MADCTL_BGR); 48 break; 49 default: // case 0: 50 r = (ILI9486_MADCTL_MX | ILI9486_MADCTL_BGR); 51 break; 52 } 53 _bus->beginWrite(); 54 _bus->writeC8D8(ILI9486_MADCTL, r); 55 _bus->endWrite(); 56 } 57 58 void Arduino_ILI9486::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) 59 { 60 if ((x != _currentX) || (w != _currentW)) 61 { 62 _currentX = x; 63 _currentW = w; 64 x += _xStart; 65 _bus->writeC8D16D16Split(ILI9486_CASET, x, x + w - 1); 66 } 67 if ((y != _currentY) || (h != _currentH)) 68 { 69 _currentY = y; 70 _currentH = h; 71 y += _yStart; 72 _bus->writeC8D16D16Split(ILI9486_PASET, y, y + h - 1); 73 } 74 75 _bus->writeCommand(ILI9486_RAMWR); // write to RAM 76 } 77 78 void Arduino_ILI9486::invertDisplay(bool i) 79 { 80 _bus->sendCommand((_ips ^ i) ? ILI9486_INVON : ILI9486_INVOFF); 81 } 82 83 void Arduino_ILI9486::displayOn(void) 84 { 85 _bus->sendCommand(ILI9486_SLPOUT); 86 delay(ILI9486_SLPOUT_DELAY); 87 } 88 89 void Arduino_ILI9486::displayOff(void) 90 { 91 _bus->sendCommand(ILI9486_SLPIN); 92 delay(ILI9486_SLPIN_DELAY); 93 } 94 95 // Companion code to the above tables. Reads and issues 96 // a series of LCD commands stored in PROGMEM byte array. 97 void Arduino_ILI9486::tftInit() 98 { 99 if (_rst != GFX_NOT_DEFINED) 100 { 101 pinMode(_rst, OUTPUT); 102 digitalWrite(_rst, HIGH); 103 delay(100); 104 digitalWrite(_rst, LOW); 105 delay(ILI9486_RST_DELAY); 106 digitalWrite(_rst, HIGH); 107 delay(ILI9486_RST_DELAY); 108 } 109 110 _bus->batchOperation(ili9486_init_operations, sizeof(ili9486_init_operations)); 111 112 if (_ips) 113 { 114 _bus->sendCommand(ILI9486_INVON); 115 } 116 else 117 { 118 _bus->sendCommand(ILI9486_INVOFF); 119 } 120 }