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_DataBus.cpp (2730B)
1 /* 2 * start rewrite from: 3 * https://github.com/adafruit/Adafruit-GFX-Library.git 4 */ 5 #include "Arduino_DataBus.h" 6 7 Arduino_DataBus::Arduino_DataBus() {} 8 9 void Arduino_DataBus::writeC8D8(uint8_t c, uint8_t d) 10 { 11 writeCommand(c); 12 write(d); 13 } 14 15 void Arduino_DataBus::writeC8D16(uint8_t c, uint16_t d) 16 { 17 writeCommand(c); 18 write16(d); 19 } 20 21 void Arduino_DataBus::writeC16D16(uint16_t c, uint16_t d) 22 { 23 writeCommand16(c); 24 write16(d); 25 } 26 27 void Arduino_DataBus::writeC8D16D16(uint8_t c, uint16_t d1, uint16_t d2) 28 { 29 writeCommand(c); 30 write16(d1); 31 write16(d2); 32 } 33 34 void Arduino_DataBus::writeC8D16D16Split(uint8_t c, uint16_t d1, uint16_t d2) 35 { 36 writeCommand(c); 37 _data16.value = d1; 38 write(_data16.msb); 39 write(_data16.lsb); 40 _data16.value = d2; 41 write(_data16.msb); 42 write(_data16.lsb); 43 } 44 45 void Arduino_DataBus::sendCommand(uint8_t c) 46 { 47 beginWrite(); 48 writeCommand(c); 49 endWrite(); 50 } 51 52 void Arduino_DataBus::sendCommand16(uint16_t c) 53 { 54 beginWrite(); 55 writeCommand16(c); 56 endWrite(); 57 } 58 59 void Arduino_DataBus::sendData(uint8_t d) 60 { 61 beginWrite(); 62 write(d); 63 endWrite(); 64 } 65 66 void Arduino_DataBus::sendData16(uint16_t d) 67 { 68 beginWrite(); 69 write16(d); 70 endWrite(); 71 } 72 73 void Arduino_DataBus::batchOperation(const uint8_t *operations, size_t len) 74 { 75 for (size_t i = 0; i < len; ++i) 76 { 77 uint8_t l = 0; 78 switch (operations[i]) 79 { 80 case BEGIN_WRITE: 81 beginWrite(); 82 break; 83 case WRITE_C8_D16: 84 l++; 85 /* fall through */ 86 case WRITE_C8_D8: 87 l++; 88 /* fall through */ 89 case WRITE_COMMAND_8: 90 writeCommand(operations[++i]); 91 break; 92 case WRITE_C16_D16: 93 l = 2; 94 /* fall through */ 95 case WRITE_COMMAND_16: 96 _data16.msb = operations[++i]; 97 _data16.lsb = operations[++i]; 98 writeCommand16(_data16.value); 99 break; 100 case WRITE_DATA_8: 101 l = 1; 102 break; 103 case WRITE_DATA_16: 104 l = 2; 105 break; 106 case WRITE_BYTES: 107 l = operations[++i]; 108 break; 109 case END_WRITE: 110 endWrite(); 111 break; 112 case DELAY: 113 delay(operations[++i]); 114 break; 115 default: 116 printf("Unknown operation id at %d: %d", i, operations[i]); 117 break; 118 } 119 while (l--) 120 { 121 write(operations[++i]); 122 } 123 } 124 } 125 126 #if !defined(LITTLE_FOOT_PRINT) 127 void Arduino_DataBus::writeIndexedPixels(uint8_t *data, uint16_t *idx, uint32_t len) 128 { 129 while (len--) 130 { 131 write16(idx[*(data++)]); 132 } 133 } 134 135 void Arduino_DataBus::writeIndexedPixelsDouble(uint8_t *data, uint16_t *idx, uint32_t len) 136 { 137 uint8_t *d = data; 138 while (len--) 139 { 140 _data16.value = idx[*(d++)]; 141 write(_data16.msb); 142 write(_data16.lsb); 143 write(_data16.msb); 144 write(_data16.lsb); 145 } 146 } 147 #endif // !defined(LITTLE_FOOT_PRINT)