]> mj.ucw.cz Git - home-hw.git/commitdiff
X-mas: WIP as always
authorMartin Mareš <mj@ucw.cz>
Wed, 24 Dec 2025 15:18:18 +0000 (16:18 +0100)
committerMartin Mareš <mj@ucw.cz>
Wed, 24 Dec 2025 15:18:18 +0000 (16:18 +0100)
xmas-lights/firmware/interface.h
xmas-lights/firmware/main.c

index 7068e16b12a3a95258718f7fb0fa8eb8b7f02016..09a2533449cb198532dd79a8a1f955097f3fa0bc 100644 (file)
@@ -8,4 +8,4 @@
 #define NPIX_USB_PRODUCT 0x0015
 #define NPIX_USB_VERSION 0x0100
 
-#define NPIX_NUM_LEDS 150
+#define NPIX_NUM_LEDS 131
index 3c6975117ffac48cbeef9c0994acc1508fac9187..5e12ba70853534b1468ffec6dfc634e2f65518ce 100644 (file)
@@ -95,9 +95,9 @@ static void delay_ms(uint ms)
 /*** Neopixels ***/
 
 #define NPIX_PERIOD 90         // timer runs on 72 MHz, so 90 periods = 1250 ns
-#define NPIX_RESET 10          // length of reset pulse in LED slots
+#define NPIX_RESET 19          // length of reset pulse in LED slots (24 periods)
                                // The chip needs longer reset pulse than documented.
-#define B0 30
+#define B0 30                  // Right length should be 32 and 64
 #define B1 60
 
 static byte neopixel_leds[NPIX_NUM_LEDS][3];
@@ -169,10 +169,10 @@ static inline void next_led(byte *buf)
        if (neopixel_index < NPIX_NUM_LEDS) {
                byte *led = neopixel_leds[neopixel_index++];
                byte r = led[0], g = led[1], b = led[2];
-               for (uint m=0x80; m; m >>= 1)
-                       *buf++ = (g & m) ? B1 : B0;
                for (uint m=0x80; m; m >>= 1)
                        *buf++ = (r & m) ? B1 : B0;
+               for (uint m=0x80; m; m >>= 1)
+                       *buf++ = (g & m) ? B1 : B0;
                for (uint m=0x80; m; m >>= 1)
                        *buf++ = (b & m) ? B1 : B0;
        } else {
@@ -396,7 +396,7 @@ static void usb_init(void)
 
 /*** Effects ***/
 
-#if 1
+#if 0
 
 static void effect(void)
 {
@@ -423,7 +423,7 @@ static void effect(void)
        static u32 last_update = 0;
        static byte b = 0;
 
-       if (ms_ticks - last_update < 60)
+       if (ms_ticks - last_update < 40)
                return;
        last_update = ms_ticks;
 
@@ -432,8 +432,8 @@ static void effect(void)
        for (uint j=0; j < NPIX_NUM_LEDS; j++)
                neopixel_set(j, neopixel_leds[j][0]*DIM, neopixel_leds[j][1]*DIM, neopixel_leds[j][2]*DIM);
 
-       for (uint k=0; k<NPIX_NUM_LEDS/3; k++) {
-               neopixel_set((b + 30*k) % NPIX_NUM_LEDS, 255, 3*k, k/5);
+       for (uint k=0; k<NPIX_NUM_LEDS/30; k++) {
+               neopixel_set((b + 30*k) % NPIX_NUM_LEDS, k/5, 3*k, 255);
        }
        b = (b + 1) % NPIX_NUM_LEDS;
 }
@@ -464,7 +464,7 @@ int main(void)
                                static uint i;
                                neopixel_set(i, 0, 0, 7);
                                i = (i+1) % NPIX_NUM_LEDS;
-                               neopixel_set(i, 0, 255, 0);
+                               neopixel_set(i, 255, 0, 0);
                        }
 #endif
                }