Routines to drive a chain of APA102 Leds.
Fork of APA102 by
A library to drive arrays of APA102 leds.
APA102a.h@4:2afea45fce8f, 2015-03-14 (annotated)
- Committer:
- rosienej
- Date:
- Sat Mar 14 20:45:03 2015 +0000
- Revision:
- 4:2afea45fce8f
- Parent:
- 3:bf8c63d10824
- Child:
- 7:629583c31cef
First release with demo code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rosienej | 3:bf8c63d10824 | 1 | #ifndef MBED_APA102a_H |
rosienej | 3:bf8c63d10824 | 2 | |
rosienej | 3:bf8c63d10824 | 3 | #define MBED_APA102a_H |
rosienej | 3:bf8c63d10824 | 4 | |
rosienej | 3:bf8c63d10824 | 5 | #include "mbed.h" |
rosienej | 3:bf8c63d10824 | 6 | |
rosienej | 3:bf8c63d10824 | 7 | |
rosienej | 3:bf8c63d10824 | 8 | |
rosienej | 3:bf8c63d10824 | 9 | /** Create an APA102 Object |
rosienej | 3:bf8c63d10824 | 10 | */ |
rosienej | 4:2afea45fce8f | 11 | class APA102a{ |
rosienej | 3:bf8c63d10824 | 12 | public: |
rosienej | 3:bf8c63d10824 | 13 | /** Create an APA102 object connected to the specified mosi,miso,sclk pins |
rosienej | 3:bf8c63d10824 | 14 | * |
rosienej | 3:bf8c63d10824 | 15 | * @param mosi : SPI Master Out Slave In pin |
rosienej | 3:bf8c63d10824 | 16 | * @param miso : SPI Master In Slave Out pin (ignored) |
rosienej | 3:bf8c63d10824 | 17 | * @param sclk : SPI Clock |
rosienej | 3:bf8c63d10824 | 18 | * @param rate : SPI Rate |
rosienej | 3:bf8c63d10824 | 19 | */ |
rosienej | 4:2afea45fce8f | 20 | APA102a(PinName mosi,PinName miso,PinName sclk,int rate); |
rosienej | 3:bf8c63d10824 | 21 | |
rosienej | 3:bf8c63d10824 | 22 | /** Set the Buffer |
rosienej | 3:bf8c63d10824 | 23 | * |
rosienej | 3:bf8c63d10824 | 24 | * @param buffer[] : a buffer of unsigned integers (4 bytes) *Rows*Stride in size |
rosienej | 3:bf8c63d10824 | 25 | * @param Rows : Number of Rows |
rosienej | 3:bf8c63d10824 | 26 | * @param Cols : Number of Columns |
rosienej | 3:bf8c63d10824 | 27 | * @param Stride : The actual number of columns (useful for data alignment) |
rosienej | 3:bf8c63d10824 | 28 | * @param Offset : The offset into a row |
rosienej | 3:bf8c63d10824 | 29 | * @param ZigZag : A boolean, do we alternate count up/ count down per row? |
rosienej | 3:bf8c63d10824 | 30 | * @param Wrap : A boolean, do we wrap if (Offset+Cols) > Stride? (handy for scrolling messages) |
rosienej | 3:bf8c63d10824 | 31 | */ |
rosienej | 3:bf8c63d10824 | 32 | void SetBuffer(unsigned int Buffer[],int Rows,int Cols, int Stride,int Offset, bool ZigZag,bool Wrap); |
rosienej | 3:bf8c63d10824 | 33 | |
rosienej | 3:bf8c63d10824 | 34 | /** Repaint the Strip |
rosienej | 3:bf8c63d10824 | 35 | * Sends to the Buffer to the Strip. |
rosienej | 3:bf8c63d10824 | 36 | * @param none |
rosienej | 3:bf8c63d10824 | 37 | */ |
rosienej | 3:bf8c63d10824 | 38 | void Repaint(); |
rosienej | 3:bf8c63d10824 | 39 | |
rosienej | 3:bf8c63d10824 | 40 | /** Create an IRGB helper function to construct a 4 byte LED Frame |
rosienej | 3:bf8c63d10824 | 41 | * |
rosienej | 3:bf8c63d10824 | 42 | * @param I : 5 bits of intensity (0,1,2,...,31) |
rosienej | 3:bf8c63d10824 | 43 | * @param R : 8 bits of Red (0,1,...,255) |
rosienej | 3:bf8c63d10824 | 44 | * @param G : 8 bits of Green (0,1,...,255) |
rosienej | 3:bf8c63d10824 | 45 | * @param B : 8 bits of Blue (0,1,...,255) |
rosienej | 3:bf8c63d10824 | 46 | */ |
rosienej | 3:bf8c63d10824 | 47 | |
rosienej | 4:2afea45fce8f | 48 | unsigned int IRGB(unsigned char I,unsigned char R,unsigned char G,unsigned char B) { |
rosienej | 4:2afea45fce8f | 49 | return ((0xE0 + (0x1F&I))<<24)|((0xFF&R)<<16)|((0xFF&G)<<8)|(0xFF&B);} |
rosienej | 3:bf8c63d10824 | 50 | |
rosienej | 3:bf8c63d10824 | 51 | protected: |
rosienej | 3:bf8c63d10824 | 52 | |
rosienej | 3:bf8c63d10824 | 53 | SPI _spi; |
rosienej | 3:bf8c63d10824 | 54 | private: |
rosienej | 3:bf8c63d10824 | 55 | int NR; |
rosienej | 3:bf8c63d10824 | 56 | int NC; |
rosienej | 3:bf8c63d10824 | 57 | int NS; |
rosienej | 3:bf8c63d10824 | 58 | int off; |
rosienej | 3:bf8c63d10824 | 59 | bool ZF; |
rosienej | 3:bf8c63d10824 | 60 | bool WF; |
rosienej | 3:bf8c63d10824 | 61 | unsigned int * Buf; |
rosienej | 3:bf8c63d10824 | 62 | }; |
rosienej | 3:bf8c63d10824 | 63 | |
rosienej | 3:bf8c63d10824 | 64 | #endif |