Subversion Repositories Projects

Rev

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

Rev 783 Rev 800
1
/****************************************************************************
1
/****************************************************************************
2
 *   Copyright (C) 2009-2010 by Claas Anders "CaScAdE" Rathje               *
2
 *   Copyright (C) 2009-2010 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
 
-
 
24
#ifndef MCU
-
 
25
#define MCU atmega162
-
 
26
#endif
-
 
27
 
-
 
28
#ifndef __AVR_ATmega162__
-
 
29
#define __AVR_ATmega162__
-
 
30
#endif
-
 
31
 
23
 
32
 
24
#include <avr/pgmspace.h>
33
#include <avr/pgmspace.h>
25
#include "mk-data-structs.h"
34
#include "mk-data-structs.h"
26
 
35
 
27
/* ##########################################################################
36
/* ##########################################################################
28
 * Debugging and general purpose definitions
37
 * Debugging and general purpose definitions
29
 * ##########################################################################*/
38
 * ##########################################################################*/
30
#ifndef BUILDDATE
39
#ifndef BUILDDATE
31
#define BUILDDATE "DEVEL-BUILD" // build date, this is testing...
40
#define BUILDDATE "DEVEL-BUILD" // build date, this is testing...
32
#endif
41
#endif
33
 
42
 
34
#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
35
 
44
 
36
#ifndef WRITECHARS              // if WRITECHARS not set via makefile
45
#ifndef WRITECHARS              // if WRITECHARS not set via makefile
37
#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
38
#endif
47
#endif
39
 
48
 
40
#ifndef NTSC                    // if NTSC is not thet via makefile
49
#ifndef NTSC                    // if NTSC is not thet via makefile
41
#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
42
#endif
51
#endif
43
 
52
 
44
#ifndef FCONLY
53
#ifndef FCONLY
45
#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
46
#endif                          // connected to the FC directly
55
#endif                          // connected to the FC directly
47
 
56
 
48
#define HUD 1               // set to 0 to disable HUD by default
57
#define HUD 1                   // set to 0 to disable HUD by default
49
#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
50
#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
51
#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
52
#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
53
 
62
 
54
//#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)
55
//#define UBAT_MAX 114          // maximal battery voltage for battery-sign (deprecated)
64
//#define UBAT_MAX 114          // maximal battery voltage for battery-sign (deprecated)
56
#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)
57
#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?)
58
#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
59
#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
60
 
69
 
61
// ### read datasheet before changing stuff below this line :)
70
// ### read datasheet before changing stuff below this line :)
62
#define BLINK   0b01001111      // attribute byte for blinking characters
71
#define BLINK   0b01001111      // attribute byte for blinking characters
63
#define INVERT  0b00101111      // attribute byte for inverted characters
72
#define INVERT  0b00101111      // attribute byte for inverted characters
64
#define BLACKBG 0b10001111      // attribute byte for _black background_ on characters
73
#define BLACKBG 0b10001111      // attribute byte for _black background_ on characters
65
 
74
 
66
// ### constants
75
// ### constants
67
#define MtoFT 32808399 // 3,2808399
76
#define MtoFT 32808399 // 3,2808399
68
 
77
 
69
// ### Antenna Tracking
78
// ### Antenna Tracking
70
//#define ANTENNATRACKTEST 1
79
//#define ANTENNATRACKTEST 1
71
 
80
 
72
/* ##########################################################################
81
/* ##########################################################################
73
 * FLAGS usable during runtime that get saved
82
 * FLAGS usable during runtime that get saved
74
 * ##########################################################################*/
83
 * ##########################################################################*/
75
#define COSD_FLAG_HUD                     1
84
#define COSD_FLAG_HUD                     1
76
#define COSD_FLAG_ARTHORIZON      2
85
#define COSD_FLAG_ARTHORIZON              2
77
#define COSD_FLAG_BIGVARIO                4
86
#define COSD_FLAG_BIGVARIO                4
78
#define COSD_FLAG_STATS                   8
87
#define COSD_FLAG_STATS                   8
79
#define COSD_FLAG_WARNINGS               16
88
#define COSD_FLAG_WARNINGS               16
80
#define COSD_FLAG_STROMVOLT              32
89
#define COSD_FLAG_STROMVOLT              32
81
#define COSD_FLAG_FCCURRENT              64
90
#define COSD_FLAG_FCCURRENT              64
82
#define COSD_FLAG_AGGRHORIZON   128
91
#define COSD_FLAG_AGGRHORIZON           128
83
 
