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
Revision 6:9d0530b7dae2, committed 2013-03-01
- Comitter:
- DavidEGrayson
- Date:
- Fri Mar 01 00:31:24 2013 +0000
- Parent:
- 5:690fdfb595de
- Child:
- 7:9a088f042ee0
- Commit message:
- Successfully read the delay amount from a table.
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 00:05:26 2013 +0000
+++ b/PololuLedStrip.cpp Fri Mar 01 00:31:24 2013 +0000
@@ -5,6 +5,8 @@
// TODO: read clock frequency from SystemCoreClock and use that to make this work on different boards.
// calculate the three delays needed and pass them to the assembly. The assembly can implement them with computed jumps.
+uint8_t led_strip_write_delays[3];
+
PololuLedStrip::PololuLedStrip(PinName pinName)
{
gpio_init(&gpio, pinName, PIN_OUTPUT);
@@ -14,6 +16,12 @@
{
__disable_irq(); // Disable interrupts temporarily because we don't want our pulse timing to be messed up.
+ int f = SystemCoreClock/1000000;
+ led_strip_write_delays[0] = 700*f/1000 - 10;
+ led_strip_write_delays[1] = 600*f/1000 - 10;
+ led_strip_write_delays[2] = 1200*f/1000 - 10;
+ led_strip_write_delays[0] = 59;
+
while(count--)
{
led_strip_write_color(colors++, gpio.reg_set, gpio.reg_clr, gpio.mask);
--- a/led_strip_write_color.s Fri Mar 01 00:05:26 2013 +0000
+++ b/led_strip_write_color.s Fri Mar 01 00:31:24 2013 +0000
@@ -1,5 +1,6 @@
AREA asm_func, CODE, READONLY
EXPORT led_strip_write_color
+ IMPORT led_strip_write_delays
led_strip_write_color
; Register usage:
@@ -10,12 +11,13 @@
; R3: pin mask
; Additionally, we use these registers:
; R4: temporary register
+ ; R5: temporary register
; 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, r12, r7, lr}
+ push {r4, r5, r12, r7, lr}
ldr r12, [r0] ; Read the next color.
rbit r12, r12 ; Reverse the order of the bits.
@@ -26,8 +28,11 @@
str r3, [r1] ; Drive the line high.
rrxs r12, r12 ; Rotate right through carry.
+ ldr r5, =led_strip_write_delays
+ ldrb r5, [r5, #0]
+ lsl r5, r5, #1
ldr r4, =delay_region_end
- sub r4, r4, #59*2
+ sub r4, r4, r5
blx r4
it cc ; If the bit to send it 0...
@@ -44,11 +49,11 @@
add r4, r4, #68
blx r4
- subs r7, r7, #1 ; Decrement the loop counter.
+ 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, r12, r7, lr}
+ pop {r4, r5, r12, r7, lr}
bx lr
