add hardware SPI support
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 24 Dec 2015 10:19:44 +0000 (11:19 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 24 Dec 2015 10:19:44 +0000 (11:19 +0100)
Hub08_LedMatrix/Hub08_LedMatrix.ino
Hub08_LedMatrix/LEDMatrix.cpp

index ee96eba..f23ceaf 100644 (file)
@@ -24,8 +24,8 @@
 #define WIDTH   64
 #define HEIGHT  16
 
-// LEDMatrix(a, b, c, d, oe, r1, stb, clk);
-LEDMatrix matrix(4, 5, 6, 7, 8, 9, 10, 11);
+//     LEDMatrix(a, b, c, d, oe, r1, stb, clk);
+LEDMatrix matrix(4, 5, 6, 7, 9,  11, 10,  13);
 
 // Display Buffer 128 = 64 * 16 / 8
 uint8_t displaybuf[WIDTH * HEIGHT / 8] = {
index b3edb56..74e4fa5 100644 (file)
 #include "LEDMatrix.h"
 #include "Arduino.h"
 
+#define USE_SPI 1
+
+#if USE_SPI
+#include <SPI.h>
+#endif
+
 #if 0
 #define ASSERT(e)   if (!(e)) { Serial.println(#e); while (1); }
 #else
@@ -40,6 +46,9 @@ LEDMatrix::LEDMatrix(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t oe, uin
 
     mask = 0xff;
     state = 0;
+#if USE_SPI
+       SPI.begin();
+#endif
 }
 
 void LEDMatrix::begin(uint8_t *displaybuf, uint16_t width, uint16_t height)
@@ -136,11 +145,15 @@ void LEDMatrix::scan()
             uint8_t pixels = *ptr;
             ptr++;
             pixels = pixels ^ mask;     // reverse: mask = 0xff, normal: mask =0x00
+#if USE_SPI
+               SPI.transfer(pixels);
+#else
             for (uint8_t bit = 0; bit < 8; bit++) {
                 digitalWrite(clk, LOW);
                 digitalWrite(r1, pixels & (0x80 >> bit));
                 digitalWrite(clk, HIGH);
             }
+#endif
         }
     }