Subversion Repositories Projects

Rev

Rev 757 | Rev 783 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 757 Rev 761
1
/****************************************************************************
1
/****************************************************************************
2
 *   Copyright (C) 2009-2010 by Claas Anders "CaScAdE" Rathje               *
2
 *   Copyright (C) 2009-2010 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
 
-
 
23
#include <util/delay.h>
22
#include <util/delay.h>
24
#include <avr/pgmspace.h> 
23
#include <avr/pgmspace.h> 
25
#include <string.h>
24
#include <string.h>
26
#include <stdlib.h>
25
#include <stdlib.h>
27
#include "main.h"
26
#include "main.h"
28
#include "max7456_software_spi.h"
27
#include "max7456_software_spi.h"
29
 
28
 
30
 
29
 
31
char conv_array[7]; // general array for number -> char conversation
30
char conv_array[7]; // general array for number -> char conversation
32
 
31
 
33
/* ##########################################################################
32
/* ##########################################################################
34
 * MAX7456 SPI & Display stuff
33
 * MAX7456 SPI & Display stuff
35
 * ##########################################################################*/
34
 * ##########################################################################*/
36
 
35
 
37
/**
36
/**
38
 * Send a byte through SPI
37
 * Send a byte through SPI
39
 * inline because it increases the codesize currenlty 'only' by 110byte but saves
38
 * inline because it increases the codesize currenlty 'only' by 110byte but saves
40
 * the context-change on every char and attribute which is at least done twice
39
 * the context-change on every char and attribute which is at least done twice
41
 * (address and data byte), a significant speed-bost we do not want to miss :)
40
 * (address and data byte), a significant speed-bost we do not want to miss :)
42
 */
41
 */
43
inline void spi_send(uint8_t byte) {
42
inline void spi_send(uint8_t byte) {
44
    for (int8_t i = 7; i >= 0; i--) {
43
    for (int8_t i = 7; i >= 0; i--) {
45
        if (((byte >> i) & 1)) {
44
        if (((byte >> i) & 1)) {
46
            MAX_SDIN_HIGH
45
            MAX_SDIN_HIGH
47
        } else {
46
        } else {
48
            MAX_SDIN_LOW
47
            MAX_SDIN_LOW
49
        }
48
        }
50
        MAX_SCLK_HIGH
49
        MAX_SCLK_HIGH
51
        MAX_SCLK_LOW
50
        MAX_SCLK_LOW
52
    }
51
    }
53
}
52
}
54
 
53
 
55
/**
54
/**
56
 *  Send <byte> to <address> of MAX7456
55
 *  Send <byte> to <address> of MAX7456
57
 */
56
 */
58
void spi_send_byte(uint8_t address, uint8_t byte) {
57
void spi_send_byte(uint8_t address, uint8_t byte) {
59
    // start sending
58
    // start sending
60
    MAX_CS_LOW
59
    MAX_CS_LOW
61
 
60
 
62
    spi_send(address);
61
    spi_send(address);
63
    spi_send(byte);
62
    spi_send(byte);
64
 
63
 
65
    // end sending
64
    // end sending
66
    MAX_CS_HIGH
65
    MAX_CS_HIGH
67
}
66
}
68
 
-
 
69
 
67
 
70
/**
68
/**
71
 *  write a <character> to <address> of MAX7456 display memory
69
 *  write a <character> to <address> of MAX7456 display memory
72
 */
70
 */
73
void write_char(uint16_t address, char character) {
71
void write_char(uint16_t address, char character) {
74
    spi_send_byte(0x05, (address & 0xFF00) >> 8); // DMAH
72
    spi_send_byte(0x05, (address & 0xFF00) >> 8); // DMAH
75
    spi_send_byte(0x06, (address & 0x00FF)); // DMAL
73
    spi_send_byte(0x06, (address & 0x00FF)); // DMAL
76
    spi_send_byte(0x07, character); // DMDI
74
    spi_send_byte(0x07, character); // DMDI
77
}
75
}
78
 
-
 
79
 
76
 
