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_HX8357A.cpp (4437B)
1 #include "Arduino_HX8357A.h" 2 3 Arduino_HX8357A::Arduino_HX8357A(Arduino_DataBus *bus, int8_t rst, uint8_t r, bool ips) 4 : Arduino_TFT(bus, rst, r, ips, HX8357A_TFTWIDTH, HX8357A_TFTHEIGHT, 0, 0, 0, 0) 5 { 6 } 7 8 bool Arduino_HX8357A::begin(int32_t speed) 9 { 10 return Arduino_TFT::begin(speed); 11 } 12 13 /**************************************************************************/ 14 /*! 15 @brief Set origin of (0,0) and orientation of TFT display 16 @param m The index for rotation, from 0-3 inclusive 17 */ 18 /**************************************************************************/ 19 void Arduino_HX8357A::setRotation(uint8_t r) 20 { 21 Arduino_TFT::setRotation(r); 22 switch (_rotation) 23 { 24 case 3: 25 // TODO: not working 26 r = (HX8357A_MADCTL_MY | HX8357A_MADCTL_MV | HX8357A_MADCTL_BGR); 27 break; 28 case 2: 29 r = (HX8357A_MADCTL_MX | HX8357A_MADCTL_BGR); 30 break; 31 case 1: 32 // TODO: not working 33 r = (HX8357A_MADCTL_MX | HX8357A_MADCTL_MV | HX8357A_MADCTL_BGR); 34 break; 35 default: // case 0: 36 r = (HX8357A_MADCTL_MY | HX8357A_MADCTL_BGR); 37 break; 38 } 39 _bus->beginWrite(); 40 _bus->writeC8D8(HX8357A_MEMORY_ACCESS_CONTROL, r); 41 _bus->endWrite(); 42 } 43 44 void Arduino_HX8357A::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) 45 { 46 if ((x != _currentX) || (w != _currentW)) 47 { 48 _currentX = x; 49 _currentW = w; 50 x += _xStart; 51 _data16.value = x; 52 _bus->writeC8D8(HX8357A_COLUMN_ADDRESS_COUNTER_2, _data16.msb); 53 _bus->writeC8D8(HX8357A_COLUMN_ADDRESS_COUNTER_1, _data16.lsb); 54 _bus->writeC8D8(HX8357A_COLUMN_ADDRESS_START_2, _data16.msb); 55 _bus->writeC8D8(HX8357A_COLUMN_ADDRESS_START_1, _data16.lsb); 56 _data16.value = x + w - 1; 57 _bus->writeC8D8(HX8357A_COLUMN_ADDRESS_END_2, _data16.msb); 58 _bus->writeC8D8(HX8357A_COLUMN_ADDRESS_END_1, _data16.lsb); 59 } 60 61 if ((y != _currentY) || (h != _currentH)) 62 { 63 _currentY = y; 64 _currentH = h; 65 y += _yStart; 66 _data16.value = y; 67 _bus->writeC8D8(HX8357A_ROW_ADDRESS_COUNTER_2, _data16.msb); 68 _bus->writeC8D8(HX8357A_ROW_ADDRESS_COUNTER_1, _data16.lsb); 69 _bus->writeC8D8(HX8357A_ROW_ADDRESS_START_2, _data16.msb); 70 _bus->writeC8D8(HX8357A_ROW_ADDRESS_START_1, _data16.lsb); 71 _data16.value = y + h - 1; 72 _bus->writeC8D8(HX8357A_ROW_ADDRESS_END_2, _data16.msb); 73 _bus->writeC8D8(HX8357A_ROW_ADDRESS_END_1, _data16.lsb); 74 } 75 76 _bus->writeCommand(HX8357A_SRAM_CONTROL); 77 } 78 79 void Arduino_HX8357A::invertDisplay(bool i) 80 { 81 _bus->beginWrite(); 82 _bus->writeC8D8(HX8357A_DISPLAY_MODE_CONTROL, (_ips ^ i) ? HX8357A_INV_ON : HX8357A_INV_OFF); 83 _bus->endWrite(); 84 } 85 86 void Arduino_HX8357A::displayOn(void) 87 { 88 _bus->beginWrite(); 89 _bus->writeC8D8(HX8357A_OSC_CONTROL_2, 0x01); // OSC_EN=1 90 _bus->endWrite(); 91 delay(5); 92 _bus->beginWrite(); 93 _bus->writeC8D8(HX8357A_POWER_CONTROL_1, 0x88); // PON=0, DK=1 94 _bus->writeC8D8(HX8357A_DISPLAY_MODE_CONTROL, 0x00); // DP_STB=00 95 _bus->writeC8D8(HX8357A_POWER_CONTROL_4, 0x03); // AP=011 96 _bus->writeC8D8(HX8357A_POWER_CONTROL_1, 0x80); // DK=0 97 _bus->endWrite(); 98 delay(3); 99 _bus->beginWrite(); 100 _bus->writeC8D8(HX8357A_POWER_CONTROL_1, 0x90); // PON=1 101 _bus->endWrite(); 102 delay(3); 103 _bus->beginWrite(); 104 _bus->writeC8D8(HX8357A_POWER_CONTROL_1, 0xD0); // VCOMG=1 105 _bus->writeC8D8(HX8357A_DISPLAY_CONTROL_3, 0x3C); // GON=1, DTE=1, D[1:0]=11 106 _bus->endWrite(); 107 } 108 109 void Arduino_HX8357A::displayOff(void) 110 { 111 _bus->beginWrite(); 112 _bus->writeC8D8(HX8357A_DISPLAY_CONTROL_3, 0x34); // GON=1, DTE=1, D[1:0]=01 113 _bus->writeC8D8(HX8357A_POWER_CONTROL_1, 0x90); // VCOMG=0 114 _bus->endWrite(); 115 delay(1); 116 _bus->beginWrite(); 117 _bus->writeC8D8(HX8357A_POWER_CONTROL_1, 0x88); // PON=0, DK=1 118 _bus->writeC8D8(HX8357A_POWER_CONTROL_4, 0x00); // AP=000 119 _bus->writeC8D8(HX8357A_POWER_CONTROL_1, 0x89); // STB=1 120 _bus->endWrite(); 121 } 122 123 // Companion code to the above tables. Reads and issues 124 // a series of LCD commands stored in PROGMEM byte array. 125 void Arduino_HX8357A::tftInit() 126 { 127 if (_rst != GFX_NOT_DEFINED) 128 { 129 pinMode(_rst, OUTPUT); 130 digitalWrite(_rst, HIGH); 131 delay(100); 132 digitalWrite(_rst, LOW); 133 delay(HX8357A_RST_DELAY); 134 digitalWrite(_rst, HIGH); 135 delay(HX8357A_RST_DELAY); 136 } 137 else 138 { 139 // Software Rest 140 } 141 142 _bus->batchOperation(hx8357a_init_operations, sizeof(hx8357a_init_operations)); 143 if (_ips) 144 { 145 _bus->sendCommand(HX8357A_DISPLAY_MODE_CONTROL); 146 _bus->sendData(HX8357A_INV_ON); 147 } 148 }