The port of adafruit dotstar library for arduino https://github.com/adafruit/Adafruit_DotStar
DotStar.h@0:bae97ff743a6, 2016-03-25 (annotated)
- Committer:
- hideakitai
- Date:
- Fri Mar 25 07:41:51 2016 +0000
- Revision:
- 0:bae97ff743a6
- Child:
- 1:d09c288b8eb3
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hideakitai | 0:bae97ff743a6 | 1 | /*------------------------------------------------------------------------ |
hideakitai | 0:bae97ff743a6 | 2 | This file is part of the Adafruit Dot Star library. |
hideakitai | 0:bae97ff743a6 | 3 | |
hideakitai | 0:bae97ff743a6 | 4 | Adafruit Dot Star is free software: you can redistribute it and/or |
hideakitai | 0:bae97ff743a6 | 5 | modify it under the terms of the GNU Lesser General Public License |
hideakitai | 0:bae97ff743a6 | 6 | as published by the Free Software Foundation, either version 3 of |
hideakitai | 0:bae97ff743a6 | 7 | the License, or (at your option) any later version. |
hideakitai | 0:bae97ff743a6 | 8 | |
hideakitai | 0:bae97ff743a6 | 9 | Adafruit Dot Star is distributed in the hope that it will be useful, |
hideakitai | 0:bae97ff743a6 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
hideakitai | 0:bae97ff743a6 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
hideakitai | 0:bae97ff743a6 | 12 | GNU Lesser General Public License for more details. |
hideakitai | 0:bae97ff743a6 | 13 | |
hideakitai | 0:bae97ff743a6 | 14 | You should have received a copy of the GNU Lesser General Public |
hideakitai | 0:bae97ff743a6 | 15 | License along with DotStar. If not, see <http://www.gnu.org/licenses/>. |
hideakitai | 0:bae97ff743a6 | 16 | ------------------------------------------------------------------------*/ |
hideakitai | 0:bae97ff743a6 | 17 | |
hideakitai | 0:bae97ff743a6 | 18 | #ifndef _ADAFRUIT_DOT_STAR_H_ |
hideakitai | 0:bae97ff743a6 | 19 | #define _ADAFRUIT_DOT_STAR_H_ |
hideakitai | 0:bae97ff743a6 | 20 | |
hideakitai | 0:bae97ff743a6 | 21 | #include <mbed.h> |
hideakitai | 0:bae97ff743a6 | 22 | |
hideakitai | 0:bae97ff743a6 | 23 | // Color-order flag for LED pixels (optional extra parameter to constructor): |
hideakitai | 0:bae97ff743a6 | 24 | // Bits 0,1 = R index (0-2), bits 2,3 = G index, bits 4,5 = B index |
hideakitai | 0:bae97ff743a6 | 25 | #define DOTSTAR_RGB (0 | (1 << 2) | (2 << 4)) |
hideakitai | 0:bae97ff743a6 | 26 | #define DOTSTAR_RBG (0 | (2 << 2) | (1 << 4)) |
hideakitai | 0:bae97ff743a6 | 27 | #define DOTSTAR_GRB (1 | (0 << 2) | (2 << 4)) |
hideakitai | 0:bae97ff743a6 | 28 | #define DOTSTAR_GBR (2 | (0 << 2) | (1 << 4)) |
hideakitai | 0:bae97ff743a6 | 29 | #define DOTSTAR_BRG (1 | (2 << 2) | (0 << 4)) |
hideakitai | 0:bae97ff743a6 | 30 | #define DOTSTAR_BGR (2 | (1 << 2) | (0 << 4)) |
hideakitai | 0:bae97ff743a6 | 31 | #define DOTSTAR_MONO 0 // Single-color strip WIP DO NOT USE YET |
hideakitai | 0:bae97ff743a6 | 32 | |
hideakitai | 0:bae97ff743a6 | 33 | class Adafruit_DotStar { |
hideakitai | 0:bae97ff743a6 | 34 | |
hideakitai | 0:bae97ff743a6 | 35 | public: |
hideakitai | 0:bae97ff743a6 | 36 | |
hideakitai | 0:bae97ff743a6 | 37 | Adafruit_DotStar(uint16_t n, uint8_t o=DOTSTAR_BRG); |
hideakitai | 0:bae97ff743a6 | 38 | Adafruit_DotStar(uint16_t n, uint8_t d, uint8_t c, uint8_t o=DOTSTAR_BRG); |
hideakitai | 0:bae97ff743a6 | 39 | ~Adafruit_DotStar(void); |
hideakitai | 0:bae97ff743a6 | 40 | void |
hideakitai | 0:bae97ff743a6 | 41 | begin(void), // Prime pins/SPI for output |
hideakitai | 0:bae97ff743a6 | 42 | clear(), // Set all pixel data to zero |
hideakitai | 0:bae97ff743a6 | 43 | setBrightness(uint8_t), // Set global brightness 0-255 |
hideakitai | 0:bae97ff743a6 | 44 | setPixelColor(uint16_t n, uint32_t c), |
hideakitai | 0:bae97ff743a6 | 45 | setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b), |
hideakitai | 0:bae97ff743a6 | 46 | show(void), // Issue color data to strip |
hideakitai | 0:bae97ff743a6 | 47 | // updatePins(void), // Change pin assignments (HW) |
hideakitai | 0:bae97ff743a6 | 48 | // updatePins(uint8_t d, uint8_t c), // Change pin assignments (SW) |
hideakitai | 0:bae97ff743a6 | 49 | updateLength(uint16_t n); // Change length |
hideakitai | 0:bae97ff743a6 | 50 | uint32_t |
hideakitai | 0:bae97ff743a6 | 51 | Color(uint8_t r, uint8_t g, uint8_t b), // R,G,B to 32-bit color |
hideakitai | 0:bae97ff743a6 | 52 | getPixelColor(uint16_t n) const; // Return 32-bit pixel color |
hideakitai | 0:bae97ff743a6 | 53 | uint16_t |
hideakitai | 0:bae97ff743a6 | 54 | numPixels(void); // Return number of pixels |
hideakitai | 0:bae97ff743a6 | 55 | uint8_t |
hideakitai | 0:bae97ff743a6 | 56 | getBrightness(void) const, // Return global brightness |
hideakitai | 0:bae97ff743a6 | 57 | *getPixels(void) const; // Return pixel data pointer |
hideakitai | 0:bae97ff743a6 | 58 | |
hideakitai | 0:bae97ff743a6 | 59 | private: |
hideakitai | 0:bae97ff743a6 | 60 | |
hideakitai | 0:bae97ff743a6 | 61 | uint16_t |
hideakitai | 0:bae97ff743a6 | 62 | numLEDs; // Number of pixels |
hideakitai | 0:bae97ff743a6 | 63 | uint8_t |
hideakitai | 0:bae97ff743a6 | 64 | dataPin, // If soft SPI, data pin # |
hideakitai | 0:bae97ff743a6 | 65 | clockPin, // If soft SPI, clock pin # |
hideakitai | 0:bae97ff743a6 | 66 | brightness, // Global brightness setting |
hideakitai | 0:bae97ff743a6 | 67 | *pixels, // LED RGB values (3 bytes ea.) |
hideakitai | 0:bae97ff743a6 | 68 | rOffset, // Index of red in 3-byte pixel |
hideakitai | 0:bae97ff743a6 | 69 | gOffset, // Index of green byte |
hideakitai | 0:bae97ff743a6 | 70 | bOffset; // Index of blue byte |
hideakitai | 0:bae97ff743a6 | 71 | void |
hideakitai | 0:bae97ff743a6 | 72 | hw_spi_init(void), // Start hardware SPI |
hideakitai | 0:bae97ff743a6 | 73 | hw_spi_end(void); // Stop hardware SPI |
hideakitai | 0:bae97ff743a6 | 74 | // sw_spi_init(void), // Start bitbang SPI |
hideakitai | 0:bae97ff743a6 | 75 | // sw_spi_out(uint8_t n), // Bitbang SPI write |
hideakitai | 0:bae97ff743a6 | 76 | // sw_spi_end(void); // Stop bitbang SPI |
hideakitai | 0:bae97ff743a6 | 77 | |
hideakitai | 0:bae97ff743a6 | 78 | }; |
hideakitai | 0:bae97ff743a6 | 79 | |
hideakitai | 0:bae97ff743a6 | 80 | #endif // _ADAFRUIT_DOT_STAR_H_ |