Yet another WS2812 driver, uses the BusrtSPI library. Less features than the PixelArray library but I felt like making my own version.

Dependencies:   BurstSPI

Dependents:   WS2812Text cylon

An alternative WS2811/2812 (NeoPixel) driver using the BusrtSPI library.

Credit for the inspiration goes to Jacob Bramley for his pixelArray library that can be found here: http://developer.mbed.org/users/JacobBramley/code/PixelArray/

This version was written mainly to help me understand what was going on rather than to overcome any shortcomings in the other library and as such it lacks some features (800kHz only, no callback on each pixel etc...)

Connect the SPI output to the LED data input, other SPI pins are unused.

Note: The voltage thresholds between the LEDs and mbed devices are on paper incompatible. The datasheet for the WS2812 indicated that running at 5V it requires 4V on Din to count it as a high (the threshold is 0.8*the supply voltage). Most mbeds are lucky to output much over 3.1V. In reality things normally work OK but it depends on the mBed and batch to batch variations in the LEDs, I've seen some combinations that start to fail at an LED supply voltage of 4.4V or more. If something odd is going on try dropping the LED power supply voltage, they run fine down to 4V.

Committer:
AndyA
Date:
Wed Nov 05 16:47:48 2014 +0000
Revision:
0:b3665f91bedc
Child:
1:741864ea11d4
Initial commit. Seems to work for me, needs more comments/documentaion

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AndyA 0:b3665f91bedc 1 #ifndef __wsDrive_h__
AndyA 0:b3665f91bedc 2 #define __wsDrive_h__
AndyA 0:b3665f91bedc 3
AndyA 0:b3665f91bedc 4 #include "BurstSPI.h"
AndyA 0:b3665f91bedc 5
AndyA 0:b3665f91bedc 6
AndyA 0:b3665f91bedc 7 typedef struct pixelInfo {
AndyA 0:b3665f91bedc 8 unsigned char G;
AndyA 0:b3665f91bedc 9 unsigned char R;
AndyA 0:b3665f91bedc 10 unsigned char B;
AndyA 0:b3665f91bedc 11 } pixelInfo;
AndyA 0:b3665f91bedc 12
AndyA 0:b3665f91bedc 13
AndyA 0:b3665f91bedc 14 class wsDrive : private BurstSPI
AndyA 0:b3665f91bedc 15 {
AndyA 0:b3665f91bedc 16 public:
AndyA 0:b3665f91bedc 17 wsDrive(PinName mosi, PinName miso, PinName clk);
AndyA 0:b3665f91bedc 18 void setData(pixelInfo *dataStart, uint16_t dataLen);
AndyA 0:b3665f91bedc 19 void sendData();
AndyA 0:b3665f91bedc 20
AndyA 0:b3665f91bedc 21 private:
AndyA 0:b3665f91bedc 22
AndyA 0:b3665f91bedc 23 void sendByte(unsigned char value);
AndyA 0:b3665f91bedc 24 void sendPixel(pixelInfo *pixToSend);
AndyA 0:b3665f91bedc 25
AndyA 0:b3665f91bedc 26 pixelInfo *pixArray;
AndyA 0:b3665f91bedc 27 uint16_t pixelLen;
AndyA 0:b3665f91bedc 28
AndyA 0:b3665f91bedc 29 };
AndyA 0:b3665f91bedc 30
AndyA 0:b3665f91bedc 31 #endif