Library for LPD8806 (and probably LPD8803/LPD8809) PWM LED driver chips, strips and pixels. Standard connected to 1st hardware SPI module. Data -> p5 and Clock -> p7 use a fixed sized buffer rather than malloc - if we use malloc rtos is unhappy...

Fork of LPD8806 by Jelmer Tiete

Files at this revision

API Documentation at this revision

Comitter:
Jasper
Date:
Fri May 30 03:37:16 2014 +0000
Parent:
1:6ebd3ac910b6
Commit message:
use a static buffer rather than using malloc - for some reason the malloc memory is somewhere that clashes with the RTOS/Ethernet/Internet stuff, don't know why...

Changed in this revision

LPD8806.cpp Show annotated file Show diff for this revision Revisions of this file
LPD8806.h Show annotated file Show diff for this revision Revisions of this file
diff -r 6ebd3ac910b6 -r 5d654eba3240 LPD8806.cpp
--- a/LPD8806.cpp	Fri Dec 16 10:26:35 2011 +0000
+++ b/LPD8806.cpp	Fri May 30 03:37:16 2014 +0000
@@ -20,10 +20,17 @@
 
 LPD8806::LPD8806(uint16_t n) {
     // Allocate 3 bytes per pixel:
-    if (NULL != (pixels = (uint8_t *)malloc(numLEDs * 3))) {
+//    if (NULL != (pixels = (uint8_t *)malloc(numLEDs * 3))) {
         memset(pixels, 0x80, numLEDs * 3); // Init to RGB 'off' state
         numLEDs     = n;
-    }
+//    }
+}
+
+int LPD8806::pixels_ok(void) {
+    if (pixels != NULL)
+        return 1;
+    else
+        return 0;
 }
 
 void LPD8806::begin(void) {
@@ -61,7 +68,7 @@
 
     // We need to have a delay here, a few ms seems to do the job
     // shorter may be OK as well - need to experiment :(
-// wait_ms(3);
+    wait_ms(3);
 }
 
 // Convert R,G,B to combined 32-bit color
@@ -76,15 +83,15 @@
 void LPD8806::setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b) {
     if (n >= numLEDs) return; // '>=' because arrays are 0-indexed
 
-    pixels[n*3  ] = g | 0x80;
-    pixels[n*3+1] = r | 0x80;
-    pixels[n*3+2] = b | 0x80;
+    pixels[(n * 3)    ] = g | 0x80;
+    pixels[(n * 3) +1 ] = r | 0x80;
+    pixels[(n * 3) +2 ] = b | 0x80;
 }
 
 void LPD8806::setPixelColor(uint16_t n, uint32_t c) {
     if (n >= numLEDs) return; // '>=' because arrays are 0-indexed
 
-    pixels[n*3  ] = (c >> 16) | 0x80;
-    pixels[n*3+1] = (c >>  8) | 0x80;
-    pixels[n*3+2] =  c        | 0x80;
+    pixels[(n * 3)    ] = ((c >> 16) & 0xff)| 0x80;
+    pixels[(n * 3) + 1] = ((c >>  8) & 0xff)| 0x80;
+    pixels[(n * 3) + 2] = ( c        & 0xff)| 0x80;
 }
diff -r 6ebd3ac910b6 -r 5d654eba3240 LPD8806.h
--- a/LPD8806.h	Fri Dec 16 10:26:35 2011 +0000
+++ b/LPD8806.h	Fri May 30 03:37:16 2014 +0000
@@ -20,6 +20,8 @@
  public:
 
   LPD8806(uint16_t n);
+  int
+    pixels_ok(void);
   void
     begin(void),
     show(void),
@@ -33,7 +35,7 @@
  private:
 
   uint8_t
-    *pixels;     // Holds LED color values
+    pixels[32 * 3];     // Holds LED color values
   uint16_t
     numLEDs;     // Number of RGB LEDs in strand