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_GC9A01.cpp (2393B)

      1 #include "Arduino_GC9A01.h"
      2 #include "SPI.h"
      3 
      4 Arduino_GC9A01::Arduino_GC9A01(
      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_GC9A01::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_GC9A01::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(GC9A01_CASET, x + _xStart, x + w - 1 + _xStart);
     24     _bus->writeC8D16D16(GC9A01_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(GC9A01_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_GC9A01::setRotation(uint8_t r)
     42 {
     43   Arduino_TFT::setRotation(r);
     44   switch (_rotation)
     45   {
     46   case 3:
     47     r = 0xA8;
     48     break;
     49   case 2:
     50     r = 0xC8;
     51     break;
     52   case 1:
     53     r = 0x68;
     54     break;
     55   default: // case 0:
     56     r = 0x08;
     57     break;
     58   }
     59   _bus->beginWrite();
     60   _bus->writeCommand(GC9A01_MADCTL);
     61   _bus->write(r);
     62   _bus->endWrite();
     63 }
     64 
     65 void Arduino_GC9A01::invertDisplay(bool i)
     66 {
     67   _bus->sendCommand(_ips ? (i ? GC9A01_INVOFF : GC9A01_INVON) : (i ? GC9A01_INVON : GC9A01_INVOFF));
     68 }
     69 
     70 void Arduino_GC9A01::displayOn(void)
     71 {
     72   _bus->sendCommand(GC9A01_SLPOUT);
     73   delay(GC9A01_SLPOUT_DELAY);
     74 }
     75 
     76 void Arduino_GC9A01::displayOff(void)
     77 {
     78   _bus->sendCommand(GC9A01_SLPIN);
     79   delay(GC9A01_SLPIN_DELAY);
     80 }
     81 
     82 void Arduino_GC9A01::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(GC9A01_RST_DELAY);
     91     digitalWrite(_rst, HIGH);
     92     delay(GC9A01_RST_DELAY);
     93   }
     94   else
     95   {
     96     // Software Rest
     97   }
     98 
     99   _bus->batchOperation(gc9a01_init_operations, sizeof(gc9a01_init_operations));
    100 
    101   if (_ips)
    102   {
    103     _bus->sendCommand(GC9A01_INVON);
    104   }
    105 }