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

Dependents:   WiFiDipCortex_Cheerlights

Committer:
SomeRandomBloke
Date:
Fri Mar 08 08:49:04 2013 +0000
Revision:
0:582e1b9c1cc1
Child:
1:6ff477690983
Initial version of library after converting Arduino library to mbed library

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 0:582e1b9c1cc1 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 0:582e1b9c1cc1 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 0:582e1b9c1cc1 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 // clkpinmask, datapinmask; // Clock & data PORT bitmasks
SomeRandomBloke 0:582e1b9c1cc1 55 // volatile uint8_t
SomeRandomBloke 0:582e1b9c1cc1 56 // *clkport , *dataport; // Clock & data PORT registers
SomeRandomBloke 0:582e1b9c1cc1 57 void
SomeRandomBloke 0:582e1b9c1cc1 58 alloc(uint16_t n),
SomeRandomBloke 0:582e1b9c1cc1 59 startSPI(void);
SomeRandomBloke 0:582e1b9c1cc1 60 bool
SomeRandomBloke 0:582e1b9c1cc1 61 hardwareSPI, // If 'true', using hardware SPI
SomeRandomBloke 0:582e1b9c1cc1 62 begun; // If 'true', begin() method was previously invoked
SomeRandomBloke 0:582e1b9c1cc1 63 };