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_NT35310.cpp (2833B)

      1 /*
      2  * start rewrite from:
      3  * https://github.com/adafruit/Adafruit-GFX-Library.git
      4  * https://github.com/daumemo/IPS_LCD_NT35310_FT6236_Arduino_eSPI_Test
      5  */
      6 #include "Arduino_NT35310.h"
      7 
      8 Arduino_NT35310::Arduino_NT35310(
      9     Arduino_DataBus *bus, int8_t rst, uint8_t r,
     10     bool ips, int16_t w, int16_t h,
     11     uint8_t col_offset1, uint8_t row_offset1, uint8_t col_offset2, uint8_t row_offset2)
     12     : Arduino_TFT(bus, rst, r, ips, w, h, col_offset1, row_offset1, col_offset2, row_offset2)
     13 {
     14 }
     15 
     16 bool Arduino_NT35310::begin(int32_t speed)
     17 {
     18   return Arduino_TFT::begin(speed);
     19 }
     20 
     21 void Arduino_NT35310::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h)
     22 {
     23   if ((x != _currentX) || (w != _currentW))
     24   {
     25     _bus->writeC8D16D16(NT35310_SET_HORIZONTAL_ADDRESS, x + _xStart, x + w - 1 + _xStart);
     26 
     27     _currentX = x;
     28     _currentW = w;
     29   }
     30   if ((y != _currentY) || (h != _currentH))
     31   {
     32     _bus->writeC8D16D16(NT35310_SET_VERTICAL_ADDRESS, y + _yStart, y + h - 1 + _yStart);
     33 
     34     _currentY = y;
     35     _currentH = h;
     36   }
     37 
     38   _bus->writeCommand(NT35310_WRITE_MEMORY_START); // write to RAM
     39 }
     40 
     41 /**************************************************************************/
     42 /*!
     43     @brief   Set origin of (0,0) and orientation of TFT display
     44     @param   m  The index for rotation, from 0-3 inclusive
     45 */
     46 /**************************************************************************/
     47 void Arduino_NT35310::setRotation(uint8_t r)
     48 {
     49   Arduino_TFT::setRotation(r);
     50   switch (_rotation)
     51   {
     52   case 3:
     53     r = NT35310_MADCTL_MY | NT35310_MADCTL_MV | NT35310_MADCTL_RGB;
     54     break;
     55   case 2:
     56     r = NT35310_MADCTL_MY | NT35310_MADCTL_MX | NT35310_MADCTL_RGB;
     57     break;
     58   case 1:
     59     r = NT35310_MADCTL_MX | NT35310_MADCTL_MV | NT35310_MADCTL_RGB;
     60     break;
     61   default: // case 0:
     62     r = NT35310_MADCTL_RGB;
     63     break;
     64   }
     65   _bus->beginWrite();
     66   _bus->writeCommand(NT35310_SET_ADDRESS_MODE);
     67   _bus->write(r);
     68   _bus->endWrite();
     69 }
     70 
     71 void Arduino_NT35310::invertDisplay(bool i)
     72 {
     73   _bus->sendCommand((_ips ^ i) ? NT35310_ENTER_INVERT_MODE : NT35310_EXIT_INVERT_MODE);
     74 }
     75 
     76 void Arduino_NT35310::displayOn(void)
     77 {
     78   _bus->sendCommand(NT35310_EXIT_SLEEP_MODE);
     79   delay(NT35310_SLPOUT_DELAY);
     80 }
     81 
     82 void Arduino_NT35310::displayOff(void)
     83 {
     84   _bus->sendCommand(NT35310_ENTER_SLEEP_MODE);
     85   delay(NT35310_SLPIN_DELAY);
     86 }
     87 
     88 void Arduino_NT35310::tftInit()
     89 {
     90   if (_rst != GFX_NOT_DEFINED)
     91   {
     92     pinMode(_rst, OUTPUT);
     93     digitalWrite(_rst, HIGH);
     94     delay(100);
     95     digitalWrite(_rst, LOW);
     96     delay(NT35310_RST_DELAY);
     97     digitalWrite(_rst, HIGH);
     98     delay(NT35310_RST_DELAY);
     99   }
    100   else
    101   {
    102     // Software Rest
    103     _bus->sendCommand(NT35310_SOFT_RESET);
    104     delay(NT35310_RST_DELAY);
    105   }
    106 
    107   _bus->batchOperation(nt35310_init_operations, sizeof(nt35310_init_operations));
    108 
    109   if (_ips)
    110   {
    111     _bus->sendCommand(NT35310_ENTER_INVERT_MODE);
    112   }
    113 }