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_SSD1351.cpp (3649B)
1 /* 2 * start rewrite from: 3 * https://github.com/adafruit/Adafruit-GFX-Library.git 4 * https://github.com/adafruit/Adafruit-SSD1351-library.git 5 */ 6 #include "Arduino_SSD1351.h" 7 #include "SPI.h" 8 9 Arduino_SSD1351::Arduino_SSD1351( 10 Arduino_DataBus *bus, int8_t rst, uint8_t r, int16_t w, int16_t h, 11 uint8_t col_offset1, uint8_t row_offset1, uint8_t col_offset2, uint8_t row_offset2) 12 : Arduino_TFT(bus, rst, r, false, w, h, col_offset1, row_offset1, col_offset2, row_offset2) 13 { 14 } 15 16 bool Arduino_SSD1351::begin(int32_t speed) 17 { 18 #if defined(ESP8266) || defined(ESP32) 19 if (speed == GFX_NOT_DEFINED) 20 { 21 speed = 16000000UL; 22 } 23 // Teensy 4.x 24 #elif defined(__IMXRT1052__) || defined(__IMXRT1062__) 25 if (speed == GFX_NOT_DEFINED) 26 { 27 speed = 16000000UL; 28 } 29 #endif 30 _override_datamode = SPI_MODE0; // always SPI_MODE0 31 32 return Arduino_TFT::begin(speed); 33 } 34 35 // Companion code to the above tables. Reads and issues 36 // a series of LCD commands stored in PROGMEM byte array. 37 void Arduino_SSD1351::tftInit() 38 { 39 if (_rst != GFX_NOT_DEFINED) 40 { 41 pinMode(_rst, OUTPUT); 42 digitalWrite(_rst, HIGH); 43 delay(100); 44 digitalWrite(_rst, LOW); 45 delay(SSD1351_RST_DELAY); 46 digitalWrite(_rst, HIGH); 47 delay(SSD1351_RST_DELAY); 48 } 49 else 50 { 51 // Software Rest 52 } 53 54 _bus->sendCommand(SSD1351_COMMANDLOCK); // set command lock 55 _bus->sendData(0x12); 56 _bus->sendCommand(SSD1351_COMMANDLOCK); // set command lock 57 _bus->sendData(0xB1); 58 _bus->sendCommand(SSD1351_DISPLAYOFF); // Display off 59 _bus->sendCommand(SSD1351_DISPLAYOFFSET); // 0xA2 60 _bus->sendData(0x0); 61 _bus->sendCommand(SSD1351_NORMALDISPLAY); // 0xA6 62 _bus->sendCommand(SSD1351_DISPLAYON); // Main screen turn on 63 } 64 65 void Arduino_SSD1351::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) 66 { 67 uint8_t cmd; 68 if ((x != _currentX) || (w != _currentW)) 69 { 70 cmd = (_rotation & 0x01) ? SSD1351_SETROW : SSD1351_SETCOLUMN; 71 uint8_t x_start = x + _xStart, x_end = x + w - 1 + _xStart; 72 73 _bus->writeCommand(cmd); // Column addr set 74 _bus->write(x_start); // XSTART 75 _bus->write(x_end); // XEND 76 77 _currentX = x; 78 _currentW = w; 79 } 80 if ((y != _currentY) || (h != _currentH)) 81 { 82 cmd = (_rotation & 0x01) ? SSD1351_SETCOLUMN : SSD1351_SETROW; 83 uint8_t y_start = y + _yStart, y_end = y + h - 1 + _yStart; 84 85 _bus->writeCommand(cmd); // Row addr set 86 _bus->write(y_start); // YSTART 87 _bus->write(y_end); // YEND 88 89 _currentY = y; 90 _currentH = h; 91 } 92 93 _bus->writeCommand(SSD1351_WRITERAM); // write to RAM 94 } 95 96 /**************************************************************************/ 97 /*! 98 @brief Set origin of (0,0) and orientation of TFT display 99 @param m The index for rotation, from 0-3 inclusive 100 */ 101 /**************************************************************************/ 102 void Arduino_SSD1351::setRotation(uint8_t r) 103 { 104 Arduino_TFT::setRotation(r); 105 uint8_t startline = (_rotation < 2) ? HEIGHT : 0; 106 switch (_rotation) 107 { 108 case 1: 109 r = 0b01110111; 110 break; 111 case 2: 112 r = 0b01100110; 113 break; 114 case 3: 115 r = 0b01100101; 116 break; 117 default: // case 0: 118 r = 0b01110100; 119 break; 120 } 121 _bus->beginWrite(); 122 _bus->writeCommand(SSD1351_SETREMAP); 123 _bus->write(r); 124 _bus->writeCommand(SSD1351_STARTLINE); 125 _bus->write(startline); 126 _bus->endWrite(); 127 } 128 129 void Arduino_SSD1351::invertDisplay(bool i) 130 { 131 _bus->sendCommand(i ? SSD1351_INVERTDISPLAY : SSD1351_NORMALDISPLAY); 132 } 133 134 void Arduino_SSD1351::displayOn(void) 135 { 136 _bus->sendCommand(SSD1351_DISPLAYALLON); 137 } 138 139 void Arduino_SSD1351::displayOff(void) 140 { 141 _bus->sendCommand(SSD1351_DISPLAYALLOFF); 142 }