80
/**
77
/**
81
 *  clear display memory
78
 *  clear display memory
82
 *  (also sets 8bit mode)
79
 *  (also sets 8bit mode)
83
 */
80
 */
84
void clear(void) {
81
void clear(void) {
85
    /*uint16_t memory_address = 0;
82
    /*uint16_t memory_address = 0;
86
    for (unsigned int a = 0; a < 480; a++) {
83
    for (unsigned int a = 0; a < 480; a++) {
87
        write_char(memory_address++, 0);
84
        write_char(memory_address++, 0);
88
    }*/
85
    }*/
89
        // clear all display-mem (DMM)
86
    // clear all display-mem (DMM)
90
    spi_send_byte(0x04, 0b01000100);
87
    spi_send_byte(0x04, 0b01000100);
91
 
88
 
92
    // clearing takes 12uS according to maxim so lets wait longer
89
    // clearing takes 12uS according to maxim so lets wait longer
93
    _delay_us(20);
90
    _delay_us(20);
94
}
91
}
95
 
92
 
96
 
93
 
97
#if (ALLCHARSDEBUG|(WRITECHARS != -1))
94
#if (ALLCHARSDEBUG|(WRITECHARS != -1))
-
 
95
 
98
/**
96
/**
99
 * for testing write all chars to screen
97
 * for testing write all chars to screen
100
 */
98
 */
101
void write_all_chars() {
99
void write_all_chars() {
102
    uint16_t x = 3, y = 2, t = 0;
100
    uint16_t x = 3, y = 2, t = 0;
103
    while (t < 256) {
101
    while (t < 256) {
104
        write_char(x++ + y*30, t++);
102
        write_char(x++ + y * 30, t++);
105
        if (x > 25) {
103
        if (x > 25) {
106
            y++;
104
            y++;
107
            x = 3;
105
            x = 3;
108
        }
106
        }
109
    }
107
    }
110
}
108
}
111
 
109
 
112
/**
110
/**
113
 * let the MAX7456 learn a new character at <number>
111
 * let the MAX7456 learn a new character at <number>
114
 * with <data>.
112
 * with <data>.
115
 */
113
 */
116
void learn_char(uint8_t number, unsigned char* data) {
114
void learn_char(uint8_t number, unsigned char* data) {
117
    // select character to write (CMAH)
115
    // select character to write (CMAH)
118
    spi_send_byte(0x09, number);
116
    spi_send_byte(0x09, number);
119
 
117
 
120
    for (uint8_t i = 0; i < 54; i++) {
118
    for (uint8_t i = 0; i < 54; i++) {
121
        // select 4pixel byte of char (CMAL)
119
        // select 4pixel byte of char (CMAL)
122
        spi_send_byte(0x0A, i);
120
        spi_send_byte(0x0A, i);
123
 
121
 
124
        // write 4pixel byte of char (CMDI)
122
        // write 4pixel byte of char (CMDI)
125
        spi_send_byte(0x0B, data[i]);
123
        spi_send_byte(0x0B, data[i]);
126
    }
124
    }
127
 
125
 
128
    // write to the NVM array from the shadow RAM (CMM)
126
    // write to the NVM array from the shadow RAM (CMM)
129
    spi_send_byte(0x08, 0b10100000);
127
    spi_send_byte(0x08, 0b10100000);
130
 
128
 
131
    // according to maxim writing to nvram takes about 12ms, lets wait longer
129
    // according to maxim writing to nvram takes about 12ms, lets wait longer
132
    _delay_ms(120);
130
    _delay_ms(120);
133
}
131
}
134
#endif
132
#endif
135
 
133
 
136
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
134
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
137
 
135
 
138
/**
136
/**
139
 *  write a character <attribute> to <address> of MAX7456 display memory
137
 *  write a character <attribute> to <address> of MAX7456 display memory
140
 */
138
 */
