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*
*****************************************************************************/
#ifndef HAL_HW3_9_C_
#define HAL_HW3_9_C_
#include "cpu.h"
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <util/delay.h>
#include <stdbool.h>
#include <stdlib.h>
#include "main.h"
#if defined HWVERSION3_9
#include "eeprom/eeprom.h"
#include "messages.h"
#include "lcd/lcd.h"
#include "uart/usart.h"
#include "uart/uart1.h"
#include "display.h"
#include "timer/timer.h"
#include "wi232/Wi232.h"
#include "motortest/twimaster.h"
#include "bluetooth/bluetooth.h"
#include "bluetooth/error.h"
#include "connect.h"
#include "lipo/lipo.h"
#include "setup/setup.h"
#include "osd/osd.h"
#include "sound/pwmsine8bit.h"
#include "tracking/ng_servo.h"
volatile uint8_t USBBT;
volatile uint8_t U02SV2;
volatile uint8_t PCB_Version;
uint8_t PortA;
uint8_t PortB;
uint8_t PortC;
uint8_t PortD;
void CheckPCB(void)
{
DDRA = 0xFF;
DDRB = 0x00;
DDRC = 0x00;
DDRD = 0x00;
PortA = PINA;
PortB = PINB;
PortC = PINC;
PortD = PIND;
if (PINC & (1<<PINC7) ) PCB_Version = PKT39m; else PCB_Version = PKT39x;
}
//--------------------------------------------------------------
void InitHWPorts(void) // Initialisierung der Hardware fÃŒr die jeweilige Leiterplattenversion
{
CheckPCB(); // Version der Leiterplatte prüfen
PORTA |= (1<<PORTA4)|(1<<PORTA5)|(1<<PORTA6)|(1<<PORTA7); // Enable Pull Up for the 4 keys
DDRA &= ~(1<<DDA4); // Eingang: A4 auf Low setzen (Power On)
//DDRA &= ~(1<<DDA1); // Eingang: PKT Lipo Messung // MartinR so war es
if (Config.Lipomessung == true)
{
DDRA &= ~(1<<DDA1); // Eingang: PKT Lipo Messung
PORTA &= ~(1<<PORTA1);
}
DDRB = 0xFF; // Alles AusgÀnge
PORTC |= (1<<PORTC4)|(1<<PORTC7); // Enable Pull Up for LBO + Summer
DDRC |= (1<<DDC2)|(1<<DDC3)|(1<<DDC5)|(1<<DDC6|(1<<DDC7)); // Ausgang: Led2,Rs232Switch,Summer
DDRC &= ~(1<<DDC4); // Eingang: LowBat LTC1308
_BTOn(); // Erstmal USB dektivieren, damit beim versehentlichen Einschalten USB im PC ruhig bleibt
PORTD |= (1<<PORTD6); // Wi232-CMD auf High schalten
DDRD |= (1<<DDD4)|(1<<DDD5)|(1<<DDD6)|(1<<DDD7); // Ausgang: PiepserTest, Servo, Wi232-CMD und Beleuchtung
set_V_On(); // Spannung mit T3 halten
Timer0_Init (); // system
Display_on = 1;
USART_Init (UART_BAUD_SELECT(USART_BAUD,F_CPU));
uart1_init (UART_BAUD_SELECT(USART_BAUD,F_CPU)); // USB
I2C_Init(1);
LCD_Init (0); // muss vor "ReadParameter" stehen
ReadParameter (); // Aktuelle Werte aus EEProm auslesen
servoInit(SERVO_PERIODE);
// servoSetDefaultPos();
sei ();
Old_Baudrate = Config.PKT_Baudrate;
SetBaudUart1(Config.PKT_Baudrate);
SetBaudUart0(Config.PKT_Baudrate);
if (Config.DisplayLanguage > NUM_LANG) // Beim ersten Start Sprache abfragen
{ Config.DisplayLanguage = 1;
Config.DisplayLanguage = Edit_generic(Config.DisplayLanguage,0,3,DISPLAY3,Language);
// WriteParameter();
}
if ((Config.HWSound==0)&&(PCB_Version == PKT39m))
{
Timer2_Init(); // Displaybeleuchtung
OCR2A = Config.LCD_Helligkeit * 2.55;
}
if (Config.HWSound==1) InitSound();
LCD_Init (1);
set_beep ( 400, 0x0080, BeepNormal);
OSD_active = false; //keine OSD Ausgabe
ADC_Init(); // ADC für Lipomessung// MartinR: verschoben
if (PCB_Version==PKT39m)
{
lcd_printp_at (2, 0, PSTR("Hardware PKT 3.9m"),0);
lcd_printp_at (7, 1, PSTR("09.2011"),0);
}
if (PCB_Version==PKT39x)
{
lcd_printp_at (2, 0, PSTR("Hardware PKT 3.9x"),0);
lcd_printp_at (7, 1, PSTR("11.2012"),0);
}
lcd_printp_at (0, 3, PSTR("Software:"),0);
// lcd_printpj_at (8, 3, PSTR(PKTSWVersion),0);
lcd_printp_at (8, 3, PSTR(PKTSWVersion), MBIG);
lcd_puts_at(0, 5, strGet(BOOT1), 0);
lcd_puts_at(0, 6, strGet(BOOT2), 0);
_delay_ms(800);
if (PINA & (1<<PINA7)) // Spannung eingeschaltet lassen
clr_V_On();
_delay_ms(100);
set_beep ( 400, 0x0080, BeepNormal);
get_key_press(KEY_ALL);
if (Config.HWSound==1);
{
playTone(505,100,Config.Volume);
playTone(515,100,Config.Volume);
playTone(525,100,Config.Volume);
playTone(535,100,Config.Volume);
playTone(525,100,Config.Volume);
playTone(515,100,Config.Volume);
playTone(505,100,Config.Volume);
}
lcd_cls();
// servoSetPosition(1,0);
// _delay_ms(250);
// servoSetPosition(0,0);
// _delay_ms(250);
// servoSetPosition(1,400);
// _delay_ms(250);
// servoSetPosition(0,400);
// _delay_ms(250);
// servoSetPosition(1,0);
// _delay_ms(250);
// servoSetPosition(0,0);
// _delay_ms(250);
// servoSetPosition(1,400);
// _delay_ms(250);
// servoSetPosition(0,400);
set_BTOff();
if ((Config.UseWi == true) && (Config.WiIsSet == false))
{
InitWi232(Config.PKT_Baudrate); // wenn Wi232 nicht initialisiert ist, dann jetzt tun
}
lcd_cls();
// BT ausschalten
if ((Config.UseBT == true) && (Config.BTIsSet == false))
{
bt_init();
// set_USBOn();
}
bt_start();
lcd_cls();
if ((Config.UseWi == true) && (U02SV2 == 0))
{
Change_Output(Uart02Wi); // Verbindung zu Wi232 herstellen
if (Config.PKT_StartInfo == true)
{
lcd_puts_at(0, 0, strGet(BOOT_WI1), 0);
lcd_puts_at(0, 1, strGet(BOOT_WI2), 0);
_delay_ms(2000);
}
}
else
{
Change_Output(Uart02FC); // Verbindung zu SV" (Kabel) herstellen
if (Config.PKT_StartInfo == true)
{
lcd_puts_at(0, 0, strGet(BOOT_WI1), 0);
lcd_puts_at(0, 1, strGet(BOOT_SV), 0);
_delay_ms(2000);
}
}
lcd_cls();
}
//#define set_BEEP() (PORTC &= ~(1 << Summer)) // Summer
//#define clr_BEEP() (PORTC |= (1 << Summer))
void set_BEEP(void)
{
if (PCB_Version == PKT39m)
PORTC &= ~(1 << Summer); // Summer
if (PCB_Version == PKT39x)
PORTD &= ~(1 << SummerV2); // Summer
}
void clr_BEEP(void)
{
if (PCB_Version == PKT39m)
PORTC |= (1 << Summer); // Summer
if (PCB_Version == PKT39x)
PORTD |= (1 << SummerV2); // Summer
}
void set_D_LIGHT(void) /* Displaybeleuchtung ein*/
{
if (PCB_Version == PKT39m)
{
if (Config.HWSound==0)
{
// PWM einschalten
TCCR2A |= (1 << WGM21) | (1 << WGM20) | (1 << COM2A1);
TCCR2B |= (1 << CS20);
}
else
clr_DISPLAYLIGHT();
}
if (PCB_Version == PKT39x)
{
// if (HWSound==0)
// {
// // PWM einschalten
// TCCR2A |= (1 << WGM21) | (1 << WGM20) | (1 << COM2A1);
// TCCR2B |= (1 << CS20);
// }
// else
clr_DISPLAYLIGHTV2();
}
}
void clr_D_LIGHT(void) /* Displaybeleuchtung aus*/
{
if (PCB_Version == PKT39m)
{
if (Config.HWSound==0)
{
// PWM ausschalten
TCCR2A = 0;
TCCR2B = 0;
}
else
set_DISPLAYLIGHT();
}
if (PCB_Version == PKT39x)
{
// if (HWSound==0)
// {
// // PWM ausschalten
// TCCR2A = 0;
// TCCR2B = 0;
// }
// else
set_DISPLAYLIGHTV2();
}
}
uint8_t BTIsOn=0;
void set_BTOn(void)
{
if (BTIsOn == 0)
{
_BTOn();
BTIsOn = 1;
_delay_ms(2000);
}
}
void set_BTOff(void)
{
set_USBOn();
BTIsOn = 0;
}
#endif
#endif // HAL_HW3_9_C_