-
Notifications
You must be signed in to change notification settings - Fork 0
/
led_matrix.h
81 lines (71 loc) · 2.1 KB
/
led_matrix.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
#ifndef LED_MATRIX_H
#define LED_MATRIX_H
// This file is the front-end abstraction for any number of
// "LED HARDWARE" modules. The idea is that you change the .c
// file in CMakeLists.txt to correspond to the hardware you
// actually have and the link process will then bundle the
// appropriate code into the driver.
#include <inttypes.h>
#if defined(led_matrix_dotstar)
#define LED_MATRIX_WIDTH 8
#define LED_MATRIX_HEIGHT 8
#define FRAME_DELAY_MS 25 // 40FPS
#elif defined(led_matrix_64x32)
#define LED_MATRIX_WIDTH 32
#define LED_MATRIX_HEIGHT 64
#define FRAME_DELAY_MS 5 // 200FPS
#else
#error Unknown LED_MATRIX_SOURCE
#endif
// Matrix dimensions. You may need to change these if your's
// is different as well as attend to code that might not
// like your chosen numbers.
#define LED_MATRIX_COUNT (LED_MATRIX_WIDTH * LED_MATRIX_HEIGHT)
// Initialize the matrix
void led_matrix_init();
// render the matrix.
// data is of the form 0xIIRRGGBB where
// II -> Intensity (brightness)
// RR -> Red
// GG -> Green
// BB -> Blue
//
// Values are 0-255
// format is horizontal rows. The first pixel
// sent is the southwest corner of the matrix.
void led_matrix_render(uint32_t* data);
// stop any background operations. This is needed to
// safely write settings to flash. Some drivers will
// not need to do anything here. Another call to
// led_matrix_render would be expected to start things
// back up.
void led_matrix_stop(void);
// converts a x,y coordinate to a pixel index
static inline uint32_t get_pixel_idx(uint16_t x, uint16_t y) {
return (y * LED_MATRIX_WIDTH) + x;
}
// sets a pixel
static inline void set_pixel(
uint32_t* led, // matrix
uint16_t x,
uint16_t y,
uint8_t br, // brightness
uint8_t r, // red
uint8_t g, // green
uint8_t b // blue
) {
const uint32_t pixel = (br << 24) | (r << 16) | (g << 8) | b;
const uint16_t idx = get_pixel_idx(x, y);
led[idx] = pixel;
}
// sets a pixel from a color
static inline void set_pixel2(
uint32_t* led, // matrix
uint16_t x,
uint16_t y,
uint32_t pixel
) {
const uint16_t idx = get_pixel_idx(x, y);
led[idx] = pixel;
}
#endif