141
void write_char_att(uint16_t address, char attribute) {
139
void write_char_att(uint16_t address, char attribute) {
142
    // the only important part is that the DMAH[1] is set
140
    // the only important part is that the DMAH[1] is set
143
    // so we add 2 which binary is the 2nd lowest byte
141
    // so we add 2 which binary is the 2nd lowest byte
144
    spi_send_byte(0x05, ((address & 0xFF00) >> 8) | 2); // DMAH
142
    spi_send_byte(0x05, ((address & 0xFF00) >> 8) | 2); // DMAH
145
    spi_send_byte(0x06, (address & 0x00FF)); // DMAL
143
    spi_send_byte(0x06, (address & 0x00FF)); // DMAL
146
    spi_send_byte(0x07, attribute); // DMDI
144
    spi_send_byte(0x07, attribute); // DMDI
147
}
145
}
148
 
146
 
149
/**
147
/**
150
 *  write a <character> at <x>/<y> to MAX7456 display memory
148
 *  write a <character> at <x>/<y> to MAX7456 display memory
151
 */
149
 */
152
void write_char_xy(uint8_t x, uint8_t y, char character) {
150
void write_char_xy(uint8_t x, uint8_t y, char character) {
153
    uint16_t address = y * 30 + x;
151
    uint16_t address = y * 30 + x;
154
    write_char(address, character);
152
    write_char(address, character);
155
}
153
}
156
 
154
 
157
/**
155
/**
158
 *  write a  character <attribute> at <x>/<y> to MAX7456 display memory
156
 *  write a  character <attribute> at <x>/<y> to MAX7456 display memory
159
 */
157
 */
160
void write_char_att_xy(uint8_t x, uint8_t y, char attribute) {
158
void write_char_att_xy(uint8_t x, uint8_t y, char attribute) {
161
    uint16_t address = y * 30 + x;
159
    uint16_t address = y * 30 + x;
162
    write_char_att(address, attribute);
160
    write_char_att(address, attribute);
163
}
161
}
164
 
162
 
165
/**
163
/**
166
 *  write an ascii <character> to <address> of MAX7456 display memory
164
 *  write an ascii <character> to <address> of MAX7456 display memory
167
 */
165
 */
168
void write_ascii_char(uint16_t address, char c) {
166
void write_ascii_char(uint16_t address, char c) {
169
    if (c == 32) c = 0; // remap space
167
    if (c == 32) c = 0; // remap space
170
    else if (c > 48 && c <= 57) c -= 48; // remap numbers
168
    else if (c > 48 && c <= 57) c -= 48; // remap numbers
171
    else if (c == '0') c = 10; // remap zero
169
    else if (c == '0') c = 10; // remap zero
172
    else if (c >= 65 && c <= 90) c -= 54; // remap big letters
170
    else if (c >= 65 && c <= 90) c -= 54; // remap big letters
173
    else if (c >= 97 && c <= 122) c -= 60; // remap small letters
171
    else if (c >= 97 && c <= 122) c -= 60; // remap small letters
174
    else if (c == '(') c = 63; // remap
172
    else if (c == '(') c = 63; // remap
175
    else if (c == ')') c = 64; // remap
173
    else if (c == ')') c = 64; // remap
176
    else if (c == '.') c = 65; // remap
174
    else if (c == '.') c = 65; // remap
177
    else if (c == '-') c = 73; // remap minus
175
    else if (c == '-') c = 73; // remap minus
178
    else if (c == ';') c = 67; // remap
176
    else if (c == ';') c = 67; // remap
179
    else if (c == ':') c = 68; // remap
177
    else if (c == ':') c = 68; // remap
180
    else if (c == ',') c = 69; // remap
178
    else if (c == ',') c = 69; // remap
181
//    else if (c == '?') c = 66; // remap
179
        //    else if (c == '?') c = 66; // remap
182
//    else if (c == '\'') c = 70; // remap
180
        //    else if (c == '\'') c = 70; // remap
183
    else if (c == '/') c = 71; // remap
181
    else if (c == '/') c = 71; // remap
184
//    else if (c == '"') c = 72; // remap
182
    //    else if (c == '"') c = 72; // remap
185
//    else if (c == '<') c = 74; // remap
183
    //    else if (c == '<') c = 74; // remap
186
//    else if (c == '>') c = 75; // remap
184
    //    else if (c == '>') c = 75; // remap
187
//    else if (c == '@') c = 76; // remap
185
    //    else if (c == '@') c = 76; // remap
188
    write_char(address, c);
186
    write_char(address, c);
189
}
187
}
190
 
