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_HX8352C.cpp (10850B)

      1 /*
      2  * start rewrite from:
      3  * https://github.com/adafruit/Adafruit-GFX-Library.git
      4  */
      5 #include "Arduino_HX8352C.h"
      6 
      7 Arduino_HX8352C::Arduino_HX8352C(
      8     Arduino_DataBus *bus, int8_t rst, uint8_t r,
      9     bool ips, int16_t w, int16_t h,
     10     uint8_t col_offset1, uint8_t row_offset1, uint8_t col_offset2, uint8_t row_offset2)
     11     : Arduino_TFT(bus, rst, r, ips, w, h, col_offset1, row_offset1, col_offset2, row_offset2)
     12 {
     13   _invert = ips;
     14 }
     15 
     16 bool Arduino_HX8352C::begin(int32_t speed)
     17 {
     18   return Arduino_TFT::begin(speed);
     19 }
     20 
     21 // Companion code to the above tables.  Reads and issues
     22 // a series of LCD commands stored in PROGMEM byte array.
     23 void Arduino_HX8352C::tftInit()
     24 {
     25   if (_rst != GFX_NOT_DEFINED)
     26   {
     27     pinMode(_rst, OUTPUT);
     28     digitalWrite(_rst, HIGH);
     29     delay(100);
     30     digitalWrite(_rst, LOW);
     31     delay(HX8352C_RST_DELAY);
     32     digitalWrite(_rst, HIGH);
     33     delay(HX8352C_RST_DELAY);
     34   }
     35   else
     36   {
     37     // Software Rest
     38   }
     39 
     40   // LCD Init For 3.0inch LCD Panel with HX8352C.
     41   // Power Voltage Setting
     42   _bus->sendCommand(0x1A);
     43   _bus->sendData(0x02); // BT
     44   _bus->sendCommand(0x1B);
     45   _bus->sendData(0x8B); // VRH
     46   //****VCOM offset**///
     47   _bus->sendCommand(0x23);
     48   _bus->sendData(0x00); // SEL_VCM
     49   _bus->sendCommand(0x24);
     50   _bus->sendData(0x5D); // VCM
     51   _bus->sendCommand(0x25);
     52   _bus->sendData(0x15); // VDV
     53   _bus->sendCommand(0x2D);
     54   _bus->sendData(0x01); // NOW[2:0]=001
     55   //****OPON**//
     56   _bus->sendCommand(0xE8);
     57   _bus->sendData(0x60);
     58   // Power on Setting
     59   _bus->sendCommand(0x18);
     60   _bus->sendData(0x04); // Frame rate 72Hz
     61   _bus->sendCommand(0x19);
     62   _bus->sendData(0x01); // OSC_EN='1', start Osc
     63   _bus->sendCommand(0x01);
     64   _bus->sendData(0x00); // DP_STB='0', out deep sleep
     65   _bus->sendCommand(0x1F);
     66   _bus->sendData(0x88); // STB=0
     67   delay(5);
     68   _bus->sendCommand(0x1F);
     69   _bus->sendData(0x80); // DK=0
     70   delay(5);
     71   _bus->sendCommand(0x1F);
     72   _bus->sendData(0x90); // PON=1
     73   delay(5);
     74   _bus->sendCommand(0x1F);
     75   _bus->sendData(0xD0); // VCOMG=1
     76   delay(5);
     77 
     78   // 262k/65k color selection
     79   _bus->sendCommand(0x17);
     80   _bus->sendData(0x05); // default 0x06 262k color // 0x05 65k color
     81   // SET PANEL
     82   _bus->sendCommand(0x29);
     83   _bus->sendData(0x31); // 400 lines
     84   _bus->sendCommand(0x71);
     85   _bus->sendData(0x1A); // RTN
     86   // Gamma 2.2 Setting
     87   _bus->sendCommand(0x40);
     88   _bus->sendData(0x00);
     89   _bus->sendCommand(0x41);
     90   _bus->sendData(0x77);
     91   _bus->sendCommand(0x42);
     92   _bus->sendData(0x77);
     93   _bus->sendCommand(0x43);
     94   _bus->sendData(0x00);
     95   _bus->sendCommand(0x44);
     96   _bus->sendData(0x04);
     97   _bus->sendCommand(0x45);
     98   _bus->sendData(0x00);
     99   _bus->sendCommand(0x46);
    100   _bus->sendData(0x00);
    101   _bus->sendCommand(0x47);
    102   _bus->sendData(0x00);
    103   _bus->sendCommand(0x48);
    104   _bus->sendData(0x77);
    105   _bus->sendCommand(0x49);
    106   _bus->sendData(0x00);
    107   _bus->sendCommand(0x4A);
    108   _bus->sendData(0x00);
    109   _bus->sendCommand(0x4B);
    110   _bus->sendData(0x08);
    111   _bus->sendCommand(0x4C);
    112   _bus->sendData(0x00);
    113   _bus->sendCommand(0x4D);
    114   _bus->sendData(0x00);
    115   _bus->sendCommand(0x4E);
    116   _bus->sendData(0x00);
    117   // Set DGC
    118   _bus->sendCommand(0xFF);
    119   _bus->sendData(0x01); // Page1
    120   _bus->sendCommand(0x00);
    121   _bus->sendData(0x01); // DGC_EN
    122   _bus->sendCommand(0x01);
    123   _bus->sendData(0x00);
    124   _bus->sendCommand(0x02);
    125   _bus->sendData(0x06);
    126   _bus->sendCommand(0x03);
    127   _bus->sendData(0x0C);
    128   _bus->sendCommand(0x04);
    129   _bus->sendData(0x12);
    130   _bus->sendCommand(0x05);
    131   _bus->sendData(0x16);
    132   _bus->sendCommand(0x06);
    133   _bus->sendData(0x1C);
    134   _bus->sendCommand(0x07);
    135   _bus->sendData(0x23);
    136   _bus->sendCommand(0x08);
    137   _bus->sendData(0x2E);
    138   _bus->sendCommand(0x09);
    139   _bus->sendData(0x36);
    140   _bus->sendCommand(0x0A);
    141   _bus->sendData(0x3F);
    142   _bus->sendCommand(0x0B);
    143   _bus->sendData(0x47);
    144   _bus->sendCommand(0x0C);
    145   _bus->sendData(0x50);
    146   _bus->sendCommand(0x0D);
    147   _bus->sendData(0x57);
    148   _bus->sendCommand(0x0E);
    149   _bus->sendData(0x5F);
    150   _bus->sendCommand(0x0F);
    151   _bus->sendData(0x67);
    152   _bus->sendCommand(0x10);
    153   _bus->sendData(0x6F);
    154   _bus->sendCommand(0x11);
    155   _bus->sendData(0x76);
    156   _bus->sendCommand(0x12);
    157   _bus->sendData(0x7F);
    158   _bus->sendCommand(0x13);
    159   _bus->sendData(0x87);
    160   _bus->sendCommand(0x14);
    161   _bus->sendData(0x90);
    162   _bus->sendCommand(0x15);
    163   _bus->sendData(0x99);
    164   _bus->sendCommand(0x16);
    165   _bus->sendData(0xA3);
    166   _bus->sendCommand(0x17);
    167   _bus->sendData(0xAD);
    168   _bus->sendCommand(0x18);
    169   _bus->sendData(0xB4);
    170   _bus->sendCommand(0x19);
    171   _bus->sendData(0xBB);
    172   _bus->sendCommand(0x1A);
    173   _bus->sendData(0xC4);
    174   _bus->sendCommand(0x1B);
    175   _bus->sendData(0xCE);
    176   _bus->sendCommand(0x1C);
    177   _bus->sendData(0xD9);
    178   _bus->sendCommand(0x1D);
    179   _bus->sendData(0xE3);
    180   _bus->sendCommand(0x1E);
    181   _bus->sendData(0xEC);
    182   _bus->sendCommand(0x1F);
    183   _bus->sendData(0xF3);
    184   _bus->sendCommand(0x20);
    185   _bus->sendData(0xF7);
    186   _bus->sendCommand(0x21);
    187   _bus->sendData(0xFC);
    188   _bus->sendCommand(0x22);
    189   _bus->sendData(0x00);
    190   _bus->sendCommand(0x23);
    191   _bus->sendData(0x06);
    192   _bus->sendCommand(0x24);
    193   _bus->sendData(0x0C);
    194   _bus->sendCommand(0x25);
    195   _bus->sendData(0x12);
    196   _bus->sendCommand(0x26);
    197   _bus->sendData(0x16);
    198   _bus->sendCommand(0x27);
    199   _bus->sendData(0x1C);
    200   _bus->sendCommand(0x28);
    201   _bus->sendData(0x23);
    202   _bus->sendCommand(0x29);
    203   _bus->sendData(0x2E);
    204   _bus->sendCommand(0x2A);
    205   _bus->sendData(0x36);
    206   _bus->sendCommand(0x2B);
    207   _bus->sendData(0x3F);
    208   _bus->sendCommand(0x2C);
    209   _bus->sendData(0x47);
    210   _bus->sendCommand(0x2D);
    211   _bus->sendData(0x50);
    212   _bus->sendCommand(0x2E);
    213   _bus->sendData(0x57);
    214   _bus->sendCommand(0x2F);
    215   _bus->sendData(0x5F);
    216   _bus->sendCommand(0x30);
    217   _bus->sendData(0x67);
    218   _bus->sendCommand(0x31);
    219   _bus->sendData(0x6F);
    220   _bus->sendCommand(0x32);
    221   _bus->sendData(0x76);
    222   _bus->sendCommand(0x33);
    223   _bus->sendData(0x7F);
    224   _bus->sendCommand(0x34);
    225   _bus->sendData(0x87);
    226   _bus->sendCommand(0x35);
    227   _bus->sendData(0x90);
    228   _bus->sendCommand(0x36);
    229   _bus->sendData(0x99);
    230   _bus->sendCommand(0x37);
    231   _bus->sendData(0xA3);
    232   _bus->sendCommand(0x38);
    233   _bus->sendData(0xAD);
    234   _bus->sendCommand(0x39);
    235   _bus->sendData(0xB4);
    236   _bus->sendCommand(0x3A);
    237   _bus->sendData(0xBB);
    238   _bus->sendCommand(0x3B);
    239   _bus->sendData(0xC4);
    240   _bus->sendCommand(0x3C);
    241   _bus->sendData(0xCE);
    242   _bus->sendCommand(0x3D);
    243   _bus->sendData(0xD9);
    244   _bus->sendCommand(0x3E);
    245   _bus->sendData(0xE3);
    246   _bus->sendCommand(0x3F);
    247   _bus->sendData(0xEC);
    248   _bus->sendCommand(0x40);
    249   _bus->sendData(0xF3);
    250   _bus->sendCommand(0x41);
    251   _bus->sendData(0xF7);
    252   _bus->sendCommand(0x42);
    253   _bus->sendData(0xFC);
    254   _bus->sendCommand(0x43);
    255   _bus->sendData(0x00);
    256   _bus->sendCommand(0x44);
    257   _bus->sendData(0x06);
    258   _bus->sendCommand(0x45);
    259   _bus->sendData(0x0C);
    260   _bus->sendCommand(0x46);
    261   _bus->sendData(0x12);
    262   _bus->sendCommand(0x47);
    263   _bus->sendData(0x16);
    264   _bus->sendCommand(0x48);
    265   _bus->sendData(0x1C);
    266   _bus->sendCommand(0x49);
    267   _bus->sendData(0x23);
    268   _bus->sendCommand(0x4A);
    269   _bus->sendData(0x2E);
    270   _bus->sendCommand(0x4B);
    271   _bus->sendData(0x36);
    272   _bus->sendCommand(0x4C);
    273   _bus->sendData(0x3F);
    274   _bus->sendCommand(0x4D);
    275   _bus->sendData(0x47);
    276   _bus->sendCommand(0x4E);
    277   _bus->sendData(0x50);
    278   _bus->sendCommand(0x4F);
    279   _bus->sendData(0x57);
    280   _bus->sendCommand(0x50);
    281   _bus->sendData(0x5F);
    282   _bus->sendCommand(0x51);
    283   _bus->sendData(0x67);
    284   _bus->sendCommand(0x52);
    285   _bus->sendData(0x6F);
    286   _bus->sendCommand(0x53);
    287   _bus->sendData(0x76);
    288   _bus->sendCommand(0x54);
    289   _bus->sendData(0x7F);
    290   _bus->sendCommand(0x55);
    291   _bus->sendData(0x87);
    292   _bus->sendCommand(0x56);
    293   _bus->sendData(0x90);
    294   _bus->sendCommand(0x57);
    295   _bus->sendData(0x99);
    296   _bus->sendCommand(0x58);
    297   _bus->sendData(0xA3);
    298   _bus->sendCommand(0x59);
    299   _bus->sendData(0xAD);
    300   _bus->sendCommand(0x5A);
    301   _bus->sendData(0xB4);
    302   _bus->sendCommand(0x5B);
    303   _bus->sendData(0xBB);
    304   _bus->sendCommand(0x5C);
    305   _bus->sendData(0xC4);
    306   _bus->sendCommand(0x5D);
    307   _bus->sendData(0xCE);
    308   _bus->sendCommand(0x5E);
    309   _bus->sendData(0xD9);
    310   _bus->sendCommand(0x5F);
    311   _bus->sendData(0xE3);
    312   _bus->sendCommand(0x60);
    313   _bus->sendData(0xEC);
    314   _bus->sendCommand(0x61);
    315   _bus->sendData(0xF3);
    316   _bus->sendCommand(0x62);
    317   _bus->sendData(0xF7);
    318   _bus->sendCommand(0x63);
    319   _bus->sendData(0xFC);
    320   _bus->sendCommand(0xFF);
    321   _bus->sendData(0x00); // Page0
    322   // Display ON Setting
    323   _bus->sendCommand(0x28);
    324   _bus->sendData(0x38); // GON=1, DTE=1, D=10
    325   delay(40);
    326   _bus->sendCommand(0x28);
    327   _bus->sendData(0x3C);    // GON=1, DTE=1, D=11
    328   _bus->sendCommand(0x22); // Start GRAM write
    329 }
    330 
    331 void Arduino_HX8352C::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h)
    332 {
    333   if ((x != _currentX) || (w != _currentW))
    334   {
    335     int16_t x_start = x + _xStart, x_end = x + w - 1 + _xStart;
    336     _bus->writeCommand(0x02);
    337     _bus->write(x_start >> 8);
    338     _bus->writeCommand(0x03);
    339     _bus->write(x_start & 0xFF);
    340     _bus->writeCommand(0x04);
    341     _bus->write(x_end >> 8);
    342     _bus->writeCommand(0x05);
    343     _bus->write(x_end & 0xFF);
    344 
    345     _currentX = x;
    346     _currentW = w;
    347   }
    348   if ((y != _currentY) || (h != _currentH))
    349   {
    350     int16_t y_start = y + _yStart, y_end = y + h - 1 + _yStart;
    351     _bus->writeCommand(0x06);
    352     _bus->write(y_start >> 8);
    353     _bus->writeCommand(0x07);
    354     _bus->write(y_start & 0xFF);
    355     _bus->writeCommand(0x08);
    356     _bus->write(y_end >> 8);
    357     _bus->writeCommand(0x09);
    358     _bus->write(y_end & 0xFF);
    359 
    360     _currentY = y;
    361     _currentH = h;
    362   }
    363 
    364   _bus->writeCommand(0x22); // write to RAM
    365 }
    366 
    367 /**************************************************************************/
    368 /*!
    369     @brief   Set origin of (0,0) and orientation of TFT display
    370     @param   m  The index for rotation, from 0-3 inclusive
    371 */
    372 /**************************************************************************/
    373 void Arduino_HX8352C::setRotation(uint8_t r)
    374 {
    375   Arduino_TFT::setRotation(r);
    376   switch (_rotation)
    377   {
    378   case 1:
    379     _bus->sendCommand(0x36);
    380     _bus->sendData(_invert ? 0x13 : 0x03);
    381     _bus->sendCommand(0x16);
    382     _bus->sendData(0x60);
    383     break;
    384   case 2:
    385     _bus->sendCommand(0x36);
    386     _bus->sendData(_invert ? 0x13 : 0x03);
    387     _bus->sendCommand(0x16);
    388     _bus->sendData(0x00);
    389     break;
    390   case 3:
    391     _bus->sendCommand(0x36);
    392     _bus->sendData(_invert ? 0x17 : 0x07);
    393     _bus->sendCommand(0x16);
    394     _bus->sendData(0x20);
    395     break;
    396   default: // case 0:
    397     _bus->sendCommand(0x36);
    398     _bus->sendData(_invert ? 0x17 : 0x07);
    399     _bus->sendCommand(0x16);
    400     _bus->sendData(0x40);
    401     break;
    402   }
    403 }
    404 
    405 void Arduino_HX8352C::invertDisplay(bool i)
    406 {
    407   _invert = _ips ^ i;
    408   setRotation(_rotation); // set invert by calling setRotation()
    409 }
    410 
    411 void Arduino_HX8352C::displayOn(void)
    412 {
    413   _bus->sendCommand(0x28);
    414   _bus->sendData(0x3C); // GON=1, DTE=1, D=11
    415 }
    416 
    417 void Arduino_HX8352C::displayOff(void)
    418 {
    419   _bus->sendCommand(0x28);
    420   _bus->sendData(0x34); // GON=1, DTE=1, D=01
    421   delay(40);
    422 }