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_HX8347D.cpp (3198B)
1 /* 2 * start rewrite from: 3 * https://github.com/adafruit/Adafruit-GFX-Library.git 4 */ 5 #include "Arduino_HX8347D.h" 6 #include "SPI.h" 7 8 Arduino_HX8347D::Arduino_HX8347D( 9 Arduino_DataBus *bus, int8_t rst, uint8_t r, 10 bool ips, int16_t w, int16_t h, 11 uint8_t col_offset1, uint8_t row_offset1, uint8_t col_offset2, uint8_t row_offset2) 12 : Arduino_TFT(bus, rst, r, ips, w, h, col_offset1, row_offset1, col_offset2, row_offset2) 13 { 14 } 15 16 bool Arduino_HX8347D::begin(int32_t speed) 17 { 18 #if defined(__AVR__) 19 _override_datamode = SPI_MODE0; 20 #endif 21 22 return Arduino_TFT::begin(speed); 23 } 24 25 // Companion code to the above tables. Reads and issues 26 // a series of LCD commands stored in PROGMEM byte array. 27 void Arduino_HX8347D::tftInit() 28 { 29 if (_rst != GFX_NOT_DEFINED) 30 { 31 pinMode(_rst, OUTPUT); 32 digitalWrite(_rst, HIGH); 33 delay(100); 34 digitalWrite(_rst, LOW); 35 delay(HX8347D_RST_DELAY); 36 digitalWrite(_rst, HIGH); 37 delay(HX8347D_RST_DELAY); 38 } 39 else 40 { 41 // Software Rest 42 } 43 44 _bus->batchOperation(hx8347d_init_operations, sizeof(hx8347d_init_operations)); 45 46 if (_ips) 47 { 48 _bus->beginWrite(); 49 _bus->writeC8D8(0x01, 0x02); 50 _bus->endWrite(); 51 } 52 } 53 54 void Arduino_HX8347D::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) 55 { 56 if ((x != _currentX) || (w != _currentW)) 57 { 58 int16_t x_start = x + _xStart, x_end = x + w - 1 + _xStart; 59 _bus->writeC8D8(0x02, x_start >> 8); 60 _bus->writeC8D8(0x03, x_start & 0xFF); 61 _bus->writeC8D8(0x04, x_end >> 8); 62 _bus->writeC8D8(0x05, x_end & 0xFF); 63 64 _currentX = x; 65 _currentW = w; 66 } 67 if ((y != _currentY) || (h != _currentH)) 68 { 69 int16_t y_start = y + _yStart, y_end = y + h - 1 + _yStart; 70 _bus->writeC8D8(0x06, y_start >> 8); 71 _bus->writeC8D8(0x07, y_start & 0xFF); 72 _bus->writeC8D8(0x08, y_end >> 8); 73 _bus->writeC8D8(0x09, y_end & 0xFF); 74 75 _currentY = y; 76 _currentH = h; 77 } 78 79 _bus->writeCommand(0x22); // write to RAM 80 } 81 82 /**************************************************************************/ 83 /*! 84 @brief Set origin of (0,0) and orientation of TFT display 85 @param m The index for rotation, from 0-3 inclusive 86 */ 87 /**************************************************************************/ 88 void Arduino_HX8347D::setRotation(uint8_t r) 89 { 90 Arduino_TFT::setRotation(r); 91 _bus->beginWrite(); 92 switch (_rotation) 93 { 94 case 1: 95 _bus->writeC8D8(0x36, 0x03); 96 _bus->writeC8D8(0x16, 0x20); 97 break; 98 case 2: 99 _bus->writeC8D8(0x36, 0x07); 100 _bus->writeC8D8(0x16, 0x00); 101 break; 102 case 3: 103 _bus->writeC8D8(0x36, 0x07); 104 _bus->writeC8D8(0x16, 0x60); 105 break; 106 default: // case 0: 107 _bus->writeC8D8(0x36, 0x03); 108 _bus->writeC8D8(0x16, 0x40); 109 break; 110 } 111 _bus->endWrite(); 112 } 113 114 void Arduino_HX8347D::invertDisplay(bool i) 115 { 116 _bus->beginWrite(); 117 if (_ips && i) 118 { 119 _bus->writeC8D8(0x01, 0x00); 120 } 121 else 122 { 123 _bus->writeC8D8(0x01, 0x02); 124 } 125 _bus->endWrite(); 126 } 127 128 void Arduino_HX8347D::displayOn(void) 129 { 130 _bus->sendCommand(0x28); 131 _bus->sendData(0x3C); // GON=1, DTE=1, D=11 132 } 133 134 void Arduino_HX8347D::displayOff(void) 135 { 136 _bus->sendCommand(0x28); 137 _bus->sendData(0x34); // GON=1, DTE=1, D=01 138 delay(40); 139 }