Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 113 lines (100 sloc) 2.446 kb
1fa2383 started on LED matrix code; this breaks the ws2821x code for now
root authored
1 /** \file
2 * Test the matrix LCD PRU firmware.
3 */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <stdint.h>
7 #include <string.h>
8 #include <time.h>
9 #include <inttypes.h>
10 #include <errno.h>
11 #include <unistd.h>
12 #include "ledscape.h"
13
14 static void
15 ledscape_fill_color(
16 ledscape_frame_t * const frame,
17 const unsigned num_pixels,
18 const uint8_t r,
19 const uint8_t g,
20 const uint8_t b
21 )
22 {
23 for (unsigned i = 0 ; i < num_pixels ; i++)
24 for (unsigned strip = 0 ; strip < LEDSCAPE_NUM_STRIPS ; strip++)
25 ledscape_set_color(frame, strip, i, r, g, b);
26 }
27
28
29 int main (void)
30 {
31 const int num_pixels = 512;
32 ledscape_t * const leds = ledscape_init(num_pixels);
33 printf("init done\n");
34 time_t last_time = time(NULL);
35 unsigned last_i = 0;
36
37 unsigned i = 0;
38 while (1)
39 {
40 // Alternate frame buffers on each draw command
41 const unsigned frame_num = i++ % 2;
42 ledscape_frame_t * const frame
43 = ledscape_frame(leds, frame_num);
44
45 uint32_t * const p = (void*) frame;
46 memset(p, 0, 4 * 32 * 512);
47
48 ledscape_draw(leds, frame_num);
49 #if 1
50 for (unsigned x = 0 ; x < 512 ; x++)
51 {
52 for (unsigned y = 0 ; y < 16 ; y++)
53 {
54 uint8_t * const px = (void*) &p[x + 512 * y];
55 const unsigned v = (i >> 10) % 16;
56 px[0] = x <= 14 ? v : 0;
57 px[1] = 11 < x && x <= 26 ? v : 0;
58 px[2] = 17 < x && x <= 32 ? v : 0;
59
60 if (x > 32)
61 p[0] = 4;
62 }
63 }
64 #else
65 uint8_t val = i >> 1;
66 uint16_t r = ((i >> 0) & 0xFF);
67 uint16_t g = ((i >> 8) & 0xFF);
68 uint16_t b = ((i >> 16) & 0xFF);
69 ledscape_fill_color(frame, num_pixels, val, val, val);
70
71 for (unsigned strip = 0 ; strip < 32 ; strip++)
72 {
73 for (unsigned p = 0 ; p < num_pixels ; p++)
74 {
75 ledscape_set_color(
76 frame,
77 strip,
78 p,
79 #if 1
80 ((strip % 3) == 0) ? (i) : 0,
81 ((strip % 3) == 1) ? (i) : 0,
82 ((strip % 3) == 2) ? (i) : 0
83 #else
84 ((strip % 3) == 0) ? 100 : 0,
85 ((strip % 3) == 1) ? 100 : 0,
86 ((strip % 3) == 2) ? 100 : 0
87 #endif
88 );
89 //ledscape_set_color(frame, strip, 3*p+1, 0, p+val + 80, 0);
90 //ledscape_set_color(frame, strip, 3*p+2, 0, 0, p+val + 160);
91 }
92 }
93 #endif
94
95 // wait for the previous frame to finish;
96 //const uint32_t response = ledscape_wait(leds);
97 const uint32_t response = 0;
98 time_t now = time(NULL);
99 if (now != last_time)
100 {
101 printf("%d fps. starting %d previous %"PRIx32"\n",
102 i - last_i, i, response);
103 last_i = i;
104 last_time = now;
105 }
106
107 }
108
109 ledscape_close(leds);
110
111 return EXIT_SUCCESS;
112 }
Something went wrong with that request. Please try again.