Optimised fork of bikeNomad's WS2811 LED control library. Supports KL25Z and KL46Z
Fork of Multi_WS2811 by
Optimised to use far less RAM than the original.
Capable of running up to 8 strings of 240 LEDs each with plenty of RAM to spare on the KL46Z.
Should run at least three strings of 240 LEDs on the KL25Z (RAM limited)
Revision 3:2b5b03a3c0a5, committed 2014-04-02
- Comitter:
- Tomo2k
- Date:
- Wed Apr 02 11:54:27 2014 +0000
- Parent:
- 2:1c2c9c8788a8
- Child:
- 4:586d20c99dbf
- Commit message:
- Documentation updated
Changed in this revision
--- a/Colors.cpp Wed Apr 02 10:53:43 2014 +0000
+++ b/Colors.cpp Wed Apr 02 11:54:27 2014 +0000
@@ -2,7 +2,7 @@
#include <mbed.h>
#include "Colors.h"
-void HSBtoRGB(float hue, float saturation, float brightness, uint8_t *pr, uint8_t *pg, uint8_t *pb)
+void Colors::HSBtoRGB(float hue, float saturation, float brightness, uint8_t *pr, uint8_t *pg, uint8_t *pb)
{
uint8_t r = 0, g = 0, b = 0;
if (saturation == 0) {
@@ -51,7 +51,7 @@
*pb = b;
}
-float* RGBtoHSB(uint8_t r, uint8_t g, uint8_t b, float* hsbvals)
+float* Colors::RGBtoHSB(uint8_t r, uint8_t g, uint8_t b, float* hsbvals)
{
float hue, saturation, brightness;
if (!hsbvals) {
--- a/Colors.h Wed Apr 02 10:53:43 2014 +0000
+++ b/Colors.h Wed Apr 02 11:54:27 2014 +0000
@@ -3,49 +3,55 @@
#ifndef __included_colors_h
#define __included_colors_h
-/**
- * Converts the components of a color, as specified by the HSB
- * model, to an equivalent set of values for the default RGB model.
- * <p>
- * The <code>saturation</code> and <code>brightness</code> components
- * should be floating-point values between zero and one
- * (numbers in the range 0.0-1.0). The <code>hue</code> component
- * can be any floating-point number. The floor of this number is
- * subtracted from it to create a fraction between 0 and 1. This
- * fractional number is then multiplied by 360 to produce the hue
- * angle in the HSB color model.
- * <p>
- * The integer that is returned by <code>HSBtoRGB</code> encodes the
- * value of a color in bits 0-23 of an integer value that is the same
- * format used by the method {@link #getRGB() <code>getRGB</code>}.
- * This integer can be supplied as an argument to the
- * <code>Color</code> constructor that takes a single integer argument.
- * @param hue the hue component of the color
- * @param saturation the saturation of the color
- * @param brightness the brightness of the color
- * @return the RGB value of the color with the indicated hue,
- * saturation, and brightness.
- */
-void HSBtoRGB(float hue, float saturation, float brightness, uint8_t *pr, uint8_t *pg, uint8_t *pb);
+//! Color Functions
+class Colors
+{
+public :
+ /**
+ * Converts the components of a color, as specified by the HSB
+ * model, to an equivalent set of values for the default RGB model.
+ * <p>
+ * The <code>saturation</code> and <code>brightness</code> components
+ * should be floating-point values between zero and one
+ * (numbers in the range 0.0-1.0). The <code>hue</code> component
+ * can be any floating-point number. The floor of this number is
+ * subtracted from it to create a fraction between 0 and 1. This
+ * fractional number is then multiplied by 360 to produce the hue
+ * angle in the HSB color model.
+ * <p>
+ * The integer that is returned by <code>HSBtoRGB</code> encodes the
+ * value of a color in bits 0-23 of an integer value that is the same
+ * format used by the method {@link #getRGB() <code>getRGB</code>}.
+ * This integer can be supplied as an argument to the
+ * <code>Color</code> constructor that takes a single integer argument.
+ * @param hue the hue component of the color
+ * @param saturation the saturation of the color
+ * @param brightness the brightness of the color
+ * @return the RGB value of the color with the indicated hue,
+ * saturation, and brightness.
+ */
+ static void HSBtoRGB(float hue, float saturation, float brightness, uint8_t *pr, uint8_t *pg, uint8_t *pb);
-/**
- * Converts the components of a color, as specified by the default RGB
- * model, to an equivalent set of values for hue, saturation, and
- * brightness that are the three components of the HSB model.
- * <p>
- * If the <code>hsbvals</code> argument is <code>null</code>, then a
- * new array is allocated to return the result. Otherwise, the method
- * returns the array <code>hsbvals</code>, with the values put into
- * that array.
- * @param r the red component of the color
- * @param g the green component of the color
- * @param b the blue component of the color
- * @param hsbvals the array used to return the
- * three HSB values, or <code>null</code>
- * @return an array of three elements containing the hue, saturation,
- * and brightness (in that order), of the color with
- * the indicated red, green, and blue components.
- */
-float* RGBtoHSB(uint8_t r, uint8_t g, uint8_t b, float* hsbvals);
+ /**
+ * Converts the components of a color, as specified by the default RGB
+ * model, to an equivalent set of values for hue, saturation, and
+ * brightness that are the three components of the HSB model.
+ * <p>
+ * If the <code>hsbvals</code> argument is <code>null</code>, then a
+ * new array is allocated to return the result. Otherwise, the method
+ * returns the array <code>hsbvals</code>, with the values put into
+ * that array.
+ * @param r the red component of the color
+ * @param g the green component of the color
+ * @param b the blue component of the color
+ * @param hsbvals the array used to return the
+ * three HSB values, or <code>null</code>
+ * @return an array of three elements containing the hue, saturation,
+ * and brightness (in that order), of the color with
+ * the indicated red, green, and blue components.
+ */
+ static float* RGBtoHSB(uint8_t r, uint8_t g, uint8_t b, float* hsbvals);
+
+};
#endif
--- a/LedStrip.h Wed Apr 02 10:53:43 2014 +0000
+++ b/LedStrip.h Wed Apr 02 11:54:27 2014 +0000
@@ -13,28 +13,72 @@
#ifndef LEDSTRIP_H
#define LEDSTRIP_H
+/** Generic LED Strip
+Pure virtual parent class for all types of LED strip
+*/
class LedStrip
{
public:
+ /** Create an LED strip
+ @param n Number of RGB LEDs on the strip
+ */
LedStrip(int n);
~LedStrip();
+ //! Initialise the LED strip
virtual void begin(void)=0;
+ //! Display the LED strip
virtual void show(void)=0;
+ //! Blank the LED strip
virtual void blank(void)=0;
+ /** Pack RGB Color data
+ @param r Amount of Red
+ @param g Amount of Green
+ @param b Amount of Blue
+ */
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b);
+ //! Number of RGB pixels
uint16_t numPixels(void) { return numLEDs; }
+ //! Number of bytes used for pixel colour data
uint16_t numPixelBytes(void) { return numLEDs * 3; }
+ //! Total brightness of all diodes\n
+ //! Use to check power budget
uint32_t total_luminance(void);
+ /** Set Blue level of pixel
+ @param n Pixel Number
+ @param b Amount of Blue
+ */
void setPixelB(uint16_t n, uint8_t b);
+ /** Set Green level of pixel
+ @param n Pixel Number
+ @param g Amount of Green
+ */
void setPixelG(uint16_t n, uint8_t g);
+ /** Set Red level of pixel
+ @param n Pixel Number
+ @param r Amount of Red
+ */
void setPixelR(uint16_t n, uint8_t r);
+ /** Set color of pixel
+ @param n Pixel Number
+ @param c Packed RGB color data
+ */
void setPixelColor(uint16_t n, uint32_t c);
+ /** Set color of pixel
+ @param n Pixel Number
+ @param r Amount of Red
+ @param g Amount of Green
+ @param b Amount of Blue
+ */
void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b);
+ /** Set color of all pixels
+ @param *buffer Packed pixel data
+ @param n number of pixels
+ */
void setPackedPixels(uint8_t * buffer, uint32_t n);
protected:
--- a/WS2811.h Wed Apr 02 10:53:43 2014 +0000
+++ b/WS2811.h Wed Apr 02 11:54:27 2014 +0000
@@ -12,6 +12,10 @@
//
// Modified by Ned Konz, December 2013.
// Using three-phase DMA ala Paul Stoffegren's version.
+//
+// Modified by richard Thompson, Marhc 2014.
+// Uses 8-bit DMA transfers instead of 32-bit, uses 1/4 of the RAM.
+// Now capable of running 240 LEDs on one pin
#ifndef MBED_WS2811_H
#define MBED_WS2811_H
@@ -24,15 +28,26 @@
extern "C" void DMA0_IRQHandler();
extern "C" void TPM0_IRQHandler();
+/**
+* WS2811/n
+* LED Strip controller
+*/
class WS2811 : public LedStrip
{
public:
+ /** Set up the LED strip
+ @param n Number of LEDs on the strip. Must be less than MAX_LEDS_PER_STRIP
+ @param pinNumber Pin number on PORTD. 0-7.
+ */
WS2811(unsigned n, unsigned pinNumber);
virtual void begin();
virtual void show();
virtual void blank();
+ /** Send a level update to all the WS2811 LED strips
+ * All updates happen in parallel, ensure all (max. 8) strips have complete data before calling this.
+ */
static void startDMA();
private:
