From: Dobrica Pavlinusic Date: Thu, 24 Dec 2015 10:19:44 +0000 (+0100) Subject: add hardware SPI support X-Git-Url: http://git.rot13.org/?p=Arduino;a=commitdiff_plain;h=ad7afe12e3eaa2a6db9426db4dfef59b0da3cfba add hardware SPI support --- diff --git a/Hub08_LedMatrix/Hub08_LedMatrix.ino b/Hub08_LedMatrix/Hub08_LedMatrix.ino index ee96eba..f23ceaf 100644 --- a/Hub08_LedMatrix/Hub08_LedMatrix.ino +++ b/Hub08_LedMatrix/Hub08_LedMatrix.ino @@ -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] = { diff --git a/Hub08_LedMatrix/LEDMatrix.cpp b/Hub08_LedMatrix/LEDMatrix.cpp index b3edb56..74e4fa5 100644 --- a/Hub08_LedMatrix/LEDMatrix.cpp +++ b/Hub08_LedMatrix/LEDMatrix.cpp @@ -21,6 +21,12 @@ #include "LEDMatrix.h" #include "Arduino.h" +#define USE_SPI 1 + +#if USE_SPI +#include +#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 } }