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

PololuLedStrip.cpp

Committer:
DavidEGrayson
Date:
2013-02-28
Revision:
4:d3b60bd43811
Parent:
1:102307d9b701
Child:
6:9d0530b7dae2

File content as of revision 4:d3b60bd43811:

#include "PololuLedStrip.h"

bool PololuLedStrip::interruptFriendly = false;

// 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.

PololuLedStrip::PololuLedStrip(PinName pinName)
{
    gpio_init(&gpio, pinName, PIN_OUTPUT);
}

void PololuLedStrip::write(rgb_color * colors, unsigned int count)
{
    __disable_irq();   // Disable interrupts temporarily because we don't want our pulse timing to be messed up.
    
    while(count--)
    {
        led_strip_write_color(colors++, gpio.reg_set, gpio.reg_clr, gpio.mask);
     
        if (interruptFriendly)
        {
            __enable_irq();
            __nop();
            __nop();
            __nop();
            __disable_irq();
        }
    }
        
    __enable_irq();   // Re-enable interrupts now that we are done.
    wait_us(24);      // Hold the line low for 24 microseconds to send the reset signal.
}