PololuLedStrip from mickaeljkoster with support for K64F

Fork of PololuLedStrip by Michael Koster

Committer:
Alegrowin
Date:
Tue Nov 25 20:31:11 2014 +0000
Revision:
24:b88e97eb2e09
Parent:
23:9d1b45daf607
Activate the K64F support

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DavidEGrayson 0:06475317f283 1 #include "mbed.h"
DavidEGrayson 0:06475317f283 2
DavidEGrayson 0:06475317f283 3 #ifndef _POLOLU_LED_STRIP_H
DavidEGrayson 0:06475317f283 4 #define _POLOLU_LED_STRIP_H
DavidEGrayson 0:06475317f283 5
DavidEGrayson 0:06475317f283 6 namespace Pololu
DavidEGrayson 0:06475317f283 7 {
Alegrowin 23:9d1b45daf607 8 #ifndef _POLOLU_RGB_COLOR
Alegrowin 23:9d1b45daf607 9 #define _POLOLU_RGB_COLOR
Alegrowin 23:9d1b45daf607 10
Alegrowin 23:9d1b45daf607 11 #ifndef _K64F
Alegrowin 24:b88e97eb2e09 12 #define _K64F //Define this to use with K64F
Alegrowin 23:9d1b45daf607 13 #endif
Alegrowin 23:9d1b45daf607 14
Alegrowin 23:9d1b45daf607 15 /** Represents an RGB color. */
Alegrowin 23:9d1b45daf607 16 typedef struct rgb_color {
Alegrowin 23:9d1b45daf607 17 uint8_t red; /*!< A number between 0 and 255 that represents the brightness of the red component. */
Alegrowin 23:9d1b45daf607 18 uint8_t green; /*!< A number between 0 and 255 that represents the brightness of the green component. */
Alegrowin 23:9d1b45daf607 19 uint8_t blue; /*!< A number between 0 and 255 that represents the brightness of the blue component. */
Alegrowin 23:9d1b45daf607 20 } rgb_color;
Alegrowin 23:9d1b45daf607 21 #endif
DavidEGrayson 0:06475317f283 22
Alegrowin 23:9d1b45daf607 23 #ifdef _K64F
Alegrowin 23:9d1b45daf607 24 extern "C" int led_strip_write_color_K64F(rgb_color *, volatile uint32_t * set, volatile uint32_t * clear, uint32_t mask);
Alegrowin 23:9d1b45daf607 25 #else
Alegrowin 23:9d1b45daf607 26 extern "C" int led_strip_write_color(rgb_color *, volatile uint32_t * set, volatile uint32_t * clear, uint32_t mask);
Alegrowin 23:9d1b45daf607 27 #endif
Alegrowin 23:9d1b45daf607 28
Alegrowin 23:9d1b45daf607 29 /** This class lets you control the addressable RGB LED strips from Pololu</a>,
Alegrowin 23:9d1b45daf607 30 or any other LED strip based on the TM1804 chip. */
Alegrowin 23:9d1b45daf607 31 class PololuLedStrip
Alegrowin 23:9d1b45daf607 32 {
Alegrowin 23:9d1b45daf607 33 gpio_t gpio;
Alegrowin 23:9d1b45daf607 34 uint32_t mask;
Alegrowin 23:9d1b45daf607 35 __IO uint32_t *reg_set;
Alegrowin 23:9d1b45daf607 36 __IO uint32_t *reg_clr;
Alegrowin 23:9d1b45daf607 37
Alegrowin 23:9d1b45daf607 38 public:
Alegrowin 23:9d1b45daf607 39
Alegrowin 23:9d1b45daf607 40 /** This constructor lets you make an led strip object by specifying the pin name.
Alegrowin 23:9d1b45daf607 41 There are no restrictions on what pin you can choose.
DavidEGrayson 0:06475317f283 42
Alegrowin 23:9d1b45daf607 43 Example:
Alegrowin 23:9d1b45daf607 44 @code
Alegrowin 23:9d1b45daf607 45 PololuLedStrip ledStrip(p8);
Alegrowin 23:9d1b45daf607 46 @endcode
Alegrowin 23:9d1b45daf607 47 */
Alegrowin 23:9d1b45daf607 48 PololuLedStrip(PinName pin);
Alegrowin 23:9d1b45daf607 49
Alegrowin 23:9d1b45daf607 50 /** Writes the specified series of colors to the LED strip.
Alegrowin 23:9d1b45daf607 51 @param colors should be a pointer to an array of rgb_color structs.
Alegrowin 23:9d1b45daf607 52 @param count should be the number of colors to write.
Alegrowin 23:9d1b45daf607 53
Alegrowin 23:9d1b45daf607 54 The first color in the array will be written to the LED closest to the data input connector.
Alegrowin 23:9d1b45daf607 55 To update all the LEDs in the LED strip, count should be equal to or greater than the number of LEDs in the strip.
Alegrowin 23:9d1b45daf607 56 If count is less than the number of LEDs in the strip, then some LEDs near the end of the strip will not be updated.
Alegrowin 23:9d1b45daf607 57
Alegrowin 23:9d1b45daf607 58 The colors are sent in series and each color takes about 45 microseconds to send.
Alegrowin 23:9d1b45daf607 59 This function disables interrupts temporarily while it is running.
Alegrowin 23:9d1b45daf607 60 This function waits for over 10 us at the end before returning to allow the colors to take effect.
Alegrowin 23:9d1b45daf607 61 */
Alegrowin 23:9d1b45daf607 62 void write(rgb_color * colors, unsigned int count);
Alegrowin 23:9d1b45daf607 63
Alegrowin 23:9d1b45daf607 64 /** This option defaults to <code>false</code>.
Alegrowin 23:9d1b45daf607 65 Setting this to true changes the behavior of the write function, making it enable interrupts
Alegrowin 23:9d1b45daf607 66 after each color is sent, about every 60 microseconds.
Alegrowin 23:9d1b45daf607 67 This allows your program to respond to interrupts faster, but makes it possible for an interrupt
Alegrowin 23:9d1b45daf607 68 that takes longer than 8 microseconds to screw up the transmission of colors to the LED strip.
Alegrowin 23:9d1b45daf607 69
Alegrowin 23:9d1b45daf607 70 Example:
Alegrowin 23:9d1b45daf607 71 @code
Alegrowin 23:9d1b45daf607 72 PololuLedStrip::interruptFriendly = true;
Alegrowin 23:9d1b45daf607 73 @endcode
Alegrowin 23:9d1b45daf607 74 */
Alegrowin 23:9d1b45daf607 75 static bool interruptFriendly;
Alegrowin 23:9d1b45daf607 76
Alegrowin 23:9d1b45daf607 77 static void calculateDelays();
Alegrowin 23:9d1b45daf607 78 };
DavidEGrayson 0:06475317f283 79 }
DavidEGrayson 0:06475317f283 80
DavidEGrayson 0:06475317f283 81 using namespace Pololu;
DavidEGrayson 0:06475317f283 82
DavidEGrayson 0:06475317f283 83 #endif