Programming an array of NeoPixels using the GPDMA for maximum performance.

Dependencies:   MODDMA mbed

Files at this revision

API Documentation at this revision

Comitter:
tohu
Date:
Sat Dec 06 07:39:42 2014 +0000
Child:
1:b6ae9e61d764
Commit message:
First version of copyImageToRender

Changed in this revision

MODDMA.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODDMA.lib	Sat Dec 06 07:39:42 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/code/MODDMA/#97a16bf2ff43
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Dec 06 07:39:42 2014 +0000
@@ -0,0 +1,65 @@
+#include "mbed.h"
+
+Serial pc(USBTX, USBRX);
+
+DigitalOut myled(LED1);
+
+uint8_t  smiley [120] = {
+    0x0,0x0,0x1F,0x0,0x0,0x1F,0x0,0x0,0x1F,0x0,0x0,0x1F,0x0,0x0,0x1F,
+    0x0,0x0,0x3E,0xFF,0xFF,0x0,0xFF,0xFF,0x0,0xFF,0xFF,0x0,0x0,0x0,0x3E,
+    0xFF,0xFF,0x0,0x0,0x0,0x0,0xFF,0xFF,0x0,0x0,0x0,0x0,0xFF,0xFF,0x0,
+    0xFF,0xFF,0x0,0xFF,0xFF,0x0,0xFF,0xFF,0x0,0xFF,0xFF,0x0,0xFF,0xFF,0x0,
+    0xFF,0xFF,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xFF,0xFF,0x0,
+    0x0,0x0,0xBA,0xFF,0xFF,0x0,0xFF,0xFF,0x0,0xFF,0xFF,0x0,0x0,0x0,0xBA,
+    0x0,0x0,0xD9,0x0,0x0,0xD9,0x0,0x0,0xD9,0x0,0x0,0xD9,0x0,0x0,0xD9,
+    0x0,0x0,0xFF,0x0,0x0,0xFF,0x0,0x0,0xFF,0x0,0x0,0xFF,0x0,0x0,0xFF
+};
+
+uint8_t renderBuffer[360];
+
+void copyImageToRender(uint8_t *image, uint8_t *buffer, size_t len)
+{
+    Timer timer;
+    
+    timer.start();
+    
+    int outIndex;
+    
+    for(int i = 0; i < len; i++)
+    {
+        outIndex = i*3;        
+        buffer[outIndex] = 0x92; // 10010010
+        buffer[outIndex] |= image[i]&128>>1;
+        buffer[outIndex] |= image[i]&64>>3;
+        buffer[outIndex] |= image[i]&32>>5;
+        
+        buffer[outIndex+1] = 0x49; // 01001001
+        buffer[outIndex+1] |= image[i]&16<<1;
+        buffer[outIndex+1] |= image[i]&8>>1;
+        
+        buffer[outIndex+1] = 0x24; // 00100100
+        buffer[outIndex+1] |= image[i]&4<<5;
+        buffer[outIndex+1] |= image[i]&2<<3;
+        buffer[outIndex+1] |= image[i]&1<<1;
+    }
+    
+    timer.stop();
+    
+    pc.printf("Time spend copying image: %d us\n", timer.read_us());
+}
+
+int main()
+{
+    // Setup the serial port to print out results.
+    pc.baud(115200);
+
+    while(1) {
+        
+        copyImageToRender(smiley, renderBuffer, 120);
+        
+        myled = 1;
+        wait(0.2);
+        myled = 0;
+        wait(0.2);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Dec 06 07:39:42 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file