Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1932 | - | 1 | /***************************************************************************** |
2 | * Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
||
3 | * Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net * |
||
4 | * Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net * |
||
5 | * Copyright (C) 2011 Harald Bongartz * |
||
6 | * * |
||
7 | * This program is free software; you can redistribute it and/or modify * |
||
8 | * it under the terms of the GNU General Public License as published by * |
||
9 | * the Free Software Foundation; either version 2 of the License. * |
||
10 | * * |
||
11 | * This program is distributed in the hope that it will be useful, * |
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
14 | * GNU General Public License for more details. * |
||
15 | * * |
||
16 | * You should have received a copy of the GNU General Public License * |
||
17 | * along with this program; if not, write to the * |
||
18 | * Free Software Foundation, Inc., * |
||
19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||
20 | * * |
||
21 | * * |
||
22 | * Credits to: * |
||
23 | * Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN * |
||
24 | * http://www.mikrokopter.de * |
||
25 | * Gregor "killagreg" Stobrawa for his version of the MK code * |
||
26 | * Thomas Kaiser "thkais" for the original project. See * |
||
27 | * http://www.ft-fanpage.de/mikrokopter/ * |
||
28 | * http://forum.mikrokopter.de/topic-4061-1.html * |
||
29 | * Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code * |
||
30 | * http://www.mylifesucks.de/oss/c-osd/ * |
||
31 | * Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility* |
||
32 | *****************************************************************************/ |
||
33 | |||
34 | |||
35 | #include "cpu.h" |
||
36 | #include <avr/pgmspace.h> |
||
37 | #include <util/delay.h> |
||
38 | #include "lcd/lcd.h" |
||
39 | #include "timer/timer.h" |
||
40 | #include "eeprom/eeprom.h" |
||
41 | #include "messages.h" |
||
42 | #include "lipo/lipo.h" |
||
43 | #include "main.h" |
||
44 | #include "bluetooth/bluetooth.h" |
||
45 | |||
46 | #if defined HWVERSION3_9 |
||
47 | //-------------------------------------------------------------- |
||
48 | void Change_Output(uint8_t UartMode) // Schaltet die Rx/Tx Richtungen |
||
49 | { |
||
50 | // hiermit werden die 74HTC125 (IC5) Gatter geschaltet |
||
51 | clr_USB2FC(); // PC2 aus |
||
52 | clr_USB2Wi(); // PB0 aus |
||
53 | clr_Uart02FC(); // PC6 aus |
||
54 | clr_Uart02Wi(); // PC5 aus |
||
55 | |||
56 | |||
57 | switch (UartMode) |
||
58 | { |
||
59 | case USB2FC: |
||
60 | UCSR1B &= ~(1<<RXEN1); |
||
61 | UCSR1B &= ~(1<<TXEN1); |
||
62 | UCSR1B &= ~(1<<RXCIE1); |
||
63 | |||
64 | DDRD &= ~(1<<DDD2); // Pins auf Eingang setzen |
||
65 | DDRD &= ~(1<<DDD3); |
||
66 | PORTD &= ~(1<<PD2); // Pullup aus |
||
67 | PORTD &= ~(1<<PD3); |
||
68 | |||
69 | set_USB2FC(); |
||
70 | break; |
||
71 | |||
72 | case Uart02Wi: |
||
73 | set_Uart02Wi(); |
||
74 | break; |
||
75 | |||
76 | case Uart02FC: |
||
77 | set_Uart02FC(); |
||
78 | break; |
||
79 | |||
80 | case USB2Wi: |
||
81 | UCSR1B &= ~(1<<RXEN1); |
||
82 | UCSR1B &= ~(1<<TXEN1); |
||
83 | UCSR1B &= ~(1<<RXCIE1); |
||
84 | |||
85 | DDRD &= ~(1<<DDD2); // Pins auf Eingang setzen |
||
86 | DDRD &= ~(1<<DDD3); |
||
87 | PORTD &= ~(1<<PD2); // Pullup aus |
||
88 | PORTD &= ~(1<<PD3); |
||
89 | |||
90 | set_USB2Wi(); |
||
91 | break; |
||
92 | } |
||
93 | |||
94 | } |
||
95 | |||
96 | |||
97 | //-------------------------------------------------------------- |
||
98 | // Function: BT2FC() |
||
99 | // Purpose: Connect BT direct to FC-Kabel (SV2 as MKUSB) |
||
100 | // Returns: |
||
101 | //-------------------------------------------------------------- |
||
102 | void Port_BT2FC(void) |
||
103 | { |
||
104 | lcd_cls (); |
||
105 | |||
106 | if(Config.UseBT == true) |
||
107 | { |
||
108 | |||
109 | lcd_puts_at(0, 0, strGet(CONNECT14), 2); |
||
110 | lcd_puts_at(0, 1, strGet(CONNECT15), 0); |
||
111 | lcd_puts_at(0, 3, strGet(CONNECT16), 0); |
||
112 | lcd_puts_at(0, 4, strGet(CONNECT17), 0); |
||
113 | lcd_puts_at(0, 5, strGet(CONNECT23), 0); |
||
114 | lcd_printp_at (0, 6, PSTR("Baudrate: "), 0); |
||
115 | show_baudrate (10,6,Config.PKT_Baudrate,0); |
||
116 | lcd_puts_at(12, 7, strGet(ESC), 0); |
||
117 | set_BTOn(); |
||
118 | _delay_ms(2000); |
||
119 | if (!Config.BTIsSlave==true) bt_set_mode(BLUETOOTH_SLAVE); |
||
120 | Change_Output(USB2FC); |
||
121 | do |
||
122 | { |
||
123 | show_Lipo(); |
||
124 | } |
||
125 | while(!get_key_press (1 << KEY_ESC)); |
||
126 | |||
127 | get_key_press(KEY_ALL); |
||
128 | if (Config.U02SV2 == 1) |
||
129 | Change_Output(Uart02FC); |
||
130 | else |
||
131 | Change_Output(Uart02Wi); |
||
132 | |||
133 | set_BTOff(); |
||
134 | return; |
||
135 | } |
||
136 | else |
||
137 | { |
||
138 | lcd_puts_at(0, 1, strGet(CONNECT12), 0); |
||
139 | lcd_puts_at(0, 1, strGet(CONNECT13), 0); |
||
140 | lcd_puts_at(0, 2, strGet(CONNECT7), 0); |
||
141 | lcd_puts_at(0, 3, strGet(CONNECT8), 0); |
||
142 | lcd_puts_at(0, 4, strGet(CONNECT9), 0); |
||
143 | lcd_puts_at(12, 7, strGet(ENDE), 0); |
||
144 | // lcd_printp_at (12, 7, PSTR("Ende"), 0); |
||
145 | while(!get_key_press (1 << KEY_ESC)); |
||
146 | |||
147 | get_key_press(KEY_ALL); |
||
148 | return; |
||
149 | } |
||
150 | } |
||
151 | |||
152 | |||
153 | //-------------------------------------------------------------- |
||
154 | // Function: BT2Wi() |
||
155 | // Purpose: Connect BT direct to Wi.232 |
||
156 | // Returns: |
||
157 | //-------------------------------------------------------------- |
||
158 | void Port_BT2Wi(void) |
||
159 | { |
||
160 | |||
161 | lcd_cls (); |
||
162 | |||
163 | lcd_puts_at(0, 0, strGet(CONNECT14), 2); |
||
164 | lcd_puts_at(0, 1, strGet(CONNECT18), 2); |
||
165 | lcd_printp_at (5, 2, PSTR("RE-ID: "), 0); |
||
166 | for (uint8_t i = 0; i < RE_ID_length; i++) |
||
167 | { |
||
168 | lcd_putc (12+i,2, Config.RE_ID[i], 0); |
||
169 | |||
170 | } |
||
171 | lcd_puts_at(0, 3, strGet(CONNECT16), 0); |
||
172 | lcd_puts_at(0, 4, strGet(CONNECT19), 0); |
||
173 | lcd_puts_at(0, 5, strGet(CONNECT23), 0); |
||
174 | lcd_printp_at (0, 6, PSTR("Baudrate: "), 0); |
||
175 | show_baudrate (10,6,Config.PKT_Baudrate,0); |
||
176 | lcd_puts_at(12, 7, strGet(ESC), 0); |
||
177 | set_BTOn(); |
||
178 | _delay_ms(2000); |
||
179 | if (!Config.BTIsSlave==true) bt_set_mode(BLUETOOTH_SLAVE); |
||
180 | |||
181 | Change_Output(USB2Wi); |
||
182 | do |
||
183 | { |
||
184 | show_Lipo(); |
||
185 | } |
||
186 | while(!get_key_press (1 << KEY_ESC)); |
||
187 | |||
188 | get_key_press(KEY_ALL); |
||
189 | if (Config.U02SV2 == 1) |
||
190 | Change_Output(Uart02FC); |
||
191 | else |
||
192 | Change_Output(Uart02Wi); |
||
193 | |||
194 | set_BTOff(); |
||
195 | return; |
||
196 | } |
||
197 | |||
198 | |||
199 | //-------------------------------------------------------------- |
||
200 | // Function: FC2CFG_BT() |
||
201 | // Purpose: Connect FC (Tx1 Pin3, Rx1 Pin4) direct to BT |
||
202 | // Returns: |
||
203 | //-------------------------------------------------------------- |
||
204 | void Port_FC2CFG_BT(void) |
||
205 | { |
||
206 | |||
207 | lcd_cls (); |
||
208 | lcd_printp_at (0, 0, PSTR("BTM-222 Konfigurieren"), 2); |
||
209 | lcd_printp_at (0, 1, PSTR("FC > MK-USB > BTM-222"), 2); |
||
210 | lcd_printp_at (0, 3, PSTR("MK-USB an PC anschl. "), 0); |
||
211 | lcd_printp_at (0, 4, PSTR("Zwischen MK-USB und "), 0); |
||
212 | lcd_printp_at (0, 5, PSTR("PKT ein gekreuztes "), 0); |
||
213 | lcd_printp_at (0, 6, PSTR("Kabel anschliessen. "), 0); |
||
214 | lcd_puts_at(12, 7, strGet(ESC), 0); |
||
215 | |||
216 | set_BTOn(); |
||
217 | Change_Output(USB2FC); |
||
218 | |||
219 | while(!get_key_press (1 << KEY_ESC)); |
||
220 | |||
221 | get_key_press(KEY_ALL); |
||
222 | if (Config.U02SV2 == 1) |
||
223 | Change_Output(Uart02FC); |
||
224 | else |
||
225 | Change_Output(Uart02Wi); |
||
226 | |||
227 | set_BTOff(); |
||
228 | return; |
||
229 | } |
||
230 | |||
231 | |||
232 | //-------------------------------------------------------------- |
||
233 | // Function: USB2FC() |
||
234 | // Purpose: Connect USB direct to FC-Kabel (SV2 as MKUSB) |
||
235 | // Returns: |
||
236 | //-------------------------------------------------------------- |
||
237 | void Port_USB2FC(void) |
||
238 | { |
||
239 | lcd_cls (); |
||
240 | lcd_puts_at(0, 0, strGet(CONNECT14), 2); |
||
241 | lcd_puts_at(0, 1, strGet(CONNECT20), 0); |
||
242 | lcd_puts_at(0, 3, strGet(CONNECT21), 0); |
||
243 | lcd_puts_at(0, 4, strGet(CONNECT17), 0); |
||
244 | lcd_puts_at(0, 5, strGet(CONNECT23), 0); |
||
245 | lcd_puts_at(12, 7, strGet(ESC), 0); |
||
246 | Change_Output(USB2FC); |
||
247 | do |
||
248 | { |
||
249 | show_Lipo(); |
||
250 | } |
||
251 | while(!get_key_press (1 << KEY_ESC)); |
||
252 | |||
253 | get_key_press(KEY_ALL); |
||
254 | if (Config.U02SV2 == 1) |
||
255 | Change_Output(Uart02FC); |
||
256 | else |
||
257 | Change_Output(Uart02Wi); |
||
258 | |||
259 | return; |
||
260 | } |
||
261 | |||
262 | //-------------------------------------------------------------- |
||
263 | // Function: USB2Wi() |
||
264 | // Purpose: Connect USB direct to Wi.232 |
||
265 | // Returns: |
||
266 | //-------------------------------------------------------------- |
||
267 | void Port_USB2Wi(void) |
||
268 | { |
||
269 | |||
270 | lcd_cls (); |
||
271 | lcd_puts_at(0, 0, strGet(CONNECT14), 2); |
||
272 | lcd_puts_at(0, 1, strGet(CONNECT22), 2); |
||
273 | lcd_puts_at(0, 3, strGet(CONNECT21), 0); |
||
274 | lcd_puts_at(0, 4, strGet(CONNECT19), 0); |
||
275 | lcd_puts_at(0, 5, strGet(CONNECT23), 0); |
||
276 | lcd_printp_at (0, 6, PSTR("Baudrate: "), 0); |
||
277 | show_baudrate (10,6,Config.PKT_Baudrate,0); |
||
278 | lcd_puts_at(12, 7, strGet(ESC), 0); |
||
279 | |||
280 | Change_Output(USB2Wi); |
||
281 | do |
||
282 | { |
||
283 | show_Lipo(); |
||
284 | } |
||
285 | while(!get_key_press (1 << KEY_ESC)); |
||
286 | |||
287 | get_key_press(KEY_ALL); |
||
288 | if (Config.U02SV2 == 1) |
||
289 | Change_Output(Uart02FC); |
||
290 | else |
||
291 | Change_Output(Uart02Wi); |
||
292 | |||
293 | return; |
||
294 | |||
295 | |||
296 | } |
||
297 | |||
298 | //-------------------------------------------------------------- |
||
299 | // Function: USB2CFG_Wi() |
||
300 | // Purpose: Connect USB direct to Wi.232 in Progmode |
||
301 | // Returns: |
||
302 | //-------------------------------------------------------------- |
||
303 | void Port_USB2CFG_Wi(void) |
||
304 | { |
||
305 | |||
306 | lcd_cls (); |
||
307 | lcd_puts_at(0, 0, strGet(CONNECT24), 2); |
||
308 | lcd_puts_at(0, 1, strGet(CONNECT22), 2); |
||
309 | lcd_puts_at(0, 3, strGet(CONNECT21), 0); |
||
310 | lcd_printp_at (0, 4, PSTR("Radiotronix Wi.232DTS"), 0); |
||
311 | lcd_printp_at (0, 5, PSTR("Evaluation (868MHz) "), 0); |
||
312 | lcd_puts_at(0, 6, strGet(CONNECT25), 0); |
||
313 | lcd_puts_at(12, 7, strGet(ESC), 0); |
||
314 | |||
315 | Change_Output(USB2Wi); |
||
316 | |||
317 | set_WI232CMD(); // Port D6 = CMD |
||
318 | |||
319 | while(!get_key_press (1 << KEY_ESC)); |
||
320 | |||
321 | get_key_press(KEY_ALL); |
||
322 | clr_WI232CMD(); // Port D6 = CMD |
||
323 | |||
324 | if (Config.U02SV2 == 1) |
||
325 | Change_Output(Uart02FC); |
||
326 | else |
||
327 | Change_Output(Uart02Wi); |
||
328 | |||
329 | return; |
||
330 | } |
||
331 | |||
332 | #endif |