This is an example program for the PololuLedStrip library. It generates a simple moving gradient pattern.

Dependencies:   PololuLedStrip mbed LedStripGradient

Dependents:   LedStripGradient led_phare_crf

For more information, see the PololuLedStrip library.

Files at this revision

API Documentation at this revision

Comitter:
DavidEGrayson
Date:
Tue Feb 26 02:04:07 2013 +0000
Parent:
0:290d713ed3e1
Child:
2:bd6fe6d2948d
Commit message:
Added a second parameter to the assembly, but I am not sure how to access it.

Changed in this revision

led_strip.s Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/led_strip.s	Tue Feb 26 01:49:34 2013 +0000
+++ b/led_strip.s	Tue Feb 26 02:04:07 2013 +0000
@@ -10,18 +10,13 @@
 ; for all of the GPIO register info and addresses
 ; Pinnames.h has the mbed modules pin port and bit connections
 ;
-; Load GPIO Port 1 base address in register R1 
-    LDR     R1, =0x2009C020 ; 0x2009C020 = GPIO port 1 base address
-; Move bit mask in register R2 for bit 18 only
+    push    {R9}
+    LDR     R9, =0x2009C020 ; 0x2009C020 = GPIO port 1 base address
     MOV.W   R2, #0x040000   ; 0x040000 = 1<<18 all "0"s with a "1" in bit 18
-; value passed from C compiler code is in R0 - compare to a "0" 
-    CMP     R0, #0          ; value == 0 ?
-; (If-Then-Else) on next two instructions using equal cond from the zero flag
+    CMP     R1, #0          ; value == 0 ?
     ITE EQ
