Routines to drive a chain of APA102 Leds.

Fork of APA102 by Joel Rosiene

A library to drive arrays of APA102 leds.

Files at this revision

API Documentation at this revision

Comitter:
rosienej
Date:
Sat Mar 14 20:45:03 2015 +0000
Parent:
3:bf8c63d10824
Child:
5:863fb3a71efd
Commit message:
First release with demo code

Changed in this revision

APA102a.cpp Show annotated file Show diff for this revision Revisions of this file
APA102a.h Show annotated file Show diff for this revision Revisions of this file
--- a/APA102a.cpp	Sat Mar 14 18:17:53 2015 +0000
+++ b/APA102a.cpp	Sat Mar 14 20:45:03 2015 +0000
@@ -1,17 +1,17 @@
 #include "APA102a.h"
 #include "mbed.h"
 
-APA102::APA102(PinName mosi,PinName miso,PinName sclk,int rate)
+APA102a::APA102a(PinName mosi,PinName miso,PinName sclk,int rate)
         : _spi(mosi, miso, sclk)
       
         {
             // Setup the spi for 8 bit data, high steady state clock,
-            // second edge capture, with a 1MHz clock rate
+            // second edge capture, with clock rate
             _spi.format(8,3);
             _spi.frequency(rate);
         } 
         
-void APA102::SetBuffer(unsigned int Buffer[],int Rows,int Cols, int Stride,int Offset, bool ZigZag,bool Wrap)
+void APA102a::SetBuffer(unsigned int Buffer[],int Rows,int Cols, int Stride,int Offset, bool ZigZag,bool Wrap)
 {
     Buf = Buffer;
     NR = Rows;
@@ -22,7 +22,7 @@
     WF = Wrap;
     }
     
-void APA102::Repaint()
+void APA102a::Repaint()
 {   
     int index;
     unsigned int val;
@@ -37,13 +37,13 @@
         for(int c = off;c<(NC+off);c++)
         {
             int cc = (WF)?(c%NS):((c<NS)?c:NS);
-            if (ZF) 
-               if((r&0x01)>0)
+         //   if (ZF) 
+         //     { if((r&0x01)>0)
                     index = r*NS + NC+off-cc;
-               else
-                    index = r*NS + cc;
-            else 
-                index = r*NS + cc;
+         //      else
+         //           index = r*NS + cc;}
+         //   else 
+                index = r*NS + c;
                 
             val = Buf[index];
             _spi.write((val>>24)&0xFF);  
--- a/APA102a.h	Sat Mar 14 18:17:53 2015 +0000
+++ b/APA102a.h	Sat Mar 14 20:45:03 2015 +0000
@@ -8,7 +8,7 @@
 
 /** Create an APA102 Object 
     */ 
- class APA102{
+ class APA102a{
   public:
 /** Create an APA102 object connected to the specified mosi,miso,sclk pins
     *
@@ -17,7 +17,7 @@
     * @param sclk : SPI Clock
     * @param rate : SPI Rate
     */
-     APA102(PinName mosi,PinName miso,PinName sclk,int rate);
+     APA102a(PinName mosi,PinName miso,PinName sclk,int rate);
        
 /** Set the Buffer
      *
@@ -45,8 +45,8 @@
     * @param B : 8 bits of Blue  (0,1,...,255)
     */
  
-int IRGB(unsigned char I,unsigned char R,unsigned char G,unsigned char B) {
-     return ((0xE0 + 0x1F&I)<<24)|((0xFF&R)<<16)|((0xFF&G)<<8)|(0xFF&B);}
+unsigned int IRGB(unsigned char I,unsigned char R,unsigned char G,unsigned char B) {
+     return ((0xE0 + (0x1F&I))<<24)|((0xFF&R)<<16)|((0xFF&G)<<8)|(0xFF&B);}
      
   protected: