debug

Fork of PololuLedStripx by Michael Koster

PololuLedStrip.h

Committer:
DavidEGrayson
Date:
2013-02-27
Revision:
0:06475317f283
Child:
1:102307d9b701

File content as of revision 0:06475317f283:

#include "mbed.h"

#ifndef _POLOLU_LED_STRIP_H
#define _POLOLU_LED_STRIP_H

namespace Pololu
{
    #ifndef _POLOLU_RGB_COLOR
    #define _POLOLU_RGB_COLOR
    typedef struct rgb_color
    {
        uint8_t red, green, blue;
    } rgb_color;
    #endif

    extern "C" int led_strip_write_color(rgb_color *, volatile uint32_t * set, volatile uint32_t * clear, uint32_t mask);

    class PololuLedStrip
    {
        gpio_t gpio;
        public:
        PololuLedStrip(PinName pin);
        void write(rgb_color * colors, unsigned int count);
        static bool interruptFriendly;
    };

    bool PololuLedStrip::interruptFriendly;

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

using namespace Pololu;

#endif