Subversion Repositories Projects

Rev

Rev 330 | Rev 335 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 330 Rev 331
Line 26... Line 26...
26
 ****************************************************************************/
26
 ****************************************************************************/
Line 27... Line 27...
27
 
27
 
28
#include <avr/io.h>
28
#include <avr/io.h>
29
#include <avr/interrupt.h>
29
#include <avr/interrupt.h>
-
 
30
#include <util/delay.h>
-
 
31
#include "max7456_software_spi.c"
Line 30... Line 32...
30
#include <util/delay.h>
32
#include "usart1.h"
31
 
33
 
32
/* TODO:
34
/* TODO:
33
 * - verifiy correctness of values
35
 * - verifiy correctness of values
Line 66... Line 68...
66
#define COSD_FLAG_NOOSD                  4
68
#define COSD_FLAG_NOOSD                  4
67
#define COSD_FLAG_NOOSD_BUT_WRN  8
69
#define COSD_FLAG_NOOSD_BUT_WRN  8
68
#define COSD_ICONS_WRITTEN              16
70
#define COSD_ICONS_WRITTEN              16
Line 69... Line 71...
69
 
71
 
70
/* ##########################################################################
-
 
71
 * Software SPI to communicate with MAX7456
-
 
72
 * ##########################################################################*/
-
 
73
#define MAX_CS_HIGH             PORTA |=  (1 << PA1);
-
 
74
#define MAX_CS_LOW              PORTA &= ~(1 << PA1);
-
 
75
#define MAX_SDIN_HIGH           PORTA |=  (1 << PA2);
-
 
76
#define MAX_SDIN_LOW            PORTA &= ~(1 << PA2);
-
 
77
#define MAX_SCLK_HIGH           PORTA |=  (1 << PA3);
-
 
78
#define MAX_SCLK_LOW            PORTA &= ~(1 << PA3);
-
 
79
#define MAX_RESET_HIGH          PORTA |=  (1 << PA5);
-
 
80
#define MAX_RESET_LOW           PORTA &= ~(1 << PA5);
-
 
81
 
-
 
82
/* ##########################################################################
72
/* ##########################################################################
83
 * LED controll
73
 * LED controll
84
 * ##########################################################################*/
74
 * ##########################################################################*/
85
#define LED1_ON                 PORTC |=  (1 << PC0);
75
#define LED1_ON                 PORTC |=  (1 << PC0);
86
#define LED1_OFF                PORTC &= ~(1 << PC0);
76
#define LED1_OFF                PORTC &= ~(1 << PC0);
Line 95... Line 85...
95
 * switch controll
85
 * switch controll
96
 * ##########################################################################*/
86
 * ##########################################################################*/
97
#define S1_PRESSED              !(PINC & (1<<PC5))
87
#define S1_PRESSED              !(PINC & (1<<PC5))
98
#define S2_PRESSED              !(PINC & (1<<PC4))
88
#define S2_PRESSED              !(PINC & (1<<PC4))
Line 99... Line -...
99
 
-
 
100
/* ##########################################################################
-
 
101
 * gain some fake arm compat :)
-
 
102
 * ##########################################################################*/
-
 
103
#define u8 uint8_t
-
 
104
#define s8 int8_t
-
 
105
#define u16 uint16_t
-
 
106
#define s16 int16_t
-
 
107
#define u32 uint32_t
-
 
108
#define s32 int32_t
-
 
109
 
89
 
110
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
-
 
111
/* ##########################################################################
-
 
112
 * MK data strucs & flags
-
 
113
 * ##########################################################################*/
-
 
114
#define NC_FLAG_FREE                    1
-
 
115
#define NC_FLAG_PH                      2
-
 
116
#define NC_FLAG_CH                      4
-
 
117
#define NC_FLAG_RANGE_LIMIT             8
-
 
118
#define NC_SERIAL_LINK_OK               16
-
 
119
#define NC_FLAG_TARGET_REACHED          32
-
 
120
 
-
 
121
#define FLAG_MOTOR_RUN  1
-
 
122
#define FLAG_FLY        2
-
 
123
#define FLAG_CALIBRATE  4
-
 
124
#define FLAG_START      8
-
 
125
 
-
 
126
/*
-
 
127
 * FC Debug Struct
-
 
128
 * portions taken and adapted from
-
 
129
 * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Ftags%2FV0.72p%2Fuart.h
-
 
130
 */
90
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
131
typedef struct {
-
 
132
    uint8_t Digital[2];
-
 
133
    uint16_t Analog[32]; // Debugvalues
-
 
134
} __attribute__((packed)) DebugOut_t;
-
 
135
 
-
 
136
/*
91
// data structs
137
 * NaviCtrl OSD Structs
-
 
138
 * portions taken and adapted from
-
 
139
 * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=NaviCtrl&path=%2Ftags%2FV0.14e%2Fuart1.h
-
 
140
 */
-
 
141
typedef struct {
-
 
142
    s32 Longitude; // in 1E-7 deg
-
 
143
    s32 Latitude; // in 1E-7 deg
-
 
144
    s32 Altitude; // in mm
-
 
145
    u8 Status; // validity of data
-
 
146
} __attribute__((packed)) GPS_Pos_t;
-
 
147
 
-
 
148
typedef struct {
-
 
149
    s16 Distance; // distance to target in cm
-
 
150
    s16 Bearing; // course to target in deg
-
 
151
} __attribute__((packed)) GPS_PosDev_t;
-
 
152
 
-
 
153
typedef struct {
-
 
154
    GPS_Pos_t CurrentPosition; // see ubx.h for details
-
 
155
    GPS_Pos_t TargetPosition;
-
 
156
    GPS_PosDev_t TargetPositionDeviation;
-
 
157
    GPS_Pos_t HomePosition;
-
 
158
    GPS_PosDev_t HomePositionDeviation;
-
 
159
    u8 WaypointIndex; // index of current waypoints running from 0 to WaypointNumber-1
-
 
160
    u8 WaypointNumber; // number of stored waypoints
-
 
161
    u8 SatsInUse; // no of satellites used for position solution
-
 
162
    s16 Altimeter; // hight according to air pressure
-
 
163
    s16 Variometer; // climb(+) and sink(-) rate
-
 
164
    u16 FlyingTime; // in seconds
-
 
165
    u8 UBat; // Battery Voltage in 0.1 Volts
-
 
166
    u16 GroundSpeed; // speed over ground in cm/s (2D)
-
 
167
    s16 Heading; // current flight direction in deg as angle to north
-
 
168
    s16 CompassHeading; // current compass value
-
 
169
    s8 AngleNick; // current Nick angle in 1°
-
 
170
    s8 AngleRoll; // current Rick angle in 1°
-
 
171
    u8 RC_Quality; // RC_Quality
-
 
172
    u8 MKFlags; // Flags from FC
-
 
173
    u8 NCFlags; // Flags from NC
-
 
174
    u8 Errorcode; // 0 --> okay
-
 
175
    u8 OperatingRadius; // current operation radius around the Home Position in m
-
 
176
    u8 Reserve[7]; // for future use
-
 
177
} __attribute__((packed)) NaviData_t;
-
 
Line 178... Line 92...
178
 
92
#include "mk-data-structs.h"
179
 
93
 
180
/* ##########################################################################
94
/* ##########################################################################
181
 * global definitions and global vars
-
 
182
 * ##########################################################################*/
-
 
183
#define baud 57600
-
 
184
 
-
 
185
#define RXD_BUFFER_LEN          150
-
 
186
#define TXD_BUFFER_LEN          150
95
 * global definitions and global vars
187
 
96
 * ##########################################################################*/