188
 
191
/**
189
/**
192
 *  write an ascii <string> at <x>/<y> to MAX7456 display memory
190
 *  write an ascii <string> at <x>/<y> to MAX7456 display memory
193
 */
191
 */
194
void write_ascii_string(uint8_t x, uint8_t y, char *string) {
192
void write_ascii_string(uint8_t x, uint8_t y, char *string) {
195
    while (*string) {
193
    while (*string) {
196
        write_ascii_char(((x++)+(y * 30)), *string);
194
        write_ascii_char(((x++)+(y * 30)), *string);
197
        string++;
195
        string++;
198
    }
196
    }
199
}
197
}
200
 
198
 
201
/**
199
/**
202
 *  write an ascii <string> from progmen at <x>/<y> to MAX7456 display memory
200
 *  write an ascii <string> from progmen at <x>/<y> to MAX7456 display memory
203
 */
201
 */
204
void write_ascii_string_pgm(uint8_t x, uint8_t y, const char *string) {
202
void write_ascii_string_pgm(uint8_t x, uint8_t y, const char *string) {
205
        while (pgm_read_byte(string) != 0x00)
203
    while (pgm_read_byte(string) != 0x00)
206
                write_ascii_char(((x++)+(y * 30)), pgm_read_byte(string++));
204
        write_ascii_char(((x++)+(y * 30)), pgm_read_byte(string++));
207
}
205
}
208
 
206
 
209
/**
207
/**
210
 *  write an <string> from progmen at <x>/<y> downwards to MAX7456 display memory
208
 *  write an <string> from progmen at <x>/<y> downwards to MAX7456 display memory
211
 */
209
 */
212
void write_string_pgm_down(uint8_t x, uint8_t y, const char *string, uint8_t length) {
210
void write_string_pgm_down(uint8_t x, uint8_t y, const char *string, uint8_t length) {
213
        while (length--)
211
    while (length--)
214
                write_char((x+(y++ * 30)), pgm_read_byte(string++));
212
        write_char((x + (y++ * 30)), pgm_read_byte(string++));
215
}
213
}
216
 
214
 
217
/**
215
/**
218
 * Write a unsigned <number> at <x>/<y> to MAX7456 display memory
216
 * Write a unsigned <number> at <x>/<y> to MAX7456 display memory
219
 * <length> represents the length to rightbound the number
217
 * <length> represents the length to rightbound the number
220
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
218
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
221
 */
219
 */
222
void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) {
220
void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) {
223
        itoa(number, conv_array, 10 );
221
    itoa(number, conv_array, 10);
224
        for (uint8_t i = 0; i < length - strlen(conv_array); i++) {
222
    for (uint8_t i = 0; i < length - strlen(conv_array); i++) {
225
                if (pad) write_char((x++)+(y * 30), 10);
223
        if (pad) write_char((x++)+(y * 30), 10);
226
                else write_ascii_char((x++)+(y * 30), 0);
224
        else write_ascii_char((x++)+(y * 30), 0);
227
        }
225
    }
228
        write_ascii_string(x,  y, conv_array);
226
    write_ascii_string(x, y, conv_array);
229
}
227
}
230
 
228
 
231
/**
229
/**
232
 * Write a signed <number> at <x>/<y> to MAX7456 display memory
230
 * Write a signed <number> at <x>/<y> to MAX7456 display memory
233
 * <length> represents the length to rightbound the number
231
 * <length> represents the length to rightbound the number
234
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
232
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
235
 */
233
 */
