DMA-enabled high data rate driver for Heroic Robotics LED strips.

Dependents:   FastPixelDemo

Files at this revision

API Documentation at this revision

Comitter:
heroic
Date:
Tue Sep 17 00:16:18 2013 +0000
Parent:
0:1518e6eb9bde
Child:
2:ed5eb375a908
Commit message:
Make work.

Changed in this revision

LPD8806_fast.cpp Show annotated file Show diff for this revision Revisions of this file
LPD8806_fast.h Show annotated file Show diff for this revision Revisions of this file
--- a/LPD8806_fast.cpp	Mon Sep 16 23:14:52 2013 +0000
+++ b/LPD8806_fast.cpp	Tue Sep 17 00:16:18 2013 +0000
@@ -45,21 +45,18 @@
  */ 
  
 LPD8806_fast::LPD8806_fast(PinName dataPin, PinName clockPin, int n) :
-    dat(dataPin),
-    clk(clockPin) {
+    _spi(dataPin, NC, clockPin)
+ {
     // Allocate 3 bytes per pixel:
     numLEDs = n;
     pixels = (uint8_t *)malloc(numLEDs * 3);
     if (pixels) {
         memset(pixels, 0x80, numLEDs * 3); // Init to RGB 'off' state
     }
+        
+    _spi.format(8,0);
+    _spi.frequency(24000000);
     
-    data_mask = dat.get_mask();
-    clock_mask = clk.get_mask();
-    data_set = dat.get_set();
-    data_clr = dat.get_clr();
-    clock_set = clk.get_set();
-    clock_clr = clk.get_clr();
 }
 
 /*
@@ -69,75 +66,7 @@
  */
  
 inline void LPD8806_fast::write(uint8_t byte) {
-   // for (int i=0; i<8; i++) {
-    
-        (*clock_clr) = clock_mask;
-        if (byte & 0x80) {
-            (*data_set) = data_mask;
-        } else {
-            (*data_clr) = data_mask;
-        }
-        (*clock_set) = clock_mask;
-        
-        (*clock_clr) = clock_mask;
-        if (byte & 0x40) {
-            (*data_set) = data_mask;
-        } else {
-            (*data_clr) = data_mask;
-        }
-        (*clock_set) = clock_mask;
-        
-        (*clock_clr) = clock_mask;
-        if (byte & 0x20) {
-            (*data_set) = data_mask;
-        } else {
-            (*data_clr) = data_mask;
-        }
-        (*clock_set) = clock_mask;
-        
-              (*clock_clr) = clock_mask;
-        if (byte & 0x10) {
-            (*data_set) = data_mask;
-        } else {
-            (*data_clr) = data_mask;
-        }
-        (*clock_set) = clock_mask;
-        
-        (*clock_clr) = clock_mask;
-        if (byte & 0x8) {
-            (*data_set) = data_mask;
-        } else {
-            (*data_clr) = data_mask;
-        }
-        (*clock_set) = clock_mask;
-        
-        (*clock_clr) = clock_mask;
-        if (byte & 0x4) {
-            (*data_set) = data_mask;
-        } else {
-            (*data_clr) = data_mask;
-        }
-        (*clock_set) = clock_mask;
-        
-        (*clock_clr) = clock_mask;
-        if (byte & 0x2) {
-            (*data_set) = data_mask;
-        } else {
-            (*data_clr) = data_mask;
-        }
-        (*clock_set) = clock_mask;
-        
-        (*clock_clr) = clock_mask;
-        if (byte & 0x1) {
-            (*data_set) = data_mask;
-        } else {
-            (*data_clr) = data_mask;
-        }
-        (*clock_set) = clock_mask;
-        
-        
-    //}
-    //clk = 0;
+    _spi.write(byte);
 }
 
 /*
--- a/LPD8806_fast.h	Mon Sep 16 23:14:52 2013 +0000
+++ b/LPD8806_fast.h	Tue Sep 17 00:16:18 2013 +0000
@@ -37,16 +37,12 @@
   virtual uint32_t total_luminance(void);
   
  private:
-  DigitalOut dat;
-  DigitalOut clk;
+  SPI _spi;
   void write(uint8_t byte);
   uint8_t *pixels;     // Holds LED color values
   uint16_t numLEDs;     // Number of RGB LEDs in strand
   
-  __IO uint32_t *data_set;
-  __IO uint32_t *clock_set;
-  __IO uint32_t *data_clr;
-  __IO uint32_t *clock_clr;
+
   uint32_t clock_mask;
   uint32_t data_mask;