Code fonctionnel pour le chenillard de led du phare GE1

Dependencies:   mbed LedStripGradient PololuLedStrip

Files at this revision

API Documentation at this revision

Comitter:
DavidEGrayson
Date:
Tue Feb 26 01:49:34 2013 +0000
Child:
1:ac1550d65296
Commit message:
This worked for blinking the LED.

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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/led_strip.s	Tue Feb 26 01:49:34 2013 +0000
@@ -0,0 +1,27 @@
+    AREA asm_func, CODE, READONLY
+; Export my_asm function location so that C compiler can find it and link
+    EXPORT my_asm
+my_asm
+;
+; ARM Assembly language function to set LED1 bit to a value passed from C   
+; LED1 gets value (passed from C compiler in R0)
+; LED1 is on GPIO port 1 bit 18
+; See Chapter 9 in the LPC1768 User Manual
+; 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
+    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
+    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)
+    BX      LR
+    END
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Feb 26 01:49:34 2013 +0000
@@ -0,0 +1,113 @@
+#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);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Feb 26 01:49:34 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/3d0ef94e36ec
\ No newline at end of file