Rev 346 | Rev 379 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 346 | Rev 349 | ||
---|---|---|---|
1 | /**************************************************************************** |
1 | /**************************************************************************** |
2 | * Copyright (C) 2009 by Claas Anders "CaScAdE" Rathje * |
2 | * Copyright (C) 2009 by Claas Anders "CaScAdE" Rathje * |
3 | * admiralcascade@gmail.com * |
3 | * admiralcascade@gmail.com * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-osd/ * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-osd/ * |
5 | * * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License. * |
8 | * the Free Software Foundation; either version 2 of the License. * |
9 | * * |
9 | * * |
10 | * This program is distributed in the hope that it will be useful, * |
10 | * This program is distributed in the hope that it will be useful, * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 | * GNU General Public License for more details. * |
13 | * GNU General Public License for more details. * |
14 | * * |
14 | * * |
15 | * You should have received a copy of the GNU General Public License * |
15 | * You should have received a copy of the GNU General Public License * |
16 | * along with this program; if not, write to the * |
16 | * along with this program; if not, write to the * |
17 | * Free Software Foundation, Inc., * |
17 | * Free Software Foundation, Inc., * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 | ****************************************************************************/ |
19 | ****************************************************************************/ |
20 | 20 | ||
21 | #include <avr/io.h> |
21 | #include <avr/io.h> |
22 | #include <util/delay.h> |
22 | #include <util/delay.h> |
23 | #include <avr/pgmspace.h> |
23 | #include <avr/pgmspace.h> |
24 | #include "max7456_software_spi.h" |
24 | #include "max7456_software_spi.h" |
25 | 25 | ||
26 | /* ########################################################################## |
26 | /* ########################################################################## |
27 | * MAX7456 SPI & Display stuff |
27 | * MAX7456 SPI & Display stuff |
28 | * ##########################################################################*/ |
28 | * ##########################################################################*/ |
29 | 29 | ||
30 | /** |
30 | /** |
31 | * Send a byte through SPI |
31 | * Send a byte through SPI |
32 | */ |
32 | */ |
33 | void spi_send(uint8_t byte) { |
33 | void spi_send(uint8_t byte) { |
34 | for (int8_t i = 7; i >= 0; i--) { |
34 | for (int8_t i = 7; i >= 0; i--) { |
35 | if (((byte >> i) & 1)) { |
35 | if (((byte >> i) & 1)) { |
36 | MAX_SDIN_HIGH |
36 | MAX_SDIN_HIGH |
37 | } else { |
37 | } else { |
38 | MAX_SDIN_LOW |
38 | MAX_SDIN_LOW |
39 | } |
39 | } |
40 | MAX_SCLK_HIGH |
40 | MAX_SCLK_HIGH |
41 | MAX_SCLK_LOW |
41 | MAX_SCLK_LOW |
42 | } |
42 | } |
43 | } |
43 | } |
44 | 44 | ||
45 | /** |
45 | /** |
46 | * Send <byte> to <address> of MAX7456 |
46 | * Send <byte> to <address> of MAX7456 |
47 | */ |
47 | */ |
48 | void spi_send_byte(uint8_t address, uint8_t byte) { |
48 | void spi_send_byte(uint8_t address, uint8_t byte) { |
49 | // start sending |
49 | // start sending |
50 | MAX_CS_LOW |
50 | MAX_CS_LOW |
51 | 51 | ||
52 | spi_send(address); |
52 | spi_send(address); |
53 | spi_send(byte); |
53 | spi_send(byte); |
54 | 54 | ||
55 | // end sending |
55 | // end sending |
56 | MAX_CS_HIGH |
56 | MAX_CS_HIGH |
57 | } |
57 | } |
58 | 58 | ||
59 | /** |
59 | /** |
60 | * write a <character> to <address> of MAX7456 display memory |
60 | * write a <character> to <address> of MAX7456 display memory |
61 | */ |
61 | */ |
62 | void write_char(uint16_t address, char character) { |
62 | void write_char(uint16_t address, char character) { |
63 | spi_send_byte(0x05, (address & 0xFF00) >> 8); // DMAH |
63 | spi_send_byte(0x05, (address & 0xFF00) >> 8); // DMAH |
64 | spi_send_byte(0x06, (address & 0x00FF)); // DMAL |
64 | spi_send_byte(0x06, (address & 0x00FF)); // DMAL |
65 | spi_send_byte(0x07, character); // DMDI |
65 | spi_send_byte(0x07, character); // DMDI |
66 | } |
66 | } |
67 | 67 | ||
68 | /** |
68 | /** |
69 | * write a character <attribute> to <address> of MAX7456 display memory |
69 | * write a character <attribute> to <address> of MAX7456 display memory |
70 | */ |
70 | */ |
71 | void write_char_att(uint16_t address, char attribute) { |
71 | void write_char_att(uint16_t address, char attribute) { |
72 | // the only important part is that the DMAH[1] is set |
72 | // the only important part is that the DMAH[1] is set |
73 | // so we add 2 which binary is the 2nd lowest byte |
73 | // so we add 2 which binary is the 2nd lowest byte |
74 | spi_send_byte(0x05, ((address & 0xFF00) >> 8) | 2); // DMAH |
74 | spi_send_byte(0x05, ((address & 0xFF00) >> 8) | 2); // DMAH |
75 | spi_send_byte(0x06, (address & 0x00FF)); // DMAL |
75 | spi_send_byte(0x06, (address & 0x00FF)); // DMAL |
76 | spi_send_byte(0x07, attribute); // DMDI |
76 | spi_send_byte(0x07, attribute); // DMDI |
77 | } |
77 | } |
78 | 78 | ||
79 | /** |
79 | /** |
80 | * write a <character> at <x>/<y> to MAX7456 display memory |
80 | * write a <character> at <x>/<y> to MAX7456 display memory |
81 | */ |
81 | */ |
82 | void write_char_xy(uint8_t x, uint8_t y, char character) { |
82 | void write_char_xy(uint8_t x, uint8_t y, char character) { |
83 | uint16_t address = y * 30 + x; |
83 | uint16_t address = y * 30 + x; |
84 | write_char(address, character); |
84 | write_char(address, character); |
85 | } |
85 | } |
86 | 86 | ||
87 | /** |
87 | /** |
88 | * write a character <attribute> at <x>/<y> to MAX7456 display memory |
88 | * write a character <attribute> at <x>/<y> to MAX7456 display memory |
89 | */ |
89 | */ |
90 | void write_char_att_xy(uint8_t x, uint8_t y, char attribute) { |
90 | void write_char_att_xy(uint8_t x, uint8_t y, char attribute) { |
91 | uint16_t address = y * 30 + x; |
91 | uint16_t address = y * 30 + x; |
92 | write_char_att(address, attribute); |
92 | write_char_att(address, attribute); |
93 | } |
93 | } |
94 | 94 | ||
95 | /** |
95 | /** |
96 | * clear display by writing blank characters all over it |
96 | * clear display by writing blank characters all over it |
97 | */ |
97 | */ |
98 | void clear(void) { |
98 | void clear(void) { |
99 | uint16_t memory_address = 0; |
99 | uint16_t memory_address = 0; |
100 | for (unsigned int a = 0; a < 480; a++) { |
100 | for (unsigned int a = 0; a < 480; a++) { |
101 | write_char(memory_address++, 0); |
101 | write_char(memory_address++, 0); |
102 | } |
102 | } |
103 | } |
103 | } |
104 | 104 | ||
105 | /** |
105 | /** |
106 | * write an ascii <character> to <address> of MAX7456 display memory |
106 | * write an ascii <character> to <address> of MAX7456 display memory |
107 | */ |
107 | */ |
108 | void write_ascii_char(uint16_t address, char c) { |
108 | void write_ascii_char(uint16_t address, char c) { |
109 | if (c == 32) c = 0; // remap space |
109 | if (c == 32) c = 0; // remap space |
110 | else if (c > 48 && c <= 57) c -= 48; // remap numbers |
110 | else if (c > 48 && c <= 57) c -= 48; // remap numbers |
111 | else if (c == '0') c = 10; // remap zero |
111 | else if (c == '0') c = 10; // remap zero |
112 | else if (c >= 65 && c <= 90) c -= 54; // remap big letters |
112 | else if (c >= 65 && c <= 90) c -= 54; // remap big letters |
113 | else if (c >= 97 && c <= 122) c -= 60; // remap small letters |
113 | else if (c >= 97 && c <= 122) c -= 60; // remap small letters |
114 | else if (c == '(') c = 63; // remap |
114 | else if (c == '(') c = 63; // remap |
115 | else if (c == ')') c = 64; // remap |
115 | else if (c == ')') c = 64; // remap |
116 | else if (c == '.') c = 65; // remap |
116 | else if (c == '.') c = 65; // remap |
117 | else if (c == '?') c = 66; // remap |
117 | else if (c == '?') c = 66; // remap |
118 | else if (c == ';') c = 67; // remap |
118 | else if (c == ';') c = 67; // remap |
119 | else if (c == ':') c = 68; // remap |
119 | else if (c == ':') c = 68; // remap |
120 | else if (c == ',') c = 69; // remap |
120 | else if (c == ',') c = 69; // remap |
121 | else if (c == '\'') c = 70; // remap |
121 | else if (c == '\'') c = 70; // remap |
122 | else if (c == '/') c = 71; // remap |
122 | else if (c == '/') c = 71; // remap |
123 | else if (c == '"') c = 72; // remap |
123 | else if (c == '"') c = 72; // remap |
124 | else if (c == '-') c = 73; // remap minus |
124 | else if (c == '-') c = 73; // remap minus |
125 | else if (c == '<') c = 74; // remap |
125 | else if (c == '<') c = 74; // remap |
126 | else if (c == '>') c = 75; // remap |
126 | else if (c == '>') c = 75; // remap |
127 | else if (c == '@') c = 76; // remap |
127 | else if (c == '@') c = 76; // remap |
128 | write_char(address, c); |
128 | write_char(address, c); |
129 | } |
129 | } |
130 | 130 | ||
131 | /** |
131 | /** |
132 | * write an ascii <string> at <x>/<y> to MAX7456 display memory |
132 | * write an ascii <string> at <x>/<y> to MAX7456 display memory |
133 | */ |
133 | */ |
134 | void write_ascii_string(uint8_t x, uint8_t y, char *string) { |
134 | void write_ascii_string(uint8_t x, uint8_t y, char *string) { |
135 | while (*string) { |
135 | while (*string) { |
136 | write_ascii_char(((x++)+(y * 30)), *string); |
136 | write_ascii_char(((x++)+(y * 30)), *string); |
137 | string++; |
137 | string++; |
138 | } |
138 | } |
139 | } |
139 | } |
140 | 140 | ||
141 | /** |
141 | /** |
142 | * write an ascii <string> from progmen at <x>/<y> to MAX7456 display memory |
142 | * write an ascii <string> from progmen at <x>/<y> to MAX7456 display memory |
143 | */ |
143 | */ |
144 | void write_ascii_string_pgm(uint8_t x, uint8_t y, char *string) { |
144 | void write_ascii_string_pgm(uint8_t x, uint8_t y, char *string) { |
145 | while (pgm_read_byte(string) != 0x00) |
145 | while (pgm_read_byte(string) != 0x00) |
146 | write_ascii_char(((x++)+(y * 30)), pgm_read_byte(string++)); |
146 | write_ascii_char(((x++)+(y * 30)), pgm_read_byte(string++)); |
147 | } |
147 | } |
148 | 148 | ||
149 | /** |
149 | /** |
150 | * Write only the last three digits of a <number> at <x>/<y> to MAX7456 |
150 | * Write only some digits of a unsigned <number> at <x>/<y> to MAX7456 display memory |
151 | * display memory. takes full 16bit numbers as well for stuff |
151 | * <num> represents the largest multiple of 10 that will still be displayable as |
152 | * like compass only taking three characters (values <= 999) |
152 | * the first digit, so num = 10 will be 0-99 and so on |
- | 153 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
|
153 | */ |
154 | */ |
154 | void write_3digit_number_u(uint8_t x, uint8_t y, uint16_t number) { |
155 | void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t num, uint8_t pad) { |
155 | uint16_t num = 100; |
- | |
156 | uint8_t started = 0; |
- | |
157 | - | ||
158 | while (num > 0) { |
- | |
159 | uint8_t b = number / num; |
- | |
160 | if (b > 0 || started || num == 1) { |
- | |
161 | write_ascii_char((x++)+(y * 30), '0' + b); |
156 | // if number is largar than 99[..]9 we must decrease it |
162 | started = 1; |
- | |
163 | } else { |
- | |
164 | write_ascii_char((x++)+(y * 30), 0); |
- | |
165 | } |
- | |
166 | number -= b * num; |
157 | while (number >= (num * 10)) { |
167 | - | ||
168 | num /= 10; |
158 | number -= num * 10; |
169 | } |
- | |
170 | } |
159 | } |
171 | 160 | ||
172 | /** |
- | |
173 | * Write only the last two digits of a number at <x>/<y> to MAX7456 |
- | |
174 | * display memory. takes full 16bit numbers as well for stuff |
- | |
175 | * like seconds only taking two characters (values <= 99) |
- | |
176 | * Since this is used for seconds only and it looks better, there |
- | |
177 | * is a trading 0 attached |
- | |
178 | */ |
- | |
179 | void write_2digit_number_u(uint8_t x, uint8_t y, uint16_t number) { |
- | |
180 | uint16_t num = 10; |
- | |
181 | uint8_t started = 0; |
161 | uint8_t started = 0; |
182 | 162 | ||
183 | while (num > 0) { |
163 | while (num > 0) { |
184 | uint8_t b = number / num; |
164 | uint8_t b = number / num; |
185 | if (b > 0 || started || num == 1) { |
165 | if (b > 0 || started || num == 1) { |
186 | write_ascii_char((x++)+(y * 30), '0' + b); |
166 | write_ascii_char((x++)+(y * 30), '0' + b); |
187 | started = 1; |
167 | started = 1; |
188 | } else { |
168 | } else { |
189 | write_ascii_char((x++)+(y * 30), '0'); |
169 | if (pad) write_ascii_char((x++)+(y * 30), '0'); |
- | 170 | else write_ascii_char((x++)+(y * 30), 0); |
|
190 | } |
171 | } |
191 | number -= b * num; |
172 | number -= b * num; |
192 | 173 | ||
193 | num /= 10; |
174 | num /= 10; |
194 | } |
175 | } |
195 | } |
176 | } |
196 | 177 | ||
197 | /** |
178 | /** |
198 | * write a unsigned number as /10th at <x>/<y> to MAX7456 display memory |
179 | * Write only some digits of a signed <number> at <x>/<y> to MAX7456 display memory |
- | 180 | * <num> represents the largest multiple of 10 that will still be displayable as |
|
- | 181 | * the first digit, so num = 10 will be 0-99 and so on |
|
- | 182 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
|
199 | */ |
183 | */ |
200 | void write_number_u_10th(uint8_t x, uint8_t y, uint16_t number) { |
184 | void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t num, uint8_t pad) { |
201 | uint16_t num = 10000; |
185 | if (((uint16_t) number) > 32767) { |
202 | uint8_t started = 0; |
186 | number = number - 65536; |
203 | - | ||
204 | while (num > 0) { |
187 | num *= -1; |
205 | uint8_t b = number / num; |
- | |
206 | 188 | ||
207 | if (b > 0 || started || num == 1) { |
- | |
208 | if ((num / 10) == 0) write_char((x++)+(y * 30), 65); |
- | |
209 | write_ascii_char((x++)+(y * 30), '0' + b); |
189 | // if number is smaller than -99[..]9 we must increase it |
210 | started = 1; |
- | |
211 | } else { |
- | |
212 | write_ascii_char((x++)+(y * 30), 0); |
- | |
213 | } |
- | |
214 | number -= b * num; |
190 | while (number <= (num * 10)) { |
215 | - | ||
216 | num /= 10; |
191 | number -= num * 10; |
217 | } |
- | |
218 | } |
192 | } |
219 | 193 | ||
220 | /** |
- | |
221 | * write a unsigned number at <x>/<y> to MAX7456 display memory |
- | |
222 | */ |
- | |
223 | void write_number_u(uint8_t x, uint8_t y, uint16_t number) { |
- | |
224 | uint16_t num = 10000; |
- | |
225 | uint8_t started = 0; |
194 | uint8_t started = 0; |
226 | 195 | ||
227 | while (num > 0) { |
196 | while (num < 0) { |
228 | uint8_t b = number / num; |
197 | uint8_t b = number / num; |
- | 198 | if (pad) write_ascii_char((x)+(y * 30), '0'); |
|
229 | if (b > 0 || started || num == 1) { |
199 | if (b > 0 || started || num == 1) { |
- | 200 | if (!started) write_char((x - 1)+(y * 30), 0x49); |
|
230 | write_ascii_char((x++)+(y * 30), '0' + b); |
201 | write_ascii_char((x++)+(y * 30), '0' + b); |
231 | started = 1; |
202 | started = 1; |
232 | } else { |
203 | } else { |
233 | write_ascii_char((x++)+(y * 30), 0); |
204 | write_ascii_char((x++)+(y * 30), 0); |
234 | } |
205 | } |
235 | number -= b * num; |
206 | number -= b * num; |
236 | 207 | ||
237 | num /= 10; |
208 | num /= 10; |
- | 209 | } |
|
- | 210 | } else { |
|
- | 211 | write_char((x)+(y * 30), 0); |
|
- | 212 | write_ndigit_number_u(x, y, number, num, pad); |
|
238 | } |
213 | } |
239 | } |
214 | } |
240 | 215 | ||
241 | /** |
216 | /** |
- | 217 | * Write only some digits of a unsigned <number> at <x>/<y> to MAX7456 display memory |
|
- | 218 | * as /10th of the value |
|
- | 219 | * <num> represents the largest multiple of 10 that will still be displayable as |
|
- | 220 | * the first digit, so num = 10 will be 0-99 and so on |
|
- | 221 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
|
- | 222 | */ |
|
- | 223 | void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t num, uint8_t pad) { |
|
- | 224 | // if number is largar than 99[..]9 we must decrease it |
|
- | 225 | while (number >= (num * 10)) { |
|
- | 226 | number -= num * 10; |
|
- | 227 | } |
|
- | 228 | ||
- | 229 | ||
- | 230 | uint8_t started = 0; |
|
- | 231 | while (num > 0) { |
|
- | 232 | uint8_t b = number / num; |
|
- | 233 | if (b > 0 || started || num == 1) { |
|
- | 234 | if ((num / 10) == 0) { |
|
- | 235 | if (!started) write_ascii_char((x - 1)+(y * 30), '0'); |
|
- | 236 | write_char((x++)+(y * 30), 65); // decimal point |
|
- | 237 | } |
|
- | 238 | write_ascii_char((x++)+(y * 30), '0' + b); |
|
- | 239 | started = 1; |
|
- | 240 | } else { |
|
- | 241 | if (pad) write_ascii_char((x++)+(y * 30), '0'); |
|
- | 242 | else write_ascii_char((x++)+(y * 30), ' '); |
|
- | 243 | } |
|
- | 244 | number -= b * num; |
|
- | 245 | ||
- | 246 | num /= 10; |
|
- | 247 | } |
|
- | 248 | } |
|
- | 249 | ||
- | 250 | /** |
|
242 | * write a signed number at <x>/<y> to MAX7456 display memory |
251 | * Write only some digits of a signed <number> at <x>/<y> to MAX7456 display memory |
- | 252 | * as /10th of the value |
|
- | 253 | * <num> represents the largest multiple of 10 that will still be displayable as |
|
- | 254 | * the first digit, so num = 10 will be 0-99 and so on |
|
- | 255 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
|
243 | */ |
256 | */ |
244 | void write_number_s(uint8_t x, uint8_t y, int16_t w) { |
257 | void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t num, uint8_t pad) { |
245 | if (((uint16_t) w) > 32767) { |
258 | if (((uint16_t) number) > 32767) { |
246 | w = w - 65536; |
259 | number = number - 65536; |
- | 260 | num *= -1; |
|
247 | 261 | ||
- | 262 | // if number is smaller than -99[..]9 we must increase it |
|
248 | int16_t num = -10000; |
263 | while (number <= (num * 10)) { |
- | 264 | number -= num * 10; |
|
- | 265 | } |
|
- | 266 | ||
249 | uint8_t started = 0; |
267 | uint8_t started = 0; |
250 | 268 | ||
251 | while (num < 0) { |
269 | while (num < 0) { |
252 | uint8_t b = w / num; |
270 | uint8_t b = number / num; |
- | 271 | if (pad) write_ascii_char((x)+(y * 30), '0'); |
|
253 | if (b > 0 || started || num == 1) { |
272 | if (b > 0 || started || num == 1) { |
- | 273 | if ((num / 10) == 0) { |
|
- | 274 | if (!started) { |
|
- | 275 | write_ascii_char((x - 2)+(y * 30), '-'); |
|
254 | if (!started) write_char((x - 1)+(y * 30), 0x49); |
276 | write_ascii_char((x - 1)+(y * 30), '0'); |
- | 277 | } |
|
- | 278 | write_char((x++)+(y * 30), 65); // decimal point |
|
- | 279 | } else if (!started) { |
|
- | 280 | write_char((x - 1)+(y * 30), 0x49); // minus |
|
- | 281 | } |
|
255 | write_ascii_char((x++)+(y * 30), '0' + b); |
282 | write_ascii_char((x++)+(y * 30), '0' + b); |
256 | started = 1; |
283 | started = 1; |
257 | } else { |
284 | } else { |
258 | write_ascii_char((x++)+(y * 30), 0); |
285 | write_ascii_char((x++)+(y * 30), 0); |
259 | } |
286 | } |
260 | w -= b * num; |
287 | number -= b * num; |
261 | 288 | ||
262 | num /= 10; |
289 | num /= 10; |
263 | } |
290 | } |
264 | } else { |
291 | } else { |
265 | write_char((x)+(y * 30), 0); |
292 | write_char((x)+(y * 30), 0); |
266 | write_number_u(x, y, w); |
293 | write_ndigit_number_u_10th(x, y, number, num, pad); |
267 | } |
294 | } |
268 | } |
295 | } |
269 | 296 | ||
270 | /** |
297 | /** |
271 | * write <seconds> as human readable time at <x>/<y> to MAX7456 display mem |
298 | * write <seconds> as human readable time at <x>/<y> to MAX7456 display mem |
272 | */ |
299 | */ |
273 | void write_time(uint8_t x, uint8_t y, uint16_t seconds) { |
300 | void write_time(uint8_t x, uint8_t y, uint16_t seconds) { |
274 | uint16_t min = seconds / 60; |
301 | uint16_t min = seconds / 60; |
275 | seconds -= min * 60; |
302 | seconds -= min * 60; |
276 | write_3digit_number_u(x, y, min); |
303 | write_ndigit_number_u(x, y, min, 100, 0); |
277 | write_char_xy(x + 3, y, 68); |
304 | write_char_xy(x + 3, y, 68); |
278 | write_2digit_number_u(x + 4, y, seconds); |
305 | write_ndigit_number_u(x + 4, y, seconds, 10, 1); |
279 | } |
306 | } |
280 | 307 | ||
281 | /** |
308 | /** |
282 | * for testing write all chars to screen |
309 | * for testing write all chars to screen |
283 | */ |
310 | */ |
284 | void write_all_chars() { |
311 | void write_all_chars() { |
285 | uint16_t x = 3, y = 2, t = 0; |
312 | uint16_t x = 3, y = 2, t = 0; |
286 | while (t < 256) { |
313 | while (t < 256) { |
287 | write_char_xy(x++, y, t++); |
314 | write_char_xy(x++, y, t++); |
288 | if (x > 25) { |
315 | if (x > 25) { |
289 | y++; |
316 | y++; |
290 | x = 3; |
317 | x = 3; |
291 | } |
318 | } |
292 | } |
319 | } |
293 | } |
320 | } |
294 | 321 | ||
295 | /** |
322 | /** |
296 | * let the MAX7456 learn a new character at <number> |
323 | * let the MAX7456 learn a new character at <number> |
297 | * with <data>. |
324 | * with <data>. |
298 | */ |
325 | */ |
299 | void learn_char(uint8_t number, unsigned char* data) { |
326 | void learn_char(uint8_t number, unsigned char* data) { |
300 | // select character to write (CMAH) |
327 | // select character to write (CMAH) |
301 | spi_send_byte(0x09, number); |
328 | spi_send_byte(0x09, number); |
302 | 329 | ||
303 | for (uint8_t i = 0; i < 54; i++) { |
330 | for (uint8_t i = 0; i < 54; i++) { |
304 | // select 4pixel byte of char (CMAL) |
331 | // select 4pixel byte of char (CMAL) |
305 | spi_send_byte(0x0A, i); |
332 | spi_send_byte(0x0A, i); |
306 | 333 | ||
307 | // write 4pixel byte of char (CMDI) |
334 | // write 4pixel byte of char (CMDI) |
308 | spi_send_byte(0x0B, data[i]); |
335 | spi_send_byte(0x0B, data[i]); |
309 | } |
336 | } |
310 | 337 | ||
311 | // write to the NVM array from the shadow RAM (CMM) |
338 | // write to the NVM array from the shadow RAM (CMM) |
312 | spi_send_byte(0x08, 0b10100000); |
339 | spi_send_byte(0x08, 0b10100000); |
313 | 340 | ||
314 | // according to maxim writing to nvram takes about 12ms, lets wait longer |
341 | // according to maxim writing to nvram takes about 12ms, lets wait longer |
315 | _delay_ms(120); |
342 | _delay_ms(120); |
316 | } |
343 | } |
317 | 344 |