Subversion Repositories Projects

Rev

Rev 902 | Rev 942 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 902 Rev 932
1
/****************************************************************************
1
/****************************************************************************
2
 *   Copyright (C) 2009-2011 by Claas Anders "CaScAdE" Rathje               *
2
 *   Copyright (C) 2009-2011 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 BUILDDATE
39
#ifndef BUILDDATE
40
#define BUILDDATE "DEVEL-BUILD" // build date, this is testing...
40
#define BUILDDATE "DEVEL-BUILD" // 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 HUD 1                    // set to 0 to disable HUD by default
57
#define HUD 1                    // set to 0 to disable HUD by default
58
#define ARTHORIZON 0            // set to 1 to enable roll&nick artificial horizon by default
58
#define ARTHORIZON 0            // set to 1 to enable roll&nick artificial horizon by default
59
#define BIGVARIO 0              // set to 1 to enable the big vario bar on right side
59
#define BIGVARIO 0              // set to 1 to enable the big vario bar on right side
60
#define STATS 1                 // set to 1 to enable statistics during motor off by default
60
#define STATS 1                 // set to 1 to enable statistics during motor off by default
61
#define WARNINGS 1              // set to 1 to display battery+rc warning even if HUD is disabled
61
#define WARNINGS 1              // set to 1 to display battery+rc warning even if HUD is disabled
62
 
62
 
63
//#define UBAT_WRN  94          // voltage for blinking warning, like FC settings (deprecated)
63
//#define UBAT_WRN  94          // voltage for blinking warning, like FC settings (deprecated)
64
//#define UBAT_MAX 114          // maximal battery voltage for battery-sign (deprecated)
64
//#define UBAT_MAX 114          // maximal battery voltage for battery-sign (deprecated)
65
#define CELL_VOLT_MAX 37        // max voltage per battery cell (37 for LiPo)
65
#define CELL_VOLT_MAX 37        // max voltage per battery cell (37 for LiPo)
66
#define CELL_VOLT_MIN 32        // min voltage per battery cell (maybe 32 for LiPo?)
66
#define CELL_VOLT_MIN 32        // min voltage per battery cell (maybe 32 for LiPo?)
67
#define CELL_NUM -1             // -1 for auto, 3 for 3s1p and 4 for 4s1p
67
#define CELL_NUM -1             // -1 for auto, 3 for 3s1p and 4 for 4s1p
68
#define RCLVL_WRN 100           // make the RC level blink if below this number
68
#define RCLVL_WRN 100           // make the RC level blink if below this number
69
 
69
 
70
// ### read datasheet before changing stuff below this line :)
70
// ### read datasheet before changing stuff below this line :)
71
#define BLINK   0b01001111      // attribute byte for blinking characters
71
#define BLINK   0b01001111      // attribute byte for blinking characters
72
#define INVERT  0b00101111      // attribute byte for inverted characters
72
#define INVERT  0b00101111      // attribute byte for inverted characters
73
#define BLACKBG 0b10001111      // attribute byte for _black background_ on characters
73
#define BLACKBG 0b10001111      // attribute byte for _black background_ on characters
74
 
74
 
75
// ### constants
75
// ### constants
76
#define MtoFT 32808399 // 3,2808399
76
#define MtoFT 32808399 // 3,2808399
77
 
77
 
78
// ### Antenna Tracking
78
// ### Antenna Tracking
79
//#define ANTENNATRACKTEST 1
79
//#define ANTENNATRACKTEST 1
80
 
80
 
-
 
81
// ### serial output of stuff sent to MAX7456
-
 
82
//#define SERIALDEBUGDRAW 1
-
 
83
 
81
/* ##########################################################################
84
/* ##########################################################################
82
 * FLAGS usable during runtime that get saved
85
 * FLAGS usable during runtime that get saved
83
 * ##########################################################################*/
86
 * ##########################################################################*/
84
#define COSD_FLAG_HUD                     1
87
#define COSD_FLAG_HUD                     1
85
#define COSD_FLAG_ARTHORIZON              2
88
#define COSD_FLAG_ARTHORIZON              2
86
#define COSD_FLAG_BIGVARIO                4
89
#define COSD_FLAG_BIGVARIO                4
87
#define COSD_FLAG_STATS                   8
90
#define COSD_FLAG_STATS                   8
88
#define COSD_FLAG_WARNINGS               16
91
#define COSD_FLAG_WARNINGS               16
89
#define COSD_FLAG_STROMVOLT              32
92
#define COSD_FLAG_STROMVOLT              32
90
#define COSD_FLAG_FCCURRENT              64
93
#define COSD_FLAG_FCCURRENT              64
91
#define COSD_FLAG_AGGRHORIZON           128
94
#define COSD_FLAG_AGGRHORIZON           128
92
 
