-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix.cpp
67 lines (57 loc) · 1.4 KB
/
Matrix.cpp
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
#include "Matrix.h"
namespace DT5EDU {
matrix_8 & matrix_8::Transmit(Address addr, uint8_t data) {
uint16_t temp = (addr << 8) | data;
cs = 0;
#ifdef _Matrix_8_Using_Simulated_SPI_
uint16_t delay = 1.e9/SPI_Freq/2;
for (int i=15; i>=0; i--) {
mosi = (temp >> i) & 0x1;
clk = 1;
wait_ns(delay);
clk = 0;
wait_ns(delay);
}
#else
spi.write(temp);
#endif
cs = 1;
return *this;
}
matrix_8 & matrix_8::SendBuffer(void) {
for (int i=1; i<=8; i++)
Transmit(matrix_8::Address(i),buffer[i-1]);
return *this;
}
matrix_8 & matrix_8::Set_Intensity(float intensity) {
uint8_t value = 0b1111 * intensity;
Transmit(Intensity,value);
return *this;
}
matrix_8 & matrix_8::Init_Setting(void) {
Transmit(DecodeMode);
Set_MatrixTest(false);
Set_Shutdown(false);
Set_Intensity();
Transmit(ScanLimit,0b111);
return *this;
}
matrix_8 & matrix_8::Set_MatrixTest(bool mode) {
Transmit(DisplayTest,mode);
inDisplayTest = mode;
return *this;
}
matrix_8 & matrix_8::Set_Shutdown(bool mode) {
Transmit(Shutdown,!mode);
inShutdown = mode;
return *this;
}
inline matrix_8 & matrix_8::ClearBuffer(void) {
buffer.fill(0);
return *this;
}
matrix_8 & matrix_8::operator<<(const frame &data) {
buffer = data;
return SendBuffer();
}
}