Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1053 - 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
 
87
        // enable pull ups for the 4 keys
88
        PORTA |= (1<<PORTA4)|(1<<PORTA5)|(1<<PORTA6)|(1<<PORTA7);
89
 
90
 
91
#ifdef HWVERSION1_2
92
        DDRC |= (1<<DDC0)|(1<<DDC1);
93
        DDRD |= (1<<DDD7);
94
        DDRB = 0xFF;
95
#endif  
96
#ifdef HWVERSION1_3
97
        DDRC |= (1<<DDC2);
98
        DDRD |= (1<<DDD6) |(1<<DDD7);
99
        DDRB = 0xFF;
100
#endif  
101
 
102
#ifdef HWVERSION3_1
103
 
104
        DDRD |= (1<<DDD7)|(1<<DDD6);
105
 
106
        DDRC = 0xFF;
107
        DDRB = 0xFF;
108
        set_LED1();
109
        set_LED2();
110
        set_LED3();
111
        set_LED4();
112
        set_BEEP();
113
        set_D_LIGHT();
114
        clr_WI232CMD();
115
 _delay_ms(250);
116
 
117
        clr_LED1();
118
        clr_LED2();
119
        clr_LED3();
120
        clr_LED4();
121
        clr_BEEP();
122
 
123
 
124
#endif
125
 
126
        Display_on = 1;
127
        ReadParameter ();
128
        LCD_Init ();
129
        USART_Init (UART_BAUD_SELECT(USART_BAUD,F_CPU));
130
 
131
 
132
 
133
#if defined HWVERSION3_1 || defined HWVERSION1_3
134
 
135
        uart1_init (UART_BAUD_SELECT(USART_BAUD,F_CPU));      /* USB*/
136
        uart1_putc('R');
137
        I2C_Init();
138
#endif
139
 
140
 
141
        TIMER0_Init ();
142
        TIMER1_Init (); // pwm
143
 
144
        sei ();
145
 
146
#ifdef HWVERSION3_1
147
        InitWi232();
148
    _delay_ms(2000);
149
        hardware = NO;
150
        current_hardware = 0;
151
#endif
152
 
153
 
154
        // switch to NC
155
        USART_putc (0x1b);
156
        USART_putc (0x1b);
157
        USART_putc (0x55);
158
        USART_putc (0xaa);
159
        USART_putc (0x00);
160
 
161
        mode = 'V';
162
#if MTEST
163
        do
164
        {
165
                timeout = 50;
166
                lcd_cls ();
167
                lcd_printpns_at (0,0,PSTR("Portables Koptertool"), 0);
168
                lcd_printpns_at (0,1,PSTR("for FC V "), 0);
169
                lcd_printpns_at (10,1,PSTR(FC_Version),0);
170
                lcd_printpns_at (0,2,PSTR("GNU GPL License"), 0);
171
                lcd_printpns_at (0,3,PSTR("checking hardware..."), 0);
172
                lcd_printpns_at (0, 7, PSTR("Skip FC-Check"), 0);
173
 
174
 
175
 
176
                while (!rxd_buffer_locked && timeout)
177
 
178
                {
179
 
180
                        SendOutData('v', ADDRESS_ANY, 0);
181
                        timer = 20;
182
                        while (timer > 0);
183
                        timeout--;
184
 
185
                        if (get_key_press (1 << KEY_MINUS))
186
                         {
187
                                for (;;)
188
                                {
189
                                        hardware = NO;
190
                                        main_menu ();
191
                                }
192
                         }
193
 
194
//#ifdef HWVERSION1_3
195
//                      debug1();
196
//#endif
197
                }
198
                if(timeout == 0)
199
                {
200
                        lcd_printpns_at (0,4,PSTR("ERROR:"), 0);
201
                        lcd_printpns_at (0,5,PSTR("no hardware detected"), 0);
202
                        timer = 90;
203
//#ifdef HWVERSION1_3
204
//                      debug1();
205
//#endif
206
                        while (timer > 0);
207
                }
208
 
209
        }
210
 
211
 
212
 
213
        while(timeout == 0);
214
 
215
                Decode64 ();
216
                version = (Version_t *) pRxData;
217
 
218
                lcd_cls ();
219
                lcd_printp (PSTR("PMK-Tool GNU GPL\r\n"), 0);
220
                lcd_printp (PSTR("found:\r\n\n"), 0);
221
 
222
                if ((rxd_buffer[1] - 'a') == ADDRESS_FC)
223
                {
224
                        lcd_printp (PSTR("Flight-Ctrl\r\n"), 0);
225
                        hardware = FC;
226
                        current_hardware = hardware;
227
                }
228
                else if ((rxd_buffer[1] - 'a') == ADDRESS_NC)
229
                {
230
                        lcd_printp (PSTR("Navi-Ctrl\r\n"), 0);
231
                        hardware = NC;
232
                        current_hardware = hardware;
233
                }
234
 
235
                lcd_printp (PSTR("Version: "), 0);
236
                lcd_write_number_u (version->SWMajor);
237
                lcd_printp (PSTR("."), 0);
238
                lcd_write_number_u (version->SWMinor);
239
                lcd_putc (lcd_xpos, lcd_ypos, version->SWPatch + 'a', 0);
240
#else
241
                lcd_cls ();
242
                lcd_printp (PSTR("PKT-Test\r\n"), 0);
243
 
244
#endif
245
 
246
                timer = 50;
247
                while (timer > 0);
248
        SwitchToFC();
249
            //Delay
250
        timer = 50;
251
                while (timer > 0);
252
#if MTEST
253
// EEprom Version / Struktur prüfen
254
        val = load_setting(1); //Parameterset 1 holen
255
                if (mk_param_struct->Revision != EEProm_Version)
256
                         {
257
                          lcd_cls ();
258
                          lcd_printp (PSTR("EEPromRev."), 0);
259
                          lcd_write_number_u (EEProm_Version);
260
                          lcd_printp (PSTR(" erwartet\r\n"), 0);
261
                          lcd_printp (PSTR("EEPromRev."), 0);
262
                          lcd_write_number_u (mk_param_struct->Revision);
263
                          lcd_printp (PSTR(" gefunden\r\n"), 0);
264
                          lcd_printp (PSTR("PMK-Tool nur mit\r\n"), 0);
265
                          lcd_printp (PSTR("FC Software "), 0);
266
                          lcd_printp (PSTR(FC_Version),0);
267
                          lcd_printp (PSTR("\r\nkompatibel"), 0);
268
                          while (mk_param_struct->Revision != EEProm_Version);
269
                         }
270
 
271
#endif
272
        mode = 0;
273
        rxd_buffer_locked = FALSE;
274
 
275
        timer = 200;
276
        while (timer > 0);
277
        for (;;)
278
        {
279
                main_menu ();
280
        }
281
}