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