188
volatile uint8_t rxd_buffer_locked = 0;
97
volatile uint8_t rxd_buffer_locked = 0;
189
volatile uint8_t rxd_buffer[RXD_BUFFER_LEN];
98
volatile uint8_t rxd_buffer[RXD_BUFFER_LEN];
190
volatile uint8_t txd_buffer[TXD_BUFFER_LEN];
99
volatile uint8_t txd_buffer[TXD_BUFFER_LEN];
Line 203... Line 112...
203
 
112
 
204
// 16bit should be enough, normal LiPos don't last that long
113
// 16bit should be enough, normal LiPos don't last that long
205
volatile uint16_t uptime = 0;
114
volatile uint16_t uptime = 0;
Line -... Line 115...
-
 
115
volatile uint16_t timer = 0;
-
 
116
 
-
 
117
// remember last time data was received
206
volatile uint16_t timer = 0;
118
volatile uint8_t seconds_since_last_data = 0;
Line 207... Line 119...
207
 
119
 
208
#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))
120
#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))
209
 
121
 
Line 231... Line 143...
231
                if (S2_PRESSED) return 1;
143
                if (S2_PRESSED) return 1;
232
        }
144
        }
233
        return 0;
145
        return 0;
234
}
146
}
Line 235... Line -...
235
 
-
 
236
/* ##########################################################################
-
 
237
 * MAX7456 SPI & Display stuff
-
 
238
 * ##########################################################################*/
-
 
239
 
-
 
240
/**
-
 
241
 * Send a byte through SPI
-
 
242
 */
-
 
243
void spi_send(uint8_t byte) {
-
 
244
    for (int8_t i = 7; i >= 0; i--) {
-
 
245
        if (((byte >> i) & 1)) {
-
 
246
            MAX_SDIN_HIGH
-
 
247
        } else {
-
 
248
            MAX_SDIN_LOW
-
 
249
        }
-
 
250
        MAX_SCLK_HIGH
-
 
251
        MAX_SCLK_LOW
-
 
252
    }
-
 
253
}
-
 
254
 
-
 
255
/**
-
 
256
 *  Send <byte> to <address> of MAX7456
-
 
257
 */
-
 
258
void spi_send_byte(uint8_t address, uint8_t byte) {
-
 
259
    // start sending
-
 
260
    MAX_CS_LOW
-
 
261
 
-
 
262
    spi_send(address);
-
 
263
    spi_send(byte);
-
 
264
 
-
 
265
    // end sending
-
 
266
    MAX_CS_HIGH
-
 
267
}
-
 
268
 
-
 
269
/**
-
 
270
 *  write a <character> to <address> of MAX7456 display memory
-
 
271
 */
-
 
272
void write_char(uint16_t address, char character) {
-
 
273
    spi_send_byte(0x05, (address & 0xFF00) >> 8); // DMAH
-
 
274
    spi_send_byte(0x06, (address & 0x00FF)); // DMAL
-
 
275
    spi_send_byte(0x07, character); // DMDI
-
 
276
}
-
 
277
 
-
 
278
/**
-
 
279
 *  write a character <attribute> to <address> of MAX7456 display memory
-
 
280
 */
-
 
281
void write_char_att(uint16_t address, char attribute) {
-
 
282
    // the only important part is that the DMAH[1] is set
-
 
283
    // so we add 2 which binary is the 2nd lowest byte
-
 
284
    spi_send_byte(0x05, ((address & 0xFF00) >> 8) | 2); // DMAH
-
 
285
    spi_send_byte(0x06, (address & 0x00FF)); // DMAL
-
 
286
    spi_send_byte(0x07, attribute); // DMDI
-
 
287
}
-
 
288
 
-
 
289
/**
-
 
290
 *  write a <character> at <x>/<y> to MAX7456 display memory
-
 
291
 */
-
 
292
void write_char_xy(uint8_t x, uint8_t y, char character) {
-
 
293
    uint16_t address = y * 30 + x;
-
 
294
    write_char(address, character);
-
 
295
}
-
 
296
 
-
 
297
/**
-
 
298
 *  write a  character <attribute> at <x>/<y> to MAX7456 display memory
-
 
299
 */
-
 
300
void write_char_att_xy(uint8_t x, uint8_t y, char attribute) {
-
 
301
    uint16_t address = y * 30 + x;
-
 
302
    write_char_att(address, attribute);
-
 
303
}
-
 
304
 
-
 
305
/**
-
 
306
 *  clear display by writing blank characters all over it
-
 
307
 */
-
 
308
void clear(void) {
-
 
309
    uint16_t memory_address = 0;
-
 
310
    for (unsigned int a = 0; a < 480; a++) {
-
 
311
        write_char(memory_address++, 0);
-
 
312
    }
-
 
313
}
-
 
314
 
-
 
315
/**
-
 
316
 *  write an ascii <character> to <address> of MAX7456 display memory
-
 
317
 */
-
 
318
void write_ascii_char(uint16_t address, char c) {
-
 
319
    if (c == 32) c = 0; // remap space
-
 
320
    else if (c > 48 && c <= 57) c -= 48; // remap numbers
-
 
321
    else if (c == '0') c = 10; // remap zero
-
 
322
    else if (c >= 65 && c <= 90) c -= 54; // remap big letters
-
 
323
    else if (c >= 97 && c <= 122) c -= 60; // remap small letters
-
 
324
    else if (c == '(') c = 63; // remap
-
 
325
    else if (c == ')') c = 64; // remap
-
 
326
    else if (c == '.') c = 65; // remap
-
 
327
    else if (c == '?') c = 66; // remap
-
 
328
    else if (c == ';') c = 67; // remap
-
 
329
    else if (c == ':') c = 68; // remap
-
 
330
    else if (c == ',') c = 69; // remap
-
 
331
    else if (c == '\'') c = 70; // remap
-
 
332
    else if (c == '/') c = 71; // remap
-
 
333
    else if (c == '"') c = 72; // remap
-
 
334
    else if (c == '-') c = 73; // remap minus
-
 
335
    else if (c == '<') c = 74; // remap
-
 
336
    else if (c == '>') c = 75; // remap
-
 
337
    else if (c == '@') c = 76; // remap
-
 
338
    write_char(address, c);
-
 
339
}
-
 
340
 
-
 
341
/**
-
 
342
 *  write an ascii <string> at <x>/<y> to MAX7456 display memory
-
 
343
 */
-
 
344
void write_ascii_string(uint8_t x, uint8_t y, char *string) {
-
 
345
    while (*string) {
-
 
346
        write_ascii_char(((x++)+(y * 30)), *string);
-
 
347
        string++;
-
 
348
    }
-
 
349
}
-
 
350
 
-
 
351
/**
-
 
352
 *  Write only the last three digits of a <number> at <x>/<y> to MAX7456
-
 
353
 *  display memory. takes full 16bit numbers as well for stuff
-
 
354
 *  like compass only taking three characters (values <= 999)
-
 
355
 */
-
 
356
void write_3digit_number_u(uint8_t x, uint8_t y, uint16_t number) {
-
 
357
    uint16_t num = 100;
-
 
358
    uint8_t started = 0;
-
 
359
 
-
 
360
    while (num > 0) {
-
 
361
        uint8_t b = number / num;
-
 
362
        if (b > 0 || started || num == 1) {
-
 
363
            write_ascii_char((x++)+(y * 30), '0' + b);
-
 
364
            started = 1;
-
 
365
        } else {
-
 
366
            write_ascii_char((x++)+(y * 30), 0);
-
 
367
        }
-
 
368
        number -= b * num;
-
 
369
 
-
 
370
        num /= 10;
-
 
371
    }
-
 
372
}
-
 
373
 
-
 
374
/**
-
 
375
 *  Write only the last two digits of a number at <x>/<y> to MAX7456
-
 
376
 *  display memory. takes full 16bit numbers as well for stuff
-
 
377
 *  like seconds only taking two characters (values <= 99)
-
 
378
 *  Since this is used for seconds only and it looks better, there
-
 
379
 *  is a trading 0 attached
-
 
380
 */
