DMA-enabled high data rate driver for Heroic Robotics LED strips.

Dependents:   FastPixelDemo

Committer:
heroic
Date:
Sat May 31 18:41:56 2014 +0000
Revision:
10:5b3be78ce6bd
Initial commit of FastPixelLPD8806 open source driver.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
heroic 10:5b3be78ce6bd 1 /***************************************************************************/
heroic 10:5b3be78ce6bd 2 // DMA-enabled high data rate driver for Heroic Robotics FastPixel strips.
heroic 10:5b3be78ce6bd 3 // Written by Jas Strong <jasmine@heroicrobotics.com>
heroic 10:5b3be78ce6bd 4 // Copyright (c) 2013-2014 Heroic Robotics, Inc.
heroic 10:5b3be78ce6bd 5 //
heroic 10:5b3be78ce6bd 6 // FastPixel is a family of high performance LED strips available from
heroic 10:5b3be78ce6bd 7 // Heroic Robotics, Inc. http://heroicrobotics.com/ - check them out!
heroic 10:5b3be78ce6bd 8 //
heroic 10:5b3be78ce6bd 9 // These strips are capable of supporting 18 Mbit/sec when run on PixelPusher
heroic 10:5b3be78ce6bd 10 // hardware; your performance on mbed is likely to be somewhat lower due to
heroic 10:5b3be78ce6bd 11 // the lack of high performance driver chips on the SPI lines.
heroic 10:5b3be78ce6bd 12 //
heroic 10:5b3be78ce6bd 13 // Heroic Robotics also sells a family of dedicated LED controllers called
heroic 10:5b3be78ce6bd 14 // PixelPusher- almost certainly the best LED controller in the world.
heroic 10:5b3be78ce6bd 15 //
heroic 10:5b3be78ce6bd 16 // Permission is hereby granted, free of charge, to any person obtaining a copy
heroic 10:5b3be78ce6bd 17 // of this software and associated documentation files (the "Software"), to deal
heroic 10:5b3be78ce6bd 18 // in the Software without restriction, including without limitation the rights
heroic 10:5b3be78ce6bd 19 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
heroic 10:5b3be78ce6bd 20 // copies of the Software, and to permit persons to whom the Software is
heroic 10:5b3be78ce6bd 21 // furnished to do so, subject to the following conditions:
heroic 10:5b3be78ce6bd 22 //
heroic 10:5b3be78ce6bd 23 // The above copyright notice and this permission notice shall be included in
heroic 10:5b3be78ce6bd 24 // all copies or substantial portions of the Software.
heroic 10:5b3be78ce6bd 25 //
heroic 10:5b3be78ce6bd 26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
heroic 10:5b3be78ce6bd 27 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
heroic 10:5b3be78ce6bd 28 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
heroic 10:5b3be78ce6bd 29 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
heroic 10:5b3be78ce6bd 30 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
heroic 10:5b3be78ce6bd 31 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
heroic 10:5b3be78ce6bd 32 // THE SOFTWARE.
heroic 10:5b3be78ce6bd 33 //
heroic 10:5b3be78ce6bd 34 // Some portions originally from:
heroic 10:5b3be78ce6bd 35 //
heroic 10:5b3be78ce6bd 36 // Mbed library to control LPD8806-based RGB LED Strips
heroic 10:5b3be78ce6bd 37 // (c) 2011 Jelmer Tiete
heroic 10:5b3be78ce6bd 38 // This library is ported from the Arduino implementation of Adafruit Industries
heroic 10:5b3be78ce6bd 39 // found at: http://github.com/adafruit/LPD8806
heroic 10:5b3be78ce6bd 40 // and their strips: http://www.adafruit.com/products/306
heroic 10:5b3be78ce6bd 41 // Released under the MIT License: http://mbed.org/license/mit
heroic 10:5b3be78ce6bd 42 //
heroic 10:5b3be78ce6bd 43 // Parameterized and modified to use soft SPI.
heroic 10:5b3be78ce6bd 44 // Jas Strong <jasmine@electronpusher.org>
heroic 10:5b3be78ce6bd 45 // Then remonstered to use hardware SPI for blast mode.
heroic 10:5b3be78ce6bd 46 /*****************************************************************************/
heroic 10:5b3be78ce6bd 47
heroic 10:5b3be78ce6bd 48 // Heavily modified by Jas Strong, 2012-10-04
heroic 10:5b3be78ce6bd 49 // Changed to use a virtual base class and to use software SPI.
heroic 10:5b3be78ce6bd 50
heroic 10:5b3be78ce6bd 51 #include "mbed.h"
heroic 10:5b3be78ce6bd 52 #include "LedStrip.h"
heroic 10:5b3be78ce6bd 53 #include "MODDMA.h"
heroic 10:5b3be78ce6bd 54
heroic 10:5b3be78ce6bd 55 #ifndef MBED_FastPixelLPD8806_H
heroic 10:5b3be78ce6bd 56 #define MBED_FastPixelLPD8806_H
heroic 10:5b3be78ce6bd 57
heroic 10:5b3be78ce6bd 58 class FastPixelLPD8806 : public LedStrip {
heroic 10:5b3be78ce6bd 59
heroic 10:5b3be78ce6bd 60 public:
heroic 10:5b3be78ce6bd 61
heroic 10:5b3be78ce6bd 62 FastPixelLPD8806(PinName dataPin, PinName clockPin, int n);
heroic 10:5b3be78ce6bd 63 virtual void begin(void);
heroic 10:5b3be78ce6bd 64 virtual void show(void);
heroic 10:5b3be78ce6bd 65 virtual void blank(void);
heroic 10:5b3be78ce6bd 66 virtual void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b);
heroic 10:5b3be78ce6bd 67 virtual void setPackedPixels(uint8_t * buffer, uint32_t n);
heroic 10:5b3be78ce6bd 68 virtual void setPixelB(uint16_t n, uint8_t b);
heroic 10:5b3be78ce6bd 69 virtual void setPixelG(uint16_t n, uint8_t g);
heroic 10:5b3be78ce6bd 70 virtual void setPixelR(uint16_t n, uint8_t r);
heroic 10:5b3be78ce6bd 71 virtual void setPixelColor(uint16_t n, uint32_t c);
heroic 10:5b3be78ce6bd 72 virtual uint16_t numPixels(void);
heroic 10:5b3be78ce6bd 73 virtual uint32_t Color(uint8_t, uint8_t, uint8_t);
heroic 10:5b3be78ce6bd 74 virtual uint32_t total_luminance(void);
heroic 10:5b3be78ce6bd 75
heroic 10:5b3be78ce6bd 76 private:
heroic 10:5b3be78ce6bd 77 SPI _spi;
heroic 10:5b3be78ce6bd 78 void write(uint8_t byte);
heroic 10:5b3be78ce6bd 79 uint8_t *pixels; // Holds LED color values
heroic 10:5b3be78ce6bd 80 uint16_t numLEDs; // Number of RGB LEDs in strand
heroic 10:5b3be78ce6bd 81 MODDMA_Config * dma_config;
heroic 10:5b3be78ce6bd 82 int strip_num;
heroic 10:5b3be78ce6bd 83
heroic 10:5b3be78ce6bd 84
heroic 10:5b3be78ce6bd 85 uint32_t clock_mask;
heroic 10:5b3be78ce6bd 86 uint32_t data_mask;
heroic 10:5b3be78ce6bd 87
heroic 10:5b3be78ce6bd 88 };
heroic 10:5b3be78ce6bd 89 #endif