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_ILI9481_18bit.cpp (5803B)

      1 /*
      2  * start rewrite from:
      3  * https://github.com/adafruit/Adafruit-GFX-Library.git
      4  */
      5 #include "Arduino_ILI9481_18bit.h"
      6 
      7 Arduino_ILI9481_18bit::Arduino_ILI9481_18bit(Arduino_DataBus *bus, int8_t rst, uint8_t r, bool ips)
      8     : Arduino_TFT_18bit(bus, rst, r, ips, ILI9481_TFTWIDTH, ILI9481_TFTHEIGHT, 0, 0, 0, 0)
      9 {
     10 }
     11 
     12 bool Arduino_ILI9481_18bit::begin(int32_t speed)
     13 {
     14 #if defined(ESP8266) || defined(ESP32)
     15   if (speed == GFX_NOT_DEFINED)
     16   {
     17     speed = 12000000UL;
     18   }
     19 // Teensy 4.x
     20 #elif defined(__IMXRT1052__) || defined(__IMXRT1062__)
     21   if (speed == GFX_NOT_DEFINED)
     22   {
     23     speed = 12000000UL;
     24   }
     25 #endif
     26 
     27   return Arduino_TFT::begin(speed);
     28 }
     29 
     30 // Companion code to the above tables.  Reads and issues
     31 // a series of LCD commands stored in PROGMEM byte array.
     32 void Arduino_ILI9481_18bit::tftInit()
     33 {
     34   if (_rst != GFX_NOT_DEFINED)
     35   {
     36     pinMode(_rst, OUTPUT);
     37     digitalWrite(_rst, HIGH);
     38     delay(100);
     39     digitalWrite(_rst, LOW);
     40     delay(ILI9481_RST_DELAY);
     41     digitalWrite(_rst, HIGH);
     42     delay(ILI9481_RST_DELAY);
     43   }
     44   else
     45   {
     46     // Software Rest
     47     _bus->sendCommand(ILI9481_SWRESET);
     48     delay(ILI9481_RST_DELAY);
     49   }
     50 
     51   _bus->sendCommand(ILI9481_SLPOUT);
     52   delay(280);
     53 
     54   _bus->sendCommand(0xd0); // Power_Setting
     55   _bus->sendData(0x07);    // 07  VC[2:0] Sets the ratio factor of Vci to generate the reference voltages Vci1
     56   _bus->sendData(0x44);    // 41  BT[2:0] Sets the Step up factor and output voltage level from the reference voltages Vci1
     57   _bus->sendData(0x1E);    // 1f  17   1C  VRH[3:0]: Sets the factor to generate VREG1OUT from VCILVL
     58   delay(220);
     59 
     60   _bus->sendCommand(0xd1); // VCOM Control
     61   _bus->sendData(0x00);    // 00
     62   _bus->sendData(0x0C);    // 1A   VCM [6:0] is used to set factor to generate VCOMH voltage from the reference voltage VREG1OUT  15    09
     63   _bus->sendData(0x1A);    // 1F   VDV[4:0] is used to set the VCOM alternating amplitude in the range of VREG1OUT x 0.70 to VREG1OUT   1F   18
     64 
     65   _bus->sendCommand(0xC5); // Frame Rate
     66   _bus->sendData(0x03);    // 03   02
     67 
     68   _bus->sendCommand(0xd2); // Power_Setting for Normal Mode
     69   _bus->sendData(0x01);    // 01
     70   _bus->sendData(0x11);    // 11
     71 
     72   _bus->sendCommand(0xE4); //
     73   _bus->sendData(0xa0);
     74   _bus->sendCommand(0xf3);
     75   _bus->sendData(0x00);
     76   _bus->sendData(0x2a);
     77 
     78   // 1  OK
     79   _bus->sendCommand(0xc8);
     80   _bus->sendData(0x00);
     81   _bus->sendData(0x26);
     82   _bus->sendData(0x21);
     83   _bus->sendData(0x00);
     84   _bus->sendData(0x00);
     85   _bus->sendData(0x1f);
     86   _bus->sendData(0x65);
     87   _bus->sendData(0x23);
     88   _bus->sendData(0x77);
     89   _bus->sendData(0x00);
     90   _bus->sendData(0x0f);
     91   _bus->sendData(0x00);
     92   // GAMMA SETTING
     93 
     94   _bus->sendCommand(0xC0); // Panel Driving Setting
     95   _bus->sendData(0x00);    // 1//00  REV  SM  GS
     96   _bus->sendData(0x3B);    // 2//NL[5:0]: Sets the number of lines to drive the LCD at an interval of 8 lines.
     97   _bus->sendData(0x00);    // 3//SCN[6:0]
     98   _bus->sendData(0x02);    // 4//PTV: Sets the Vcom output in non-display area drive period
     99   _bus->sendData(0x11);    // 5//NDL: Sets the source output level in non-display area.  PTG: Sets the scan mode in non-display area.
    100 
    101   _bus->sendCommand(0xc6); // Interface Control
    102   _bus->sendData(0x83);
    103   // GAMMA SETTING
    104 
    105   _bus->sendCommand(0xf0); //?
    106   _bus->sendData(0x01);
    107 
    108   _bus->sendCommand(0xE4); //?
    109   _bus->sendData(0xa0);
    110 
    111   _bus->sendCommand(ILI9481_PIXFMT);
    112   _bus->sendData(0x66);
    113 
    114   _bus->sendCommand(0xb4); // Display Mode and Frame Memory Write Mode Setting
    115   _bus->sendData(0x02);
    116   _bus->sendData(0x00); //
    117   _bus->sendData(0x00);
    118   _bus->sendData(0x01);
    119 
    120   delay(280);
    121 
    122   if (_ips)
    123   {
    124     _bus->sendCommand(ILI9481_INVON);
    125   }
    126   else
    127   {
    128     _bus->sendCommand(ILI9481_INVOFF);
    129   }
    130   _bus->sendCommand(0x29);
    131 }
    132 
    133 void Arduino_ILI9481_18bit::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h)
    134 {
    135   if ((x != _currentX) || (w != _currentW))
    136   {
    137     int16_t x_start = x + _xStart, x_end = x + w - 1 + _xStart;
    138 
    139     _bus->writeCommand(ILI9481_CASET); // Column addr set
    140     _bus->write(x_start >> 8);
    141     _bus->write(x_start & 0xFF); // XSTART
    142     _bus->write(x_end >> 8);
    143     _bus->write(x_end & 0xFF); // XEND
    144 
    145     _currentX = x;
    146     _currentW = w;
    147   }
    148   if ((y != _currentY) || (h != _currentH))
    149   {
    150     int16_t y_start = y + _yStart, y_end = y + h - 1 + _yStart;
    151 
    152     _bus->writeCommand(ILI9481_PASET); // Row addr set
    153     _bus->write(y_start >> 8);
    154     _bus->write(y_start & 0xFF); // YSTART
    155     _bus->write(y_end >> 8);
    156     _bus->write(y_end & 0xFF); // YEND
    157 
    158     _currentY = y;
    159     _currentH = h;
    160   }
    161 
    162   _bus->writeCommand(ILI9481_RAMWR); // write to RAM
    163 }
    164 
    165 /**************************************************************************/
    166 /*!
    167     @brief   Set origin of (0,0) and orientation of TFT display
    168     @param   m  The index for rotation, from 0-3 inclusive
    169 */
    170 /**************************************************************************/
    171 void Arduino_ILI9481_18bit::setRotation(uint8_t r)
    172 {
    173   Arduino_TFT::setRotation(r);
    174   switch (_rotation)
    175   {
    176   case 1:
    177     r = (ILI9481_MADCTL_MV | ILI9481_MADCTL_BGR | ILI9481_MADCTL_HF | ILI9481_MADCTL_VF);
    178     break;
    179   case 2:
    180     r = (ILI9481_MADCTL_BGR | ILI9481_MADCTL_HF);
    181     break;
    182   case 3:
    183     r = (ILI9481_MADCTL_MV | ILI9481_MADCTL_BGR);
    184     break;
    185   default: // case 0:
    186     r = (ILI9481_MADCTL_BGR | ILI9481_MADCTL_VF);
    187     break;
    188   }
    189   _bus->beginWrite();
    190   _bus->writeCommand(ILI9481_MADCTL);
    191   _bus->write(r);
    192   _bus->endWrite();
    193 }
    194 
    195 void Arduino_ILI9481_18bit::invertDisplay(bool i)
    196 {
    197   _bus->sendCommand(_ips ? (i ? ILI9481_INVOFF : ILI9481_INVON) : (i ? ILI9481_INVON : ILI9481_INVOFF));
    198 }
    199 
    200 void Arduino_ILI9481_18bit::displayOn(void)
    201 {
    202   _bus->sendCommand(ILI9481_SLPOUT);
    203   delay(ILI9481_SLPOUT_DELAY);
    204 }
    205 
    206 void Arduino_ILI9481_18bit::displayOff(void)
    207 {
    208   _bus->sendCommand(ILI9481_SLPIN);
    209   delay(ILI9481_SLPIN_DELAY);
    210 }