|
| 1 | +/********************************************************************* |
| 2 | +This is a library for our Monochrome OLEDs based on SSD1325 drivers |
| 3 | +
|
| 4 | + Pick one up today in the adafruit shop! |
| 5 | + ------> http://www.adafruit.com/category/63_98 |
| 6 | +
|
| 7 | +These displays use SPI to communicate, 4 or 5 pins are required to |
| 8 | +interface |
| 9 | +
|
| 10 | +Adafruit invests time and resources providing this open source code, |
| 11 | +please support Adafruit and open-source hardware by purchasing |
| 12 | +products from Adafruit! |
| 13 | +
|
| 14 | +Written by Limor Fried/Ladyada for Adafruit Industries. |
| 15 | +BSD license, check license.txt for more information |
| 16 | +All text above, and the splash screen below must be included in any redistribution |
| 17 | +*********************************************************************/ |
| 18 | + |
| 19 | +//#include <Wire.h> |
| 20 | +#include <avr/pgmspace.h> |
| 21 | +#include <util/delay.h> |
| 22 | +#include <stdlib.h> |
| 23 | + |
| 24 | +#include "Adafruit_GFX.h" |
| 25 | +#include "Adafruit_SSD1325.h" |
| 26 | + |
| 27 | +#include "glcdfont.c" |
| 28 | + |
| 29 | +// a 5x7 font table |
| 30 | +extern uint8_t PROGMEM font[]; |
| 31 | + |
| 32 | +// the memory buffer for the LCD |
| 33 | + |
| 34 | +static uint8_t buffer[SSD1325_LCDHEIGHT * SSD1325_LCDWIDTH / 8] = { |
| 35 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 36 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 37 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 38 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, |
| 39 | +0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 40 | +0x00, 0x80, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 41 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 42 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 43 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 44 | +0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00, |
| 45 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, |
| 46 | +0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0xFF, |
| 47 | +0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, |
| 48 | +0x80, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x80, 0x80, |
| 49 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x8C, 0x8E, 0x84, 0x00, 0x00, 0x80, 0xF8, |
| 50 | +0xF8, 0xF8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 51 | +0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, |
| 52 | +0x00, 0xE0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, |
| 53 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xC7, 0x01, 0x01, |
| 54 | +0x01, 0x01, 0x83, 0xFF, 0xFF, 0x00, 0x00, 0x7C, 0xFE, 0xC7, 0x01, 0x01, 0x01, 0x01, 0x83, 0xFF, |
| 55 | +0xFF, 0xFF, 0x00, 0x38, 0xFE, 0xC7, 0x83, 0x01, 0x01, 0x01, 0x83, 0xC7, 0xFF, 0xFF, 0x00, 0x00, |
| 56 | +0x01, 0xFF, 0xFF, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0x07, 0x01, 0x01, 0x01, 0x00, 0x00, 0x7F, 0xFF, |
| 57 | +0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0xFF, |
| 58 | +0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 59 | +0x03, 0x0F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x8F, |
| 60 | +0x8F, 0x9F, 0xBF, 0xFF, 0xFF, 0xC3, 0xC0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC, |
| 61 | +0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x01, 0x03, 0x03, 0x03, |
| 62 | +0x03, 0x03, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, |
| 63 | +0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x00, 0x00, |
| 64 | +0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, |
| 65 | +0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0x03, |
| 66 | +0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 67 | +#if (SSD1325_LCDHEIGHT == 64) |
| 68 | +0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x1F, 0x0F, |
| 69 | +0x87, 0xC7, 0xF7, 0xFF, 0xFF, 0x1F, 0x1F, 0x3D, 0xFC, 0xF8, 0xF8, 0xF8, 0xF8, 0x7C, 0x7D, 0xFF, |
| 70 | +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x00, 0x30, 0x30, 0x00, 0x00, |
| 71 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 72 | +0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 73 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xC0, 0x00, |
| 74 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, |
| 75 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 76 | +0x00, 0xC0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x1F, |
| 77 | +0x0F, 0x07, 0x1F, 0x7F, 0xFF, 0xFF, 0xF8, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xE0, |
| 78 | +0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, |
| 79 | +0x00, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0xF0, 0xF8, 0x1C, 0x0E, |
| 80 | +0x06, 0x06, 0x06, 0x0C, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xFC, |
| 81 | +0xFE, 0xFC, 0x00, 0x18, 0x3C, 0x7E, 0x66, 0xE6, 0xCE, 0x84, 0x00, 0x00, 0x06, 0xFF, 0xFF, 0x06, |
| 82 | +0x06, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x06, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0xC0, 0xF8, |
| 83 | +0xFC, 0x4E, 0x46, 0x46, 0x46, 0x4E, 0x7C, 0x78, 0x40, 0x18, 0x3C, 0x76, 0xE6, 0xCE, 0xCC, 0x80, |
| 84 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 85 | +0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F, 0x1F, 0x0F, 0x03, |
| 86 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, |
| 87 | +0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x03, 0x07, 0x0E, 0x0C, |
| 88 | +0x18, 0x18, 0x0C, 0x06, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x01, 0x0F, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, |
| 89 | +0x07, 0x01, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, |
| 90 | +0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x07, |
| 91 | +0x07, 0x0C, 0x0C, 0x18, 0x1C, 0x0C, 0x06, 0x06, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, |
| 92 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 93 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 94 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 95 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 96 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 97 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 98 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 99 | +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 100 | +#endif |
| 101 | +}; |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | +// the most basic function, set a single pixel |
| 106 | +void Adafruit_SSD1325::drawPixel(uint16_t x, uint16_t y, uint16_t color) { |
| 107 | + if ((x >= width()) || (y >= height())) |
| 108 | + return; |
| 109 | + |
| 110 | + // check rotation, move pixel around if necessary |
| 111 | + switch (getRotation()) { |
| 112 | + case 1: |
| 113 | + swap(x, y); |
| 114 | + x = WIDTH - x - 1; |
| 115 | + break; |
| 116 | + case 2: |
| 117 | + x = WIDTH - x - 1; |
| 118 | + y = HEIGHT - y - 1; |
| 119 | + break; |
| 120 | + case 3: |
| 121 | + swap(x, y); |
| 122 | + y = HEIGHT - y - 1; |
| 123 | + break; |
| 124 | + } |
| 125 | + |
| 126 | + // x is which column |
| 127 | + if (color == WHITE) |
| 128 | + buffer[x+ (y/8)*SSD1325_LCDWIDTH] |= _BV((y%8)); |
| 129 | + else |
| 130 | + buffer[x+ (y/8)*SSD1325_LCDWIDTH] &= ~_BV((y%8)); |
| 131 | +} |
| 132 | + |
| 133 | +void Adafruit_SSD1325::begin(void) { |
| 134 | + constructor(128, 64); |
| 135 | + |
| 136 | + // set pin directions |
| 137 | + pinMode(sid, OUTPUT); |
| 138 | + pinMode(sclk, OUTPUT); |
| 139 | + pinMode(dc, OUTPUT); |
| 140 | + pinMode(rst, OUTPUT); |
| 141 | + pinMode(cs, OUTPUT); |
| 142 | + |
| 143 | + clkport = portOutputRegister(digitalPinToPort(sclk)); |
| 144 | + clkpinmask = digitalPinToBitMask(sclk); |
| 145 | + mosiport = portOutputRegister(digitalPinToPort(sid)); |
| 146 | + mosipinmask = digitalPinToBitMask(sid); |
| 147 | + csport = portOutputRegister(digitalPinToPort(cs)); |
| 148 | + cspinmask = digitalPinToBitMask(cs); |
| 149 | + dcport = portOutputRegister(digitalPinToPort(dc)); |
| 150 | + dcpinmask = digitalPinToBitMask(dc); |
| 151 | + |
| 152 | + digitalWrite(rst, HIGH); |
| 153 | + // VDD (3.3V) goes high at start, lets just chill for a ms |
| 154 | + delay(1); |
| 155 | + // bring reset low |
| 156 | + digitalWrite(rst, LOW); |
| 157 | + // wait 10ms |
| 158 | + delay(10); |
| 159 | + // bring out of reset |
| 160 | + digitalWrite(rst, HIGH); |
| 161 | + |
| 162 | + command(SSD1325_DISPLAYOFF); /* display off */ |
| 163 | + command(SSD1325_SETCLOCK); /* set osc division */ |
| 164 | + command(0x91); /*145 */ |
| 165 | + command(SSD1325_SETMULTIPLEX ); /* multiplex ratio */ |
| 166 | + command(0x3f); /* duty = 1/64 */ |
| 167 | + command( SSD1325_SETOFFSET); /* set display offset --- */ |
| 168 | + command(0x4C); /* 76 */ |
| 169 | + command(SSD1325_SETSTARTLINE); /*set start line */ |
| 170 | + command(0x00); /* ------ */ |
| 171 | + command(SSD1325_MASTERCONFIG); /*Set Master Config DC/DC Converter*/ |
| 172 | + command(0x02); |
| 173 | + command(SSD1325_SETREMAP); /* set segment remap------ */ |
| 174 | + command(0x56); |
| 175 | + //command(0x52); |
| 176 | + command(SSD1325_SETCURRENT + 0x2); /* Set Full Current Range */ |
| 177 | + command(SSD1325_SETGRAYTABLE); |
| 178 | + command(0x01); |
| 179 | + command(0x11); |
| 180 | + command(0x22); |
| 181 | + command(0x32); |
| 182 | + command(0x43); |
| 183 | + command(0x54); |
| 184 | + command(0x65); |
| 185 | + command(0x76); |
| 186 | + |
| 187 | + command(SSD1325_SETCONTRAST); /* set contrast current */ |
| 188 | + command(0x7F); |
| 189 | + command(SSD1325_SETROWPERIOD); |
| 190 | + command(0x51); |
| 191 | + command(SSD1325_SETPHASELEN); |
| 192 | + command(0x55); |
| 193 | + command(SSD1325_SETPRECHARGECOMP); |
| 194 | + command(0x02); |
| 195 | + command(SSD1325_SETPRECHARGECOMPENABLE); |
| 196 | + command(0x28); |
| 197 | + command(SSD1325_SETVCOMLEVEL); /* Set High Voltage Level of COM Pin */ |
| 198 | + command(0x1C); //? |
| 199 | + command(SSD1325_SETVSL); /*set Low Voltage Level of SEG Pin */ |
| 200 | + command(0x0D|0x02); |
| 201 | + command(SSD1325_DISPLAYALLON); |
| 202 | + delay(200); |
| 203 | + command(SSD1325_NORMALDISPLAY); /* set display mode */ |
| 204 | + /* Clear Screen */ |
| 205 | + |
| 206 | + // command(0x23); /*set graphic acceleration commmand */ |
| 207 | + // command(SSD1325_GFXACCEL); |
| 208 | + // command(SSD1325_DRAWRECT); /* draw rectangle */ |
| 209 | + // command(0x00); /* Gray Scale Level 1 */ |
| 210 | + // command(0x00); /* Gray Scale Level 3 & 2 */ |
| 211 | + // command(0x3f); /* Gray Scale Level 3 & 2 */ |
| 212 | + // command(0x3f); /* Gray Scale Level 3 & 2 */ |
| 213 | + // command(0x00); /* Gray Scale Level 3 & 2 */ |
| 214 | + |
| 215 | + command(SSD1325_DISPLAYON); /* display ON */ |
| 216 | +} |
| 217 | + |
| 218 | +void Adafruit_SSD1325::invertDisplay(uint8_t i) { |
| 219 | + if (i) { |
| 220 | + command(SSD1325_INVERTDISPLAY); |
| 221 | + } else { |
| 222 | + command(SSD1325_NORMALDISPLAY); |
| 223 | + } |
| 224 | +} |
| 225 | + |
| 226 | +void Adafruit_SSD1325::command(uint8_t c) { |
| 227 | + //digitalWrite(cs, HIGH); |
| 228 | + *csport |= cspinmask; |
| 229 | + //digitalWrite(dc, LOW); |
| 230 | + *dcport &= ~dcpinmask; |
| 231 | + //digitalWrite(cs, LOW); |
| 232 | + *csport &= ~cspinmask; |
| 233 | + fastSPIwrite(c); |
| 234 | + //digitalWrite(cs, HIGH); |
| 235 | + *csport |= cspinmask; |
| 236 | +} |
| 237 | + |
| 238 | +void Adafruit_SSD1325::data(uint8_t c) { |
| 239 | + //digitalWrite(cs, HIGH); |
| 240 | + *csport |= cspinmask; |
| 241 | + //digitalWrite(dc, HIGH); |
| 242 | + *dcport |= dcpinmask; |
| 243 | + //digitalWrite(cs, LOW); |
| 244 | + *csport &= ~cspinmask; |
| 245 | + fastSPIwrite(c); |
| 246 | + //digitalWrite(cs, HIGH); |
| 247 | + *csport |= cspinmask; |
| 248 | +} |
| 249 | + |
| 250 | +void Adafruit_SSD1325::display(void) { |
| 251 | + |
| 252 | + command(0x15); /* set column address */ |
| 253 | + command(0x00); /* set column start address */ |
| 254 | + command(0x3f); /* set column end address */ |
| 255 | + command(0x75); /* set row address */ |
| 256 | + command(0x00); /* set row start address */ |
| 257 | + command(0x3f); /* set row end address */ |
| 258 | + uint8_t foo=0; |
| 259 | + |
| 260 | + for (uint8_t x=0; x<128; x+=2) { |
| 261 | + uint8_t foo = x; |
| 262 | + for (uint8_t y=0; y<64; y+=8) { // we write 8 pixels at once |
| 263 | + uint8_t d = 0; |
| 264 | + uint8_t left8 = buffer[y*8+x]; |
| 265 | + uint8_t right8 = buffer[y*8+x+1]; |
| 266 | + for (uint8_t p=0; p<8; p++) { |
| 267 | + uint8_t d = 0; |
| 268 | + if (left8 & (1 << p)) d |= 0xF0; |
| 269 | + if (right8 & (1 << p)) d |= 0x0F; |
| 270 | + data(d); |
| 271 | + } |
| 272 | + } |
| 273 | + } |
| 274 | + return; |
| 275 | + |
| 276 | + for(uint8_t x=0; x<128; x+=2) |
| 277 | + { |
| 278 | + foo++; |
| 279 | + for (uint8_t y=0; y<16; y++) { |
| 280 | + uint8_t d = 0; |
| 281 | + uint8_t left8 = buffer[y*64+x]; |
| 282 | + uint8_t right8 = buffer[y*64+x+1]; |
| 283 | + left8 = 0; |
| 284 | + right8 = foo; |
| 285 | + for (uint8_t p=0; p<8; p++) { |
| 286 | + uint8_t d = 0; |
| 287 | + if (left8 & (1 << p)) d |= 0xF0; |
| 288 | + if (right8 & (1 << p)) d |= 0x0F; |
| 289 | + data(d); |
| 290 | + } |
| 291 | + } |
| 292 | + } |
| 293 | +} |
| 294 | + |
| 295 | +// clear everything |
| 296 | +void Adafruit_SSD1325::clearDisplay(void) { |
| 297 | + memset(buffer, 0, (SSD1325_LCDWIDTH*SSD1325_LCDHEIGHT/8)); |
| 298 | +} |
| 299 | + |
| 300 | + |
| 301 | +inline void Adafruit_SSD1325::fastSPIwrite(uint8_t d) { |
| 302 | + |
| 303 | + for(uint8_t bit = 0x80; bit; bit >>= 1) { |
| 304 | + *clkport &= ~clkpinmask; |
| 305 | + if(d & bit) *mosiport |= mosipinmask; |
| 306 | + else *mosiport &= ~mosipinmask; |
| 307 | + *clkport |= clkpinmask; |
| 308 | + } |
| 309 | + //*csport |= cspinmask; |
| 310 | +} |
| 311 | + |
| 312 | +inline void Adafruit_SSD1325::slowSPIwrite(uint8_t d) { |
| 313 | + for (int8_t i=7; i>=0; i--) { |
| 314 | + digitalWrite(sclk, LOW); |
| 315 | + if (d & _BV(i)) { |
| 316 | + digitalWrite(sid, HIGH); |
| 317 | + } else { |
| 318 | + digitalWrite(sid, LOW); |
| 319 | + } |
| 320 | + digitalWrite(sclk, HIGH); |
| 321 | + } |
| 322 | +} |
| 323 | + |
0 commit comments