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_ST7796.cpp (2760B)

      1 /*
      2  * start rewrite from:
      3  * https://github.com/adafruit/Adafruit-GFX-Library.git
      4  */
      5 #include "Arduino_ST7796.h"
      6 
      7 Arduino_ST7796::Arduino_ST7796(
      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_ST7796::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_ST7796::setRotation(uint8_t r)
     27 {
     28   Arduino_TFT::setRotation(r);
     29   switch (_rotation)
     30   {
     31   case 1:
     32     r = ST7796_MADCTL_MX | ST7796_MADCTL_MV | ST7796_MADCTL_BGR;
     33     break;
     34   case 2:
     35     r = ST7796_MADCTL_MX | ST7796_MADCTL_MY | ST7796_MADCTL_BGR;
     36     break;
     37   case 3:
     38     r = ST7796_MADCTL_MY | ST7796_MADCTL_MV | ST7796_MADCTL_BGR;
     39     break;
     40   default: // case 0:
     41     r = ST7796_MADCTL_BGR;
     42     break;
     43   }
     44   _bus->beginWrite();
     45   _bus->writeCommand(ST7796_MADCTL);
     46   _bus->write(r);
     47   _bus->endWrite();
     48 }
     49 
     50 void Arduino_ST7796::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(ST7796_CASET, x, x + w - 1);
     58   }
     59 
     60   if ((y != _currentY) || (h != _currentH))
     61   {
     62     _currentY = y;
     63     _currentH = h;
     64     x += _yStart;
     65     _bus->writeC8D16D16(ST7796_RASET, y, y + h - 1);
     66   }
     67 
     68   _bus->writeCommand(ST7796_RAMWR); // write to RAM
     69 }
     70 
     71 void Arduino_ST7796::invertDisplay(bool i)
     72 {
     73   _bus->sendCommand(_ips ? (i ? ST7796_INVOFF : ST7796_INVON) : (i ? ST7796_INVON : ST7796_INVOFF));
     74 }
     75 
     76 void Arduino_ST7796::displayOn(void)
     77 {
     78   _bus->sendCommand(ST7796_SLPOUT);
     79   delay(ST7796_SLPOUT_DELAY);
     80 }
     81 
     82 void Arduino_ST7796::displayOff(void)
     83 {
     84   _bus->sendCommand(ST7796_SLPIN);
     85   delay(ST7796_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_ST7796::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(ST7796_RST_DELAY);
     99     digitalWrite(_rst, HIGH);
    100     delay(ST7796_RST_DELAY);
    101   }
    102   else
    103   {
    104     // Software Rest
    105     _bus->sendCommand(ST7796_SWRESET);
    106     delay(ST7796_RST_DELAY);
    107   }
    108 
    109   _bus->batchOperation(st7796_init_operations, sizeof(st7796_init_operations));
    110 
    111   if (_ips)
    112   {
    113     _bus->sendCommand(ST7796_INVON);
    114   }
    115 }