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_GC9106.cpp (2559B)
1 #include "Arduino_GC9106.h" 2 #include "SPI.h" 3 4 Arduino_GC9106::Arduino_GC9106( 5 Arduino_DataBus *bus, int8_t rst, uint8_t r, 6 bool ips, int16_t w, int16_t h, 7 uint8_t col_offset1, uint8_t row_offset1, uint8_t col_offset2, uint8_t row_offset2) 8 : Arduino_TFT(bus, rst, r, ips, w, h, col_offset1, row_offset1, col_offset2, row_offset2) 9 { 10 } 11 12 bool Arduino_GC9106::begin(int32_t speed) 13 { 14 _override_datamode = SPI_MODE0; // always use SPI_MODE0 15 16 return Arduino_TFT::begin(speed); 17 } 18 19 void Arduino_GC9106::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h) 20 { 21 if ((x != _currentX) || (w != _currentW) || (y != _currentY) || (h != _currentH)) 22 { 23 _bus->writeC8D16D16(GC9106_CASET, x + _xStart, x + w - 1 + _xStart); 24 _bus->writeC8D16D16(GC9106_RASET, y + _yStart, y + h - 1 + _yStart); 25 26 _currentX = x; 27 _currentY = y; 28 _currentW = w; 29 _currentH = h; 30 } 31 32 _bus->writeCommand(GC9106_RAMWR); // write to RAM 33 } 34 35 /**************************************************************************/ 36 /*! 37 @brief Set origin of (0,0) and orientation of TFT display 38 @param m The index for rotation, from 0-3 inclusive 39 */ 40 /**************************************************************************/ 41 void Arduino_GC9106::setRotation(uint8_t r) 42 { 43 Arduino_TFT::setRotation(r); 44 switch (_rotation) 45 { 46 case 3: 47 r = GC9106_MADCTL_MY | GC9106_MADCTL_MV | GC9106_MADCTL_BGR; 48 break; 49 case 2: 50 r = GC9106_MADCTL_MY | GC9106_MADCTL_MX | GC9106_MADCTL_BGR; 51 break; 52 case 1: 53 r = GC9106_MADCTL_MX | GC9106_MADCTL_MV | GC9106_MADCTL_BGR; 54 break; 55 default: // case 0: 56 r = GC9106_MADCTL_BGR; 57 break; 58 } 59 _bus->beginWrite(); 60 _bus->writeCommand(GC9106_MADCTL); 61 _bus->write(r); 62 _bus->endWrite(); 63 } 64 65 void Arduino_GC9106::invertDisplay(bool i) 66 { 67 _bus->sendCommand(_ips ? (i ? GC9106_INVOFF : GC9106_INVON) : (i ? GC9106_INVON : GC9106_INVOFF)); 68 } 69 70 void Arduino_GC9106::displayOn(void) 71 { 72 _bus->sendCommand(GC9106_SLPOUT); 73 delay(GC9106_SLPOUT_DELAY); 74 } 75 76 void Arduino_GC9106::displayOff(void) 77 { 78 _bus->sendCommand(GC9106_SLPIN); 79 delay(GC9106_SLPIN_DELAY); 80 } 81 82 void Arduino_GC9106::tftInit() 83 { 84 if (_rst != GFX_NOT_DEFINED) 85 { 86 pinMode(_rst, OUTPUT); 87 digitalWrite(_rst, HIGH); 88 delay(100); 89 digitalWrite(_rst, LOW); 90 delay(GC9106_RST_DELAY); 91 digitalWrite(_rst, HIGH); 92 delay(GC9106_RST_DELAY); 93 } 94 else 95 { 96 // Software Rest 97 } 98 99 _bus->batchOperation(GC9106_init_operations, sizeof(GC9106_init_operations)); 100 101 if (_ips) 102 { 103 _bus->sendCommand(GC9106_INVON); 104 } 105 }