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_RPiPicoPAR16.cpp (4478B)

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