driver for WS2812B LED, modified for better compatibility with LPC812 and LPC1549

Dependencies:   BurstSPI

Dependents:   RGB-balls cylon

Fork of wsDrive by Andy A

Revision:
6:270a9728ee29
Parent:
4:c965e448d96b
--- a/wsDrive.cpp	Sun Oct 09 16:53:55 2016 +0000
+++ b/wsDrive.cpp	Sat Dec 10 14:30:38 2016 +0000
@@ -2,9 +2,13 @@
 
 wsDrive::wsDrive(PinName mosi, PinName miso, PinName clk) : BurstSPI(mosi,miso,clk)
 {
+#if defined(TARGET_STM32F4)    
+    frequency(4000000);
+    format(4*4, 1);          // one WS bit -> four SPI bits
+#else
     frequency(2400000);
-    format(12, 1);
-    //setFormat();
+    format(3*4, 1);          // one WS bit -> three SPI bits
+#endif
 
     pixArray = NULL;
     pixArray16 = NULL;
@@ -42,10 +46,20 @@
 // each bytes sent as two 12 bit messages (3 bits of data per LED bit).
 void wsDrive::sendByte(unsigned char value)
 {
+    uint16_t dataToSend = 0;
+    uint8_t mask = 0x80;
 
-    uint16_t dataToSend = 0;
-
-    uint8_t mask = 0x80;
+#if defined(TARGET_STM32F4)    
+    while (mask) {
+        dataToSend += (value & mask)?0x0C:0x08; // 1000 for a 0 or  1100 for a 1
+        if (mask & 0x11) {                     // trans
+            fastWrite(dataToSend);
+            dataToSend = 0;
+        }
+        dataToSend = dataToSend << 4;
+        mask = mask >> 1;
+    }
+#else
     while (mask) {
         dataToSend += (value & mask)?0x06:0x4; // 100 for a 0 or  110 for a 1
         if (mask & 0x11) {                     // trans
@@ -55,6 +69,7 @@
         dataToSend = dataToSend << 3;
         mask = mask >> 1;
     }
+#endif
 }
 
 void wsDrive::sendPixel(pixelInfo *pixToSend)