Blame |
Last modification |
View Log
| RSS feed
/*****************************************************************************
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de *
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net *
* Copyright (C) 2011 Harald Bongartz *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
* *
* Credits to: *
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN *
* http://www.mikrokopter.de *
* Gregor "killagreg" Stobrawa for his version of the MK code *
* Thomas Kaiser "thkais" for the original project. See *
* http://www.ft-fanpage.de/mikrokopter/ *
* http://forum.mikrokopter.de/topic-4061-1.html *
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code *
* http://www.mylifesucks.de/oss/c-osd/ *
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility*
*****************************************************************************/
#include "cpu.h"
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "lcd/lcd.h"
#include "timer/timer.h"
#include "eeprom/eeprom.h"
#include "messages.h"
#include "lipo/lipo.h"
#include "main.h"
#include "bluetooth/bluetooth.h"
#if defined HWVERSION3_9
//--------------------------------------------------------------
void Change_Output(uint8_t UartMode) // Schaltet die Rx/Tx Richtungen
{
// hiermit werden die 74HTC125 (IC5) Gatter geschaltet
clr_USB2FC(); // PC2 aus
clr_USB2Wi(); // PB0 aus
clr_Uart02FC(); // PC6 aus
clr_Uart02Wi(); // PC5 aus
switch (UartMode)
{
case USB2FC:
UCSR1B &= ~(1<<RXEN1);
UCSR1B &= ~(1<<TXEN1);
UCSR1B &= ~(1<<RXCIE1);
DDRD &= ~(1<<DDD2); // Pins auf Eingang setzen
DDRD &= ~(1<<DDD3);
PORTD &= ~(1<<PD2); // Pullup aus
PORTD &= ~(1<<PD3);
set_USB2FC();
break;
case Uart02Wi:
set_Uart02Wi();
break;
case Uart02FC:
set_Uart02FC();
break;
case USB2Wi:
UCSR1B &= ~(1<<RXEN1);
UCSR1B &= ~(1<<TXEN1);
UCSR1B &= ~(1<<RXCIE1);
DDRD &= ~(1<<DDD2); // Pins auf Eingang setzen
DDRD &= ~(1<<DDD3);
PORTD &= ~(1<<PD2); // Pullup aus
PORTD &= ~(1<<PD3);
set_USB2Wi();
break;
}
}
//--------------------------------------------------------------
// Function: BT2FC()
// Purpose: Connect BT direct to FC-Kabel (SV2 as MKUSB)
// Returns:
//--------------------------------------------------------------
void Port_BT2FC(void)
{
lcd_cls ();
if(Config.UseBT == true)
{
lcd_puts_at(0, 0, strGet(CONNECT14), 2);
lcd_puts_at(0, 1, strGet(CONNECT15), 0);
lcd_puts_at(0, 3, strGet(CONNECT16), 0);
lcd_puts_at(0, 4, strGet(CONNECT17), 0);
lcd_puts_at(0, 5, strGet(CONNECT23), 0);
lcd_printp_at (0, 6, PSTR("Baudrate: "), 0);
show_baudrate (10,6,Config.PKT_Baudrate,0);
lcd_puts_at(12, 7, strGet(ESC), 0);
set_BTOn();
_delay_ms(2000);
if (!Config.BTIsSlave==true) bt_set_mode(BLUETOOTH_SLAVE);
Change_Output(USB2FC);
do
{
show_Lipo();
}
while(!get_key_press (1 << KEY_ESC));
get_key_press(KEY_ALL);
if (Config.U02SV2 == 1)
Change_Output(Uart02FC);
else
Change_Output(Uart02Wi);
set_BTOff();
return;
}
else
{
lcd_puts_at(0, 1, strGet(CONNECT12), 0);
lcd_puts_at(0, 1, strGet(CONNECT13), 0);
lcd_puts_at(0, 2, strGet(CONNECT7), 0);
lcd_puts_at(0, 3, strGet(CONNECT8), 0);
lcd_puts_at(0, 4, strGet(CONNECT9), 0);
lcd_puts_at(12, 7, strGet(ENDE), 0);
// lcd_printp_at (12, 7, PSTR("Ende"), 0);
while(!get_key_press (1 << KEY_ESC));
get_key_press(KEY_ALL);
return;
}
}
//--------------------------------------------------------------
// Function: BT2Wi()
// Purpose: Connect BT direct to Wi.232
// Returns:
//--------------------------------------------------------------
void Port_BT2Wi(void)
{
lcd_cls ();
lcd_puts_at(0, 0, strGet(CONNECT14), 2);
lcd_puts_at(0, 1, strGet(CONNECT18), 2);
lcd_printp_at (5, 2, PSTR("RE-ID: "), 0);
for (uint8_t i = 0; i < RE_ID_length; i++)
{
lcd_putc (12+i,2, Config.RE_ID[i], 0);
}
lcd_puts_at(0, 3, strGet(CONNECT16), 0);
lcd_puts_at(0, 4, strGet(CONNECT19), 0);
lcd_puts_at(0, 5, strGet(CONNECT23), 0);
lcd_printp_at (0, 6, PSTR("Baudrate: "), 0);
show_baudrate (10,6,Config.PKT_Baudrate,0);
lcd_puts_at(12, 7, strGet(ESC), 0);
set_BTOn();
_delay_ms(2000);
if (!Config.BTIsSlave==true) bt_set_mode(BLUETOOTH_SLAVE);
Change_Output(USB2Wi);
do
{
show_Lipo();
}
while(!get_key_press (1 << KEY_ESC));
get_key_press(KEY_ALL);
if (Config.U02SV2 == 1)
Change_Output(Uart02FC);
else
Change_Output(Uart02Wi);
set_BTOff();
return;
}
//--------------------------------------------------------------
// Function: FC2CFG_BT()
// Purpose: Connect FC (Tx1 Pin3, Rx1 Pin4) direct to BT
// Returns:
//--------------------------------------------------------------
void Port_FC2CFG_BT(void)
{
lcd_cls ();
lcd_printp_at (0, 0, PSTR("BTM-222 Konfigurieren"), 2);
lcd_printp_at (0, 1, PSTR("FC > MK-USB > BTM-222"), 2);
lcd_printp_at (0, 3, PSTR("MK-USB an PC anschl. "), 0);
lcd_printp_at (0, 4, PSTR("Zwischen MK-USB und "), 0);
lcd_printp_at (0, 5, PSTR("PKT ein gekreuztes "), 0);
lcd_printp_at (0, 6, PSTR("Kabel anschliessen. "), 0);
lcd_puts_at(12, 7, strGet(ESC), 0);
set_BTOn();
Change_Output(USB2FC);
while(!get_key_press (1 << KEY_ESC));
get_key_press(KEY_ALL);
if (Config.U02SV2 == 1)
Change_Output(Uart02FC);
else
Change_Output(Uart02Wi);
set_BTOff();
return;
}
//--------------------------------------------------------------
// Function: USB2FC()
// Purpose: Connect USB direct to FC-Kabel (SV2 as MKUSB)
// Returns:
//--------------------------------------------------------------
void Port_USB2FC(void)
{
lcd_cls ();
lcd_puts_at(0, 0, strGet(CONNECT14), 2);
lcd_puts_at(0, 1, strGet(CONNECT20), 0);
lcd_puts_at(0, 3, strGet(CONNECT21), 0);
lcd_puts_at(0, 4, strGet(CONNECT17), 0);
lcd_puts_at(0, 5, strGet(CONNECT23), 0);
lcd_puts_at(12, 7, strGet(ESC), 0);
Change_Output(USB2FC);
do
{
show_Lipo();
}
while(!get_key_press (1 << KEY_ESC));
get_key_press(KEY_ALL);
if (Config.U02SV2 == 1)
Change_Output(Uart02FC);
else
Change_Output(Uart02Wi);
return;
}
//--------------------------------------------------------------
// Function: USB2Wi()
// Purpose: Connect USB direct to Wi.232
// Returns:
//--------------------------------------------------------------
void Port_USB2Wi(void)
{
lcd_cls ();
lcd_puts_at(0, 0, strGet(CONNECT14), 2);
lcd_puts_at(0, 1, strGet(CONNECT22), 2);
lcd_puts_at(0, 3, strGet(CONNECT21), 0);
lcd_puts_at(0, 4, strGet(CONNECT19), 0);
lcd_puts_at(0, 5, strGet(CONNECT23), 0);
lcd_printp_at (0, 6, PSTR("Baudrate: "), 0);
show_baudrate (10,6,Config.PKT_Baudrate,0);
lcd_puts_at(12, 7, strGet(ESC), 0);
Change_Output(USB2Wi);
do
{
show_Lipo();
}
while(!get_key_press (1 << KEY_ESC));
get_key_press(KEY_ALL);
if (Config.U02SV2 == 1)
Change_Output(Uart02FC);
else
Change_Output(Uart02Wi);
return;
}
//--------------------------------------------------------------
// Function: USB2CFG_Wi()
// Purpose: Connect USB direct to Wi.232 in Progmode
// Returns:
//--------------------------------------------------------------
void Port_USB2CFG_Wi(void)
{
lcd_cls ();
lcd_puts_at(0, 0, strGet(CONNECT24), 2);
lcd_puts_at(0, 1, strGet(CONNECT22), 2);
lcd_puts_at(0, 3, strGet(CONNECT21), 0);
lcd_printp_at (0, 4, PSTR("Radiotronix Wi.232DTS"), 0);
lcd_printp_at (0, 5, PSTR("Evaluation (868MHz) "), 0);
lcd_puts_at(0, 6, strGet(CONNECT25), 0);
lcd_puts_at(12, 7, strGet(ESC), 0);
Change_Output(USB2Wi);
set_WI232CMD(); // Port D6 = CMD
while(!get_key_press (1 << KEY_ESC));
get_key_press(KEY_ALL);
clr_WI232CMD(); // Port D6 = CMD
if (Config.U02SV2 == 1)
Change_Output(Uart02FC);
else
Change_Output(Uart02Wi);
return;
}
#endif