-
 
381
void write_2digit_number_u(uint8_t x, uint8_t y, uint16_t number) {
-
 
382
    uint16_t num = 10;
-
 
383
    uint8_t started = 0;
-
 
384
 
-
 
385
    while (num > 0) {
-
 
386
        uint8_t b = number / num;
-
 
387
        if (b > 0 || started || num == 1) {
-
 
388
            write_ascii_char((x++)+(y * 30), '0' + b);
-
 
389
            started = 1;
-
 
390
        } else {
-
 
391
            write_ascii_char((x++)+(y * 30), '0');
-
 
392
        }
-
 
393
        number -= b * num;
-
 
394
 
-
 
395
        num /= 10;
-
 
396
    }
-
 
397
}
-
 
398
 
-
 
399
/**
-
 
400
 *  write a unsigned number as /10th at <x>/<y> to MAX7456 display memory
-
 
401
 */
-
 
402
void write_number_u_10th(uint8_t x, uint8_t y, uint16_t number) {
-
 
403
    uint16_t num = 10000;
-
 
404
    uint8_t started = 0;
-
 
405
 
-
 
406
    while (num > 0) {
-
 
407
        uint8_t b = number / num;
-
 
408
 
-
 
409
        if (b > 0 || started || num == 1) {
-
 
410
            if ((num / 10) == 0) write_char((x++)+(y * 30), 65);
-
 
411
            write_ascii_char((x++)+(y * 30), '0' + b);
-
 
412
            started = 1;
-
 
413
        } else {
-
 
414
            write_ascii_char((x++)+(y * 30), 0);
-
 
415
        }
-
 
416
        number -= b * num;
-
 
417
 
-
 
418
        num /= 10;
-
 
419
    }
-
 
420
}
-
 
421
 
-
 
422
/**
-
 
423
 *  write a unsigned number at <x>/<y> to MAX7456 display memory
-
 
424
 */
-
 
425
void write_number_u(uint8_t x, uint8_t y, uint16_t number) {
-
 
426
    uint16_t num = 10000;
-
 
427
    uint8_t started = 0;
-
 
428
 
-
 
429
    while (num > 0) {
-
 
430
        uint8_t b = number / num;
-
 
431
        if (b > 0 || started || num == 1) {
-
 
432
            write_ascii_char((x++)+(y * 30), '0' + b);
-
 
433
            started = 1;
-
 
434
        } else {
-
 
435
            write_ascii_char((x++)+(y * 30), 0);
-
 
436
        }
-
 
437
        number -= b * num;
-
 
438
 
-
 
439
        num /= 10;
-
 
440
    }
-
 
441
}
-
 
442
 
-
 
443
/**
-
 
444
 *  write a signed number at <x>/<y> to MAX7456 display memory
-
 
445
 */
-
 
446
void write_number_s(uint8_t x, uint8_t y, int16_t w) {
-
 
447
    if (((uint16_t) w) > 32767) {
-
 
448
        w = w - 65536;
-
 
449
 
-
 
450
        int16_t num = -10000;
-
 
451
        uint8_t started = 0;
-
 
452
 
-
 
453
        while (num < 0) {
-
 
454
            uint8_t b = w / num;
-
 
455
            if (b > 0 || started || num == 1) {
-
 
456
                if (!started) write_char((x - 1)+(y * 30), 0x49);
-
 
457
                write_ascii_char((x++)+(y * 30), '0' + b);
-
 
458
                started = 1;
-
 
459
            } else {
-
 
460
                write_ascii_char((x++)+(y * 30), 0);
-
 
461
            }
-
 
462
            w -= b * num;
-
 
463
 
-
 
464
            num /= 10;
-
 
465
        }
-
 
466
    } else {
-
 
467
        write_char((x)+(y * 30), 0);
-
 
468
        write_number_u(x, y, w);
-
 
469
    }
-
 
470
}
-
 
471
 
-
 
472
/**
-
 
473
 *  write <seconds> as human readable time at <x>/<y> to MAX7456 display mem
-
 
474
 */
-
 
475
void write_time(uint8_t x, uint8_t y, uint16_t seconds) {
-
 
476
    uint16_t min = seconds / 60;
-
 
477
    seconds -= min * 60;
-
 
478
    write_3digit_number_u(x, y, min);
-
 
479
    write_char_xy(x + 3, y, 68);
-
 
480
    write_2digit_number_u(x + 4, y, seconds);
-
 
481
}
-
 
482
 
-
 
483
/**
-
 
484
 * for testing write all chars to screen
-
 
485
 */
-
 
486
void write_all_chars() {
-
 
487
    uint16_t x = 3, y = 2, t = 0;
-
 
488
    while (t < 256) {
-
 
489
        write_char_xy(x++, y, t++);
-
 
490
        if (x > 25) {
-
 
491
            y++;
-
 
492
            x = 3;
-
 
493
        }
-
 
494
    }
-
 
Line 495... Line 147...
495
}
147
 
496
 
-
 
497
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
-
 
498
/* ##########################################################################
-
 
499
 * USART stuff
-
 
500
 * ##########################################################################*/
-
 
501
 
-
 
502
/**
-
 
503
 * init usart1
-
 
504
 */
-
 
505
void usart1_init() {
-
 
506
    UBRR1H = ((F_CPU / (16UL * baud)) - 1) >> 8;
-
 
507
    UBRR1L = (F_CPU / (16UL * baud)) - 1;
-
 
508
 
-
 
509
    // Enable receiver and transmitter; enable RX interrupt
-
 
510
    UCSR1B = (1 << RXEN1) | (1 << TXEN1) | (1 << RXCIE1);
-
 
511
 
-
 
512
    //asynchronous 8N1
-
 
513
    UCSR1C = (1 << URSEL1) | (3 << UCSZ10);
-
 
514
}
-
 
515
 
-
 
516
/**
-
 
517
 * send a single <character> through usart1
-
 
518
 */
-
 
519
void usart1_putc(unsigned char character) {
-
 
520
    // wait until UDR ready
-
 
521
    while (!(UCSR1A & (1 << UDRE1)));
-
 
522
    UDR1 = character;
-
 
523
}
-
 
524
 
-
 
525
/**
-
 
526
 * send a <string> throught usart1
-
 
527
 */
-
 
528
void usart1_puts(char *s) {
-
 
529
    while (*s) {
-
 
530
        usart1_putc(*s);
-
 
531
        s++;
-
 
532
    }
-
 
533
}
-
 
534
 
-
 
535
/**
-
 
536
 * receive data through usart1
-
 
537
 * portions taken and adapted from
-
 
538
 * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Fbranches%2FV0.72p+Code+Redesign+killagreg%2Fuart0.c
-
 
539
 */
-
 
