From 1d65fbb3cb6c0b1cb82b332d408308bff610e9a0 Mon Sep 17 00:00:00 2001
From: EndlessFork <EndlessFork@users.noreply.github.com>
Date: Wed, 5 Apr 2017 11:05:47 +0200
Subject: [PATCH] WS2812: Block after ws2812_dma_start until finished

---
 src/ws2812/ws2812.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/ws2812/ws2812.c b/src/ws2812/ws2812.c
index 96a655a..622165a 100644
--- a/src/ws2812/ws2812.c
+++ b/src/ws2812/ws2812.c
@@ -77,7 +77,7 @@ static volatile uint_fast16_t       current_led_offset;
 static volatile uint_fast16_t       current_data_pause_len;
 static volatile uint_fast16_t       current_leds;
 
-#define DMA_LEDS_PER_HALFBUFF       9
+#define DMA_LEDS_PER_HALFBUFF       1
 #define DATA_LEN(n)                 ((n) * WS2812_BIT_PER_LED)                                  // number of total bytes to transfer data
 #define PAUSE_LEN                   (WS2812_PAUSE_LEN)                                          // number of total bytes to transfer pause
 #define DMA_BUF_LEN                 (2 * DMA_LEDS_PER_HALFBUFF * WS2812_BIT_PER_LED)                                    // DMA buffer length: 2 LEDs
@@ -382,6 +382,11 @@ ws2812_refresh (uint_fast16_t n_leds)
     ws2812_setup_dma_buf (0);
     ws2812_setup_dma_buf (1);
     ws2812_dma_start();
+
+    while (ws2812_dma_status != 0)
+    {
+        ;                                                        // wait until DMA transfer is ready
+    }
 }
 
 /*-----------------------------------------------------------------------------------------------------------------------------------------------
-- 
2.7.4

