LED Strip with K64F
Fork of PololuLedStrip by
Diff: PololuLedStrip.h
- Revision:
- 1:102307d9b701
- Parent:
- 0:06475317f283
- Child:
- 7:9a088f042ee0
diff -r 06475317f283 -r 102307d9b701 PololuLedStrip.h --- a/PololuLedStrip.h Wed Feb 27 00:28:26 2013 +0000 +++ b/PololuLedStrip.h Wed Feb 27 01:43:44 2013 +0000 @@ -7,50 +7,64 @@ { #ifndef _POLOLU_RGB_COLOR #define _POLOLU_RGB_COLOR + + /** Represents an RGB color. */ typedef struct rgb_color { - uint8_t red, green, blue; + uint8_t red; /*!< A number between 0 and 255 that represents the brightness of the red component. */ + uint8_t green; /*!< A number between 0 and 255 that represents the brightness of the green component. */ + uint8_t blue; /*!< A number between 0 and 255 that represents the brightness of the blue component. */ } rgb_color; #endif extern "C" int led_strip_write_color(rgb_color *, volatile uint32_t * set, volatile uint32_t * clear, uint32_t mask); + /** This class lets you control the + <a href="http://www.pololu.com/catalog/category/20">addressable RGB LED strips from Pololu</a>, + or any other LED strip based on the TM1804 chip. */ class PololuLedStrip { gpio_t gpio; + public: + + /** This constructor lets you make an led strip object by specifying the pin name. + There are no restrictions on what pin you can choose. + + Example: + @code +PololuLedStrip ledStrip(p8); + @endcode + */ PololuLedStrip(PinName pin); + + /** Writes the specified series of colors to the LED strip. + @param colors should be a pointer to an array of rgb_color structs. + @param count should be the number of colors to write. + + The first color in the array will be written to the LED closest to the data input connector. + To update all the LEDs in the LED strip, count should be equal to or greater than the number of LEDs in the strip. + 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. + + The colors are sent in series and each color takes about 60 microseconds to send. + This function disables interrupts temporarily while it is running. + This function waits for over 10 us at the end before returning to allow the colors to take effect. + */ void write(rgb_color * colors, unsigned int count); + + /** This option defaults to <code>false</code>. + Setting this to true changes the behavior of the write function, making it enable interrupts + after each color is sent, about every 60 microseconds. + This allows your program to respond to interrupts faster, but makes it possible for an interrupt + that takes longer than 8 microseconds to screw up the transmission of colors to the LED strip. + + Example: + @code + PololuLedStrip::interruptFriendly = true; + @endcode + */ static bool interruptFriendly; }; - - bool PololuLedStrip::interruptFriendly; - - PololuLedStrip::PololuLedStrip(PinName pinName) - { - gpio_init(&gpio, pinName, PIN_OUTPUT); - } - - void PololuLedStrip::write(rgb_color * colors, unsigned int count) - { - __disable_irq(); // Disable interrupts temporarily because we don't want our pulse timing to be messed up. - - while(count--) - { - led_strip_write_color(colors++, gpio.reg_set, gpio.reg_clr, gpio.mask); - - if (interruptFriendly) - { - __enable_irq(); - __nop(); - __nop(); - __nop(); - __disable_irq(); - } - } - __enable_irq(); // Re-enable interrupts now that we are done. - wait_us(24); // Hold the line low for 24 microseconds to send the reset signal. - } } using namespace Pololu;