540
ISR(SIG_USART1_RECV) {
-
 
541
    if (rxd_buffer_locked) return; // if rxd buffer is locked immediately return
-
 
542
    LED1_ON
-
 
543
            static uint16_t crc;
-
 
544
    static uint8_t ptr_rxd_buffer = 0;
-
 
545
    uint8_t crc1, crc2;
-
 
546
    uint8_t c;
-
 
547
 
-
 
548
    c = UDR1; // catch the received byte
-
 
549
 
-
 
550
    // the rxd buffer is unlocked
-
 
551
    if ((ptr_rxd_buffer == 0) && (c == '#')) // if rxd buffer is empty and syncronisation character is received
-
 
552
    {
-
 
553
                /*
-
 
554
                // skip other datasets
-
 
555
        if (ptr_rxd_buffer == 2 && rxd_buffer[ptr_rxd_buffer] != 'O') {
-
 
556
                        ptr_rxd_buffer = 0; // reset rxd buffer
-
 
557
                rxd_buffer_locked = 0; // unlock rxd buffer
-
 
558
                }*/
-
 
559
                rxd_buffer[ptr_rxd_buffer++] = c; // copy 1st byte to buffer
-
 
560
        crc = c; // init crc
-
 
561
    } else if (ptr_rxd_buffer < RXD_BUFFER_LEN) // collect incomming bytes
-
 
562
    {
-
 
563
        if (c != '\r') // no termination character
-
 
564
        {
-
 
565
            rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer
-
 
566
            crc += c; // update crc
-
 
567
        } else // termination character was received
-
 
568
        {
-
 
569
            // the last 2 bytes are no subject for checksum calculation
-
 
570
            // they are the checksum itself
-
 
571
            crc -= rxd_buffer[ptr_rxd_buffer - 2];
-
 
572
            crc -= rxd_buffer[ptr_rxd_buffer - 1];
-
 
573
            // calculate checksum from transmitted data
-
 
574
            crc %= 4096;
-
 
575
            crc1 = '=' + crc / 64;
-
 
576
            crc2 = '=' + crc % 64;
-
 
577
            // compare checksum to transmitted checksum bytes
-
 
578
            if ((crc1 == rxd_buffer[ptr_rxd_buffer - 2]) && (crc2 == rxd_buffer[ptr_rxd_buffer - 1])) { // checksum valid
-
 
579
                rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character
-
 
580
                ReceivedBytes = ptr_rxd_buffer + 1; // store number of received bytes
-
 
581
                rxd_buffer_locked = 1; // lock the rxd buffer
-
 
582
            } else { // checksum invalid
-
 
583
                rxd_buffer_locked = 0; // unlock rxd buffer
-
 
584
            }
-
 
585
            ptr_rxd_buffer = 0; // reset rxd buffer pointer
-
 
586
        }
-
 
587
    } else // rxd buffer overrun
-
 
588
    {
-
 
589
        ptr_rxd_buffer = 0; // reset rxd buffer
-
 
590
        rxd_buffer_locked = 0; // unlock rxd buffer
-
 
591
    }
-
 
Line 592... Line 148...
592
    LED1_OFF
148
 
593
}
149
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
594
 
-
 
595
/**
-
 
596
 * Decode the recevied Buffer
150
 
597
 * portions taken and adapted from
-
 
598
 * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Ftags%2FV0.72p%2Fuart.c
-
 
599
 */
-
 
