Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1071 - 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
 
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
        ReadParameter ();
154
 
155
        // switch to NC
156
        USART_putc (0x1b);
157
        USART_putc (0x1b);
158
        USART_putc (0x55);
159
        USART_putc (0xaa);
160
        USART_putc (0x00);
161
 
162
        mode = 'V';
163
#if MTEST
164
        do
165
        {
166
                timeout = 50;
167
                lcd_cls ();
168
                lcd_printpns_at (0,0,PSTR("Portables Koptertool"), 0);
169
                lcd_printpns_at (0,1,PSTR("for FC V "), 0);
170
                lcd_printpns_at (10,1,PSTR(FC_Version),0);
171
                lcd_printpns_at (0,2,PSTR("GNU GPL License"), 0);
172
                lcd_printpns_at (0,3,PSTR("checking hardware..."), 0);
173
                lcd_printpns_at (0, 7, PSTR("Skip FC-Check"), 0);
174
 
175
 
176
 
177
                while (!rxd_buffer_locked && timeout)
178
 
179
                {
180
 
181
                        SendOutData('v', ADDRESS_ANY, 0);
182
                        timer = 20;
183
                        while (timer > 0);
184
                        timeout--;
185
 
186
                        if (get_key_press (1 << KEY_MINUS))
187
                         {
188
                                for (;;)
189
                                {
190
                                        hardware = NO;
191
                                        main_menu ();
192
                                }
193
                         }
194
 
195
//#ifdef HWVERSION1_3
196
//                      debug1();
197
//#endif
198
                }
199
                if(timeout == 0)
200
                {
201
                        lcd_printpns_at (0,4,PSTR("ERROR:"), 0);
202
                        lcd_printpns_at (0,5,PSTR("no hardware detected"), 0);
203
                        timer = 90;
204
//#ifdef HWVERSION1_3
205
//                      debug1();
206
//#endif
207
                        while (timer > 0);
208
                }
209
 
210
        }
211
 
212
 
213
 
214
        while(timeout == 0);
215
 
216
                Decode64 ();
217
                version = (Version_t *) pRxData;
218
 
219
                lcd_cls ();
220
                lcd_printp (PSTR("PMK-Tool GNU GPL\r\n"), 0);
221
                lcd_printp (PSTR("found:\r\n\n"), 0);
222
 
223
                if ((rxd_buffer[1] - 'a') == ADDRESS_FC)
224
                {
225
                        lcd_printp (PSTR("Flight-Ctrl\r\n"), 0);
226
                        hardware = FC;
227
                        current_hardware = hardware;
228
                }
229
                else if ((rxd_buffer[1] - 'a') == ADDRESS_NC)
230
                {
231
                        lcd_printp (PSTR("Navi-Ctrl\r\n"), 0);
232
                        hardware = NC;
233
                        current_hardware = hardware;
234
                }
235
 
236
                lcd_printp (PSTR("Version: "), 0);
237
                lcd_write_number_u (version->SWMajor);
238
                lcd_printp (PSTR("."), 0);
239
                lcd_write_number_u (version->SWMinor);
240
                lcd_putc (lcd_xpos, lcd_ypos, version->SWPatch + 'a', 0);
241
#else
242
                lcd_cls ();
243
                lcd_printp (PSTR("PKT-Test\r\n"), 0);
244
 
245
#endif
246
 
247
                timer = 50;
248
                while (timer > 0);
249
        SwitchToFC();
250
            //Delay
251
        timer = 50;
252
                while (timer > 0);
253
#if MTEST
254
// EEprom Version / Struktur prüfen
255
        val = load_setting(1); //Parameterset 1 holen
256
                if (mk_param_struct->Revision != EEProm_Version)
257
                         {
258
                          lcd_cls ();
259
                          lcd_printp (PSTR("EEPromRev."), 0);
260
                          lcd_write_number_u (EEProm_Version);
261
                          lcd_printp (PSTR(" erwartet\r\n"), 0);
262
                          lcd_printp (PSTR("EEPromRev."), 0);
263
                          lcd_write_number_u (mk_param_struct->Revision);
264
                          lcd_printp (PSTR(" gefunden\r\n"), 0);
265
                          lcd_printp (PSTR("PMK-Tool nur mit\r\n"), 0);
266
                          lcd_printp (PSTR("FC Software "), 0);
267
                          lcd_printp (PSTR(FC_Version),0);
268
                          lcd_printp (PSTR("\r\nkompatibel"), 0);
269
                          while (mk_param_struct->Revision != EEProm_Version);
270
                         }
271
 
272
#endif
273
        mode = 0;
274
        rxd_buffer_locked = FALSE;
275
 
276
        timer = 200;
277
        while (timer > 0);
278
        for (;;)
279
        {
280
                main_menu ();
281
        }
282
}