Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
724 | 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 | #define LEDS // my development board has some status LEDs |
||
53 | |||
54 | //#define MTEST // Menu Test (skip FC/NC detection) |
||
55 | |||
56 | |||
57 | Version_t *version; |
||
58 | |||
59 | volatile uint8_t mode = 0; |
||
60 | |||
61 | uint8_t hardware = 0; |
||
62 | uint8_t current_hardware = 0; |
||
63 | |||
64 | |||
65 | int main (void) |
||
66 | { |
||
67 | uint8_t timeout; |
||
68 | |||
69 | PORTA = 0xF0; |
||
70 | PORTB = 0x43; |
||
71 | PORTC = 0xFF; |
||
72 | PORTD = 0x70; |
||
73 | |||
74 | #ifdef LEDS |
||
75 | DDRC = 0x1C; |
||
76 | DDRD = 0xF0; |
||
77 | #else |
||
78 | // DDRC = 0x03; |
||
79 | DDRD = 0x80; |
||
80 | #endif |
||
81 | |||
82 | ReadParameter (); |
||
83 | |||
84 | LCD_Init (); |
||
85 | USART_Init (); |
||
86 | JETI_Init(); |
||
87 | TIMER0_Init (); |
||
88 | ADC_Init(); |
||
89 | |||
90 | sei (); |
||
91 | #ifndef MTEST |
||
92 | lcd_cls (); |
||
93 | //lcd_printp (PSTR("Portable Kopter Tool\r\n"), 0); |
||
94 | lcd_printp (PSTR("MK Multi Box\r\n"), 0); |
||
95 | lcd_printp (PSTR("checking hardware..."), 0); |
||
96 | |||
97 | // switch to NC |
||
98 | USART_putc (0x1b); |
||
99 | USART_putc (0x1b); |
||
100 | USART_putc (0x55); |
||
101 | USART_putc (0xaa); |
||
102 | USART_putc (0x00); |
||
103 | |||
104 | mode = 'V'; |
||
105 | timeout = 50; |
||
106 | while (!rxd_buffer_locked && timeout) |
||
107 | { |
||
108 | SendOutData('v', ADDRESS_ANY, 0); |
||
109 | timer = 20; |
||
110 | while (timer > 0); |
||
111 | timeout--; |
||
112 | } |
||
113 | if (timeout != 0) |
||
114 | { |
||
115 | Decode64 (); |
||
116 | version = (Version_t *) pRxData; |
||
117 | |||
118 | lcd_cls (); |
||
119 | //lcd_printp (PSTR("Portable Kopter Tool\r\n"), 0); |
||
120 | lcd_printp (PSTR("MK Multi Box\r\n"), 0); |
||
121 | lcd_printp (PSTR("found:\r\n\n"), 0); |
||
122 | |||
123 | if ((rxd_buffer[1] - 'a') == ADDRESS_FC) |
||
124 | { |
||
125 | lcd_printp (PSTR("Flight-Ctrl\r\n"), 0); |
||
126 | hardware = FC; |
||
127 | current_hardware = hardware; |
||
128 | } |
||
129 | else if ((rxd_buffer[1] - 'a') == ADDRESS_NC) |
||
130 | { |
||
131 | lcd_printp (PSTR("Navi-Ctrl\r\n"), 0); |
||
132 | hardware = NC; |
||
133 | current_hardware = hardware; |
||
134 | } |
||
135 | |||
136 | lcd_printp (PSTR("Version: "), 0); |
||
137 | lcd_write_number_u (version->SWMajor); |
||
138 | lcd_printp (PSTR("."), 0); |
||
139 | lcd_write_number_u (version->SWMinor); |
||
140 | lcd_putc (lcd_xpos, lcd_ypos, version->SWPatch + 'a', 0); |
||
141 | } |
||
142 | else |
||
143 | { // timeout occured |
||
144 | lcd_printp (PSTR("\r\n\nERROR: no data"), 0); |
||
145 | } |
||
146 | mode = 0; |
||
147 | rxd_buffer_locked = FALSE; |
||
148 | |||
149 | timer = 200; |
||
150 | while (timer > 0); |
||
151 | #endif |
||
152 | for (;;) |
||
153 | { |
||
154 | main_menu (); |
||
155 | } |
||
156 | } |