95
 
93
 
96
 
94
#define COSD_FLAG_NTSC                    1
97
#define COSD_FLAG_NTSC                    1
95
#define COSD_FLAG_GPSHEIGHT               2
98
#define COSD_FLAG_GPSHEIGHT               2
96
#define COSD_FLAG_FCMODE                  4
99
#define COSD_FLAG_FCMODE                  4
97
#define COSD_FLAG_FEET                    8
100
#define COSD_FLAG_FEET                    8
98
#define COSD_FLAG_PASSIVE                16
101
#define COSD_FLAG_PASSIVE                16
99
#define COSD_FLAG_SHOW_SCOPE             32
102
#define COSD_FLAG_SHOW_SCOPE             32
100
#define COSD_FLAG_SHOW_COORDS            64
103
#define COSD_FLAG_SHOW_COORDS            64
101
#define COSD_FLAG_BIGSPEED              128
104
#define COSD_FLAG_BIGSPEED              128
102
 
105
 
103
/* ##########################################################################
106
/* ##########################################################################
104
 * FLAGS only usable during runtime (not saved)
107
 * FLAGS only usable during runtime (not saved)
105
 * ##########################################################################*/
108
 * ##########################################################################*/
106
#define COSD_FLAG_STROMREC                1
109
#define COSD_FLAG_STROMREC                1
107
#define COSD_ICONS_WRITTEN                2
110
#define COSD_ICONS_WRITTEN                2
108
#define COSD_WASFLYING                    4
111
#define COSD_WASFLYING                    4
109
#define COSD_DATARECEIVED                 8
112
#define COSD_DATARECEIVED                 8
110
 
113
 
111
/* ##########################################################################
114
/* ##########################################################################
112
 * LED controll
115
 * LED controll
113
 * ##########################################################################*/
116
 * ##########################################################################*/
114
#define LED1_ON                 PORTC |=  (1 << PC0);
117
#define LED1_ON                 PORTC |=  (1 << PC0);
115
#define LED1_OFF                PORTC &= ~(1 << PC0);
118
#define LED1_OFF                PORTC &= ~(1 << PC0);
116
#define LED2_ON                 PORTC |=  (1 << PC1);
119
#define LED2_ON                 PORTC |=  (1 << PC1);
117
#define LED2_OFF                PORTC &= ~(1 << PC1);
120
#define LED2_OFF                PORTC &= ~(1 << PC1);
118
#define LED3_ON                 PORTC |=  (1 << PC2);
121
#define LED3_ON                 PORTC |=  (1 << PC2);
119
#define LED3_OFF                PORTC &= ~(1 << PC2);
122
#define LED3_OFF                PORTC &= ~(1 << PC2);
120
#define LED4_ON                 PORTC |=  (1 << PC3);
123
#define LED4_ON                 PORTC |=  (1 << PC3);
121
#define LED4_OFF                PORTC &= ~(1 << PC3);
124
#define LED4_OFF                PORTC &= ~(1 << PC3);
122
 
125
 
123
/* ##########################################################################
126
/* ##########################################################################
124
 * switch controll
127
 * switch controll
125
 * ##########################################################################*/
128
 * ##########################################################################*/
126
#define S1_PRESSED              !(PINC & (1<<PC5))
129
#define S1_PRESSED              !(PINC & (1<<PC5))
127
#define S2_PRESSED              !(PINC & (1<<PC4))
130
#define S2_PRESSED              !(PINC & (1<<PC4))
128
 
131
 
129
 
132
 
130
/* ##########################################################################
133
/* ##########################################################################
131
 * extern spi controlled vars
134
 * extern spi controlled vars
132
 * ##########################################################################*/
135
 * ##########################################################################*/
133
extern volatile uint16_t icnt;
136
extern volatile uint16_t icnt;
134
extern volatile unsigned char * iptr;
137
extern volatile unsigned char * iptr;
135
extern volatile uint8_t spi_cmd_buffer[];
138
extern volatile uint8_t spi_cmd_buffer[];
136
extern volatile uint8_t spi_ready;
139
extern volatile uint8_t spi_ready;
137
extern int16_t ampere, max_ampere, s_volt;
140
extern int16_t ampere, max_ampere, s_volt;
138
extern int32_t ampere_wasted;
141
extern int32_t ampere_wasted;
139
 