-; STORE if EQ - clear led 1 port bit using GPIO FIOCLR register and mask
-    STREQ   R2, [R1,#0x1C]  ; if==0, clear LED1 bit
-; STORE if NE - set led 1 port bit using GPIO FIOSET register and mask
-    STRNE   R2, [R1,#0x18]  ; if==1, set LED1 bit
-; Return to C using link register (Branch indirect using LR - a return)
+    STREQ   R2, [R9,#0x1C]  ; if==0, clear LED1 bit
+    STRNE   R2, [R9,#0x18]  ; if==1, set LED1 bit
+    pop     {R9}
     BX      LR
     END
\ No newline at end of file
--- a/main.cpp	Tue Feb 26 01:49:34 2013 +0000
+++ b/main.cpp	Tue Feb 26 02:04:07 2013 +0000
@@ -1,113 +1,118 @@
-#include "mbed.h"
-#include "gpio_api.h"
-
-extern "C" int my_asm(int value);
-
-namespace Pololu
-{
-  #ifndef _POLOLU_RGB_COLOR
-  #define _POLOLU_RGB_COLOR
-  typedef struct rgb_color
-  {
-    uint8_t red, green, blue;
-  } rgb_color;
-  #endif
-
-  class PololuLedStrip
-  {
-    static bool interruptFriendly;
-    public:
-    gpio_t gpio;
-    PololuLedStrip(PinName pin);
-    void write(rgb_color *, unsigned int count);
-  };
-
-  bool PololuLedStrip::interruptFriendly;
-
-  PololuLedStrip::PololuLedStrip(PinName pinName)
-  {
-    gpio_init(&gpio, pinName, PIN_OUTPUT);
-  }
-
-  void PololuLedStrip::write(rgb_color * colors, unsigned int count)
-  {
-    uint32_t pinValue = gpio.pin & 0x1F;  // Mimicing mbed/libraries/mbed/vendor/NXP/capi/gpio_api.c
-    
-    __disable_irq();   // Disable interrupts temporarily because we don't want our pulse timing to be messed up.
-    
-    while(count--)
-    {
-    /**
-      // Send a color to the LED strip.
-      // The assembly below also increments the 'colors' pointer,
-      // it will be pointing to the next color at the end of this loop.
-      __ASM volatile(
-        "ldr r12, [%0], #3\n"   // Read the next color and advance the pointer.
-        "rbit r12, r12\n"       // Reverse the order of the bits.
-        "rev r12, r12\n"        // Reverse the order of the bytes.
-        "mov r3, #24\n"         // Initialize the loop counter register.
-
-        "send_led_strip_bit%=:\n"
-        "str %[val], %[set]\n"            // Drive the line high.
-        "rrxs r12, r12\n"                 // Rotate right through carry.
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n"
-        "it cc\n" "strcc %[val], %[clear]\n"  // If the bit to send is 0, set the line low now.
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "it cs\n" "strcs %[val], %[clear]\n"  // If the bit to send is 1, set the line low now.
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
-
-        "sub r3, r3, #1\n"                // Decrement the loop counter.
-        "cbz r3, led_strip_asm_end%=\n"   // If we have sent 24 bits, go to the end.
-        "b send_led_strip_bit%=\n"
-        
-        "led_strip_asm_end%=:\n"
-
-      : "=r" (colors)
-      : "0" (colors),
-        [set] "m" (gpio.reg_set),
-        [clear] "m" (gpio.reg_clr),
-        [val] "r" (pinValue)
-      : "r3", "r12", "cc"
-      );**/
-      
-      if (interruptFriendly)
-      {
-        __enable_irq();
-        //asm volatile("nop\n");
-        __disable_irq();
-      }
-    }
-    __enable_irq();          // Re-enable interrupts now that we are done.
-    //delayMicroseconds(24);  // Hold the line low for 24 microseconds to send the reset signal.
-  }
-
-}
-
-using namespace Pololu;
-
-DigitalOut myled(LED1);
-
-PololuLedStrip ledStrip(p9);
-
-int main() {
-    while(1) {
-        //myled = 1;
-        my_asm(1);
-        wait(0.2);
-        my_asm(0);
-        //myled = 0;
-        wait(1);
-    }
-}
+#include "mbed.h"
+#include "gpio_api.h"
+
+//extern "C" int my_asm(volatile uint32_t * set, int value);
+extern "C" int my_asm(int x, int value);
+
+namespace Pololu
+{
+  #ifndef _POLOLU_RGB_COLOR
+  #define _POLOLU_RGB_COLOR
+  typedef struct rgb_color
+  {
+    uint8_t red, green, blue;
+  } rgb_color;
+  #endif
+
+  class PololuLedStrip
+  {
+    static bool interruptFriendly;
+    public:
+    gpio_t gpio;
+    PololuLedStrip(PinName pin);
+    void write(rgb_color *, unsigned int count);
+  };
+
+  bool PololuLedStrip::interruptFriendly;
+
+  PololuLedStrip::PololuLedStrip(PinName pinName)
+  {
+    gpio_init(&gpio, pinName, PIN_OUTPUT);
+  }
+
+  void PololuLedStrip::write(rgb_color * colors, unsigned int count)
+  {
+    uint32_t pinValue = gpio.pin & 0x1F;  // Mimicing mbed/libraries/mbed/vendor/NXP/capi/gpio_api.c
+    
+    __disable_irq();   // Disable interrupts temporarily because we don't want our pulse timing to be messed up.
+    
+    while(count--)
+    {
+    /**
+      // Send a color to the LED strip.
+      // The assembly below also increments the 'colors' pointer,
+      // it will be pointing to the next color at the end of this loop.
+      __ASM volatile(
+        "ldr r12, [%0], #3\n"   // Read the next color and advance the pointer.
+        "rbit r12, r12\n"       // Reverse the order of the bits.
+        "rev r12, r12\n"        // Reverse the order of the bytes.
+        "mov r3, #24\n"         // Initialize the loop counter register.
+
+        "send_led_strip_bit%=:\n"
+        "str %[val], %[set]\n"            // Drive the line high.
+        "rrxs r12, r12\n"                 // Rotate right through carry.
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n"
+        "it cc\n" "strcc %[val], %[clear]\n"  // If the bit to send is 0, set the line low now.
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "it cs\n" "strcs %[val], %[clear]\n"  // If the bit to send is 1, set the line low now.
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+        "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" "nop\n"
+
+        "sub r3, r3, #1\n"                // Decrement the loop counter.
+        "cbz r3, led_strip_asm_end%=\n"   // If we have sent 24 bits, go to the end.
+        "b send_led_strip_bit%=\n"
+        
+        "led_strip_asm_end%=:\n"
+
+      : "=r" (colors)
+      : "0" (colors),
+        [set] "m" (gpio.reg_set),
+        [clear] "m" (gpio.reg_clr),
+        [val] "r" (pinValue)
+      : "r3", "r12", "cc"
+      );**/
+      
+      if (interruptFriendly)
+      {
+        __enable_irq();
+        //asm volatile("nop\n");
+        __disable_irq();
+      }
+    }
+    __enable_irq();          // Re-enable interrupts now that we are done.
+    //delayMicroseconds(24);  // Hold the line low for 24 microseconds to send the reset signal.
+  }
+
+}
+
+using namespace Pololu;
+
+DigitalOut myled(LED1);
+DigitalOut myled2(LED2);
+
+PololuLedStrip ledStrip(p9);
+
+int main() {
+    gpio_t gpio;
+    gpio_init(&gpio, LED1, PIN_OUTPUT);
+
+    while(1) {
+        myled2 = 1;
+        my_asm(1, 1);
+        wait(0.2);
+        my_asm(0, 0);
+        myled2 = 0;
+        wait(1);
+    }
+}