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_ESP32S2PAR8Q.cpp (5403B)
1 #include "Arduino_ESP32S2PAR8Q.h" 2 3 #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3) 4 5 Arduino_ESP32S2PAR8Q::Arduino_ESP32S2PAR8Q(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_ESP32S2PAR8Q::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 if (_dc != GFX_NOT_DEFINED) 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 75 // INIT 8-bit mask 76 _dataClrMask = (1 << _wr) | 0xFF; 77 _dataPortSet = (PORTreg_t)&GPIO.out_w1ts; 78 _dataPortClr = (PORTreg_t)&GPIO.out_w1tc; 79 *_dataPortClr = _dataClrMask; 80 81 return true; 82 } 83 84 void Arduino_ESP32S2PAR8Q::beginWrite() 85 { 86 DC_HIGH(); 87 CS_LOW(); 88 } 89 90 void Arduino_ESP32S2PAR8Q::endWrite() 91 { 92 CS_HIGH(); 93 } 94 95 void Arduino_ESP32S2PAR8Q::writeCommand(uint8_t c) 96 { 97 DC_LOW(); 98 99 WRITE(c); 100 101 DC_HIGH(); 102 } 103 104 void Arduino_ESP32S2PAR8Q::writeCommand16(uint16_t c) 105 { 106 DC_LOW(); 107 108 _data16.value = c; 109 WRITE(_data16.msb); 110 WRITE(_data16.lsb); 111 112 DC_HIGH(); 113 } 114 115 void Arduino_ESP32S2PAR8Q::write(uint8_t d) 116 { 117 WRITE(d); 118 } 119 120 void Arduino_ESP32S2PAR8Q::write16(uint16_t d) 121 { 122 _data16.value = d; 123 WRITE(_data16.msb); 124 WRITE(_data16.lsb); 125 } 126 127 void Arduino_ESP32S2PAR8Q::writeRepeat(uint16_t p, uint32_t len) 128 { 129 _data16.value = p; 130 if (_data16.msb == _data16.lsb) 131 { 132 *_dataPortClr = _dataClrMask; 133 *_dataPortSet = _data16.msb; 134 *_wrPortSet = _wrPinMask; 135 *_wrPortClr = _wrPinMask; 136 *_wrPortSet = _wrPinMask; 137 while (--len) 138 { 139 *_wrPortClr = _wrPinMask; 140 *_wrPortSet = _wrPinMask; 141 *_wrPortClr = _wrPinMask; 142 *_wrPortSet = _wrPinMask; 143 } 144 } 145 else 146 { 147 while (len--) 148 { 149 *_dataPortClr = _dataClrMask; 150 *_dataPortSet = _data16.msb; 151 *_wrPortSet = _wrPinMask; 152 153 *_dataPortClr = _dataClrMask; 154 *_dataPortSet = _data16.lsb; 155 *_wrPortSet = _wrPinMask; 156 } 157 } 158 } 159 160 void Arduino_ESP32S2PAR8Q::writePixels(uint16_t *data, uint32_t len) 161 { 162 while (len--) 163 { 164 _data16.value = *data++; 165 WRITE(_data16.msb); 166 WRITE(_data16.lsb); 167 } 168 } 169 170 void Arduino_ESP32S2PAR8Q::writeC8D8(uint8_t c, uint8_t d) 171 { 172 DC_LOW(); 173 174 WRITE(c); 175 176 DC_HIGH(); 177 178 WRITE(d); 179 } 180 181 void Arduino_ESP32S2PAR8Q::writeC8D16(uint8_t c, uint16_t d) 182 { 183 DC_LOW(); 184 185 WRITE(c); 186 187 DC_HIGH(); 188 189 _data16.value = d; 190 WRITE(_data16.msb); 191 WRITE(_data16.lsb); 192 } 193 194 void Arduino_ESP32S2PAR8Q::writeC8D16D16(uint8_t c, uint16_t d1, uint16_t d2) 195 { 196 DC_LOW(); 197 198 WRITE(c); 199 200 DC_HIGH(); 201 202 _data16.value = d1; 203 WRITE(_data16.msb); 204 WRITE(_data16.lsb); 205 206 _data16.value = d2; 207 WRITE(_data16.msb); 208 WRITE(_data16.lsb); 209 } 210 211 void Arduino_ESP32S2PAR8Q::writeBytes(uint8_t *data, uint32_t len) 212 { 213 while (len--) 214 { 215 WRITE(*data++); 216 } 217 } 218 219 void Arduino_ESP32S2PAR8Q::writePattern(uint8_t *data, uint8_t len, uint32_t repeat) 220 { 221 while (repeat--) 222 { 223 writeBytes(data, len); 224 } 225 } 226 227 void Arduino_ESP32S2PAR8Q::writeIndexedPixels(uint8_t *data, uint16_t *idx, uint32_t len) 228 { 229 while (len--) 230 { 231 _data16.value = idx[*data++]; 232 WRITE(_data16.msb); 233 WRITE(_data16.lsb); 234 } 235 } 236 237 void Arduino_ESP32S2PAR8Q::writeIndexedPixelsDouble(uint8_t *data, uint16_t *idx, uint32_t len) 238 { 239 while (len--) 240 { 241 _data16.value = idx[*data++]; 242 WRITE(_data16.msb); 243 WRITE(_data16.lsb); 244 WRITE(_data16.msb); 245 WRITE(_data16.lsb); 246 } 247 } 248 249 INLINE void Arduino_ESP32S2PAR8Q::WRITE(uint8_t d) 250 { 251 *_dataPortClr = _dataClrMask; 252 *_dataPortSet = d; 253 *_wrPortSet = _wrPinMask; 254 } 255 256 /******** low level bit twiddling **********/ 257 258 INLINE void Arduino_ESP32S2PAR8Q::DC_HIGH(void) 259 { 260 *_dcPortSet = _dcPinMask; 261 } 262 263 INLINE void Arduino_ESP32S2PAR8Q::DC_LOW(void) 264 { 265 *_dcPortClr = _dcPinMask; 266 } 267 268 INLINE void Arduino_ESP32S2PAR8Q::CS_HIGH(void) 269 { 270 if (_cs != GFX_NOT_DEFINED) 271 { 272 *_csPortSet = _csPinMask; 273 } 274 } 275 276 INLINE void Arduino_ESP32S2PAR8Q::CS_LOW(void) 277 { 278 if (_cs != GFX_NOT_DEFINED) 279 { 280 *_csPortClr = _csPinMask; 281 } 282 } 283 284 #endif // #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3)