92
 
84
 
93
 
85
#define COSD_FLAG_NTSC                    1
94
#define COSD_FLAG_NTSC                    1
86
#define COSD_FLAG_GPSHEIGHT               2
95
#define COSD_FLAG_GPSHEIGHT               2
87
#define COSD_FLAG_FCMODE                  4
96
#define COSD_FLAG_FCMODE                  4
88
#define COSD_FLAG_FEET                    8
97
#define COSD_FLAG_FEET                    8
89
 
98
 
90
/* ##########################################################################
99
/* ##########################################################################
91
 * FLAGS only usable during runtime (not saved)
100
 * FLAGS only usable during runtime (not saved)
92
 * ##########################################################################*/
101
 * ##########################################################################*/
93
#define COSD_FLAG_STROMREC                1
102
#define COSD_FLAG_STROMREC                1
94
#define COSD_ICONS_WRITTEN                2
103
#define COSD_ICONS_WRITTEN                2
95
#define COSD_WASFLYING                    4
104
#define COSD_WASFLYING                    4
96
 
105
 
97
/* ##########################################################################
106
/* ##########################################################################
98
 * LED controll
107
 * LED controll
99
 * ##########################################################################*/
108
 * ##########################################################################*/
100
#define LED1_ON                 PORTC |=  (1 << PC0);
109
#define LED1_ON                 PORTC |=  (1 << PC0);
101
#define LED1_OFF                PORTC &= ~(1 << PC0);
110
#define LED1_OFF                PORTC &= ~(1 << PC0);
102
#define LED2_ON                 PORTC |=  (1 << PC1);
111
#define LED2_ON                 PORTC |=  (1 << PC1);
103
#define LED2_OFF                PORTC &= ~(1 << PC1);
112
#define LED2_OFF                PORTC &= ~(1 << PC1);
104
#define LED3_ON                 PORTC |=  (1 << PC2);
113
#define LED3_ON                 PORTC |=  (1 << PC2);
105
#define LED3_OFF                PORTC &= ~(1 << PC2);
114
#define LED3_OFF                PORTC &= ~(1 << PC2);
106
#define LED4_ON                 PORTC |=  (1 << PC3);
115
#define LED4_ON                 PORTC |=  (1 << PC3);
107
#define LED4_OFF                PORTC &= ~(1 << PC3);
116
#define LED4_OFF                PORTC &= ~(1 << PC3);
108
 
117
 
109
/* ##########################################################################
118
/* ##########################################################################
110
 * switch controll
119
 * switch controll
111
 * ##########################################################################*/
120
 * ##########################################################################*/
112
#define S1_PRESSED              !(PINC & (1<<PC5))
121
#define S1_PRESSED              !(PINC & (1<<PC5))
113
#define S2_PRESSED              !(PINC & (1<<PC4))
122
#define S2_PRESSED              !(PINC & (1<<PC4))
114
 
123
 
115
 
124
 
116
/* ##########################################################################
125
/* ##########################################################################
117
 * extern spi controlled vars
126
 * extern spi controlled vars
118
 * ##########################################################################*/
127
 * ##########################################################################*/
119
extern volatile uint16_t icnt;
128
extern volatile uint16_t icnt;
120
extern volatile unsigned char * iptr;
129
extern volatile unsigned char * iptr;
121
extern volatile uint8_t spi_cmd_buffer[];
130
extern volatile uint8_t spi_cmd_buffer[];
122
extern volatile uint8_t spi_ready;
131
extern volatile uint8_t spi_ready;
123
extern int16_t ampere, max_ampere, s_volt;
132
extern int16_t ampere, max_ampere, s_volt;
124
extern int32_t ampere_wasted;
133
extern int32_t ampere_wasted;
125
 
134
 
