Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1470 - 1
/*****************************************************************************
2
 *   Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de                  *
3
 *   Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net                  *
4
 *   Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net *
5
 *   Copyright (C) 2011 Harald Bongartz                                      *
6
 *                                                                           *
7
 *   This program is free software; you can redistribute it and/or modify    *
8
 *   it under the terms of the GNU General Public License as published by    *
9
 *   the Free Software Foundation; either version 2 of the License.          *
10
 *                                                                           *
11
 *   This program is distributed in the hope that it will be useful,         *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
14
 *   GNU General Public License for more details.                            *
15
 *                                                                           *
16
 *   You should have received a copy of the GNU General Public License       *
17
 *   along with this program; if not, write to the                           *
18
 *   Free Software Foundation, Inc.,                                         *
19
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               *
20
 *                                                                           *
21
 *                                                                           *
22
 *   Credits to:                                                             *
23
 *   Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN  *
24
 *                          http://www.mikrokopter.de                        *
25
 *   Gregor "killagreg" Stobrawa for his version of the MK code              *
26
 *   Thomas Kaiser "thkais" for the original project. See                    *
27
 *                          http://www.ft-fanpage.de/mikrokopter/            *
28
 *                          http://forum.mikrokopter.de/topic-4061-1.html    *
29
 *   Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code *
30
 *                          http://www.mylifesucks.de/oss/c-osd/             *
31
 *   Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility*
32
 *****************************************************************************/
33
 
34
 
35
#ifndef HAL_HW3_9_C_
36
#define HAL_HW3_9_C_
37
 
38
#include "cpu.h"
39
#include <inttypes.h>
40
#include <avr/io.h>
41
#include <avr/interrupt.h>
42
#include <avr/pgmspace.h>
43
#include <avr/eeprom.h>
44
#include <util/delay.h>
45
#include <stdbool.h>
46
#include "main.h"
47
#if defined HWVERSION3_9
48
#include "messages.h"
49
#include "lcd.h"
50
#include "usart.h"
51
#include "uart1.h"
52
#include "display.h"
53
#include "timer.h"
54
#include "eeprom.h"
55
#include "Wi232.h"
56
#include "twimaster.h"
57
#include "uart1.h"
58
#include "bluetooth.h"
59
#include "error.h"
60
#include "connect.h"
61
#include "lipo.h"
62
#include "setup.h"
63
 
64
 
65
volatile uint8_t USBBT;
66
volatile uint8_t U02SV2;
67
 
68
 
69
//--------------------------------------------------------------
70
void InitHWPorts(void)  // Initialisierung der Hardware für die jeweilige Leiterplattenversion
71
 
