Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 1070 → Rev 1071

/Transportables_Koptertool/tags/V3.2/main.c
0,0 → 1,282
/*****************************************************************************
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de *
* Copyright (C) 2009-2010 Peter "woggle" Mack, mac@denich.net *
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net *
* *
* 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/ *
*****************************************************************************/
 
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <util/delay.h>
#include <avr/wdt.h>
 
/* Watchdog integrieren und abschalten, wird für Bootloader benötigt*/
void wdt_init(void) __attribute__((naked)) __attribute__((section(".init1")));
 
void wdt_init(void)
{
MCUSR = 0;
wdt_disable();
 
return;
}
 
#include "main.h"
#include "lcd.h"
#include "usart.h"
#include "uart1.h"
#include "mk-data-structs.h"
#include "parameter.h"
#include "menu.h"
#include "display.h"
#include "timer.h"
#include "eeprom.h"
#include "Wi232.h"
 
#if defined HWVERSION3_1 || defined HWVERSION1_3
#include "motortestI2C.h"
#endif
 
 
 
#define MTEST 1 // Menu Test (skip FC/NC detection)
 
Version_t *version;
 
volatile uint8_t mode = 0;
 
uint8_t hardware = 0;
uint8_t current_hardware = 0;
//uint8_t no_hardware = 0;
 
mk_param_struct_t *mk_param_struct;
 
 
int main (void)
{
uint8_t timeout;
uint8_t val =0;
 
// enable pull ups for the 4 keys
PORTA |= (1<<PORTA4)|(1<<PORTA5)|(1<<PORTA6)|(1<<PORTA7);
 
 
#ifdef HWVERSION1_2
DDRC |= (1<<DDC0)|(1<<DDC1);
DDRD |= (1<<DDD7);
DDRB = 0xFF;
#endif
#ifdef HWVERSION1_3
DDRC |= (1<<DDC2);
DDRD |= (1<<DDD6) |(1<<DDD7);
DDRB = 0xFF;
#endif
 
#ifdef HWVERSION3_1
 
DDRD |= (1<<DDD7)|(1<<DDD6);
 
DDRC = 0xFF;
DDRB = 0xFF;
set_LED1();
set_LED2();
set_LED3();
set_LED4();
set_BEEP();
set_D_LIGHT();
clr_WI232CMD();
_delay_ms(250);
 
clr_LED1();
clr_LED2();
clr_LED3();
clr_LED4();
clr_BEEP();
 
 
#endif
 
Display_on = 1;
 
LCD_Init ();
USART_Init (UART_BAUD_SELECT(USART_BAUD,F_CPU));
 
 
 
#if defined HWVERSION3_1 || defined HWVERSION1_3
 
uart1_init (UART_BAUD_SELECT(USART_BAUD,F_CPU)); /* USB*/
uart1_putc('R');
I2C_Init();
#endif
 
 
TIMER0_Init ();
TIMER1_Init (); // pwm
 
sei ();
 
#ifdef HWVERSION3_1
InitWi232();
_delay_ms(2000);
hardware = NO;
current_hardware = 0;
#endif
 
ReadParameter ();
 
// switch to NC
USART_putc (0x1b);
USART_putc (0x1b);
USART_putc (0x55);
USART_putc (0xaa);
USART_putc (0x00);
 
mode = 'V';
#if MTEST
do
{
timeout = 50;
lcd_cls ();
lcd_printpns_at (0,0,PSTR("Portables Koptertool"), 0);
lcd_printpns_at (0,1,PSTR("for FC V "), 0);
lcd_printpns_at (10,1,PSTR(FC_Version),0);
lcd_printpns_at (0,2,PSTR("GNU GPL License"), 0);
lcd_printpns_at (0,3,PSTR("checking hardware..."), 0);
lcd_printpns_at (0, 7, PSTR("Skip FC-Check"), 0);
 
 
 
while (!rxd_buffer_locked && timeout)
 
{
 
SendOutData('v', ADDRESS_ANY, 0);
timer = 20;
while (timer > 0);
timeout--;
 
if (get_key_press (1 << KEY_MINUS))
{
for (;;)
{
hardware = NO;
main_menu ();
}
}
 
//#ifdef HWVERSION1_3
// debug1();
//#endif
}
if(timeout == 0)
{
lcd_printpns_at (0,4,PSTR("ERROR:"), 0);
lcd_printpns_at (0,5,PSTR("no hardware detected"), 0);
timer = 90;
//#ifdef HWVERSION1_3
// debug1();
//#endif
while (timer > 0);
}
}
 
 
 
while(timeout == 0);
 
Decode64 ();
version = (Version_t *) pRxData;
 
lcd_cls ();
lcd_printp (PSTR("PMK-Tool GNU GPL\r\n"), 0);
lcd_printp (PSTR("found:\r\n\n"), 0);
if ((rxd_buffer[1] - 'a') == ADDRESS_FC)
{
lcd_printp (PSTR("Flight-Ctrl\r\n"), 0);
hardware = FC;
current_hardware = hardware;
}
else if ((rxd_buffer[1] - 'a') == ADDRESS_NC)
{
lcd_printp (PSTR("Navi-Ctrl\r\n"), 0);
hardware = NC;
current_hardware = hardware;
}
lcd_printp (PSTR("Version: "), 0);
lcd_write_number_u (version->SWMajor);
lcd_printp (PSTR("."), 0);
lcd_write_number_u (version->SWMinor);
lcd_putc (lcd_xpos, lcd_ypos, version->SWPatch + 'a', 0);
#else
lcd_cls ();
lcd_printp (PSTR("PKT-Test\r\n"), 0);
 
#endif
 
timer = 50;
while (timer > 0);
SwitchToFC();
//Delay
timer = 50;
while (timer > 0);
#if MTEST
// EEprom Version / Struktur prüfen
val = load_setting(1); //Parameterset 1 holen
if (mk_param_struct->Revision != EEProm_Version)
{
lcd_cls ();
lcd_printp (PSTR("EEPromRev."), 0);
lcd_write_number_u (EEProm_Version);
lcd_printp (PSTR(" erwartet\r\n"), 0);
lcd_printp (PSTR("EEPromRev."), 0);
lcd_write_number_u (mk_param_struct->Revision);
lcd_printp (PSTR(" gefunden\r\n"), 0);
lcd_printp (PSTR("PMK-Tool nur mit\r\n"), 0);
lcd_printp (PSTR("FC Software "), 0);
lcd_printp (PSTR(FC_Version),0);
lcd_printp (PSTR("\r\nkompatibel"), 0);
while (mk_param_struct->Revision != EEProm_Version);
}
 
#endif
mode = 0;
rxd_buffer_locked = FALSE;
 
timer = 200;
while (timer > 0);
for (;;)
{
main_menu ();
}
}