From 2ae0c8b47057a1baa6e897bd5d31687d5f2adc80 Mon Sep 17 00:00:00 2001
From: schneider <schneider@blinkenlichts.net>
Date: Sun, 26 May 2019 15:43:44 +0200
Subject: [PATCH] feat(leds): support for 15 leds, support to dim per LED

---
 Hello_World/main.c | 18 ++++++++++++++----
 lib/card10/leds.c  | 19 ++++++++++++-------
 lib/card10/leds.h  |  2 +-
 3 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/Hello_World/main.c b/Hello_World/main.c
index d4c1cd4f..dc7d6c87 100644
--- a/Hello_World/main.c
+++ b/Hello_World/main.c
@@ -31,13 +31,23 @@ int main(void)
     Paint_DrawImage(Heart, 0, 0, 160, 80);
     LCD_Update();
 
+    for(int i=0; i<11; i++) {
+        leds_set_dim(i, 1);
+    }
+
     int h = 0;
     while (1) {
 #if 0
-        leds_set_hsv(0, h, 1., 1.);
-        leds_set_hsv(1, (h + 90) % 360, 1., 1.);
-        leds_set_hsv(2, (h + 180) % 360, 1., 1.);
-        leds_set_hsv(3, (h + 270) % 360, 1., 1.);
+
+        #define NUM     15
+        for(int i=0; i<NUM; i++) {
+            if(i < 12) {
+                leds_set_hsv(i, (h + 360/NUM * i) % 360, 1., 1./8);
+            } else {
+                leds_set_hsv(i, (h + 360/NUM * i) % 360, 1., 1.);
+            }
+        }
+
         leds_update();
         TMR_Delay(MXC_TMR0, MSEC(10), 0);
         h++;
diff --git a/lib/card10/leds.c b/lib/card10/leds.c
index d9322f4c..2ad3cbe3 100644
--- a/lib/card10/leds.c
+++ b/lib/card10/leds.c
@@ -3,10 +3,11 @@
 #include <stdint.h>
 #include <string.h>
 
+#define NUM_LEDS    15
+
 static const gpio_cfg_t rgb_dat_pin = {PORT_1, PIN_14, GPIO_FUNC_OUT, GPIO_PAD_NONE};
 static const gpio_cfg_t rgb_clk_pin = {PORT_1, PIN_15, GPIO_FUNC_OUT, GPIO_PAD_NONE};
-static uint8_t led_dim = 8;
-static uint8_t leds[15][3];
+static uint8_t leds[NUM_LEDS][4];
 
 /***** Functions *****/
 // *****************************************************************************
@@ -159,9 +160,9 @@ static void leds_stop(void)
     shift(0xFF); shift(0xFF); shift(0xFF); shift(0xFF);
 }
 
-void leds_set_dim(uint8_t dim)
+void leds_set_dim(uint8_t led, uint8_t dim)
 {
-    led_dim = dim;
+    leds[led][3] = dim;
 }
 
 void leds_set(uint8_t led, uint8_t r, uint8_t g, uint8_t b)
@@ -183,8 +184,8 @@ void leds_set_hsv(uint8_t led, float h, float s, float v)
 void leds_update(void)
 {
     leds_start();
-    for(int i=3; i>=0; i--) {
-        leds_shift(leds[i][0], leds[i][1], leds[i][2], led_dim);
+    for(int i=NUM_LEDS-1; i>=0; i--) {
+        leds_shift(leds[i][0], leds[i][1], leds[i][2], leds[i][3]);
     }
     leds_stop();
 }
@@ -198,7 +199,11 @@ void leds_init(void)
     GPIO_OutClr(&rgb_dat_pin);
 
     memset(leds, 0, sizeof(leds));
-    led_dim = 8;
+
+    for(int i=0; i<NUM_LEDS; i++) {
+        leds[i][3] = 8;
+    }
+
     leds_update();
 }
 
diff --git a/lib/card10/leds.h b/lib/card10/leds.h
index 0b977e11..7b4dc91a 100644
--- a/lib/card10/leds.h
+++ b/lib/card10/leds.h
@@ -2,7 +2,7 @@
 
 #include <stdint.h>
 
-void leds_set_dim(uint8_t dim);
+void leds_set_dim(uint8_t led, uint8_t dim);
 void leds_set(uint8_t led, uint8_t r, uint8_t g, uint8_t b);
 void leds_set_hsv(uint8_t led, float h, float s, float v);
 void leds_update(void);
-- 
GitLab