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_SSD1283A.cpp (5425B)

      1 /*
      2  * start rewrite from:
      3  * https://github.com/adafruit/Adafruit-GFX-Library.git
      4  * https://github.com/gitcnd/LCDWIKI_SPI.git
      5  */
      6 #include "Arduino_SSD1283A.h"
      7 #include "SPI.h"
      8 
      9 Arduino_SSD1283A::Arduino_SSD1283A(
     10     Arduino_DataBus *bus, int8_t rst, uint8_t r, int16_t w, int16_t h,
     11     uint8_t col_offset1, uint8_t row_offset1, uint8_t col_offset2, uint8_t row_offset2)
     12     : Arduino_TFT(bus, rst, r, false, w, h, col_offset1, row_offset1, col_offset2, row_offset2)
     13 {
     14 }
     15 
     16 bool Arduino_SSD1283A::begin(int32_t speed)
     17 {
     18 #if defined(ESP8266) || defined(ESP32)
     19   if (speed == GFX_NOT_DEFINED)
     20   {
     21     speed = 27000000UL;
     22   }
     23 // Teensy 4.x
     24 #elif defined(__IMXRT1052__) || defined(__IMXRT1062__)
     25   if (speed == GFX_NOT_DEFINED)
     26   {
     27     speed = 27000000UL;
     28   }
     29 #endif
     30 
     31   return Arduino_TFT::begin(speed);
     32 }
     33 
     34 // Companion code to the above tables.  Reads and issues
     35 // a series of LCD commands stored in PROGMEM byte array.
     36 void Arduino_SSD1283A::tftInit()
     37 {
     38   if (_rst != GFX_NOT_DEFINED)
     39   {
     40     pinMode(_rst, OUTPUT);
     41     digitalWrite(_rst, HIGH);
     42     delay(100);
     43     digitalWrite(_rst, LOW);
     44     delay(SSD1283A_RST_DELAY);
     45     digitalWrite(_rst, HIGH);
     46     delay(SSD1283A_RST_DELAY);
     47   }
     48   else
     49   {
     50     // Software Rest
     51   }
     52 
     53   // Initialization Sequence
     54   _bus->beginWrite();
     55   _bus->writeCommand16(SSD1283A_POWER_CONTROL_1);
     56   _bus->write16(0x2F8E);
     57   _bus->writeCommand16(SSD1283A_POWER_CONTROL_2);
     58   _bus->write16(0x000C);
     59   _bus->writeCommand16(SSD1283A_DISPLAY_CONTROL);
     60   _bus->write16(0x0021);
     61   _bus->writeCommand16(SSD1283A_VCOM_OTP_1);
     62   _bus->write16(0x0006);
     63   _bus->writeCommand16(SSD1283A_VCOM_OTP_1);
     64   _bus->write16(0x0005);
     65   _bus->writeCommand16(SSD1283A_FURTHER_BIAS_CURRENT_SETTING);
     66   _bus->write16(0x057F);
     67   _bus->writeCommand16(SSD1283A_VCOM_OTP_2);
     68   _bus->write16(0x89A1);
     69   _bus->writeCommand16(SSD1283A_OSCILLATOR);
     70   _bus->write16(0x0001);
     71   _bus->endWrite();
     72   delay(100);
     73   _bus->beginWrite();
     74   _bus->writeCommand16(SSD1283A_VCOM_OTP_2);
     75   _bus->write16(0x80B0);
     76   _bus->endWrite();
     77   delay(30);
     78   _bus->beginWrite();
     79   _bus->writeCommand16(SSD1283A_VCOM_OTP_2);
     80   _bus->write16(0xFFFE);
     81   _bus->writeCommand16(SSD1283A_DISPLAY_CONTROL);
     82   _bus->write16(0x0223);
     83   _bus->endWrite();
     84   delay(30);
     85   _bus->beginWrite();
     86   _bus->writeCommand16(SSD1283A_DISPLAY_CONTROL);
     87   _bus->write16(0x0233);
     88   _bus->writeCommand16(SSD1283A_DRIVER_OUTPUT_CONTROL);
     89   _bus->write16(0x2183);
     90   _bus->writeCommand16(SSD1283A_ENTRY_MODE);
     91   _bus->write16(0x6830);
     92   _bus->writeCommand16(0x2F);
     93   _bus->write16(0xFFFF);
     94   _bus->writeCommand16(SSD1283A_OSCILLATOR_FREQUENCY);
     95   _bus->write16(0x8000);
     96   _bus->writeCommand16(SSD1283A_FURTHER_BIAS_CURRENT_SETTING);
     97   _bus->write16(0x0570);
     98   _bus->writeCommand16(SSD1283A_LCD_DRIVING_WAVEFORM_CONTROL);
     99   _bus->write16(0x0300);
    100   _bus->writeCommand16(SSD1283A_FRAME_CYCLE_CONTROL);
    101   _bus->write16(0x580C);
    102   _bus->writeCommand16(SSD1283A_POWER_CONTROL_3);
    103   _bus->write16(0x0609);
    104   _bus->writeCommand16(SSD1283A_POWER_CONTROL_4);
    105   _bus->write16(0x3100);
    106   _bus->endWrite();
    107 }
    108 
    109 void Arduino_SSD1283A::writeAddrWindow(int16_t x, int16_t y, uint16_t w, uint16_t h)
    110 {
    111   uint8_t v1 = 0, v2 = 0, v3 = 0, h1 = 0, h2 = 0, h3 = 0;
    112 
    113   // TODO: it works, but should have better way
    114   switch (_rotation)
    115   {
    116   case 1:
    117     v1 = x + w - 1 + _xStart;
    118     v2 = x + _xStart;
    119     v3 = v2;
    120     h1 = SSD1283A_TFTWIDTH - y - 1 + _yStart;
    121     h2 = SSD1283A_TFTWIDTH - y - h + _yStart;
    122     h3 = h1;
    123     break;
    124   case 2:
    125     v1 = SSD1283A_TFTWIDTH - y - 1 + _yStart;
    126     v2 = SSD1283A_TFTWIDTH - y - h + _yStart;
    127     v3 = v1;
    128     h1 = SSD1283A_TFTHEIGHT - x - 1 + _xStart;
    129     h2 = SSD1283A_TFTHEIGHT - x - w + _xStart;
    130     h3 = h1;
    131     break;
    132   case 3:
    133     v1 = SSD1283A_TFTHEIGHT - x - 1 + _xStart;
    134     v2 = SSD1283A_TFTHEIGHT - x - w + _xStart;
    135     v3 = v1;
    136     h1 = y + h - 1 + _yStart;
    137     h2 = y + _yStart;
    138     h3 = h2;
    139     break;
    140   default: // case 0:
    141     v1 = y + h - 1 + _yStart;
    142     v2 = y + _yStart;
    143     v3 = v2;
    144     h1 = x + w - 1 + _xStart;
    145     h2 = x + _xStart;
    146     h3 = h2;
    147     break;
    148   }
    149   _bus->writeCommand(SSD1283A_HORIZONTAL_RAM_ADDRESS_POSITION);
    150   _bus->write(h1);
    151   _bus->write(h2);
    152 
    153   _bus->writeCommand(SSD1283A_VERTICAL_RAM_ADDRESS_POSITION);
    154   _bus->write(v1);
    155   _bus->write(v2);
    156 
    157   _bus->writeCommand(SSD1283A_RAM_ADDRESS_SET);
    158   _bus->write(v3);
    159   _bus->write(h3);
    160 
    161   _bus->writeCommand(SSD1283A_WRITE_DATA_TO_GRAM);
    162 }
    163 
    164 /**************************************************************************/
    165 /*!
    166     @brief   Set origin of (0,0) and orientation of TFT display
    167     @param   m  The index for rotation, from 0-3 inclusive
    168 */
    169 /**************************************************************************/
    170 void Arduino_SSD1283A::setRotation(uint8_t r)
    171 {
    172   Arduino_TFT::setRotation(r);
    173   _bus->beginWrite();
    174   switch (_rotation)
    175   {
    176   case 1:
    177     _bus->writeCommand16(SSD1283A_ENTRY_MODE);
    178     _bus->write16(0x6828);
    179     break;
    180   case 2:
    181     _bus->writeCommand(SSD1283A_ENTRY_MODE);
    182     _bus->write16(0x6800);
    183     break;
    184   case 3:
    185     _bus->writeCommand(SSD1283A_ENTRY_MODE);
    186     _bus->write16(0x6818);
    187     break;
    188   default: // case 0:
    189     _bus->writeCommand16(SSD1283A_ENTRY_MODE);
    190     _bus->write16(0x6830);
    191     break;
    192   }
    193   _bus->endWrite();
    194 }
    195 
    196 void Arduino_SSD1283A::invertDisplay(bool i)
    197 {
    198   // Not Implemented
    199   UNUSED(i);
    200 }
    201 
    202 void Arduino_SSD1283A::displayOn(void)
    203 {
    204   // Not Implemented
    205 }
    206 
    207 void Arduino_SSD1283A::displayOff(void)
    208 {
    209   // Not Implemented
    210 }