Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1734 | - | 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 <stdlib.h> |
||
47 | #include "main.h" |
||
48 | #if defined HWVERSION3_9 |
||
49 | #include "messages.h" |
||
50 | #include "lcd.h" |
||
51 | #include "usart.h" |
||
52 | #include "uart1.h" |
||
53 | #include "display.h" |
||
54 | #include "timer.h" |
||
55 | #include "eeprom.h" |
||
56 | #include "Wi232.h" |
||
57 | #include "twimaster.h" |
||
58 | #include "uart1.h" |
||
59 | #include "bluetooth.h" |
||
60 | #include "error.h" |
||
61 | #include "connect.h" |
||
62 | #include "lipo.h" |
||
63 | #include "setup.h" |
||
64 | #include "osd.h" |
||
65 | |||
66 | |||
67 | volatile uint8_t USBBT; |
||
68 | volatile uint8_t U02SV2; |
||
69 | |||
70 | |||
71 | //-------------------------------------------------------------- |
||
72 | void InitHWPorts(void) // Initialisierung der Hardware für die jeweilige Leiterplattenversion |
||
73 | |||
74 | { |
||
75 | //PORTA |= (1<<PORTA4)|(1<<PORTA5)|(1<<PORTA6)|(1<<PORTA7); // Enable Pull Up for the 4 keys // MartinR: so war es |
||
76 | PORTA |= (1<<PORTA3)|(1<<PORTA4)|(1<<PORTA5)|(1<<PORTA6)|(1<<PORTA7); // Enable Pull Up for the 4 keys // MartinR: Port3: Taster von Joystick |
||
77 | DDRA &= ~(1<<DDA4); // Eingang: A4 auf Low setzen (Power On) |
||
78 | |||
79 | DDRB = 0xFF; // Alles Ausgänge |
||
80 | |||
81 | PORTC |= (1<<PORTC4)|(1<<PORTC7); // Enable Pull Up for LBO + Summer |
||
82 | DDRC |= (1<<DDC2)|(1<<DDC3)|(1<<DDC5)|(1<<DDC6)|(1<<DDC7); // Ausgang: Led2,Rs232Switch,Summer |
||
83 | DDRC &= ~(1<<DDC4); // Eingang: LowBat LTC1308 |
||
84 | _BTOn(); // Erstmal USB dektivieren, damit beim versehentlichen Einschalten USB im PC ruhig bleibt |
||
85 | |||
86 | PORTD |= (1<<PORTD6); // Wi232-CMD auf High schalten |
||
87 | DDRD |= (1<<DDD4)|(1<<DDD5)|(1<<DDD6)|(1<<DDD7); // Ausgang: PiepserTest, Servo, Wi232-CMD und Beleuchtung |
||
88 | |||
89 | set_V_On(); // Spannung mit T3 halten |
||
90 | |||
91 | Timer0_Init (); // system |
||
92 | Timer1_Init (); // pwm |
||
93 | Timer2_Init (); // display |
||
94 | |||
95 | |||
96 | Display_on = 1; |
||
97 | USART_Init (UART_BAUD_SELECT(USART_BAUD,F_CPU)); |
||
98 | uart1_init (UART_BAUD_SELECT(USART_BAUD,F_CPU)); // USB |
||
99 | I2C_Init(1); |
||
100 | |||
101 | |||
102 | sei (); |
||
103 | |||
104 | LCD_Init (0); // muss vor "ReadParameter" stehen |
||
105 | ReadParameter (); // Aktuelle Werte aus EEProm auslesen |
||
106 | |||
107 | if (DisplayLanguage > NUM_LANG) // Beim ersten Start Sprache abfragen |
||
108 | { DisplayLanguage = 1; |
||
109 | DisplayLanguage = Edit_Language(DisplayLanguage,0,3,DISPLAY3); |
||
110 | WriteParameter(); |
||
111 | } |
||
112 | |||
113 | |||
114 | OCR2A = LCD_Helligkeit * 2.55; |
||
115 | LCD_Init (1); |
||
116 | set_beep ( 200, 0x0080, BeepNormal); |
||
117 | |||
118 | OSD_active = false; //keine OSD Ausgabe |
||
119 | // MartinR: zu menue.c hin verschoben |
||
120 | // ADC_Init(); // ADC für Lipomessung |
||
121 | // Power On Delay |
||
122 | // lcd_printp_at (2,2,PSTR("Taste 1 Sekunde"), 0); |
||
123 | // lcd_printp_at (2,3,PSTR("lang festhalten."), 0); |
||
124 | lcd_printpj_at (4, 1, PSTR("PKT 3.9"),0); |
||
125 | lcd_printpj_at (4, 2, PSTR(PKTSWVersion),0); |
||
126 | lcd_puts_at(0, 4, strGet(BOOT1), 0); |
||
127 | lcd_puts_at(0, 5, strGet(BOOT2), 0); |
||
128 | |||
129 | _delay_ms(800); |
||
130 | |||
131 | if (PINA & (1<<PINA7)) // Spannung eingeschaltet lassen |
||
132 | clr_V_On(); |
||
133 | |||
134 | _delay_ms(100); |
||
135 | |||
136 | set_beep ( 500, 0x0080, BeepNormal); |
||
137 | get_key_press(KEY_ALL); |
||
138 | |||
139 | lcd_cls(); |
||
140 | |||
141 | if ((UseWi == true) && (WiIsSet == false)) |
||
142 | { |
||
143 | InitWi232(PKT_Baudrate); // wenn Wi232 nicht initialisiert ist, dann jetzt tun |
||
144 | } |
||
145 | |||
146 | lcd_cls(); |
||
147 | set_BTOff(); // BT ausschalten |
||
148 | if ((UseBT == true) && (BTIsSet == false)) |
||
149 | { |
||
150 | bt_init(); |
||
151 | // set_USBOn(); |
||
152 | } |
||
153 | |||
154 | lcd_cls(); |
||
155 | |||
156 | if ((UseWi == true) && (U02SV2 == 0)) |
||
157 | { |
||
158 | Change_Output(Uart02Wi); // Verbindung zu Wi232 herstellen |
||
159 | if (PKT_StartInfo == true) |
||
160 | { |
||
161 | // lcd_printp_at (0, 0, PSTR("Verbindung zum MK ist"), 0); |
||
162 | // lcd_printp_at (0, 1, PSTR("auf Wi232 eingestellt"), 0); |
||
163 | lcd_puts_at(0, 0, strGet(BOOT_WI1), 0); |
||
164 | lcd_puts_at(0, 1, strGet(BOOT_WI2), 0); |
||
165 | _delay_ms(2000); |
||
166 | } |
||
167 | } |
||
168 | else |
||
169 | { |
||
170 | Change_Output(Uart02FC); // Verbindung zu SV" (Kabel) herstellen |
||
171 | if (PKT_StartInfo == true) |
||
172 | { |
||
173 | // lcd_printp_at (0, 0, PSTR("Verbindung zum MK ist"), 0); |
||
174 | // lcd_printp_at (0, 1, PSTR("auf Kabel eingestellt"), 0); |
||
175 | lcd_puts_at(0, 0, strGet(BOOT_WI1), 0); |
||
176 | lcd_puts_at(0, 1, strGet(BOOT_SV), 0); |
||
177 | _delay_ms(2000); |
||
178 | } |
||
179 | } |
||
180 | |||
181 | lcd_cls(); |
||
182 | |||
183 | } |
||
184 | |||
185 | |||
186 | |||
187 | void set_D_LIGHT(void) /* Displaybeleuchtung ein*/ |
||
188 | { |
||
189 | // PWM einschalten |
||
190 | TCCR2A |= (1 << WGM21) | (1 << WGM20) | (1 << COM2A1); |
||
191 | TCCR2B |= (1 << CS20); |
||
192 | } |
||
193 | |||
194 | void clr_D_LIGHT(void) /* Displaybeleuchtung aus*/ |
||
195 | { |
||
196 | // PWM ausschalten |
||
197 | TCCR2A = 0; |
||
198 | TCCR2B = 0; |
||
199 | } |
||
200 | |||
201 | uint8_t BTIsOn=0; |
||
202 | |||
203 | void set_BTOn(void) |
||
204 | { |
||
205 | if (BTIsOn == 0) |
||
206 | { |
||
207 | _BTOn(); |
||
208 | BTIsOn = 1; |
||
209 | _delay_ms(2000); |
||
210 | } |
||
211 | } |
||
212 | void set_BTOff(void) |
||
213 | { |
||
214 | set_USBOn(); |
||
215 | BTIsOn = 0; |
||
216 | } |
||
217 | |||
218 | |||
219 | |||
220 | #endif |
||
221 | #endif // HAL_HW3_9_C_ |