72
{
73
        PORTA |= (1<<PORTA4)|(1<<PORTA5)|(1<<PORTA6)|(1<<PORTA7);       // Enable Pull Up for the 4 keys
74
        DDRA &= ~(1<<DDA4);                                                                                     // Eingang: A4 auf Low setzen (Power On)
75
 
76
        DDRB = 0xFF;                                                                                            // Alles Ausgänge
77
 
78
        PORTC |= (1<<PORTC4)|(1<<PORTC7);                                                       // Enable Pull Up for LBO + Summer
79
        DDRC |= (1<<DDC2)|(1<<DDC3)|(1<<DDC5)|(1<<DDC6)|(1<<DDC7);      // Ausgang: Led2,Rs232Switch,Summer
80
        DDRC &= ~(1<<DDC4);                                                                                     // Eingang: LowBat LTC1308
81
        set_BTOn();                                                     // Erstmal USB dektivieren, damit beim versehentlichen Einschalten USB im PC ruhig bleibt
82
 
83
        PORTD |= (1<<PORTD6);                                                                           // Wi232-CMD auf High schalten
84
        DDRD |= (1<<DDD4)|(1<<DDD5)|(1<<DDD6)|(1<<DDD7);                        // Ausgang: PiepserTest, Servo, Wi232-CMD und Beleuchtung
85
 
86
        set_V_On();                     // Spannung mit T3 halten
87
 
88
        Timer0_Init ();         // system
89
        Timer1_Init ();         // pwm
90
        Timer2_Init ();         // display
91
 
92
 
93
        Display_on = 1;
94
        USART_Init (UART_BAUD_SELECT(USART_BAUD,F_CPU));
95
        uart1_init (UART_BAUD_SELECT(USART_BAUD,F_CPU));        // USB
96
        I2C_Init(1);
97
 
98
 
99
        sei ();
100
 
101
        LCD_Init (0);           // muss vor "ReadParameter" stehen
102
        ReadParameter ();       // Aktuelle Werte aus EEProm auslesen
103
 
104
        if (DisplayLanguage > NUM_LANG)    // Beim ersten Start Sprache abfragen
105
          { DisplayLanguage = 1;
106
            DisplayLanguage = Edit_Language(DisplayLanguage,0,3,DISPLAY3);
107
            WriteParameter();
108
          }
109
 
110
 
111
        OCR2A = LCD_Helligkeit * 2.55;
112
        LCD_Init (1);
113
        BeepTime = 200;
114
        BeepMuster = 0x0080;
115
        ADC_Init();             // ADC für Lipomessung
116
        // Power On Delay
117
//      lcd_printp_at (2,2,PSTR("Taste 1 Sekunde"), 0);
118
//      lcd_printp_at (2,3,PSTR("lang festhalten."), 0);
119
 
120
         lcd_puts_at(0, 2, strGet(BOOT1), 0);
121
         lcd_puts_at(0, 3, strGet(BOOT2), 0);
122
 
123
        _delay_ms(800);
124
 
125
        if (PINA & (1<<PINA7))    // Spannung eingeschaltet lassen
126
                clr_V_On();
127
 
128
        _delay_ms(100);
129
        BeepTime = 500;
130
        BeepMuster = 0x0080;
131
        get_key_press(KEY_ALL);
132
 
133
        lcd_cls();
134
 
135
        if ((UseWi == true) && (WiIsSet == false))
136
        {
137
                InitWi232();    // wenn Wi232 nicht initialisiert ist, dann jetzt tun
138
        }
139
 
140
        lcd_cls();
141
        set_USBOn();                                            // USB erstmal wieder einschalten
142
        if ((UseBT == true) && (BTIsSet == false))
143
        {
144
                bt_init();
145
                set_USBOn();
146
        }
147
 
148
        lcd_cls();
149
 
150
        if ((UseWi == true) && (U02SV2 == 0))
151
        {
152
                Change_Output(Uart02Wi);    // Verbindung zu Wi232 herstellen
153
                if (PKT_StartInfo == true)
154
                {
155
//                      lcd_printp_at (0, 0, PSTR("Verbindung zum MK ist"), 0);
156
//                      lcd_printp_at (0, 1, PSTR("auf Wi232 eingestellt"), 0);
157
                         lcd_puts_at(0, 0, strGet(BOOT_WI1), 0);
158
                         lcd_puts_at(0, 1, strGet(BOOT_WI2), 0);
159
                        _delay_ms(2000);
160
                }
161
        }
162
        else
163
        {
164
                Change_Output(Uart02FC);    // Verbindung zu SV" (Kabel) herstellen
165
                if (PKT_StartInfo == true)
166
                {
167
//                      lcd_printp_at (0, 0, PSTR("Verbindung zum MK ist"), 0);
168
//                      lcd_printp_at (0, 1, PSTR("auf Kabel eingestellt"), 0);
169
                         lcd_puts_at(0, 0, strGet(BOOT_WI1), 0);
170
                         lcd_puts_at(0, 1, strGet(BOOT_SV), 0);
171
                        _delay_ms(2000);
172
                }
173
        }
174
 
175
        lcd_cls();
176
 
177
}
178
 
179
 
180
 
181
void set_D_LIGHT(void)  /* Displaybeleuchtung ein*/
182
        {
183
          // PWM einschalten
184
          TCCR2A |= (1 << WGM21)  | (1 << WGM20)  | (1 << COM2A1);
185
          TCCR2B |= (1 << CS20);
186
        }
187
 
188
void clr_D_LIGHT(void)  /* Displaybeleuchtung aus*/
189
        {
190
          // PWM ausschalten
191
          TCCR2A = 0;
192
          TCCR2B = 0;
193
        }
194
 
195
#endif
196
#endif // HAL_HW3_9_C_