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_NT35510.cpp (6240B)

      1 /*
      2  * start rewrite from:
      3  * https://github.com/hi631/LCD_NT35510-MRB3971.git
      4  */
      5 #include "Arduino_NT35510.h"
      6 
      7 Arduino_NT35510::Arduino_NT35510(
      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 }
     14 
     15 bool Arduino_NT35510::begin(int32_t speed)
     16 {
     17   return Arduino_TFT::begin(speed);
     18 }
     19 
     20 /**************************************************************************/
     21 /*!
     22     @brief   Set origin of (0,0) and orientation of TFT display
     23     @param   m  The index for rotation, from 0-3 inclusive
     24 */
     25 /**************************************************************************/
     26 void Arduino_NT35510::setRotation(uint8_t r)
     27 {
     28   Arduino_TFT::setRotation(r);
     29   switch (_rotation)
     30   {
     31   case 3:
     32     r = (NT35510_MADCTL_MY | NT35510_MADCTL_MV);
     33     break;
     34   case 2:
     35     r = (NT35510_MADCTL_MY | NT35510_MADCTL_MX);
     36     break;
     37   case 1:
     38     r = (NT35510_MADCTL_MX | NT35510_MADCTL_MV);
     39     break;
     40   default: // case 0:
     41     r = 0;
     42     break;
     43   }
     44   _bus->beginWrite();
     45   _bus->writeCommand16(NT35510_MADCTR);
     46   _bus->write16(r);
     47   _bus->endWrite();
     48 }
     49 
     50 void Arduino_NT35510::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h)
     51 {
     52   if ((x != _currentX) || (w != _currentW))
     53   {
     54     _currentX = x;
     55     _currentW = w;
     56     _data16.value = x + _xStart;
     57     _bus->writeC16D16(NT35510_CASET, _data16.msb);
     58     _bus->writeC16D16(NT35510_CASET + 1, _data16.lsb);
     59     _data16.value += w - 1;
     60     _bus->writeC16D16(NT35510_CASET + 2, _data16.msb);
     61     _bus->writeC16D16(NT35510_CASET + 3, _data16.lsb);
     62   }
     63 
     64   if ((y != _currentY) || (h != _currentH))
     65   {
     66     _currentY = y;
     67     _currentH = h;
     68     _data16.value = y + _yStart;
     69     _bus->writeC16D16(NT35510_PASET, _data16.msb);
     70     _bus->writeC16D16(NT35510_PASET + 1, _data16.lsb);
     71     _data16.value += h - 1;
     72     _bus->writeC16D16(NT35510_PASET + 2, _data16.msb);
     73     _bus->writeC16D16(NT35510_PASET + 3, _data16.lsb);
     74   }
     75 
     76   _bus->writeCommand16(NT35510_RAMWR); // write to RAM
     77 }
     78 
     79 void Arduino_NT35510::invertDisplay(bool i)
     80 {
     81   // Not Implemented
     82   UNUSED(i);
     83 }
     84 
     85 void Arduino_NT35510::displayOn(void)
     86 {
     87   // Not Implemented
     88 }
     89 
     90 void Arduino_NT35510::displayOff(void)
     91 {
     92   // Not Implemented
     93 }
     94 
     95 void Arduino_NT35510::WriteRegM(uint16_t adr, uint16_t len, uint8_t dat[])
     96 {
     97   for (uint16_t i = 0; i < len; i++)
     98   {
     99     _bus->writeCommand16(adr++);
    100     _bus->write16(dat[i]);
    101   }
    102 }
    103 
    104 // Companion code to the above tables.  Reads and issues
    105 // a series of LCD commands stored in PROGMEM byte array.
    106 void Arduino_NT35510::tftInit()
    107 {
    108   if (_rst != GFX_NOT_DEFINED)
    109   {
    110     pinMode(_rst, OUTPUT);
    111     digitalWrite(_rst, HIGH);
    112     delay(100);
    113     digitalWrite(_rst, LOW);
    114     delay(NT35510_RST_DELAY);
    115     digitalWrite(_rst, HIGH);
    116     delay(NT35510_RST_DELAY);
    117   }
    118   else
    119   {
    120     // Software Rest
    121   }
    122 
    123   //************* NT35510**********//
    124   _bus->beginWrite();
    125   uint8_t ini01[] = {0x55, 0xAA, 0x52, 0x08, 0x01};
    126   WriteRegM(0xF000, sizeof(ini01), ini01);
    127   uint8_t ini03[] = {0x34, 0x34, 0x34};
    128   WriteRegM(0xB600, sizeof(ini03), ini03);
    129   uint8_t ini02[] = {0x0D, 0x0D, 0x0D};
    130   WriteRegM(0xB000, sizeof(ini02), ini02); // AVDD Set AVDD 5.2V
    131   uint8_t ini05[] = {0x34, 0x34, 0x34};
    132   WriteRegM(0xB700, sizeof(ini05), ini05); // AVEE ratio
    133   uint8_t ini04[] = {0x0D, 0x0D, 0x0D};
    134   WriteRegM(0xB100, sizeof(ini04), ini04); // AVEE  -5.2V
    135   uint8_t ini07[] = {0x24, 0x24, 0x24};
    136   WriteRegM(0xB800, sizeof(ini07), ini07); // VCL ratio
    137   uint8_t ini10[] = {0x34, 0x34, 0x34};
    138   WriteRegM(0xB900, sizeof(ini10), ini10); // VGH  ratio
    139   uint8_t ini09[] = {0x0F, 0x0F, 0x0F};
    140   WriteRegM(0xB300, sizeof(ini09), ini09);
    141   uint8_t ini14[] = {0x24, 0x24, 0x24};
    142   WriteRegM(0xBA00, sizeof(ini14), ini14); // VGLX  ratio
    143   uint8_t ini12[] = {0x08, 0x08};
    144   WriteRegM(0xB500, sizeof(ini12), ini12);
    145   uint8_t ini15[] = {0x00, 0x78, 0x00};
    146   WriteRegM(0xBC00, sizeof(ini15), ini15); // VGMP/VGSP 4.5V/0V
    147   uint8_t ini16[] = {0x00, 0x78, 0x00};
    148   WriteRegM(0xBD00, sizeof(ini16), ini16); // VGMN/VGSN -4.5V/0V
    149   uint8_t ini17[] = {0x00, 0x89};
    150   WriteRegM(0xBE00, sizeof(ini17), ini17); // VCOM  -1.325V
    151   // Gamma Setting
    152   uint8_t ini20[] = {
    153       0x00, 0x2D, 0x00, 0x2E, 0x00, 0x32, 0x00, 0x44, 0x00, 0x53, 0x00, 0x88, 0x00, 0xB6, 0x00, 0xF3, 0x01, 0x22, 0x01, 0x64,
    154       0x01, 0x92, 0x01, 0xD4, 0x02, 0x07, 0x02, 0x08, 0x02, 0x34, 0x02, 0x5F, 0x02, 0x78, 0x02, 0x94, 0x02, 0xA6, 0x02, 0xBB,
    155       0x02, 0xCA, 0x02, 0xDB, 0x02, 0xE8, 0x02, 0xF9, 0x03, 0x1F, 0x03, 0x7F};
    156   WriteRegM(0xD100, sizeof(ini20), ini20);
    157   WriteRegM(0xD400, sizeof(ini20), ini20); // R+ R-
    158   WriteRegM(0xD200, sizeof(ini20), ini20);
    159   WriteRegM(0xD500, sizeof(ini20), ini20); // G+ G-
    160   WriteRegM(0xD300, sizeof(ini20), ini20);
    161   WriteRegM(0xD600, sizeof(ini20), ini20); // B+ B-
    162   //
    163   uint8_t ini21[] = {0x55, 0xAA, 0x52, 0x08, 0x00};
    164   WriteRegM(0xF000, sizeof(ini21), ini21); // #Enable Page0
    165   uint8_t ini22[] = {0x08, 0x05, 0x02, 0x05, 0x02};
    166   WriteRegM(0xB000, sizeof(ini22), ini22); // # RGB I/F Setting
    167   _bus->writeCommand16(0xB600);
    168   _bus->write16(0x08);
    169   _bus->writeCommand16(0xB500);
    170   _bus->write16(0x50); // ## SDT: //0x6b ?? 480x854  0x50 ?? 480x800
    171   uint8_t ini24[] = {0x00, 0x00};
    172   WriteRegM(0xB700, sizeof(ini24), ini24); // ## Gate EQ:
    173   uint8_t ini25[] = {0x01, 0x05, 0x05, 0x05};
    174   WriteRegM(0xB800, sizeof(ini25), ini25); // ## Source EQ:
    175   uint8_t ini26[] = {0x00, 0x00, 0x00};
    176   WriteRegM(0xBC00, sizeof(ini26), ini26); // # Inversion: Column inversion (NVT)
    177   uint8_t ini27[] = {0x03, 0x00, 0x00};
    178   WriteRegM(0xCC00, sizeof(ini27), ini27); // # BOE's Setting(default)
    179   uint8_t ini28[] = {0x01, 0x84, 0x07, 0x31, 0x00, 0x01};
    180   WriteRegM(0xBD00, sizeof(ini28), ini28); // # Display Timing:
    181   //
    182   uint8_t ini30[] = {0xAA, 0x55, 0x25, 0x01};
    183   WriteRegM(0xFF00, sizeof(ini30), ini30);
    184   _bus->writeCommand16(NT35510_TEON);
    185   _bus->write16(0x00);
    186   _bus->writeCommand16(NT35510_COLMOD);
    187   _bus->write16(0x55); // 0x55=16bit Mode
    188   _bus->writeCommand16(NT35510_SLPOUT);
    189   _bus->endWrite();
    190 
    191   delay(NT35510_SLPOUT_DELAY);
    192 
    193   _bus->sendCommand16(NT35510_DISPON);
    194 
    195   delay(NT35510_SLPOUT_DELAY);
    196 }