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_ILI9342.cpp (2750B)

      1 /*
      2  * start rewrite from:
      3  * https://github.com/adafruit/Adafruit-GFX-Library.git
      4  * https://github.com/adafruit/Adafruit_ILI9342.git
      5  */
      6 #include "Arduino_ILI9342.h"
      7 #include "SPI.h"
      8 
      9 Arduino_ILI9342::Arduino_ILI9342(Arduino_DataBus *bus, int8_t rst, uint8_t r, bool ips)
     10     : Arduino_TFT(bus, rst, r, ips, ILI9342_TFTWIDTH, ILI9342_TFTHEIGHT, 0, 0, 0, 0)
     11 {
     12 }
     13 
     14 bool Arduino_ILI9342::begin(int32_t speed)
     15 {
     16   _override_datamode = SPI_MODE0; // always use SPI_MODE0
     17 
     18   return Arduino_TFT::begin(speed);
     19 }
     20 
     21 /**************************************************************************/
     22 /*!
     23     @brief   Set origin of (0,0) and orientation of TFT display
     24     @param   m  The index for rotation, from 0-3 inclusive
     25 */
     26 /**************************************************************************/
     27 void Arduino_ILI9342::setRotation(uint8_t r)
     28 {
     29   Arduino_TFT::setRotation(r);
     30   switch (_rotation)
     31   {
     32   case 1:
     33     r = (ILI9342_MADCTL_MV | ILI9342_MADCTL_MY | ILI9342_MADCTL_BGR);
     34     break;
     35   case 2:
     36     r = (ILI9342_MADCTL_BGR);
     37     break;
     38   case 3:
     39     r = (ILI9342_MADCTL_MV | ILI9342_MADCTL_MX | ILI9342_MADCTL_BGR);
     40     break;
     41   default: // case 0:
     42     r = (ILI9342_MADCTL_MX | ILI9342_MADCTL_MY | ILI9342_MADCTL_BGR);
     43     break;
     44   }
     45   _bus->beginWrite();
     46   _bus->writeC8D8(ILI9342_MADCTL, r);
     47   _bus->endWrite();
     48 }
     49 
     50 void Arduino_ILI9342::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     x += _xStart;
     57     _bus->writeC8D16D16(ILI9342_CASET, x, x + w - 1);
     58   }
     59 
     60   if ((y != _currentY) || (h != _currentH))
     61   {
     62     _currentY = y;
     63     _currentH = h;
     64     y += _yStart;
     65     _bus->writeC8D16D16(ILI9342_PASET, y, y + h - 1);
     66   }
     67 
     68   _bus->writeCommand(ILI9342_RAMWR); // write to RAM
     69 }
     70 
     71 void Arduino_ILI9342::invertDisplay(bool i)
     72 {
     73   _bus->sendCommand((_ips ^ i) ? ILI9342_INVON : ILI9342_INVOFF);
     74 }
     75 
     76 void Arduino_ILI9342::displayOn(void)
     77 {
     78   _bus->sendCommand(ILI9342_SLPOUT);
     79   delay(ILI9342_SLPOUT_DELAY);
     80 }
     81 
     82 void Arduino_ILI9342::displayOff(void)
     83 {
     84   _bus->sendCommand(ILI9342_SLPIN);
     85   delay(ILI9342_SLPIN_DELAY);
     86 }
     87 
     88 // Companion code to the above tables.  Reads and issues
     89 // a series of LCD commands stored in PROGMEM byte array.
     90 void Arduino_ILI9342::tftInit()
     91 {
     92   if (_rst != GFX_NOT_DEFINED)
     93   {
     94     pinMode(_rst, OUTPUT);
     95     digitalWrite(_rst, HIGH);
     96     delay(100);
     97     digitalWrite(_rst, LOW);
     98     delay(ILI9342_RST_DELAY);
     99     digitalWrite(_rst, HIGH);
    100     delay(ILI9342_RST_DELAY);
    101   }
    102   else
    103   {
    104     // Software Rest
    105     _bus->sendCommand(ILI9342_SWRESET);
    106     delay(ILI9342_RST_DELAY);
    107   }
    108 
    109   _bus->batchOperation(ILI9342_init_operations, sizeof(ILI9342_init_operations));
    110 
    111   if (_ips)
    112   {
    113     _bus->sendCommand(ILI9342_INVON);
    114   }
    115 }