Rev 1771 | Rev 1866 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1771 | Rev 1801 | ||
---|---|---|---|
1 | /**************************************************************************** |
1 | /**************************************************************************** |
2 | * Copyright (C) 2009-2012 by Claas Anders "CaScAdE" Rathje * |
2 | * Copyright (C) 2009-2012 by Claas Anders "CaScAdE" Rathje * |
3 | * admiralcascade@gmail.com * |
3 | * admiralcascade@gmail.com * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-osd/ * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-osd/ * |
5 | * * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License. * |
8 | * the Free Software Foundation; either version 2 of the License. * |
9 | * * |
9 | * * |
10 | * This program is distributed in the hope that it will be useful, * |
10 | * This program is distributed in the hope that it will be useful, * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 | * GNU General Public License for more details. * |
13 | * GNU General Public License for more details. * |
14 | * * |
14 | * * |
15 | * You should have received a copy of the GNU General Public License * |
15 | * You should have received a copy of the GNU General Public License * |
16 | * along with this program; if not, write to the * |
16 | * along with this program; if not, write to the * |
17 | * Free Software Foundation, Inc., * |
17 | * Free Software Foundation, Inc., * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 | ****************************************************************************/ |
19 | ****************************************************************************/ |
20 | 20 | ||
21 | #ifndef _MAIN_H |
21 | #ifndef _MAIN_H |
22 | #define _MAIN_H |
22 | #define _MAIN_H |
23 | 23 | ||
24 | #ifndef MCU |
24 | #ifndef MCU |
25 | #define MCU atmega162 |
25 | #define MCU atmega162 |
26 | #endif |
26 | #endif |
27 | 27 | ||
28 | #ifndef __AVR_ATmega162__ |
28 | #ifndef __AVR_ATmega162__ |
29 | #define __AVR_ATmega162__ |
29 | #define __AVR_ATmega162__ |
30 | #endif |
30 | #endif |
31 | 31 | ||
32 | 32 | ||
33 | #include <avr/pgmspace.h> |
33 | #include <avr/pgmspace.h> |
34 | #include "mk-data-structs.h" |
34 | #include "mk-data-structs.h" |
35 | 35 | ||
36 | /* ########################################################################## |
36 | /* ########################################################################## |
37 | * Debugging and general purpose definitions |
37 | * Debugging and general purpose definitions |
38 | * ##########################################################################*/ |
38 | * ##########################################################################*/ |
39 | #ifndef BUILDOSDBUILDDATE |
39 | #ifndef BUILDOSDBUILDDATE |
40 | #define BUILDOSDBUILDDATE "DEV "__DATE__ // build date, this is testing... |
40 | #define BUILDOSDBUILDDATE "DEV "__DATE__ // build date, this is testing... |
41 | #endif |
41 | #endif |
42 | 42 | ||
43 | #define ALLCHARSDEBUG 0 // set to 1 and flash firmware to see all chars |
43 | #define ALLCHARSDEBUG 0 // set to 1 and flash firmware to see all chars |
44 | 44 | ||
45 | #ifndef WRITECHARS // if WRITECHARS not set via makefile |
45 | #ifndef WRITECHARS // if WRITECHARS not set via makefile |
46 | #define WRITECHARS -1 // set to 1 and flash firmware to write all chars |
46 | #define WRITECHARS -1 // set to 1 and flash firmware to write all chars |
47 | #endif |
47 | #endif |
48 | 48 | ||
49 | #ifndef NTSC // if NTSC is not thet via makefile |
49 | #ifndef NTSC // if NTSC is not thet via makefile |
50 | #define NTSC 0 // set to 1 for NTSC mode + lifts the bottom line |
50 | #define NTSC 0 // set to 1 for NTSC mode + lifts the bottom line |
51 | #endif |
51 | #endif |
52 | 52 | ||
53 | #ifndef FCONLY |
53 | #ifndef FCONLY |
54 | #define FCONLY 0 // set to 1 if you do NOT have a NaviCtrl and the OSD is |
54 | #define FCONLY 0 // set to 1 if you do NOT have a NaviCtrl and the OSD is |
55 | #endif // connected to the FC directly |
55 | #endif // connected to the FC directly |
56 | 56 | ||
57 | //#define ACT_RSSI_FROM_LCD 1 // set to 1 to get the ACT RSSI from the FC-LCD in FC-Only mode... Really dirty! |
57 | //#define ACT_RSSI_FROM_LCD 1 // set to 1 to get the ACT RSSI from the FC-LCD in FC-Only mode... Really dirty! |
58 | 58 | ||
59 | #define HUD 1 // set to 0 to disable HUD by default |
59 | #define HUD 1 // set to 0 to disable HUD by default |
60 | #define ARTHORIZON 0 // set to 1 to enable roll&nick artificial horizon by default |
60 | #define ARTHORIZON 0 // set to 1 to enable roll&nick artificial horizon by default |
61 | #define BIGVARIO 0 // set to 1 to enable the big vario bar on right side |
61 | #define BIGVARIO 0 // set to 1 to enable the big vario bar on right side |
62 | #define STATS 1 // set to 1 to enable statistics during motor off by default |
62 | #define STATS 1 // set to 1 to enable statistics during motor off by default |
63 | #define WARNINGS 1 // set to 1 to display battery+rc warning even if HUD is disabled |
63 | #define WARNINGS 1 // set to 1 to display battery+rc warning even if HUD is disabled |
64 | 64 | ||
65 | //#define UBAT_WRN 94 // voltage for blinking warning, like FC settings (deprecated) |
65 | //#define UBAT_WRN 94 // voltage for blinking warning, like FC settings (deprecated) |
66 | //#define UBAT_MAX 114 // maximal battery voltage for battery-sign (deprecated) |
66 | //#define UBAT_MAX 114 // maximal battery voltage for battery-sign (deprecated) |
67 | #define CELL_VOLT_MAX 37 // max voltage per battery cell (37 for LiPo) |
67 | #define CELL_VOLT_MAX 37 // max voltage per battery cell (37 for LiPo) |
68 | #define CELL_VOLT_MIN 32 // min voltage per battery cell (maybe 32 for LiPo?) |
68 | #define CELL_VOLT_MIN 32 // min voltage per battery cell (maybe 32 for LiPo?) |
69 | #define CELL_NUM -1 // -1 for auto, 3 for 3s1p and 4 for 4s1p |
69 | #define CELL_NUM -1 // -1 for auto, 3 for 3s1p and 4 for 4s1p |
70 | #define RCLVL_WRN 100 // make the RC level blink if below this number |
70 | #define RCLVL_WRN 100 // make the RC level blink if below this number |
71 | 71 | ||
72 | // ### read datasheet before changing stuff below this line :) |
72 | // ### read datasheet before changing stuff below this line :) |
73 | #define BLINK 0b01001111 // attribute byte for blinking characters |
73 | #define BLINK 0b01001111 // attribute byte for blinking characters |
74 | #define INVERT 0b00101111 // attribute byte for inverted characters |
74 | #define INVERT 0b00101111 // attribute byte for inverted characters |
75 | #define BLACKBG 0b10001111 // attribute byte for _black background_ on characters |
75 | #define BLACKBG 0b10001111 // attribute byte for _black background_ on characters |
76 | 76 | ||
77 | // ### constants |
77 | // ### constants |
78 | #define MtoFT 32808399 // 3,2808399 |
78 | #define MtoFT 32808399 // 3,2808399 |
79 | 79 | ||
80 | // ### Antenna Tracking |
80 | // ### Antenna Tracking |
81 | //#define ANTENNATRACKTEST 1 |
81 | //#define ANTENNATRACKTEST 1 |
82 | 82 | ||
83 | // ### serial output of stuff sent to MAX7456 |
83 | // ### serial output of stuff sent to MAX7456 |
84 | //#define SERIALDEBUGDRAW 1 |
84 | //#define SERIALDEBUGDRAW 1 |
85 | 85 | ||
86 | /* ########################################################################## |
86 | /* ########################################################################## |
87 | * FLAGS usable during runtime that get saved |
87 | * FLAGS usable during runtime that get saved |
88 | * ##########################################################################*/ |
88 | * ##########################################################################*/ |
89 | #define COSD_FLAG_HUD 1 |
89 | #define COSD_FLAG_HUD 1 |
90 | #define COSD_FLAG_ARTHORIZON 2 |
90 | #define COSD_FLAG_ARTHORIZON 2 |
91 | #define COSD_FLAG_BIGVARIO 4 |
91 | #define COSD_FLAG_BIGVARIO 4 |
92 | #define COSD_FLAG_STATS 8 |
92 | #define COSD_FLAG_STATS 8 |
93 | #define COSD_FLAG_WARNINGS 16 |
93 | #define COSD_FLAG_WARNINGS 16 |
94 | #define COSD_FLAG_STROMVOLT 32 |
94 | #define COSD_FLAG_STROMVOLT 32 |
95 | #define COSD_FLAG_FCCURRENT 64 |
95 | #define COSD_FLAG_FCCURRENT 64 |
96 | #define COSD_FLAG_AGGRHORIZON 128 |
96 | #define COSD_FLAG_AGGRHORIZON 128 |
97 | 97 | ||
98 | 98 | ||
99 | #define COSD_FLAG_NTSC 1 |
99 | #define COSD_FLAG_NTSC 1 |
100 | #define COSD_FLAG_GPSHEIGHT 2 |
100 | #define COSD_FLAG_GPSHEIGHT 2 |
101 | #define COSD_FLAG_FCMODE 4 |
101 | #define COSD_FLAG_FCMODE 4 |
102 | #define COSD_FLAG_FEET 8 |
102 | #define COSD_FLAG_FEET 8 |
103 | #define COSD_FLAG_PASSIVE 16 |
103 | #define COSD_FLAG_PASSIVE 16 |
104 | #define COSD_FLAG_SHOW_SCOPE 32 |
104 | #define COSD_FLAG_SHOW_SCOPE 32 |
105 | #define COSD_FLAG_SHOW_COORDS 64 |
105 | #define COSD_FLAG_SHOW_COORDS 64 |
106 | #define COSD_FLAG_BIGSPEED 128 |
106 | #define COSD_FLAG_BIGSPEED 128 |
107 | 107 | ||
108 | /* ########################################################################## |
108 | /* ########################################################################## |
109 | * FLAGS only usable during runtime (not saved) |
109 | * FLAGS only usable during runtime (not saved) |
110 | * ##########################################################################*/ |
110 | * ##########################################################################*/ |
111 | #define COSD_FLAG_STROMREC 1 |
111 | #define COSD_FLAG_STROMREC 1 |
112 | #define COSD_ICONS_WRITTEN 2 |
112 | #define COSD_ICONS_WRITTEN 2 |
113 | #define COSD_WASFLYING 4 |
113 | #define COSD_WASFLYING 4 |
114 | #define COSD_DATARECEIVED 8 |
114 | #define COSD_DATARECEIVED 8 |
115 | #define COSD_BLANKBYSJ 16 |
115 | #define COSD_BLANKBYSJ 16 |
116 | 116 | ||
117 | /* ########################################################################## |
117 | /* ########################################################################## |
118 | * LED controll |
118 | * LED controll |
119 | * ##########################################################################*/ |
119 | * ##########################################################################*/ |
120 | #define LED1_ON PORTC |= (1 << PC0); |
120 | #define LED1_ON PORTC |= (1 << PC0); |
121 | #define LED1_OFF PORTC &= ~(1 << PC0); |
121 | #define LED1_OFF PORTC &= ~(1 << PC0); |
122 | #define LED2_ON PORTC |= (1 << PC1); |
122 | #define LED2_ON PORTC |= (1 << PC1); |
123 | #define LED2_OFF PORTC &= ~(1 << PC1); |
123 | #define LED2_OFF PORTC &= ~(1 << PC1); |
124 | #define LED3_ON PORTC |= (1 << PC2); |
124 | #define LED3_ON PORTC |= (1 << PC2); |
125 | #define LED3_OFF PORTC &= ~(1 << PC2); |
125 | #define LED3_OFF PORTC &= ~(1 << PC2); |
126 | #define LED4_ON PORTC |= (1 << PC3); |
126 | #define LED4_ON PORTC |= (1 << PC3); |
127 | #define LED4_OFF PORTC &= ~(1 << PC3); |
127 | #define LED4_OFF PORTC &= ~(1 << PC3); |
128 | 128 | ||
129 | /* ########################################################################## |
129 | /* ########################################################################## |
130 | * switch controll |
130 | * switch controll |
131 | * ##########################################################################*/ |
131 | * ##########################################################################*/ |
132 | #define S1_PRESSED !(PINC & (1<<PC5)) |
132 | #define S1_PRESSED !(PINC & (1<<PC5)) |
133 | #define S2_PRESSED !(PINC & (1<<PC4)) |
133 | #define S2_PRESSED !(PINC & (1<<PC4)) |
134 | 134 | ||
135 | /* ########################################################################## |
135 | /* ########################################################################## |
136 | * solder jumpers |
136 | * solder jumpers |
137 | * ##########################################################################*/ |
137 | * ##########################################################################*/ |
138 | 138 | ||
139 | #define SJ1_CLOSED !(PINC & (1<<PC6)) |
139 | #define SJ1_CLOSED !(PINC & (1<<PC6)) |
140 | #define SJ2_CLOSED !(PINC & (1<<PC7)) |
140 | #define SJ2_CLOSED !(PINC & (1<<PC7)) |
141 | 141 | ||
142 | 142 | ||
143 | /* ########################################################################## |
143 | /* ########################################################################## |
144 | * extern spi controlled vars |
144 | * extern spi controlled vars |
145 | * ##########################################################################*/ |
145 | * ##########################################################################*/ |
146 | extern volatile uint16_t icnt; |
146 | extern volatile uint16_t icnt; |
147 | extern volatile unsigned char * iptr; |
147 | extern volatile unsigned char * iptr; |
148 | extern volatile uint8_t spi_cmd_buffer[]; |
148 | extern volatile uint8_t spi_cmd_buffer[]; |
149 | extern volatile uint8_t spi_ready; |
149 | extern volatile uint8_t spi_ready; |
150 | extern int16_t ampere, max_ampere, s_volt; |
150 | extern int16_t ampere, max_ampere, s_volt; |
151 | extern int32_t ampere_wasted; |
151 | extern int32_t ampere_wasted; |
152 | 152 | ||
153 | /* ########################################################################## |
153 | /* ########################################################################## |
154 | * struct for displaymodes |
154 | * struct for displaymodes |
155 | * ##########################################################################*/ |
155 | * ##########################################################################*/ |
156 | typedef struct { |
156 | typedef struct { |
157 | int (*dfun)(void); // function pointer |
157 | int (*dfun)(void); // function pointer |
158 | char *desc; // description text |
158 | char *desc; // description text |
159 | } displaymode_t; |
159 | } displaymode_t; |
160 | 160 | ||
161 | const displaymode_t ncdisplaymodes[2]; |
161 | const displaymode_t ncdisplaymodes[2]; |
162 | const displaymode_t fcdisplaymodes[2]; |
162 | const displaymode_t fcdisplaymodes[2]; |
163 | 163 | ||
164 | int (*osd_ncmode)(void); |
164 | int (*osd_ncmode)(void); |
165 | int (*osd_fcmode)(void); |
165 | int (*osd_fcmode)(void); |
166 | 166 | ||
167 | /* ########################################################################## |
167 | /* ########################################################################## |
168 | * vars used by other parts as well |
168 | * vars used by other parts as well |
169 | * ##########################################################################*/ |
169 | * ##########################################################################*/ |
170 | volatile uint16_t setsReceived; |
170 | volatile uint16_t setsReceived; |
171 | 171 | ||
172 | #if FCONLY |
172 | #if FCONLY |
173 | volatile str_DebugOut debugData; |
173 | volatile str_DebugOut debugData; |
174 | #else |
174 | #else |
175 | volatile NaviData_t naviData; |
175 | volatile NaviData_t naviData; |
- | 176 | volatile Data3D_t data3d; |
|
176 | #endif |
177 | #endif |
177 | 178 | ||
178 | // cache old vars for blinking attribute, checkup is faster than full |
179 | // cache old vars for blinking attribute, checkup is faster than full |
179 | // attribute write each time |
180 | // attribute write each time |
180 | volatile uint8_t last_UBat; |
181 | volatile uint8_t last_UBat; |
181 | volatile uint8_t last_RC_Quality; |
182 | volatile uint8_t last_RC_Quality; |
182 | 183 | ||
183 | // 16bit should be enough, normal LiPos don't last that long |
184 | // 16bit should be enough, normal LiPos don't last that long |
184 | volatile uint16_t uptime; |
185 | volatile uint16_t uptime; |
185 | volatile uint16_t timer; |
186 | volatile uint16_t timer; |
186 | volatile uint16_t flytime_fc; |
187 | volatile uint16_t flytime_fc; |
187 | volatile uint16_t wasted_ampere_offset; |
188 | volatile uint16_t wasted_ampere_offset; |
188 | 189 | ||
189 | // remember last time data was received |
190 | // remember last time data was received |
190 | volatile uint8_t seconds_since_last_data; |
191 | volatile uint8_t seconds_since_last_data; |
191 | 192 | ||
192 | // general PAL|NTSC distingiusch stuff |
193 | // general PAL|NTSC distingiusch stuff |
193 | uint8_t top_line; |
194 | uint8_t top_line; |
194 | uint8_t bottom_line; |
195 | uint8_t bottom_line; |
195 | 196 | ||
196 | // battery voltages |
197 | // battery voltages |
197 | uint8_t min_voltage; |
198 | uint8_t min_voltage; |
198 | uint8_t max_voltage; |
199 | uint8_t max_voltage; |
199 | 200 | ||
200 | // scope for 2nd camera field of view |
201 | // scope for 2nd camera field of view |
201 | uint8_t scope[12]; |
202 | uint8_t scope[12]; |
202 | 203 | ||
203 | // Flags |
204 | // Flags |
204 | uint8_t COSD_FLAGS_MODES, COSD_FLAGS_CONFIG, COSD_FLAGS_RUNTIME, COSD_DISPLAYMODE; |
205 | uint8_t COSD_FLAGS_MODES, COSD_FLAGS_CONFIG, COSD_FLAGS_RUNTIME, COSD_DISPLAYMODE; |
205 | 206 | ||
206 | // stats for after flight |
207 | // stats for after flight |
207 | int16_t max_Altimeter, altimeter_offset; |
208 | int16_t max_Altimeter, altimeter_offset; |
208 | uint8_t min_UBat; |
209 | uint8_t min_UBat; |
209 | 210 | ||
210 | uint16_t max_GroundSpeed; |
211 | uint16_t max_GroundSpeed; |
211 | int16_t max_Distance; |
212 | int16_t max_Distance; |
212 | uint16_t max_FlyingTime; |
213 | uint16_t max_FlyingTime; |
213 | 214 | ||
214 | // flags from last round to check for changes |
215 | // flags from last round to check for changes |
215 | uint8_t old_MKFlags; |
216 | uint8_t old_MKFlags; |
216 | uint8_t old_NCFlags; |
217 | uint8_t old_NCFlags; |
217 | 218 | ||
218 | char *directions[8]; |
219 | char *directions[8]; |
219 | 220 | ||
220 | #endif |
221 | #endif |
221 | 222 |