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_NT39125.h (8836B)
1 /* 2 * start rewrite from: 3 * https://github.com/adafruit/Adafruit-GFX-Library.git 4 * https://github.com/daumemo/IPS_LCD_NT39125_FT6236_Arduino_eSPI_Test 5 * Data Sheet: 6 * http://read.pudn.com/downloads648/ebook/2620902/NT39125.pdf 7 */ 8 #ifndef _ARDUINO_NT39125_H_ 9 #define _ARDUINO_NT39125_H_ 10 11 #include <Arduino.h> 12 #include <Print.h> 13 #include "../Arduino_GFX.h" 14 #include "../Arduino_TFT.h" 15 16 #define NT39125_TFTWIDTH 240 // NT39125 max width 17 #define NT39125_TFTHEIGHT 432 // NT39125 max height 18 19 #define NT39125_RST_DELAY 200 // delay ms wait for reset finish 20 #define NT39125_SLPIN_DELAY 20 // delay ms wait for sleep in finish 21 #define NT39125_SLPOUT_DELAY 1200 // delay ms wait for sleep out finish 22 23 // User Command 24 #define NT39125_NOP 0x00 // NOP 25 #define NT39125_SWRESET 0x01 // Software Reset 26 #define NT39125_RDDID 0x04 // Read Display ID 27 #define NT39125_RDDST 0x09 // Read Display Status 28 #define NT39125_RDDPM 0x0A // Read Display Power Mode 29 #define NT39125_RDDMADCTR 0x0B // Read Display MADCTR 30 #define NT39125_RDDCOLMOD 0x0C // Read Display Pixel Format 31 #define NT39125_RDDIM 0x0D // Read Display Image Mode 32 #define NT39125_RDDSM 0x0E // Read Display Signal Mode 33 #define NT39125_RDDSDR 0x0F // Read Display Self-Diagnostic Result 34 #define NT39125_SLPIN 0x10 // Sleep In 35 #define NT39125_SLPOUT 0x11 // Sleep Out 36 #define NT39125_PTLON 0x12 // Partial Display Mode On 37 #define NT39125_NORON 0x13 // Normal Display Mode On 38 #define NT39125_INVOFF 0x20 // Display Inversion Off 39 #define NT39125_INVON 0x21 // Display Inversion On 40 #define NT39125_GAMSET 0x26 // Gamma Set 41 #define NT39125_DISPOFF 0x28 // Display Off 42 #define NT39125_DISPON 0x29 // Display On 43 #define NT39125_CASET 0x2A // Column Address Set 44 #define NT39125_RASET 0x2B // Row Address Set 45 #define NT39125_RAMWR 0x2C // Memory Write 46 #define NT39125_RAMRD 0x2E // Memory Read 47 #define NT39125_RGBSET 0x2D // Color Set for 65k or 4k-Color Display 48 #define NT39125_PTLAR 0x30 // Partial Area 49 #define NT39125_SCRLAR 0x33 // Scroll Area 50 #define NT39125_TEOFF 0x34 // Tearing Effect Line OFF 51 #define NT39125_TEON 0x35 // Tearing Effect Line ON 52 #define NT39125_MADCTL 0x36 // Memory Data Access Control 53 #define NT39125_VSCSAD 0x37 // Vertical Scroll Start Address of RAM 54 #define NT39125_IDMOFF 0x38 // Idle Mode Off 55 #define NT39125_IDMON 0x39 // Idle Mode On 56 #define NT39125_COLMOD 0x3A // Interface Pixel Format 57 #define NT39125_RDID1 0xDA // Read ID1 Value 58 #define NT39125_RDID2 0xDB // Read ID2 Value 59 #define NT39125_RDID3 0xDC // Read ID3 Value 60 #define NT39125_IFMODE 0xB0 // Set Display Interface Mode 61 #define NT39125_FRMCTR1 0xB1 // Set Division ratio for internal clocks of Normal mode 62 #define NT39125_FRMCTR2 0xB2 // Set Division ratio for internal clocks of Idle mode 63 #define NT39125_FRMCTR3 0xB3 // Set Division ratio for internal clocks of Partial mode (Idle mode off) 64 #define NT39125_INVCTR 0xB4 // Inversion Control 65 #define NT39125_RESCTR 0xB5 // Display Resolution Control 66 #define NT39125_DISSET5 0xB6 // Display Function set 5 67 #define NT39125_PWCTR1 0xC0 // Power Control 1 68 #define NT39125_PWCTR2 0xC1 // Power Control 2 69 #define NT39125_PWCTR3 0xC2 // Power Control 3 (in Normal mode/ Full colors) 70 #define NT39125_PWCTR4 0xC3 // Power Control 4 (in Idle mode/ 8-colors) 71 #define NT39125_PWCTR5 0xC4 // Power Control 5 (in Partial mode/ full-colors) 72 #define NT39125_VMCTR1 0xC5 // VCOM Control 73 #define NT39125_VMFCTR 0xC7 // VCOM offset control 74 #define NT39125_RDVMF 0xC8 // Read VCOM offset value 75 #define NT39125_WRID2 0xD1 // Write ID2 for MTP program 76 #define NT39125_WRID3 0xD2 // Write ID3 for MTP program 77 #define NT39125_RDID4 0xD3 // Read ID4 for IC Vender Code 78 #define NT39125_RDVNT 0xD4 // Read NV Memory Flag Status 79 #define NT39125_EPWRITE 0xDE // MTP write command 80 #define NT39125_DNVRS 0xDF // NV Memory Control 81 #define NT39125_GMCTRP0 0xE0 // Positive RED Gamma Control 82 #define NT39125_GMCTRN0 0xE1 // Negative RED Gamma Control 83 #define NT39125_GMCTRP1 0xE2 // Positive GREEN Gamma Control 84 #define NT39125_GMCTRN1 0xE3 // Negative GREEN Gamma Control 85 #define NT39125_GMCTRP2 0xE4 // Positive BLUE Gamma Control 86 #define NT39125_GMCTRN2 0xE5 // Negative BLUE Gamma Control 87 #define NT39125_GAM_R_SEL 0xEA // Gamma Selection 88 #define NT39125_TSTGVDD 0xEB // GVDD output control 89 90 // parameters 91 #define NT39125_MADCTL_MY 0x80 // Bottom to top 92 #define NT39125_MADCTL_MX 0x40 // Right to left 93 #define NT39125_MADCTL_MV 0x20 // Reverse Mode 94 #define NT39125_MADCTL_ML 0x10 // LCD refresh Bottom to top 95 #define NT39125_MADCTL_RGB 0x00 // Red-Green-Blue pixel order 96 #define NT39125_MADCTL_BGR 0x08 // Blue-Green-Red pixel order 97 #define NT39125_MADCTL_MH 0x04 // LCD refresh right to left 98 99 static const uint8_t nt39125_init_operations[] = { 100 // Initializing 101 BEGIN_WRITE, 102 WRITE_COMMAND_8, NT39125_SLPOUT, // Sleep Out 103 END_WRITE, 104 105 DELAY, 250, 106 DELAY, 250, 107 DELAY, 250, 108 DELAY, 250, 109 DELAY, 200, 110 111 // Display Settings 112 BEGIN_WRITE, 113 WRITE_C8_D8, NT39125_TEOFF, // Tearing Effect Line OFF 114 WRITE_C8_D16, NT39125_FRMCTR1, 0x11, 0x1b, // Set Division ratio for internal clocks of Normal mode 115 WRITE_C8_D16, NT39125_FRMCTR2, 0x11, 0x1b, // Set Division ratio for internal clocks of Idle mode 116 WRITE_C8_D16, NT39125_FRMCTR3, 0x11, 0x1b, // Set Division ratio for internal clocks of Partial mode (Idle mode off) 117 WRITE_C8_D8, NT39125_INVCTR, 0x02, // Inversion Control 118 WRITE_C8_D16, NT39125_DISSET5, 0x01, 0x02, // Display Function set 5 119 WRITE_C8_D8, NT39125_PWCTR1, 0x24, // Power Control 1, 4.1V 120 121 // VGL -7V 122 WRITE_C8_D16, NT39125_PWCTR2, 0x02, 0x00, // Power Control 2 123 // WRITE_C8_D16, NT39125_PWCTR2, 0x02, 0x07, // gate modulation removed (spec 1.03 version) 124 // VGL -7V 125 126 WRITE_C8_D16, NT39125_PWCTR3, 0x05, 0x01, // Power Control 3 (in Normal mode/ Full colors), e1 setting 127 WRITE_C8_D16, NT39125_PWCTR4, 0x02, 0x05, // Power Control 4 (in Idle mode/ 8-colors) 128 WRITE_C8_D16, NT39125_PWCTR5, 0x02, 0x04, // Power Control 5 (in Partial mode/ full-colors) 129 WRITE_C8_D16, NT39125_VMCTR1, // VCOM Control, Chameleon 130 0x14, // 3 . VcomH 131 0x2e, // -1.35 .VcomL 132 WRITE_C8_D8, NT39125_GAM_R_SEL, 0x01, // Gamma Selection 133 134 ///////////////////////////////////////// gamma ////////////////////// 135 136 WRITE_COMMAND_8, NT39125_GMCTRP0, // Positive RED Gamma Control, d1 third vibration 137 WRITE_BYTES, 15, 138 0x27, 0x2B, 0x2E, 0x06, 139 0x0D, 0x11, 0x28, 0x7B, 140 0x35, 0x0C, 0x20, 0x26, 141 0x25, 0x28, 0x3C, 142 143 WRITE_COMMAND_8, NT39125_GMCTRN0, // Negative RED Gamma Control 144 WRITE_BYTES, 15, 145 0x08, 0x21, 0x26, 0x09, 146 0x0F, 0x12, 0x1F, 0x38, 147 0x31, 0x0D, 0x23, 0x29, 148 0x2C, 0x2F, 0x33, 149 150 WRITE_COMMAND_8, NT39125_GMCTRP1, // Positive GREEN Gamma Control 151 WRITE_BYTES, 15, 152 0x27, 0x2C, 0x2F, 0x07, 153 0x0E, 0x11, 0x29, 0x7A, 154 0x35, 0x0C, 0x20, 0x26, 155 0x24, 0x29, 0x3C, 156 157 WRITE_COMMAND_8, NT39125_GMCTRN1, // Negative GREEN Gamma Control 158 WRITE_BYTES, 15, 159 0x08, 0x20, 0x26, 0x09, 160 0x0F, 0x12, 0x1F, 0x48, 161 0x30, 0x0D, 0x22, 0x28, 162 0x2B, 0x2E, 0x33, 163 164 WRITE_COMMAND_8, NT39125_GMCTRP2, // Positive BLUE Gamma Control 165 WRITE_BYTES, 15, 166 0x1F, 0x24, 0x27, 0x08, 167 0x0F, 0x12, 0x25, 0x7B, 168 0x32, 0x0C, 0x20, 0x26, 169 0x20, 0x25, 0x3C, 170 171 WRITE_COMMAND_8, NT39125_GMCTRN2, // Negative BLUE Gamma Control 172 WRITE_BYTES, 15, 173 0x08, 0x24, 0x2B, 0x09, 174 0x0F, 0x12, 0x22, 0x38, 175 0x35, 0x0C, 0x21, 0x27, 176 0x33, 0x36, 0x3B, 177 178 ////////////////////////////////////////////////////////// 179 180 WRITE_C8_D8, 0x3A, 0x55, // Color mode, 16-bit 181 182 WRITE_COMMAND_8, 0x11, // SLEEP MODE OUT / BOOSTER ON 183 END_WRITE, 184 185 DELAY, 250, 186 DELAY, 250, 187 DELAY, 250, 188 DELAY, 250, 189 DELAY, 200, 190 191 BEGIN_WRITE, 192 // WRITE_COMMAND_8, 0x13, // 193 WRITE_COMMAND_8, 0x29, 194 END_WRITE}; 195 196 class Arduino_NT39125 : public Arduino_TFT 197 { 198 public: 199 Arduino_NT39125( 200 Arduino_DataBus *bus, int8_t rst = GFX_NOT_DEFINED, uint8_t r = 0, 201 bool ips = false, int16_t w = NT39125_TFTWIDTH, int16_t h = NT39125_TFTHEIGHT, 202 uint8_t col_offset1 = 0, uint8_t row_offset1 = 0, uint8_t col_offset2 = 0, uint8_t row_offset2 = 0); 203 204 bool begin(int32_t speed = GFX_NOT_DEFINED) override; 205 void writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) override; 206 void setRotation(uint8_t r) override; 207 void invertDisplay(bool) override; 208 void displayOn() override; 209 void displayOff() override; 210 211 protected: 212 void tftInit() override; 213 214 private: 215 }; 216 217 #endif // _ARDUINO_NT39125_H_