Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | jlesech | 1 | /**************************************************************************//** |
2 | * \brief MAX7219 library for Arduino |
||
3 | * \author Copyright (C) 2011 Julien Le Sech - www.idreammicro.com |
||
4 | * \version 1.0 |
||
5 | * \date 20110801 |
||
6 | * |
||
7 | * This file is part of the MAX7219 library for Arduino. |
||
8 | * |
||
9 | * This library is free software: you can redistribute it and/or modify it under |
||
10 | * the terms of the GNU Lesser General Public License as published by the Free |
||
11 | * Software Foundation, either version 3 of the License, or (at your option) any |
||
12 | * later version. |
||
13 | * |
||
14 | * This library is distributed in the hope that it will be useful, but WITHOUT |
||
15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
||
16 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
||
17 | * details. |
||
18 | * |
||
19 | * You should have received a copy of the GNU Lesser General Public License |
||
20 | * along with this program. If not, see http://www.gnu.org/licenses/ |
||
21 | ******************************************************************************/ |
||
22 | |||
23 | /**************************************************************************//** |
||
24 | * \headerfile MAX7219.h |
||
25 | ******************************************************************************/ |
||
26 | |||
27 | #ifndef MAX7219_h |
||
28 | #define MAX7219_h |
||
29 | |||
30 | /****************************************************************************** |
||
31 | * Header file inclusions. |
||
32 | ******************************************************************************/ |
||
33 | |||
34 | #include <WProgram.h> |
||
35 | |||
36 | /**************************************************************************//** |
||
37 | * \class MAX7219 |
||
38 | ******************************************************************************/ |
||
39 | class MAX7219 |
||
40 | { |
||
41 | public: |
||
42 | |||
43 | /******************************************************************//** |
||
44 | * \enum DecodeModes |
||
45 | * \typedef DecodeMode_t |
||
46 | **********************************************************************/ |
||
47 | typedef enum DecodeModes |
||
48 | { |
||
49 | DecodeMode_NoDecode = 0x00, |
||
50 | DecodeMode_Digit0 = 0x01, |
||
51 | DecodeMode_Digit1 = 0x02, |
||
52 | DecodeMode_Digit2 = 0x04, |
||
53 | DecodeMode_Digit3 = 0x08, |
||
54 | DecodeMode_Digit4 = 0x10, |
||
55 | DecodeMode_Digit5 = 0x20, |
||
56 | DecodeMode_Digit6 = 0x40, |
||
57 | DecodeMode_Digit7 = 0x80, |
||
58 | DecodeMode_AllDigits = 0xFF |
||
59 | } DecodeMode_t; |
||
60 | |||
61 | /******************************************************************//** |
||
62 | * \enum DecodeModes |
||
63 | * \typedef DecodeMode_t |
||
64 | **********************************************************************/ |
||
65 | typedef enum Intensities |
||
66 | { |
||
67 | Intensity_Level0 = 0x00, |
||
68 | Intensity_Level1 = 0x01, |
||
69 | Intensity_Level2 = 0x02, |
||
70 | Intensity_Level3 = 0x03, |
||
71 | Intensity_Level4 = 0x04, |
||
72 | Intensity_Level5 = 0x05, |
||
73 | Intensity_Level6 = 0x06, |
||
74 | Intensity_Level7 = 0x07, |
||
75 | Intensity_Level8 = 0x08, |
||
76 | Intensity_Level9 = 0x09, |
||
77 | Intensity_Level10 = 0x0A, |
||
78 | Intensity_Level11 = 0x0B, |
||
79 | Intensity_Level12 = 0x0C, |
||
80 | Intensity_Level13 = 0x0D, |
||
81 | Intensity_Level14 = 0x0E, |
||
82 | Intensity_Level15 = 0x0F |
||
83 | } Intensity_t; |
||
84 | |||
85 | /******************************************************************//** |
||
86 | * \enum ScanLimits |
||
87 | * \typedef ScanLimit_t |
||
88 | **********************************************************************/ |
||
89 | typedef enum ScanLimits |
||
90 | { |
||
91 | ScanLimit_Digit0 = 0x00, |
||
92 | ScanLimit_Digit0To1 = 0x01, |
||
93 | ScanLimit_Digit0To2 = 0x02, |
||
94 | ScanLimit_Digit0To3 = 0x03, |
||
95 | ScanLimit_Digit0To4 = 0x04, |
||
96 | ScanLimit_Digit0To5 = 0x05, |
||
97 | ScanLimit_Digit0To6 = 0x06, |
||
98 | ScanLimit_Digit0To7 = 0x07 |
||
99 | } ScanLimit_t; |
||
100 | |||
101 | /******************************************************************//** |
||
102 | * \enum ShutdownModes |
||
103 | * \typedef ShutdownMode_t |
||
104 | **********************************************************************/ |
||
105 | typedef enum ShutdownModes |
||
106 | { |
||
107 | ShutdownMode_Shutdown = 0x00, |
||
108 | ShutdownMode_NormalOperation = 0x01 |
||
109 | } ShutdownMode_t; |
||
110 | |||
111 | /******************************************************************//** |
||
112 | * \enum DisplayTestModes |
||
113 | * \typedef DisplayTestMode_t |
||
114 | **********************************************************************/ |
||
115 | typedef enum DisplayTestModes |
||
116 | { |
||
117 | NormalOperation = 0x00, |
||
118 | TestMode = 0x01 |
||
119 | } DisplayTestMode_t; |
||
120 | |||
121 | /******************************************************************//** |
||
122 | * \enum Digits |
||
123 | * \typedef Digit_t |
||
124 | **********************************************************************/ |
||
125 | typedef enum Digits |
||
126 | { |
||
127 | Digit_0 = 0x01, |
||
128 | Digit_1 = 0x02, |
||
129 | Digit_2 = 0x03, |
||
130 | Digit_3 = 0x04, |
||
131 | Digit_4 = 0x05, |
||
132 | Digit_5 = 0x06, |
||
133 | Digit_6 = 0x07, |
||
134 | Digit_7 = 0x08 |
||
135 | } Digit_t; |
||
136 | |||
137 | /******************************************************************//** |
||
138 | * \enum Characters |
||
139 | * \typedef Character_t |
||
140 | **********************************************************************/ |
||
141 | typedef enum Characters |
||
142 | { |
||
143 | Character_Zero = 0x00, |
||
144 | Character_One = 0x01, |
||
145 | Character_Two = 0x02, |
||
146 | Character_Three = 0x03, |
||
147 | Character_Four = 0x04, |
||
148 | Character_Five = 0x05, |
||
149 | Character_Six = 0x06, |
||
150 | Character_Seven = 0x07, |
||
151 | Character_Eight = 0x08, |
||
152 | Character_Nine = 0x09, |
||
153 | Character_Dash = 0x0A, |
||
154 | Character_E = 0x0B, |
||
155 | Character_H = 0x0C, |
||
156 | Character_L = 0x0D, |
||
157 | Character_P = 0x0E, |
||
158 | Character_Blank = 0x0F |
||
159 | } Character_t; |
||
160 | |||
161 | /******************************************************************//** |
||
162 | * \enum Segments |
||
163 | * \typedef Segment_t |
||
164 | **********************************************************************/ |
||
165 | typedef enum Segments |
||
166 | { |
||
167 | Segment_DP = 0x80, |
||
168 | Segment_A = 0x40, |
||
169 | Segment_B = 0x20, |
||
170 | Segment_C = 0x10, |
||
171 | Segment_D = 0x08, |
||
172 | Segment_E = 0x04, |
||
173 | Segment_F = 0x02, |
||
174 | Segment_G = 0x01 |
||
175 | } Segment_t; |
||
176 | |||
177 | public: |
||
178 | |||
179 | /******************************************************************//** |
||
180 | * \fn MAX7219(byte csPin) |
||
181 | * |
||
182 | * \brief Constructor. |
||
183 | * |
||
184 | * \param csPin Chip select pin number. |
||
185 | **********************************************************************/ |
||
186 | MAX7219 |
||
187 | ( |
||
188 | byte csPin |
||
189 | ); |
||
190 | |||
191 | /******************************************************************//** |
||
192 | * \fn void initialize() |
||
193 | * |
||
194 | * \brief Initialize SPI to drive MAX7219. |
||
195 | **********************************************************************/ |
||
196 | void |
||
197 | initialize(); |
||
198 | |||
199 | /******************************************************************//** |
||
200 | * \fn void setDecodeMode(DecodeModes mode) |
||
201 | * |
||
202 | * \brief Set MAX7219 decode mode. |
||
203 | * |
||
204 | * \param mode Decode mode to set. |
||
205 | **********************************************************************/ |
||
206 | void |
||
207 | setDecodeMode |
||
208 | ( |
||
209 | DecodeModes mode |
||
210 | ); |
||
211 | |||
212 | /******************************************************************//** |
||
213 | * \fn void setIntensity(Intensities intensity) |
||
214 | * |
||
215 | * \brief Set MAX7219 intensity. |
||
216 | * |
||
217 | * \param itensity Intensity to set. |
||
218 | **********************************************************************/ |
||
219 | void |
||
220 | setIntensity |
||
221 | ( |
||
222 | Intensities intensity |
||
223 | ); |
||
224 | |||
225 | /******************************************************************//** |
||
226 | * \fn void setScanLimit(ScanLimits limit) |
||
227 | * |
||
228 | * \brief Set MAX7219 scan limit. |
||
229 | * |
||
230 | * \param limit Scan limit to set. |
||
231 | **********************************************************************/ |
||
232 | void |
||
233 | setScanLimit |
||
234 | ( |
||
235 | ScanLimits limit |
||
236 | ); |
||
237 | |||
238 | /******************************************************************//** |
||
239 | * \fn void setShutdownMode(ShutdownModes mode) |
||
240 | * |
||
241 | * \brief Set MAX7219 shutdown mode. |
||
242 | * |
||
243 | * \param mode Shutdown mode to set. |
||
244 | **********************************************************************/ |
||
245 | void |
||
246 | setShutdownMode |
||
247 | ( |
||
248 | ShutdownModes mode |
||
249 | ); |
||
250 | |||
251 | /******************************************************************//** |
||
252 | * \fn void setDisplayTestMode(DisplayTestModes mode) |
||
253 | * |
||
254 | * \brief Set MAX7219 display test mode. |
||
255 | * |
||
256 | * \param mode Display test mode to set. |
||
257 | **********************************************************************/ |
||
258 | void |
||
259 | setDisplayTestMode |
||
260 | ( |
||
261 | DisplayTestModes mode |
||
262 | ); |
||
263 | |||
264 | /******************************************************************//** |
||
265 | * \fn void writeDigit( |
||
266 | * Digits digit, |
||
267 | * Characters character, |
||
268 | * bool decimalPoint = false) |
||
269 | * |
||
270 | * \brief Write character on digit. |
||
271 | * |
||
272 | * \param digit Digit to write. |
||
273 | * \param character Character to write. |
||
274 | * \param decimalPoint Display decimal point. |
||
275 | **********************************************************************/ |
||
276 | void |
||
277 | writeDigit |
||
278 | ( |
||
279 | Digits digit, |
||
280 | Characters character, |
||
281 | bool decimalPoint = false |
||
282 | ); |
||
283 | |||
284 | /******************************************************************//** |
||
285 | * \fn void writeDigit(Digits digit, Segments segments) |
||
286 | * |
||
287 | * \brief Set segment(s) on digit. |
||
288 | * |
||
289 | * \param digit Digit to write. |
||
290 | * \param segment Segment(s) to set. |
||
291 | **********************************************************************/ |
||
292 | void |
||
293 | writeDigit |
||
294 | ( |
||
295 | Digits digit, |
||
296 | Segments segment |
||
297 | ); |
||
298 | |||
299 | private: |
||
300 | |||
301 | byte m_csPin; |
||
302 | |||
303 | /******************************************************************//** |
||
304 | * \fn void write(byte address, byte value) |
||
305 | * |
||
306 | * \brief Write value into MAX7219 register. |
||
307 | * |
||
308 | * \param address Register address. |
||
309 | * \param value Value to write. |
||
310 | **********************************************************************/ |
||
311 | void |
||
312 | write |
||
313 | ( |
||
314 | byte address, |
||
315 | byte value |
||
316 | ); |
||
317 | }; |
||
318 | |||
319 | #endif // MAX7219_h |