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_NV3041A.cpp (2728B)

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