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_JBT6K71.cpp (4214B)
1 /* 2 * start rewrite from: 3 * https://github.com/adafruit/Adafruit-GFX-Library.git 4 * https://github.com/gitcnd/LCDWIKI_SPI.git 5 */ 6 #include "Arduino_JBT6K71.h" 7 #include "SPI.h" 8 9 Arduino_JBT6K71::Arduino_JBT6K71( 10 Arduino_DataBus *bus, int8_t rst, uint8_t r, 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_JBT6K71::begin(int32_t speed) 17 { 18 return Arduino_TFT::begin(speed); 19 } 20 21 // Companion code to the above tables. Reads and issues 22 // a series of LCD commands stored in PROGMEM byte array. 23 void Arduino_JBT6K71::tftInit() 24 { 25 if (_rst != GFX_NOT_DEFINED) 26 { 27 pinMode(_rst, OUTPUT); 28 digitalWrite(_rst, HIGH); 29 delay(100); 30 digitalWrite(_rst, LOW); 31 delay(JBT6K71_RST_DELAY); 32 digitalWrite(_rst, HIGH); 33 delay(JBT6K71_RST_DELAY); 34 } 35 else 36 { 37 // Software Rest 38 } 39 40 _bus->batchOperation(jbt6k71_init_operations, sizeof(jbt6k71_init_operations)); 41 42 invertDisplay(false); 43 } 44 45 void Arduino_JBT6K71::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) 46 { 47 uint16_t cmd1, cmd2, cmd3; 48 49 if ((x != _currentX) || (w != _currentW)) 50 { 51 int16_t x_start, x_end, x_pos; 52 53 if (_rotation & 0x01) // Landscape 54 { 55 cmd1 = 0x0408; 56 cmd2 = 0x0409; 57 cmd3 = 0x0201; 58 } 59 else 60 { 61 cmd1 = 0x0406; 62 cmd2 = 0x0407; 63 cmd3 = 0x0200; 64 } 65 if (_rotation == 1) 66 { 67 x_start = JBT6K71_TFTHEIGHT - x - w - _xStart; 68 x_end = JBT6K71_TFTHEIGHT - x - 1 - _xStart; 69 x_pos = x_end; 70 } 71 else 72 { 73 x_start = x + _xStart; 74 x_end = x + w - 1 + _xStart; 75 x_pos = x_start; 76 } 77 _bus->writeCommand16(cmd1); 78 _bus->write16(x_start); 79 _bus->writeCommand16(cmd2); 80 _bus->write16(x_end); 81 _bus->writeCommand16(cmd3); 82 _bus->write16(x_pos); 83 84 _currentX = x; 85 _currentW = w; 86 } 87 if ((y != _currentY) || (h != _currentH)) 88 { 89 int16_t y_start, y_end, y_pos; 90 91 if (_rotation & 0x01) // Portrait 92 { 93 cmd1 = 0x0406; 94 cmd2 = 0x0407; 95 cmd3 = 0x0200; 96 } 97 else 98 { 99 cmd1 = 0x0408; 100 cmd2 = 0x0409; 101 cmd3 = 0x0201; 102 } 103 if (_rotation == 0) 104 { 105 y_start = JBT6K71_TFTHEIGHT - y - h - _yStart; 106 y_end = JBT6K71_TFTHEIGHT - y - 1 - _yStart; 107 y_pos = y_end; 108 } 109 else 110 { 111 y_start = y + _yStart; 112 y_end = y + h - 1 + _yStart; 113 y_pos = y_start; 114 } 115 _bus->writeCommand16(cmd1); 116 _bus->write16(y_start); 117 _bus->writeCommand16(cmd2); 118 _bus->write16(y_end); 119 _bus->writeCommand16(cmd3); 120 _bus->write16(y_pos); 121 122 _currentY = y; 123 _currentH = h; 124 } 125 126 _bus->writeCommand16(0x0202); // write to RAM 127 } 128 129 /**************************************************************************/ 130 /*! 131 @brief Set origin of (0,0) and orientation of TFT display 132 @param m The index for rotation, from 0-3 inclusive 133 */ 134 /**************************************************************************/ 135 void Arduino_JBT6K71::setRotation(uint8_t r) 136 { 137 Arduino_TFT::setRotation(r); 138 uint16_t output_control, entry_mode; 139 switch (_rotation) 140 { 141 case 1: 142 output_control = 0x0127; // SS=1 143 entry_mode = 0x0018; 144 break; 145 case 2: 146 output_control = 0x0127; // SS=1 147 entry_mode = 0x0030; 148 break; 149 case 3: 150 output_control = 0x0027; // SS=0 151 entry_mode = 0x0038; 152 break; 153 default: // case 0: 154 output_control = 0x0027; // SS=0 155 entry_mode = 0x0010; // ID=01 156 break; 157 } 158 _bus->beginWrite(); 159 _bus->writeCommand16(0x0001); // Driver output control 160 _bus->write16(output_control); 161 _bus->writeCommand16(0x0003); // Entry mode 162 _bus->write16(entry_mode); 163 _bus->endWrite(); 164 } 165 166 void Arduino_JBT6K71::invertDisplay(bool i) 167 { 168 if ( 169 (_ips && (!i)) || ((!_ips) && i)) 170 { 171 _bus->writeCommand16(0x0007); // Display mode 172 _bus->write16(0x4004); 173 } 174 else 175 { 176 _bus->writeCommand16(0x0007); // Display mode 177 _bus->write16(0x4000); 178 } 179 } 180 181 void Arduino_JBT6K71::displayOn(void) 182 { 183 // Not Implemented 184 } 185 186 void Arduino_JBT6K71::displayOff(void) 187 { 188 // Not Implemented 189 }