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_SEPS525.cpp (5344B)
1 /* 2 * start rewrite from: 3 * https://github.com/adafruit/Adafruit-GFX-Library.git 4 */ 5 #include "Arduino_SEPS525.h" 6 #include "SPI.h" 7 8 Arduino_SEPS525::Arduino_SEPS525( 9 Arduino_DataBus *bus, int8_t rst, uint8_t r, int16_t w, int16_t h, 10 uint8_t col_offset1, uint8_t row_offset1, uint8_t col_offset2, uint8_t row_offset2) 11 : Arduino_TFT(bus, rst, r, false, w, h, col_offset1, row_offset1, col_offset2, row_offset2) 12 { 13 } 14 15 bool Arduino_SEPS525::begin(int32_t speed) 16 { 17 return Arduino_TFT::begin(speed); 18 } 19 20 // Companion code to the above tables. Reads and issues 21 // a series of LCD commands stored in PROGMEM byte array. 22 void Arduino_SEPS525::tftInit() 23 { 24 if (_rst != GFX_NOT_DEFINED) 25 { 26 pinMode(_rst, OUTPUT); 27 digitalWrite(_rst, HIGH); 28 delay(100); 29 digitalWrite(_rst, LOW); 30 delay(SEPS525_RST_DELAY); 31 digitalWrite(_rst, HIGH); 32 delay(SEPS525_RST_DELAY); 33 } 34 else 35 { 36 // Software Rest 37 _bus->sendCommand(SEPS525_SOFT_RST); 38 _bus->sendData(0x01); 39 delay(SEPS525_RST_DELAY); 40 } 41 42 _bus->sendCommand(SEPS525_REDUCE_CURRENT); 43 _bus->sendData(0x01); 44 delay(1); 45 46 // normal mode 47 _bus->sendCommand(SEPS525_REDUCE_CURRENT); 48 _bus->sendData(0x00); 49 delay(1); 50 51 // display off 52 _bus->sendCommand(SEPS525_DISP_ON_OFF); 53 _bus->sendData(0x00); 54 55 // turn on internal oscillator using external resistor 56 _bus->sendCommand(SEPS525_OSC_CTL); 57 _bus->sendData(0x01); 58 59 // 90 hz frame rate, divider 0 60 _bus->sendCommand(SEPS525_CLOCK_DIV); 61 _bus->sendData(0x30); 62 63 // duty cycle 127 64 _bus->sendCommand(0x28); 65 _bus->sendData(0x7f); 66 67 // start on line 0 68 _bus->sendCommand(0x29); 69 _bus->sendData(0x00); 70 71 // rgb_if 72 _bus->sendCommand(SEPS525_RGB_IF); 73 _bus->sendData(0x31); 74 75 // driving current r g b (uA) 76 _bus->sendCommand(SEPS525_DRIVING_CURRENT_R); 77 _bus->sendData(0x45); 78 _bus->sendCommand(SEPS525_DRIVING_CURRENT_G); 79 _bus->sendData(0x34); 80 _bus->sendCommand(SEPS525_DRIVING_CURRENT_B); 81 _bus->sendData(0x33); 82 83 // precharge time r g b 84 _bus->sendCommand(SEPS525_PRECHARGE_TIME_R); 85 _bus->sendData(0x04); 86 _bus->sendCommand(SEPS525_PRECHARGE_TIME_G); 87 _bus->sendData(0x05); 88 _bus->sendCommand(SEPS525_PRECHARGE_TIME_B); 89 _bus->sendData(0x05); 90 91 // precharge current r g b (uA) 92 _bus->sendCommand(SEPS525_PRECHARGE_CURRENT_R); 93 _bus->sendData(0x9d); 94 _bus->sendCommand(SEPS525_PRECHARGE_CURRENT_G); 95 _bus->sendData(0x8c); 96 _bus->sendCommand(SEPS525_PRECHARGE_CURRENT_B); 97 _bus->sendData(0x57); 98 99 _bus->sendCommand(SEPS525_IREF); 100 _bus->sendData(0x00); 101 102 // display on 103 _bus->sendCommand(SEPS525_DISP_ON_OFF); 104 _bus->sendData(0x01); 105 } 106 107 void Arduino_SEPS525::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) 108 { 109 uint8_t cmd1, cmd2, cmd3; 110 if ((x != _currentX) || (w != _currentW)) 111 { 112 int16_t x_start = x + _xStart, x_end = x + w - 1 + _xStart; 113 if (_rotation & 0x01) // Portrait 114 { 115 cmd1 = SEPS525_MY1_ADDR; 116 cmd2 = SEPS525_M_AP_Y; 117 cmd3 = SEPS525_MY2_ADDR; 118 } 119 else 120 { 121 cmd1 = SEPS525_MX1_ADDR; 122 cmd2 = SEPS525_M_AP_X; 123 cmd3 = SEPS525_MX2_ADDR; 124 } 125 _bus->writeCommand(cmd1); 126 _bus->write16(x_start); 127 _bus->writeCommand(cmd2); 128 _bus->write16(x_start); 129 _bus->writeCommand(cmd3); 130 _bus->write16(x_end); 131 132 _currentX = x; 133 _currentW = w; 134 } 135 if ((y != _currentY) || (h != _currentH)) 136 { 137 int16_t y_start = y + _yStart, y_end = y + h - 1 + _yStart; 138 if (_rotation & 0x01) // Portrait 139 { 140 cmd1 = SEPS525_MX1_ADDR; 141 cmd2 = SEPS525_M_AP_X; 142 cmd3 = SEPS525_MX2_ADDR; 143 } 144 else 145 { 146 cmd1 = SEPS525_MY1_ADDR; 147 cmd2 = SEPS525_M_AP_Y; 148 cmd3 = SEPS525_MY2_ADDR; 149 } 150 _bus->writeCommand(cmd1); 151 _bus->write16(y_start); 152 _bus->writeCommand(cmd2); 153 _bus->write16(y_start); 154 _bus->writeCommand(cmd3); 155 _bus->write16(y_end); 156 157 _currentY = y; 158 _currentH = h; 159 } 160 161 _bus->writeCommand(SEPS525_RAMWR); // write to RAM 162 } 163 164 /**************************************************************************/ 165 /*! 166 @brief Set origin of (0,0) and orientation of TFT display 167 @param m The index for rotation, from 0-3 inclusive 168 */ 169 /**************************************************************************/ 170 void Arduino_SEPS525::setRotation(uint8_t r) 171 { 172 Arduino_TFT::setRotation(r); 173 switch (_rotation) 174 { 175 case 1: 176 _bus->sendCommand(SEPS525_DISPLAY_MODE_SET); 177 _bus->sendData(0x10); 178 _bus->sendCommand(SEPS525_MEMORY_WRITE_MODE); 179 _bus->sendData(0x67); 180 break; 181 case 2: 182 _bus->sendCommand(SEPS525_DISPLAY_MODE_SET); 183 _bus->sendData(0x30); 184 _bus->sendCommand(SEPS525_MEMORY_WRITE_MODE); 185 _bus->sendData(0x66); 186 break; 187 case 3: 188 _bus->sendCommand(SEPS525_DISPLAY_MODE_SET); 189 _bus->sendData(0x20); 190 _bus->sendCommand(SEPS525_MEMORY_WRITE_MODE); 191 _bus->sendData(0x67); 192 break; 193 default: // case 0: 194 _bus->sendCommand(SEPS525_DISPLAY_MODE_SET); 195 _bus->sendData(0x00); 196 _bus->sendCommand(SEPS525_MEMORY_WRITE_MODE); 197 _bus->sendData(0x66); 198 break; 199 } 200 } 201 202 void Arduino_SEPS525::invertDisplay(bool i) 203 { 204 // Not Implemented 205 UNUSED(i); 206 } 207 208 void Arduino_SEPS525::displayOn(void) 209 { 210 _bus->sendCommand(SEPS525_DISP_ON_OFF); 211 _bus->sendData(0x01); 212 } 213 214 void Arduino_SEPS525::displayOff(void) 215 { 216 _bus->sendCommand(SEPS525_DISP_ON_OFF); 217 _bus->sendData(0x00); 218 }