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_ILI9331.h (7544B)
1 /* 2 * start rewrite from: 3 * https://github.com/adafruit/Adafruit-GFX-Library.git 4 * https://github.com/adafruit/Adafruit_ILI9331.git 5 */ 6 #ifndef _ARDUINO_ILI9331_H_ 7 #define _ARDUINO_ILI9331_H_ 8 9 #include <Arduino.h> 10 #include <Print.h> 11 #include "../Arduino_GFX.h" 12 #include "../Arduino_TFT.h" 13 14 #define ILI9331_TFTWIDTH 240 /// ILI9331 max TFT width 15 #define ILI9331_TFTHEIGHT 320 /// ILI9331 max TFT height 16 17 #define ILI9331_RST_DELAY 150 18 19 #define ILI9331_DRVCODER 0x00 /// Driver Code Read 20 #define ILI9331_DRVOUTCTL 0x01 /// Driver Output Control 1 21 #define ILI9331_DRIVWVCTL 0x02 /// LCD Driving Control 22 #define ILI9331_ENTRY_MODE 0x03 /// Entry Mode 23 #define ILI9331_DC1 0x07 /// Display Control 1 24 #define ILI9331_DC2 0x08 /// Display Control 2 25 #define ILI9331_DC3 0x09 /// Display Control 3 26 #define ILI9331_DC4 0x0A /// Display Control 4 27 #define ILI9331_RGBDIC1 0x0C /// RGB Display Interface Control 1 28 #define ILI9331_FMARK 0x0D /// Frame Marker Position 29 #define ILI9331_RGDIC2 0x0F /// RGB Display Interface Control 2 30 31 #define ILI9331_PWCTL1 0x10 /// Power Control 1 32 #define ILI9331_PWCTL2 0x11 /// Power Control 2 33 #define ILI9331_PWCTL3 0x12 /// Power Control 3 34 #define ILI9331_PWCTL4 0x13 /// Power Control 4 35 36 #define ILI9331_MC 0x20 /// GRAM Horizontal Address Set 37 #define ILI9331_MP 0x21 /// GRAM Vertical Address Set 38 #define ILI9331_MW 0x22 /// Write Data to GRAM 39 40 #define ILI9331_PWCTL7 0x29 /// Power Control 7 41 #define ILI9331_FRCR 0x2B /// Frame Rate and Color Control 42 43 #define ILI9331_HSA 0x50 /// Horizontal RAM Address Position 44 #define ILI9331_HSE 0x51 /// Horizontal RAM Address Position 45 #define ILI9331_VSA 0x52 /// Vertical RAM Address Position 46 #define ILI9331_VSE 0x53 /// Vertical RAM Address Position 47 48 #define ILI9331_GSC1 0x60 /// Gate Scan Control 49 #define ILI9331_GSC2 0x61 /// Gate Scan Control 50 #define ILI9331_GSC3 0x6A /// Gate Scan Control 51 52 #define ILI9331_PANCLT1 0x90 /// Panel Interface Control 1 53 #define ILI9331_PANCLT2 0x92 /// Panel Interface Control 2 54 #define ILI9331_PANCLT4 0x95 /// Panel Interface Control 4 55 #define ILI9331_PANCLT5 0x97 /// Panel Interface Control 5 56 57 #define ILI9331_WBRI 0xB1 /// Write Display Brightness Value 58 #define ILI9331_RBRI 0xB2 /// Read Display Brightness Value 59 #define ILI9331_WBRICTRL 0xB3 /// Write CTRL Display Value 60 #define ILI9331_RBRICTRL 0xB4 /// Read CTRL Display Value 61 #define ILI9331_WCABC 0xB5 /// Write Content Adaptive Brightness Control Value 62 #define ILI9331_RCABC 0xB6 /// Read Content Adaptive Brightness Control Value 63 #define ILI9331_WCABCMIN 0xBE /// Write CABC Minimum Brightness 64 #define ILI9331_RCABCMIN 0xBF /// Read CABC Minimum Brightness 65 #define ILI9331_CABCCTL1 0xC8 /// CABC Control 1 66 #define ILI9331_CABCCTL2 0xC9 /// CABC Control 2 67 #define ILI9331_CABCCTL3 0xCA /// CABC Control 3 68 #define ILI9331_CABCCTL4 0xCB /// CABC Control 4 69 #define ILI9331_CABCCTL5 0xCC /// CABC Control 5 70 #define ILI9331_CABCCTL6 0xCD /// CABC Control 6 71 #define ILI9331_CABCCTL7 0xCD /// CABC Control 7 72 73 static const uint8_t ili9331_init_operations[] = { 74 BEGIN_WRITE, 75 //************* Start Initial Sequence **********// 76 WRITE_C16_D16, 0x00, 0xE7, 0x10, 0x14, // Not sure about this. 77 // This register is not in datasheet and display inits without it, 78 // but it mentioned in official code snippet. 79 WRITE_C16_D16, 0x00, 0x01, 0x01, 0x00, // set SS and SM bit 80 WRITE_C16_D16, 0x00, 0x02, 0x02, 0x00, // set 1 line inversion 81 WRITE_C16_D16, 0x00, 0x03, 0x10, 0x30, // set GRAM write direction and BGR=1. 82 WRITE_C16_D16, 0x00, 0x08, 0x02, 0x07, // set the back porch and front porch 83 WRITE_C16_D16, 0x00, 0x09, 0x00, 0x00, // set non-display area refresh cycle ISC[3:0] 84 WRITE_C16_D16, 0x00, 0x0A, 0x00, 0x00, // FMARK function 85 WRITE_C16_D16, 0x00, 0x0C, 0x00, 0x00, // RGB interface setting 86 WRITE_C16_D16, 0x00, 0x0D, 0x00, 0x00, // Frame marker Position 87 WRITE_C16_D16, 0x00, 0x0F, 0x00, 0x00, // RGB interface polarity 88 //*************Power On sequence ****************// 89 WRITE_C16_D16, 0x00, 0x10, 0x00, 0x00, // SAP, BT[3:0], AP, DSTB, SLP, STB 90 WRITE_C16_D16, 0x00, 0x11, 0x00, 0x01, // DC1[2:0], DC0[2:0], VC[2:0] 91 WRITE_C16_D16, 0x00, 0x12, 0x00, 0x00, // VREG1OUT voltage 92 WRITE_C16_D16, 0x00, 0x13, 0x00, 0x00, // VDV[4:0] for VCOM amplitude 93 DELAY, 200, // Dis-charge capacitor power voltage 94 WRITE_C16_D16, 0x00, 0x10, 0x16, 0x90, // SAP=1, BT=6, APE=1, AP=1, DSTB=0, SLP=0, STB=0 95 WRITE_C16_D16, 0x00, 0x11, 0x00, 0x01, // DC1=2, DC0=2, VC=7 96 DELAY, 50, // wait_ms 50ms 97 WRITE_C16_D16, 0x00, 0x12, 0x00, 0x0C, // Internal reference voltage= Vci; VCIRE=1, PON=0, VRH=5 98 DELAY, 50, // wait_ms 50ms 99 WRITE_C16_D16, 0x00, 0x13, 0x07, 0x00, // VDV=28 for VCOM amplitude 100 WRITE_C16_D16, 0x00, 0x29, 0x00, 0x05, // VCM=10 for VCOMH 101 WRITE_C16_D16, 0x00, 0x2B, 0x00, 0x0D, // Set Frame Rate 102 DELAY, 50, // wait_ms 50ms 103 WRITE_C16_D16, 0x00, 0x20, 0x00, 0x00, // GRAM horizontal Address 104 WRITE_C16_D16, 0x00, 0x21, 0x00, 0x00, // GRAM Vertical Address 105 // ----------- Adjust the Gamma Curve ----------// 106 WRITE_C16_D16, 0x00, 0x30, 0x00, 0x00, 107 WRITE_C16_D16, 0x00, 0x31, 0x02, 0x07, 108 WRITE_C16_D16, 0x00, 0x32, 0x00, 0x00, 109 WRITE_C16_D16, 0x00, 0x35, 0x00, 0x07, 110 WRITE_C16_D16, 0x00, 0x36, 0x05, 0x08, 111 WRITE_C16_D16, 0x00, 0x37, 0x07, 0x07, 112 WRITE_C16_D16, 0x00, 0x38, 0x00, 0x05, 113 WRITE_C16_D16, 0x00, 0x39, 0x07, 0x07, 114 WRITE_C16_D16, 0x00, 0x3C, 0x02, 0x02, 115 WRITE_C16_D16, 0x00, 0x3D, 0x0A, 0x09, 116 //------------------ Set GRAM area ---------------// 117 WRITE_C16_D16, 0x00, 0x50, 0x00, 0x00, // Horizontal GRAM Start Address 118 WRITE_C16_D16, 0x00, 0x51, 0x00, 0xEF, // Horizontal GRAM End Address 119 WRITE_C16_D16, 0x00, 0x52, 0x00, 0x00, // Vertical GRAM Start Address 120 WRITE_C16_D16, 0x00, 0x53, 0x01, 0x3F, // Vertical GRAM Start Address 121 WRITE_C16_D16, 0x00, 0x60, 0xA7, 0x00, // Gate Scan Line GS=0 [0xA700] 122 WRITE_C16_D16, 0x00, 0x61, 0x00, 0x01, // NDL,VLE, REV 123 WRITE_C16_D16, 0x00, 0x6A, 0x00, 0x00, // set scrolling line 124 //-------------- Partial Display Control ---------// 125 WRITE_C16_D16, 0x00, 0x80, 0x00, 0x00, 126 WRITE_C16_D16, 0x00, 0x81, 0x00, 0x00, 127 WRITE_C16_D16, 0x00, 0x82, 0x00, 0x00, 128 WRITE_C16_D16, 0x00, 0x83, 0x00, 0x00, 129 WRITE_C16_D16, 0x00, 0x84, 0x00, 0x00, 130 WRITE_C16_D16, 0x00, 0x85, 0x00, 0x00, 131 //-------------- Panel Control -------------------// 132 WRITE_C16_D16, 0x00, 0x90, 0x00, 0x10, 133 WRITE_C16_D16, 0x00, 0x92, 0x06, 0x00, 134 WRITE_C16_D16, 0x00, 0x07, 0x01, 0x33, 135 //-------------- Backlight Control ---------------// 136 WRITE_C16_D16, 0x00, 0xB3, 0x00, 0x24, // Enable backlight 137 WRITE_C16_D16, 0x00, 0xB1, 0x00, 0xFF, // Set maximum brightness 138 END_WRITE}; 139 140 class Arduino_ILI9331 : public Arduino_TFT 141 { 142 public: 143 Arduino_ILI9331(Arduino_DataBus *bus, int8_t rst = GFX_NOT_DEFINED, uint8_t r = 0, bool ips = false); 144 145 bool begin(int32_t speed = GFX_NOT_DEFINED) override; 146 147 void setRotation(uint8_t r) override; 148 149 void writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) override; 150 151 void invertDisplay(bool) override; 152 void displayOn() override; 153 void displayOff() override; 154 155 protected: 156 void tftInit() override; 157 158 private: 159 uint16_t _MC, _MP, _SC, _EC, _SP, _EP; 160 }; 161 162 #endif