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_ILI9225.cpp (3358B)
1 /* 2 * start rewrite from: 3 * https://github.com/adafruit/Adafruit-GFX-Library.git 4 * https://github.com/lcdwiki/LCDWIKI_SPI 5 */ 6 #include "Arduino_ILI9225.h" 7 8 Arduino_ILI9225::Arduino_ILI9225(Arduino_DataBus *bus, int8_t rst, uint8_t r) 9 : Arduino_TFT(bus, rst, r, false, ILI9225_TFTWIDTH, ILI9225_TFTHEIGHT, 0, 0, 0, 0) 10 { 11 } 12 13 bool Arduino_ILI9225::begin(int32_t speed) 14 { 15 return Arduino_TFT::begin(speed); 16 } 17 18 /**************************************************************************/ 19 /*! 20 @brief Set origin of (0,0) and orientation of TFT display 21 @param m The index for rotation, from 0-3 inclusive 22 */ 23 /**************************************************************************/ 24 void Arduino_ILI9225::setRotation(uint8_t r) 25 { 26 Arduino_TFT::setRotation(r); 27 _bus->beginWrite(); 28 switch (_rotation) 29 { 30 case 3: 31 _bus->writeC8D16(ILI9225_DRIVER_OUTPUT_CTRL, 0x031C); 32 _bus->writeC8D16(ILI9225_ENTRY_MODE, 0x1038); 33 break; 34 case 2: 35 _bus->writeC8D16(ILI9225_DRIVER_OUTPUT_CTRL, 0x021C); 36 _bus->writeC8D16(ILI9225_ENTRY_MODE, 0x1030); 37 break; 38 case 1: 39 _bus->writeC8D16(ILI9225_DRIVER_OUTPUT_CTRL, 0x001C); 40 _bus->writeC8D16(ILI9225_ENTRY_MODE, 0x1038); 41 break; 42 default: // case 0: 43 _bus->writeC8D16(ILI9225_DRIVER_OUTPUT_CTRL, 0x011C); 44 _bus->writeC8D16(ILI9225_ENTRY_MODE, 0x1030); 45 break; 46 } 47 _bus->endWrite(); 48 } 49 50 void Arduino_ILI9225::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) 51 { 52 uint8_t cmd1, cmd2, cmd3; 53 54 if ((x != _currentX) || (w != _currentW)) 55 { 56 _currentX = x; 57 _currentW = w; 58 x += _xStart; 59 if (_rotation & 0x01) // Landscape 60 { 61 cmd1 = ILI9225_VERTICAL_WINDOW_ADDR2; 62 cmd2 = ILI9225_VERTICAL_WINDOW_ADDR1; 63 cmd3 = ILI9225_RAM_ADDR_SET2; 64 } 65 else 66 { 67 cmd1 = ILI9225_HORIZONTAL_WINDOW_ADDR2; 68 cmd2 = ILI9225_HORIZONTAL_WINDOW_ADDR1; 69 cmd3 = ILI9225_RAM_ADDR_SET1; 70 } 71 _bus->writeC8D16(cmd1, x); 72 _bus->writeC8D16(cmd2, x + w - 1); 73 _bus->writeC8D16(cmd3, x); 74 } 75 if ((y != _currentY) || (h != _currentH)) 76 { 77 _currentY = y; 78 _currentH = h; 79 y += _yStart; 80 if (_rotation & 0x01) // Landscape 81 { 82 cmd1 = ILI9225_HORIZONTAL_WINDOW_ADDR2; 83 cmd2 = ILI9225_HORIZONTAL_WINDOW_ADDR1; 84 cmd3 = ILI9225_RAM_ADDR_SET1; 85 } 86 else 87 { 88 cmd1 = ILI9225_VERTICAL_WINDOW_ADDR2; 89 cmd2 = ILI9225_VERTICAL_WINDOW_ADDR1; 90 cmd3 = ILI9225_RAM_ADDR_SET2; 91 } 92 _bus->writeC8D16(cmd1, y); 93 _bus->writeC8D16(cmd2, y + h - 1); 94 _bus->writeC8D16(cmd3, y); 95 } 96 97 _bus->writeCommand(ILI9225_GRAM_DATA_REG); // write to RAM 98 } 99 100 void Arduino_ILI9225::invertDisplay(bool i) 101 { 102 // Not Implemented 103 UNUSED(i); 104 } 105 106 void Arduino_ILI9225::displayOn(void) 107 { 108 _bus->sendCommand(ILI9225_POWER_CTRL1); 109 _bus->sendData16(0x0800); // Set SAP,DSTB,STB 110 } 111 112 void Arduino_ILI9225::displayOff(void) 113 { 114 _bus->sendCommand(ILI9225_POWER_CTRL1); 115 _bus->sendData16(0x0801); // Set SAP,DSTB,STB 116 } 117 118 void Arduino_ILI9225::tftInit() 119 { 120 if (_rst != GFX_NOT_DEFINED) 121 { 122 pinMode(_rst, OUTPUT); 123 digitalWrite(_rst, HIGH); 124 delay(100); 125 digitalWrite(_rst, LOW); 126 delay(ILI9225_RST_DELAY); 127 digitalWrite(_rst, HIGH); 128 delay(ILI9225_RST_DELAY); 129 } 130 else 131 { 132 // Software Rest 133 } 134 135 _bus->batchOperation(ili9225_init_operations, sizeof(ili9225_init_operations)); 136 }