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_ILI9331.cpp (3564B)

      1 /*
      2  * start rewrite from:
      3  * https://github.com/adafruit/Adafruit-GFX-Library.git
      4  * https://github.com/adafruit/Adafruit_ILI9331.git
      5  */
      6 #include "Arduino_ILI9331.h"
      7 #include "SPI.h"
      8 
      9 Arduino_ILI9331::Arduino_ILI9331(Arduino_DataBus *bus, int8_t rst, uint8_t r, bool ips)
     10     : Arduino_TFT(bus, rst, r, ips, ILI9331_TFTWIDTH, ILI9331_TFTHEIGHT, 0, 0, 0, 0)
     11 {
     12 }
     13 
     14 bool Arduino_ILI9331::begin(int32_t speed)
     15 {
     16   return Arduino_TFT::begin(speed);
     17 }
     18 
     19 /**************************************************************************/
     20 /*!
     21     @brief   Set origin of (0,0) and orientation of TFT display
     22     @param   m  The index for rotation, from 0-3 inclusive
     23 */
     24 /**************************************************************************/
     25 void Arduino_ILI9331::setRotation(uint8_t r)
     26 {
     27   uint16_t gs, ss, org;
     28   Arduino_TFT::setRotation(r);
     29   switch (_rotation)
     30   {
     31   case 1:
     32     gs = 0x2700;
     33     ss = 0;
     34     org = 0x1038;
     35     break;
     36   case 2:
     37     gs = 0xA700;
     38     ss = 0;
     39     org = 0x1030;
     40     break;
     41   case 3:
     42     gs = 0xA700;
     43     ss = 0x100;
     44     org = 0x1038;
     45     break;
     46   default: // case 0:
     47     gs = 0x2700;
     48     ss = 0x100;
     49     org = 0x1030;
     50     break;
     51   }
     52 
     53   _MC = 0x20, _MP = 0x21, _SC = 0x50, _EC = 0x51, _SP = 0x52, _EP = 0x53;
     54 
     55   if ((_rotation & 1))
     56   {
     57     uint16_t x;
     58     x = _MC, _MC = _MP, _MP = x;
     59     x = _SC, _SC = _SP, _SP = x;
     60     x = _EC, _EC = _EP, _EP = x;
     61   }
     62 
     63   _bus->beginWrite();
     64   _bus->writeC16D16(ILI9331_GSC1, gs);        // Set the direction of scan by the gate driver
     65   _bus->writeC16D16(ILI9331_DRVOUTCTL, ss);   // Select the shift direction of outputs from the source driver
     66   _bus->writeC16D16(ILI9331_ENTRY_MODE, org); // Set GRAM write direction
     67   _bus->writeCommand16(ILI9331_MW);           // Write to GRAM
     68   _bus->endWrite();
     69 }
     70 
     71 void Arduino_ILI9331::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h)
     72 {
     73   if ((x != _currentX) || (w != _currentW))
     74   {
     75     _currentX = x;
     76     _currentW = w;
     77     x += _xStart;
     78     _bus->writeC16D16(_MC, x);
     79     _bus->writeC16D16(_SC, x);
     80     _bus->writeC16D16(_EC, x + w - 1);
     81   }
     82 
     83   if ((y != _currentY) || (h != _currentH))
     84   {
     85     _currentY = y;
     86     _currentH = h;
     87     y += _yStart;
     88     _bus->writeC16D16(_MP, y);
     89     _bus->writeC16D16(_SP, y);
     90     _bus->writeC16D16(_EP, y + h - 1);
     91   }
     92 
     93   _bus->writeCommand16(ILI9331_MW);
     94 }
     95 
     96 void Arduino_ILI9331::invertDisplay(bool i)
     97 {
     98   _bus->beginWrite();
     99   _bus->writeC16D16(ILI9331_GSC2, _ips != i);
    100   _bus->endWrite();
    101 }
    102 
    103 void Arduino_ILI9331::displayOn(void)
    104 {
    105   _bus->beginWrite();
    106   _bus->writeC16D16(ILI9331_PWCTL1, 0x1690);   // Standby mode OFF
    107   _bus->writeC16D16(ILI9331_WBRICTRL, 0x0024); // Enable backlight
    108   _bus->writeC16D16(ILI9331_WBRI, 0x00FF);     // Set maximum brightness
    109   _bus->endWrite();
    110   delay(100);
    111 }
    112 
    113 void Arduino_ILI9331::displayOff(void)
    114 {
    115   _bus->beginWrite();
    116   _bus->writeC16D16(ILI9331_PWCTL1, 0x1691);   // Standby mode OFF
    117   _bus->writeC16D16(ILI9331_WBRICTRL, 0x0020); // Disable backlight
    118   _bus->endWrite();
    119 }
    120 
    121 // Companion code to the above tables.  Reads and issues
    122 // a series of LCD commands stored in PROGMEM byte array.
    123 void Arduino_ILI9331::tftInit()
    124 {
    125   if (_rst != GFX_NOT_DEFINED)
    126   {
    127     pinMode(_rst, OUTPUT);
    128     digitalWrite(_rst, HIGH);
    129     delay(100);
    130     digitalWrite(_rst, LOW);
    131     delay(ILI9331_RST_DELAY);
    132     digitalWrite(_rst, HIGH);
    133     delay(ILI9331_RST_DELAY);
    134   }
    135 
    136   _bus->batchOperation(ili9331_init_operations, sizeof(ili9331_init_operations));
    137   if (_ips)
    138   {
    139     _bus->beginWrite();
    140     _bus->writeC16D16(ILI9331_GSC2, _ips); // Invert display
    141     _bus->endWrite();
    142   }
    143 }