forked from Yona-Appletree/LEDscape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathledscape.h
executable file
·176 lines (145 loc) · 3.29 KB
/
ledscape.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/** \file
* LEDscape for the BeagleBone Black.
*
* Drives up to 32 ws281x LED strips using the PRU to have no CPU overhead.
* Allows easy double buffering of frames.
*/
#ifndef _ledscape_h_
#define _ledscape_h_
#include <stdint.h>
#include "pru.h"
/** The number of strips supported.
*
* Changing this also requires changes in ws281x.p to stride the
* correct number of bytes per row..
*/
#define LEDSCAPE_NUM_STRIPS 48
/**
* An LEDscape "pixel" consists of three channels of output and an unused fourth channel. The color mapping of these
* channels is not defined by the pixel construct, but is specified by color_channel_order_t. Use ledscape_pixel_set_color
* to assign color values to a pixel.
*/
typedef struct {
uint8_t a;// was blue
uint8_t b;// was red
uint8_t c;// was green
uint8_t unused;
} __attribute__((__packed__)) ledscape_pixel_t;
/** LEDscape frame buffer is "strip-major".
*
* All 32 strips worth of data for each pixel are stored adjacent.
* This makes it easier to clock out while reading from the DDR
* in a burst mode.
*/
typedef struct {
ledscape_pixel_t strip[LEDSCAPE_NUM_STRIPS];
} __attribute__((__packed__)) ledscape_frame_t;
typedef struct ws281x_command ws281x_command_t;
typedef struct {
ws281x_command_t * ws281x_0;
ws281x_command_t * ws281x_1;
pru_t * pru0;
pru_t * pru1;
const char* pru0_program_filename;
const char* pru1_program_filename;
unsigned num_pixels;
size_t frame_size;
} ledscape_t;
typedef enum {
COLOR_ORDER_RGB,
COLOR_ORDER_RBG,
COLOR_ORDER_GRB,
COLOR_ORDER_GBR,
COLOR_ORDER_BGR,
COLOR_ORDER_BRG // Old LEDscape default
} color_channel_order_t;
extern ledscape_t * ledscape_init(
unsigned num_pixels
);
extern ledscape_t * ledscape_init_with_programs(
unsigned num_pixels,
const char* pru0_program_filename,
const char* pru1_program_filename
);
extern ledscape_frame_t *
ledscape_frame(
ledscape_t * const leds,
unsigned frame
);
extern void
ledscape_draw(
ledscape_t * const leds,
unsigned frame
);
inline void ledscape_pixel_set_color(
ledscape_pixel_t * const out_pixel,
color_channel_order_t color_channel_order,
uint8_t r,
uint8_t g,
uint8_t b
) {
switch (color_channel_order) {
case COLOR_ORDER_RGB:
out_pixel->a = r;
out_pixel->b = g;
out_pixel->c = b;
break;
case COLOR_ORDER_RBG:
out_pixel->a = r;
out_pixel->b = b;
out_pixel->c = g;
break;
case COLOR_ORDER_GRB:
out_pixel->a = g;
out_pixel->b = r;
out_pixel->c = b;
break;
case COLOR_ORDER_GBR:
out_pixel->a = g;
out_pixel->b = b;
out_pixel->c = r;
break;
case COLOR_ORDER_BGR:
out_pixel->a = b;
out_pixel->b = g;
out_pixel->c = r;
break;
case COLOR_ORDER_BRG:
out_pixel->a = b;
out_pixel->b = r;
out_pixel->c = g;
break;
}
}
inline void ledscape_set_color(
ledscape_frame_t * const frame,
color_channel_order_t color_channel_order,
uint8_t strip,
uint16_t pixel,
uint8_t r,
uint8_t g,
uint8_t b
) {
ledscape_pixel_set_color(
&frame[pixel].strip[strip],
color_channel_order,
r,
g,
b
);
}
extern void
ledscape_wait(
ledscape_t * const leds
);
extern void
ledscape_close(
ledscape_t * const leds
);
extern const char* color_channel_order_to_string(
color_channel_order_t color_channel_order
);
extern color_channel_order_t color_channel_order_from_string(
const char* str
);
#endif