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_ILI9806.cpp (2691B)

      1 #include "Arduino_ILI9806.h"
      2 #include "SPI.h"
      3 
      4 Arduino_ILI9806::Arduino_ILI9806(Arduino_DataBus *bus, int8_t rst, uint8_t r, bool ips)
      5     : Arduino_TFT(bus, rst, r, ips, ILI9806_TFTWIDTH, ILI9806_TFTHEIGHT, 0, 0, 0, 0)
      6 {
      7 }
      8 
      9 bool Arduino_ILI9806::begin(int32_t speed)
     10 {
     11   _override_datamode = SPI_MODE0; // always use SPI_MODE0
     12 
     13   return Arduino_TFT::begin(speed);
     14 }
     15 
     16 /**************************************************************************/
     17 /*!
     18     @brief   Set origin of (0,0) and orientation of TFT display
     19     @param   m  The index for rotation, from 0-3 inclusive
     20 */
     21 /**************************************************************************/
     22 void Arduino_ILI9806::setRotation(uint8_t r)
     23 {
     24   Arduino_TFT::setRotation(r);
     25   switch (_rotation)
     26   {
     27   case 3:
     28     r = (ILI9806_MADCTL_MY | ILI9806_MADCTL_MV | ILI9806_MADCTL_RGB);
     29     break;
     30   case 2:
     31     r = (ILI9806_MADCTL_MX | ILI9806_MADCTL_MY | ILI9806_MADCTL_RGB);
     32     break;
     33   case 1:
     34     r = (ILI9806_MADCTL_MX | ILI9806_MADCTL_MV | ILI9806_MADCTL_RGB);
     35     break;
     36   default: // case 0:
     37     r = ILI9806_MADCTL_RGB;
     38     break;
     39   }
     40   _bus->beginWrite();
     41   _bus->writeC8D8(ILI9806_MADCTL, r);
     42   _bus->endWrite();
     43 }
     44 
     45 void Arduino_ILI9806::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h)
     46 {
     47   if ((x != _currentX) || (w != _currentW))
     48   {
     49     _currentX = x;
     50     _currentW = w;
     51     x += _xStart;
     52     _bus->writeC8D16D16Split(ILI9806_CASET, x, x + w - 1);
     53   }
     54 
     55   if ((y != _currentY) || (h != _currentH))
     56   {
     57     _currentY = y;
     58     _currentH = h;
     59     y += _yStart;
     60     _bus->writeC8D16D16Split(ILI9806_PASET, y, y + h - 1);
     61   }
     62 
     63   _bus->writeCommand(ILI9806_RAMWR); // write to RAM
     64 }
     65 
     66 void Arduino_ILI9806::invertDisplay(bool i)
     67 {
     68   _bus->sendCommand((_ips ^ i) ? ILI9806_INVON : ILI9806_INVOFF);
     69 }
     70 
     71 void Arduino_ILI9806::displayOn(void)
     72 {
     73   _bus->sendCommand(ILI9806_SLPOUT);
     74   delay(ILI9806_SLPOUT_DELAY);
     75   _bus->sendCommand(ILI9806_DISPON);
     76 }
     77 
     78 void Arduino_ILI9806::displayOff(void)
     79 {
     80   _bus->sendCommand(ILI9806_DISPOFF);
     81   delay(10);
     82   _bus->sendCommand(ILI9806_SLPIN);
     83   delay(ILI9806_SLPIN_DELAY);
     84 }
     85 
     86 // Companion code to the above tables.  Reads and issues
     87 // a series of LCD commands stored in PROGMEM byte array.
     88 void Arduino_ILI9806::tftInit()
     89 {
     90   if (_rst != GFX_NOT_DEFINED)
     91   {
     92     pinMode(_rst, OUTPUT);
     93     digitalWrite(_rst, HIGH);
     94     delay(1);
     95     digitalWrite(_rst, LOW);
     96     delay(10);
     97     digitalWrite(_rst, HIGH);
     98     delay(ILI9806_RST_DELAY);
     99   }
    100   else
    101   {
    102     // Software Rest
    103     _bus->sendCommand(ILI9806_SWRESET);
    104     delay(ILI9806_RST_DELAY);
    105   }
    106 
    107   _bus->batchOperation(ili9806_init_operations, sizeof(ili9806_init_operations));
    108 
    109   if (_ips)
    110   {
    111     _bus->sendCommand(ILI9806_INVON);
    112   }
    113 }