Hexiwear specific mods for SSD1351
Fork of Adafruit_GFX_1351 by
Adafruit_SSD1351.cpp@17:0a4bb1070fd5, 2015-04-22 (annotated)
- Committer:
- lionello
- Date:
- Wed Apr 22 02:14:36 2015 +0000
- Revision:
- 17:0a4bb1070fd5
- Child:
- 18:8606e2c579f1
Added SSD1351 support
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lionello | 17:0a4bb1070fd5 | 1 | #include "Adafruit_SSD1351.h" |
lionello | 17:0a4bb1070fd5 | 2 | |
lionello | 17:0a4bb1070fd5 | 3 | #include <stdarg.h> |
lionello | 17:0a4bb1070fd5 | 4 | |
lionello | 17:0a4bb1070fd5 | 5 | #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) |
lionello | 17:0a4bb1070fd5 | 6 | |
lionello | 17:0a4bb1070fd5 | 7 | |
lionello | 17:0a4bb1070fd5 | 8 | Adafruit_SSD1351::Adafruit_SSD1351(PinName cs, PinName rs, PinName dc, PinName clk, PinName data) |
lionello | 17:0a4bb1070fd5 | 9 | : Adafruit_GFX(SSD1351WIDTH, SSD1351HEIGHT), |
lionello | 17:0a4bb1070fd5 | 10 | _spi(data, NC, clk), |
lionello | 17:0a4bb1070fd5 | 11 | _cs(cs), |
lionello | 17:0a4bb1070fd5 | 12 | _reset(rs), |
lionello | 17:0a4bb1070fd5 | 13 | _dc(dc) |
lionello | 17:0a4bb1070fd5 | 14 | { |
lionello | 17:0a4bb1070fd5 | 15 | } |
lionello | 17:0a4bb1070fd5 | 16 | |
lionello | 17:0a4bb1070fd5 | 17 | void Adafruit_SSD1351::writeCommand(uint8_t code) |
lionello | 17:0a4bb1070fd5 | 18 | { |
lionello | 17:0a4bb1070fd5 | 19 | _cs = 1; |
lionello | 17:0a4bb1070fd5 | 20 | _dc = 0; |
lionello | 17:0a4bb1070fd5 | 21 | _cs = 0; |
lionello | 17:0a4bb1070fd5 | 22 | _spi.write(code); |
lionello | 17:0a4bb1070fd5 | 23 | _cs = 1; |
lionello | 17:0a4bb1070fd5 | 24 | } |
lionello | 17:0a4bb1070fd5 | 25 | |
lionello | 17:0a4bb1070fd5 | 26 | void Adafruit_SSD1351::writeData(uint8_t value) |
lionello | 17:0a4bb1070fd5 | 27 | { |
lionello | 17:0a4bb1070fd5 | 28 | _cs = 1; |
lionello | 17:0a4bb1070fd5 | 29 | _dc = 1; |
lionello | 17:0a4bb1070fd5 | 30 | _cs = 0; |
lionello | 17:0a4bb1070fd5 | 31 | _spi.write(value); |
lionello | 17:0a4bb1070fd5 | 32 | _cs = 1; |
lionello | 17:0a4bb1070fd5 | 33 | } |
lionello | 17:0a4bb1070fd5 | 34 | |
lionello | 17:0a4bb1070fd5 | 35 | void Adafruit_SSD1351::off() |
lionello | 17:0a4bb1070fd5 | 36 | { |
lionello | 17:0a4bb1070fd5 | 37 | writeCommand(0xAE); |
lionello | 17:0a4bb1070fd5 | 38 | } |
lionello | 17:0a4bb1070fd5 | 39 | |
lionello | 17:0a4bb1070fd5 | 40 | void Adafruit_SSD1351::on() |
lionello | 17:0a4bb1070fd5 | 41 | { |
lionello | 17:0a4bb1070fd5 | 42 | writeCommand(0xAF); |
lionello | 17:0a4bb1070fd5 | 43 | } |
lionello | 17:0a4bb1070fd5 | 44 | |
lionello | 17:0a4bb1070fd5 | 45 | void Adafruit_SSD1351::goTo(int x, int y) { |
lionello | 17:0a4bb1070fd5 | 46 | if ((x >= SSD1351WIDTH) || (y >= SSD1351HEIGHT)) return; |
lionello | 17:0a4bb1070fd5 | 47 | |
lionello | 17:0a4bb1070fd5 | 48 | // set x and y coordinate |
lionello | 17:0a4bb1070fd5 | 49 | writeCommand(SSD1351_CMD_SETCOLUMN); |
lionello | 17:0a4bb1070fd5 | 50 | writeData(x); |
lionello | 17:0a4bb1070fd5 | 51 | writeData(SSD1351WIDTH-1); |
lionello | 17:0a4bb1070fd5 | 52 | |
lionello | 17:0a4bb1070fd5 | 53 | writeCommand(SSD1351_CMD_SETROW); |
lionello | 17:0a4bb1070fd5 | 54 | writeData(y); |
lionello | 17:0a4bb1070fd5 | 55 | writeData(SSD1351HEIGHT-1); |
lionello | 17:0a4bb1070fd5 | 56 | |
lionello | 17:0a4bb1070fd5 | 57 | writeCommand(SSD1351_CMD_WRITERAM); |
lionello | 17:0a4bb1070fd5 | 58 | } |
lionello | 17:0a4bb1070fd5 | 59 | |
lionello | 17:0a4bb1070fd5 | 60 | uint16_t Adafruit_SSD1351::Color565(uint8_t r, uint8_t g, uint8_t b) { |
lionello | 17:0a4bb1070fd5 | 61 | uint16_t c; |
lionello | 17:0a4bb1070fd5 | 62 | c = r >> 3; |
lionello | 17:0a4bb1070fd5 | 63 | c <<= 6; |
lionello | 17:0a4bb1070fd5 | 64 | c |= g >> 2; |
lionello | 17:0a4bb1070fd5 | 65 | c <<= 5; |
lionello | 17:0a4bb1070fd5 | 66 | c |= b >> 3; |
lionello | 17:0a4bb1070fd5 | 67 | |
lionello | 17:0a4bb1070fd5 | 68 | return c; |
lionello | 17:0a4bb1070fd5 | 69 | } |
lionello | 17:0a4bb1070fd5 | 70 | |
lionello | 17:0a4bb1070fd5 | 71 | void Adafruit_SSD1351::fillScreen(uint16_t fillcolor) { |
lionello | 17:0a4bb1070fd5 | 72 | fillRect(0, 0, SSD1351WIDTH, SSD1351HEIGHT, fillcolor); |
lionello | 17:0a4bb1070fd5 | 73 | } |
lionello | 17:0a4bb1070fd5 | 74 | |
lionello | 17:0a4bb1070fd5 | 75 | // Draw a filled rectangle with no rotation. |
lionello | 17:0a4bb1070fd5 | 76 | void Adafruit_SSD1351::rawFillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t fillcolor) { |
lionello | 17:0a4bb1070fd5 | 77 | // Bounds check |
lionello | 17:0a4bb1070fd5 | 78 | if ((x >= SSD1351WIDTH) || (y >= SSD1351HEIGHT)) |
lionello | 17:0a4bb1070fd5 | 79 | return; |
lionello | 17:0a4bb1070fd5 | 80 | |
lionello | 17:0a4bb1070fd5 | 81 | // Y bounds check |
lionello | 17:0a4bb1070fd5 | 82 | if (y+h > SSD1351HEIGHT) |
lionello | 17:0a4bb1070fd5 | 83 | { |
lionello | 17:0a4bb1070fd5 | 84 | h = SSD1351HEIGHT - y - 1; |
lionello | 17:0a4bb1070fd5 | 85 | } |
lionello | 17:0a4bb1070fd5 | 86 | |
lionello | 17:0a4bb1070fd5 | 87 | // X bounds check |
lionello | 17:0a4bb1070fd5 | 88 | if (x+w > SSD1351WIDTH) |
lionello | 17:0a4bb1070fd5 | 89 | { |
lionello | 17:0a4bb1070fd5 | 90 | w = SSD1351WIDTH - x - 1; |
lionello | 17:0a4bb1070fd5 | 91 | } |
lionello | 17:0a4bb1070fd5 | 92 | |
lionello | 17:0a4bb1070fd5 | 93 | /* |
lionello | 17:0a4bb1070fd5 | 94 | Serial.print(x); Serial.print(", "); |
lionello | 17:0a4bb1070fd5 | 95 | Serial.print(y); Serial.print(", "); |
lionello | 17:0a4bb1070fd5 | 96 | Serial.print(w); Serial.print(", "); |
lionello | 17:0a4bb1070fd5 | 97 | Serial.print(h); Serial.println(", "); |
lionello | 17:0a4bb1070fd5 | 98 | */ |
lionello | 17:0a4bb1070fd5 | 99 | |
lionello | 17:0a4bb1070fd5 | 100 | // set location |
lionello | 17:0a4bb1070fd5 | 101 | writeCommand(SSD1351_CMD_SETCOLUMN); |
lionello | 17:0a4bb1070fd5 | 102 | writeData(x); |
lionello | 17:0a4bb1070fd5 | 103 | writeData(x+w-1); |
lionello | 17:0a4bb1070fd5 | 104 | writeCommand(SSD1351_CMD_SETROW); |
lionello | 17:0a4bb1070fd5 | 105 | writeData(y); |
lionello | 17:0a4bb1070fd5 | 106 | writeData(y+h-1); |
lionello | 17:0a4bb1070fd5 | 107 | // fill! |
lionello | 17:0a4bb1070fd5 | 108 | writeCommand(SSD1351_CMD_WRITERAM); |
lionello | 17:0a4bb1070fd5 | 109 | |
lionello | 17:0a4bb1070fd5 | 110 | for (uint16_t i=0; i < w*h; i++) { |
lionello | 17:0a4bb1070fd5 | 111 | writeData(fillcolor >> 8); |
lionello | 17:0a4bb1070fd5 | 112 | writeData(fillcolor); |
lionello | 17:0a4bb1070fd5 | 113 | } |
lionello | 17:0a4bb1070fd5 | 114 | } |
lionello | 17:0a4bb1070fd5 | 115 | |
lionello | 17:0a4bb1070fd5 | 116 | /**************************************************************************/ |
lionello | 17:0a4bb1070fd5 | 117 | /*! |
lionello | 17:0a4bb1070fd5 | 118 | @brief Draws a filled rectangle using HW acceleration |
lionello | 17:0a4bb1070fd5 | 119 | */ |
lionello | 17:0a4bb1070fd5 | 120 | /**************************************************************************/ |
lionello | 17:0a4bb1070fd5 | 121 | void Adafruit_SSD1351::fillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t fillcolor) { |
lionello | 17:0a4bb1070fd5 | 122 | // Transform x and y based on current rotation. |
lionello | 17:0a4bb1070fd5 | 123 | switch (getRotation()) { |
lionello | 17:0a4bb1070fd5 | 124 | case 0: // No rotation |
lionello | 17:0a4bb1070fd5 | 125 | rawFillRect(x, y, w, h, fillcolor); |
lionello | 17:0a4bb1070fd5 | 126 | break; |
lionello | 17:0a4bb1070fd5 | 127 | case 1: // Rotated 90 degrees clockwise. |
lionello | 17:0a4bb1070fd5 | 128 | swap(x, y); |
lionello | 17:0a4bb1070fd5 | 129 | x = _rawWidth - x - h; |
lionello | 17:0a4bb1070fd5 | 130 | rawFillRect(x, y, h, w, fillcolor); |
lionello | 17:0a4bb1070fd5 | 131 | break; |
lionello | 17:0a4bb1070fd5 | 132 | case 2: // Rotated 180 degrees clockwise. |
lionello | 17:0a4bb1070fd5 | 133 | x = _rawWidth - x - w; |
lionello | 17:0a4bb1070fd5 | 134 | y = _rawHeight - y - h; |
lionello | 17:0a4bb1070fd5 | 135 | rawFillRect(x, y, w, h, fillcolor); |
lionello | 17:0a4bb1070fd5 | 136 | break; |
lionello | 17:0a4bb1070fd5 | 137 | case 3: // Rotated 270 degrees clockwise. |
lionello | 17:0a4bb1070fd5 | 138 | swap(x, y); |
lionello | 17:0a4bb1070fd5 | 139 | y = _rawHeight - y - w; |
lionello | 17:0a4bb1070fd5 | 140 | rawFillRect(x, y, h, w, fillcolor); |
lionello | 17:0a4bb1070fd5 | 141 | break; |
lionello | 17:0a4bb1070fd5 | 142 | } |
lionello | 17:0a4bb1070fd5 | 143 | } |
lionello | 17:0a4bb1070fd5 | 144 | |
lionello | 17:0a4bb1070fd5 | 145 | // Draw a horizontal line ignoring any screen rotation. |
lionello | 17:0a4bb1070fd5 | 146 | void Adafruit_SSD1351::rawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) { |
lionello | 17:0a4bb1070fd5 | 147 | // Bounds check |
lionello | 17:0a4bb1070fd5 | 148 | if ((x >= SSD1351WIDTH) || (y >= SSD1351HEIGHT)) |
lionello | 17:0a4bb1070fd5 | 149 | return; |
lionello | 17:0a4bb1070fd5 | 150 | |
lionello | 17:0a4bb1070fd5 | 151 | // X bounds check |
lionello | 17:0a4bb1070fd5 | 152 | if (x+w > SSD1351WIDTH) |
lionello | 17:0a4bb1070fd5 | 153 | { |
lionello | 17:0a4bb1070fd5 | 154 | w = SSD1351WIDTH - x - 1; |
lionello | 17:0a4bb1070fd5 | 155 | } |
lionello | 17:0a4bb1070fd5 | 156 | |
lionello | 17:0a4bb1070fd5 | 157 | if (w < 0) return; |
lionello | 17:0a4bb1070fd5 | 158 | |
lionello | 17:0a4bb1070fd5 | 159 | // set location |
lionello | 17:0a4bb1070fd5 | 160 | writeCommand(SSD1351_CMD_SETCOLUMN); |
lionello | 17:0a4bb1070fd5 | 161 | writeData(x); |
lionello | 17:0a4bb1070fd5 | 162 | writeData(x+w-1); |
lionello | 17:0a4bb1070fd5 | 163 | writeCommand(SSD1351_CMD_SETROW); |
lionello | 17:0a4bb1070fd5 | 164 | writeData(y); |
lionello | 17:0a4bb1070fd5 | 165 | writeData(y); |
lionello | 17:0a4bb1070fd5 | 166 | // fill! |
lionello | 17:0a4bb1070fd5 | 167 | writeCommand(SSD1351_CMD_WRITERAM); |
lionello | 17:0a4bb1070fd5 | 168 | |
lionello | 17:0a4bb1070fd5 | 169 | for (uint16_t i=0; i < w; i++) { |
lionello | 17:0a4bb1070fd5 | 170 | writeData(color >> 8); |
lionello | 17:0a4bb1070fd5 | 171 | writeData(color); |
lionello | 17:0a4bb1070fd5 | 172 | } |
lionello | 17:0a4bb1070fd5 | 173 | } |
lionello | 17:0a4bb1070fd5 | 174 | |
lionello | 17:0a4bb1070fd5 | 175 | // Draw a vertical line ignoring any screen rotation. |
lionello | 17:0a4bb1070fd5 | 176 | void Adafruit_SSD1351::rawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { |
lionello | 17:0a4bb1070fd5 | 177 | // Bounds check |
lionello | 17:0a4bb1070fd5 | 178 | if ((x >= SSD1351WIDTH) || (y >= SSD1351HEIGHT)) |
lionello | 17:0a4bb1070fd5 | 179 | return; |
lionello | 17:0a4bb1070fd5 | 180 | |
lionello | 17:0a4bb1070fd5 | 181 | // X bounds check |
lionello | 17:0a4bb1070fd5 | 182 | if (y+h > SSD1351HEIGHT) |
lionello | 17:0a4bb1070fd5 | 183 | { |
lionello | 17:0a4bb1070fd5 | 184 | h = SSD1351HEIGHT - y - 1; |
lionello | 17:0a4bb1070fd5 | 185 | } |
lionello | 17:0a4bb1070fd5 | 186 | |
lionello | 17:0a4bb1070fd5 | 187 | if (h < 0) return; |
lionello | 17:0a4bb1070fd5 | 188 | |
lionello | 17:0a4bb1070fd5 | 189 | // set location |
lionello | 17:0a4bb1070fd5 | 190 | writeCommand(SSD1351_CMD_SETCOLUMN); |
lionello | 17:0a4bb1070fd5 | 191 | writeData(x); |
lionello | 17:0a4bb1070fd5 | 192 | writeData(x); |
lionello | 17:0a4bb1070fd5 | 193 | writeCommand(SSD1351_CMD_SETROW); |
lionello | 17:0a4bb1070fd5 | 194 | writeData(y); |
lionello | 17:0a4bb1070fd5 | 195 | writeData(y+h-1); |
lionello | 17:0a4bb1070fd5 | 196 | // fill! |
lionello | 17:0a4bb1070fd5 | 197 | writeCommand(SSD1351_CMD_WRITERAM); |
lionello | 17:0a4bb1070fd5 | 198 | |
lionello | 17:0a4bb1070fd5 | 199 | for (uint16_t i=0; i < h; i++) { |
lionello | 17:0a4bb1070fd5 | 200 | writeData(color >> 8); |
lionello | 17:0a4bb1070fd5 | 201 | writeData(color); |
lionello | 17:0a4bb1070fd5 | 202 | } |
lionello | 17:0a4bb1070fd5 | 203 | } |
lionello | 17:0a4bb1070fd5 | 204 | |
lionello | 17:0a4bb1070fd5 | 205 | void Adafruit_SSD1351::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { |
lionello | 17:0a4bb1070fd5 | 206 | // Transform x and y based on current rotation. |
lionello | 17:0a4bb1070fd5 | 207 | switch (getRotation()) { |
lionello | 17:0a4bb1070fd5 | 208 | case 0: // No rotation |
lionello | 17:0a4bb1070fd5 | 209 | rawFastVLine(x, y, h, color); |
lionello | 17:0a4bb1070fd5 | 210 | break; |
lionello | 17:0a4bb1070fd5 | 211 | case 1: // Rotated 90 degrees clockwise. |
lionello | 17:0a4bb1070fd5 | 212 | swap(x, y); |
lionello | 17:0a4bb1070fd5 | 213 | x = _rawWidth - x - h; |
lionello | 17:0a4bb1070fd5 | 214 | rawFastHLine(x, y, h, color); |
lionello | 17:0a4bb1070fd5 | 215 | break; |
lionello | 17:0a4bb1070fd5 | 216 | case 2: // Rotated 180 degrees clockwise. |
lionello | 17:0a4bb1070fd5 | 217 | x = _rawWidth - x - 1; |
lionello | 17:0a4bb1070fd5 | 218 | y = _rawHeight - y - h; |
lionello | 17:0a4bb1070fd5 | 219 | rawFastVLine(x, y, h, color); |
lionello | 17:0a4bb1070fd5 | 220 | break; |
lionello | 17:0a4bb1070fd5 | 221 | case 3: // Rotated 270 degrees clockwise. |
lionello | 17:0a4bb1070fd5 | 222 | swap(x, y); |
lionello | 17:0a4bb1070fd5 | 223 | y = _rawHeight - y - 1; |
lionello | 17:0a4bb1070fd5 | 224 | rawFastHLine(x, y, h, color); |
lionello | 17:0a4bb1070fd5 | 225 | break; |
lionello | 17:0a4bb1070fd5 | 226 | } |
lionello | 17:0a4bb1070fd5 | 227 | } |
lionello | 17:0a4bb1070fd5 | 228 | |
lionello | 17:0a4bb1070fd5 | 229 | void Adafruit_SSD1351::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) { |
lionello | 17:0a4bb1070fd5 | 230 | // Transform x and y based on current rotation. |
lionello | 17:0a4bb1070fd5 | 231 | switch (getRotation()) { |
lionello | 17:0a4bb1070fd5 | 232 | case 0: // No rotation. |
lionello | 17:0a4bb1070fd5 | 233 | rawFastHLine(x, y, w, color); |
lionello | 17:0a4bb1070fd5 | 234 | break; |
lionello | 17:0a4bb1070fd5 | 235 | case 1: // Rotated 90 degrees clockwise. |
lionello | 17:0a4bb1070fd5 | 236 | swap(x, y); |
lionello | 17:0a4bb1070fd5 | 237 | x = _rawWidth - x - 1; |
lionello | 17:0a4bb1070fd5 | 238 | rawFastVLine(x, y, w, color); |
lionello | 17:0a4bb1070fd5 | 239 | break; |
lionello | 17:0a4bb1070fd5 | 240 | case 2: // Rotated 180 degrees clockwise. |
lionello | 17:0a4bb1070fd5 | 241 | x = _rawWidth - x - w; |
lionello | 17:0a4bb1070fd5 | 242 | y = _rawHeight - y - 1; |
lionello | 17:0a4bb1070fd5 | 243 | rawFastHLine(x, y, w, color); |
lionello | 17:0a4bb1070fd5 | 244 | break; |
lionello | 17:0a4bb1070fd5 | 245 | case 3: // Rotated 270 degrees clockwise. |
lionello | 17:0a4bb1070fd5 | 246 | swap(x, y); |
lionello | 17:0a4bb1070fd5 | 247 | y = _rawHeight - y - w; |
lionello | 17:0a4bb1070fd5 | 248 | rawFastVLine(x, y, w, color); |
lionello | 17:0a4bb1070fd5 | 249 | break; |
lionello | 17:0a4bb1070fd5 | 250 | } |
lionello | 17:0a4bb1070fd5 | 251 | } |
lionello | 17:0a4bb1070fd5 | 252 | |
lionello | 17:0a4bb1070fd5 | 253 | void Adafruit_SSD1351::drawPixel(int16_t x, int16_t y, uint16_t color) |
lionello | 17:0a4bb1070fd5 | 254 | { |
lionello | 17:0a4bb1070fd5 | 255 | // Transform x and y based on current rotation. |
lionello | 17:0a4bb1070fd5 | 256 | switch (getRotation()) { |
lionello | 17:0a4bb1070fd5 | 257 | // Case 0: No rotation |
lionello | 17:0a4bb1070fd5 | 258 | case 1: // Rotated 90 degrees clockwise. |
lionello | 17:0a4bb1070fd5 | 259 | swap(x, y); |
lionello | 17:0a4bb1070fd5 | 260 | x = _rawWidth - x - 1; |
lionello | 17:0a4bb1070fd5 | 261 | break; |
lionello | 17:0a4bb1070fd5 | 262 | case 2: // Rotated 180 degrees clockwise. |
lionello | 17:0a4bb1070fd5 | 263 | x = _rawWidth - x - 1; |
lionello | 17:0a4bb1070fd5 | 264 | y = _rawHeight - y - 1; |
lionello | 17:0a4bb1070fd5 | 265 | break; |
lionello | 17:0a4bb1070fd5 | 266 | case 3: // Rotated 270 degrees clockwise. |
lionello | 17:0a4bb1070fd5 | 267 | swap(x, y); |
lionello | 17:0a4bb1070fd5 | 268 | y = _rawHeight - y - 1; |
lionello | 17:0a4bb1070fd5 | 269 | break; |
lionello | 17:0a4bb1070fd5 | 270 | } |
lionello | 17:0a4bb1070fd5 | 271 | |
lionello | 17:0a4bb1070fd5 | 272 | // Bounds check. |
lionello | 17:0a4bb1070fd5 | 273 | if ((x >= SSD1351WIDTH) || (y >= SSD1351HEIGHT)) return; |
lionello | 17:0a4bb1070fd5 | 274 | if ((x < 0) || (y < 0)) return; |
lionello | 17:0a4bb1070fd5 | 275 | |
lionello | 17:0a4bb1070fd5 | 276 | goTo(x, y); |
lionello | 17:0a4bb1070fd5 | 277 | |
lionello | 17:0a4bb1070fd5 | 278 | writeData(color >> 8); |
lionello | 17:0a4bb1070fd5 | 279 | writeData(color); |
lionello | 17:0a4bb1070fd5 | 280 | } |
lionello | 17:0a4bb1070fd5 | 281 | |
lionello | 17:0a4bb1070fd5 | 282 | void Adafruit_SSD1351::begin(void) { |
lionello | 17:0a4bb1070fd5 | 283 | #if 0 |
lionello | 17:0a4bb1070fd5 | 284 | // set pin directions |
lionello | 17:0a4bb1070fd5 | 285 | pinMode(_rs, OUTPUT); |
lionello | 17:0a4bb1070fd5 | 286 | |
lionello | 17:0a4bb1070fd5 | 287 | if (_sclk) { |
lionello | 17:0a4bb1070fd5 | 288 | pinMode(_sclk, OUTPUT); |
lionello | 17:0a4bb1070fd5 | 289 | |
lionello | 17:0a4bb1070fd5 | 290 | pinMode(_sid, OUTPUT); |
lionello | 17:0a4bb1070fd5 | 291 | } else { |
lionello | 17:0a4bb1070fd5 | 292 | // using the hardware SPI |
lionello | 17:0a4bb1070fd5 | 293 | SPI.begin(); |
lionello | 17:0a4bb1070fd5 | 294 | SPI.setDataMode(SPI_MODE3); |
lionello | 17:0a4bb1070fd5 | 295 | } |
lionello | 17:0a4bb1070fd5 | 296 | |
lionello | 17:0a4bb1070fd5 | 297 | // Toggle RST low to reset; CS low so it'll listen to us |
lionello | 17:0a4bb1070fd5 | 298 | pinMode(_cs, OUTPUT); |
lionello | 17:0a4bb1070fd5 | 299 | digitalWrite(_cs, LOW); |
lionello | 17:0a4bb1070fd5 | 300 | |
lionello | 17:0a4bb1070fd5 | 301 | if (_rst) { |
lionello | 17:0a4bb1070fd5 | 302 | pinMode(_rst, OUTPUT); |
lionello | 17:0a4bb1070fd5 | 303 | digitalWrite(_rst, HIGH); |
lionello | 17:0a4bb1070fd5 | 304 | delay(500); |
lionello | 17:0a4bb1070fd5 | 305 | digitalWrite(_rst, LOW); |
lionello | 17:0a4bb1070fd5 | 306 | delay(500); |
lionello | 17:0a4bb1070fd5 | 307 | digitalWrite(_rst, HIGH); |
lionello | 17:0a4bb1070fd5 | 308 | delay(500); |
lionello | 17:0a4bb1070fd5 | 309 | } |
lionello | 17:0a4bb1070fd5 | 310 | #endif |
lionello | 17:0a4bb1070fd5 | 311 | |
lionello | 17:0a4bb1070fd5 | 312 | _spi.format(8,3); |
lionello | 17:0a4bb1070fd5 | 313 | //_spi.format(9,3);// no D/C# pin |
lionello | 17:0a4bb1070fd5 | 314 | //_spi.frequency(2000000); |
lionello | 17:0a4bb1070fd5 | 315 | |
lionello | 17:0a4bb1070fd5 | 316 | _cs = 0; |
lionello | 17:0a4bb1070fd5 | 317 | _reset = 1; |
lionello | 17:0a4bb1070fd5 | 318 | wait(0.1f); |
lionello | 17:0a4bb1070fd5 | 319 | _reset = 0; |
lionello | 17:0a4bb1070fd5 | 320 | wait(0.1f); |
lionello | 17:0a4bb1070fd5 | 321 | _reset = 1; |
lionello | 17:0a4bb1070fd5 | 322 | wait(0.1f); |
lionello | 17:0a4bb1070fd5 | 323 | |
lionello | 17:0a4bb1070fd5 | 324 | // Initialization Sequence |
lionello | 17:0a4bb1070fd5 | 325 | writeCommand(SSD1351_CMD_COMMANDLOCK); // set command lock |
lionello | 17:0a4bb1070fd5 | 326 | writeData(0x12); |
lionello | 17:0a4bb1070fd5 | 327 | writeCommand(SSD1351_CMD_COMMANDLOCK); // set command lock |
lionello | 17:0a4bb1070fd5 | 328 | writeData(0xB1); |
lionello | 17:0a4bb1070fd5 | 329 | |
lionello | 17:0a4bb1070fd5 | 330 | writeCommand(SSD1351_CMD_DISPLAYOFF); // 0xAE |
lionello | 17:0a4bb1070fd5 | 331 | |
lionello | 17:0a4bb1070fd5 | 332 | writeCommand(SSD1351_CMD_CLOCKDIV); // 0xB3 |
lionello | 17:0a4bb1070fd5 | 333 | writeCommand(0xF1); // 7:4 = Oscillator Frequency, 3:0 = CLK Div Ratio (A[3:0]+1 = 1..16) |
lionello | 17:0a4bb1070fd5 | 334 | |
lionello | 17:0a4bb1070fd5 | 335 | writeCommand(SSD1351_CMD_MUXRATIO); |
lionello | 17:0a4bb1070fd5 | 336 | writeData(127); |
lionello | 17:0a4bb1070fd5 | 337 | |
lionello | 17:0a4bb1070fd5 | 338 | writeCommand(SSD1351_CMD_SETREMAP); |
lionello | 17:0a4bb1070fd5 | 339 | writeData(0x74); |
lionello | 17:0a4bb1070fd5 | 340 | |
lionello | 17:0a4bb1070fd5 | 341 | writeCommand(SSD1351_CMD_SETCOLUMN); |
lionello | 17:0a4bb1070fd5 | 342 | writeData(0x00); |
lionello | 17:0a4bb1070fd5 | 343 | writeData(0x7F); |
lionello | 17:0a4bb1070fd5 | 344 | writeCommand(SSD1351_CMD_SETROW); |
lionello | 17:0a4bb1070fd5 | 345 | writeData(0x00); |
lionello | 17:0a4bb1070fd5 | 346 | writeData(0x7F); |
lionello | 17:0a4bb1070fd5 | 347 | |
lionello | 17:0a4bb1070fd5 | 348 | writeCommand(SSD1351_CMD_STARTLINE); // 0xA1 |
lionello | 17:0a4bb1070fd5 | 349 | if (SSD1351HEIGHT == 96) { |
lionello | 17:0a4bb1070fd5 | 350 | writeData(96); |
lionello | 17:0a4bb1070fd5 | 351 | } else { |
lionello | 17:0a4bb1070fd5 | 352 | writeData(0); |
lionello | 17:0a4bb1070fd5 | 353 | } |
lionello | 17:0a4bb1070fd5 | 354 | |
lionello | 17:0a4bb1070fd5 | 355 | |
lionello | 17:0a4bb1070fd5 | 356 | writeCommand(SSD1351_CMD_DISPLAYOFFSET); // 0xA2 |
lionello | 17:0a4bb1070fd5 | 357 | writeData(0x0); |
lionello | 17:0a4bb1070fd5 | 358 | |
lionello | 17:0a4bb1070fd5 | 359 | writeCommand(SSD1351_CMD_SETGPIO); |
lionello | 17:0a4bb1070fd5 | 360 | writeData(0x00); |
lionello | 17:0a4bb1070fd5 | 361 | |
lionello | 17:0a4bb1070fd5 | 362 | writeCommand(SSD1351_CMD_FUNCTIONSELECT); |
lionello | 17:0a4bb1070fd5 | 363 | writeData(0x01); // internal (diode drop) |
lionello | 17:0a4bb1070fd5 | 364 | //writeData(0x01); // external bias |
lionello | 17:0a4bb1070fd5 | 365 | |
lionello | 17:0a4bb1070fd5 | 366 | // writeCommand(SSSD1351_CMD_SETPHASELENGTH); |
lionello | 17:0a4bb1070fd5 | 367 | // writeData(0x32); |
lionello | 17:0a4bb1070fd5 | 368 | |
lionello | 17:0a4bb1070fd5 | 369 | writeCommand(SSD1351_CMD_PRECHARGE); // 0xB1 |
lionello | 17:0a4bb1070fd5 | 370 | writeCommand(0x32); |
lionello | 17:0a4bb1070fd5 | 371 | |
lionello | 17:0a4bb1070fd5 | 372 | writeCommand(SSD1351_CMD_VCOMH); // 0xBE |
lionello | 17:0a4bb1070fd5 | 373 | writeCommand(0x05); |
lionello | 17:0a4bb1070fd5 | 374 | |
lionello | 17:0a4bb1070fd5 | 375 | writeCommand(SSD1351_CMD_NORMALDISPLAY); // 0xA6 |
lionello | 17:0a4bb1070fd5 | 376 | |
lionello | 17:0a4bb1070fd5 | 377 | writeCommand(SSD1351_CMD_CONTRASTABC); |
lionello | 17:0a4bb1070fd5 | 378 | writeData(0xC8); |
lionello | 17:0a4bb1070fd5 | 379 | writeData(0x80); |
lionello | 17:0a4bb1070fd5 | 380 | writeData(0xC8); |
lionello | 17:0a4bb1070fd5 | 381 | |
lionello | 17:0a4bb1070fd5 | 382 | writeCommand(SSD1351_CMD_CONTRASTMASTER); |
lionello | 17:0a4bb1070fd5 | 383 | writeData(0x0F); |
lionello | 17:0a4bb1070fd5 | 384 | |
lionello | 17:0a4bb1070fd5 | 385 | writeCommand(SSD1351_CMD_SETVSL ); |
lionello | 17:0a4bb1070fd5 | 386 | writeData(0xA0); |
lionello | 17:0a4bb1070fd5 | 387 | writeData(0xB5); |
lionello | 17:0a4bb1070fd5 | 388 | writeData(0x55); |
lionello | 17:0a4bb1070fd5 | 389 | |
lionello | 17:0a4bb1070fd5 | 390 | writeCommand(SSD1351_CMD_PRECHARGE2); |
lionello | 17:0a4bb1070fd5 | 391 | writeData(0x01); |
lionello | 17:0a4bb1070fd5 | 392 | |
lionello | 17:0a4bb1070fd5 | 393 | writeCommand(SSD1351_CMD_DISPLAYON); //--turn on oled panel |
lionello | 17:0a4bb1070fd5 | 394 | } |
lionello | 17:0a4bb1070fd5 | 395 | |
lionello | 17:0a4bb1070fd5 | 396 | void Adafruit_SSD1351::invert(bool v) { |
lionello | 17:0a4bb1070fd5 | 397 | if (v) { |
lionello | 17:0a4bb1070fd5 | 398 | writeCommand(SSD1351_CMD_INVERTDISPLAY); |
lionello | 17:0a4bb1070fd5 | 399 | } else { |
lionello | 17:0a4bb1070fd5 | 400 | writeCommand(SSD1351_CMD_NORMALDISPLAY); |
lionello | 17:0a4bb1070fd5 | 401 | } |
lionello | 17:0a4bb1070fd5 | 402 | } |