forked from hzeller/rpi-rgb-led-matrix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathled-matrix.h
72 lines (60 loc) · 1.87 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
// -*- c++ -*-
// Controlling a 32x32 RGB matrix via GPIO.
#ifndef RPI_RGBMATRIX_H
#define RPI_RGBMATRIX_H
#include <stdint.h>
#include "gpio.h"
class RGBMatrix {
public:
RGBMatrix(GPIO *io);
void ClearScreen();
void FillScreen(uint8_t red, uint8_t green, uint8_t blue);
// Here the set-up [>] [>]
// v
// [<] [<] ... so column 65..127 are backwards.
int width() const { return 64; }
int height() const { return 64; }
void SetPixel(uint8_t x, uint8_t y,
uint8_t red, uint8_t green, uint8_t blue);
// Updates the screen once. Call this in a continous loop in some realtime
// thread.
void UpdateScreen();
private:
GPIO *const io_;
enum {
kDoubleRows = 16, // Physical constant of the used board.
kChainedBoards = 4, // Number of boards that are daisy-chained.
kColumns = kChainedBoards * 32,
kPWMBits = 4 // maximum PWM resolution.
};
union IoBits {
struct {
unsigned int unused1 : 2; // 0..1
unsigned int output_enable : 1; // 2
unsigned int clock : 1; // 3
unsigned int strobe : 1; // 4
unsigned int unused2 : 2; // 5..6
unsigned int row : 4; // 7..10
unsigned int unused3 : 6; // 11..16
unsigned int r1 : 1; // 17
unsigned int g1 : 1; // 18
unsigned int unused4 : 3;
unsigned int b1 : 1; // 22
unsigned int r2 : 1; // 23
unsigned int g2 : 1; // 24
unsigned int b2 : 1; // 25
} bits;
uint32_t raw;
IoBits() : raw(0) {}
};
// A double row represents row n and n+16. The physical layout of the
// 32x32 RGB is two sub-panels with 32 columns and 16 rows.
struct DoubleRow {
IoBits column[kColumns]; // only color bits are set
};
struct Screen {
DoubleRow row[kDoubleRows];
};
Screen bitplane_[kPWMBits];
};
#endif // RPI_RGBMATRIX_H