school project using led strip

Fork of PololuLedStrip by David Grayson

Files at this revision

API Documentation at this revision

Comitter:
DavidEGrayson
Date:
Wed Feb 27 00:28:26 2013 +0000
Child:
1:102307d9b701
Commit message:
Still working;

Changed in this revision

PololuLedStrip.h Show annotated file Show diff for this revision Revisions of this file
led_strip_write_color.s Show annotated file Show diff for this revision Revisions of this file
--- /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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/led_strip_write_color.s	Wed Feb 27 00:28:26 2013 +0000
@@ -0,0 +1,285 @@
+    AREA asm_func, CODE, READONLY
+    EXPORT led_strip_write_color
+
+led_strip_write_color
+    push    {r12, r7}
+   
+    ldr r12, [r0]      ; Read the next color.
+    rbit r12, r12      ; Reverse the order of the bits.
+    rev r12, r12       ; Reverse the order of the bytes.
+    mov r7, #24        ; Initialize the loop counter register.
+    
+send_led_strip_bit
+    str r3, [r1]       ; Drive the line high.
+    rrxs r12, r12      ; Rotate right through carry.
+    
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+        
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+        
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+        
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+        
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    
+    nop
+    nop
+    nop
+    nop
+    
+    it cc                ; If the bit to send it 0...
+    strcc r3, [r2]       ; Drive the line low.
+
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+
+
+    it cs                ; If the bit to send is 1...
+    strcs r3, [r2]       ; Drive the line low.
+    
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop   
+
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop
+    nop   
+    
+    sub r7, r7, #1               ; Decrement the loop counter.
+    cbz r7, led_strip_asm_end    ; If we have sent 24 bits, go to the end.
+    b send_led_strip_bit         ; Otherwise, go back and send another bit.
+    
+led_strip_asm_end
+    pop {r12, r7}
+    bx lr
+    
+    END
\ No newline at end of file