Rev 932 | Rev 1866 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 932 | Rev 1437 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /**************************************************************************** |
1 | /**************************************************************************** |
2 | * Copyright (C) 2009-2011 by Claas Anders "CaScAdE" Rathje * |
2 | * Copyright (C) 2009-2012 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 * |
Line 28... | Line 28... | ||
28 | #include "usart0.h" |
28 | #include "usart0.h" |
Line 29... | Line 29... | ||
29 | 29 | ||
Line 30... | Line 30... | ||
30 | 30 | ||
31 | char conv_array[7]; // general array for number -> char conversation |
31 | char conv_array[7]; // general array for number -> char conversation |
32 | 32 | ||
33 | int pow(int a, int b) { |
33 | int int_pow(int a, int b) { |
34 | if (b <= 0) return 1; |
34 | if (b <= 0) return 1; |
35 | int res = 1; |
35 | int res = 1; |
Line 84... | Line 84... | ||
84 | 84 | ||
85 | /** |
85 | /** |
86 | * write a <character> to <address> of MAX7456 display memory |
86 | * write a <character> to <address> of MAX7456 display memory |
87 | */ |
87 | */ |
88 | void write_char(uint16_t address, char character) { |
88 | void write_char(uint16_t address, char character) { |
89 | spi_send_byte(0x05, (address & 0xFF00) >> 8); // DMAH |
89 | spi_send_byte(MAX7456_DMAH, (address & 0xFF00) >> 8); |
90 | spi_send_byte(0x06, (address & 0x00FF)); // DMAL |
90 | spi_send_byte(MAX7456_DMAL, (address & 0x00FF)); |
91 | spi_send_byte(0x07, character); // DMDI |
91 | spi_send_byte(MAX7456_DMDI, character); |
Line 92... | Line 92... | ||
92 | } |
92 | } |
93 | 93 | ||
94 | /** |
94 | /** |
Line 99... | Line 99... | ||
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 | // clear all display-mem (DMM) |
103 | // clear all display-mem (DMM) |
104 | spi_send_byte(0x04, 0b01000100); |
104 | spi_send_byte(MAX7456_DMM, 0b01000100); |
Line 105... | Line 105... | ||
105 | 105 | ||
106 | // clearing takes 12uS according to maxim so lets wait longer |
106 | // clearing takes 20us according to maxim so lets wait longer |
107 | _delay_us(20); |
107 | _delay_us(21); |
Line 108... | Line 108... | ||
108 | } |
108 | } |
Line 127... | Line 127... | ||
127 | /** |
127 | /** |
128 | * let the MAX7456 learn a new character at <number> |
128 | * let the MAX7456 learn a new character at <number> |
129 | * with <data>. |
129 | * with <data>. |
130 | */ |
130 | */ |
131 | void learn_char(uint8_t number, unsigned char* data) { |
131 | void learn_char(uint8_t number, unsigned char* data) { |
132 | // select character to write (CMAH) |
132 | // select character to write |
133 | spi_send_byte(0x09, number); |
133 | spi_send_byte(MAX7456_CMAH, number); |
Line 134... | Line 134... | ||
134 | 134 | ||
135 | for (uint8_t i = 0; i < 54; i++) { |
135 | for (uint8_t i = 0; i < 54; i++) { |
136 | // select 4pixel byte of char (CMAL) |
136 | // select 4pixel byte of char |
Line 137... | Line 137... | ||
137 | spi_send_byte(0x0A, i); |
137 | spi_send_byte(MAX7456_CMAL, i); |
138 | 138 | ||
139 | // write 4pixel byte of char (CMDI) |
139 | // write 4pixel byte of char |
Line 140... | Line 140... | ||
140 | spi_send_byte(0x0B, data[i]); |
140 | spi_send_byte(MAX7456_CMDI, data[i]); |
141 | } |
141 | } |
Line 142... | Line 142... | ||
142 | 142 | ||
143 | // write to the NVM array from the shadow RAM (CMM) |
143 | // write to the NVM array from the shadow RAM |
144 | spi_send_byte(0x08, 0b10100000); |
144 | spi_send_byte(MAX7456_CMM, 0b10100000); |
145 | 145 | ||
Line 154... | Line 154... | ||
154 | * write a character <attribute> to <address> of MAX7456 display memory |
154 | * write a character <attribute> to <address> of MAX7456 display memory |
155 | */ |
155 | */ |
156 | void write_char_att(uint16_t address, char attribute) { |
156 | void write_char_att(uint16_t address, char attribute) { |
157 | // the only important part is that the DMAH[1] is set |
157 | // the only important part is that the DMAH[1] is set |
158 | // so we add 2 which binary is the 2nd lowest byte |
158 | // so we add 2 which binary is the 2nd lowest byte |
159 | spi_send_byte(0x05, ((address & 0xFF00) >> 8) | 2); // DMAH |
159 | spi_send_byte(MAX7456_DMAH, ((address & 0xFF00) >> 8) | 2); |
160 | spi_send_byte(0x06, (address & 0x00FF)); // DMAL |
160 | spi_send_byte(MAX7456_DMAL, (address & 0x00FF)); |
161 | spi_send_byte(0x07, attribute); // DMDI |
161 | spi_send_byte(MAX7456_DMDI, attribute); |
162 | } |
162 | } |
Line 163... | Line 163... | ||
163 | 163 | ||
164 | /** |
164 | /** |
165 | * write a <character> at <x>/<y> to MAX7456 display memory |
165 | * write a <character> at <x>/<y> to MAX7456 display memory |
Line 244... | Line 244... | ||
244 | * Write a unsigned <number> at <x>/<y> to MAX7456 display memory |
244 | * Write a unsigned <number> at <x>/<y> to MAX7456 display memory |
245 | * <length> represents the length to rightbound the number |
245 | * <length> represents the length to rightbound the number |
246 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
246 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
247 | */ |
247 | */ |
248 | void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) { |
248 | void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) { |
249 | if (number >= pow(10, length)) { |
249 | if (number >= int_pow(10, length)) { |
250 | number = pow(10, length) - 1; |
250 | number = int_pow(10, length) - 1; |
251 | } |
251 | } |
252 | itoa(number, conv_array, 10); |
252 | itoa(number, conv_array, 10); |
253 | for (uint8_t i = 0; i < length - strlen(conv_array); i++) { |
253 | for (uint8_t i = 0; i < length - strlen(conv_array); i++) { |
254 | if (pad) write_char((x++)+(y * 30), 10); |
254 | if (pad) write_char((x++)+(y * 30), 10); |
255 | else write_ascii_char((x++)+(y * 30), 0); |
255 | else write_ascii_char((x++)+(y * 30), 0); |
Line 261... | Line 261... | ||
261 | * Write a signed <number> at <x>/<y> to MAX7456 display memory |
261 | * Write a signed <number> at <x>/<y> to MAX7456 display memory |
262 | * <length> represents the length to rightbound the number |
262 | * <length> represents the length to rightbound the number |
263 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
263 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
264 | */ |
264 | */ |
265 | void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) { |
265 | void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) { |
266 | if (number <= -pow(10, length)) { |
266 | if (number <= -int_pow(10, length)) { |
267 | number = -pow(10, length) + 1; |
267 | number = -int_pow(10, length) + 1; |
268 | } else if (number >= pow(10, length)) { |
268 | } else if (number >= int_pow(10, length)) { |
269 | number = pow(10, length) - 1; |
269 | number = int_pow(10, length) - 1; |
270 | } |
270 | } |
Line 271... | Line 271... | ||
271 | 271 | ||
272 | itoa(number, conv_array, 10); |
272 | itoa(number, conv_array, 10); |
273 | if (strlen(conv_array) < length) { |
273 | if (strlen(conv_array) < length) { |
Line 283... | Line 283... | ||
283 | * Write a unsigned <number> at <x>/<y> to MAX7456 display memory as /10th of value |
283 | * Write a unsigned <number> at <x>/<y> to MAX7456 display memory as /10th of value |
284 | * <length> represents the length to rightbound the number |
284 | * <length> represents the length to rightbound the number |
285 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
285 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
286 | */ |
286 | */ |
287 | void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) { |
287 | void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) { |
288 | if (number >= pow(10, length)) { |
288 | if (number >= int_pow(10, length)) { |
289 | number = pow(10, length) - 1; |
289 | number = int_pow(10, length) - 1; |
290 | } |
290 | } |
291 | itoa(number, conv_array, 10); |
291 | itoa(number, conv_array, 10); |
292 | uint8_t len = strlen(conv_array); |
292 | uint8_t len = strlen(conv_array); |
293 | for (uint8_t i = 0; i < length - len; i++) { |
293 | for (uint8_t i = 0; i < length - len; i++) { |
294 | if (pad) write_char((x++)+(y * 30), 10); // zero |
294 | if (pad) write_char((x++)+(y * 30), 10); // zero |
Line 313... | Line 313... | ||
313 | * Write a signed <number> at <x>/<y> to MAX7456 display memory as /10th of value |
313 | * Write a signed <number> at <x>/<y> to MAX7456 display memory as /10th of value |
314 | * <length> represents the length to rightbound the number |
314 | * <length> represents the length to rightbound the number |
315 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
315 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
316 | */ |
316 | */ |
317 | void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) { |
317 | void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) { |
318 | if (number >= pow(10, length)) { |
318 | if (number >= int_pow(10, length)) { |
319 | number = pow(10, length) - 1; |
319 | number = int_pow(10, length) - 1; |
320 | } |
320 | } |
321 | itoa(number, conv_array, 10); |
321 | itoa(number, conv_array, 10); |
322 | uint8_t len = strlen(conv_array); |
322 | uint8_t len = strlen(conv_array); |
323 | for (uint8_t i = 0; i < length - len; i++) { |
323 | for (uint8_t i = 0; i < length - len; i++) { |
324 | if (pad) write_char((x++)+(y * 30), 10); // zero |
324 | if (pad) write_char((x++)+(y * 30), 10); // zero |