Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of APA102 by
APA102a.cpp@6:5d4edfc955f3, 2015-04-07 (annotated)
- Committer:
- rosienej
- Date:
- Tue Apr 07 01:41:17 2015 +0000
- Revision:
- 6:5d4edfc955f3
- Parent:
- 5:863fb3a71efd
spi
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| rosienej | 3:bf8c63d10824 | 1 | #include "APA102a.h" |
| rosienej | 3:bf8c63d10824 | 2 | #include "mbed.h" |
| rosienej | 3:bf8c63d10824 | 3 | |
| rosienej | 4:2afea45fce8f | 4 | APA102a::APA102a(PinName mosi,PinName miso,PinName sclk,int rate) |
| rosienej | 3:bf8c63d10824 | 5 | : _spi(mosi, miso, sclk) |
| rosienej | 3:bf8c63d10824 | 6 | |
| rosienej | 3:bf8c63d10824 | 7 | { |
| rosienej | 6:5d4edfc955f3 | 8 | // Setup the spi for 8 bit data, low steady state clock, |
| rosienej | 5:863fb3a71efd | 9 | // second edge capture, with clock rate, clock active low, rising edge |
| rosienej | 6:5d4edfc955f3 | 10 | _spi.format(8,0); |
| rosienej | 3:bf8c63d10824 | 11 | _spi.frequency(rate); |
| rosienej | 3:bf8c63d10824 | 12 | } |
| rosienej | 3:bf8c63d10824 | 13 | |
| rosienej | 4:2afea45fce8f | 14 | void APA102a::SetBuffer(unsigned int Buffer[],int Rows,int Cols, int Stride,int Offset, bool ZigZag,bool Wrap) |
| rosienej | 3:bf8c63d10824 | 15 | { |
| rosienej | 3:bf8c63d10824 | 16 | Buf = Buffer; |
| rosienej | 3:bf8c63d10824 | 17 | NR = Rows; |
| rosienej | 3:bf8c63d10824 | 18 | NC = Cols; |
| rosienej | 3:bf8c63d10824 | 19 | NS = Stride; |
| rosienej | 3:bf8c63d10824 | 20 | off = Offset; |
| rosienej | 3:bf8c63d10824 | 21 | ZF = ZigZag; |
| rosienej | 3:bf8c63d10824 | 22 | WF = Wrap; |
| rosienej | 3:bf8c63d10824 | 23 | } |
| rosienej | 3:bf8c63d10824 | 24 | |
| rosienej | 4:2afea45fce8f | 25 | void APA102a::Repaint() |
| rosienej | 3:bf8c63d10824 | 26 | { |
| rosienej | 3:bf8c63d10824 | 27 | int index; |
| rosienej | 3:bf8c63d10824 | 28 | unsigned int val; |
| rosienej | 3:bf8c63d10824 | 29 | |
| rosienej | 3:bf8c63d10824 | 30 | _spi.write(0X00); // Start |
| rosienej | 3:bf8c63d10824 | 31 | _spi.write(0X00); |
| rosienej | 3:bf8c63d10824 | 32 | _spi.write(0X00); |
| rosienej | 3:bf8c63d10824 | 33 | _spi.write(0X00); |
| rosienej | 3:bf8c63d10824 | 34 | |
| rosienej | 3:bf8c63d10824 | 35 | for(int r = 0;r<NR;r++) |
| rosienej | 3:bf8c63d10824 | 36 | { |
| rosienej | 3:bf8c63d10824 | 37 | for(int c = off;c<(NC+off);c++) |
| rosienej | 3:bf8c63d10824 | 38 | { |
| rosienej | 3:bf8c63d10824 | 39 | int cc = (WF)?(c%NS):((c<NS)?c:NS); |
| rosienej | 4:2afea45fce8f | 40 | // if (ZF) |
| rosienej | 4:2afea45fce8f | 41 | // { if((r&0x01)>0) |
| rosienej | 3:bf8c63d10824 | 42 | index = r*NS + NC+off-cc; |
| rosienej | 4:2afea45fce8f | 43 | // else |
| rosienej | 4:2afea45fce8f | 44 | // index = r*NS + cc;} |
| rosienej | 4:2afea45fce8f | 45 | // else |
| rosienej | 4:2afea45fce8f | 46 | index = r*NS + c; |
| rosienej | 3:bf8c63d10824 | 47 | |
| rosienej | 3:bf8c63d10824 | 48 | val = Buf[index]; |
| rosienej | 3:bf8c63d10824 | 49 | _spi.write((val>>24)&0xFF); |
| rosienej | 3:bf8c63d10824 | 50 | _spi.write((val>>16)&0xFF); |
| rosienej | 3:bf8c63d10824 | 51 | _spi.write((val>>8)&0xFF); |
| rosienej | 3:bf8c63d10824 | 52 | _spi.write(val&0xFF); |
| rosienej | 3:bf8c63d10824 | 53 | } |
| rosienej | 3:bf8c63d10824 | 54 | } |
| rosienej | 3:bf8c63d10824 | 55 | _spi.write(0XFF); // Stop |
| rosienej | 3:bf8c63d10824 | 56 | _spi.write(0XFF); |
| rosienej | 3:bf8c63d10824 | 57 | _spi.write(0XFF); |
| rosienej | 3:bf8c63d10824 | 58 | _spi.write(0XFF); |
| rosienej | 3:bf8c63d10824 | 59 | |
| rosienej | 3:bf8c63d10824 | 60 | } |
