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_HX8357B.cpp (2552B)

      1 #include "Arduino_HX8357B.h"
      2 
      3 Arduino_HX8357B::Arduino_HX8357B(Arduino_DataBus *bus, int8_t rst, uint8_t r, bool ips /* = false */)
      4     : Arduino_TFT(bus, rst, r, ips, HX8357B_TFTWIDTH, HX8357B_TFTHEIGHT, 0, 0, 0, 0)
      5 {
      6 }
      7 
      8 bool Arduino_HX8357B::begin(int32_t speed)
      9 {
     10   return Arduino_TFT::begin(speed);
     11 }
     12 
     13 /**************************************************************************/
     14 /*!
     15     @brief   Set origin of (0,0) and orientation of TFT display
     16     @param   m  The index for rotation, from 0-3 inclusive
     17 */
     18 /**************************************************************************/
     19 void Arduino_HX8357B::setRotation(uint8_t r)
     20 {
     21   Arduino_TFT::setRotation(r);
     22   switch (_rotation)
     23   {
     24   case 3:
     25     r = (HX8357B_MADCTL_MX | HX8357B_MADCTL_MY | HX8357B_MADCTL_MV | HX8357B_MADCTL_BGR);
     26     break;
     27   case 2:
     28     r = (HX8357B_MADCTL_MY | HX8357B_MADCTL_BGR);
     29     break;
     30   case 1:
     31     r = (HX8357B_MADCTL_MV | HX8357B_MADCTL_BGR);
     32     break;
     33   default: // case 0:
     34     r = (HX8357B_MADCTL_MX | HX8357B_MADCTL_BGR);
     35     break;
     36   }
     37   _bus->beginWrite();
     38   _bus->writeC8D8(HX8357B_SET_ADDRESS_MODE, r);
     39   _bus->endWrite();
     40 }
     41 
     42 void Arduino_HX8357B::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h)
     43 {
     44   if ((x != _currentX) || (w != _currentW))
     45   {
     46     _currentX = x;
     47     _currentW = w;
     48     x += _xStart;
     49     _bus->writeC8D16D16(HX8357B_SET_COLUMN_ADDRESS, x, x + w - 1);
     50   }
     51 
     52   if ((y != _currentY) || (h != _currentH))
     53   {
     54     _currentY = y;
     55     _currentH = h;
     56     y += _yStart;
     57     _bus->writeC8D16D16(HX8357B_SET_PAGE_ADDRESS, y, y + h - 1);
     58   }
     59 
     60   _bus->writeCommand(HX8357B_WRITE_MEMORY_START); // write to RAM
     61 }
     62 
     63 void Arduino_HX8357B::invertDisplay(bool i)
     64 {
     65   _bus->sendCommand((_ips ^ i) ? HX8357B_ENTER_INVERSION_MODE : HX8357B_EXIT_INVERSION_MODE);
     66 }
     67 
     68 void Arduino_HX8357B::displayOn(void)
     69 {
     70   _bus->sendCommand(HX8357B_EXIT_SLEEP_MODE);
     71   delay(HX8357B_SLPOUT_DELAY);
     72 }
     73 
     74 void Arduino_HX8357B::displayOff(void)
     75 {
     76   _bus->sendCommand(HX8357B_ENTER_SLEEP_MODE);
     77   delay(HX8357B_SLPIN_DELAY);
     78 }
     79 
     80 void Arduino_HX8357B::tftInit()
     81 {
     82   if (_rst != GFX_NOT_DEFINED)
     83   {
     84     pinMode(_rst, OUTPUT);
     85     digitalWrite(_rst, HIGH);
     86     delay(100);
     87     digitalWrite(_rst, LOW);
     88     delay(HX8357B_RST_DELAY);
     89     digitalWrite(_rst, HIGH);
     90     delay(HX8357B_RST_DELAY);
     91   }
     92   else
     93   {
     94     // Software Rest
     95     _bus->sendCommand(HX8357B_SOFTWARE_RESET);
     96     delay(HX8357B_RST_DELAY);
     97   }
     98 
     99   _bus->batchOperation(hx8357b_init_operations, sizeof(hx8357b_init_operations));
    100 
    101   if (_ips)
    102   {
    103     _bus->sendCommand(HX8357B_ENTER_INVERSION_MODE);
    104   }
    105 }