WS2812B

Dependents:   high speed light Bracelet

Fork of PololuLedStrip by David Grayson

Files at this revision

API Documentation at this revision

Comitter:
DavidEGrayson
Date:
Fri Mar 01 04:34:54 2013 +0000
Parent:
11:e00ba70ac54c
Child:
13:9c72841ec45e
Commit message:
Introduced the delay_fudges array. The code still works for the M0.

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 04:16:44 2013 +0000
+++ b/PololuLedStrip.cpp	Fri Mar 01 04:34:54 2013 +0000
@@ -4,6 +4,8 @@
 
 uint8_t led_strip_write_delays[3];
 
+static const uint8_t delay_fudges[] = { 32, 0, 0 };
+
 void PololuLedStrip::calculateDelays()
 {
     // Get the clock frequency in MHz.
@@ -14,15 +16,24 @@
     
     // 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;
+    led_strip_write_delays[1] = 600*f_mhz/1000;
     
     // 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;
+    led_strip_write_delays[2] = 1200*f_mhz/1000;
     
-    led_strip_write_delays[0] <<= 1;
-    led_strip_write_delays[1] <<= 1;
-    led_strip_write_delays[2] <<= 1;
+    for(int i = 0; i < 3; i++)
+    {
+        if (led_strip_write_delays[i] < delay_fudges[i])
+        {
+            led_strip_write_delays[i] = 0;
+        }
+        else
+        {
+            led_strip_write_delays[i] -= delay_fudges[i];
+            led_strip_write_delays[i] <<= 1;
+        }
+    }
 }
 
 PololuLedStrip::PololuLedStrip(PinName pinName)
--- a/led_strip_write_color.s	Fri Mar 01 04:16:44 2013 +0000
+++ b/led_strip_write_color.s	Fri Mar 01 04:34:54 2013 +0000
@@ -54,7 +54,7 @@
     ldr r4, =0x80000000
     tst r6, r4
     bne delay1
-    str r3, [r2]     ; If the bit to send it 0, drive the line low.
+    str r3, [r2]       ; If the bit to send it 0, drive the line low.
 delay1
 
     delay #1
@@ -62,17 +62,15 @@
     ldr r4, =0x80000000
     tst r6, r4
     beq delay2
-    str r3, [r2]     ; If the bit to send is 1, drive the line low.
+    str r3, [r2]       ; If the bit to send is 1, drive the line low.
 delay2
     
     delay #2
     
-    lsls r6, r6, #1              ; Shift color bits.
+    lsls r6, r6, #1           ; Shift color bits.
     subs r7, r7, #1           ; Decrement the loop counter.
-    bne send_led_strip_bit    ; Send another bit if we have not reached zero.
-    
-led_strip_asm_end
-    pop {r4, r5, r6, r7, pc}
+    bne send_led_strip_bit    ; Send another bit if we have not reached zero.   
+    pop {r4, r5, r6, r7, pc}  ; Otherwise, restore the registers and return.
     
 
 delay_region