ADAFRUIT GP9002 VFD Driver supporting grayscale display, requires GFX-Library Note no "invert" function, also fixed timing issue in "begin"

Dependencies:   bitreversetable256

Dependents:   GP9002af_gray

Fork of Adafruit-GP9002-Graphic-VFD-Library by Oliver Broad

Committer:
oliverb
Date:
Sun May 08 15:30:51 2016 +0000
Revision:
2:ecf13e85f0fa
Parent:
1:09dc95ba8711
Child:
3:0a38cff87d2e
Caching of address and location of last byte written makes it crazy-fast for vertical-aligned drawing operations; After a pixel write any further pixel writes that land in the same display byte need only one SPI write operation to complete.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
oliverb 0:e760d4cfabe4 1 /*#include <avr/pgmspace.h>
oliverb 0:e760d4cfabe4 2 #include <util/delay.h>
oliverb 0:e760d4cfabe4 3 #include <stdlib.h>*/
oliverb 0:e760d4cfabe4 4
oliverb 0:e760d4cfabe4 5 #include "Adafruit_GFX.h"
oliverb 0:e760d4cfabe4 6 #include "Adafruit_GP9002.h"
oliverb 0:e760d4cfabe4 7 #include "glcdfont.c"
oliverb 0:e760d4cfabe4 8
oliverb 0:e760d4cfabe4 9 extern const unsigned char BitReverseTable256[] =
oliverb 0:e760d4cfabe4 10 {
oliverb 0:e760d4cfabe4 11 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
oliverb 0:e760d4cfabe4 12 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
oliverb 0:e760d4cfabe4 13 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
oliverb 0:e760d4cfabe4 14 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
oliverb 0:e760d4cfabe4 15 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
oliverb 0:e760d4cfabe4 16 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
oliverb 0:e760d4cfabe4 17 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
oliverb 0:e760d4cfabe4 18 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
oliverb 0:e760d4cfabe4 19 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
oliverb 0:e760d4cfabe4 20 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
oliverb 0:e760d4cfabe4 21 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
oliverb 0:e760d4cfabe4 22 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
oliverb 0:e760d4cfabe4 23 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
oliverb 0:e760d4cfabe4 24 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
oliverb 0:e760d4cfabe4 25 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
oliverb 0:e760d4cfabe4 26 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
oliverb 0:e760d4cfabe4 27 };
oliverb 0:e760d4cfabe4 28
oliverb 0:e760d4cfabe4 29
oliverb 0:e760d4cfabe4 30 /*
oliverb 0:e760d4cfabe4 31 Adafruit_GP9002::Adafruit_GP9002(int8_t SCLK, int8_t MISO, int8_t MOSI,
oliverb 0:e760d4cfabe4 32 int8_t CS, int8_t DC) : Adafruit_GFX(128, 64) {
oliverb 0:e760d4cfabe4 33 _sclk = SCLK;
oliverb 0:e760d4cfabe4 34 _miso = MISO;
oliverb 0:e760d4cfabe4 35 _mosi = MOSI;
oliverb 0:e760d4cfabe4 36 _cs = CS;
oliverb 0:e760d4cfabe4 37 _dc = DC;
oliverb 0:e760d4cfabe4 38 hwSPI = false;
oliverb 0:e760d4cfabe4 39 }
oliverb 0:e760d4cfabe4 40
oliverb 0:e760d4cfabe4 41 Adafruit_GP9002::Adafruit_GP9002(int8_t CS, int8_t DC) :
oliverb 0:e760d4cfabe4 42 Adafruit_GFX(128, 64) {
oliverb 0:e760d4cfabe4 43 _sclk = -1;
oliverb 0:e760d4cfabe4 44 _miso = -1;
oliverb 0:e760d4cfabe4 45 _mosi = -1;
oliverb 0:e760d4cfabe4 46 _cs = CS;
oliverb 0:e760d4cfabe4 47 _dc = DC;
oliverb 0:e760d4cfabe4 48 hwSPI = true;
oliverb 0:e760d4cfabe4 49 }
oliverb 0:e760d4cfabe4 50 */
oliverb 0:e760d4cfabe4 51 Adafruit_GP9002::Adafruit_GP9002(SPI &SPIport, PinName CS, PinName DC): Adafruit_GFX(128, 64), _spi(SPIport), _dc(DC), _cs(CS,1){} ;
oliverb 0:e760d4cfabe4 52
oliverb 0:e760d4cfabe4 53
oliverb 0:e760d4cfabe4 54 void Adafruit_GP9002::begin(void) {
oliverb 0:e760d4cfabe4 55 // set pin directions
oliverb 0:e760d4cfabe4 56 // pinMode(_dc, OUTPUT);
oliverb 0:e760d4cfabe4 57 // pinMode(_cs, OUTPUT);
oliverb 0:e760d4cfabe4 58
oliverb 0:e760d4cfabe4 59 /* if (! hwSPI) {
oliverb 0:e760d4cfabe4 60 pinMode(_mosi, OUTPUT);
oliverb 0:e760d4cfabe4 61 pinMode(_miso, INPUT);
oliverb 0:e760d4cfabe4 62 pinMode(_sclk, OUTPUT);
oliverb 0:e760d4cfabe4 63
oliverb 0:e760d4cfabe4 64 clkport = portOutputRegister(digitalPinToPort(_sclk));
oliverb 0:e760d4cfabe4 65 clkpinmask = digitalPinToBitMask(_sclk);
oliverb 0:e760d4cfabe4 66 mosiport = portOutputRegister(digitalPinToPort(_mosi));
oliverb 0:e760d4cfabe4 67 mosipinmask = digitalPinToBitMask(_mosi);
oliverb 0:e760d4cfabe4 68 misopin = portInputRegister(digitalPinToPort(_miso));
oliverb 0:e760d4cfabe4 69 misopinmask = digitalPinToBitMask(_miso);
oliverb 0:e760d4cfabe4 70 } else {
oliverb 0:e760d4cfabe4 71 */
oliverb 0:e760d4cfabe4 72 //SPI.begin();
oliverb 0:e760d4cfabe4 73 // SPI.setClockDivider(SPI_CLOCK_DIV4);
oliverb 0:e760d4cfabe4 74 // SPI.setBitOrder(MSBFIRST);
oliverb 0:e760d4cfabe4 75 //SPI.setDataMode(SPI_MODE0);
oliverb 0:e760d4cfabe4 76 _spi.format(8,3); // I'm sure this is a mode 3 device
oliverb 0:e760d4cfabe4 77 _spi.frequency(2000000); //
oliverb 0:e760d4cfabe4 78 // }
oliverb 0:e760d4cfabe4 79 /*
oliverb 0:e760d4cfabe4 80 csport = portOutputRegister(digitalPinToPort(_cs));
oliverb 0:e760d4cfabe4 81 cspinmask = digitalPinToBitMask(_cs);
oliverb 0:e760d4cfabe4 82 dcport = portOutputRegister(digitalPinToPort(_dc));
oliverb 0:e760d4cfabe4 83 dcpinmask = digitalPinToBitMask(_dc);
oliverb 0:e760d4cfabe4 84 */
oliverb 0:e760d4cfabe4 85
oliverb 1:09dc95ba8711 86 command(GP9002_DISPLAYSOFF);
oliverb 1:09dc95ba8711 87 // command(GP9002_DISPLAY1ON); //defer till display clear
oliverb 0:e760d4cfabe4 88 command(GP9002_DISPLAY);
oliverb 1:09dc95ba8711 89 dataWrite(GP9002_DISPLAY_GRAYSCALE);
oliverb 0:e760d4cfabe4 90 command(GP9002_LOWERADDR1);
oliverb 0:e760d4cfabe4 91 dataWrite(0x0);
oliverb 0:e760d4cfabe4 92 command(GP9002_HIGHERADDR1);
oliverb 0:e760d4cfabe4 93 dataWrite(0x0);
oliverb 1:09dc95ba8711 94 // command(GP9002_LOWERADDR2);
oliverb 1:09dc95ba8711 95 // dataWrite(0x0);
oliverb 1:09dc95ba8711 96 // command(GP9002_HIGHERADDR2);
oliverb 1:09dc95ba8711 97 // dataWrite(0x4);
oliverb 1:09dc95ba8711 98 // command(GP9002_OR); //contradicted by display1on, so no
oliverb 0:e760d4cfabe4 99 command(GP9002_CLEARSCREEN);
oliverb 1:09dc95ba8711 100 wait_us(500);
oliverb 0:e760d4cfabe4 101 command(GP9002_DISPLAY1ON);
oliverb 0:e760d4cfabe4 102
oliverb 0:e760d4cfabe4 103 // hold the address so we can read and then write
oliverb 0:e760d4cfabe4 104 command(GP9002_ADDRHELD);
oliverb 2:ecf13e85f0fa 105 addrcache=0; //known because we just set the address
oliverb 2:ecf13e85f0fa 106 bytecache=0; //known because display cleared
oliverb 0:e760d4cfabe4 107 }
oliverb 0:e760d4cfabe4 108
oliverb 0:e760d4cfabe4 109
oliverb 0:e760d4cfabe4 110
oliverb 0:e760d4cfabe4 111 // updated high speed drawing!
oliverb 0:e760d4cfabe4 112 void Adafruit_GP9002::drawFastVLine(int16_t x, int16_t orig_y, int16_t h, uint16_t color) {
oliverb 0:e760d4cfabe4 113 if ((x < 0) || (x >= width()) || (orig_y >= height())) return;
oliverb 0:e760d4cfabe4 114 //if ((orig_y+h) >= height())
oliverb 0:e760d4cfabe4 115 // h = height() - orig_y -1;
oliverb 0:e760d4cfabe4 116
oliverb 0:e760d4cfabe4 117 //drawLine(x, orig_y, x, orig_y+h, color); return;
oliverb 0:e760d4cfabe4 118
oliverb 0:e760d4cfabe4 119 while (h) {
oliverb 1:09dc95ba8711 120 if ((h >= 4) && ((orig_y) % 4 == 0))
oliverb 0:e760d4cfabe4 121 break;
oliverb 0:e760d4cfabe4 122 drawPixel(x, orig_y, color);
oliverb 0:e760d4cfabe4 123 orig_y++;
oliverb 0:e760d4cfabe4 124 h--;
oliverb 0:e760d4cfabe4 125 }
oliverb 0:e760d4cfabe4 126
oliverb 1:09dc95ba8711 127 if (h >= 4) {
oliverb 0:e760d4cfabe4 128 // calculate addr
oliverb 0:e760d4cfabe4 129 uint16_t addr = 0;
oliverb 1:09dc95ba8711 130 addr = x*16;
oliverb 0:e760d4cfabe4 131 // uint16_t y = orig_y+h-8;
oliverb 0:e760d4cfabe4 132 uint16_t y=orig_y;
oliverb 0:e760d4cfabe4 133 // y = 63 - y; //why?
oliverb 1:09dc95ba8711 134 addr += y/4;
oliverb 0:e760d4cfabe4 135
oliverb 0:e760d4cfabe4 136 // Serial.println(addr, HEX); ///debug line ?
oliverb 2:ecf13e85f0fa 137 addrcache=-1; //invalidate the cache
oliverb 0:e760d4cfabe4 138 command(GP9002_ADDRINCR);
oliverb 0:e760d4cfabe4 139 command(GP9002_ADDRL);
oliverb 0:e760d4cfabe4 140 dataWrite(addr & 0xFF);
oliverb 0:e760d4cfabe4 141 command(GP9002_ADDRH);
oliverb 0:e760d4cfabe4 142 dataWrite(addr >> 8);
oliverb 0:e760d4cfabe4 143 command(GP9002_DATAWRITE);
oliverb 0:e760d4cfabe4 144
oliverb 1:09dc95ba8711 145 while (h >= 4) {
oliverb 0:e760d4cfabe4 146 // draw 8 pixels at once!
oliverb 0:e760d4cfabe4 147 if (color)
oliverb 1:09dc95ba8711 148 dataWrite(0b01010101 * (color & 3));
oliverb 0:e760d4cfabe4 149 else
oliverb 0:e760d4cfabe4 150 dataWrite(0x00);
oliverb 1:09dc95ba8711 151 h -= 4;
oliverb 1:09dc95ba8711 152 orig_y += 4;
oliverb 0:e760d4cfabe4 153 }
oliverb 0:e760d4cfabe4 154 }
oliverb 0:e760d4cfabe4 155 while (h+1) {
oliverb 0:e760d4cfabe4 156 drawPixel(x, orig_y-1, color);
oliverb 0:e760d4cfabe4 157 orig_y++;
oliverb 0:e760d4cfabe4 158 h--;
oliverb 0:e760d4cfabe4 159 }
oliverb 0:e760d4cfabe4 160
oliverb 0:e760d4cfabe4 161 }
oliverb 0:e760d4cfabe4 162
oliverb 0:e760d4cfabe4 163 // the most basic function, set a single pixel
oliverb 0:e760d4cfabe4 164 void Adafruit_GP9002::drawPixel(int16_t x, int16_t y, uint16_t color) {
oliverb 0:e760d4cfabe4 165 if ((x < 0) || (x >= width()) || (y < 0) || (y >= height()))
oliverb 0:e760d4cfabe4 166 return;
oliverb 0:e760d4cfabe4 167
oliverb 2:ecf13e85f0fa 168 //uint8_t p;
oliverb 0:e760d4cfabe4 169
oliverb 0:e760d4cfabe4 170 // calculate addr
oliverb 0:e760d4cfabe4 171 uint16_t addr = 0;
oliverb 1:09dc95ba8711 172 addr = x*16;
oliverb 0:e760d4cfabe4 173 // y = 63 - y; //why
oliverb 1:09dc95ba8711 174 addr += y/4;
oliverb 2:ecf13e85f0fa 175 if (addr != addrcache)
oliverb 2:ecf13e85f0fa 176 {
oliverb 2:ecf13e85f0fa 177 addrcache=addr;
oliverb 2:ecf13e85f0fa 178 command(GP9002_ADDRHELD);
oliverb 2:ecf13e85f0fa 179 command(GP9002_ADDRL);
oliverb 2:ecf13e85f0fa 180 dataWrite(addr & 0xFF);
oliverb 2:ecf13e85f0fa 181 command(GP9002_ADDRH);
oliverb 2:ecf13e85f0fa 182 dataWrite(addr >> 8);
oliverb 2:ecf13e85f0fa 183 command(GP9002_DATAREAD);
oliverb 2:ecf13e85f0fa 184 dataRead();
oliverb 2:ecf13e85f0fa 185 bytecache = dataRead();
oliverb 2:ecf13e85f0fa 186 }
oliverb 1:09dc95ba8711 187 y=0xc0>>((y & 3) <<1);
oliverb 1:09dc95ba8711 188 color*=0b01010101;
oliverb 0:e760d4cfabe4 189 //Serial.println(p, HEX);
oliverb 2:ecf13e85f0fa 190 bytecache &= ~y;
oliverb 0:e760d4cfabe4 191
oliverb 2:ecf13e85f0fa 192 bytecache |= color&y;
oliverb 1:09dc95ba8711 193
oliverb 0:e760d4cfabe4 194 command(GP9002_DATAWRITE);
oliverb 2:ecf13e85f0fa 195 dataWrite(bytecache);
oliverb 0:e760d4cfabe4 196 }
oliverb 0:e760d4cfabe4 197
oliverb 0:e760d4cfabe4 198
oliverb 1:09dc95ba8711 199 /* forbidden
oliverb 0:e760d4cfabe4 200 void Adafruit_GP9002::invert(bool i) {
oliverb 0:e760d4cfabe4 201 // This is kinda clumsy but it does work
oliverb 0:e760d4cfabe4 202 // fill the opposite screen with all on pixels so we can invert!
oliverb 0:e760d4cfabe4 203 uint16_t addr = 0x400;
oliverb 0:e760d4cfabe4 204
oliverb 0:e760d4cfabe4 205 command(GP9002_ADDRINCR);
oliverb 0:e760d4cfabe4 206 command(GP9002_ADDRL);
oliverb 0:e760d4cfabe4 207 dataWrite(addr & 0xFF);
oliverb 0:e760d4cfabe4 208 command(GP9002_ADDRH);
oliverb 0:e760d4cfabe4 209 dataWrite(addr >> 8);
oliverb 0:e760d4cfabe4 210 command(GP9002_DATAWRITE);
oliverb 0:e760d4cfabe4 211
oliverb 0:e760d4cfabe4 212 if (i) {
oliverb 0:e760d4cfabe4 213 while (addr < 0x0800) {
oliverb 0:e760d4cfabe4 214 dataWrite(0xFF);
oliverb 0:e760d4cfabe4 215 addr++;
oliverb 0:e760d4cfabe4 216 }
oliverb 0:e760d4cfabe4 217 command(GP9002_XOR);
oliverb 0:e760d4cfabe4 218 } else {
oliverb 0:e760d4cfabe4 219 while (addr < 0x0800) {
oliverb 0:e760d4cfabe4 220 dataWrite(0x00);
oliverb 0:e760d4cfabe4 221 addr++;
oliverb 0:e760d4cfabe4 222 }
oliverb 0:e760d4cfabe4 223 command(GP9002_OR);
oliverb 0:e760d4cfabe4 224 }
oliverb 0:e760d4cfabe4 225 command(GP9002_ADDRHELD);
oliverb 0:e760d4cfabe4 226
oliverb 0:e760d4cfabe4 227 }
oliverb 1:09dc95ba8711 228 */
oliverb 0:e760d4cfabe4 229 /*
oliverb 0:e760d4cfabe4 230 void Adafruit_GP9002::slowSPIwrite(uint8_t d) {
oliverb 0:e760d4cfabe4 231 for (uint8_t i=0; i<8; i++) {
oliverb 0:e760d4cfabe4 232 digitalWrite(_sclk, LOW);
oliverb 0:e760d4cfabe4 233 if (d & _BV(i)) {
oliverb 0:e760d4cfabe4 234 digitalWrite(_mosi, HIGH);
oliverb 0:e760d4cfabe4 235 } else {
oliverb 0:e760d4cfabe4 236 digitalWrite(_mosi, LOW);
oliverb 0:e760d4cfabe4 237 }
oliverb 0:e760d4cfabe4 238 digitalWrite(_sclk, HIGH);
oliverb 0:e760d4cfabe4 239 }
oliverb 0:e760d4cfabe4 240 }
oliverb 0:e760d4cfabe4 241 */
oliverb 0:e760d4cfabe4 242 /*
oliverb 0:e760d4cfabe4 243 inline void Adafruit_GP9002::fastSPIwrite(uint8_t d) {
oliverb 0:e760d4cfabe4 244 if (hwSPI) {
oliverb 0:e760d4cfabe4 245 SPDR = d;
oliverb 0:e760d4cfabe4 246 while(!(SPSR & _BV(SPIF)));
oliverb 0:e760d4cfabe4 247 return;
oliverb 0:e760d4cfabe4 248 }
oliverb 0:e760d4cfabe4 249 for(uint8_t bit = 0x1; bit != 0x00; bit <<= 1) {
oliverb 0:e760d4cfabe4 250 *clkport &= ~clkpinmask;
oliverb 0:e760d4cfabe4 251 if(d & bit) *mosiport |= mosipinmask;
oliverb 0:e760d4cfabe4 252 else *mosiport &= ~mosipinmask;
oliverb 0:e760d4cfabe4 253 *clkport |= clkpinmask;
oliverb 0:e760d4cfabe4 254 }
oliverb 0:e760d4cfabe4 255 }
oliverb 0:e760d4cfabe4 256 */
oliverb 0:e760d4cfabe4 257 /*
oliverb 0:e760d4cfabe4 258 uint8_t Adafruit_GP9002::slowSPIread(void) {
oliverb 0:e760d4cfabe4 259 uint8_t reply = 0;
oliverb 0:e760d4cfabe4 260 for (uint8_t i=0; i<8; i++) {
oliverb 0:e760d4cfabe4 261 digitalWrite(_sclk, LOW);
oliverb 0:e760d4cfabe4 262
oliverb 0:e760d4cfabe4 263 digitalWrite(_sclk, HIGH);
oliverb 0:e760d4cfabe4 264 if (digitalRead(_miso))
oliverb 0:e760d4cfabe4 265 reply |= _BV(i);
oliverb 0:e760d4cfabe4 266 }
oliverb 0:e760d4cfabe4 267 return reply;
oliverb 0:e760d4cfabe4 268 }
oliverb 0:e760d4cfabe4 269
oliverb 0:e760d4cfabe4 270 inline uint8_t Adafruit_GP9002::fastSPIread(void) {
oliverb 0:e760d4cfabe4 271 uint8_t reply = 0;
oliverb 0:e760d4cfabe4 272 for (uint8_t i=0; i<8; i++) {
oliverb 0:e760d4cfabe4 273 *clkport &= ~clkpinmask;
oliverb 0:e760d4cfabe4 274
oliverb 0:e760d4cfabe4 275 *clkport |= clkpinmask;
oliverb 0:e760d4cfabe4 276 if ((*misopin) & misopinmask)
oliverb 0:e760d4cfabe4 277 reply |= _BV(i);
oliverb 0:e760d4cfabe4 278 }
oliverb 0:e760d4cfabe4 279 return reply;
oliverb 0:e760d4cfabe4 280 }
oliverb 0:e760d4cfabe4 281 */
oliverb 0:e760d4cfabe4 282
oliverb 0:e760d4cfabe4 283 void Adafruit_GP9002::command(uint8_t d) {
oliverb 0:e760d4cfabe4 284 /*
oliverb 0:e760d4cfabe4 285 *dcport |= dcpinmask;
oliverb 0:e760d4cfabe4 286 *csport &= ~cspinmask;
oliverb 0:e760d4cfabe4 287 fastSPIwrite(d);
oliverb 0:e760d4cfabe4 288 *csport |= cspinmask;
oliverb 0:e760d4cfabe4 289 delayMicroseconds(1); // should be 400ns actually
oliverb 0:e760d4cfabe4 290 */
oliverb 0:e760d4cfabe4 291 _dc=1;
oliverb 0:e760d4cfabe4 292 _cs=0;
oliverb 0:e760d4cfabe4 293 _spi.write(BitReverseTable256[d]);
oliverb 0:e760d4cfabe4 294 _cs=1;
oliverb 0:e760d4cfabe4 295 wait_us(1);
oliverb 0:e760d4cfabe4 296 }
oliverb 0:e760d4cfabe4 297
oliverb 0:e760d4cfabe4 298 inline void Adafruit_GP9002::dataWrite(uint8_t d) {
oliverb 0:e760d4cfabe4 299 /*
oliverb 0:e760d4cfabe4 300 *dcport &= ~dcpinmask;
oliverb 0:e760d4cfabe4 301 *csport &= ~cspinmask;
oliverb 0:e760d4cfabe4 302
oliverb 0:e760d4cfabe4 303 fastSPIwrite(d);
oliverb 0:e760d4cfabe4 304
oliverb 0:e760d4cfabe4 305 *csport |= cspinmask;
oliverb 0:e760d4cfabe4 306 delayMicroseconds(1); // should be 600ns actually
oliverb 0:e760d4cfabe4 307 */
oliverb 0:e760d4cfabe4 308 _dc=0;
oliverb 0:e760d4cfabe4 309 _cs=0;
oliverb 0:e760d4cfabe4 310 _spi.write(BitReverseTable256[d]);
oliverb 0:e760d4cfabe4 311 _cs=1;
oliverb 0:e760d4cfabe4 312 wait_us(1);
oliverb 0:e760d4cfabe4 313 }
oliverb 0:e760d4cfabe4 314
oliverb 0:e760d4cfabe4 315 inline uint8_t Adafruit_GP9002::dataRead() {
oliverb 0:e760d4cfabe4 316 uint8_t r;
oliverb 0:e760d4cfabe4 317 /*
oliverb 0:e760d4cfabe4 318 *dcport &= ~dcpinmask;
oliverb 0:e760d4cfabe4 319 *csport &= ~cspinmask;
oliverb 0:e760d4cfabe4 320
oliverb 0:e760d4cfabe4 321 r = fastSPIread();
oliverb 0:e760d4cfabe4 322
oliverb 0:e760d4cfabe4 323 *csport |= cspinmask;
oliverb 0:e760d4cfabe4 324 delayMicroseconds(1);
oliverb 0:e760d4cfabe4 325 */
oliverb 0:e760d4cfabe4 326
oliverb 0:e760d4cfabe4 327 _dc=0;
oliverb 0:e760d4cfabe4 328 _cs=0;
oliverb 0:e760d4cfabe4 329 r=BitReverseTable256[_spi.write(0)&0xFF];
oliverb 0:e760d4cfabe4 330 _cs=1;
oliverb 0:e760d4cfabe4 331 wait_us(1);
oliverb 0:e760d4cfabe4 332
oliverb 0:e760d4cfabe4 333
oliverb 0:e760d4cfabe4 334 return r;
oliverb 0:e760d4cfabe4 335 }
oliverb 0:e760d4cfabe4 336
oliverb 0:e760d4cfabe4 337 void Adafruit_GP9002::setBrightness(uint8_t val) {
oliverb 0:e760d4cfabe4 338
oliverb 0:e760d4cfabe4 339 }
oliverb 0:e760d4cfabe4 340
oliverb 0:e760d4cfabe4 341 // clear everything
oliverb 0:e760d4cfabe4 342 void Adafruit_GP9002::clearDisplay(void) {
oliverb 0:e760d4cfabe4 343 command(GP9002_CLEARSCREEN);
oliverb 0:e760d4cfabe4 344
oliverb 1:09dc95ba8711 345 wait_us(500);
oliverb 0:e760d4cfabe4 346 }
oliverb 0:e760d4cfabe4 347
oliverb 0:e760d4cfabe4 348 void Adafruit_GP9002::displayOff(void) {
oliverb 0:e760d4cfabe4 349 command(GP9002_DISPLAYSOFF);
oliverb 0:e760d4cfabe4 350 }
oliverb 0:e760d4cfabe4 351 void Adafruit_GP9002::displayOn(void) {
oliverb 0:e760d4cfabe4 352 command(GP9002_DISPLAY1ON);
oliverb 0:e760d4cfabe4 353 }
oliverb 0:e760d4cfabe4 354
oliverb 0:e760d4cfabe4 355