school project using led strip

Fork of PololuLedStrip by David Grayson

Revision:
0:06475317f283
Child:
1:102307d9b701
diff -r 000000000000 -r 06475317f283 PololuLedStrip.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PololuLedStrip.h	Wed Feb 27 00:28:26 2013 +0000
@@ -0,0 +1,58 @@
+#include "mbed.h"
+
+#ifndef _POLOLU_LED_STRIP_H
+#define _POLOLU_LED_STRIP_H
+
+namespace Pololu
+{
+    #ifndef _POLOLU_RGB_COLOR
+    #define _POLOLU_RGB_COLOR
+    typedef struct rgb_color
+    {
+        uint8_t red, green, blue;
+    } rgb_color;
+    #endif
+
+    extern "C" int led_strip_write_color(rgb_color *, volatile uint32_t * set, volatile uint32_t * clear, uint32_t mask);
+
+    class PololuLedStrip
+    {
+        gpio_t gpio;
+        public:
+        PololuLedStrip(PinName pin);
+        void write(rgb_color * colors, unsigned int count);
+        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;
+
+#endif
\ No newline at end of file