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_NT35310.h (14878B)
1 /* 2 * start rewrite from: 3 * https://github.com/adafruit/Adafruit-GFX-Library.git 4 * https://github.com/daumemo/IPS_LCD_NT35310_FT6236_Arduino_eSPI_Test 5 * Data Sheet: 6 * http://read.pudn.com/downloads648/ebook/2620902/NT35310.pdf 7 */ 8 #ifndef _ARDUINO_NT35310_H_ 9 #define _ARDUINO_NT35310_H_ 10 11 #include <Arduino.h> 12 #include <Print.h> 13 #include "../Arduino_GFX.h" 14 #include "../Arduino_TFT.h" 15 16 #define NT35310_TFTWIDTH 320 // NT35310 max width 17 #define NT35310_TFTHEIGHT 480 // NT35310 max height 18 19 #define NT35310_RST_DELAY 100 // delay ms wait for reset finish 20 #define NT35310_SLPIN_DELAY 100 // delay ms wait for sleep in finish 21 #define NT35310_SLPOUT_DELAY 100 // delay ms wait for sleep out finish 22 23 // User Command 24 #define NT35310_NOP 0x00 // No Operation 25 #define NT35310_SOFT_RESET 0x01 // Software Reset 26 #define NT35310_RDID 0x04 // Read Display ID 27 #define NT35310_RDNUMED 0x05 // Read Number of the Errors on DSI 28 #define NT35310_GET_POWER_MODE 0x0A // Read Display Power Mode 29 #define NT35310_GET_ADDRESS_MODE 0x0B // Get the Frame Memory to the Display Panel Read Order 30 #define NT35310_GET_PIXEL_MODE 0x0C // Read Input Pixel Format 31 #define NT35310_GET_DISPLAY_MODE 0x0D // Read the Current Display Mode 32 #define NT35310_GET_SIGNAL_MODE 0x0E // Get Display Module Signaling Mode 33 #define NT35310_RDDSDR1 0x0F // Read Display Self-Diagnostic Result 34 #define NT35310_ENTER_SLEEP_MODE 0x10 // Enter the Sleep-In Mode 35 #define NT35310_EXIT_SLEEP_MODE 0x11 // Exit the Sleep-In Mode 36 #define NT35310_ENTER_PARTIAL_MODE 0x12 // Partial Display Mode On 37 #define NT35310_ENTER_NORMAL_MODE 0x13 // Normal Display Mode On 38 #define NT35310_EXIT_INVERT_MODE 0x20 // Display Inversion Off 39 #define NT35310_ENTER_INVERT_MODE 0x21 // Display Inversion On 40 #define NT35310_ALLPOFF 0x22 // All Pixel Off 41 #define NT35310_ALLPON 0x23 // All Pixel On 42 #define NT35310_GMASET 0x26 // Gamma Curves Selection 43 #define NT35310_SET_DISPLAY_OFF 0x28 // Display Off 44 #define NT35310_SET_DISPLAY_ON 0x29 // Display On 45 #define NT35310_SET_HORIZONTAL_ADDRESS 0x2A // Set the Column Address 46 #define NT35310_SET_VERTICAL_ADDRESS 0x2B // Set Page Address 47 #define NT35310_WRITE_MEMORY_START 0x2C // Memory Write Start Command 48 #define NT35310_SET_MDDI_RAM_READ_ADDRESS 0x2D // Set the RAM Horizontal and Vertical Address 49 #define NT35310_READ_MEMORY_START 0x2E // Memory Read Start Command 50 #define NT35310_SET_PARTIAL_AREA 0x30 // Defines the Partial Display Area 51 #define NT35310_SCRLAR 0x33 // Set Scroll Area 52 #define NT35310_SET_TEAR_ON 0x35 // Tearing Effect Line ON 53 #define NT35310_SET_ADDRESS_MODE 0x36 // Memory Data Access Control 54 #define NT35310_VSCSAD 0x37 // Vertical Scroll Start Address of RAM 55 #define NT35310_EXIT_IDLE_MODE 0x38 // Idle Mode Off 56 #define NT35310_ENTER_IDLE_MODE 0x39 // Idle Mode On 57 #define NT35310_SET_PIXEL_FORMAT 0x3A // Set the Interface Pixel Format 58 #define NT35310_RGBCTRL 0x3B // RGB Interface Signal Control 59 #define NT35310_RAMWRC 0x3C // Memory Write Continuously 60 #define NT35310_RAMRDC 0x3E // RAM Read Continuously 61 #define NT35310_SET_TEAR_SCANLINE 0x44 // Set Tear Line 62 #define NT35310_RDSCL 0x45 // Read Scan Line 63 #define NT35310_ENTER_DSTB_MODE 0x4F // Enter the Deep Standby Mode 64 #define NT35310_WRDISBV 0x51 // Write Display Brightness 65 #define NT35310_RDDISBV 0x52 // Read Display Brightness 66 #define NT35310_WRCTRLD1 0x53 // Write CTRL Display 67 #define NT35310_RDCTRLD 0x54 // Read CTRL Display 68 #define NT35310_WRCTRLD2 0x55 // Write CTRL Display 69 #define NT35310_RDCABC 0x56 // Read Content Adaptive Brightness Control (CABC) Mode 70 #define NT35310_RDCABCMB 0x5F // Read CABC Minimum Brightness 71 #define NT35310_RDDSDR2 0x68 // Read Display Self-Diagnostic Result 72 #define NT35310_SET_MDDI 0x8F 73 #define NT35310_RDDDBS 0xA1 // Read DDB Start 74 #define NT35310_RDDDBC 0xA8 // Read DDB Continue 75 #define NT35310_RDFCS 0xAA // Read First Checksum 76 #define NT35310_MDDI_WAKE_TOGGLE 0xAD // MDDI VSYNC BASED LINK WAKE-UP 77 #define NT35310_STB_EDGE_POSITION 0xAE 78 #define NT35310_RDCCS 0xAF // Read Continue Checksum 79 #define NT35310_RDID1 0xDA // Read ID1 80 #define NT35310_RDID2 0xDB // Read ID2 81 #define NT35310_RDID3 0xDC // Read ID3 82 #define NT35310_WRITE_IDLEMODE_BL 0xE1 // Write IDLEMODE_BL_Control 83 #define NT35310_READ_IDLEMODE_BL 0xE2 // Read IDLEMODE_BL_Control 84 #define NT35310_PAGE_CTRL 0xED // Unlock CMD2 85 #define NT35310_PAGE_STATUS 0xFF // PAGE unlock status 86 87 // 6.2 CMD2_P0 REGISTER LIST 88 #define NT35310_DISPLAY_CTRL 0xB0 89 #define NT35310_PORCH_CTRL 0xB1 // Front & Back Porch Setting 90 #define NT35310_FRAMERATE_CTRL 0xB2 91 #define NT35310_SPI_RGB_IF_SETTING 0xB3 // SPI&RGB INTERFACE SETTING 92 #define NT35310_INVCTRL 0xB4 // Inversion Control 93 #define NT35310_PMTCTL 0xB5 // Partial and Idle Mode Timing Control 94 #define NT35310_DISPLAY_CTRL_NORM 0xB6 95 #define NT35310_DISPLAY_CTRL2 0xB7 // Set the States for LED Control 96 #define NT35310_MTP_SELECTION 0xB8 97 #define NT35310_PWR_CTRL1 0xC0 98 #define NT35310_PWR_CTRL2 0xC1 99 #define NT35310_PWR_CTRL3 0xC2 100 #define NT35310_PWR_CTRL5 0xC3 101 #define NT35310_PWR_CTRL6 0xC4 102 #define NT35310_PWR_CTRL7 0xC5 103 #define NT35310_PWR_CTRL8 0xC6 104 #define NT35310_WID_CTRL1 0xD1 // WID1 105 #define NT35310_WID_CTRL2 0xD2 // WID2 106 #define NT35310_WID_CTRL3 0xD3 // WID3 107 #define NT35310_READID4 0xD4 // Read ID4 108 #define NT35310_DDB_CTRL 0xD5 // Write DDB Info 109 #define NT35310_RDVNT 0xDD // Read NV Memory Flag Status 110 #define NT35310_EPWRITE 0xDE // NV Memory Write Command 111 #define NT35310_MTPPWR 0xDF // MTP Write function enable 112 #define NT35310_RDREGEXT1 0xEB // Register read command in SPI interface 113 #define NT35310_RDREGEXT2 0xEC // Register read command in SPI interface 114 #define NT35310_PAGE_LOCK1 0xEF // Set the Register to command1 115 #define NT35310_PAGE_LOCK2 0xBF // Set the Register to command2 116 117 // 6.3 CMD2_P1 REGISTER LIST 118 #define NT35310_3GAMMAR_CTRL_RED_P 0xE0 119 #define NT35310_3GAMAR_CTRL_RED_N 0xE1 120 #define NT35310_3GAMMAR_CTRL_GREEN_P 0xE2 121 #define NT35310_3GAMMAR_CTRL_GREEN_N 0xE3 122 #define NT35310_3GAMMAR_CTRL_BLUE_P 0xE4 123 #define NT35310_3GAMMAR_CTRL_BLUE_N 0xE5 124 #define NT35310_CABC_GAMMA1 0xE6 125 #define NT35310_CABC_GAMMA2 0xE7 126 #define NT35310_CABC_GAMMA3 0xE8 127 #define NT35310_PAGE_LOCK3 0x00 // Set the Register to command2 Page 0 128 129 // parameters 130 #define NT35310_MADCTL_MY 0x80 // Bottom to top 131 #define NT35310_MADCTL_MX 0x40 // Right to left 132 #define NT35310_MADCTL_MV 0x20 // Reverse Mode 133 #define NT35310_MADCTL_ML 0x10 // LCD refresh Bottom to top 134 #define NT35310_MADCTL_RGB 0x00 // Red-Green-Blue pixel order 135 #define NT35310_MADCTL_BGR 0x08 // Blue-Green-Red pixel order 136 #define NT35310_MADCTL_MH 0x04 // LCD refresh right to left 137 138 static const uint8_t nt35310_init_operations[] = { 139 BEGIN_WRITE, 140 WRITE_C8_D16, NT35310_PAGE_CTRL, 0x01, 0xFE, 141 142 WRITE_C8_D16, 0xEE, 0xDE, 0x21, // PAGE_CTRL Into CMD3 143 144 WRITE_C8_D8, 0xF1, 0x01, 145 WRITE_C8_D8, 0xDF, 0x10, 146 147 // VCOMvoltage// 148 WRITE_C8_D8, NT35310_PWR_CTRL6, 0x8F, // 5f 149 150 WRITE_COMMAND_8, NT35310_PWR_CTRL8, 151 WRITE_BYTES, 4, 0x00, 0xE2, 0xE2, 0xE2, 152 153 WRITE_C8_D8, NT35310_PAGE_LOCK2, 0xAA, 154 155 WRITE_COMMAND_8, 0xB0, 156 WRITE_BYTES, 18, 157 0x0D, 0x00, 0x0D, 0x00, 0x11, 158 0x00, 0x19, 0x00, 0x21, 0x00, 159 0x2D, 0x00, 0x3D, 0x00, 0x5D, 160 0x00, 0x5D, 0x00, 161 162 WRITE_COMMAND_8, 0xB1, 163 WRITE_BYTES, 6, 164 0x80, 0x00, 0x8B, 0x00, 0x96, 165 0x00, 166 167 WRITE_COMMAND_8, 0xB2, 168 WRITE_BYTES, 6, 169 0x00, 0x00, 0x02, 0x00, 0x03, 170 0x00, 171 172 WRITE_COMMAND_8, 0xB3, 173 WRITE_BYTES, 24, 174 0x00, 0x00, 0x00, 0x00, 0x00, 175 0x00, 0x00, 0x00, 0x00, 0x00, 176 0x00, 0x00, 0x00, 0x00, 0x00, 177 0x00, 0x00, 0x00, 0x00, 0x00, 178 0x00, 0x00, 0x00, 0x00, 179 180 WRITE_COMMAND_8, 0xB4, 181 WRITE_BYTES, 6, 182 0x8B, 0x00, 0x96, 0x00, 0xA1, 183 0x00, 184 185 WRITE_COMMAND_8, 0xB5, 186 WRITE_BYTES, 6, 187 0x02, 0x00, 0x03, 0x00, 0x04, 188 0x00, 189 190 WRITE_C8_D16, 0xB6, 0x00, 0x00, 191 192 WRITE_COMMAND_8, 0xB7, 193 WRITE_BYTES, 22, 194 0x00, 0x00, 0x3F, 0x00, 0x5E, 195 0x00, 0x64, 0x00, 0x8C, 0x00, 196 0xAC, 0x00, 0xDC, 0x00, 0x70, 197 0x00, 0x90, 0x00, 0xEB, 0x00, 198 0xDC, 0x00, 199 200 WRITE_COMMAND_8, 0xB8, 201 WRITE_BYTES, 8, 202 0x00, 0x00, 0x00, 0x00, 0x00, 203 0x00, 0x00, 0x00, 204 205 WRITE_COMMAND_8, 0xBA, 206 WRITE_BYTES, 4, 207 0x24, 0x00, 0x00, 0x00, 208 209 WRITE_COMMAND_8, 0xC1, 210 WRITE_BYTES, 6, 211 0x20, 0x00, 0x54, 0x00, 0xFF, 212 0x00, 213 214 WRITE_COMMAND_8, 0xC2, 215 WRITE_BYTES, 4, 216 0x0A, 0x00, 0x04, 0x00, 217 218 WRITE_COMMAND_8, 0xC3, 219 WRITE_BYTES, 48, 220 0x3C, 0x00, 0x3A, 0x00, 0x39, 221 0x00, 0x37, 0x00, 0x3C, 0x00, 222 0x36, 0x00, 0x32, 0x00, 0x2F, 223 0x00, 0x2C, 0x00, 0x29, 0x00, 224 0x26, 0x00, 0x24, 0x00, 0x24, 225 0x00, 0x23, 0x00, 0x3C, 0x00, 226 0x36, 0x00, 0x32, 0x00, 0x2F, 227 0x00, 0x2C, 0x00, 0x29, 0x00, 228 0x26, 0x00, 0x24, 0x00, 0x24, 229 0x00, 0x23, 0x00, 230 231 WRITE_COMMAND_8, 0xC4, 232 WRITE_BYTES, 26, 233 0x62, 0x00, 0x05, 0x00, 0x84, 234 0x00, 0xF0, 0x00, 0x18, 0x00, 235 0xA4, 0x00, 0x18, 0x00, 0x50, 236 0x00, 0x0C, 0x00, 0x17, 0x00, 237 0x95, 0x00, 0xF3, 0x00, 0xE6, 238 0x00, 239 240 WRITE_COMMAND_8, 0xC5, 241 WRITE_BYTES, 10, 242 0x32, 0x00, 0x44, 0x00, 0x65, 243 0x00, 0x76, 0x00, 0x88, 0x00, 244 245 WRITE_COMMAND_8, 0xC6, 246 WRITE_BYTES, 6, 247 0x20, 0x00, 0x17, 0x00, 0x01, 248 0x00, 249 250 WRITE_COMMAND_8, 0xC7, 251 WRITE_BYTES, 4, 252 0x00, 0x00, 0x00, 0x00, 253 254 WRITE_COMMAND_8, 0xC8, 255 WRITE_BYTES, 4, 256 0x00, 0x00, 0x00, 0x00, 257 258 WRITE_COMMAND_8, 0xC9, 259 WRITE_BYTES, 16, 260 0x00, 0x00, 0x00, 0x00, 0x00, 261 0x00, 0x00, 0x00, 0x00, 0x00, 262 0x00, 0x00, 0x00, 0x00, 0x00, 263 0x00, 264 265 WRITE_COMMAND_8, NT35310_3GAMMAR_CTRL_RED_P, 266 WRITE_BYTES, 36, 267 0x16, 0x00, 0x1C, 0x00, 0x21, 268 0x00, 0x36, 0x00, 0x46, 0x00, 269 0x52, 0x00, 0x64, 0x00, 0x7A, 270 0x00, 0x8B, 0x00, 0x99, 0x00, 271 0xA8, 0x00, 0xB9, 0x00, 0xC4, 272 0x00, 0xCA, 0x00, 0xD2, 0x00, 273 0xD9, 0x00, 0xE0, 0x00, 0xF3, 274 0x00, 275 276 // WRITE_COMMAND_8, NT35310_3GAMAR_CTRL_RED_N, 277 // WRITE_BYTES, 36, 278 // 0x16, 0x00, 0x1C, 0x00, 0x22, 279 // 0x00, 0x36, 0x00, 0x45, 0x00, 280 // 0x52, 0x00, 0x64, 0x00, 0x7A, 281 // 0x00, 0x8B, 0x00, 0x99, 0x00, 282 // 0xA8, 0x00, 0xB9, 0x00, 0xC4, 283 // 0x00, 0xCA, 0x00, 0xD2, 0x00, 284 // 0xD8, 0x00, 0xE0, 0x00, 0xF3, 285 // 0x00, 286 287 WRITE_COMMAND_8, NT35310_3GAMMAR_CTRL_GREEN_P, 288 WRITE_BYTES, 36, 289 0x05, 0x00, 0x0B, 0x00, 0x1B, 290 0x00, 0x34, 0x00, 0x44, 0x00, 291 0x4F, 0x00, 0x61, 0x00, 0x79, 292 0x00, 0x88, 0x00, 0x97, 0x00, 293 0xA6, 0x00, 0xB7, 0x00, 0xC2, 294 0x00, 0xC7, 0x00, 0xD1, 0x00, 295 0xD6, 0x00, 0xDD, 0x00, 0xF3, 296 0x00, 297 298 // WRITE_COMMAND_8, NT35310_3GAMMAR_CTRL_GREEN_N, 299 // WRITE_BYTES, 36, 300 // 0x05, 0x00, 0x0A, 0x00, 0x1C, 301 // 0x00, 0x33, 0x00, 0x44, 0x00, 302 // 0x50, 0x00, 0x62, 0x00, 0x78, 303 // 0x00, 0x88, 0x00, 0x97, 0x00, 304 // 0xA6, 0x00, 0xB7, 0x00, 0xC2, 305 // 0x00, 0xC7, 0x00, 0xD1, 0x00, 306 // 0xD5, 0x00, 0xDD, 0x00, 0xF3, 307 // 0x00, 308 309 WRITE_COMMAND_8, NT35310_3GAMMAR_CTRL_BLUE_P, 310 WRITE_BYTES, 36, 311 // 0x01, 0x00, 0x01, 0x00, 0x02, 312 // 0x00, 0x2A, 0x00, 0x3C, 0x00, 313 // 0x4B, 0x00, 0x5D, 0x00, 0x74, 314 // 0x00, 0x84, 0x00, 0x93, 0x00, 315 // 0xA2, 0x00, 0xB3, 0x00, 0xBE, 316 // 0x00, 0xC4, 0x00, 0xCD, 0x00, 317 // 0xD3, 0x00, 0xDD, 0x00, 0xF3, 318 // 0x00, 319 0x05, 0x00, 0x0B, 0x00, 0x1B, 320 0x00, 0x34, 0x00, 0x44, 0x00, 321 0x4F, 0x00, 0x61, 0x00, 0x79, 322 0x00, 0x88, 0x00, 0x97, 0x00, 323 0xA6, 0x00, 0xB7, 0x00, 0xC2, 324 0x00, 0xC7, 0x00, 0xD1, 0x00, 325 0xD6, 0x00, 0xDD, 0x00, 0xF3, 326 0x00, 327 328 // WRITE_COMMAND_8, NT35310_3GAMMAR_CTRL_BLUE_N, 329 // WRITE_BYTES, 36, 330 // 0x00, 0x00, 0x00, 0x00, 0x02, 331 // 0x00, 0x29, 0x00, 0x3C, 0x00, 332 // 0x4B, 0x00, 0x5D, 0x00, 0x74, 333 // 0x00, 0x84, 0x00, 0x93, 0x00, 334 // 0xA2, 0x00, 0xB3, 0x00, 0xBE, 335 // 0x00, 0xC4, 0x00, 0xCD, 0x00, 336 // 0xD3, 0x00, 0xDC, 0x00, 0xF3, 337 // 0x00, 338 339 WRITE_COMMAND_8, 0xE6, 340 WRITE_BYTES, 32, 341 0x11, 0x00, 0x34, 0x00, 0x56, 342 0x00, 0x76, 0x00, 0x77, 0x00, 343 0x66, 0x00, 0x88, 0x00, 0x99, 344 0x00, 0xBB, 0x00, 0x99, 0x00, 345 0x66, 0x00, 0x55, 0x00, 0x55, 346 0x00, 0x45, 0x00, 0x43, 0x00, 347 0x44, 0x00, 348 349 WRITE_COMMAND_8, 0xE7, 350 WRITE_BYTES, 32, 351 0x32, 0x00, 0x55, 0x00, 0x76, 352 0x00, 0x66, 0x00, 0x67, 0x00, 353 0x67, 0x00, 0x87, 0x00, 0x99, 354 0x00, 0xBB, 0x00, 0x99, 0x00, 355 0x77, 0x00, 0x44, 0x00, 0x56, 356 0x00, 0x23, 0x00, 0x33, 0x00, 357 0x45, 0x00, 358 359 WRITE_COMMAND_8, 0xE8, 360 WRITE_BYTES, 32, 361 0x00, 0x00, 0x99, 0x00, 0x87, 362 0x00, 0x88, 0x00, 0x77, 0x00, 363 0x66, 0x00, 0x88, 0x00, 0xAA, 364 0x00, 0xBB, 0x00, 0x99, 0x00, 365 0x66, 0x00, 0x55, 0x00, 0x55, 366 0x00, 0x44, 0x00, 0x44, 0x00, 367 0x55, 0x00, 368 369 WRITE_COMMAND_8, 0xE9, 370 WRITE_BYTES, 4, 371 0xAA, 0x00, 0x00, 0x00, 372 373 WRITE_C8_D8, 0x00, 0xAA, 374 375 WRITE_COMMAND_8, 0xCF, 376 WRITE_BYTES, 17, 377 0x00, 0x00, 0x00, 0x00, 0x00, 378 0x00, 0x00, 0x00, 0x00, 0x00, 379 0x00, 0x00, 0x00, 0x00, 0x00, 380 0x00, 0x00, 381 382 WRITE_COMMAND_8, 0xF0, 383 WRITE_BYTES, 5, 384 0x00, 0x50, 0x00, 0x00, 0x00, 385 386 WRITE_C8_D8, 0xF3, 0x00, 387 388 WRITE_COMMAND_8, 0xF9, 389 WRITE_BYTES, 4, 390 0x06, 0x10, 0x29, 0x00, 391 392 WRITE_C8_D8, NT35310_SET_PIXEL_FORMAT, 0x55, // 66 393 394 WRITE_COMMAND_8, NT35310_EXIT_SLEEP_MODE, 395 END_WRITE, 396 397 DELAY, NT35310_SLPOUT_DELAY, 398 399 BEGIN_WRITE, 400 WRITE_COMMAND_8, NT35310_SET_DISPLAY_ON, 401 WRITE_C8_D8, NT35310_SET_TEAR_ON, 0x00, 402 403 WRITE_C8_D8, NT35310_WRDISBV, 0xFF, 404 WRITE_C8_D8, NT35310_WRCTRLD1, 0x2C, 405 WRITE_C8_D8, NT35310_WRCTRLD2, 0x82, 406 END_WRITE}; 407 408 class Arduino_NT35310 : public Arduino_TFT 409 { 410 public: 411 Arduino_NT35310( 412 Arduino_DataBus *bus, int8_t rst = GFX_NOT_DEFINED, uint8_t r = 0, 413 bool ips = false, int16_t w = NT35310_TFTWIDTH, int16_t h = NT35310_TFTHEIGHT, 414 uint8_t col_offset1 = 0, uint8_t row_offset1 = 0, uint8_t col_offset2 = 0, uint8_t row_offset2 = 0); 415 416 bool begin(int32_t speed = GFX_NOT_DEFINED) override; 417 void writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) override; 418 void setRotation(uint8_t r) override; 419 void invertDisplay(bool) override; 420 void displayOn() override; 421 void displayOff() override; 422 423 protected: 424 void tftInit() override; 425 426 private: 427 }; 428 429 #endif // _ARDUINO_NT35310_H_