Johannes Stratmann / wsDrive

Dependencies:   BurstSPI

Dependents:   RGB-balls cylon

Fork of wsDrive by Andy A

Files at this revision

API Documentation at this revision

Comitter:
JojoS
Date:
Sat Dec 10 14:30:38 2016 +0000
Parent:
5:360f5e63b104
Commit message:
support for STM32F4

Changed in this revision

BurstSPI.lib Show annotated file Show diff for this revision Revisions of this file
wsDrive.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/BurstSPI.lib	Sun Oct 09 16:53:55 2016 +0000
+++ b/BurstSPI.lib	Sat Dec 10 14:30:38 2016 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/JojoS/code/BurstSPI/#83e3b8ba3f43
+https://developer.mbed.org/users/JojoS/code/BurstSPI/#8241b7d84ad2
--- 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)