LibDriver MAX7219
Loading...
Searching...
No Matches
driver_max7219_matrix_cascade_test.c
Go to the documentation of this file.
1
37
39
40static max7219_handle_t gs_handle;
42static uint8_t gs_matrix[MATRIX_CASCADE_TEST_LENGTH][8];
43
52{
53 uint8_t res;
54 uint32_t i, j;
55 max7219_info_t info;
56
57 /* link functions */
65
66 /* max7219 info */
67 res = max7219_info(&info);
68 if (res != 0)
69 {
70 max7219_interface_debug_print("max7219: get info failed.\n");
71
72 return 1;
73 }
74 else
75 {
76 /* print chip information */
77 max7219_interface_debug_print("max7219: chip is %s.\n", info.chip_name);
78 max7219_interface_debug_print("max7219: manufacturer is %s.\n", info.manufacturer_name);
79 max7219_interface_debug_print("max7219: interface is %s.\n", info.interface);
80 max7219_interface_debug_print("max7219: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
81 max7219_interface_debug_print("max7219: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
82 max7219_interface_debug_print("max7219: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
83 max7219_interface_debug_print("max7219: max current is %0.2fmA.\n", info.max_current_ma);
84 max7219_interface_debug_print("max7219: max temperature is %0.1fC.\n", info.temperature_max);
85 max7219_interface_debug_print("max7219: min temperature is %0.1fC.\n", info.temperature_min);
86 }
87
88 /* start matrix cascade test */
89 max7219_interface_debug_print("max7219: start matrix cascade test.\n");
90
91 /* max7219 init */
92 res = max7219_init(&gs_handle);
93 if (res != 0)
94 {
95 max7219_interface_debug_print("max7219: init failed.\n");
96
97 return 1;
98 }
99
100 /* set no decode */
101 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
102 {
103 gs_cascade[i].command = MAX7219_CASCADE_COMMAND_DECODE;
104 gs_cascade[i].data = MAX7219_DECODE_CODEB_DIGITS_NONE;
105 }
106 res = max7219_set_cascade(&gs_handle, (max7219_cascade_t *)gs_cascade, MATRIX_CASCADE_TEST_LENGTH);
107 if (res != 0)
108 {
109 max7219_interface_debug_print("max7219: set cascade failed.\n");
110 (void)max7219_deinit(&gs_handle);
111
112 return 1;
113 }
114
115 /* set intensity */
116 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
117 {
118 gs_cascade[i].command = MAX7219_CASCADE_COMMAND_INTENSITY;
119 gs_cascade[i].data = MAX7219_INTENSITY_31_32;
120 }
121 res = max7219_set_cascade(&gs_handle, (max7219_cascade_t *)gs_cascade, MATRIX_CASCADE_TEST_LENGTH);
122 if (res != 0)
123 {
124 max7219_interface_debug_print("max7219: set cascade failed.\n");
125 (void)max7219_deinit(&gs_handle);
126
127 return 1;
128 }
129
130 /* set scan limit digit 0-7 */
131 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
132 {
133 gs_cascade[i].command = MAX7219_CASCADE_COMMAND_SCAN_LIMIT;
134 gs_cascade[i].data = MAX7219_SCAN_LIMIT_DIGIT_0_7;
135 }
136 res = max7219_set_cascade(&gs_handle, (max7219_cascade_t *)gs_cascade, MATRIX_CASCADE_TEST_LENGTH);
137 if (res != 0)
138 {
139 max7219_interface_debug_print("max7219: set cascade failed.\n");
140 (void)max7219_deinit(&gs_handle);
141
142 return 1;
143 }
144
145 /* set display test off */
146 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
147 {
148 gs_cascade[i].command = MAX7219_CASCADE_COMMAND_DISPLAY_TEST;
149 gs_cascade[i].data = MAX7219_DISPLAY_TEST_MODE_OFF;
150 }
151 res = max7219_set_cascade(&gs_handle, (max7219_cascade_t *)gs_cascade, MATRIX_CASCADE_TEST_LENGTH);
152 if (res != 0)
153 {
154 max7219_interface_debug_print("max7219: set display test off failed.\n");
155 (void)max7219_deinit(&gs_handle);
156
157 return 1;
158 }
159
160 /* set power on */
161 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
162 {
163 gs_cascade[i].command = MAX7219_CASCADE_COMMAND_SHUT_DOWN;
164 gs_cascade[i].data = MAX7219_MODE_NORMAL;
165 }
166 res = max7219_set_cascade(&gs_handle, (max7219_cascade_t *)gs_cascade, MATRIX_CASCADE_TEST_LENGTH);
167 if (res != 0)
168 {
169 max7219_interface_debug_print("max7219: set display test off failed.\n");
170 (void)max7219_deinit(&gs_handle);
171
172 return 1;
173 }
174
175 /* set rows display */
176 max7219_interface_debug_print("max7219: set rows display.\n");
177 for (j = 0; j < 8; j++)
178 {
179 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
180 {
181 if ((j % 2) != 0)
182 {
183 gs_matrix[i][j] = 0xFF;
184 }
185 else
186 {
187 gs_matrix[i][j] = 0x00;
188 }
189 }
190 }
191 for (j = 0; j < 8; j++)
192 {
193 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
194 {
195 gs_cascade[i].command = (max7219_cascade_command_t)(j + 1);
196 gs_cascade[i].data = gs_matrix[i][j];
197 }
198 res = max7219_set_cascade(&gs_handle, (max7219_cascade_t *)gs_cascade, MATRIX_CASCADE_TEST_LENGTH);
199 if (res != 0)
200 {
201 max7219_interface_debug_print("max7219: set display test off failed.\n");
202 (void)max7219_deinit(&gs_handle);
203
204 return 1;
205 }
206 }
207
208 /* delay 3000 ms */
210
211 /* set column display */
212 max7219_interface_debug_print("max7219: set column display.\n");
213 for (j = 0; j < 8; j++)
214 {
215 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
216 {
217 gs_matrix[i][j] = 0xAA;
218 }
219 }
220 for (j = 0; j < 8; j++)
221 {
222 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
223 {
224 gs_cascade[i].command = (max7219_cascade_command_t)(j + 1);
225 gs_cascade[i].data = gs_matrix[i][j];
226 }
227 res = max7219_set_cascade(&gs_handle, (max7219_cascade_t *)gs_cascade, MATRIX_CASCADE_TEST_LENGTH);
228 if (res != 0)
229 {
230 max7219_interface_debug_print("max7219: set display test off failed.\n");
231 (void)max7219_deinit(&gs_handle);
232
233 return 1;
234 }
235 }
236
237 /* delay 3000 ms */
239
240 /* set cross */
241 max7219_interface_debug_print("max7219: set cross.\n");
242 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
243 {
244 gs_matrix[i][0] = 0x18;
245 }
246 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
247 {
248 gs_matrix[i][1] = 0x18;
249 }
250 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
251 {
252 gs_matrix[i][2] = 0x18;
253 }
254 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
255 {
256 gs_matrix[i][3] = 0xFF;
257 }
258 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
259 {
260 gs_matrix[i][4] = 0xFF;
261 }
262 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
263 {
264 gs_matrix[i][5] = 0x18;
265 }
266 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
267 {
268 gs_matrix[i][6] = 0x18;
269 }
270 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
271 {
272 gs_matrix[i][7] = 0x18;
273 }
274 for (j = 0; j < 8; j++)
275 {
276 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
277 {
278 gs_cascade[i].command = (max7219_cascade_command_t)(j + 1);
279 gs_cascade[i].data = gs_matrix[i][j];
280 }
281 res = max7219_set_cascade(&gs_handle, (max7219_cascade_t *)gs_cascade, MATRIX_CASCADE_TEST_LENGTH);
282 if (res != 0)
283 {
284 max7219_interface_debug_print("max7219: set display test off failed.\n");
285 (void)max7219_deinit(&gs_handle);
286
287 return 1;
288 }
289 }
290
291 /* delay 3000 ms */
293
294 /* set mixed pattern display */
295 max7219_interface_debug_print("max7219: set mixed pattern display.\n");
296 for (j = 0; j < 8; j++)
297 {
298 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH/2; i++)
299 {
300 gs_matrix[i][j] = 0xAA;
301 }
303 {
304 if ((j % 2) != 0)
305 {
306 gs_matrix[i][j] = 0xFF;
307 }
308 else
309 {
310 gs_matrix[i][j] = 0x00;
311 }
312 }
313 }
314 for (j = 0; j < 8; j++)
315 {
316 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
317 {
318 gs_cascade[i].command = (max7219_cascade_command_t)(j + 1);
319 gs_cascade[i].data = gs_matrix[i][j];
320 }
321 res = max7219_set_cascade(&gs_handle, (max7219_cascade_t *)gs_cascade, MATRIX_CASCADE_TEST_LENGTH);
322 if (res != 0)
323 {
324 max7219_interface_debug_print("max7219: set display test off failed.\n");
325 (void)max7219_deinit(&gs_handle);
326
327 return 1;
328 }
329 }
330
331 /* delay 3000 ms */
333 max7219_interface_debug_print("max7219: power off all.\n");
334
335 /* set power off */
336 for (i = 0; i < MATRIX_CASCADE_TEST_LENGTH; i++)
337 {
338 gs_cascade[i].command = MAX7219_CASCADE_COMMAND_SHUT_DOWN;
339 gs_cascade[i].data = MAX7219_MODE_SHUT_DOWN;
340 }
341 res = max7219_set_cascade(&gs_handle, (max7219_cascade_t *)gs_cascade, MATRIX_CASCADE_TEST_LENGTH);
342 if (res != 0)
343 {
344 max7219_interface_debug_print("max7219: set display test off failed.\n");
345 (void)max7219_deinit(&gs_handle);
346
347 return 1;
348 }
349
350 /* finish matrix cascade test */
351 max7219_interface_debug_print("max7219: finish matrix cascade test.\n");
352 (void)max7219_deinit(&gs_handle);
353
354 return 0;
355}
driver max7219 matrix cascade test header file
uint8_t max7219_info(max7219_info_t *info)
get chip's information
uint8_t max7219_init(max7219_handle_t *handle)
initialize the chip
uint8_t max7219_deinit(max7219_handle_t *handle)
close the chip
struct max7219_info_s max7219_info_t
max7219 info structure definition
struct max7219_handle_s max7219_handle_t
max7219 handle structure definition
@ MAX7219_DISPLAY_TEST_MODE_OFF
@ MAX7219_DECODE_CODEB_DIGITS_NONE
@ MAX7219_SCAN_LIMIT_DIGIT_0_7
@ MAX7219_MODE_SHUT_DOWN
@ MAX7219_MODE_NORMAL
@ MAX7219_INTENSITY_31_32
uint8_t max7219_set_cascade(max7219_handle_t *handle, max7219_cascade_t *cascade, uint16_t len)
set the cascade data
max7219_cascade_command_t
max7219 cascade command enumeration definition
struct max7219_cascade_s max7219_cascade_t
max7219 cascade structure definition
@ MAX7219_CASCADE_COMMAND_DECODE
@ MAX7219_CASCADE_COMMAND_SCAN_LIMIT
@ MAX7219_CASCADE_COMMAND_SHUT_DOWN
@ MAX7219_CASCADE_COMMAND_DISPLAY_TEST
@ MAX7219_CASCADE_COMMAND_INTENSITY
uint8_t max7219_interface_spi_init(void)
interface spi bus init
uint8_t max7219_interface_spi_deinit(void)
interface spi bus deinit
uint8_t max7219_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t max7219_interface_spi_write_cmd(uint8_t *buf, uint16_t len)
interface spi bus write command
void max7219_interface_delay_ms(uint32_t ms)
interface delay ms
void max7219_interface_debug_print(const char *const fmt,...)
interface print format data
#define MATRIX_CASCADE_TEST_LENGTH
max7219 matrix cascade length definition
uint8_t max7219_matrix_cascade_test(void)
matrix cascade test
uint32_t driver_version
char manufacturer_name[32]