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:
thegink
Date:
Sat May 19 14:16:38 2018 +0000
Parent:
26:c3193bc73cff
Commit message:
Added #define for RGB/GRB order for WS2811 and WS2812b based strips, respectively. Ideally this should be selectable per instance, but it's late, and I'm tired.

Changed in this revision

PololuLedStrip.cpp Show annotated file Show diff for this revision Revisions of this file
PololuLedStrip.h 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	Wed Nov 01 23:11:49 2017 +0000
+++ b/PololuLedStrip.cpp	Sat May 19 14:16:38 2018 +0000
@@ -52,12 +52,21 @@
 
 void PololuLedStrip::write(rgb_color * colors, unsigned int count)
 {
+    uint8_t t;
     calculateDelays();
-
+    
     __disable_irq();   // Disable interrupts temporarily because we don't want our pulse timing to be messed up.
 
     while(count--)
     {
+
+#ifdef _POLOLU_ORDER_GRB
+        //swap red and green for WS2812b strips
+        t = colors->red;
+        colors->red = colors->green;
+        colors->green = t;
+#endif
+
         led_strip_write_color(colors, gpio.reg_set, gpio.reg_clr, gpio.mask);
         colors++;
          
--- a/PololuLedStrip.h	Wed Nov 01 23:11:49 2017 +0000
+++ b/PololuLedStrip.h	Sat May 19 14:16:38 2018 +0000
@@ -3,11 +3,20 @@
 #ifndef _POLOLU_LED_STRIP_H
 #define _POLOLU_LED_STRIP_H
 
+//If multiple colour orders are enabled, GRB will override RGB.
+
+//Use RGB colour order for WS2811 leds
+#define _POLOLU_ORDER_RGB
+
+//Use GRB colour order for WS2812b leds
+//#define _POLOLU_ORDER_GRB
+
+
 namespace Pololu
 {
     #ifndef _POLOLU_RGB_COLOR
     #define _POLOLU_RGB_COLOR
-    
+
     /** Represents an RGB color. */
     typedef struct rgb_color
     {
@@ -15,8 +24,7 @@
         uint8_t green; /*!< A number between 0 and 255 that represents the brightness of the green component. */
         uint8_t blue;  /*!< A number between 0 and 255 that represents the brightness of the blue component. */
     } rgb_color;
-    #endif
-
+#endif
     extern "C" int led_strip_write_color(rgb_color *, volatile uint32_t * set, volatile uint32_t * clear, uint32_t mask);
 
     /** This class lets you control the addressable RGB LED strips from Pololu</a>,
--- a/led_strip_write_color.s	Wed Nov 01 23:11:49 2017 +0000
+++ b/led_strip_write_color.s	Sat May 19 14:16:38 2018 +0000
@@ -28,14 +28,14 @@
     ; Push those registers so we can restore them later.
     push {r4, r5, r6, r7, lr}
 
-    ldrb r6, [r0, #1]  ; Load green.
-    lsls r6, r6, #24   ; Put green in MSB of r6.
-    ldrb r4, [r0, #0]  ; Load red.
+    ldrb r6, [r0, #0]  ; Load first colour.
+    lsls r6, r6, #24   ; Put first colour in MSB of r6.
+    ldrb r4, [r0, #1]  ; Load second colour.
     lsls r4, r4, #16
-    orrs r6, r6, r4    ; Put red in r6.
-    ldrb r4, [r0, #2]  ; Load blue.
+    orrs r6, r6, r4    ; Put second colour in r6.
+    ldrb r4, [r0, #2]  ; Load third colour.
     lsls r4, r4, #8
-    orrs r6, r6, r4    ; Put blue in r6.
+    orrs r6, r6, r4    ; Put third colour in r6.
    
     ; On the Cortex-M3 we simply did:
     ;    ldr r6, [r0]       ; Read the color.  Now we have:     xxBbGgRr