0,0 → 1,172 |
/***************************************************************************** |
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de * |
* Copyright (C) 2009-2010 Peter "woggle" Mack, mac@denich.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 "main.h" |
#include "lcd.h" |
#include "usart.h" |
#include "parameter.h" |
#include "menu.h" |
#include "display.h" |
#include "timer.h" |
#include "jeti.h" |
#include "lipo.h" |
#include "eeprom.h" |
|
#include "mk-data-structs.h" |
|
|
#ifndef USE_MMT |
#define LEDS // my development board has some status LEDs |
#endif |
|
//#define MTEST // Menu Test (skip FC/NC detection) |
|
|
Version_t *version; |
|
volatile uint8_t mode = 0; |
|
uint8_t hardware = 0; |
uint8_t current_hardware = 0; |
|
|
int main (void) |
{ |
uint8_t timeout; |
|
PORTA = 0xF0; |
PORTB = 0x43; |
#if defined (__AVR_ATmega32__) |
PORTC = 0xFC; |
#else |
PORTC = 0xFF; |
#endif |
PORTD = 0x70; |
|
#ifdef LEDS |
DDRC = 0x1C; |
DDRD = 0xF0; |
#else |
#if defined (__AVR_ATmega32__) |
DDRC = 0x03; |
#endif |
DDRD = 0x80; |
#endif |
|
ReadParameter (); |
|
LCD_Init (); |
USART_Init (); |
TIMER0_Init (); |
#ifndef USE_MMT |
JETI_Init(); |
ADC_Init(); |
#endif |
|
sei (); |
#ifndef MTEST |
lcd_cls (); |
#ifdef USE_MMT |
lcd_printp (PSTR("Portable Kopter Tool\r\n"), 0); |
#else |
lcd_printp (PSTR("MK Multi Box\r\n"), 0); |
#endif |
lcd_printp (PSTR("checking hardware..."), 0); |
|
// switch to NC |
USART_putc (0x1b); |
USART_putc (0x1b); |
USART_putc (0x55); |
USART_putc (0xaa); |
USART_putc (0x00); |
|
mode = 'V'; |
timeout = 50; |
while (!rxd_buffer_locked && timeout) |
{ |
SendOutData('v', ADDRESS_ANY, 0); |
timer = 20; |
while (timer > 0); |
timeout--; |
} |
if (timeout != 0) |
{ |
Decode64 (); |
version = (Version_t *) pRxData; |
|
lcd_cls (); |
#ifdef USE_MMT |
lcd_printp (PSTR("Portable Kopter Tool\r\n"), 0); |
#else |
lcd_printp (PSTR("MK Multi Box\r\n"), 0); |
#endif |
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 |
{ // timeout occured |
lcd_printp (PSTR("\r\n\nERROR: no data"), 0); |
} |
mode = 0; |
rxd_buffer_locked = FALSE; |
|
timer = 200; |
while (timer > 0); |
#endif |
for (;;) |
{ |
main_menu (); |
} |
} |