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 "messages.h"
#include "lcd.h"
#include "usart.h"
#include "uart1.h"
#include "display.h"
#include "timer.h"
#include "eeprom.h"
#include "Wi232.h"
#include "twimaster.h"
#include "uart1.h"
#include "bluetooth.h"
#include "error.h"
#include "connect.h"
#include "lipo.h"
#include "setup.h"
#include "osd.h"
volatile uint8_t USBBT;
volatile uint8_t U02SV2;
//--------------------------------------------------------------
void InitHWPorts(void) // Initialisierung der Hardware für die jeweilige Leiterplattenversion
{
//PORTA |= (1<<PORTA4)|(1<<PORTA5)|(1<<PORTA6)|(1<<PORTA7); // Enable Pull Up for the 4 keys // MartinR: so war es
PORTA |= (1<<PORTA3)|(1<<PORTA4)|(1<<PORTA5)|(1<<PORTA6)|(1<<PORTA7); // Enable Pull Up for the 4 keys // MartinR: Port3: Taster von Joystick
DDRA &= ~(1<<DDA4); // Eingang: A4 auf Low setzen (Power On)
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
Timer1_Init (); // pwm
Timer2_Init (); // display
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);
sei ();
LCD_Init (0); // muss vor "ReadParameter" stehen
ReadParameter (); // Aktuelle Werte aus EEProm auslesen
if (DisplayLanguage > NUM_LANG) // Beim ersten Start Sprache abfragen
{ DisplayLanguage = 1;
DisplayLanguage = Edit_Language(DisplayLanguage,0,3,DISPLAY3);
WriteParameter();
}
OCR2A = LCD_Helligkeit * 2.55;
LCD_Init (1);
set_beep ( 200, 0x0080, BeepNormal);
OSD_active = false; //keine OSD Ausgabe
// MartinR: zu menue.c hin verschoben
// ADC_Init(); // ADC für Lipomessung
// Power On Delay
// lcd_printp_at (2,2,PSTR("Taste 1 Sekunde"), 0);
// lcd_printp_at (2,3,PSTR("lang festhalten."), 0);
lcd_printpj_at (4, 1, PSTR("PKT 3.9"),0);
lcd_printpj_at (4, 2, PSTR(PKTSWVersion),0);
lcd_puts_at(0, 4, strGet(BOOT1), 0);
lcd_puts_at(0, 5, strGet(BOOT2), 0);
_delay_ms(800);
if (PINA & (1<<PINA7)) // Spannung eingeschaltet lassen
clr_V_On();
_delay_ms(100);
set_beep ( 500, 0x0080, BeepNormal);
get_key_press(KEY_ALL);
lcd_cls();
if ((UseWi == true) && (WiIsSet == false))
{
InitWi232(PKT_Baudrate); // wenn Wi232 nicht initialisiert ist, dann jetzt tun
}
lcd_cls();
set_BTOff(); // BT ausschalten
if ((UseBT == true) && (BTIsSet == false))
{
bt_init();
// set_USBOn();
}
lcd_cls();
if ((UseWi == true) && (U02SV2 == 0))
{
Change_Output(Uart02Wi); // Verbindung zu Wi232 herstellen
if (PKT_StartInfo == true)
{
// lcd_printp_at (0, 0, PSTR("Verbindung zum MK ist"), 0);
// lcd_printp_at (0, 1, PSTR("auf Wi232 eingestellt"), 0);
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 (PKT_StartInfo == true)
{
// lcd_printp_at (0, 0, PSTR("Verbindung zum MK ist"), 0);
// lcd_printp_at (0, 1, PSTR("auf Kabel eingestellt"), 0);
lcd_puts_at(0, 0, strGet(BOOT_WI1), 0);
lcd_puts_at(0, 1, strGet(BOOT_SV), 0);
_delay_ms(2000);
}
}
lcd_cls();
}
void set_D_LIGHT(void) /* Displaybeleuchtung ein*/
{
// PWM einschalten
TCCR2A |= (1 << WGM21) | (1 << WGM20) | (1 << COM2A1);
TCCR2B |= (1 << CS20);
}
void clr_D_LIGHT(void) /* Displaybeleuchtung aus*/
{
// PWM ausschalten
TCCR2A = 0;
TCCR2B = 0;
}
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_