Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
730 woggle 1
/*****************************************************************************
2
 *   Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de                  *
3
 *   Copyright (C) 2009-2010 Peter "woggle" Mack, mac@denich.net             *
4
 *                                                                           *
5
 *   This program is free software; you can redistribute it and/or modify    *
6
 *   it under the terms of the GNU General Public License as published by    *
7
 *   the Free Software Foundation; either version 2 of the License.          *
8
 *                                                                           *
9
 *   This program is distributed in the hope that it will be useful,         *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
12
 *   GNU General Public License for more details.                            *
13
 *                                                                           *
14
 *   You should have received a copy of the GNU General Public License       *
15
 *   along with this program; if not, write to the                           *
16
 *   Free Software Foundation, Inc.,                                         *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               *
18
 *                                                                           *
19
 *                                                                           *
20
 *   Credits to:                                                             *
21
 *   Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN  *
22
 *                          http://www.mikrokopter.de                        *
23
 *   Gregor "killagreg" Stobrawa for his version of the MK code              *
24
 *   Thomas Kaiser "thkais" for the original project. See                    *
25
 *                          http://www.ft-fanpage.de/mikrokopter/            *
26
 *                          http://forum.mikrokopter.de/topic-4061-1.html    *
27
 *   Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code *
28
 *                          http://www.mylifesucks.de/oss/c-osd/             *
29
 *****************************************************************************/
30
 
31
#include <inttypes.h>
32
#include <avr/io.h>
33
#include <avr/interrupt.h>
34
#include <avr/pgmspace.h>
35
#include <avr/eeprom.h>
36
#include <util/delay.h>
37
 
38
#include "main.h"
39
#include "lcd.h"
40
#include "usart.h"
41
#include "parameter.h"
42
#include "menu.h"
43
#include "display.h"
44
#include "timer.h"
45
#include "jeti.h"
46
#include "lipo.h"
47
#include "eeprom.h"
48
 
49
#include "mk-data-structs.h"
50
 
51
 
52
#ifndef USE_MMT
53
#define LEDS    // my development board has some status LEDs
54
#endif
55
 
56
//#define MTEST // Menu Test (skip FC/NC detection)
57
 
58
 
59
Version_t *version;
60
 
61
volatile uint8_t mode = 0;
62
 
63
uint8_t hardware = 0;
64
uint8_t current_hardware = 0;
65
 
66
 
67
int main (void)
68
{
69
        uint8_t timeout;
70
 
71
        PORTA = 0xF0;
72
        PORTB = 0x43;
73
#if defined (__AVR_ATmega32__)
74
        PORTC = 0xFC;
75
#else
76
        PORTC = 0xFF;
77
#endif
78
        PORTD = 0x70;
79
 
80
#ifdef LEDS
81
        DDRC = 0x1C;
82
        DDRD = 0xF0;
83
#else
84
#if defined (__AVR_ATmega32__)
85
        DDRC = 0x03;
86
#endif
87
        DDRD = 0x80;
88
#endif
89
 
90
        ReadParameter ();
91
 
92
        LCD_Init ();
93
        USART_Init ();
94
        TIMER0_Init ();
95
#ifndef USE_MMT
96
        JETI_Init();
97
        ADC_Init();
98
#endif
99
 
100
        sei ();
101
#ifndef MTEST
102
        lcd_cls ();
103
#ifdef USE_MMT
104
        lcd_printp (PSTR("Portable Kopter Tool\r\n"), 0);
105
#else
106
        lcd_printp (PSTR("MK Multi Box\r\n"), 0);
107
#endif
108
        lcd_printp (PSTR("checking hardware..."), 0);
109
 
110
        // switch to NC
111
        USART_putc (0x1b);
112
        USART_putc (0x1b);
113
        USART_putc (0x55);
114
        USART_putc (0xaa);
115
        USART_putc (0x00);
116
 
117
        mode = 'V';
118
        timeout = 50;
119
        while (!rxd_buffer_locked && timeout)
120
        {
121
                SendOutData('v', ADDRESS_ANY, 0);
122
                timer = 20;
123
                while (timer > 0);
124
                timeout--;
125
        }
126
        if (timeout != 0)
127
        {
128
                Decode64 ();
129
                version = (Version_t *) pRxData;
130
 
131
                lcd_cls ();
132
#ifdef USE_MMT
133
                lcd_printp (PSTR("Portable Kopter Tool\r\n"), 0);
134
#else
135
                lcd_printp (PSTR("MK Multi Box\r\n"), 0);
136
#endif
137
                lcd_printp (PSTR("found:\r\n\n"), 0);
138
 
139
                if ((rxd_buffer[1] - 'a') == ADDRESS_FC)
140
                {
141
                        lcd_printp (PSTR("Flight-Ctrl\r\n"), 0);
142
                        hardware = FC;
143
                        current_hardware = hardware;
144
                }
145
                else if ((rxd_buffer[1] - 'a') == ADDRESS_NC)
146
                {
147
                        lcd_printp (PSTR("Navi-Ctrl\r\n"), 0);
148
                        hardware = NC;
149
                        current_hardware = hardware;
150
                }
151
 
152
                lcd_printp (PSTR("Version: "), 0);
153
                lcd_write_number_u (version->SWMajor);
154
                lcd_printp (PSTR("."), 0);
155
                lcd_write_number_u (version->SWMinor);
156
                lcd_putc (lcd_xpos, lcd_ypos, version->SWPatch + 'a', 0);
157
        }
158
        else
159
        {       // timeout occured
160
                lcd_printp (PSTR("\r\n\nERROR: no data"), 0);
161
        }
162
        mode = 0;
163
        rxd_buffer_locked = FALSE;
164
 
165
        timer = 200;
166
        while (timer > 0);
167
#endif
168
        for (;;)
169
        {
170
                main_menu ();
171
        }
172
}