-
Notifications
You must be signed in to change notification settings - Fork 0
/
MAX7219.h
319 lines (292 loc) · 11.2 KB
/
MAX7219.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/**************************************************************************//**
* \brief MAX7219 library for Arduino
* \author Copyright (C) 2011 Julien Le Sech - www.idreammicro.com
* \version 1.0
* \date 20110801
*
* This file is part of the MAX7219 library for Arduino.
*
* This library is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
******************************************************************************/
/**************************************************************************//**
* \headerfile MAX7219.h
******************************************************************************/
#ifndef MAX7219_h
#define MAX7219_h
/******************************************************************************
* Header file inclusions.
******************************************************************************/
#include <Arduino.h>
/**************************************************************************//**
* \class MAX7219
******************************************************************************/
class MAX7219
{
public:
/******************************************************************//**
* \enum DecodeModes
* \typedef DecodeMode_t
**********************************************************************/
typedef enum DecodeModes
{
DecodeMode_NoDecode = 0x00,
DecodeMode_Digit0 = 0x01,
DecodeMode_Digit1 = 0x02,
DecodeMode_Digit2 = 0x04,
DecodeMode_Digit3 = 0x08,
DecodeMode_Digit4 = 0x10,
DecodeMode_Digit5 = 0x20,
DecodeMode_Digit6 = 0x40,
DecodeMode_Digit7 = 0x80,
DecodeMode_AllDigits = 0xFF
} DecodeMode_t;
/******************************************************************//**
* \enum DecodeModes
* \typedef DecodeMode_t
**********************************************************************/
typedef enum Intensities
{
Intensity_Level0 = 0x00,
Intensity_Level1 = 0x01,
Intensity_Level2 = 0x02,
Intensity_Level3 = 0x03,
Intensity_Level4 = 0x04,
Intensity_Level5 = 0x05,
Intensity_Level6 = 0x06,
Intensity_Level7 = 0x07,
Intensity_Level8 = 0x08,
Intensity_Level9 = 0x09,
Intensity_Level10 = 0x0A,
Intensity_Level11 = 0x0B,
Intensity_Level12 = 0x0C,
Intensity_Level13 = 0x0D,
Intensity_Level14 = 0x0E,
Intensity_Level15 = 0x0F
} Intensity_t;
/******************************************************************//**
* \enum ScanLimits
* \typedef ScanLimit_t
**********************************************************************/
typedef enum ScanLimits
{
ScanLimit_Digit0 = 0x00,
ScanLimit_Digit0To1 = 0x01,
ScanLimit_Digit0To2 = 0x02,
ScanLimit_Digit0To3 = 0x03,
ScanLimit_Digit0To4 = 0x04,
ScanLimit_Digit0To5 = 0x05,
ScanLimit_Digit0To6 = 0x06,
ScanLimit_Digit0To7 = 0x07
} ScanLimit_t;
/******************************************************************//**
* \enum ShutdownModes
* \typedef ShutdownMode_t
**********************************************************************/
typedef enum ShutdownModes
{
ShutdownMode_Shutdown = 0x00,
ShutdownMode_NormalOperation = 0x01
} ShutdownMode_t;
/******************************************************************//**
* \enum DisplayTestModes
* \typedef DisplayTestMode_t
**********************************************************************/
typedef enum DisplayTestModes
{
NormalOperation = 0x00,
TestMode = 0x01
} DisplayTestMode_t;
/******************************************************************//**
* \enum Digits
* \typedef Digit_t
**********************************************************************/
typedef enum Digits
{
Digit_0 = 0x01,
Digit_1 = 0x02,
Digit_2 = 0x03,
Digit_3 = 0x04,
Digit_4 = 0x05,
Digit_5 = 0x06,
Digit_6 = 0x07,
Digit_7 = 0x08
} Digit_t;
/******************************************************************//**
* \enum Characters
* \typedef Character_t
**********************************************************************/
typedef enum Characters
{
Character_Zero = 0x00,
Character_One = 0x01,
Character_Two = 0x02,
Character_Three = 0x03,
Character_Four = 0x04,
Character_Five = 0x05,
Character_Six = 0x06,
Character_Seven = 0x07,
Character_Eight = 0x08,
Character_Nine = 0x09,
Character_Dash = 0x0A,
Character_E = 0x0B,
Character_H = 0x0C,
Character_L = 0x0D,
Character_P = 0x0E,
Character_Blank = 0x0F
} Character_t;
/******************************************************************//**
* \enum Segments
* \typedef Segment_t
**********************************************************************/
typedef enum Segments
{
Segment_DP = 0x80,
Segment_A = 0x40,
Segment_B = 0x20,
Segment_C = 0x10,
Segment_D = 0x08,
Segment_E = 0x04,
Segment_F = 0x02,
Segment_G = 0x01
} Segment_t;
public:
/******************************************************************//**
* \fn MAX7219(byte csPin)
*
* \brief Constructor.
*
* \param csPin Chip select pin number.
**********************************************************************/
MAX7219
(
byte csPin
);
/******************************************************************//**
* \fn void initialize()
*
* \brief Initialize SPI to drive MAX7219.
**********************************************************************/
void
initialize();
/******************************************************************//**
* \fn void setDecodeMode(DecodeModes mode)
*
* \brief Set MAX7219 decode mode.
*
* \param mode Decode mode to set.
**********************************************************************/
void
setDecodeMode
(
DecodeModes mode
);
/******************************************************************//**
* \fn void setIntensity(Intensities intensity)
*
* \brief Set MAX7219 intensity.
*
* \param itensity Intensity to set.
**********************************************************************/
void
setIntensity
(
Intensities intensity
);
/******************************************************************//**
* \fn void setScanLimit(ScanLimits limit)
*
* \brief Set MAX7219 scan limit.
*
* \param limit Scan limit to set.
**********************************************************************/
void
setScanLimit
(
ScanLimits limit
);
/******************************************************************//**
* \fn void setShutdownMode(ShutdownModes mode)
*
* \brief Set MAX7219 shutdown mode.
*
* \param mode Shutdown mode to set.
**********************************************************************/
void
setShutdownMode
(
ShutdownModes mode
);
/******************************************************************//**
* \fn void setDisplayTestMode(DisplayTestModes mode)
*
* \brief Set MAX7219 display test mode.
*
* \param mode Display test mode to set.
**********************************************************************/
void
setDisplayTestMode
(
DisplayTestModes mode
);
/******************************************************************//**
* \fn void writeDigit(
* Digits digit,
* Characters character,
* bool decimalPoint = false)
*
* \brief Write character on digit.
*
* \param digit Digit to write.
* \param character Character to write.
* \param decimalPoint Display decimal point.
**********************************************************************/
void
writeDigit
(
Digits digit,
Characters character,
bool decimalPoint = false
);
/******************************************************************//**
* \fn void writeDigit(Digits digit, Segments segments)
*
* \brief Set segment(s) on digit.
*
* \param digit Digit to write.
* \param segment Segment(s) to set.
**********************************************************************/
void
writeDigit
(
Digits digit,
Segments segment
);
private:
byte m_csPin;
/******************************************************************//**
* \fn void write(byte address, byte value)
*
* \brief Write value into MAX7219 register.
*
* \param address Register address.
* \param value Value to write.
**********************************************************************/
void
write
(
byte address,
byte value
);
};
#endif // MAX7219_h