A conversion of the excellent Adafruit WS2801 library for Arduino to work on mbed

Dependents:   WiFiDipCortex_Cheerlights

Committer:
SomeRandomBloke
Date:
Wed Feb 12 22:05:44 2014 +0000
Revision:
2:2fdaa13896a4
Parent:
1:6ff477690983
Child:
3:dfffbd9f8ac6
Updated to use hardware SPI on SPI0, only tested on WiFiDIPCortex, LPC1347 based board.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SomeRandomBloke 0:582e1b9c1cc1 1 #include "mbed.h"
SomeRandomBloke 0:582e1b9c1cc1 2
SomeRandomBloke 0:582e1b9c1cc1 3
SomeRandomBloke 0:582e1b9c1cc1 4 // Not all LED pixels are RGB order; 36mm type expects GRB data.
SomeRandomBloke 0:582e1b9c1cc1 5 // Optional flag to constructors indicates data order (default if
SomeRandomBloke 0:582e1b9c1cc1 6 // unspecified is RGB). As long as setPixelColor/getPixelColor are
SomeRandomBloke 0:582e1b9c1cc1 7 // used, other code can always treat 'packed' colors as RGB; the
SomeRandomBloke 0:582e1b9c1cc1 8 // library will handle any required translation internally.
SomeRandomBloke 0:582e1b9c1cc1 9 #define WS2801_RGB 0
SomeRandomBloke 0:582e1b9c1cc1 10 #define WS2801_GRB 1
SomeRandomBloke 0:582e1b9c1cc1 11
SomeRandomBloke 0:582e1b9c1cc1 12 class Adafruit_WS2801 {
SomeRandomBloke 0:582e1b9c1cc1 13
SomeRandomBloke 0:582e1b9c1cc1 14 public:
SomeRandomBloke 0:582e1b9c1cc1 15
SomeRandomBloke 0:582e1b9c1cc1 16 // Configurable pins:
SomeRandomBloke 0:582e1b9c1cc1 17 Adafruit_WS2801(uint16_t n, PinName dpin, PinName cpin, uint8_t order=WS2801_RGB);
SomeRandomBloke 0:582e1b9c1cc1 18 Adafruit_WS2801(uint16_t x, uint16_t y, PinName dpin, PinName cpin, uint8_t order=WS2801_RGB);
SomeRandomBloke 0:582e1b9c1cc1 19 // Use SPI hardware; specific pins only:
SomeRandomBloke 1:6ff477690983 20 // Adafruit_WS2801(uint16_t n, uint8_t order=WS2801_RGB);
SomeRandomBloke 0:582e1b9c1cc1 21 // Empty constructor; init pins/strand length/data order later:
SomeRandomBloke 1:6ff477690983 22 // Adafruit_WS2801();
SomeRandomBloke 0:582e1b9c1cc1 23 // Release memory (as needed):
SomeRandomBloke 0:582e1b9c1cc1 24 ~Adafruit_WS2801();
SomeRandomBloke 0:582e1b9c1cc1 25
SomeRandomBloke 0:582e1b9c1cc1 26 void
SomeRandomBloke 0:582e1b9c1cc1 27 begin(void),
SomeRandomBloke 0:582e1b9c1cc1 28 show(void),
SomeRandomBloke 0:582e1b9c1cc1 29 setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b),
SomeRandomBloke 0:582e1b9c1cc1 30 setPixelColor(uint16_t n, uint32_t c),
SomeRandomBloke 0:582e1b9c1cc1 31 setPixelColor(uint16_t x, uint16_t y, uint8_t r, uint8_t g, uint8_t b),
SomeRandomBloke 0:582e1b9c1cc1 32 setPixelColor(uint16_t x, uint16_t y, uint32_t c),
SomeRandomBloke 0:582e1b9c1cc1 33 updatePins(PinName dpin, PinName cpin), // Change pins, configurable
SomeRandomBloke 2:2fdaa13896a4 34 updatePins(void), // Change pins, hardware SPI
SomeRandomBloke 0:582e1b9c1cc1 35 updateLength(uint16_t n), // Change strand length
SomeRandomBloke 0:582e1b9c1cc1 36 updateOrder(uint8_t order); // Change data order
SomeRandomBloke 0:582e1b9c1cc1 37 uint16_t
SomeRandomBloke 0:582e1b9c1cc1 38 numPixels(void);
SomeRandomBloke 0:582e1b9c1cc1 39 uint32_t
SomeRandomBloke 0:582e1b9c1cc1 40 getPixelColor(uint16_t n);
SomeRandomBloke 0:582e1b9c1cc1 41
SomeRandomBloke 0:582e1b9c1cc1 42 private:
SomeRandomBloke 0:582e1b9c1cc1 43
SomeRandomBloke 0:582e1b9c1cc1 44 uint16_t
SomeRandomBloke 0:582e1b9c1cc1 45 numLEDs,
SomeRandomBloke 0:582e1b9c1cc1 46 width, // used with matrix mode
SomeRandomBloke 0:582e1b9c1cc1 47 height; // used with matrix mode
SomeRandomBloke 0:582e1b9c1cc1 48 uint8_t
SomeRandomBloke 0:582e1b9c1cc1 49 *pixels, // Holds color values for each LED (3 bytes each)
SomeRandomBloke 0:582e1b9c1cc1 50 rgb_order // Color order; RGB vs GRB (or others, if needed in future)
SomeRandomBloke 0:582e1b9c1cc1 51 ;
SomeRandomBloke 0:582e1b9c1cc1 52 DigitalOut clkpin;
SomeRandomBloke 0:582e1b9c1cc1 53 DigitalOut datapin; // Clock & data pin numbers
SomeRandomBloke 0:582e1b9c1cc1 54 void
SomeRandomBloke 1:6ff477690983 55 alloc(uint16_t n);
SomeRandomBloke 1:6ff477690983 56 // startSPI(void);
SomeRandomBloke 2:2fdaa13896a4 57 bool hardwareSPI; // If 'true', using hardware SPI
SomeRandomBloke 1:6ff477690983 58 bool begun; // If 'true', begin() method was previously invoked
SomeRandomBloke 0:582e1b9c1cc1 59 };