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_OTM8009A.cpp (7454B)
1 #include "Arduino_OTM8009A.h" 2 3 Arduino_OTM8009A::Arduino_OTM8009A( 4 Arduino_DataBus *bus, int8_t rst, uint8_t r, 5 bool ips, int16_t w, int16_t h, 6 uint8_t col_offset1, uint8_t row_offset1, uint8_t col_offset2, uint8_t row_offset2) 7 : Arduino_TFT(bus, rst, r, ips, w, h, col_offset1, row_offset1, col_offset2, row_offset2) 8 { 9 } 10 11 bool Arduino_OTM8009A::begin(int32_t speed) 12 { 13 return Arduino_TFT::begin(speed); 14 } 15 16 /**************************************************************************/ 17 /*! 18 @brief Set origin of (0,0) and orientation of TFT display 19 @param m The index for rotation, from 0-3 inclusive 20 */ 21 /**************************************************************************/ 22 void Arduino_OTM8009A::setRotation(uint8_t r) 23 { 24 Arduino_TFT::setRotation(r); 25 switch (_rotation) 26 { 27 case 3: 28 r = (OTM8009A_MADCTL_MY | OTM8009A_MADCTL_MV); 29 break; 30 case 2: 31 r = (OTM8009A_MADCTL_MY | OTM8009A_MADCTL_MX); 32 break; 33 case 1: 34 r = (OTM8009A_MADCTL_MX | OTM8009A_MADCTL_MV); 35 break; 36 default: // case 0: 37 r = 0; 38 break; 39 } 40 _bus->beginWrite(); 41 _bus->writeCommand16(OTM8009A_MADCTR); 42 _bus->write16(r); 43 _bus->endWrite(); 44 } 45 46 void Arduino_OTM8009A::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) 47 { 48 if ((x != _currentX) || (w != _currentW)) 49 { 50 _currentX = x; 51 _currentW = w; 52 _data16.value = x + _xStart; 53 _bus->writeC16D16(OTM8009A_CASET, _data16.msb); 54 _bus->writeC16D16(OTM8009A_CASET + 1, _data16.lsb); 55 _data16.value += w - 1; 56 _bus->writeC16D16(OTM8009A_CASET + 2, _data16.msb); 57 _bus->writeC16D16(OTM8009A_CASET + 3, _data16.lsb); 58 } 59 60 if ((y != _currentY) || (h != _currentH)) 61 { 62 _currentY = y; 63 _currentH = h; 64 _data16.value = y + _yStart; 65 _bus->writeC16D16(OTM8009A_PASET, _data16.msb); 66 _bus->writeC16D16(OTM8009A_PASET + 1, _data16.lsb); 67 _data16.value += h - 1; 68 _bus->writeC16D16(OTM8009A_PASET + 2, _data16.msb); 69 _bus->writeC16D16(OTM8009A_PASET + 3, _data16.lsb); 70 } 71 72 _bus->writeCommand16(OTM8009A_RAMWR); // write to RAM 73 } 74 75 void Arduino_OTM8009A::invertDisplay(bool i) 76 { 77 // Not Implemented 78 UNUSED(i); 79 } 80 81 void Arduino_OTM8009A::displayOn(void) 82 { 83 // Not Implemented 84 } 85 86 void Arduino_OTM8009A::displayOff(void) 87 { 88 // Not Implemented 89 } 90 91 void Arduino_OTM8009A::WriteRegM(uint16_t adr, uint16_t len, uint8_t dat[]) 92 { 93 for (uint16_t i = 0; i < len; i++) 94 { 95 _bus->writeCommand16(adr++); 96 _bus->write16(dat[i]); 97 } 98 } 99 100 // Companion code to the above tables. Reads and issues 101 // a series of LCD commands stored in PROGMEM byte array. 102 void Arduino_OTM8009A::tftInit() 103 { 104 if (_rst != GFX_NOT_DEFINED) 105 { 106 pinMode(_rst, OUTPUT); 107 digitalWrite(_rst, HIGH); 108 delay(100); 109 digitalWrite(_rst, LOW); 110 delay(OTM8009A_RST_DELAY); 111 digitalWrite(_rst, HIGH); 112 delay(OTM8009A_RST_DELAY); 113 } 114 else 115 { 116 // Software Rest 117 } 118 119 //************* OTM8009A**********// 120 _bus->beginWrite(); 121 // 3.97inch OTM8009 Init 20190116 122 /* Enter CMD2 */ 123 uint8_t ini01[] = {0x80, 0x09, 0x01, 0x01}; 124 WriteRegM(0xFF00, sizeof(ini01), ini01); 125 /* Enter Orise Command2 */ 126 uint8_t ini02[] = {0x80, 0x09}; 127 WriteRegM(0xFF80, sizeof(ini02), ini02); 128 129 /* Command not documented */ 130 _bus->writeCommand16(0xf5b6); 131 _bus->write16(0x06); //?? 132 133 /* Source Driver Precharge Control */ 134 uint8_t ini03[] = {0x30, 0x83}; 135 WriteRegM(0xC480, sizeof(ini03), ini03); 136 137 /* Command not documented: 0xC48A */ 138 _bus->writeCommand16(0xC48A); 139 _bus->write16(0x40); 140 141 /* Source Driver Timing Setting */ 142 _bus->writeCommand16(0xC0A2 + 1); 143 _bus->write16(0x1B); 144 145 /* Command not documented */ 146 _bus->writeCommand16(0xc0ba); //--> (0xc0b4); // column inversion // 2013.12.16 modify 147 _bus->write16(0x50); 148 149 /* Oscillator Adjustment for Idle/Normal mode */ 150 _bus->writeCommand16(0xC181); 151 _bus->write16(0x66); /* 65Hz */ 152 153 /* RGB Video Mode Setting */ 154 _bus->writeCommand16(0xC1A1); 155 _bus->write16(0x0E); 156 157 /* Power Control Setting 1 */ 158 _bus->writeCommand16(0xC580 + 2); 159 _bus->write16(0x83); 160 161 /* Power Control Setting 2 for Normal Mode */ 162 uint8_t ini04[] = {0x96, 0x2B, 0x01, 0x33, 0x34}; 163 WriteRegM(0xC590, sizeof(ini04), ini04); 164 165 /* Power Control Setting 4 for DC Voltage */ 166 _bus->writeCommand16(0xC5B0 + 1); 167 _bus->write16(0xa9); 168 169 /* GOA VST Setting */ 170 uint8_t ini05[] = {0x86, 0x01, 0x00, 0x85, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 171 WriteRegM(0xCE80, sizeof(ini05), ini05); 172 173 /* GOA CLKA1 Setting */ 174 uint8_t ini06[] = {0x18, 0x04, 0x03, 0x21, 0x00, 0x00, 0x00}; 175 WriteRegM(0xCEA0, sizeof(ini06), ini06); 176 177 /* GOA CLKA2 Setting */ 178 uint8_t ini07[] = {0x18, 0x03, 0x03, 0x22, 0x00, 0x00, 0x00}; 179 WriteRegM(0xCEA7, sizeof(ini07), ini07); 180 181 /* GOA CLKA3 Setting */ 182 uint8_t ini08[] = {0x18, 0x02, 0x03, 0x23, 0x00, 0x00, 0x00}; 183 WriteRegM(0xCEB0, sizeof(ini08), ini08); 184 185 /* GOA CLKA4 Setting */ 186 uint8_t ini09[] = {0x18, 0x01, 0x03, 0x24, 0x00, 0x00, 0x00}; 187 WriteRegM(0xCEB7, sizeof(ini09), ini09); 188 189 /* GOA ECLK Setting */ 190 uint8_t ini10[] = {0x01, 0x01, 0x20, 0x20, 0x00, 0x00}; 191 WriteRegM(0xCFC0, sizeof(ini10), ini10); 192 193 /* GOA Other Options 1 */ 194 _bus->writeCommand16(0xCFC6); // cfc7[7:0] : 00, vstmask, vendmask, 00, dir1, dir2 (0=VGL, 1=VGH) 195 _bus->write16(0x01); 196 197 /* GOA Signal Toggle Option Setting */ 198 uint8_t ini11[] = {0x00, 0x00, 0x00}; 199 WriteRegM(0xCFC7, sizeof(ini11), ini11); // cfc8[7:0] : reg_goa_gnd_opt, reg_goa_dpgm_tail_set, reg_goa_f_gating_en, reg_goa_f_odd_gating, toggle_mod1, 2, 3, 4 200 201 /* Command not documented: 0xCFD0 */ 202 _bus->writeCommand16(0xCFD0); // cfd1[7:0] : 0000000, reg_goa_frame_odd_high 203 _bus->write16(0x00); 204 205 /* Panel Control Setting 5 */ 206 uint8_t ini12[] = {0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 207 WriteRegM(0xCBC0, sizeof(ini12), ini12); // cbc[7:0] : enmode H-byte of sig (pwrof_0, pwrof_1, norm, pwron_4 ) 208 209 /* Panel Control Setting 6 */ 210 uint8_t ini13[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00}; 211 WriteRegM(0xCBD0, sizeof(ini13), ini13); // cbd1[7:0] : enmode H-byte of sig16 (pwrof_0, pwrof_1, norm, pwron_4 ) 212 213 /* Panel Control Setting 7 */ 214 uint8_t ini14[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 215 WriteRegM(0xCBE0, sizeof(ini14), ini14); // cbe1[7:0] : enmode H-byte of sig31 (pwrof_0, pwrof_1, norm, pwron_4 ) 216 217 /* Panel U2D Setting 1 */ 218 // cc8x 219 uint8_t ini15[] = {0x00, 0x26, 0x09, 0x0B, 0x01, 0x25, 0x00, 0x00, 0x00, 0x00}; 220 WriteRegM(0xCC80, sizeof(ini15), ini15); // cc81[7:0] : reg setting for signal01 selection with u2d mode 221 222 /* Panel U2D Setting 2 */ 223 // cc9x 224 uint8_t ini16[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x0A, 0x0C, 0x02}; 225 WriteRegM(0xCC90, sizeof(ini16), ini16); // cc91[7:0] : reg setting for signal11 selection with u2d mode 226 227 /* Panel U2D Setting 3 */ 228 // ccax 229 uint8_t ini17[] = {0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 230 WriteRegM(0xCCA0, sizeof(ini17), ini17); // cca1[7:0] : reg setting for signal26 selection with u2d mode 231 232 /* Command not documented: 0x3A00 */ 233 _bus->writeCommand16(0x3A00); // ccaa[7:0] : reg setting for signal35 selection with u2d mode 234 _bus->write16(0x55); // 0x55 235 236 _bus->endWrite(); 237 238 /* Sleep out */ 239 _bus->sendCommand16(0x1100); 240 delay(100); 241 242 /* Display on */ 243 _bus->sendCommand16(0x2900); 244 delay(50); 245 }