142
 
140
/* ##########################################################################
143
/* ##########################################################################
141
 * struct for displaymodes
144
 * struct for displaymodes
142
 * ##########################################################################*/
145
 * ##########################################################################*/
143
typedef struct {
146
typedef struct {
144
    int (*dfun)(void); // function pointer
147
    int (*dfun)(void); // function pointer
145
    char *desc; // description text
148
    char *desc; // description text
146
} displaymode_t;
149
} displaymode_t;
147
 
150
 
148
const displaymode_t ncdisplaymodes[2];
151
const displaymode_t ncdisplaymodes[2];
149
const displaymode_t fcdisplaymodes[2];
152
const displaymode_t fcdisplaymodes[2];
150
 
153
 
151
int (*osd_ncmode)(void);
154
int (*osd_ncmode)(void);
152
int (*osd_fcmode)(void);
155
int (*osd_fcmode)(void);
153
 
156
 
154
/* ##########################################################################
157
/* ##########################################################################
155
 * vars used by other parts as well
158
 * vars used by other parts as well
156
 * ##########################################################################*/
159
 * ##########################################################################*/
157
volatile uint16_t setsReceived;
160
volatile uint16_t setsReceived;
158
 
161
 
159
volatile NaviData_t naviData;
162
volatile NaviData_t naviData;
160
volatile str_DebugOut debugData;
163
volatile str_DebugOut debugData;
161
 
164
 
162
// cache old vars for blinking attribute, checkup is faster than full
165
// cache old vars for blinking attribute, checkup is faster than full
163
// attribute write each time
166
// attribute write each time
164
volatile uint8_t last_UBat;
167
volatile uint8_t last_UBat;
165
volatile uint8_t last_RC_Quality;
168
volatile uint8_t last_RC_Quality;
166
 
169
 
167
// 16bit should be enough, normal LiPos don't last that long
170
// 16bit should be enough, normal LiPos don't last that long
168
volatile uint16_t uptime;
171
volatile uint16_t uptime;
169
volatile uint16_t timer;
172
volatile uint16_t timer;
170
volatile uint16_t flytime_fc;
173
volatile uint16_t flytime_fc;
171
volatile uint16_t wasted_ampere_offset;
174
volatile uint16_t wasted_ampere_offset;
172
 
175
 
173
// remember last time data was received
176
// remember last time data was received
174
volatile uint8_t seconds_since_last_data;
177
volatile uint8_t seconds_since_last_data;
175
 
178
 
176
// general PAL|NTSC distingiusch stuff
179
// general PAL|NTSC distingiusch stuff
177
uint8_t top_line;
180
uint8_t top_line;
178
uint8_t bottom_line;
181
uint8_t bottom_line;
179
 
182
 
180
// battery voltages
183
// battery voltages
181
uint8_t min_voltage;
184
uint8_t min_voltage;
182
uint8_t max_voltage;
185
uint8_t max_voltage;
183
 
186
 
184
// scope for 2nd camera field of view
187
// scope for 2nd camera field of view
185
uint8_t scope[12];
188
uint8_t scope[12];
186
 
189
 
187
// Flags
190
// Flags
188
uint8_t COSD_FLAGS_MODES, COSD_FLAGS_CONFIG, COSD_FLAGS_RUNTIME, COSD_DISPLAYMODE;
191
uint8_t COSD_FLAGS_MODES, COSD_FLAGS_CONFIG, COSD_FLAGS_RUNTIME, COSD_DISPLAYMODE;
189
 
192
 
190
// stats for after flight
193
// stats for after flight
191
int16_t max_Altimeter, altimeter_offset;
194
int16_t max_Altimeter, altimeter_offset;
192
uint8_t min_UBat;
195
uint8_t min_UBat;
193
 
196
 
194
uint16_t max_GroundSpeed;
197
uint16_t max_GroundSpeed;
195
int16_t max_Distance;
198
int16_t max_Distance;
196
uint16_t max_FlyingTime;
199
uint16_t max_FlyingTime;
197
 
200
 
198
// flags from last round to check for changes
201
// flags from last round to check for changes
199
uint8_t old_MKFlags;
202
uint8_t old_MKFlags;
200
uint8_t old_NCFlags;
203
uint8_t old_NCFlags;
201
 
204
 
202
const char *directions[8];
205
const char *directions[8];
203
const char *stats_item_pointers[8];
206
const char *stats_item_pointers[8];
204
 
207
 
205
#endif
208
#endif
206
 
209