Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1148 - 1
/*****************************************************************************
2
 *   Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de                  *
3
 *   Copyright (C) 2009-2010 Peter "woggle" Mack, mac@denich.net             *
4
 *   Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net *
5
 *                                                                           *
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    *
8
 *   the Free Software Foundation; either version 2 of the License.          *
9
 *                                                                           *
10
 *   This program is distributed in the hope that it will be useful,         *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
13
 *   GNU General Public License for more details.                            *
14
 *                                                                           *
15
 *   You should have received a copy of the GNU General Public License       *
16
 *   along with this program; if not, write to the                           *
17
 *   Free Software Foundation, Inc.,                                         *
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               *
19
 *                                                                           *
20
 *                                                                           *
21
 *   Credits to:                                                             *
22
 *   Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN  *
23
 *                          http://www.mikrokopter.de                        *
24
 *   Gregor "killagreg" Stobrawa for his version of the MK code              *
25
 *   Thomas Kaiser "thkais" for the original project. See                    *
26
 *                          http://www.ft-fanpage.de/mikrokopter/            *
27
 *                          http://forum.mikrokopter.de/topic-4061-1.html    *
28
 *   Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code *
29
 *                          http://www.mylifesucks.de/oss/c-osd/             *
30
 *****************************************************************************/
31
 
32
#include <inttypes.h>
33
#include <avr/io.h>
34
#include <avr/interrupt.h>
35
#include <avr/pgmspace.h>
36
#include <avr/eeprom.h>
37
#include <util/delay.h>
38
#include <avr/wdt.h>
39
 
40
/* Watchdog integrieren und abschalten, wird für Bootloader benötigt*/
41
void wdt_init(void) __attribute__((naked)) __attribute__((section(".init1")));
42
 
43
void wdt_init(void)
44
{
45
    MCUSR = 0;
46
    wdt_disable();
47
 
48
    return;
49
}
50
 
51
#include "main.h"
52
#include "lcd.h"
53
#include "usart.h"
54
#include "uart1.h"
55
#include "mk-data-structs.h"
56
#include "parameter.h"
57
#include "menu.h"
58
#include "display.h"
59
#include "timer.h"
60
#include "eeprom.h"
61
#include "Wi232.h"
62
 
63
#if defined HWVERSION3_1 || defined HWVERSION1_3
64
#include "motortestI2C.h"
65
#endif
66
 
67
 
68
 
69
#define MTEST 1 // Menu Test (skip FC/NC detection)
70
 
71
Version_t *version;
72
 
73
volatile uint8_t mode = 0;
74
 
75
uint8_t hardware = 0;
76
uint8_t current_hardware = 0;
77
//uint8_t no_hardware = 0;
78
 
79
mk_param_struct_t *mk_param_struct;
80
 
81
 
