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

Revision:
2:ecf13e85f0fa
Parent:
1:09dc95ba8711
Child:
3:0a38cff87d2e
diff -r 09dc95ba8711 -r ecf13e85f0fa Adafruit_GP9002.cpp
--- a/Adafruit_GP9002.cpp	Sun May 08 13:47:58 2016 +0000
+++ b/Adafruit_GP9002.cpp	Sun May 08 15:30:51 2016 +0000
@@ -102,6 +102,8 @@
 
   // hold the address so we can read and then write
   command(GP9002_ADDRHELD);
+  addrcache=0; //known because we just set the address
+  bytecache=0; //known because display cleared
 }
 
 
@@ -132,6 +134,7 @@
       addr += y/4;
 
   //    Serial.println(addr, HEX);  ///debug line ?
+      addrcache=-1; //invalidate the cache
       command(GP9002_ADDRINCR);
       command(GP9002_ADDRL);
       dataWrite(addr & 0xFF);
@@ -162,31 +165,34 @@
   if ((x < 0) || (x >= width()) || (y < 0) || (y >= height()))
     return;
 
-  uint8_t p;
+  //uint8_t p;
   
   // calculate addr
   uint16_t addr = 0;
   addr = x*16;
  // y = 63 - y;                //why
   addr += y/4;
-
-  command(GP9002_ADDRHELD);
-  command(GP9002_ADDRL);
-  dataWrite(addr & 0xFF);
-  command(GP9002_ADDRH);
-  dataWrite(addr >> 8);
-  command(GP9002_DATAREAD);
-  dataRead();
-  p = dataRead();
+  if (addr != addrcache)
+  {
+    addrcache=addr;
+    command(GP9002_ADDRHELD);
+    command(GP9002_ADDRL);
+    dataWrite(addr & 0xFF);
+    command(GP9002_ADDRH);
+    dataWrite(addr >> 8);
+    command(GP9002_DATAREAD);
+    dataRead();
+    bytecache = dataRead();
+  }
   y=0xc0>>((y & 3) <<1);
   color*=0b01010101;
   //Serial.println(p, HEX);
-  p &= ~y;
+  bytecache &= ~y;
 
-  p |= color&y;
+  bytecache |= color&y;
   
   command(GP9002_DATAWRITE);
-  dataWrite(p);
+  dataWrite(bytecache);
 }