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_ST7735.h (3537B)
1 /* 2 * start rewrite from: 3 * https://github.com/adafruit/Adafruit-GFX-Library.git 4 */ 5 #ifndef _ARDUINO_ST7735_H_ 6 #define _ARDUINO_ST7735_H_ 7 8 #include <Arduino.h> 9 #include <Print.h> 10 #include "../Arduino_GFX.h" 11 #include "../Arduino_TFT.h" 12 13 #define ST7735_TFTWIDTH 128 14 #define ST7735_TFTHEIGHT 160 15 16 #define ST7735_RST_DELAY 50 ///< delay ms wait for reset finish 17 #define ST7735_SLPIN_DELAY 120 ///< delay ms wait for sleep in finish 18 #define ST7735_SLPOUT_DELAY 120 ///< delay ms wait for sleep out finish 19 20 #define ST7735_NOP 0x00 21 #define ST7735_SWRESET 0x01 22 #define ST7735_RDDID 0x04 23 #define ST7735_RDDST 0x09 24 25 #define ST7735_SLPIN 0x10 26 #define ST7735_SLPOUT 0x11 27 #define ST7735_PTLON 0x12 28 #define ST7735_NORON 0x13 29 30 #define ST7735_INVOFF 0x20 31 #define ST7735_INVON 0x21 32 #define ST7735_DISPOFF 0x28 33 #define ST7735_DISPON 0x29 34 35 #define ST7735_CASET 0x2A 36 #define ST7735_RASET 0x2B 37 #define ST7735_RAMWR 0x2C 38 #define ST7735_RAMRD 0x2E 39 40 #define ST7735_PTLAR 0x30 41 #define ST7735_COLMOD 0x3A 42 #define ST7735_MADCTL 0x36 43 44 #define ST7735_FRMCTR1 0xB1 45 #define ST7735_FRMCTR2 0xB2 46 #define ST7735_FRMCTR3 0xB3 47 #define ST7735_INVCTR 0xB4 48 #define ST7735_DISSET5 0xB6 49 50 #define ST7735_PWCTR1 0xC0 51 #define ST7735_PWCTR2 0xC1 52 #define ST7735_PWCTR3 0xC2 53 #define ST7735_PWCTR4 0xC3 54 #define ST7735_PWCTR5 0xC4 55 #define ST7735_VMCTR1 0xC5 56 57 #define ST7735_RDID1 0xDA 58 #define ST7735_RDID2 0xDB 59 #define ST7735_RDID3 0xDC 60 #define ST7735_RDID4 0xDD 61 62 #define ST7735_PWCTR6 0xFC 63 64 #define ST7735_GMCTRP1 0xE0 65 #define ST7735_GMCTRN1 0xE1 66 67 #define ST7735_MADCTL_MY 0x80 68 #define ST7735_MADCTL_MX 0x40 69 #define ST7735_MADCTL_MV 0x20 70 #define ST7735_MADCTL_ML 0x10 71 #define ST7735_MADCTL_RGB 0x00 72 #define ST7735_MADCTL_MH 0x04 73 #define ST7735_MADCTL_BGR 0x08 74 75 static const uint8_t st7735_init_operations[] = { 76 BEGIN_WRITE, 77 WRITE_COMMAND_8, ST7735_SLPOUT, // 2: Out of sleep mode, no args, w/delay 78 END_WRITE, 79 80 DELAY, ST7735_SLPOUT_DELAY, 81 82 BEGIN_WRITE, 83 WRITE_C8_D8, ST7735_COLMOD, 0x05, // 3: Set color mode, 16-bit color 84 85 WRITE_COMMAND_8, ST7735_GMCTRP1, // Gamma Adjustments (pos. polarity), 16 args: 86 WRITE_BYTES, 16, 87 0x09, 0x16, 0x09, 0x20, // (Not entirely necessary, but provides 88 0x21, 0x1B, 0x13, 0x19, // accurate colors) 89 0x17, 0x15, 0x1E, 0x2B, 90 0x04, 0x05, 0x02, 0x0E, 91 92 WRITE_COMMAND_8, ST7735_GMCTRN1, // Gamma Adjustments (neg. polarity), 16 args: 93 WRITE_BYTES, 16, 94 0x0B, 0x14, 0x08, 0x1E, // (Not entirely necessary, but provides 95 0x22, 0x1D, 0x18, 0x1E, // accurate colors) 96 0x1B, 0x1A, 0x24, 0x2B, 97 0x06, 0x06, 0x02, 0x0F, 98 END_WRITE, 99 100 DELAY, 10, 101 102 BEGIN_WRITE, 103 WRITE_COMMAND_8, ST7735_NORON, // 5: Normal display on, no args, w/delay 104 END_WRITE, 105 106 DELAY, 10, 107 108 BEGIN_WRITE, 109 WRITE_COMMAND_8, ST7735_DISPON, // 6: Main screen turn on, no args, w/delay 110 END_WRITE}; 111 112 class Arduino_ST7735 : public Arduino_TFT 113 { 114 public: 115 Arduino_ST7735( 116 Arduino_DataBus *bus, int8_t rst = GFX_NOT_DEFINED, uint8_t r = 0, 117 bool ips = false, int16_t w = ST7735_TFTWIDTH, int16_t h = ST7735_TFTHEIGHT, 118 uint8_t col_offset1 = 0, uint8_t row_offset1 = 0, uint8_t col_offset2 = 0, uint8_t row_offset2 = 0, 119 bool bgr = true); 120 121 bool begin(int32_t speed = GFX_NOT_DEFINED) override; 122 void writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) override; 123 void setRotation(uint8_t r) override; 124 void invertDisplay(bool) override; 125 void displayOn() override; 126 void displayOff() override; 127 128 protected: 129 void tftInit() override; 130 bool _bgr; 131 132 private: 133 }; 134 135 #endif