This library lets you control the addressable RGB LED strips from Pololu Robotics. Forked to add selectable colour order (Support RGB or GRB Leds)

Fork of PololuLedStrip by David Grayson

Files at this revision

API Documentation at this revision

Comitter:
DavidEGrayson
Date:
Fri Mar 01 02:05:21 2013 +0000
Parent:
7:9a088f042ee0
Child:
9:6ffb85d69eaf
Commit message:
Changed the registers so that the push and pop commands can work on the Cortex M0 (LPC 11U24). There are still more things to fix though.

Changed in this revision

PololuLedStrip.cpp 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
--- a/PololuLedStrip.cpp	Fri Mar 01 01:16:48 2013 +0000
+++ b/PololuLedStrip.cpp	Fri Mar 01 02:05:21 2013 +0000
@@ -6,20 +6,30 @@
 
 void PololuLedStrip::calculateDelays()
 {
-    int fmhz = SystemCoreClock / 1000000;
-    led_strip_write_delays[0] = 700*fmhz/1000 - 25;
-    led_strip_write_delays[1] = 600*fmhz/1000 - 19;
-    led_strip_write_delays[2] = 1200*fmhz/1000 - 24;
+    // Get the clock frequency in MHz.
+    int f_mhz = SystemCoreClock / 1000000;
+    
+    // Arrange for a 700 nanosecond delay between the rise time and the fall time for a 0 bit.
+    led_strip_write_delays[0] = 700*f_mhz/1000 - 25;
+    
+    // Arrange for a 600 nanosecond delay between the fall time for a 0 bit and the fall time for a 1 bit.
+    // This means the pulses representing a 1 will be 700+600 = 1300 nanoseconds.
+    led_strip_write_delays[1] = 600*f_mhz/1000 - 19;
+    
+    // Arrange for a 1200 nanosecond delay between the fall time for a 1 bit and rise time of the next bit.
+    // This means the period of the signal will be 2500 nanoseconds.
+    led_strip_write_delays[2] = 1200*f_mhz/1000 - 24;
 }
 
 PololuLedStrip::PololuLedStrip(PinName pinName)
 {
     gpio_init(&gpio, pinName, PIN_OUTPUT);
-    calculateDelays();    // Assumption
 }
 
 void PololuLedStrip::write(rgb_color * colors, unsigned int count)
 {
+    calculateDelays();
+
     __disable_irq();   // Disable interrupts temporarily because we don't want our pulse timing to be messed up.
 
     while(count--)
--- a/led_strip_write_color.s	Fri Mar 01 01:16:48 2013 +0000
+++ b/led_strip_write_color.s	Fri Mar 01 02:05:21 2013 +0000
@@ -22,20 +22,20 @@
     ; Additionally, we use these registers:
     ;   R4:  temporary register
     ;   R5:  temporary register
+    ;   R6: shift register that holds the 24-bit color
     ;   R7:  the number of bits we still need to send
-    ;   R12: shift register that holds the 24-bit color
     ;   R13: Link Register, holds return addresses.
 
-    push {r4, r5, r12, r7, lr}  ; Push those registers so we can restore them later.
+    push {r4, r5, r6, r7, lr}  ; Push those registers so we can restore them later.
     
-    ldr r12, [r0]      ; Read the color.  Now we have:     xxBbGgRr
-    rbit r12, r12      ; Reverse the order of the bits:    rRgGbBxx
-    rev r12, r12       ; Reverse the order of the bytes:   xxbBgGrR
+    ldr r6, [r0]       ; Read the color.  Now we have:     xxBbGgRr
+    rbit r6, r6        ; Reverse the order of the bits:    rRgGbBxx
+    rev r6, r6         ; Reverse the order of the bytes:   xxbBgGrR
     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.
+    rrxs r6, r6        ; Rotate right through carry.
     
     delay #0
     
@@ -53,7 +53,7 @@
     bne send_led_strip_bit    ; Send another bit if we have not reached zero.
     
 led_strip_asm_end
-    pop {r4, r5, r12, r7, lr}
+    pop {r4, r5, r6, r7, lr}
     bx lr