• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <string>
27 #include <mraa/aio.hpp>
28 
29 #include <mraa/gpio.hpp>
30 
31 #include <mraa/spi.hpp>
32 
33 #define HIGH                    1
34 #define LOW                     0
35 
36 namespace upm {
37 
38 /**
39  * @brief FastPixel LPD8806 library
40  * @defgroup lpd8806 libupm-lpd8806
41  * @ingroup adafruit spi led
42  */
43 
44 /**
45  * @library lpd8806
46  * @sensor lpd8806
47  * @comname LPD8806 RGB LED Strip Controller
48  * @type led
49  * @man adafruit
50  * @con spi
51  *
52  * @brief API for the LPD8806 RGB LED Strip Controller
53  *
54  * FastPixel* LPD8806 is an RGB LED strip controller.
55  *
56  * @image html lpd8806.jpg
57  * @snippet lpd8806.cxx Interesting
58  */
59 class LPD8806 {
60     public:
61 
62         /**
63          * Instantiates an LPD8806 object
64          *
65          * @param pixelCount Number of pixels in the strip
66          * @param csn Chip select pin
67          */
68         LPD8806 (uint16_t pixelCount, uint8_t csn);
69 
70         /**
71          * LPD8806 object destructor; basically, it frees the allocated
72          * pixel buffer.
73          */
74         ~LPD8806 ();
75 
76         /**
77          * @param pixelOffset Pixel offset in the strip of the pixel
78          * @param r Red LED
79          * @param g Green LED
80          * @param b Blue LED
81          */
82         void setPixelColor (uint16_t pixelOffset, uint8_t r, uint8_t g, uint8_t b);
83 
84         /**
85          * Writes the data stored in the array of pixels to the chip
86          */
87         void show (void);
88 
89         /**
90          * Returns the length of the LED strip
91          */
92         uint16_t getStripLength (void);
93 
94         /**
95          * Returns the name of the component
96          */
name()97         std::string name()
98         {
99             return m_name;
100         }
101     private:
102         std::string m_name;
103         mraa::Spi        m_spi;
104         mraa::Gpio       m_csnPinCtx;
105 
106         uint8_t*                m_pixels;
107         uint8_t                 m_pixelsCount;
108 
109         uint8_t readRegister (uint8_t reg);
110         void writeRegister (uint8_t reg, uint8_t data);
111 
112         /**
113          * Sets the chip select pin to LOW
114          */
115         mraa::Result CSOn ();
116 
117         /**
118          * Sets the chip select pin to HIGH
119          */
120         mraa::Result CSOff ();
121 };
122 
123 }
124