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_ESP32S2PAR16Q.cpp (5271B)

      1 #include "Arduino_ESP32S2PAR16Q.h"
      2 
      3 #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3)
      4 
      5 Arduino_ESP32S2PAR16Q::Arduino_ESP32S2PAR16Q(int8_t dc, int8_t cs, int8_t wr, int8_t rd)
      6     : _dc(dc), _cs(cs), _wr(wr), _rd(rd)
      7 {
      8 }
      9 
     10 bool Arduino_ESP32S2PAR16Q::begin(int32_t speed, int8_t dataMode)
     11 {
     12   pinMode(_dc, OUTPUT);
     13   digitalWrite(_dc, HIGH); // Data mode
     14   if (_dc >= 32)
     15   {
     16     _dcPinMask = digitalPinToBitMask(_dc);
     17     _dcPortSet = (PORTreg_t)&GPIO.out1_w1ts.val;
     18     _dcPortClr = (PORTreg_t)&GPIO.out1_w1tc.val;
     19   }
     20   else
     21   {
     22     _dcPinMask = digitalPinToBitMask(_dc);
     23     _dcPortSet = (PORTreg_t)&GPIO.out_w1ts;
     24     _dcPortClr = (PORTreg_t)&GPIO.out_w1tc;
     25   }
     26 
     27   if (_cs != GFX_NOT_DEFINED)
     28   {
     29     pinMode(_cs, OUTPUT);
     30     digitalWrite(_cs, HIGH); // disable chip select
     31   }
     32   if (_cs >= 32)
     33   {
     34     _csPinMask = digitalPinToBitMask(_cs);
     35     _csPortSet = (PORTreg_t)&GPIO.out1_w1ts.val;
     36     _csPortClr = (PORTreg_t)&GPIO.out1_w1tc.val;
     37   }
     38   else if (_cs != GFX_NOT_DEFINED)
     39   {
     40     _csPinMask = digitalPinToBitMask(_cs);
     41     _csPortSet = (PORTreg_t)&GPIO.out_w1ts;
     42     _csPortClr = (PORTreg_t)&GPIO.out_w1tc;
     43   }
     44 
     45   pinMode(_wr, OUTPUT);
     46   digitalWrite(_wr, HIGH); // Set write strobe high (inactive)
     47   if (_wr >= 32)
     48   {
     49     _wrPinMask = digitalPinToBitMask(_wr);
     50     _wrPortSet = (PORTreg_t)&GPIO.out1_w1ts.val;
     51     _wrPortClr = (PORTreg_t)&GPIO.out1_w1tc.val;
     52   }
     53   else
     54   {
     55     _wrPinMask = digitalPinToBitMask(_wr);
     56     _wrPortSet = (PORTreg_t)&GPIO.out_w1ts;
     57     _wrPortClr = (PORTreg_t)&GPIO.out_w1tc;
     58   }
     59 
     60   if (_rd != GFX_NOT_DEFINED)
     61   {
     62     pinMode(_rd, OUTPUT);
     63     digitalWrite(_rd, HIGH);
     64   }
     65 
     66   pinMode(0, OUTPUT);
     67   pinMode(1, OUTPUT);
     68   pinMode(2, OUTPUT);
     69   pinMode(3, OUTPUT);
     70   pinMode(4, OUTPUT);
     71   pinMode(5, OUTPUT);
     72   pinMode(6, OUTPUT);
     73   pinMode(7, OUTPUT);
     74   pinMode(8, OUTPUT);
     75   pinMode(9, OUTPUT);
     76   pinMode(10, OUTPUT);
     77   pinMode(11, OUTPUT);
     78   pinMode(12, OUTPUT);
     79   pinMode(13, OUTPUT);
     80   pinMode(14, OUTPUT);
     81   pinMode(15, OUTPUT);
     82 
     83   // INIT 16-bit mask
     84   _dataClrMask = (1 << _wr) | 0xFFFF;
     85   _dataPortSet = (PORTreg_t)&GPIO.out_w1ts;
     86   _dataPortClr = (PORTreg_t)&GPIO.out_w1tc;
     87   *_dataPortClr = _dataClrMask;
     88 
     89   return true;
     90 }
     91 
     92 void Arduino_ESP32S2PAR16Q::beginWrite()
     93 {
     94   DC_HIGH();
     95   CS_LOW();
     96 }
     97 
     98 void Arduino_ESP32S2PAR16Q::endWrite()
     99 {
    100   CS_HIGH();
    101 }
    102 
    103 void Arduino_ESP32S2PAR16Q::writeCommand(uint8_t c)
    104 {
    105   DC_LOW();
    106 
    107   WRITE(c);
    108 
    109   DC_HIGH();
    110 }
    111 
    112 void Arduino_ESP32S2PAR16Q::writeCommand16(uint16_t c)
    113 {
    114   DC_LOW();
    115 
    116   WRITE16(c);
    117 
    118   DC_HIGH();
    119 }
    120 
    121 void Arduino_ESP32S2PAR16Q::write(uint8_t d)
    122 {
    123   WRITE(d);
    124 }
    125 
    126 void Arduino_ESP32S2PAR16Q::write16(uint16_t d)
    127 {
    128   WRITE16(d);
    129 }
    130 
    131 void Arduino_ESP32S2PAR16Q::writeRepeat(uint16_t p, uint32_t len)
    132 {
    133   *_dataPortClr = _dataClrMask;
    134   *_dataPortSet = p;
    135   while (len--)
    136   {
    137     *_wrPortClr = _wrPinMask;
    138     *_wrPortSet = _wrPinMask;
    139   }
    140 }
    141 
    142 void Arduino_ESP32S2PAR16Q::writePixels(uint16_t *data, uint32_t len)
    143 {
    144   while (len--)
    145   {
    146     WRITE16(*data++);
    147   }
    148 }
    149 
    150 void Arduino_ESP32S2PAR16Q::writeC8D8(uint8_t c, uint8_t d)
    151 {
    152   DC_LOW();
    153 
    154   WRITE(c);
    155 
    156   DC_HIGH();
    157 
    158   WRITE(d);
    159 }
    160 
    161 void Arduino_ESP32S2PAR16Q::writeC8D16(uint8_t c, uint16_t d)
    162 {
    163   DC_LOW();
    164 
    165   WRITE(c);
    166 
    167   DC_HIGH();
    168 
    169   WRITE16(d);
    170 }
    171 
    172 void Arduino_ESP32S2PAR16Q::writeC8D16D16(uint8_t c, uint16_t d1, uint16_t d2)
    173 {
    174   DC_LOW();
    175 
    176   WRITE(c);
    177 
    178   DC_HIGH();
    179 
    180   WRITE16(d1);
    181   WRITE16(d2);
    182 }
    183 
    184 void Arduino_ESP32S2PAR16Q::writeC8D16D16Split(uint8_t c, uint16_t d1, uint16_t d2)
    185 {
    186   DC_LOW();
    187 
    188   WRITE(c);
    189 
    190   DC_HIGH();
    191 
    192   _data16.value = d1;
    193   WRITE(_data16.msb);
    194   WRITE(_data16.lsb);
    195 
    196   _data16.value = d2;
    197   WRITE(_data16.msb);
    198   WRITE(_data16.lsb);
    199 }
    200 
    201 void Arduino_ESP32S2PAR16Q::writeBytes(uint8_t *data, uint32_t len)
    202 {
    203   while (len > 1)
    204   {
    205     _data16.msb = *data++;
    206     _data16.lsb = *data++;
    207     WRITE16(_data16.value);
    208     len -= 2;
    209   }
    210   if (len)
    211   {
    212     WRITE(*data);
    213   }
    214 }
    215 
    216 void Arduino_ESP32S2PAR16Q::writePattern(uint8_t *data, uint8_t len, uint32_t repeat)
    217 {
    218   while (repeat--)
    219   {
    220     writeBytes(data, len);
    221   }
    222 }
    223 
    224 void Arduino_ESP32S2PAR16Q::writeIndexedPixels(uint8_t *data, uint16_t *idx, uint32_t len)
    225 {
    226   while (len--)
    227   {
    228     WRITE16(idx[*data++]);
    229   }
    230 }
    231 
    232 void Arduino_ESP32S2PAR16Q::writeIndexedPixelsDouble(uint8_t *data, uint16_t *idx, uint32_t len)
    233 {
    234   while (len--)
    235   {
    236     *_dataPortClr = _dataClrMask;
    237     *_dataPortSet = idx[*data++];
    238     *_wrPortSet = _wrPinMask;
    239     *_wrPortClr = _wrPinMask;
    240     *_wrPortSet = _wrPinMask;
    241   }
    242 }
    243 
    244 INLINE void Arduino_ESP32S2PAR16Q::WRITE(uint8_t d)
    245 {
    246   *_dataPortClr = _dataClrMask;
    247   *_dataPortSet = d;
    248   *_wrPortSet = _wrPinMask;
    249 }
    250 
    251 INLINE void Arduino_ESP32S2PAR16Q::WRITE16(uint16_t d)
    252 {
    253   *_dataPortClr = _dataClrMask;
    254   *_dataPortSet = d;
    255   *_wrPortSet = _wrPinMask;
    256 }
    257 
    258 /******** low level bit twiddling **********/
    259 
    260 INLINE void Arduino_ESP32S2PAR16Q::DC_HIGH(void)
    261 {
    262   *_dcPortSet = _dcPinMask;
    263 }
    264 
    265 INLINE void Arduino_ESP32S2PAR16Q::DC_LOW(void)
    266 {
    267   *_dcPortClr = _dcPinMask;
    268 }
    269 
    270 INLINE void Arduino_ESP32S2PAR16Q::CS_HIGH(void)
    271 {
    272   if (_cs != GFX_NOT_DEFINED)
    273   {
    274     *_csPortSet = _csPinMask;
    275   }
    276 }
    277 
    278 INLINE void Arduino_ESP32S2PAR16Q::CS_LOW(void)
    279 {
    280   if (_cs != GFX_NOT_DEFINED)
    281   {
    282     *_csPortClr = _csPinMask;
    283   }
    284 }
    285 
    286 #endif // #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3)