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_AVRPAR8.cpp (3922B)
1 #ifdef __AVR__ 2 3 #include "Arduino_AVRPAR8.h" 4 5 Arduino_AVRPAR8::Arduino_AVRPAR8(int8_t dc, int8_t cs, int8_t wr, int8_t rd, uint8_t port) 6 : _dc(dc), _cs(cs), _wr(wr), _rd(rd), _port(port) 7 { 8 } 9 10 bool Arduino_AVRPAR8::begin(int32_t speed, int8_t dataMode) 11 { 12 UNUSED(speed); 13 UNUSED(dataMode); 14 15 pinMode(_dc, OUTPUT); 16 digitalWrite(_dc, HIGH); // Data mode 17 _dcPort = (PORTreg_t)portOutputRegister(digitalPinToPort(_dc)); 18 _dcPinMaskSet = digitalPinToBitMask(_dc); 19 _dcPinMaskClr = ~_dcPinMaskSet; 20 21 if (_cs != GFX_NOT_DEFINED) 22 { 23 pinMode(_cs, OUTPUT); 24 digitalWrite(_cs, HIGH); // Disable chip select 25 _csPort = (PORTreg_t)portOutputRegister(digitalPinToPort(_cs)); 26 _csPinMaskSet = digitalPinToBitMask(_cs); 27 } 28 _csPinMaskClr = ~_csPinMaskSet; 29 30 pinMode(_wr, OUTPUT); 31 digitalWrite(_wr, HIGH); // Set write strobe high (inactive) 32 _wrPort = (PORTreg_t)portOutputRegister(digitalPinToPort(_wr)); 33 _wrPinMaskSet = digitalPinToBitMask(_wr); 34 _wrPinMaskClr = ~_wrPinMaskSet; 35 36 if (_rd != GFX_NOT_DEFINED) 37 { 38 pinMode(_rd, OUTPUT); 39 digitalWrite(_rd, HIGH); // Disable RD 40 _rdPort = (PORTreg_t)portOutputRegister(digitalPinToPort(_rd)); 41 _rdPinMaskSet = digitalPinToBitMask(_rd); 42 } 43 else 44 { 45 _rdPort = _dcPort; 46 _rdPinMaskSet = 0; 47 } 48 _rdPinMaskClr = ~_rdPinMaskSet; 49 50 *(portModeRegister(_port)) = 0xFF; 51 _dataPort = portOutputRegister(_port); 52 *_dataPort = 0xFF; 53 54 return true; 55 } 56 57 void Arduino_AVRPAR8::beginWrite() 58 { 59 DC_HIGH(); 60 CS_LOW(); 61 } 62 63 void Arduino_AVRPAR8::endWrite() 64 { 65 CS_HIGH(); 66 } 67 68 void Arduino_AVRPAR8::writeCommand(uint8_t c) 69 { 70 DC_LOW(); 71 72 WRITE(c); 73 74 DC_HIGH(); 75 } 76 77 void Arduino_AVRPAR8::writeCommand16(uint16_t c) 78 { 79 DC_LOW(); 80 81 _data16.value = c; 82 WRITE(_data16.msb); 83 WRITE(_data16.lsb); 84 85 DC_HIGH(); 86 } 87 88 void Arduino_AVRPAR8::write(uint8_t d) 89 { 90 WRITE(d); 91 } 92 93 void Arduino_AVRPAR8::write16(uint16_t d) 94 { 95 _data16.value = d; 96 WRITE(_data16.msb); 97 WRITE(_data16.lsb); 98 } 99 100 void Arduino_AVRPAR8::writeRepeat(uint16_t p, uint32_t len) 101 { 102 uint8_t wrMaskBase = *_wrPort & _wrPinMaskClr; 103 uint8_t wrMaskSet = wrMaskBase | _wrPinMaskSet; 104 _data16.value = p; 105 if (_data16.msb == _data16.lsb) 106 { 107 *_dataPort = _data16.msb; 108 while (len--) 109 { 110 *_wrPort = wrMaskBase; 111 *_wrPort = wrMaskSet; 112 *_wrPort = wrMaskBase; 113 *_wrPort = wrMaskSet; 114 } 115 } 116 else 117 { 118 while (len--) 119 { 120 *_dataPort = _data16.msb; 121 *_wrPort = wrMaskBase; 122 *_wrPort = wrMaskSet; 123 124 *_dataPort = _data16.lsb; 125 *_wrPort = wrMaskBase; 126 *_wrPort = wrMaskSet; 127 } 128 } 129 } 130 131 void Arduino_AVRPAR8::writePixels(uint16_t *data, uint32_t len) 132 { 133 while (len--) 134 { 135 _data16.value = *data++; 136 WRITE(_data16.msb); 137 WRITE(_data16.lsb); 138 } 139 } 140 141 void Arduino_AVRPAR8::writeC8D8(uint8_t c, uint8_t d) 142 { 143 DC_LOW(); 144 145 WRITE(c); 146 147 DC_HIGH(); 148 149 WRITE(d); 150 } 151 152 void Arduino_AVRPAR8::writeC8D16(uint8_t c, uint16_t d) 153 { 154 DC_LOW(); 155 156 WRITE(c); 157 158 DC_HIGH(); 159 160 _data16.value = d; 161 WRITE(_data16.msb); 162 WRITE(_data16.lsb); 163 } 164 165 void Arduino_AVRPAR8::writeC8D16D16(uint8_t c, uint16_t d1, uint16_t d2) 166 { 167 DC_LOW(); 168 169 WRITE(c); 170 171 DC_HIGH(); 172 173 _data16.value = d1; 174 WRITE(_data16.msb); 175 WRITE(_data16.lsb); 176 177 _data16.value = d2; 178 WRITE(_data16.msb); 179 WRITE(_data16.lsb); 180 } 181 182 INLINE void Arduino_AVRPAR8::WRITE(uint8_t d) 183 { 184 uint8_t wrMaskBase = *_wrPort & _wrPinMaskClr; 185 *_dataPort = d; 186 *_wrPort = wrMaskBase; 187 *_wrPort = wrMaskBase | _wrPinMaskSet; 188 } 189 190 /******** low level bit twiddling **********/ 191 192 INLINE void Arduino_AVRPAR8::DC_HIGH(void) 193 { 194 *_dcPort |= _dcPinMaskSet; 195 } 196 197 INLINE void Arduino_AVRPAR8::DC_LOW(void) 198 { 199 *_dcPort &= _dcPinMaskClr; 200 } 201 202 INLINE void Arduino_AVRPAR8::CS_HIGH(void) 203 { 204 if (_cs != GFX_NOT_DEFINED) 205 { 206 *_csPort |= _csPinMaskSet; 207 } 208 } 209 210 INLINE void Arduino_AVRPAR8::CS_LOW(void) 211 { 212 if (_cs != GFX_NOT_DEFINED) 213 { 214 *_csPort &= _csPinMaskClr; 215 } 216 } 217 218 #endif // #ifdef __AVR__