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_ESP32S2PAR16.cpp (5318B)
1 #include "Arduino_ESP32S2PAR16.h" 2 3 #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3) 4 5 Arduino_ESP32S2PAR16::Arduino_ESP32S2PAR16(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_ESP32S2PAR16::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 = 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_ESP32S2PAR16::beginWrite() 93 { 94 DC_HIGH(); 95 CS_LOW(); 96 } 97 98 void Arduino_ESP32S2PAR16::endWrite() 99 { 100 CS_HIGH(); 101 } 102 103 void Arduino_ESP32S2PAR16::writeCommand(uint8_t c) 104 { 105 DC_LOW(); 106 107 WRITE(c); 108 109 DC_HIGH(); 110 } 111 112 void Arduino_ESP32S2PAR16::writeCommand16(uint16_t c) 113 { 114 DC_LOW(); 115 116 WRITE16(c); 117 118 DC_HIGH(); 119 } 120 121 void Arduino_ESP32S2PAR16::write(uint8_t d) 122 { 123 WRITE(d); 124 } 125 126 void Arduino_ESP32S2PAR16::write16(uint16_t d) 127 { 128 WRITE16(d); 129 } 130 131 void Arduino_ESP32S2PAR16::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_ESP32S2PAR16::writePixels(uint16_t *data, uint32_t len) 143 { 144 while (len--) 145 { 146 WRITE16(*data++); 147 } 148 } 149 150 void Arduino_ESP32S2PAR16::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_ESP32S2PAR16::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_ESP32S2PAR16::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_ESP32S2PAR16::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_ESP32S2PAR16::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_ESP32S2PAR16::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_ESP32S2PAR16::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_ESP32S2PAR16::writeIndexedPixelsDouble(uint8_t *data, uint16_t *idx, uint32_t len) 233 { 234 while (len--) 235 { 236 *_dataPortClr = _dataClrMask; 237 *_dataPortSet = idx[*data++]; 238 *_wrPortClr = _wrPinMask; 239 *_wrPortSet = _wrPinMask; 240 *_wrPortClr = _wrPinMask; 241 *_wrPortSet = _wrPinMask; 242 } 243 } 244 245 INLINE void Arduino_ESP32S2PAR16::WRITE(uint8_t d) 246 { 247 *_dataPortClr = _dataClrMask; 248 *_dataPortSet = d; 249 *_wrPortClr = _wrPinMask; 250 *_wrPortSet = _wrPinMask; 251 } 252 253 INLINE void Arduino_ESP32S2PAR16::WRITE16(uint16_t d) 254 { 255 *_dataPortClr = _dataClrMask; 256 *_dataPortSet = d; 257 *_wrPortClr = _wrPinMask; 258 *_wrPortSet = _wrPinMask; 259 } 260 261 /******** low level bit twiddling **********/ 262 263 INLINE void Arduino_ESP32S2PAR16::DC_HIGH(void) 264 { 265 *_dcPortSet = _dcPinMask; 266 } 267 268 INLINE void Arduino_ESP32S2PAR16::DC_LOW(void) 269 { 270 *_dcPortClr = _dcPinMask; 271 } 272 273 INLINE void Arduino_ESP32S2PAR16::CS_HIGH(void) 274 { 275 if (_cs != GFX_NOT_DEFINED) 276 { 277 *_csPortSet = _csPinMask; 278 } 279 } 280 281 INLINE void Arduino_ESP32S2PAR16::CS_LOW(void) 282 { 283 if (_cs != GFX_NOT_DEFINED) 284 { 285 *_csPortClr = _csPinMask; 286 } 287 } 288 289 #endif // #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3)