altosui: Add config and pyro tabs to graph widget
[fw/altos] / src / kernel / ao_config.h
1 /*
2  * Copyright © 2013 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #ifndef _AO_CONFIG_H_
20 #define _AO_CONFIG_H_
21
22 #ifndef AO_FLIGHT_TEST
23 #include <ao.h>
24 #endif
25
26 #if AO_PYRO_NUM
27 #include <ao_pyro.h>
28 #endif
29
30 #ifndef USE_STORAGE_CONFIG
31 #define USE_STORAGE_CONFIG 1
32 #endif
33
34 #ifndef USE_EEPROM_CONFIG
35 #define USE_EEPROM_CONFIG 0
36 #endif
37
38 #ifndef FLIGHT_LOG_APPEND
39 #define FLIGHT_LOG_APPEND 0
40 #endif
41
42 #if USE_STORAGE_CONFIG
43
44 #include <ao_storage.h>
45
46 #define ao_config_setup()               ao_storage_setup()
47 #define ao_config_erase()               ao_storage_erase(ao_storage_config, ao_storage_block)
48 #define ao_config_write(pos,bytes, len) ao_storage_write(ao_storage_config+(pos), bytes, len)
49 #define ao_config_read(pos,bytes, len)  ao_storage_read(ao_storage_config+(pos), bytes, len)
50 #define ao_config_flush()               ao_storage_flush()
51
52 #endif
53
54 #if USE_EEPROM_CONFIG
55
56 #include <ao_eeprom.h>
57
58 #define ao_config_setup()
59 #define ao_config_erase()
60 #define ao_config_write(pos,bytes, len) ao_eeprom_write(pos, bytes, len)
61 #define ao_config_read(pos,bytes, len)  ao_eeprom_read(pos, bytes, len)
62 #define ao_config_flush()
63
64 #endif
65
66 #define AO_CONFIG_MAJOR 1
67 #define AO_CONFIG_MINOR 26
68
69 /* All cc1200 devices support limiting TX power to 10mW */
70 #if !defined(HAS_RADIO_10MW) && defined(AO_CC1200_SPI)
71 #define HAS_RADIO_10MW 1
72 #endif
73
74 #define AO_AES_LEN 16
75
76 extern uint8_t ao_config_aes_seq;
77
78 struct ao_config {
79         uint8_t         major;
80         uint8_t         minor;
81         uint16_t        main_deploy;
82         int16_t         accel_plus_g;           /* changed for minor version 2 */
83         uint8_t         _legacy_radio_channel;
84         char            callsign[AO_MAX_CALLSIGN + 1];
85         uint8_t         apogee_delay;           /* minor version 1 */
86         int16_t         accel_minus_g;          /* minor version 2 */
87         uint32_t        radio_cal;              /* minor version 3 */
88         uint32_t        flight_log_max;         /* minor version 4 */
89         uint8_t         ignite_mode;            /* minor version 5 */
90         uint8_t         pad_orientation;        /* minor version 6 */
91         uint32_t        radio_setting;          /* minor version 7 */
92         uint8_t         radio_enable;           /* minor version 8 */
93         uint8_t         aes_key[AO_AES_LEN];    /* minor version 9 */
94         uint32_t        frequency;              /* minor version 10 */
95         uint16_t        apogee_lockout;         /* minor version 11 */
96 #if AO_PYRO_NUM
97         struct ao_pyro  pyro[AO_PYRO_NUM];      /* minor version 12 */
98 #endif
99         uint16_t        aprs_interval;          /* minor version 13 */
100 #if HAS_RADIO_POWER
101         uint8_t         radio_power;            /* minor version 14 */
102 #endif
103 #if HAS_RADIO_AMP
104         uint8_t         radio_amp;              /* minor version 14 */
105 #endif
106 #if HAS_IMU
107         int16_t         accel_zero_along;       /* minor version 15 */
108         int16_t         accel_zero_across;      /* minor version 15 */
109         int16_t         accel_zero_through;     /* minor version 15 */
110 #endif
111 #if HAS_BEEP
112         uint8_t         mid_beep;               /* minor version 16 */
113 #endif
114 #if HAS_TRACKER
115         uint16_t        tracker_motion;         /* minor version 17 */
116         uint8_t         tracker_interval;       /* minor version 17 */
117 #endif
118 #if AO_PYRO_NUM
119         uint16_t        pyro_time;              /* minor version 18 */
120 #endif
121 #if HAS_APRS
122         uint8_t         aprs_ssid;              /* minor version 19 */
123 #endif
124 #if HAS_RADIO_RATE
125         uint8_t         radio_rate;             /* minor version 20 */
126 #endif
127 #if HAS_RADIO_FORWARD
128         uint32_t        send_frequency;         /* minor version 21 */
129 #endif
130 #if HAS_APRS
131         uint8_t         aprs_format;            /* minor version 22 */
132 #endif
133 #if HAS_FIXED_PAD_BOX
134         uint8_t         pad_box;                /* minor version 22 */
135         uint8_t         pad_idle;               /* minor version 23 */
136 #endif
137 #if HAS_APRS
138         uint8_t         aprs_offset;            /* minor version 24 */
139 #endif
140 #if HAS_RADIO_10MW
141         uint8_t         radio_10mw;             /* minor version 25 */
142 #endif
143         uint8_t         report_feet;            /* minor version 26 */
144 };
145
146 struct ao_config_1_24 {
147         uint8_t         major;
148         uint8_t         minor;
149         uint16_t        main_deploy;
150         int16_t         accel_plus_g;           /* changed for minor version 2 */
151         uint8_t         _legacy_radio_channel;
152         char            callsign[AO_MAX_CALLSIGN + 1];
153         uint8_t         apogee_delay;           /* minor version 1 */
154         int16_t         accel_minus_g;          /* minor version 2 */
155         uint32_t        radio_cal;              /* minor version 3 */
156         uint32_t        flight_log_max;         /* minor version 4 */
157         uint8_t         ignite_mode;            /* minor version 5 */
158         uint8_t         pad_orientation;        /* minor version 6 */
159         uint32_t        radio_setting;          /* minor version 7 */
160         uint8_t         radio_enable;           /* minor version 8 */
161         uint8_t         aes_key[AO_AES_LEN];    /* minor version 9 */
162         uint32_t        frequency;              /* minor version 10 */
163         uint16_t        apogee_lockout;         /* minor version 11 */
164 #if AO_PYRO_NUM
165         struct ao_pyro_1_24     pyro[AO_PYRO_NUM];      /* minor version 12 */
166 #endif
167         uint16_t        aprs_interval;          /* minor version 13 */
168 #if HAS_RADIO_POWER
169         uint8_t         radio_power;            /* minor version 14 */
170 #endif
171 #if HAS_RADIO_AMP
172         uint8_t         radio_amp;              /* minor version 14 */
173 #endif
174 #if HAS_IMU
175         int16_t         accel_zero_along;       /* minor version 15 */
176         int16_t         accel_zero_across;      /* minor version 15 */
177         int16_t         accel_zero_through;     /* minor version 15 */
178 #endif
179 #if HAS_BEEP
180         uint8_t         mid_beep;               /* minor version 16 */
181 #endif
182 #if HAS_TRACKER
183         uint16_t        tracker_motion;         /* minor version 17 */
184         uint8_t         tracker_interval;       /* minor version 17 */
185 #endif
186 #if AO_PYRO_NUM
187         uint16_t        pyro_time;              /* minor version 18 */
188 #endif
189 #if HAS_APRS
190         uint8_t         aprs_ssid;              /* minor version 19 */
191 #endif
192 #if HAS_RADIO_RATE
193         uint8_t         radio_rate;             /* minor version 20 */
194 #endif
195 #if HAS_RADIO_FORWARD
196         uint32_t        send_frequency;         /* minor version 21 */
197 #endif
198 #if HAS_APRS
199         uint8_t         aprs_format;            /* minor version 22 */
200 #endif
201 #if HAS_FIXED_PAD_BOX
202         uint8_t         pad_box;                /* minor version 22 */
203         uint8_t         pad_idle;               /* minor version 23 */
204 #endif
205 #if HAS_APRS
206         uint8_t         aprs_offset;            /* minor version 24 */
207 #endif
208 };
209
210 #define AO_APRS_FORMAT_COMPRESSED       0
211 #define AO_APRS_FORMAT_UNCOMPRESSED     1
212 #define AO_CONFIG_DEFAULT_APRS_FORMAT   AO_APRS_FORMAT_COMPRESSED
213
214 #if HAS_RADIO_FORWARD
215 extern uint32_t ao_send_radio_setting;
216 #endif
217
218 #define AO_IGNITE_MODE_DUAL             0
219 #define AO_IGNITE_MODE_APOGEE           1
220 #define AO_IGNITE_MODE_MAIN             2
221 #define AO_IGNITE_MODE_BOOSTER          3
222
223 #define AO_RADIO_ENABLE_CORE            1
224 #define AO_RADIO_DISABLE_TELEMETRY      2
225 #define AO_RADIO_DISABLE_RDF            4
226
227 #define AO_PAD_ORIENTATION_ANTENNA_UP   0
228 #define AO_PAD_ORIENTATION_ANTENNA_DOWN 1
229
230 #ifndef AO_CONFIG_MAX_SIZE
231 #define AO_CONFIG_MAX_SIZE      128
232 #endif
233
234 /* Make sure AO_CONFIG_MAX_SIZE is big enough */
235 typedef uint8_t config_check_space[(int) (AO_CONFIG_MAX_SIZE - sizeof (struct ao_config))];
236
237 extern struct ao_config ao_config;
238 extern uint8_t ao_config_loaded;
239
240 void
241 _ao_config_edit_start(void);
242
243 void
244 _ao_config_edit_finish(void);
245
246 void
247 ao_config_get(void);
248
249 void
250 ao_config_put(void);
251
252 void
253 ao_config_set_radio(void);
254
255 void
256 ao_config_log_fix_append(void);
257
258 void
259 ao_config_init(void);
260
261 #endif /* _AO_CONFIG_H_ */