126
/* ##########################################################################
135
/* ##########################################################################
127
 * struct for displaymodes
136
 * struct for displaymodes
128
 * ##########################################################################*/
137
 * ##########################################################################*/
129
typedef struct {
138
typedef struct {
130
    int (*dfun)(void); // function pointer
139
    int (*dfun)(void); // function pointer
131
    char *desc; // description text
140
    char *desc; // description text
132
} displaymode_t;
141
} displaymode_t;
133
 
142
 
134
const displaymode_t ncdisplaymodes[2];
143
const displaymode_t ncdisplaymodes[2];
135
const displaymode_t fcdisplaymodes[2];
144
const displaymode_t fcdisplaymodes[2];
136
 
145
 
137
int (*osd_ncmode)(void);
146
int (*osd_ncmode)(void);
138
int (*osd_fcmode)(void);
147
int (*osd_fcmode)(void);
139
 
148
 
140
/* ##########################################################################
149
/* ##########################################################################
141
 * vars used by other parts as well
150
 * vars used by other parts as well
142
 * ##########################################################################*/
151
 * ##########################################################################*/
143
volatile uint16_t setsReceived;
152
volatile uint16_t setsReceived;
144
 
153
 
145
volatile NaviData_t naviData;
154
volatile NaviData_t naviData;
146
volatile str_DebugOut debugData;
155
volatile str_DebugOut debugData;
147
 
156
 
148
// cache old vars for blinking attribute, checkup is faster than full
157
// cache old vars for blinking attribute, checkup is faster than full
149
// attribute write each time
158
// attribute write each time
150
volatile uint8_t last_UBat;
159
volatile uint8_t last_UBat;
151
volatile uint8_t last_RC_Quality;
160
volatile uint8_t last_RC_Quality;
152
 
161
 
153
// 16bit should be enough, normal LiPos don't last that long
162
// 16bit should be enough, normal LiPos don't last that long
154
volatile uint16_t uptime;
163
volatile uint16_t uptime;
155
volatile uint16_t timer;
164
volatile uint16_t timer;
156
volatile uint16_t flytime_fc;
165
volatile uint16_t flytime_fc;
157
volatile uint16_t wasted_ampere_offset;
166
volatile uint16_t wasted_ampere_offset;
158
 
167
 
159
// remember last time data was received
168
// remember last time data was received
160
volatile uint8_t seconds_since_last_data;
169
volatile uint8_t seconds_since_last_data;
161
 
170
 
162
// general PAL|NTSC distingiusch stuff
171
// general PAL|NTSC distingiusch stuff
163
uint8_t top_line;
172
uint8_t top_line;
164
uint8_t bottom_line;
173
uint8_t bottom_line;
165
 
174
 
166
// battery voltages
175
// battery voltages
167
uint8_t min_voltage;
176
uint8_t min_voltage;
168
uint8_t max_voltage;
177
uint8_t max_voltage;
169
 
178
 
170
// Flags
179
// Flags
171
uint8_t COSD_FLAGS_MODES, COSD_FLAGS_CONFIG, COSD_FLAGS_RUNTIME, COSD_DISPLAYMODE;
180
uint8_t COSD_FLAGS_MODES, COSD_FLAGS_CONFIG, COSD_FLAGS_RUNTIME, COSD_DISPLAYMODE;
172
 
181
 
173
// stats for after flight
182
// stats for after flight
174
int16_t max_Altimeter, altimeter_offset;
183
int16_t max_Altimeter, altimeter_offset;
175
uint8_t min_UBat;
184
uint8_t min_UBat;
176
 
185
 
177
uint16_t max_GroundSpeed;
186
uint16_t max_GroundSpeed;
178
int16_t max_Distance;
187
int16_t max_Distance;
179
uint16_t max_FlyingTime;
188
uint16_t max_FlyingTime;
180
 
189
 
181
// flags from last round to check for changes
190
// flags from last round to check for changes
182
uint8_t old_MKFlags;
191
uint8_t old_MKFlags;
183
 
192
 
184
const char *directions[8];
193
const char *directions[8];
185
const char *stats_item_pointers[8];
194
const char *stats_item_pointers[8];
186
 
195
 
187
#endif
196
#endif
188
 
197