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_HX8369A.cpp (3264B)

      1 #include "Arduino_HX8369A.h"
      2 
      3 Arduino_HX8369A::Arduino_HX8369A(
      4     Arduino_DataBus *bus, int8_t rst, uint8_t r,
      5     bool ips, int16_t w, int16_t h,
      6     uint8_t col_offset1, uint8_t row_offset1, uint8_t col_offset2, uint8_t row_offset2)
      7     : Arduino_TFT(bus, rst, r, ips, w, h, col_offset1, row_offset1, col_offset2, row_offset2)
      8 
      9 {
     10 }
     11 
     12 bool Arduino_HX8369A::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_HX8369A::setRotation(uint8_t r)
     24 {
     25   Arduino_TFT::setRotation(r);
     26   switch (_rotation)
     27   {
     28   case 7:
     29     r = (HX8369A_MADCTL_MV);
     30     break;
     31   case 6:
     32     r = (HX8369A_MADCTL_MY);
     33     break;
     34   case 5:
     35     r = (HX8369A_MADCTL_MY | HX8369A_MADCTL_MX | HX8369A_MADCTL_MV);
     36     break;
     37   case 4:
     38     r = (HX8369A_MADCTL_MX);
     39     break;
     40   case 3:
     41     r = (HX8369A_MADCTL_MY | HX8369A_MADCTL_MV);
     42     break;
     43   case 2:
     44     r = (HX8369A_MADCTL_MY | HX8369A_MADCTL_MX);
     45     break;
     46   case 1:
     47     r = (HX8369A_MADCTL_MX | HX8369A_MADCTL_MV);
     48     break;
     49   default: // case 0:
     50     r = 0;
     51     break;
     52   }
     53   _bus->beginWrite();
     54   _bus->writeC8D8(HX8369A_SET_ADDRESS_MODE, r);
     55   _bus->endWrite();
     56 }
     57 
     58 void Arduino_HX8369A::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h)
     59 {
     60   if ((x != _currentX) || (w != _currentW))
     61   {
     62     _currentX = x;
     63     _currentW = w;
     64     x += _xStart;
     65     _bus->writeC8D16D16Split(HX8369A_SET_CLUMN_ADDRESS, x, x + w - 1);
     66   }
     67 
     68   if ((y != _currentY) || (h != _currentH))
     69   {
     70     _currentY = y;
     71     _currentH = h;
     72     y += _yStart;
     73     _bus->writeC8D16D16Split(HX8369A_SET_PAGE_ADDRESS, y, y + h - 1);
     74   }
     75 
     76   _bus->writeCommand(HX8369A_WRITE_MEMORY_START);
     77 }
     78 
     79 void Arduino_HX8369A::invertDisplay(bool i)
     80 {
     81   if (_ips ^ i)
     82   {
     83     _bus->sendCommand(HX8369A_ENTER_INVERSION_MODE);
     84   }
     85   else
     86   {
     87     _bus->sendCommand(HX8369A_EXIT_INVERSION_MODE);
     88   }
     89 }
     90 
     91 void Arduino_HX8369A::displayOn(void)
     92 {
     93   _bus->sendCommand(HX8369A_EXIT_SLEEP_MODE);
     94   delay(120);
     95   _bus->sendCommand(HX8369A_SET_DISPLAY_ON);
     96 }
     97 
     98 void Arduino_HX8369A::displayOff(void)
     99 {
    100   _bus->sendCommand(HX8369A_SET_DISPLAY_OFF);
    101   delay(120);
    102   _bus->sendCommand(HX8369A_ENTER_SLEEP_MODE);
    103 }
    104 
    105 // Companion code to the above tables.  Reads and issues
    106 // a series of LCD commands stored in PROGMEM byte array.
    107 void Arduino_HX8369A::tftInit()
    108 {
    109   if (_rst != GFX_NOT_DEFINED)
    110   {
    111     pinMode(_rst, OUTPUT);
    112     digitalWrite(_rst, HIGH);
    113     delay(100);
    114     digitalWrite(_rst, LOW);
    115     delay(HX8369A_RST_DELAY);
    116     digitalWrite(_rst, HIGH);
    117     delay(HX8369A_RST_DELAY);
    118   }
    119   else
    120   {
    121     _bus->sendCommand(HX8369A_SWRESET);
    122     delay(HX8369A_RST_DELAY);
    123   }
    124 
    125   _bus->batchOperation(hx8369a_init_operations_part1, sizeof(hx8369a_init_operations_part1));
    126   for (int i = 0; i <= 63; i++)
    127   {
    128     _bus->write(i * 8);
    129   }
    130 
    131   for (int i = 0; i <= 63; i++)
    132   {
    133     _bus->write(i * 4);
    134   }
    135 
    136   for (int i = 0; i <= 63; i++)
    137   {
    138     _bus->write(i * 8);
    139   }
    140   _bus->batchOperation(hx8369a_init_operations_part2, sizeof(hx8369a_init_operations_part2));
    141 
    142   invertDisplay(false);
    143 }