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_RPiPicoPAR8.cpp (4314B)

      1 #if defined(TARGET_RP2040)
      2 
      3 #include "Arduino_RPiPicoPAR8.h"
      4 
      5 Arduino_RPiPicoPAR8::Arduino_RPiPicoPAR8(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_RPiPicoPAR8::begin(int32_t speed, int8_t dataMode)
     11 {
     12   pinMode(_dc, OUTPUT);
     13   digitalWrite(_dc, HIGH); // Data mode
     14   _dcPinMask = digitalPinToBitMask(_dc);
     15   if (_cs != GFX_NOT_DEFINED)
     16   {
     17     pinMode(_cs, OUTPUT);
     18     digitalWrite(_cs, HIGH); // disable chip select
     19     _csPinMask = digitalPinToBitMask(_cs);
     20   }
     21   pinMode(_wr, OUTPUT);
     22   digitalWrite(_wr, HIGH); // Set write strobe high (inactive)
     23   _wrPinMask = digitalPinToBitMask(_wr);
     24   _dataClrMask = 0xFF | _wrPinMask;
     25   if (_rd != GFX_NOT_DEFINED)
     26   {
     27     pinMode(_rd, OUTPUT);
     28     digitalWrite(_rd, HIGH);
     29     _rdPinMask = digitalPinToBitMask(_rd);
     30   }
     31 
     32   pinMode(0, OUTPUT);
     33   pinMode(1, OUTPUT);
     34   pinMode(2, OUTPUT);
     35   pinMode(3, OUTPUT);
     36   pinMode(4, OUTPUT);
     37   pinMode(5, OUTPUT);
     38   pinMode(6, OUTPUT);
     39   pinMode(7, OUTPUT);
     40   sio_hw->gpio_clr = 0xFF;
     41 
     42   return true;
     43 }
     44 
     45 void Arduino_RPiPicoPAR8::beginWrite()
     46 {
     47   DC_HIGH();
     48   CS_LOW();
     49 }
     50 
     51 void Arduino_RPiPicoPAR8::endWrite()
     52 {
     53   CS_HIGH();
     54 }
     55 
     56 void Arduino_RPiPicoPAR8::writeCommand(uint8_t c)
     57 {
     58   DC_LOW();
     59 
     60   WRITE(c);
     61 
     62   DC_HIGH();
     63 }
     64 
     65 void Arduino_RPiPicoPAR8::writeCommand16(uint16_t c)
     66 {
     67   DC_LOW();
     68 
     69   _data16.value = c;
     70   WRITE(_data16.msb);
     71   WRITE(_data16.lsb);
     72 
     73   DC_HIGH();
     74 }
     75 
     76 void Arduino_RPiPicoPAR8::write(uint8_t d)
     77 {
     78   WRITE(d);
     79 }
     80 
     81 void Arduino_RPiPicoPAR8::write16(uint16_t d)
     82 {
     83   _data16.value = d;
     84   WRITE(_data16.msb);
     85   WRITE(_data16.lsb);
     86 }
     87 
     88 void Arduino_RPiPicoPAR8::writeRepeat(uint16_t p, uint32_t len)
     89 {
     90   _data16.value = p;
     91   if (_data16.msb == _data16.lsb)
     92   {
     93     sio_hw->gpio_clr = 0xFF;
     94     sio_hw->gpio_set = _data16.msb;
     95     while (len--)
     96     {
     97       sio_hw->gpio_clr = _wrPinMask;
     98       sio_hw->gpio_set = _wrPinMask;
     99       sio_hw->gpio_clr = _wrPinMask;
    100       sio_hw->gpio_set = _wrPinMask;
    101     }
    102   }
    103   else
    104   {
    105     while (len--)
    106     {
    107       sio_hw->gpio_clr = _dataClrMask;
    108       sio_hw->gpio_set = _data16.msb;
    109       sio_hw->gpio_set = _wrPinMask;
    110 
    111       sio_hw->gpio_clr = _dataClrMask;
    112       sio_hw->gpio_set = _data16.lsb;
    113       sio_hw->gpio_set = _wrPinMask;
    114     }
    115   }
    116 }
    117 
    118 void Arduino_RPiPicoPAR8::writePixels(uint16_t *data, uint32_t len)
    119 {
    120   while (len--)
    121   {
    122     _data16.value = *data++;
    123     WRITE(_data16.msb);
    124     WRITE(_data16.lsb);
    125   }
    126 }
    127 
    128 void Arduino_RPiPicoPAR8::writeC8D8(uint8_t c, uint8_t d)
    129 {
    130   DC_LOW();
    131 
    132   WRITE(c);
    133 
    134   DC_HIGH();
    135 
    136   WRITE(d);
    137 }
    138 
    139 void Arduino_RPiPicoPAR8::writeC8D16(uint8_t c, uint16_t d)
    140 {
    141   DC_LOW();
    142 
    143   WRITE(c);
    144 
    145   DC_HIGH();
    146 
    147   _data16.value = d;
    148   WRITE(_data16.msb);
    149   WRITE(_data16.lsb);
    150 }
    151 
    152 void Arduino_RPiPicoPAR8::writeC8D16D16(uint8_t c, uint16_t d1, uint16_t d2)
    153 {
    154   DC_LOW();
    155 
    156   WRITE(c);
    157 
    158   DC_HIGH();
    159 
    160   _data16.value = d1;
    161   WRITE(_data16.msb);
    162   WRITE(_data16.lsb);
    163 
    164   _data16.value = d2;
    165   WRITE(_data16.msb);
    166   WRITE(_data16.lsb);
    167 }
    168 
    169 void Arduino_RPiPicoPAR8::writeBytes(uint8_t *data, uint32_t len)
    170 {
    171   while (len--)
    172   {
    173     WRITE(*data++);
    174   }
    175 }
    176 
    177 void Arduino_RPiPicoPAR8::writePattern(uint8_t *data, uint8_t len, uint32_t repeat)
    178 {
    179   while (repeat--)
    180   {
    181     writeBytes(data, len);
    182   }
    183 }
    184 
    185 void Arduino_RPiPicoPAR8::writeIndexedPixels(uint8_t *data, uint16_t *idx, uint32_t len)
    186 {
    187   while (len--)
    188   {
    189     _data16.value = idx[*data++];
    190     WRITE(_data16.msb);
    191     WRITE(_data16.lsb);
    192   }
    193 }
    194 
    195 void Arduino_RPiPicoPAR8::writeIndexedPixelsDouble(uint8_t *data, uint16_t *idx, uint32_t len)
    196 {
    197   while (len--)
    198   {
    199     _data16.value = idx[*data++];
    200     WRITE(_data16.msb);
    201     WRITE(_data16.lsb);
    202     WRITE(_data16.msb);
    203     WRITE(_data16.lsb);
    204   }
    205 }
    206 
    207 INLINE void Arduino_RPiPicoPAR8::WRITE(uint8_t d)
    208 {
    209   sio_hw->gpio_clr = _dataClrMask;
    210   sio_hw->gpio_set = d;
    211   sio_hw->gpio_set = _wrPinMask;
    212 }
    213 
    214 /******** low level bit twiddling **********/
    215 
    216 INLINE void Arduino_RPiPicoPAR8::DC_HIGH(void)
    217 {
    218   sio_hw->gpio_set = _dcPinMask;
    219 }
    220 
    221 INLINE void Arduino_RPiPicoPAR8::DC_LOW(void)
    222 {
    223   sio_hw->gpio_clr = _dcPinMask;
    224 }
    225 
    226 INLINE void Arduino_RPiPicoPAR8::CS_HIGH(void)
    227 {
    228   if (_cs != GFX_NOT_DEFINED)
    229   {
    230     sio_hw->gpio_set = _csPinMask;
    231   }
    232 }
    233 
    234 INLINE void Arduino_RPiPicoPAR8::CS_LOW(void)
    235 {
    236   if (_cs != GFX_NOT_DEFINED)
    237   {
    238     sio_hw->gpio_clr = _csPinMask;
    239   }
    240 }
    241 
    242 #endif // #if defined(TARGET_RP2040)