Forked

Fork of Multi_WS2811 by Ned Konz

Committer:
antoniorohit
Date:
Tue Dec 09 23:42:23 2014 +0000
Revision:
1:39db2057b5da
Parent:
0:a8535703f23b
Forked;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bikeNomad 0:a8535703f23b 1 // Mbed library to control WS2801-based RGB LED Strips
bikeNomad 0:a8535703f23b 2 // some portions (c) 2011 Jelmer Tiete
bikeNomad 0:a8535703f23b 3 // This library is ported from the Arduino implementation of Adafruit Industries
bikeNomad 0:a8535703f23b 4 // found at: http://github.com/adafruit/LPD8806
bikeNomad 0:a8535703f23b 5 // and their strips: http://www.adafruit.com/products/306
bikeNomad 0:a8535703f23b 6 // Released under the MIT License: http://mbed.org/license/mit
bikeNomad 0:a8535703f23b 7 //
bikeNomad 0:a8535703f23b 8 /*****************************************************************************/
bikeNomad 0:a8535703f23b 9
bikeNomad 0:a8535703f23b 10 // Heavily modified by Jas Strong, 2012-10-04
bikeNomad 0:a8535703f23b 11 // Changed to use a virtual base class and to use software SPI.
bikeNomad 0:a8535703f23b 12 //
bikeNomad 0:a8535703f23b 13 // Modified by Ned Konz, December 2013.
bikeNomad 0:a8535703f23b 14 // Using three-phase DMA ala Paul Stoffegren's version.
bikeNomad 0:a8535703f23b 15
bikeNomad 0:a8535703f23b 16 #ifndef MBED_WS2811_H
bikeNomad 0:a8535703f23b 17 #define MBED_WS2811_H
bikeNomad 0:a8535703f23b 18
bikeNomad 0:a8535703f23b 19 #include "mbed.h"
bikeNomad 0:a8535703f23b 20 #include "LedStrip.h"
bikeNomad 0:a8535703f23b 21
bikeNomad 0:a8535703f23b 22 #define MAX_LEDS_PER_STRIP 60
bikeNomad 0:a8535703f23b 23
bikeNomad 0:a8535703f23b 24 extern "C" void DMA0_IRQHandler();
bikeNomad 0:a8535703f23b 25 extern "C" void TPM0_IRQHandler();
bikeNomad 0:a8535703f23b 26
bikeNomad 0:a8535703f23b 27 class WS2811 : public LedStrip
bikeNomad 0:a8535703f23b 28 {
bikeNomad 0:a8535703f23b 29 public:
bikeNomad 0:a8535703f23b 30 WS2811(unsigned n, unsigned pinNumber);
bikeNomad 0:a8535703f23b 31
bikeNomad 0:a8535703f23b 32 virtual void begin();
bikeNomad 0:a8535703f23b 33 virtual void show();
bikeNomad 0:a8535703f23b 34 virtual void blank();
bikeNomad 0:a8535703f23b 35
bikeNomad 0:a8535703f23b 36 static void startDMA();
bikeNomad 0:a8535703f23b 37
bikeNomad 0:a8535703f23b 38 private:
bikeNomad 0:a8535703f23b 39 uint32_t pinMask;
bikeNomad 0:a8535703f23b 40
bikeNomad 0:a8535703f23b 41 void writePixel(unsigned n, uint8_t *p);
bikeNomad 0:a8535703f23b 42
bikeNomad 0:a8535703f23b 43 // Class Static:
bikeNomad 0:a8535703f23b 44
bikeNomad 0:a8535703f23b 45 static bool initialized;
bikeNomad 0:a8535703f23b 46 static uint32_t enabledPins;
bikeNomad 0:a8535703f23b 47 static volatile bool dma_done;
bikeNomad 0:a8535703f23b 48 static void wait_for_dma_done() { while (!dma_done) __WFI(); }
bikeNomad 0:a8535703f23b 49
bikeNomad 0:a8535703f23b 50 static void writeByte(uint8_t byte, uint32_t mask, uint32_t *dest);
bikeNomad 0:a8535703f23b 51
bikeNomad 0:a8535703f23b 52 static void hw_init();
bikeNomad 0:a8535703f23b 53 static void io_init();
bikeNomad 0:a8535703f23b 54 static void clock_init();
bikeNomad 0:a8535703f23b 55 static void dma_init();
bikeNomad 0:a8535703f23b 56 static void tpm_init();
bikeNomad 0:a8535703f23b 57 static void dma_data_init();
bikeNomad 0:a8535703f23b 58
bikeNomad 0:a8535703f23b 59 friend void TPM0_IRQHandler();
bikeNomad 0:a8535703f23b 60 };
bikeNomad 0:a8535703f23b 61
bikeNomad 0:a8535703f23b 62 #endif
bikeNomad 0:a8535703f23b 63