|
1 /* |
|
2 |
|
3 u8x8_d_max7219.c |
|
4 |
|
5 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/) |
|
6 |
|
7 Copyright (c) 2017, olikraus@gmail.com |
|
8 All rights reserved. |
|
9 |
|
10 Redistribution and use in source and binary forms, with or without modification, |
|
11 are permitted provided that the following conditions are met: |
|
12 |
|
13 * Redistributions of source code must retain the above copyright notice, this list |
|
14 of conditions and the following disclaimer. |
|
15 |
|
16 * Redistributions in binary form must reproduce the above copyright notice, this |
|
17 list of conditions and the following disclaimer in the documentation and/or other |
|
18 materials provided with the distribution. |
|
19 |
|
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|
21 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
22 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
23 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
|
25 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
27 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
30 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
32 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
33 |
|
34 */ |
|
35 |
|
36 |
|
37 #include "u8x8.h" |
|
38 |
|
39 |
|
40 |
|
41 static const uint8_t u8x8_d_max7219_init_seq[] = { |
|
42 |
|
43 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
44 U8X8_CA(15, 0), /* test mode off */ |
|
45 U8X8_CA(15, 0), /* test mode off */ |
|
46 U8X8_CA(15, 0), /* test mode off */ |
|
47 U8X8_CA(15, 0), /* test mode off */ |
|
48 U8X8_END_TRANSFER(), /* disable chip */ |
|
49 |
|
50 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
51 U8X8_CA(12, 0), /* */ |
|
52 U8X8_CA(12, 0), /* */ |
|
53 U8X8_CA(12, 0), /* */ |
|
54 U8X8_CA(12, 0), /* */ |
|
55 U8X8_END_TRANSFER(), /* disable chip */ |
|
56 |
|
57 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
58 U8X8_CA(9, 0), /* decode mode: graphics */ |
|
59 U8X8_CA(9, 0), /* decode mode: graphics */ |
|
60 U8X8_CA(9, 0), /* decode mode: graphics */ |
|
61 U8X8_CA(9, 0), /* decode mode: graphics */ |
|
62 U8X8_END_TRANSFER(), /* disable chip */ |
|
63 |
|
64 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
65 U8X8_CA(10, 10), /* medium high intensity */ |
|
66 U8X8_CA(10, 10), /* medium high intensity */ |
|
67 U8X8_CA(10, 10), /* medium high intensity */ |
|
68 U8X8_CA(10, 10), /* medium high intensity */ |
|
69 U8X8_END_TRANSFER(), /* disable chip */ |
|
70 |
|
71 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
72 U8X8_CA(11, 7), /* scan limit: display all digits (assuming a 8x8 matrix) */ |
|
73 U8X8_CA(11, 7), /* scan limit: display all digits (assuming a 8x8 matrix) */ |
|
74 U8X8_CA(11, 7), /* scan limit: display all digits (assuming a 8x8 matrix) */ |
|
75 U8X8_CA(11, 7), /* scan limit: display all digits (assuming a 8x8 matrix) */ |
|
76 U8X8_END_TRANSFER(), /* disable chip */ |
|
77 |
|
78 |
|
79 //U8X8_CA(12, 0), /* shutdown */ |
|
80 |
|
81 //U8X8_END_TRANSFER(), /* disable chip */ |
|
82 U8X8_END() /* end of sequence */ |
|
83 }; |
|
84 |
|
85 static const uint8_t u8x8_d_max7219_powersave0_seq[] = { |
|
86 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
87 U8X8_CA(12, 1), /* display on */ |
|
88 U8X8_CA(12, 1), /* display on */ |
|
89 U8X8_CA(12, 1), /* display on */ |
|
90 U8X8_CA(12, 1), /* display on */ |
|
91 U8X8_END_TRANSFER(), /* disable chip */ |
|
92 U8X8_END() /* end of sequence */ |
|
93 }; |
|
94 |
|
95 static const uint8_t u8x8_d_max7219_powersave1_seq[] = { |
|
96 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
97 U8X8_CA(12, 0), /* shutdown */ |
|
98 U8X8_CA(12, 0), /* shutdown */ |
|
99 U8X8_CA(12, 0), /* shutdown */ |
|
100 U8X8_CA(12, 0), /* shutdown */ |
|
101 U8X8_END_TRANSFER(), /* disable chip */ |
|
102 U8X8_END() /* end of sequence */ |
|
103 }; |
|
104 |
|
105 |
|
106 static uint8_t u8x8_d_max7219_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
|
107 { |
|
108 uint8_t c, j, i; |
|
109 uint8_t *ptr; |
|
110 switch(msg) |
|
111 { |
|
112 /* handled by the calling function |
|
113 case U8X8_MSG_DISPLAY_SETUP_MEMORY: |
|
114 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_pcf8812_96x65_display_info); |
|
115 break; |
|
116 case U8X8_MSG_DISPLAY_INIT: |
|
117 u8x8_d_helper_display_init(u8x8); |
|
118 u8x8_cad_SendSequence(u8x8, u8x8_d_max7219_init_seq); |
|
119 break; |
|
120 case U8X8_MSG_DISPLAY_SET_POWER_SAVE: |
|
121 if ( arg_int == 0 ) |
|
122 u8x8_cad_SendSequence(u8x8, u8x8_d_max7219_powersave0_seq); |
|
123 else |
|
124 u8x8_cad_SendSequence(u8x8, u8x8_d_max7219_powersave1_seq); |
|
125 break; |
|
126 */ |
|
127 /* not supported by MAX7219 |
|
128 case U8X8_MSG_DISPLAY_SET_FLIP_MODE: |
|
129 break; |
|
130 */ |
|
131 #ifdef U8X8_WITH_SET_CONTRAST |
|
132 case U8X8_MSG_DISPLAY_SET_CONTRAST: |
|
133 u8x8_cad_StartTransfer(u8x8); |
|
134 for( i = 0; i < u8x8->display_info->tile_width; i++ ) |
|
135 { |
|
136 u8x8_cad_SendCmd(u8x8, 10 ); /* brightness */ |
|
137 u8x8_cad_SendArg(u8x8, (arg_int>>4) ); /* 0..15 for contrast */ |
|
138 } |
|
139 u8x8_cad_EndTransfer(u8x8); |
|
140 break; |
|
141 #endif |
|
142 case U8X8_MSG_DISPLAY_DRAW_TILE: |
|
143 /* transfer always has to start at x pos 0 (u8x8 is not supported) */ |
|
144 /* also y pos has to be 0 */ |
|
145 /* arg_int is ignored */ |
|
146 //x = ((u8x8_tile_t *)arg_ptr)->x_pos; |
|
147 |
|
148 c = ((u8x8_tile_t *)arg_ptr)->cnt; /* number of tiles */ |
|
149 ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; /* data ptr to the tiles */ |
|
150 for( i = 0; i < 8; i++ ) |
|
151 { |
|
152 u8x8_cad_StartTransfer(u8x8); |
|
153 for( j = 0; j < c; j++ ) |
|
154 { |
|
155 u8x8_cad_SendCmd(u8x8, i+1); |
|
156 u8x8_cad_SendArg(u8x8, *ptr ); |
|
157 ptr++; |
|
158 } |
|
159 u8x8_cad_EndTransfer(u8x8); |
|
160 } |
|
161 |
|
162 break; |
|
163 default: |
|
164 return 0; |
|
165 } |
|
166 return 1; |
|
167 } |
|
168 |
|
169 /*==============================*/ |
|
170 |
|
171 static const u8x8_display_info_t u8x8_max7219_32x8_display_info = |
|
172 { |
|
173 /* chip_enable_level = */ 0, |
|
174 /* chip_disable_level = */ 1, |
|
175 |
|
176 /* post_chip_enable_wait_ns = */ 100, |
|
177 /* pre_chip_disable_wait_ns = */ 100, |
|
178 /* reset_pulse_width_ms = */ 100, |
|
179 /* post_reset_wait_ms = */ 100, |
|
180 /* sda_setup_time_ns = */ 100, |
|
181 /* sck_pulse_width_ns = */ 100, |
|
182 /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */ |
|
183 /* spi_mode = */ 0, /* active high, rising edge */ |
|
184 /* i2c_bus_clock_100kHz = */ 4, |
|
185 /* data_setup_time_ns = */ 40, |
|
186 /* write_pulse_width_ns = */ 150, |
|
187 /* tile_width = */ 4, |
|
188 /* tile_hight = */ 1, |
|
189 /* default_x_offset = */ 0, |
|
190 /* flipmode_x_offset = */ 0, |
|
191 /* pixel_width = */ 32, |
|
192 /* pixel_height = */ 8 |
|
193 }; |
|
194 |
|
195 uint8_t u8x8_d_max7219_32x8(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
|
196 { |
|
197 switch(msg) |
|
198 { |
|
199 case U8X8_MSG_DISPLAY_SETUP_MEMORY : |
|
200 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_max7219_32x8_display_info); |
|
201 return 1; |
|
202 case U8X8_MSG_DISPLAY_INIT: |
|
203 u8x8_d_helper_display_init(u8x8); |
|
204 u8x8_cad_SendSequence(u8x8, u8x8_d_max7219_init_seq); |
|
205 return 1; |
|
206 case U8X8_MSG_DISPLAY_SET_POWER_SAVE: |
|
207 if ( arg_int == 0 ) |
|
208 u8x8_cad_SendSequence(u8x8, u8x8_d_max7219_powersave0_seq); |
|
209 else |
|
210 u8x8_cad_SendSequence(u8x8, u8x8_d_max7219_powersave1_seq); |
|
211 return 1; |
|
212 } |
|
213 return u8x8_d_max7219_generic(u8x8, msg, arg_int, arg_ptr); |
|
214 } |
|
215 |
|
216 /*==============================*/ |
|
217 |
|
218 static const u8x8_display_info_t u8x8_max7219_8x8_display_info = |
|
219 { |
|
220 /* chip_enable_level = */ 0, |
|
221 /* chip_disable_level = */ 1, |
|
222 |
|
223 /* post_chip_enable_wait_ns = */ 100, |
|
224 /* pre_chip_disable_wait_ns = */ 100, |
|
225 /* reset_pulse_width_ms = */ 100, |
|
226 /* post_reset_wait_ms = */ 100, |
|
227 /* sda_setup_time_ns = */ 100, |
|
228 /* sck_pulse_width_ns = */ 100, |
|
229 /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */ |
|
230 /* spi_mode = */ 0, /* active high, rising edge */ |
|
231 /* i2c_bus_clock_100kHz = */ 4, |
|
232 /* data_setup_time_ns = */ 40, |
|
233 /* write_pulse_width_ns = */ 150, |
|
234 /* tile_width = */ 1, |
|
235 /* tile_hight = */ 1, |
|
236 /* default_x_offset = */ 0, |
|
237 /* flipmode_x_offset = */ 0, |
|
238 /* pixel_width = */ 8, |
|
239 /* pixel_height = */ 8 |
|
240 }; |
|
241 |
|
242 uint8_t u8x8_d_max7219_8x8(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
|
243 { |
|
244 switch(msg) |
|
245 { |
|
246 case U8X8_MSG_DISPLAY_SETUP_MEMORY : |
|
247 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_max7219_8x8_display_info); |
|
248 return 1; |
|
249 case U8X8_MSG_DISPLAY_INIT: |
|
250 u8x8_d_helper_display_init(u8x8); |
|
251 u8x8_cad_SendSequence(u8x8, u8x8_d_max7219_init_seq); |
|
252 return 1; |
|
253 case U8X8_MSG_DISPLAY_SET_POWER_SAVE: |
|
254 if ( arg_int == 0 ) |
|
255 u8x8_cad_SendSequence(u8x8, u8x8_d_max7219_powersave0_seq); |
|
256 else |
|
257 u8x8_cad_SendSequence(u8x8, u8x8_d_max7219_powersave1_seq); |
|
258 return 1; |
|
259 } |
|
260 return u8x8_d_max7219_generic(u8x8, msg, arg_int, arg_ptr); |
|
261 } |
|
262 |
|
263 |
|
264 /*==============================*/ |
|
265 |
|
266 static const uint8_t u8x8_d_max7219_8_init_seq[] = { |
|
267 |
|
268 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
269 U8X8_CA(15, 0), /* test mode off */ |
|
270 U8X8_CA(15, 0), /* test mode off */ |
|
271 U8X8_CA(15, 0), /* test mode off */ |
|
272 U8X8_CA(15, 0), /* test mode off */ |
|
273 U8X8_CA(15, 0), /* test mode off */ |
|
274 U8X8_CA(15, 0), /* test mode off */ |
|
275 U8X8_CA(15, 0), /* test mode off */ |
|
276 U8X8_CA(15, 0), /* test mode off */ |
|
277 U8X8_END_TRANSFER(), /* disable chip */ |
|
278 |
|
279 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
280 U8X8_CA(12, 0), /* */ |
|
281 U8X8_CA(12, 0), /* */ |
|
282 U8X8_CA(12, 0), /* */ |
|
283 U8X8_CA(12, 0), /* */ |
|
284 U8X8_CA(12, 0), /* */ |
|
285 U8X8_CA(12, 0), /* */ |
|
286 U8X8_CA(12, 0), /* */ |
|
287 U8X8_CA(12, 0), /* */ |
|
288 U8X8_END_TRANSFER(), /* disable chip */ |
|
289 |
|
290 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
291 U8X8_CA(9, 0), /* decode mode: graphics */ |
|
292 U8X8_CA(9, 0), /* decode mode: graphics */ |
|
293 U8X8_CA(9, 0), /* decode mode: graphics */ |
|
294 U8X8_CA(9, 0), /* decode mode: graphics */ |
|
295 U8X8_CA(9, 0), /* decode mode: graphics */ |
|
296 U8X8_CA(9, 0), /* decode mode: graphics */ |
|
297 U8X8_CA(9, 0), /* decode mode: graphics */ |
|
298 U8X8_CA(9, 0), /* decode mode: graphics */ |
|
299 U8X8_END_TRANSFER(), /* disable chip */ |
|
300 |
|
301 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
302 U8X8_CA(10, 10), /* medium high intensity */ |
|
303 U8X8_CA(10, 10), /* medium high intensity */ |
|
304 U8X8_CA(10, 10), /* medium high intensity */ |
|
305 U8X8_CA(10, 10), /* medium high intensity */ |
|
306 U8X8_CA(10, 10), /* medium high intensity */ |
|
307 U8X8_CA(10, 10), /* medium high intensity */ |
|
308 U8X8_CA(10, 10), /* medium high intensity */ |
|
309 U8X8_CA(10, 10), /* medium high intensity */ |
|
310 U8X8_END_TRANSFER(), /* disable chip */ |
|
311 |
|
312 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
313 U8X8_CA(11, 7), /* scan limit: display all digits (assuming a 8x8 matrix) */ |
|
314 U8X8_CA(11, 7), /* scan limit: display all digits (assuming a 8x8 matrix) */ |
|
315 U8X8_CA(11, 7), /* scan limit: display all digits (assuming a 8x8 matrix) */ |
|
316 U8X8_CA(11, 7), /* scan limit: display all digits (assuming a 8x8 matrix) */ |
|
317 U8X8_CA(11, 7), /* scan limit: display all digits (assuming a 8x8 matrix) */ |
|
318 U8X8_CA(11, 7), /* scan limit: display all digits (assuming a 8x8 matrix) */ |
|
319 U8X8_CA(11, 7), /* scan limit: display all digits (assuming a 8x8 matrix) */ |
|
320 U8X8_CA(11, 7), /* scan limit: display all digits (assuming a 8x8 matrix) */ |
|
321 U8X8_END_TRANSFER(), /* disable chip */ |
|
322 |
|
323 |
|
324 //U8X8_CA(12, 0), /* shutdown */ |
|
325 |
|
326 //U8X8_END_TRANSFER(), /* disable chip */ |
|
327 U8X8_END() /* end of sequence */ |
|
328 }; |
|
329 |
|
330 static const uint8_t u8x8_d_max7219_8_powersave0_seq[] = { |
|
331 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
332 U8X8_CA(12, 1), /* display on */ |
|
333 U8X8_CA(12, 1), /* display on */ |
|
334 U8X8_CA(12, 1), /* display on */ |
|
335 U8X8_CA(12, 1), /* display on */ |
|
336 U8X8_CA(12, 1), /* display on */ |
|
337 U8X8_CA(12, 1), /* display on */ |
|
338 U8X8_CA(12, 1), /* display on */ |
|
339 U8X8_CA(12, 1), /* display on */ |
|
340 U8X8_END_TRANSFER(), /* disable chip */ |
|
341 U8X8_END() /* end of sequence */ |
|
342 }; |
|
343 |
|
344 static const uint8_t u8x8_d_max7219_8_powersave1_seq[] = { |
|
345 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
346 U8X8_CA(12, 0), /* shutdown */ |
|
347 U8X8_CA(12, 0), /* shutdown */ |
|
348 U8X8_CA(12, 0), /* shutdown */ |
|
349 U8X8_CA(12, 0), /* shutdown */ |
|
350 U8X8_CA(12, 0), /* shutdown */ |
|
351 U8X8_CA(12, 0), /* shutdown */ |
|
352 U8X8_CA(12, 0), /* shutdown */ |
|
353 U8X8_CA(12, 0), /* shutdown */ |
|
354 U8X8_END_TRANSFER(), /* disable chip */ |
|
355 U8X8_END() /* end of sequence */ |
|
356 }; |
|
357 |
|
358 |
|
359 static const u8x8_display_info_t u8x8_max7219_64x8_display_info = |
|
360 { |
|
361 /* chip_enable_level = */ 0, |
|
362 /* chip_disable_level = */ 1, |
|
363 |
|
364 /* post_chip_enable_wait_ns = */ 100, |
|
365 /* pre_chip_disable_wait_ns = */ 100, |
|
366 /* reset_pulse_width_ms = */ 100, |
|
367 /* post_reset_wait_ms = */ 100, |
|
368 /* sda_setup_time_ns = */ 100, |
|
369 /* sck_pulse_width_ns = */ 100, |
|
370 /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */ |
|
371 /* spi_mode = */ 0, /* active high, rising edge */ |
|
372 /* i2c_bus_clock_100kHz = */ 4, |
|
373 /* data_setup_time_ns = */ 40, |
|
374 /* write_pulse_width_ns = */ 150, |
|
375 /* tile_width = */ 8, |
|
376 /* tile_hight = */ 1, |
|
377 /* default_x_offset = */ 0, |
|
378 /* flipmode_x_offset = */ 0, |
|
379 /* pixel_width = */ 64, |
|
380 /* pixel_height = */ 8 |
|
381 }; |
|
382 |
|
383 uint8_t u8x8_d_max7219_64x8(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
|
384 { |
|
385 switch(msg) |
|
386 { |
|
387 case U8X8_MSG_DISPLAY_SETUP_MEMORY : |
|
388 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_max7219_64x8_display_info); |
|
389 return 1; |
|
390 case U8X8_MSG_DISPLAY_INIT: |
|
391 u8x8_d_helper_display_init(u8x8); |
|
392 u8x8_cad_SendSequence(u8x8, u8x8_d_max7219_8_init_seq); |
|
393 return 1; |
|
394 case U8X8_MSG_DISPLAY_SET_POWER_SAVE: |
|
395 if ( arg_int == 0 ) |
|
396 u8x8_cad_SendSequence(u8x8, u8x8_d_max7219_8_powersave0_seq); |
|
397 else |
|
398 u8x8_cad_SendSequence(u8x8, u8x8_d_max7219_8_powersave1_seq); |
|
399 return 1; |
|
400 } |
|
401 return u8x8_d_max7219_generic(u8x8, msg, arg_int, arg_ptr); |
|
402 } |
|
403 |
|
404 |