LED bus driver on any GPIO pin for addressable RGB LEDs (like NeoPixels or other WS2812 based LEDs)

Revision:
2:735bb1b9cfc2
Parent:
0:1e68c70236a4
Child:
3:67e68c46daef
--- a/LEDBus.h	Tue May 10 20:22:18 2016 +0000
+++ b/LEDBus.h	Wed Jun 14 19:51:33 2017 +0000
@@ -1,66 +1,18 @@
-#ifndef _LED_BUS_H_
-#define _LED_BUS_H_
+#ifndef _LED_BUS_PIN_H_
+#define _LED_BUS_PIN_H_
 
 #include "mbed.h"
+#include "Color.h"
 
 #define MICRO_SECOND 1000000.f
 
-/**
-    RGB Color
-*/
-struct Color {
-    
-    /**
-        Constructor with rgb initializing
-    
-        @param r - the red byte
-        @param g - the green byte
-        @param b - the blue byte
-    */
-    Color(uint8_t r, uint8_t g, uint8_t b) {
-        red = r;
-        green = g;
-        blue = b;
-    }
 
-    /**
-        Default constructor
-    */
-    Color() {
-    }
-
-    /**
-        Red byte
-    */
-    uint8_t red;
-
-    /**
-        Green byte
-    */
-    uint8_t green;
-
-    /**
-        Blue byte
-    */
-    uint8_t blue;
-};
 
 /**
     Callback method, supplying a Color struct to edit and the led index
 */
 typedef void (*ColorGenerator)(Color* out, uint32_t index);
 
-/**
-    Order of r, g and b bytes
-*/
-enum ByteOrder {
-    RGB,
-    RBG,
-    GRB,
-    GBR,
-    BRG,
-    BGR,
-};
 
 /**
     LEDBus
@@ -70,7 +22,7 @@
 
 private:
     DigitalOut _wire;
-    ByteOrder _byteOrder;
+    ColorByteOrder _byteOrder;
 
     unsigned int _delayT1H, _delayT0H, _delayT1L, _delayT0L, _delayReset;
 
@@ -92,7 +44,7 @@
     *   @param t1l_us - T1L as found in the addressable led datasheet. The duration, in microseconds, the pin will stay low for sending a 1 bit
     *   @param tReset_us - TReset as found in the addressable led datasheet. The duration, in microsecond, the pin will stay low for sending a reset command,
     */
-    LEDBus(PinName wirePin, ByteOrder byteOrder, float t0h_us, float t0l_us, float t1h_us, float t1l_us, float tReset_us);
+    LEDBus(PinName wirePin, ColorByteOrder byteOrder, float t0h_us, float t0l_us, float t1h_us, float t1l_us, float tReset_us);
 
     ~LEDBus();
 
@@ -107,11 +59,11 @@
     * // The led bus control class.
     * LEDBus ledBus(p9, RGB, 0.5f, 2.0f, 1.25f, 1.25f, 50.0f);
     *
-    * Color* red = new Color(255,0,0);
-    * Color* green = new Color(0,255,0);
-    * Color* blue = new Color(0,0,255);
+    * Color* led1 = new Color(255,0,0);
+    * Color* led2 = new Color(0,255,0);
+    * Color* led3 = new Color(0,0,255);
     *
-    * Color* buffer[] = { red, green, blue };
+    * Color* buffer[] = { led1, led2, led3 };
     *
     * ledBus.write(buffer, 3);
     * @endcode