236
void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) {
234
void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) {
237
        itoa(number, conv_array, 10 );
235
    itoa(number, conv_array, 10);
238
        for (uint8_t i = 0; i < length - strlen(conv_array); i++) {
236
    for (uint8_t i = 0; i < length - strlen(conv_array); i++) {
239
                if (pad) write_char((x++)+(y * 30), 10);
237
        if (pad) write_char((x++)+(y * 30), 10);
240
                else write_ascii_char((x++)+(y * 30), 0);
238
        else write_ascii_char((x++)+(y * 30), 0);
241
        }
239
    }
242
        write_ascii_string(x,  y, conv_array);
240
    write_ascii_string(x, y, conv_array);
243
}
241
}
244
 
242
 
245
/**
243
/**
246
 * Write a unsigned <number> at <x>/<y> to MAX7456 display memory as /10th of value
244
 * Write a unsigned <number> at <x>/<y> to MAX7456 display memory as /10th of value
247
 * <length> represents the length to rightbound the number
245
 * <length> represents the length to rightbound the number
248
 * <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
249
 */
247
 */
250
void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) {
248
void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) {
251
        itoa(number, conv_array, 10 );
249
    itoa(number, conv_array, 10);
252
        uint8_t len = strlen(conv_array);
250
    uint8_t len = strlen(conv_array);
253
        for (uint8_t i = 0; i < length - len; i++) {
251
    for (uint8_t i = 0; i < length - len; i++) {
254
                if (pad) write_char((x++)+(y * 30), 10); //  zero
252
        if (pad) write_char((x++)+(y * 30), 10); //  zero
255
                else write_char((x++)+(y * 30), 0); // blank
253
        else write_char((x++)+(y * 30), 0); // blank
256
        }
254
    }
257
        char rest = conv_array[len - 1];
255
    char rest = conv_array[len - 1];
258
        conv_array[len - 1] = 0;
256
    conv_array[len - 1] = 0;
259
        if (len == 1) {
257
    if (len == 1) {
260
                write_char((x-1)+(y * 30), 10); // zero
258
        write_char((x - 1)+(y * 30), 10); // zero
261
        } else if (len == 2 && conv_array[0] == '-') {
259
    } else if (len == 2 && conv_array[0] == '-') {
262
                write_char((x-1)+(y * 30), 0x49); // minus
260
        write_char((x - 1)+(y * 30), 0x49); // minus
263
                write_char((x)+(y * 30), 10); // zero
261
        write_char((x)+(y * 30), 10); // zero
264
        } else {
262
    } else {
265
                write_ascii_string(x,  y, conv_array);
263
        write_ascii_string(x, y, conv_array);
266
        }
264
    }
267
        x += len - 1;
265
    x += len - 1;
268
        write_char((x++)+(y * 30), 65); // decimal point
266
    write_char((x++)+(y * 30), 65); // decimal point
269
        write_ascii_char((x++)+(y * 30), rest); // after dot
267
    write_ascii_char((x++)+(y * 30), rest); // after dot
270
}
268
}
271
 
269
 
272
/**
270
/**
273
 * Write a signed <number> at <x>/<y> to MAX7456 display memory as /10th of value
271
 * Write a signed <number> at <x>/<y> to MAX7456 display memory as /10th of value
274
 * <length> represents the length to rightbound the number
272
 * <length> represents the length to rightbound the number
275
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
273
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
276
 */
274
 */
