-
Notifications
You must be signed in to change notification settings - Fork 1
/
max7219_matrix.h
218 lines (197 loc) · 7.24 KB
/
max7219_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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include <font.h>
#ifndef MAX7219_DIGITS_AMOUNT
#define MAX7219_DIGITS_AMOUNT 0x08
#endif
#ifndef MAX7219_DISPLAYS_AMOUNT
#define MAX7219_DISPLAYS_AMOUNT 0x04
#endif
#ifndef MAX7219_VERTICAL_DISPLAYS_AMOUNT
#define MAX7219_VERTICAL_DISPLAYS_AMOUNT 0x01
#endif
#define MATRIX_COLUMNS MAX7219_DISPLAYS_AMOUNT
#define MATRIX_SUBCOLUMNS MATRIX_COLUMNS*8
#define MATRIX_ROWS MAX7219_DIGITS_AMOUNT*MAX7219_VERTICAL_DISPLAYS_AMOUNT
#define MAX7219_MATRIX_MIDDLEWARE 0xFF
unsigned int8 ledMatrix[MATRIX_ROWS][MATRIX_COLUMNS];
/**
* Shifts data to the left in the specified row of the in memory matrix
*
* @param row Number of row to be shifted
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void _shiftRowLeft(unsigned int16);
/**
* Shifts data to the left of the in memory matrix, depends on _shiftRowLeft
*
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void shiftMatrixLeft(void);
/**
* Shifts data to the right in the specified row of the in memory matrix
*
* @param row Number of row to be shifted
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void _shiftRowRight(unsigned int8);
/**
* Shifts data to the left of the in memory matrix, depends on _shiftRowRight
*
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void shiftMatrixRight(void);
/**
* Shifts data to the row above the specified row of the in memory matrix
*
* @param row Number of row to be shifted
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void _shiftRowUp(unsigned int8);
/**
* Shifts data of the in memory matrix upwards , depends on _shiftRowUp
*
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void shiftMatrixUp(void);
/**
* Shifts data to the row below the specified row of the in memory matrix
*
* @param row Number of row to be shifted
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void _shiftRowDown(unsigned int8);
/**
* Shifts data of the in memory matrix downwards , depends on _shiftRowDown
*
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void shiftMatrixDown(void);
/**
* Sets all the rows and columns values of the in memory matrix to zero
*
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void clearMatrix(void);
/**
* Sets the values of specific rows and columns of the in memory matrix to zero
*
* @param x0 The origin horizontal point of the section to be cleared
* @param y0 The origin vertical point of the section to be cleared
* @param x1 The last horizontal point of the section to be cleared
* @param y1 The last vertical point of the section to be cleared
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void clearPartialMatrix(signed int16, signed int16, signed int16, signed int16);
/**
* Sets the pixel at the given x and y coordinates as true
*
* @param x The horizontal coordinate of the pixel
* @param y The vertical coordinate of the pixel
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return True if a valid coordinate, False otherwise (e.g. negative values will return False)
*/
int1 putPixel(signed int16, signed int16);
/**
* Draws a line from a given coordinate to another, uses Bresenham algorithm to do the drawing.
* Depends on _drawLineLow and _drawLineHigh to be able to draw lines in all octants
*
* @param x0 The origin horizontal point of the line
* @param y0 The origin vertical point of the line
* @param x1 The end horizontal point of the line
* @param y1 The end vertical point of the line
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void drawLine(signed int16, signed int16, signed int16, signed int16);
/**
* Used to draw lines in the horizontal plane, uses Bresenham algorithm to do the drawing.
* Depends on putPixel
*
* @param x0 The origin horizontal point of the line
* @param y0 The origin vertical point of the line
* @param x1 The end horizontal point of the line
* @param y1 The end vertical point of the line
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void _drawLineLow(signed int16, signed int16, signed int16, signed int16);
/**
* Used to draw lines in the vertical plane, uses Bresenham algorithm to do the drawing.
* Depends on putPixel
*
* @param x0 The origin horizontal point of the line
* @param y0 The origin vertical point of the line
* @param x1 The end horizontal point of the line
* @param y1 The end vertical point of the line
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void _drawLineHigh(signed int16, signed int16, signed int16, signed int16);
/**
* Used to draw rectangular outlines in the matrix.
* Depends on drawLine
*
* @param x0 The origin horizontal point of the rectangle
* @param y0 The origin vertical point of the rectangle
* @param width The width of the rectangle in pixels
* @param height The height of the rectangle in pixels
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void drawRectangle(signed int16, signed int16, signed int16, signed int16);
/**
* Draws a circle with it's center on the given coordinates and radius, uses Bresenham circle algorithm to do the drawing.
*
* @param xc The horizontal coordinate of the circle center
* @param yc The vertical coordinate of the circle center
* @param radius The circle radius
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void drawCircle(signed int16, signed int16, signed int16);
/**
* Draws a character with it's origin on the given coordinates.
* Depends on putPixel
*
* @param x The horizontal coordinate of the character origin
* @param y The vertical coordinate of the character origin
* @param character The character to be drawn
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void drawCharacter(signed int16, signed int16, char);
/**
* Draws a string with it's origin on the given coordinates, also a spacing in can be given
* to separate each character horizantally from each other.
* Depends on drawCharacter
*
* @param x The horizontal coordinate of the string origin
* @param y The vertical coordinate of the string origin
* @param string The string to be drawn
* @param stringLength The length of the string to be drawn
* @param spacing The amount of horizontal pixels to be used as separation between characters
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void drawString(signed int16, signed int16, char *, unsigned int8, unsigned int8);
/**
* Sends the data from the in memory matrix to the MAX7219 devices, this should be done
* only after doing all the drawing and clearing operations to avoid unnecesary cycle wasting
*
* Depends on max7219.c so include it in your preprocessor directives like so:
* #include <max7219.c>
*
* @param pinArray The array of the pins which will be used to load the data in each row of MAX7219
* @author Luis Antonio Garcia Castañeda (LuisAGC)
* @return Nothing, void method
*/
void sendMatrix(unsigned int16 *);