Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of PololuLedStrip by
PololuLedStrip.h@0:06475317f283, 2013-02-27 (annotated)
- Committer:
- DavidEGrayson
- Date:
- Wed Feb 27 00:28:26 2013 +0000
- Revision:
- 0:06475317f283
- Child:
- 1:102307d9b701
Still working;
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 | { |
DavidEGrayson | 0:06475317f283 | 8 | #ifndef _POLOLU_RGB_COLOR |
DavidEGrayson | 0:06475317f283 | 9 | #define _POLOLU_RGB_COLOR |
DavidEGrayson | 0:06475317f283 | 10 | typedef struct rgb_color |
DavidEGrayson | 0:06475317f283 | 11 | { |
DavidEGrayson | 0:06475317f283 | 12 | uint8_t red, green, blue; |
DavidEGrayson | 0:06475317f283 | 13 | } rgb_color; |
DavidEGrayson | 0:06475317f283 | 14 | #endif |
DavidEGrayson | 0:06475317f283 | 15 | |
DavidEGrayson | 0:06475317f283 | 16 | extern "C" int led_strip_write_color(rgb_color *, volatile uint32_t * set, volatile uint32_t * clear, uint32_t mask); |
DavidEGrayson | 0:06475317f283 | 17 | |
DavidEGrayson | 0:06475317f283 | 18 | class PololuLedStrip |
DavidEGrayson | 0:06475317f283 | 19 | { |
DavidEGrayson | 0:06475317f283 | 20 | gpio_t gpio; |
DavidEGrayson | 0:06475317f283 | 21 | public: |
DavidEGrayson | 0:06475317f283 | 22 | PololuLedStrip(PinName pin); |
DavidEGrayson | 0:06475317f283 | 23 | void write(rgb_color * colors, unsigned int count); |
DavidEGrayson | 0:06475317f283 | 24 | static bool interruptFriendly; |
DavidEGrayson | 0:06475317f283 | 25 | }; |
DavidEGrayson | 0:06475317f283 | 26 | |
DavidEGrayson | 0:06475317f283 | 27 | bool PololuLedStrip::interruptFriendly; |
DavidEGrayson | 0:06475317f283 | 28 | |
DavidEGrayson | 0:06475317f283 | 29 | PololuLedStrip::PololuLedStrip(PinName pinName) |
DavidEGrayson | 0:06475317f283 | 30 | { |
DavidEGrayson | 0:06475317f283 | 31 | gpio_init(&gpio, pinName, PIN_OUTPUT); |
DavidEGrayson | 0:06475317f283 | 32 | } |
DavidEGrayson | 0:06475317f283 | 33 | |
DavidEGrayson | 0:06475317f283 | 34 | void PololuLedStrip::write(rgb_color * colors, unsigned int count) |
DavidEGrayson | 0:06475317f283 | 35 | { |
DavidEGrayson | 0:06475317f283 | 36 | __disable_irq(); // Disable interrupts temporarily because we don't want our pulse timing to be messed up. |
DavidEGrayson | 0:06475317f283 | 37 | |
DavidEGrayson | 0:06475317f283 | 38 | while(count--) |
DavidEGrayson | 0:06475317f283 | 39 | { |
DavidEGrayson | 0:06475317f283 | 40 | led_strip_write_color(colors++, gpio.reg_set, gpio.reg_clr, gpio.mask); |
DavidEGrayson | 0:06475317f283 | 41 | |
DavidEGrayson | 0:06475317f283 | 42 | if (interruptFriendly) |
DavidEGrayson | 0:06475317f283 | 43 | { |
DavidEGrayson | 0:06475317f283 | 44 | __enable_irq(); |
DavidEGrayson | 0:06475317f283 | 45 | __nop(); |
DavidEGrayson | 0:06475317f283 | 46 | __nop(); |
DavidEGrayson | 0:06475317f283 | 47 | __nop(); |
DavidEGrayson | 0:06475317f283 | 48 | __disable_irq(); |
DavidEGrayson | 0:06475317f283 | 49 | } |
DavidEGrayson | 0:06475317f283 | 50 | } |
DavidEGrayson | 0:06475317f283 | 51 | __enable_irq(); // Re-enable interrupts now that we are done. |
DavidEGrayson | 0:06475317f283 | 52 | wait_us(24); // Hold the line low for 24 microseconds to send the reset signal. |
DavidEGrayson | 0:06475317f283 | 53 | } |
DavidEGrayson | 0:06475317f283 | 54 | } |
DavidEGrayson | 0:06475317f283 | 55 | |
DavidEGrayson | 0:06475317f283 | 56 | using namespace Pololu; |
DavidEGrayson | 0:06475317f283 | 57 | |
DavidEGrayson | 0:06475317f283 | 58 | #endif |