K64F version
Fork of PololuLedStrip_r8 by
PololuLedStrip.h@25:3b22d6d32a7a, 2014-12-11 (annotated)
- Committer:
- michaeljkoster
- Date:
- Thu Dec 11 23:14:12 2014 +0000
- Revision:
- 25:3b22d6d32a7a
- Parent:
- 19:46d7ab0ba3e7
K64F support etc
Who changed what in which revision?
User | Revision | Line number | New 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 | { |
michaeljkoster | 25:3b22d6d32a7a | 8 | #ifndef _POLOLU_RGB_COLOR |
michaeljkoster | 25:3b22d6d32a7a | 9 | #define _POLOLU_RGB_COLOR |
michaeljkoster | 25:3b22d6d32a7a | 10 | |
michaeljkoster | 25:3b22d6d32a7a | 11 | #ifndef _K64F |
michaeljkoster | 25:3b22d6d32a7a | 12 | #define _K64F //Define this to use with K64F |
michaeljkoster | 25:3b22d6d32a7a | 13 | #endif |
michaeljkoster | 25:3b22d6d32a7a | 14 | |
michaeljkoster | 25:3b22d6d32a7a | 15 | /** Represents an RGB color. */ |
michaeljkoster | 25:3b22d6d32a7a | 16 | typedef struct rgb_color { |
michaeljkoster | 25:3b22d6d32a7a | 17 | uint8_t red; /*!< A number between 0 and 255 that represents the brightness of the red component. */ |
michaeljkoster | 25:3b22d6d32a7a | 18 | uint8_t green; /*!< A number between 0 and 255 that represents the brightness of the green component. */ |
michaeljkoster | 25:3b22d6d32a7a | 19 | uint8_t blue; /*!< A number between 0 and 255 that represents the brightness of the blue component. */ |
michaeljkoster | 25:3b22d6d32a7a | 20 | } rgb_color; |
michaeljkoster | 25:3b22d6d32a7a | 21 | #endif |
DavidEGrayson | 0:06475317f283 | 22 | |
michaeljkoster | 25:3b22d6d32a7a | 23 | #ifdef _K64F |
michaeljkoster | 25:3b22d6d32a7a | 24 | extern "C" int led_strip_write_color_K64F(rgb_color *, volatile uint32_t * set, volatile uint32_t * clear, uint32_t mask); |
michaeljkoster | 25:3b22d6d32a7a | 25 | #else |
michaeljkoster | 25:3b22d6d32a7a | 26 | extern "C" int led_strip_write_color(rgb_color *, volatile uint32_t * set, volatile uint32_t * clear, uint32_t mask); |
michaeljkoster | 25:3b22d6d32a7a | 27 | #endif |
michaeljkoster | 25:3b22d6d32a7a | 28 | |
michaeljkoster | 25:3b22d6d32a7a | 29 | /** This class lets you control the addressable RGB LED strips from Pololu</a>, |
michaeljkoster | 25:3b22d6d32a7a | 30 | or any other LED strip based on the TM1804 chip. */ |
michaeljkoster | 25:3b22d6d32a7a | 31 | class PololuLedStrip |
michaeljkoster | 25:3b22d6d32a7a | 32 | { |
michaeljkoster | 25:3b22d6d32a7a | 33 | gpio_t gpio; |
michaeljkoster | 25:3b22d6d32a7a | 34 | uint32_t mask; |
michaeljkoster | 25:3b22d6d32a7a | 35 | __IO uint32_t *reg_set; |
michaeljkoster | 25:3b22d6d32a7a | 36 | __IO uint32_t *reg_clr; |
michaeljkoster | 25:3b22d6d32a7a | 37 | |
michaeljkoster | 25:3b22d6d32a7a | 38 | public: |
michaeljkoster | 25:3b22d6d32a7a | 39 | |
michaeljkoster | 25:3b22d6d32a7a | 40 | /** This constructor lets you make an led strip object by specifying the pin name. |
michaeljkoster | 25:3b22d6d32a7a | 41 | There are no restrictions on what pin you can choose. |
DavidEGrayson | 0:06475317f283 | 42 | |
michaeljkoster | 25:3b22d6d32a7a | 43 | Example: |
michaeljkoster | 25:3b22d6d32a7a | 44 | @code |
michaeljkoster | 25:3b22d6d32a7a | 45 | PololuLedStrip ledStrip(p8); |
michaeljkoster | 25:3b22d6d32a7a | 46 | @endcode |
michaeljkoster | 25:3b22d6d32a7a | 47 | */ |
michaeljkoster | 25:3b22d6d32a7a | 48 | PololuLedStrip(PinName pin); |
michaeljkoster | 25:3b22d6d32a7a | 49 | |
michaeljkoster | 25:3b22d6d32a7a | 50 | /** Writes the specified series of colors to the LED strip. |
michaeljkoster | 25:3b22d6d32a7a | 51 | @param colors should be a pointer to an array of rgb_color structs. |
michaeljkoster | 25:3b22d6d32a7a | 52 | @param count should be the number of colors to write. |
michaeljkoster | 25:3b22d6d32a7a | 53 | |
michaeljkoster | 25:3b22d6d32a7a | 54 | The first color in the array will be written to the LED closest to the data input connector. |
michaeljkoster | 25:3b22d6d32a7a | 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. |
michaeljkoster | 25:3b22d6d32a7a | 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. |
michaeljkoster | 25:3b22d6d32a7a | 57 | |
michaeljkoster | 25:3b22d6d32a7a | 58 | The colors are sent in series and each color takes about 45 microseconds to send. |
michaeljkoster | 25:3b22d6d32a7a | 59 | This function disables interrupts temporarily while it is running. |
michaeljkoster | 25:3b22d6d32a7a | 60 | This function waits for over 10 us at the end before returning to allow the colors to take effect. |
michaeljkoster | 25:3b22d6d32a7a | 61 | */ |
michaeljkoster | 25:3b22d6d32a7a | 62 | void write(rgb_color * colors, unsigned int count); |
michaeljkoster | 25:3b22d6d32a7a | 63 | |
michaeljkoster | 25:3b22d6d32a7a | 64 | /** This option defaults to <code>false</code>. |
michaeljkoster | 25:3b22d6d32a7a | 65 | Setting this to true changes the behavior of the write function, making it enable interrupts |
michaeljkoster | 25:3b22d6d32a7a | 66 | after each color is sent, about every 60 microseconds. |
michaeljkoster | 25:3b22d6d32a7a | 67 | This allows your program to respond to interrupts faster, but makes it possible for an interrupt |
michaeljkoster | 25:3b22d6d32a7a | 68 | that takes longer than 8 microseconds to screw up the transmission of colors to the LED strip. |
michaeljkoster | 25:3b22d6d32a7a | 69 | |
michaeljkoster | 25:3b22d6d32a7a | 70 | Example: |
michaeljkoster | 25:3b22d6d32a7a | 71 | @code |
michaeljkoster | 25:3b22d6d32a7a | 72 | PololuLedStrip::interruptFriendly = true; |
michaeljkoster | 25:3b22d6d32a7a | 73 | @endcode |
michaeljkoster | 25:3b22d6d32a7a | 74 | */ |
michaeljkoster | 25:3b22d6d32a7a | 75 | static bool interruptFriendly; |
michaeljkoster | 25:3b22d6d32a7a | 76 | |
michaeljkoster | 25:3b22d6d32a7a | 77 | static void calculateDelays(); |
michaeljkoster | 25:3b22d6d32a7a | 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 |