600
void Decode64(void) {
-
 
601
    uint8_t a, b, c, d;
-
 
602
    uint8_t x, y, z;
-
 
603
    uint8_t ptrIn = 3;
-
 
604
    uint8_t ptrOut = 3;
-
 
605
    uint8_t len = ReceivedBytes - 6;
-
 
606
 
-
 
607
    while (len) {
-
 
608
        a = rxd_buffer[ptrIn++] - '=';
-
 
609
        b = rxd_buffer[ptrIn++] - '=';
-
 
610
        c = rxd_buffer[ptrIn++] - '=';
-
 
611
        d = rxd_buffer[ptrIn++] - '=';
-
 
612
 
-
 
613
        x = (a << 2) | (b >> 4);
-
 
614
        y = ((b & 0x0f) << 4) | (c >> 2);
-
 
615
        z = ((c & 0x03) << 6) | d;
151
/**
616
 
-
 
617
        if (len--) rxd_buffer[ptrOut++] = x;
-
 
618
        else break;
-
 
619
        if (len--) rxd_buffer[ptrOut++] = y;
-
 
620
        else break;
-
 
621
        if (len--) rxd_buffer[ptrOut++] = z;
-
 
622
        else break;
-
 
623
    }
-
 
Line 624... Line -...
624
    pRxData = &rxd_buffer[3];
-
 
625
    RxDataLen = ptrOut - 3;
-
 
626
}
-
 
627
 
-
 
628
/**
-
 
629
 * request Data through USART in special MK format by adding checksum and
-
 
630
 * encode data in modified Base64
-
 
631
 * portions taken and adapted from
-
 
632
 * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Ftags%2FV0.72p%2Fuart.c
-
 
633
 */
-
 
634
void sendMKData(unsigned char cmd, unsigned char addr, unsigned char *snd, unsigned char len) {
-
 
635
    unsigned int pt = 0;
-
 
636
    unsigned char a, b, c;
-
 
637
    unsigned char ptr = 0;
-
 
638
 
-
 
639
    txd_buffer[pt++] = '#'; // Start-Byte
-
 
640
    txd_buffer[pt++] = 'a' + addr; // Adress
-
 
641
    txd_buffer[pt++] = cmd; // Command
-
 
642
    while (len) {
-
 
643
        if (len) {
-
 
644
            a = snd[ptr++];
-
 
645
            len--;
-
 
646
        } else a = 0;
-
 
647
        if (len) {
-
 
648
            b = snd[ptr++];
-
 
649
            len--;
-
 
650
        } else b = 0;
-
 
651
        if (len) {
-
 
652
            c = snd[ptr++];
-
 
653
            len--;
-
 
654
        } else c = 0;
-
 
655
        txd_buffer[pt++] = '=' + (a >> 2);
-
 
656
        txd_buffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
-
 
657
        txd_buffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
-
 
658
        txd_buffer[pt++] = '=' + (c & 0x3f);
-
 
659
    }
-
 
660
 
-
 
661
    // add crc
-
 
662
    unsigned int tmpCRC = 0, i;
-
 
663
    for (i = 0; i < pt; i++) {
-
 
664
        tmpCRC += txd_buffer[i];
-
 
665
    }
-
 
666
    tmpCRC %= 4096;
-
 
667
    txd_buffer[i++] = '=' + tmpCRC / 64;
-
 
668
    txd_buffer[i++] = '=' + tmpCRC % 64;
-
 
Line 669... Line 152...
669
    txd_buffer[i++] = '\r';
152
 * serial support
670
 
153
 */
671
    usart1_puts((char*) txd_buffer);
154
#include "usart1.c"
Line 672... Line 155...
672
}
155
 
673
 
156
 
674
/* ##########################################################################
157
/* ##########################################################################
675
 * timer stuff
158
 * timer stuff
676
 * ##########################################################################*/
159
 * ##########################################################################*/
677
 
160
 
678
/*
161
/**
679
 * timer kicks in every 1000uS
162
 * timer kicks in every 1000uS ^= 1ms
-
 
163
 */
680
 */
164
ISR(TIMER0_OVF_vect) {
681
ISR(TIMER0_OVF_vect) {
165
    OCR0 = 6; // preload
Line 682... Line 166...
682
    OCR0 = 6; // preload
166
    if (!timer--) {
683
    if (!timer--) {
167
        uptime++;
Line 921... Line 405...
921
    LED4_ON
405
    LED4_ON
922
    _delay_ms(2000);
406
    _delay_ms(2000);
Line 923... Line 407...
923
 
407
 
Line 924... Line -...
924
    LED4_OFF
-
 
925
 
-
 
926
    /* ##########################################################################
-
 
927
     * Pushing NEW chars to the MAX7456
-
 
928
     * ##########################################################################*/
-
 
929
#if (WRITECHARS != -1)
-
 
930
        void learn_char(uint8_t number, unsigned char* data) {
-
 
931
        // select character to write (CMAH)
-
 
932
        spi_send_byte(0x09, number);
-
 
933
 
-
 
934
        for (uint8_t i = 0; i < 54; i++) {
-
 
935
            // select 4pixel byte of char (CMAL)
-
 
936
            spi_send_byte(0x0A, i);
-
 
937
 
-
 
938
            // write 4pixel byte of char (CMDI)
-
 
939
            spi_send_byte(0x0B, data[i]);
-
 
940
        }
-
 
941
 
-
 
Line 942... Line 408...
942
        // write to the NVM array from the shadow RAM (CMM)
408
    LED4_OFF
943
        spi_send_byte(0x08, 0b10100000);
409
 
944
 
-
 
945
        // according to maxim writing to nvram takes about 12ms, lets wait longer
-
 
946
        _delay_ms(120);
410
 
947
    }
411
     //Pushing NEW chars to the MAX7456
Line 948... Line -...
948
 
-
 
949
    // DISABLE display (VM0)
412
#if (WRITECHARS != -1)
950
    spi_send_byte(0x00, 0b00000000);
-
 
951
 
-
 
952
    /**
-
 
953
     * easy char creation:
-
 
954
     * http://cascade.dyndns.org/~cascade/scripts/max7456/
-
 
955
     */
-
 
956
        // flashing more than 8 chars per time is not proven to be safe
-
 
957
        // so take care
-
 
958
#if WRITECHARS == 200
-
 
959
        // GPS
-
 
960
    unsigned char cc8[54] = {0x55, 0x50, 0x55, 0x55, 0x4a, 0x15, 0x55, 0x2a,
-
 
961
        0x85, 0x55, 0x2a, 0xa1, 0x55, 0x4a, 0xa8, 0x55,
-
 
962
        0x52, 0xa8, 0x55, 0x54, 0xaa, 0x55, 0x55, 0x09,
-
 
963
        0x55, 0x55, 0x52, 0x55, 0x55, 0x1a, 0x55, 0x51,
-
 
964
        0x96, 0x55, 0x18, 0x85, 0x54, 0x88, 0x28, 0x54,
-
 
965
        0x82, 0x05, 0x55, 0x20, 0xa1, 0x55, 0x48, 0x15,
-
 
966
        0x55, 0x52, 0x85, 0x55, 0x54, 0x15};
-
 
967
 
-
 
968
    unsigned char cc9[54] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
969
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x45,
-
 
970
        0x55, 0x55, 0x21, 0x55, 0x55, 0xa8, 0x55, 0x55,
-
 
971
        0xa1, 0x55, 0x55, 0x98, 0x15, 0x55, 0x2a, 0x85,
-
 
972
        0x55, 0x4a, 0xa1, 0x55, 0x4a, 0xa8, 0x55, 0x52,
-
 
973
        0xaa, 0x15, 0x54, 0xaa, 0x15, 0x55, 0x28, 0x55,
-
 
974
        0x55, 0x41, 0x55, 0x55, 0x55, 0x55};
-
 
975
 
-
 
976
    // RC
-
 
977
    unsigned char cca[54] = {0x54, 0xaa, 0x85, 0x52, 0x00, 0x21, 0x48, 0x2a,
-
 
978
        0x08, 0x60, 0x80, 0x82, 0x62, 0x08, 0x22, 0x62,
-
 
979
        0x2a, 0x22, 0x62, 0x08, 0x22, 0x60, 0x88, 0x82,
-
 
980
        0x48, 0x08, 0x08, 0x52, 0x08, 0x21, 0x54, 0x48,
-
 
981
        0x45, 0x55, 0x48, 0x55, 0x55, 0x48, 0x55, 0x55,
-
 
982
        0x48, 0x55, 0x55, 0x48, 0x55, 0x55, 0x48, 0x55,
-
 
983
        0x55, 0x2a, 0x15, 0x54, 0xaa, 0x85};
-
 
984
 
-
 
985
    // km/h
-
 
986
    unsigned char ccb[54] = {0x55, 0x55, 0x55, 0x01, 0x55, 0x55, 0x21, 0x55,
-
 
987
        0x55, 0x20, 0x15, 0x55, 0x22, 0x15, 0x55, 0x28,
-
 
988
        0x15, 0x55, 0x22, 0x15, 0x55, 0x00, 0x00, 0x15,
-
 
989
        0x52, 0xaa, 0x15, 0x52, 0x22, 0x15, 0x52, 0x22,
-
 
990
        0x15, 0x50, 0x00, 0x05, 0x55, 0x54, 0x85, 0x55,
-
 
991
        0x54, 0x80, 0x55, 0x54, 0xa8, 0x55, 0x54, 0x88,
-
 
992
        0x55, 0x54, 0x88, 0x55, 0x54, 0x00};
-
 
993
 
-
 
994
 
-
 
995
    // small meters m
-
 
996
    unsigned char ccc[54] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
997
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
998
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
999
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1000
        0x55, 0x55, 0x55, 0x55, 0x00, 0x00, 0x15, 0x22,
-
 
1001
        0x8a, 0x15, 0x28, 0xa2, 0x15, 0x20, 0x82, 0x15,
-
 
1002
        0x20, 0x82, 0x15, 0x00, 0x00, 0x15};
-
 
1003
 
-
 
1004
    // vario down
-
 
1005
    unsigned char ccd[54] = {0x55, 0x00, 0x55, 0x55, 0x28, 0x55, 0x55, 0x28,
-
 
1006
        0x55, 0x55, 0x28, 0x55, 0x55, 0x28, 0x55, 0x55,
-
 
1007
        0x28, 0x55, 0x55, 0x28, 0x55, 0x55, 0x28, 0x55,
-
 
1008
        0x55, 0x28, 0x55, 0x55, 0x28, 0x55, 0x55, 0x28,
-
 
1009
        0x55, 0x00, 0x28, 0x00, 0x2a, 0xaa, 0xa8, 0x0a,
-
 
1010
        0xaa, 0xa0, 0x42, 0xaa, 0x81, 0x50, 0xaa, 0x05,
-
 
1011
        0x54, 0x28, 0x15, 0x55, 0x00, 0x55};
-
 
1012
 
-
 
1013
    // vario hold
-
 
1014
    unsigned char cce[54] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1015
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1016
        0x55, 0x55, 0x55, 0x55, 0x55, 0x00, 0x00, 0x00,
-
 
1017
        0x2a, 0xaa, 0xa8, 0x2a, 0xaa, 0xa8, 0x00, 0x00,
-
 
1018
        0x00, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1019
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1020
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
 
1021
 
-
 
1022
    // vario up
-
 
1023
    unsigned char ccf[54] = {0x55, 0x00, 0x55, 0x54, 0x28, 0x15, 0x50, 0xaa,
-
 
1024
        0x05, 0x42, 0xaa, 0x81, 0x0a, 0xaa, 0xa0, 0x2a,
-
 
1025
        0xaa, 0xa8, 0x00, 0x28, 0x00, 0x55, 0x28, 0x55,
-
 
1026
        0x55, 0x28, 0x55, 0x55, 0x28, 0x55, 0x55, 0x28,
-
 
1027
        0x55, 0x55, 0x28, 0x55, 0x55, 0x28, 0x55, 0x55,
-
 
1028
        0x28, 0x55, 0x55, 0x28, 0x55, 0x55, 0x28, 0x55,
-
 
1029
        0x55, 0x28, 0x55, 0x55, 0x00, 0x55};
-
 
1030
 
-
 
1031
    learn_char(200, cc8);
-
 
1032
    learn_char(201, cc9);
-
 
1033
    learn_char(202, cca);
-
 
1034
    learn_char(203, ccb);
-
 
1035
    learn_char(204, ccc);
413
        // DISABLE display (VM0)
1036
    learn_char(205, ccd);
-
 
1037
    learn_char(206, cce);
-
 
1038
    learn_char(207, ccf);
-
 
1039
#endif
-
 
1040
#if WRITECHARS == 208
-
 
1041
   // degree symbol
-
 
1042
    unsigned char cd0[54] = {0x55, 0x55, 0x55, 0x54, 0x01, 0x55, 0x52, 0xa8,
-
 
1043
        0x55, 0x48, 0x02, 0x15, 0x48, 0x52, 0x15, 0x48,
-
 
1044
        0x52, 0x15, 0x48, 0x02, 0x15, 0x52, 0xa8, 0x55,
-
 
1045
        0x54, 0x01, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1046
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1047
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1048
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
 
1049
 
-
 
1050
    // clock on symbol
-
 
1051
    unsigned char cd1[54] = {0x54, 0x14, 0x51, 0x52, 0x82, 0x08, 0x48, 0x22,
-
 
1052
        0x88, 0x48, 0x22, 0x28, 0x48, 0x22, 0x28, 0x52,
-
 
1053
        0x82, 0x08, 0x54, 0x14, 0x51, 0x55, 0x40, 0x55,
-
 
1054
        0x55, 0x2a, 0x15, 0x54, 0x88, 0x85, 0x52, 0x08,
-
 
1055
        0x21, 0x48, 0x48, 0x08, 0x48, 0x4a, 0x88, 0x48,
-
 
1056
        0x50, 0x08, 0x52, 0x15, 0x21, 0x54, 0x80, 0x85,
-
 
1057
        0x55, 0x2a, 0x15, 0x55, 0x40, 0x55};
-
 
1058
 
-
 
1059
    // clock fly symbol
-
 
1060
    unsigned char cd2[54] = {0x40, 0x45, 0x11, 0x2a, 0x20, 0x88, 0x20, 0x20,
-
 
1061
        0x88, 0x28, 0x21, 0x21, 0x21, 0x20, 0x21, 0x21,
-
 
1062
        0x2a, 0x21, 0x45, 0x40, 0x45, 0x55, 0x40, 0x55,
-
 
1063
        0x55, 0x2a, 0x15, 0x54, 0x88, 0x85, 0x52, 0x08,
-
 
1064
        0x21, 0x48, 0x48, 0x08, 0x48, 0x4a, 0x88, 0x48,
-
 
1065
        0x50, 0x08, 0x52, 0x15, 0x21, 0x54, 0x80, 0x85,
-
 
1066
        0x55, 0x2a, 0x15, 0x55, 0x40, 0x55};
-
 
1067
 
-
 
1068
    // compass north
-
 
1069
    unsigned char cd3[54] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1070
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x54,
-
 
1071
        0x54, 0x55, 0x52, 0x12, 0x15, 0x52, 0x82, 0x15,
-
 
1072
        0x02, 0x82, 0x00, 0xa2, 0x22, 0x2a, 0x02, 0x0a,
-
 
1073
        0x00, 0x52, 0x0a, 0x15, 0x52, 0x12, 0x15, 0x54,
-
 
1074
        0x54, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1075
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
 
1076
 
-
 
1077
    // compass south
-
 
1078
    unsigned char cd4[54] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1079
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1080
        0x01, 0x55, 0x54, 0xa8, 0x55, 0x52, 0x02, 0x15,
-
 
1081
        0x04, 0x84, 0x40, 0xa1, 0x21, 0x2a, 0x04, 0x48,
-
 
1082
        0x40, 0x52, 0x02, 0x15, 0x54, 0xa8, 0x55, 0x55,
-
 
1083
        0x01, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1084
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
 
1085
 
-
 
1086
    // compass east
-
 
1087
    unsigned char cd5[54] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1088
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x54,
-
 
1089
        0x00, 0x55, 0x52, 0xaa, 0x15, 0x52, 0x00, 0x55,
-
 
1090
        0x02, 0x05, 0x40, 0xa2, 0xa1, 0x2a, 0x02, 0x05,
-
 
1091
        0x40, 0x52, 0x00, 0x55, 0x52, 0xaa, 0x15, 0x54,
-
 
1092
        0x00, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1093
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
 
1094
 
-
 
1095
    // compass west
-
 
1096
    unsigned char cd6[54] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1097
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x54,
-
 
1098
        0x54, 0x55, 0x52, 0x12, 0x15, 0x52, 0x12, 0x15,
-
 
1099
        0x02, 0x02, 0x00, 0xa2, 0x22, 0x2a, 0x02, 0x8a,
-
 
1100
        0x00, 0x52, 0x8a, 0x15, 0x52, 0x12, 0x15, 0x54,
-
 
1101
        0x54, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1102
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
 
1103
 
-
 
1104
    // compass between
-
 
1105
    unsigned char cd7[54] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1106
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1107
        0x55, 0x55, 0x55, 0x45, 0x55, 0x55, 0x21, 0x55,
-
 
1108
        0x01, 0x21, 0x00, 0xa8, 0x20, 0xaa, 0x01, 0x21,
-
 
1109
        0x00, 0x55, 0x21, 0x55, 0x55, 0x45, 0x55, 0x55,
-
 
1110
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1111
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
 
1112
 
-
 
1113
    learn_char(208, cd0);
-
 
1114
    learn_char(209, cd1);
-
 
1115
    learn_char(210, cd2);
-
 
1116
    learn_char(211, cd3);
-
 
1117
    learn_char(212, cd4);
-
 
1118
    learn_char(213, cd5);
-
 
1119
    learn_char(214, cd6);
-
 
1120
    learn_char(215, cd7);
-
 
1121
#endif
-
 
1122
#if WRITECHARS == 216
-
 
1123
    // compass line
-
 
1124
    unsigned char cd8[54] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1125
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1126
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1127
        0x00, 0x00, 0x00, 0xaa, 0xaa, 0xaa, 0x00, 0x00,
-
 
1128
        0x00, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1129
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1130
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
 
1131
 
-
 
1132
    // arrow right
-
 
1133
    unsigned char cd9[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1134
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1135
        0x55, 0x15, 0x55, 0x54, 0x85, 0x40, 0x00, 0xa1,
-
 
1136
        0x2a, 0xaa, 0xa8, 0x2a, 0xaa, 0xa8, 0x40, 0x00,
-
 
1137
        0xa1, 0x55, 0x54, 0x85, 0x55, 0x55, 0x15, 0x55,
-
 
1138
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1139
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
 
1140
 
-
 
1141
    // arrow right-up
-
 
1142
    unsigned char cda[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1143
        0x55, 0x55, 0x40, 0x01, 0x55, 0x2a, 0xa8, 0x55,
-
 
1144
        0x4a, 0xa8, 0x55, 0x52, 0xa8, 0x55, 0x4a, 0xa8,
-
 
1145
        0x55, 0x2a, 0x28, 0x54, 0xa8, 0x48, 0x52, 0xa1,
-
 
1146
        0x51, 0x4a, 0x85, 0x55, 0x52, 0x15, 0x55, 0x54,
-
 
1147
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1148
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
 
1149
 
-
 
1150
    // arrow up
-
 
1151
    unsigned char cdb[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1152
        0x55, 0x55, 0x41, 0x55, 0x55, 0x28, 0x55, 0x54,
-
 
1153
        0xaa, 0x15, 0x52, 0xaa, 0x85, 0x54, 0x28, 0x15,
-
 
1154
        0x55, 0x28, 0x55, 0x55, 0x28, 0x55, 0x55, 0x28,
-
 
1155
        0x55, 0x55, 0x28, 0x55, 0x55, 0x28, 0x55, 0x55,
-
 
1156
        0x28, 0x55, 0x55, 0x41, 0x55, 0x55, 0x55, 0x55,
-
 
1157
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
 
1158
 
-
 
1159
    // arrow left-up
-
 
1160
    unsigned char cdc[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1161
        0x55, 0x40, 0x01, 0x55, 0x2a, 0xa8, 0x55, 0x2a,
-
 
1162
        0xa1, 0x55, 0x2a, 0x85, 0x55, 0x2a, 0xa1, 0x55,
-
 
1163
        0x28, 0xa8, 0x55, 0x21, 0x2a, 0x15, 0x45, 0x4a,
-
 
1164
        0x85, 0x55, 0x52, 0xa1, 0x55, 0x54, 0x85, 0x55,
-
 
1165
        0x55, 0x15, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1166
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
 
1167
 
-
 
1168
    // arrow left
-
 
1169
    unsigned char cdd[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1170
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x54,
-
 
1171
        0x55, 0x55, 0x52, 0x15, 0x55, 0x4a, 0x00, 0x01,
-
 
1172
        0x2a, 0xaa, 0xa8, 0x2a, 0xaa, 0xa8, 0x4a, 0x00,
-
 
1173
        0x01, 0x52, 0x15, 0x55, 0x54, 0x55, 0x55, 0x55,
-
 
1174
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1175
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
 
1176
 
-
 
1177
    // arrow left-down
-
 
1178
    unsigned char cde[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1179
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x15, 0x55,
-
 
1180
        0x54, 0x85, 0x55, 0x52, 0xa1, 0x45, 0x4a, 0x85,
-
 
1181
        0x21, 0x2a, 0x15, 0x28, 0xa8, 0x55, 0x2a, 0xa1,
-
 
1182
        0x55, 0x2a, 0x85, 0x55, 0x2a, 0xa1, 0x55, 0x2a,
-
 
1183
        0xa8, 0x55, 0x40, 0x01, 0x55, 0x55, 0x55, 0x55,
-
 
1184
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
 
1185
 
-
 
1186
    // arrow down
-
 
1187
    unsigned char cdf[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1188
        0x55, 0x55, 0x41, 0x55, 0x55, 0x28, 0x55, 0x55,
-
 
1189
        0x28, 0x55, 0x55, 0x28, 0x55, 0x55, 0x28, 0x55,
-
 
1190
        0x55, 0x28, 0x55, 0x55, 0x28, 0x55, 0x54, 0x28,
-
 
1191
        0x15, 0x52, 0xaa, 0x85, 0x54, 0xaa, 0x15, 0x55,
-
 
1192
        0x28, 0x55, 0x55, 0x41, 0x55, 0x55, 0x55, 0x55,
-
 
1193
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
 
1194
 
-
 
1195
    learn_char(216, cd8);
-
 
1196
        learn_char(217, cd9);
-
 
1197
    learn_char(218, cda);
-
 
1198
    learn_char(219, cdb);
-
 
1199
    learn_char(220, cdc);
-
 
1200
    learn_char(221, cdd);
-
 
1201
    learn_char(222, cde);
-
 
1202
    learn_char(223, cdf);
-
 
1203
#endif
-
 
1204
#if WRITECHARS == 224
-
 
1205
     // arrow right-down
-
 
1206
    unsigned char ce0[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1207
        0x55, 0x55, 0x55, 0x55, 0x54, 0x55, 0x55, 0x52,
-
 
1208
        0x15, 0x55, 0x4a, 0x85, 0x55, 0x52, 0xa1, 0x51,
-
 
1209
        0x54, 0xa8, 0x48, 0x55, 0x2a, 0x28, 0x55, 0x4a,
-
 
1210
        0xa8, 0x55, 0x52, 0xa8, 0x55, 0x4a, 0xa8, 0x55,
-
 
1211
        0x2a, 0xa8, 0x55, 0x40, 0x01, 0x55, 0x55, 0x55,
-
 
1212
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
 
1213
 
-
 
1214
        // horizon up
-
 
1215
    unsigned char ce1[54] ={0x55, 0x55, 0x55, 0x00, 0x00, 0x00, 0xaa, 0xaa,
-
 
1216
        0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x55,
-
 
1217
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1218
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1219
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1220
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1221
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
 
1222
 
-
 
1223
        // horizon middle
-
 
1224
    unsigned char ce2[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1225
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1226
        0x55, 0x55, 0x55, 0x55, 0x55, 0x00, 0x00, 0x00,
-
 
1227
        0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00,
-
 
1228
        0x00, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1229
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1230
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
 
1231
 
-
 
1232
        // horizon down
-
 
1233
    unsigned char ce3[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1234
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1235
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1236
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1237
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x00,
-
 
1238
        0x00, 0x00, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
-
 
1239
        0x00, 0x00, 0x00, 0x55, 0x55, 0x55};
-
 
1240
 
-
 
1241
        // horizon center
-
 
1242
    unsigned char ce4[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1243
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1244
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1245
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1246
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x00,
-
 
1247
        0x14, 0x00, 0xaa, 0x14, 0xaa, 0xaa, 0x82, 0xaa,
-
 
1248
        0x00, 0xaa, 0x00, 0x54, 0x00, 0x15};
-
 
1249
 
-
 
1250
        // horizon roll
-
 
1251
    unsigned char ce5[54] ={0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1252
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1253
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1254
        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
-
 
1255
        0x55, 0x00, 0x55, 0x00, 0x2a, 0x14, 0xa8, 0x4a,
-
 
1256
        0x82, 0xa1, 0x52, 0xaa, 0x85, 0x54, 0xaa, 0x15,
-
 
1257
        0x55, 0x28, 0x55, 0x55, 0x41, 0x55};
-
 
1258
       
-
 
1259
        // gps PH
-
 
1260
    unsigned char ce6[54] ={0x55, 0x05, 0x11, 0x54, 0xa0, 0x88, 0x54, 0x88,
-
 
1261
        0x88, 0x54, 0xa0, 0xa8, 0x54, 0x84, 0x88, 0x44,
-
 
1262
        0x84, 0x88, 0x21, 0x15, 0x11, 0xa8, 0x55, 0x55,
-
 
1263
        0xa1, 0x55, 0x55, 0x98, 0x15, 0x55, 0x2a, 0x85,
-
 
1264
        0x55, 0x4a, 0xa1, 0x55, 0x4a, 0xa8, 0x55, 0x52,
-
 
1265
        0xaa, 0x15, 0x54, 0xaa, 0x15, 0x55, 0x28, 0x55,
-
 
1266
        0x55, 0x41, 0x55, 0x55, 0x55, 0x55};
-
 
1267
       
-
 
1268
        // gps CH
-
 
1269
    unsigned char ce7[54] ={0x55, 0x55, 0x41, 0x55, 0x55, 0x28, 0x55, 0x54,
-
 
1270
        0x81, 0x55, 0x54, 0x85, 0x55, 0x54, 0x81, 0x45,
-
 
1271
        0x55, 0x28, 0x21, 0x55, 0x01, 0xa8, 0x54, 0x88,
-
 
1272
        0xa1, 0x54, 0x88, 0x98, 0x14, 0xa8, 0x2a, 0x84,
-
 
1273
        0x88, 0x4a, 0xa0, 0x88, 0x4a, 0xa8, 0x11, 0x52,
-
 
1274
        0xaa, 0x15, 0x54, 0xaa, 0x15, 0x55, 0x28, 0x55,
-
 
1275
        0x55, 0x41, 0x55, 0x55, 0x55, 0x55};
-
 
1276
 
-
 
1277
    learn_char(224, ce0);
-
 
1278
        learn_char(225, ce1);
-
 
1279
        learn_char(226, ce2);
-
 
1280
        learn_char(227, ce3);
-
 
1281
        learn_char(228, ce4);
-
 
1282
        learn_char(229, ce5);
-
 
1283
        learn_char(230, ce6);
-
 
Line 1284... Line -...
1284
        learn_char(231, ce7);
-
 
1285
#endif
-
 
1286
 
-
 
1287
#if WRITECHARS == 232
-
 
1288
 
-
 
1289
    // small arrow down
-
 
1290
    unsigned char ce8[54] = {0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
-
 
1291
        0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
-
 
1292
        0x55,0x55,0x55,0x55,0x55,0x00,0x00,0x00,
-
 
1293
        0x2a,0xaa,0xa8,0x2a,0xaa,0xa8,0x0a,0xaa,
-
 
1294
        0xa0,0x52,0xaa,0x85,0x54,0xaa,0x15,0x55,
-
 
1295
        0x28,0x55,0x55,0x41,0x55,0x55,0x55,0x55,
-
 
1296
        0x55,0x55,0x55,0x55,0x55,0x55};
-
 
1297
 
-
 
1298
    // big arrow down
-
 
1299
    unsigned char ce9[54] = {0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
-
 
1300
        0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
-
 
1301
        0x55,0x55,0x55,0x55,0x55,0x00,0x00,0x00,
-
 
1302
        0x2a,0xaa,0xa8,0x2a,0xaa,0xa8,0x00,0x28,
-
 
1303
        0x00,0x55,0x28,0x55,0x40,0x28,0x01,0x2a,
-
 
1304
        0xaa,0xa8,0x4a,0xaa,0xa1,0x52,0xaa,0x85,
-
 
1305
        0x54,0xaa,0x15,0x55,0x28,0x55};
-
 
1306
 
-
 
1307
    // small arrow up
-
 
1308
    unsigned char cea[54] = {0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
-
 
1309
        0x55,0x55,0x41,0x55,0x55,0x28,0x55,0x54,
-
 
1310
        0xaa,0x15,0x52,0xaa,0x85,0x0a,0xaa,0xa0,
-
 
1311
        0x2a,0xaa,0xa8,0x2a,0xaa,0xa8,0x00,0x00,
-
 
1312
        0x00,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
-
 
1313
        0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
-
 
1314
        0x55,0x55,0x55,0x55,0x55,0x55};
-
 
1315
 
-
 
1316
    // big arrow up
-
 
1317
    unsigned char ceb[54] = {0x55,0x28,0x55,0x54,0xaa,0x15,0x52,0xaa,
-
 
1318
        0x85,0x4a,0xaa,0xa1,0x2a,0xaa,0xa8,0x40,
-
 
1319
        0x28,0x01,0x55,0x28,0x55,0x00,0x28,0x00,
-
 
1320
        0x2a,0xaa,0xa8,0x2a,0xaa,0xa8,0x00,0x00,
-
 
1321
        0x00,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
-
 
1322
        0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
-
 
1323
        0x55,0x55,0x55,0x55,0x55,0x55};
-
 
1324
 
-
 
1325
    learn_char(232, ce8);
-
 
1326
    learn_char(233, ce9);
-
 
1327
    learn_char(234, cea);
-
 
1328
    learn_char(235, ceb);
-
 
1329
 
-
 
1330
#endif
-
 
1331
 
-
 
1332
 
-
 
1333
 
-
 
1334
#endif // write char general
414
    spi_send_byte(0x00, 0b00000000);
1335
    /* ##########################################################################
415
 
1336
     * continue normal main
416
        #include "characters.c"
1337
     * ##########################################################################*/
417
#endif 
1338
       
418
 
Line 1415... Line 495...
1415
    sendMKData('o', 1, &ms, 1);
495
    sendMKData('o', 1, &ms, 1);
1416
        // and disable debug...
496
        // and disable debug...
1417
        //ms = 0;
497
        //ms = 0;
1418
        //sendMKData('d', 0, &ms, 1);
498
        //sendMKData('d', 0, &ms, 1);
Line -... Line 499...
-
 
499
 
-
 
500
        // disable TXD-pin
-
 
501
        usart1_DisableTXD();
1419
 
502
 
1420
        // stats for after flight
503
        // stats for after flight
1421
        int16_t max_Altimeter = 0;
504
        int16_t max_Altimeter = 0;
1422
        uint16_t max_GroundSpeed = 0;
505
        uint16_t max_GroundSpeed = 0;
1423
        int16_t max_Distance = 0;
506
        int16_t max_Distance = 0;
Line 1448... Line 531...
1448
            if (rxd_buffer[2] == 'D') { // FC Data
531
            if (rxd_buffer[2] == 'D') { // FC Data
1449
                /*Decode64();
532
                /*Decode64();
1450
                debugData = *((DebugOut_t*) pRxData);
533
                debugData = *((DebugOut_t*) pRxData);
1451
                write_number_s(12, 2, RxDataLen);
534
                write_number_s(12, 2, RxDataLen);
1452
                write_number_s(20, 2, setsReceived++);
535
                write_number_s(20, 2, setsReceived++);
1453
                write_number_s(12, 3, debugData.Analog[0]);
536
                write_number_s(12, 3, debugData.Analog[0]); // AngleNick
1454
                write_number_s(12, 4, debugData.Analog[2]);
537
                write_number_s(12, 4, debugData.Analog[1]); // AngleRoll
1455
                write_number_s(12, 5, debugData.Analog[1]);
538
                                write_number_s(12, 5, debugData.Analog[5]); // Height
1456
                write_number_s(12, 6, debugData.Analog[3]);
-
 
1457
                write_number_s(12, 7, debugData.Analog[9]);
539
                write_number_s(12, 6, debugData.Analog[9]); // Voltage
1458
                write_number_s(12, 8, debugData.Analog[10]);
540
                write_number_s(12, 7, debugData.Analog[10]);// RC Signal
1459
                                write_number_s(12, 4, debugData.Analog[12]);
-
 
1460
                                write_number_s(12, 5, debugData.Analog[13]);
-
 
1461
                                write_number_s(12, 6, debugData.Analog[14]);
-
 
1462
                                write_number_s(12, 7, debugData.Analog[15]);*/
541
                                write_number_s(12, 8, debugData.Analog[11]);// Gyro compass*/
1463
            } else if (rxd_buffer[2] == 'O') { // NC OSD Data
542
            } else if (rxd_buffer[2] == 'O') { // NC OSD Data
1464
                Decode64();
543
                Decode64();
1465
                naviData = *((NaviData_t*) pRxData);
544
                naviData = *((NaviData_t*) pRxData);
Line 1466... Line 545...
1466
 
545
 
Line 1571... Line 650...
1571
                                if (naviData.UBat < min_UBat) min_UBat = naviData.UBat;
650
                                if (naviData.UBat < min_UBat) min_UBat = naviData.UBat;
1572
                                if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime;
651
                                if (naviData.FlyingTime > max_FlyingTime) max_FlyingTime = naviData.FlyingTime;
Line 1573... Line 652...
1573
                               
652
                               
1574
                                old_MKFlags = naviData.MKFlags;
653
                                old_MKFlags = naviData.MKFlags;
-
 
654
            }
1575
            }
655
                        seconds_since_last_data = 0;
1576
            rxd_buffer_locked = 0;
656
            rxd_buffer_locked = 0;
1577
        }
657
        }
1578
        // handle keypress
658
        // handle keypress
1579
        if (s1_pressed()) {
659
        if (s1_pressed()) {
Line 1586... Line 666...
1586
        }
666
        }
1587
                if (s2_pressed()) {
667
                if (s2_pressed()) {
1588
            uptime = 0;
668
            uptime = 0;
1589
            _delay_ms(100);
669
            _delay_ms(100);
1590
        }
670
        }
-
 
671
                if (seconds_since_last_data > 2) {
-
 
672
                        // re-request OSD Data from NC
-
 
673
                       
-
 
674
                        // re-enable TXD pin
-
 
675
                        usart1_EnableTXD();
-
 
676
                       
-
 
677
                        // every 100ms
-
 
678
                        unsigned char ms = 10;
-
 
679
            sendMKData('o', 1, &ms, 1);
-
 
680
                       
-
 
681
                        // disable TXD pin again
-
 
682
                        usart1_DisableTXD();
-
 
683
 
-
 
684
                        seconds_since_last_data = 0;
-
 
685
                }
1591
    }
686
    }
1592
#endif
687
#endif
1593
    return 0;
688
    return 0;
1594
}
689
}