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_ILI9341.cpp (2750B)
1 /* 2 * start rewrite from: 3 * https://github.com/adafruit/Adafruit-GFX-Library.git 4 * https://github.com/adafruit/Adafruit_ILI9341.git 5 */ 6 #include "Arduino_ILI9341.h" 7 #include "SPI.h" 8 9 Arduino_ILI9341::Arduino_ILI9341(Arduino_DataBus *bus, int8_t rst, uint8_t r, bool ips) 10 : Arduino_TFT(bus, rst, r, ips, ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT, 0, 0, 0, 0) 11 { 12 } 13 14 bool Arduino_ILI9341::begin(int32_t speed) 15 { 16 _override_datamode = SPI_MODE0; // always use SPI_MODE0 17 18 return Arduino_TFT::begin(speed); 19 } 20 21 /**************************************************************************/ 22 /*! 23 @brief Set origin of (0,0) and orientation of TFT display 24 @param m The index for rotation, from 0-3 inclusive 25 */ 26 /**************************************************************************/ 27 void Arduino_ILI9341::setRotation(uint8_t r) 28 { 29 Arduino_TFT::setRotation(r); 30 switch (_rotation) 31 { 32 case 1: 33 r = (ILI9341_MADCTL_MV | ILI9341_MADCTL_BGR); 34 break; 35 case 2: 36 r = (ILI9341_MADCTL_MY | ILI9341_MADCTL_BGR); 37 break; 38 case 3: 39 r = (ILI9341_MADCTL_MX | ILI9341_MADCTL_MY | ILI9341_MADCTL_MV | ILI9341_MADCTL_BGR); 40 break; 41 default: // case 0: 42 r = (ILI9341_MADCTL_MX | ILI9341_MADCTL_BGR); 43 break; 44 } 45 _bus->beginWrite(); 46 _bus->writeC8D8(ILI9341_MADCTL, r); 47 _bus->endWrite(); 48 } 49 50 void Arduino_ILI9341::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) 51 { 52 if ((x != _currentX) || (w != _currentW)) 53 { 54 _currentX = x; 55 _currentW = w; 56 x += _xStart; 57 _bus->writeC8D16D16(ILI9341_CASET, x, x + w - 1); 58 } 59 60 if ((y != _currentY) || (h != _currentH)) 61 { 62 _currentY = y; 63 _currentH = h; 64 y += _yStart; 65 _bus->writeC8D16D16(ILI9341_PASET, y, y + h - 1); 66 } 67 68 _bus->writeCommand(ILI9341_RAMWR); // write to RAM 69 } 70 71 void Arduino_ILI9341::invertDisplay(bool i) 72 { 73 _bus->sendCommand((_ips ^ i) ? ILI9341_INVON : ILI9341_INVOFF); 74 } 75 76 void Arduino_ILI9341::displayOn(void) 77 { 78 _bus->sendCommand(ILI9341_SLPOUT); 79 delay(ILI9341_SLPOUT_DELAY); 80 } 81 82 void Arduino_ILI9341::displayOff(void) 83 { 84 _bus->sendCommand(ILI9341_SLPIN); 85 delay(ILI9341_SLPIN_DELAY); 86 } 87 88 // Companion code to the above tables. Reads and issues 89 // a series of LCD commands stored in PROGMEM byte array. 90 void Arduino_ILI9341::tftInit() 91 { 92 if (_rst != GFX_NOT_DEFINED) 93 { 94 pinMode(_rst, OUTPUT); 95 digitalWrite(_rst, HIGH); 96 delay(100); 97 digitalWrite(_rst, LOW); 98 delay(ILI9341_RST_DELAY); 99 digitalWrite(_rst, HIGH); 100 delay(ILI9341_RST_DELAY); 101 } 102 else 103 { 104 // Software Rest 105 _bus->sendCommand(ILI9341_SWRESET); 106 delay(ILI9341_RST_DELAY); 107 } 108 109 _bus->batchOperation(ili9341_init_operations, sizeof(ili9341_init_operations)); 110 111 if (_ips) 112 { 113 _bus->sendCommand(ILI9341_INVON); 114 } 115 }