277
void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) {
275
void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) {
278
        itoa(number, conv_array, 10 );
276
    itoa(number, conv_array, 10);
279
        uint8_t len = strlen(conv_array);
277
    uint8_t len = strlen(conv_array);
280
        for (uint8_t i = 0; i < length - len; i++) {
278
    for (uint8_t i = 0; i < length - len; i++) {
281
                if (pad) write_char((x++)+(y * 30), 10); //  zero
279
        if (pad) write_char((x++)+(y * 30), 10); //  zero
282
                else write_char((x++)+(y * 30), 0); // blank
280
        else write_char((x++)+(y * 30), 0); // blank
283
        }
281
    }
284
        char rest = conv_array[len - 1];
282
    char rest = conv_array[len - 1];
285
        conv_array[len - 1] = 0;
283
    conv_array[len - 1] = 0;
286
        if (len == 1) {
284
    if (len == 1) {
287
                write_char((x-1)+(y * 30), 10); // zero
285
        write_char((x - 1)+(y * 30), 10); // zero
288
        } else if (len == 2 && conv_array[0] == '-') {
286
    } else if (len == 2 && conv_array[0] == '-') {
289
                write_char((x-1)+(y * 30), 0x49); // minus
287
        write_char((x - 1)+(y * 30), 0x49); // minus
290
                write_char((x)+(y * 30), 10); // zero
288
        write_char((x)+(y * 30), 10); // zero
291
        } else {
289
    } else {
292
                write_ascii_string(x,  y, conv_array);
290
        write_ascii_string(x, y, conv_array);
293
        }
291
    }
294
        x += len - 1;
292
    x += len - 1;
295
        write_char((x++)+(y * 30), 65); // decimal point
293
    write_char((x++)+(y * 30), 65); // decimal point
296
        write_ascii_char((x++)+(y * 30), rest); // after dot
294
    write_ascii_char((x++)+(y * 30), rest); // after dot
297
}
295
}
298
 
296
 
299
/**
297
/**
300
 *  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
301
 */
299
 */
302
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) {
303
    uint16_t min = seconds / 60;
301
    uint16_t min = seconds / 60;
304
    seconds -= min * 60;
302
    seconds -= min * 60;
305
    write_ndigit_number_u(x, y, min, 3, 0);
303
    write_ndigit_number_u(x, y, min, 3, 0);
306
    write_char_xy(x + 3, y, 68);
304
    write_char_xy(x + 3, y, 68);
307
    write_ndigit_number_u(x + 4, y, seconds, 2, 1);
305
    write_ndigit_number_u(x + 4, y, seconds, 2, 1);
308
}
306
}
309
 
307
 
310
/**
308
/**
311
 * wirte a <position> at <x>/<y> assuming it is a gps position for long-/latitude
309
 * wirte a <position> at <x>/<y> assuming it is a gps position for long-/latitude
312
 */
310
 */
313
void write_gps_pos(uint8_t x, uint8_t y, int32_t position) {
311
void write_gps_pos(uint8_t x, uint8_t y, int32_t position) {
314
        if (position < 0) {
312
    if (position < 0) {
315
                position ^= ~0;
313
        position ^= ~0;
316
                position++;
314
        position++;
317
                write_char_xy(x++, y, 0x49); // minus
315
        write_char_xy(x++, y, 0x49); // minus
318
        } else {
316
    } else {
319
                write_char_xy(x++, y, 0); // clear ('+' would be nice, maybe later)
317
        write_char_xy(x++, y, 0); // clear ('+' would be nice, maybe later)
320
        }
318
    }
321
        write_ndigit_number_u(x, y, (uint16_t) (position / (int32_t) 10000000), 3, 1);
319
    write_ndigit_number_u(x, y, (uint16_t)(position / (int32_t)10000000), 3, 1);
322
        write_char_xy(x + 3, y, 65); // decimal point
320
    write_char_xy(x + 3, y, 65); // decimal point
323
        position = position - ((position / (int32_t) 10000000) * (int32_t) 10000000);
321
    position = position - ((position / (int32_t)10000000) * (int32_t)10000000);
324
        write_ndigit_number_u(x + 4, y, (uint16_t) (position / (int32_t) 1000), 4, 1);
322
    write_ndigit_number_u(x + 4, y, (uint16_t)(position / (int32_t)1000), 4, 1);
325
        position = position - ((uint16_t) (position / (int32_t) 1000) * (int32_t) 1000);
323
    position = position - ((uint16_t)(position / (int32_t)1000) * (int32_t)1000);
326
        write_ndigit_number_u(x + 8, y, (uint16_t) position, 3, 1);
324
    write_ndigit_number_u(x + 8, y, (uint16_t)position, 3, 1);
327
        write_char_xy(x + 11, y, 0xD0); // degree symbol
325
    write_char_xy(x + 11, y, 0xD0); // degree symbol
328
}
326
}
329
 
327
 
330
#endif
328
#endif
331
 
329