82
int main (void)
83
{
84
        uint8_t timeout;
85
        uint8_t val =0;
86
        uint8_t spalte =0;
87
 
88
        // enable pull ups for the 4 keys
89
        PORTA |= (1<<PORTA4)|(1<<PORTA5)|(1<<PORTA6)|(1<<PORTA7);
90
 
91
 
92
#ifdef HWVERSION1_2
93
        DDRC |= (1<<DDC0)|(1<<DDC1);
94
        DDRD |= (1<<DDD7);
95
        DDRB = 0xFF;
96
#endif  
97
#ifdef HWVERSION1_3
98
        DDRC |= (1<<DDC2);
99
        DDRD |= (1<<DDD6) |(1<<DDD7);
100
        DDRB = 0xFF;
101
#endif  
102
 
103
#ifdef HWVERSION3_1
104
 
105
        DDRD |= (1<<DDD7)|(1<<DDD6);
106
 
107
        DDRC = 0xFF;
108
        DDRB = 0xFF;
109
        set_LED1();
110
        set_LED2();
111
        set_LED3();
112
        set_LED4();
113
        set_BEEP();
114
        set_D_LIGHT();
115
        clr_WI232CMD();
116
 _delay_ms(250);
117
 
118
        clr_LED1();
119
        clr_LED2();
120
        clr_LED3();
121
        clr_LED4();
122
        clr_BEEP();
123
 
124
 
125
#endif
126
 
127
        Display_on = 1;
128
 
129
        LCD_Init ();
130
        USART_Init (UART_BAUD_SELECT(USART_BAUD,F_CPU));
131
 
132
 
133
 
134
#if defined HWVERSION3_1 || defined HWVERSION1_3
135
 
136
        uart1_init (UART_BAUD_SELECT(USART_BAUD,F_CPU));      /* USB*/
137
        uart1_putc('R');
138
        I2C_Init();
139
#endif
140
 
141
 
142
        TIMER0_Init ();
143
        TIMER1_Init (); // pwm
144
 
145
        sei ();
146
 
147
        ReadParameter ();
148
        LCD_Init ();
149
 
150
 
151
#ifdef HWVERSION3_1
152
        InitWi232();
153
 
154
        hardware = NO;
155
        current_hardware = 0;
156
#endif
157
 
158
 
159
        // switch to NC
160
        USART_putc (0x1b);
161
        USART_putc (0x1b);
162
        USART_putc (0x55);
163
        USART_putc (0xaa);
164
        USART_putc (0x00);
165
 
166
        mode = 'V';
167
 
168
        lcd_cls ();
169
        lcd_printpns_at (0,0,PSTR("Portables Koptertool"), 0);
170
        lcd_printpns_at (0,1,PSTR("for FC V "), 0);
171
        lcd_printpns_at (10,1,PSTR(FC_Version),0);
172
        lcd_printpns_at (0,2,PSTR("GNU GPL License"), 0);
173
 
174
#ifdef HWVERSION3_1
175
        lcd_printpns_at (0,3,PSTR("Hardware 3.2, 644P"), 0);
176
#endif
177
#ifdef HWVERSION1_2
178
        lcd_printpns_at (0,3,PSTR("Hardware 1.2, 644"), 0);
179
#endif
180
#ifdef HWVERSION1_3
181
        lcd_printpns_at (0,3,PSTR("Hardware 1.3, 644P"), 0);
182
#endif
183
        _delay_ms(2000);
184
 
185
 
186
 
187
#if MTEST
188
        do
189
        {
190
                timeout = 50;
191
 
192
                lcd_printpns_at (0,4,PSTR("suche FC..."), 0);
193
                lcd_printpns_at (0, 7, PSTR("Skip FC-Check"), 0);
194
 
195
                while (!rxd_buffer_locked && timeout)
196
 
197
                {
198
 
199
                        SendOutData('v', ADDRESS_ANY, 0);
200
 
201
                        timer = 20;
202
                        while (timer > 0);
203
                        timeout--;
204
                        if (spalte <= 20)
205
                          {
206
                                lcd_printpns_at (spalte,6,PSTR("?"),0);
207
                                spalte++;
208
                          }
209
                        else
210
                          {
211
                                lcd_printpns_at (0,6,PSTR("                     "),0);
212
                                spalte=0;
213
                          }
214
 
215
                        if (get_key_press (1 << KEY_MINUS))
216
                         {
217
                                for (;;)
218
                                {
219
                                        hardware = NO;
220
                                        main_menu ();
221
                                }
222
                         }
223
 
224
//#ifdef HWVERSION1_3
225
//                      debug1();
226
//#endif
227
                }
228
                if(timeout == 0)
229
                {
230
 
231
                        lcd_printpns_at (0,5,PSTR("FC nicht gefunden"), 0);
232
                        timer = 90;
233
//#ifdef HWVERSION1_3
234
//                      debug1();
235
//#endif
236
                        while (timer > 0);
237
                }
238
 
239
        }
240
 
241
 
242
 
243
        while(timeout == 0);
244
 
245
                Decode64 ();
246
                version = (Version_t *) pRxData;
247
 
248
                lcd_cls ();
249
                lcd_printp (PSTR("PMK-Tool GNU GPL\r\n"), 0);
250
                lcd_printp (PSTR("found:\r\n\n"), 0);
251
 
252
                if ((rxd_buffer[1] - 'a') == ADDRESS_FC)
253
                {
254
                        lcd_printp (PSTR("Flight-Ctrl\r\n"), 0);
255
                        hardware = FC;
256
                        current_hardware = hardware;
257
                }
258
                else if ((rxd_buffer[1] - 'a') == ADDRESS_NC)
259
                {
260
                        lcd_printp (PSTR("Navi-Ctrl\r\n"), 0);
261
                        hardware = NC;
262
                        current_hardware = hardware;
263
                }
264
 
265
                lcd_printp (PSTR("Version: "), 0);
266
                lcd_write_number_u (version->SWMajor);
267
                lcd_printp (PSTR("."), 0);
268
                lcd_write_number_u (version->SWMinor);
269
                lcd_putc (lcd_xpos, lcd_ypos, version->SWPatch + 'a', 0);
270
#else
271
                lcd_cls ();
272
                lcd_printp (PSTR("PKT-Test\r\n"), 0);
273
 
274
#endif
275
 
276
                timer = 50;
277
                while (timer > 0);
278
        SwitchToFC();
279
            //Delay
280
        timer = 50;
281
                while (timer > 0);
282
#if MTEST
283
// EEprom Version / Struktur prüfen
284
        val = load_setting(1); //Parameterset 1 holen
285
                if (mk_param_struct->Revision != EEProm_Version)
286
                         {
287
                          lcd_cls ();
288
                          lcd_printp (PSTR("EEPromRev."), 0);
289
                          lcd_write_number_u (EEProm_Version);
290
                          lcd_printp (PSTR(" erwartet\r\n"), 0);
291
                          lcd_printp (PSTR("EEPromRev."), 0);
292
                          lcd_write_number_u (mk_param_struct->Revision);
293
                          lcd_printp (PSTR(" gefunden\r\n"), 0);
294
                          lcd_printp (PSTR("PMK-Tool nur mit\r\n"), 0);
295
                          lcd_printp (PSTR("FC Software "), 0);
296
                          lcd_printp (PSTR(FC_Version),0);
297
                          lcd_printp (PSTR("\r\nkompatibel"), 0);
298
                          while (mk_param_struct->Revision != EEProm_Version);
299
                         }
300
 
301
#endif
302
        mode = 0;
303
        rxd_buffer_locked = FALSE;
304
 
305
        timer = 200;
306
        while (timer > 0);
307
        for (;;)
308
        {
309
                main_menu ();
310
        }
311
}