Adafruit-RGB_matrix_Panel(32*16)

Dependencies:   Adafruit-GFX

Revision:
8:6d98c8cd8045
Parent:
6:b594794a132e
diff -r b594794a132e -r 6d98c8cd8045 RGBmatrixPanel.cpp
--- a/RGBmatrixPanel.cpp	Sun May 25 11:40:55 2014 +0000
+++ b/RGBmatrixPanel.cpp	Sun May 25 12:02:10 2014 +0000
@@ -36,26 +36,32 @@
 // Constructor for 16x32 panel:
 RGBmatrixPanel::RGBmatrixPanel(PinName r1,PinName r2,PinName g1,PinName g2,PinName b1,PinName b2,PinName a,PinName b, PinName c, PinName sclk, PinName latch, PinName oe, bool dbuf)
     :Adafruit_GFX(32, 16),
-     _dataBus(r1,g1,b1,r2,g2,b2),
      _rowBus(a,b,c),
      _d(NC),
      _sclk(sclk),
      _latch(latch),
      _oe(oe)
 {
+    PinName pins[6] = {r1,g1,b1,r2,g2,b2};
+    for(int i=0; i<6; i++) {
+        _pin[i] = (pins[i] != NC) ? new DigitalOut(pins[i]) : 0;
+    }
     init(8, dbuf);
 }
 
 // Constructor for 32x32 panel:
 RGBmatrixPanel::RGBmatrixPanel(PinName r1,PinName r2,PinName g1,PinName g2,PinName b1,PinName b2,PinName a,PinName b,PinName c,PinName d,PinName sclk,PinName latch,PinName oe,bool dbuf)
     :Adafruit_GFX(32, 32),
-     _dataBus(r1,g1,b1,r2,g2,b2),
      _rowBus(a,b,c),
      _d(d),// Init 32x32-specific elements:
      _sclk(sclk),
      _latch(latch),
      _oe(oe)
 {
+    PinName pins[6] = {r1,g1,b1,r2,g2,b2};
+    for(int i=0; i<6; i++) {
+        _pin[i] = (pins[i] != NC) ? new DigitalOut(pins[i]) : 0;
+    }
     init(16,dbuf);
 }
 
@@ -317,6 +323,24 @@
 #endif
 
 }
+void RGBmatrixPanel::setBus(int value)
+{
+    for (int i=0; i<6; i++) {
+        if (_pin[i] != 0) {
+            _pin[i]->write((value >> i) & 1);
+        }
+    }
+}
+int RGBmatrixPanel::readBus()
+{
+    int v = 0;
+    for (int i=0; i<6; i++) {
+        if (_pin[i] != 0) {
+            v |= _pin[i]->read() << i;
+        }
+    }
+    return v;
+}
 
 void RGBmatrixPanel::updateDisplay(void)
 {
@@ -340,7 +364,7 @@
         log_debug("\tupdate row%s","\r\n");
         _rowBus.write(row);
     }
-    _dataBus=0;
+    setBus(0);
     _oe=0;
     _latch=0;
     ptr = (uint8_t *)buffptr;
@@ -352,9 +376,29 @@
         for(int i=0; i<32; i++) {
             color=*(ptr+i);
             color=(color>>2)&0x3F;
-            _dataBus.write(color);
+            setBus(color);
             _sclk=1;
             _sclk=0;
+#if 0
+#ifdef DEBUG
+            if(int(readBus)==color) {
+                log_debug(" %02x",int(_dataBus));
+            } else {
+                _dataBus=color;
+                log_debug(" (%x->%x)%s",color,int(_dataBus),"\0");
+            }
+#endif
+#endif
+        }
+        buffptr += _rawWidth;
+    } else {
+        //((ptr[i]<<4)|((ptr[i+32]<<2)&0x0C)|((ptr[i+64])&0x03));
+        for(int i=0; i<32; i++) {
+            color=0x3F&((ptr[i]<<4)|((ptr[i+32]<<2)&0x0C)|((ptr[i+64])&0x03));
+            setBus(color);
+            _sclk=1;
+            _sclk=0;
+#if 0
 #ifdef DEBUG
             if(int(_dataBus)==color) {
                 log_debug(" %02x",int(_dataBus));
@@ -363,22 +407,6 @@
                 log_debug(" (%x->%x)%s",color,int(_dataBus),"\0");
             }
 #endif
-        }
-        buffptr += _rawWidth;
-    } else {
-        //((ptr[i]<<4)|((ptr[i+32]<<2)&0x0C)|((ptr[i+64])&0x03));
-        for(int i=0; i<32; i++) {
-            color=0x3F&((ptr[i]<<4)|((ptr[i+32]<<2)&0x0C)|((ptr[i+64])&0x03));
-            _dataBus.write(color);
-            _sclk=1;
-            _sclk=0;
-#ifdef DEBUG
-            if(int(_dataBus)==color) {
-                log_debug(" %02x",int(_dataBus));
-            } else {
-                _dataBus=color;
-                log_debug(" (%x->%x)%s",color,int(_dataBus),"\0");
-            }
 #endif
         }
     }