ADAFRUIT GP9002 VFD Driver supporting grayscale display, requires GFX-Library Note no "invert" function, also fixed timing issue in "begin"
Dependencies: bitreversetable256
Fork of Adafruit-GP9002-Graphic-VFD-Library by
Diff: Adafruit_GP9002.cpp
- Revision:
- 1:09dc95ba8711
- Parent:
- 0:e760d4cfabe4
- Child:
- 2:ecf13e85f0fa
diff -r e760d4cfabe4 -r 09dc95ba8711 Adafruit_GP9002.cpp --- a/Adafruit_GP9002.cpp Sat May 07 12:53:09 2016 +0000 +++ b/Adafruit_GP9002.cpp Sun May 08 13:47:58 2016 +0000 @@ -83,18 +83,21 @@ dcpinmask = digitalPinToBitMask(_dc); */ + command(GP9002_DISPLAYSOFF); + // command(GP9002_DISPLAY1ON); //defer till display clear command(GP9002_DISPLAY); - dataWrite(GP9002_DISPLAY_MONOCHROME); + dataWrite(GP9002_DISPLAY_GRAYSCALE); command(GP9002_LOWERADDR1); dataWrite(0x0); command(GP9002_HIGHERADDR1); dataWrite(0x0); - command(GP9002_LOWERADDR2); - dataWrite(0x0); - command(GP9002_HIGHERADDR2); - dataWrite(0x4); - command(GP9002_OR); +// command(GP9002_LOWERADDR2); +// dataWrite(0x0); + // command(GP9002_HIGHERADDR2); +// dataWrite(0x4); + // command(GP9002_OR); //contradicted by display1on, so no command(GP9002_CLEARSCREEN); + wait_us(500); command(GP9002_DISPLAY1ON); // hold the address so we can read and then write @@ -112,21 +115,21 @@ //drawLine(x, orig_y, x, orig_y+h, color); return; while (h) { - if ((h >= 8) && ((orig_y) % 8 == 0)) + if ((h >= 4) && ((orig_y) % 4 == 0)) break; drawPixel(x, orig_y, color); orig_y++; h--; } - if (h >= 8) { + if (h >= 4) { // calculate addr uint16_t addr = 0; - addr = x*8; + addr = x*16; // uint16_t y = orig_y+h-8; uint16_t y=orig_y; // y = 63 - y; //why? - addr += y/8; + addr += y/4; // Serial.println(addr, HEX); ///debug line ? command(GP9002_ADDRINCR); @@ -136,14 +139,14 @@ dataWrite(addr >> 8); command(GP9002_DATAWRITE); - while (h >= 8) { + while (h >= 4) { // draw 8 pixels at once! if (color) - dataWrite(0xFF); + dataWrite(0b01010101 * (color & 3)); else dataWrite(0x00); - h -= 8; - orig_y += 8; + h -= 4; + orig_y += 4; } } while (h+1) { @@ -163,9 +166,9 @@ // calculate addr uint16_t addr = 0; - addr = x*8; + addr = x*16; // y = 63 - y; //why - addr += y/8; + addr += y/4; command(GP9002_ADDRHELD); command(GP9002_ADDRL); @@ -175,19 +178,19 @@ command(GP9002_DATAREAD); dataRead(); p = dataRead(); - + y=0xc0>>((y & 3) <<1); + color*=0b01010101; //Serial.println(p, HEX); + p &= ~y; - if (color) - p |= (1 << (7-(y % 8))); - else - p &= ~(1 << (7-(y % 8))); + p |= color&y; + command(GP9002_DATAWRITE); dataWrite(p); } - +/* forbidden void Adafruit_GP9002::invert(bool i) { // This is kinda clumsy but it does work // fill the opposite screen with all on pixels so we can invert! @@ -216,6 +219,7 @@ command(GP9002_ADDRHELD); } +*/ /* void Adafruit_GP9002::slowSPIwrite(uint8_t d) { for (uint8_t i=0; i<8; i++) { @@ -332,7 +336,7 @@ void Adafruit_GP9002::clearDisplay(void) { command(GP9002_CLEARSCREEN); - wait_ms(1); + wait_us(500); } void Adafruit_GP9002::displayOff(void) {