forked from osresearch/LEDscape
-
Notifications
You must be signed in to change notification settings - Fork 58
/
ledscape.h
executable file
·130 lines (104 loc) · 2.61 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
/** \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
);
extern 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
);
extern 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
);
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