Rev 1761 | Rev 1769 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1622 | killagreg | 1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) Holger Buss, Ingo Busker |
||
3 | // + Nur für den privaten Gebrauch |
||
4 | // + porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
||
5 | // + www.MikroKopter.com |
||
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
7 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
||
8 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
||
9 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
||
10 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
||
11 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
||
12 | // + Verkauf von Luftbildaufnahmen, usw. |
||
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
14 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
||
15 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
||
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
17 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
||
18 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
||
19 | // + eindeutig als Ursprung verlinkt werden |
||
20 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
21 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
||
22 | // + Benutzung auf eigene Gefahr |
||
23 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
||
24 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
25 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
||
26 | // + mit unserer Zustimmung zulässig |
||
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
28 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
||
29 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
30 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
||
31 | // + this list of conditions and the following disclaimer. |
||
32 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
||
33 | // + from this software without specific prior written permission. |
||
34 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
||
35 | // + for non-commercial use (directly or indirectly) |
||
36 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
||
37 | // + with our written permission |
||
38 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
||
39 | // + clearly linked as origin |
||
40 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
||
41 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
42 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
43 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
44 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
45 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
46 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
47 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
48 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
49 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
50 | // + POSSIBILITY OF SUCH DAMAGE. |
||
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
52 | |||
395 | hbuss | 53 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1622 | killagreg | 54 | // + Contant Values |
55 | // + 0-250 -> normale Values |
||
56 | // + 251 -> Poti1 |
||
57 | // + 252 -> Poti2 |
||
395 | hbuss | 58 | // + 253 -> Poti3 |
1622 | killagreg | 59 | // + 254 -> Poti4 |
395 | hbuss | 60 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1622 | killagreg | 61 | |
62 | #ifndef EEMEM |
||
63 | #define EEMEM __attribute__ ((section (".eeprom"))) |
||
64 | #endif |
||
65 | |||
66 | |||
67 | #include <avr/eeprom.h> |
||
68 | #include <string.h> |
||
69 | #include "eeprom.h" |
||
70 | #include "uart.h" |
||
71 | #include "led.h" |
||
72 | #include "main.h" |
||
73 | #include "fc.h" |
||
1657 | killagreg | 74 | #include "twimaster.h" |
1622 | killagreg | 75 | |
76 | paramset_t EE_Parameter; |
||
77 | MixerTable_t Mixer; |
||
1654 | killagreg | 78 | uint8_t RequiredMotors; |
1622 | killagreg | 79 | |
80 | |||
81 | uint8_t RAM_Checksum(uint8_t* pBuffer, uint16_t len) |
||
395 | hbuss | 82 | { |
1622 | killagreg | 83 | uint8_t crc = 0xAA; |
84 | uint16_t i; |
||
85 | |||
86 | for(i=0; i<len; i++) |
||
87 | { |
||
88 | crc += pBuffer[i]; |
||
89 | } |
||
90 | return crc; |
||
993 | hbuss | 91 | } |
92 | |||
1622 | killagreg | 93 | uint8_t EEProm_Checksum(uint16_t EEAddr, uint16_t len) |
993 | hbuss | 94 | { |
1622 | killagreg | 95 | uint8_t crc = 0xAA; |
96 | uint16_t off; |
||
97 | |||
98 | for(off=0; off<len; off++) |
||
99 | { |
||
100 | crc += eeprom_read_byte((uint8_t*)(EEAddr + off));; |
||
101 | } |
||
102 | return crc; |
||
395 | hbuss | 103 | } |
1622 | killagreg | 104 | |
105 | void ParamSet_DefaultStickMapping(void) |
||
395 | hbuss | 106 | { |
1622 | killagreg | 107 | EE_Parameter.Kanalbelegung[K_GAS] = 1; |
108 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
||
109 | EE_Parameter.Kanalbelegung[K_NICK] = 3; |
||
110 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
||
111 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
||
112 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
||
113 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
||
114 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
||
115 | EE_Parameter.Kanalbelegung[K_POTI5] = 9; |
||
116 | EE_Parameter.Kanalbelegung[K_POTI6] = 10; |
||
117 | EE_Parameter.Kanalbelegung[K_POTI7] = 11; |
||
118 | EE_Parameter.Kanalbelegung[K_POTI8] = 12; |
||
395 | hbuss | 119 | } |
120 | |||
1622 | killagreg | 121 | |
122 | /***************************************************/ |
||
123 | /* Default Values for parameter set 1 */ |
||
124 | /***************************************************/ |
||
1760 | holgerb | 125 | void CommonDefaults(void) |
395 | hbuss | 126 | { |
1622 | killagreg | 127 | EE_Parameter.Revision = EEPARAM_REVISION; |
128 | |||
129 | if(PlatinenVersion >= 20) |
||
130 | { |
||
1676 | holgerb | 131 | EE_Parameter.Gyro_D = 10; |
1622 | killagreg | 132 | EE_Parameter.Driftkomp = 0; |
133 | EE_Parameter.GyroAccFaktor = 27; |
||
134 | EE_Parameter.WinkelUmschlagNick = 78; |
||
135 | EE_Parameter.WinkelUmschlagRoll = 78; |
||
136 | } |
||
137 | else |
||
138 | { |
||
139 | EE_Parameter.Gyro_D = 3; |
||
140 | EE_Parameter.Driftkomp = 32; |
||
141 | EE_Parameter.GyroAccFaktor = 30; |
||
142 | EE_Parameter.WinkelUmschlagNick = 85; |
||
143 | EE_Parameter.WinkelUmschlagRoll = 85; |
||
144 | } |
||
1762 | holgerb | 145 | EE_Parameter.GlobalConfig = CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER; |
146 | EE_Parameter.ExtraConfig = CFG2_HEIGHT_LIMIT | CFG2_VARIO_BEEP; |
||
147 | EE_Parameter.Receiver = RECEIVER_SPEKTRUM; |
||
148 | EE_Parameter.MotorSafetySwitch = 0; |
||
1760 | holgerb | 149 | |
1762 | holgerb | 150 | EE_Parameter.Gas_Min = 8; // Wert : 0-32 |
151 | EE_Parameter.Gas_Max = 230; // Wert : 33-247 |
||
152 | EE_Parameter.KompassWirkung = 128; // Wert : 0-247 |
||
153 | |||
154 | EE_Parameter.Hoehe_MinGas = 30; |
||
155 | EE_Parameter.MaxHoehe = 255; // Wert : 0-247 255 -> Poti1 |
||
156 | EE_Parameter.Hoehe_P = 15; // Wert : 0-32 |
||
157 | EE_Parameter.Luftdruck_D = 30; // Wert : 0-247 |
||
158 | EE_Parameter.Hoehe_ACC_Wirkung = 0; // Wert : 0-247 |
||
159 | EE_Parameter.Hoehe_HoverBand = 8; // Wert : 0-247 |
||
160 | EE_Parameter.Hoehe_GPS_Z = 64; // Wert : 0-247 |
||
161 | EE_Parameter.Hoehe_StickNeutralPoint = 0;// Wert : 0-247 (0 = Hover-Estimation) |
||
162 | EE_Parameter.Hoehe_Verstaerkung = 15; // Wert : 0-50 |
||
163 | |||
1622 | killagreg | 164 | EE_Parameter.UserParam1 = 0; // zur freien Verwendung |
165 | EE_Parameter.UserParam2 = 0; // zur freien Verwendung |
||
166 | EE_Parameter.UserParam3 = 0; // zur freien Verwendung |
||
167 | EE_Parameter.UserParam4 = 0; // zur freien Verwendung |
||
168 | EE_Parameter.UserParam5 = 0; // zur freien Verwendung |
||
169 | EE_Parameter.UserParam6 = 0; // zur freien Verwendung |
||
170 | EE_Parameter.UserParam7 = 0; // zur freien Verwendung |
||
171 | EE_Parameter.UserParam8 = 0; // zur freien Verwendung |
||
1762 | holgerb | 172 | |
1622 | killagreg | 173 | EE_Parameter.ServoNickControl = 100; // Wert : 0-247 // Stellung des Servos |
174 | EE_Parameter.ServoNickComp = 40; // Wert : 0-247 // Einfluss Gyro/Servo |
||
175 | EE_Parameter.ServoCompInvert = 1; // Wert : 0-247 // Richtung Einfluss Gyro/Servo |
||
1762 | holgerb | 176 | EE_Parameter.ServoNickMin = 15; // Wert : 0-247 // Anschlag |
177 | EE_Parameter.ServoNickMax = 255; // Wert : 0-247 // Anschlag |
||
178 | EE_Parameter.ServoNickRefresh = 5; |
||
1622 | killagreg | 179 | EE_Parameter.Servo3 = 125; |
180 | EE_Parameter.Servo4 = 125; |
||
181 | EE_Parameter.Servo5 = 125; |
||
182 | EE_Parameter.ServoRollControl = 100; // Wert : 0-247 // Stellung des Servos |
||
183 | EE_Parameter.ServoRollComp = 40; // Wert : 0-247 // Einfluss Gyro/Servo |
||
184 | EE_Parameter.ServoRollMin = 0; // Wert : 0-247 // Anschlag |
||
185 | EE_Parameter.ServoRollMax = 247; // Wert : 0-247 // Anschlag |
||
1762 | holgerb | 186 | EE_Parameter.ServoManualControlSpeed = 30; |
187 | EE_Parameter.CamOrientation = 0; |
||
188 | |||
1622 | killagreg | 189 | EE_Parameter.J16Bitmask = 95; |
190 | EE_Parameter.J17Bitmask = 243; |
||
191 | EE_Parameter.WARN_J16_Bitmask = 0xAA; |
||
192 | EE_Parameter.WARN_J17_Bitmask = 0xAA; |
||
1760 | holgerb | 193 | EE_Parameter.J16Timing = 20; |
194 | EE_Parameter.J17Timing = 20; |
||
1762 | holgerb | 195 | |
196 | EE_Parameter.LoopGasLimit = 50; |
||
197 | EE_Parameter.LoopThreshold = 90; // Wert: 0-247 Schwelle für Stickausschlag |
||
198 | EE_Parameter.LoopHysterese = 50; |
||
199 | EE_Parameter.BitConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts / wird getrennt behandelt |
||
200 | |||
1622 | killagreg | 201 | EE_Parameter.NaviGpsModeControl = 254; // 254 -> Poti 2 |
202 | EE_Parameter.NaviGpsGain = 100; |
||
203 | EE_Parameter.NaviGpsP = 90; |
||
204 | EE_Parameter.NaviGpsI = 90; |
||
205 | EE_Parameter.NaviGpsD = 90; |
||
206 | EE_Parameter.NaviGpsPLimit = 75; |
||
207 | EE_Parameter.NaviGpsILimit = 75; |
||
208 | EE_Parameter.NaviGpsDLimit = 75; |
||
209 | EE_Parameter.NaviGpsACC = 0; |
||
210 | EE_Parameter.NaviGpsMinSat = 6; |
||
211 | EE_Parameter.NaviStickThreshold = 8; |
||
212 | EE_Parameter.NaviWindCorrection = 90; |
||
213 | EE_Parameter.NaviSpeedCompensation = 30; |
||
214 | EE_Parameter.NaviOperatingRadius = 100; |
||
215 | EE_Parameter.NaviAngleLimitation = 100; |
||
1664 | holgerb | 216 | EE_Parameter.NaviPH_LoginTime = 2; |
1668 | holgerb | 217 | EE_Parameter.OrientationAngle = 0; |
218 | EE_Parameter.OrientationModeControl = 0; |
||
1760 | holgerb | 219 | EE_Parameter.UnterspannungsWarnung = 33; // Wert : 0-247 ( Automatische Zellenerkennung bei < 50) |
220 | EE_Parameter.NotGas = 45; // Wert : 0-247 // Gaswert bei Empangsverlust |
||
221 | EE_Parameter.NotGasZeit = 90; // Wert : 0-247 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
||
222 | } |
||
223 | |||
224 | void ParamSet_DefaultSet1(void) // sport |
||
225 | { |
||
226 | CommonDefaults(); |
||
227 | EE_Parameter.Stick_P = 14; // Wert : 1-20 |
||
228 | EE_Parameter.Stick_D = 16; // Wert : 0-20 |
||
229 | EE_Parameter.Gier_P = 12; // Wert : 1-20 |
||
230 | EE_Parameter.Gyro_P = 80; // Wert : 0-247 |
||
231 | EE_Parameter.Gyro_I = 150; // Wert : 0-247 |
||
232 | EE_Parameter.Gyro_Gier_P = 80; // Wert : 0-247 |
||
233 | EE_Parameter.Gyro_Gier_I = 150; // Wert : 0-247 |
||
234 | EE_Parameter.Gyro_Stability = 6; // Wert : 1-8 |
||
235 | EE_Parameter.I_Faktor = 32; |
||
236 | EE_Parameter.AchsKopplung1 = 90; |
||
237 | EE_Parameter.AchsKopplung2 = 80; |
||
238 | EE_Parameter.CouplingYawCorrection = 1; |
||
239 | EE_Parameter.GyroAccAbgleich = 16; // 1/k; |
||
240 | EE_Parameter.DynamicStability = 100; |
||
1622 | killagreg | 241 | memcpy(EE_Parameter.Name, "Sport\0", 12); |
242 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
||
395 | hbuss | 243 | } |
1622 | killagreg | 244 | |
245 | |||
246 | /***************************************************/ |
||
247 | /* Default Values for parameter set 2 */ |
||
248 | /***************************************************/ |
||
249 | void ParamSet_DefaultSet2(void) // normal |
||
250 | { |
||
1760 | holgerb | 251 | CommonDefaults(); |
1664 | holgerb | 252 | EE_Parameter.Stick_P = 10; // Wert : 1-20 |
253 | EE_Parameter.Stick_D = 16; // Wert : 0-20 |
||
1622 | killagreg | 254 | EE_Parameter.Gier_P = 6; // Wert : 1-20 |
255 | EE_Parameter.Gyro_P = 90; // Wert : 0-247 |
||
256 | EE_Parameter.Gyro_I = 120; // Wert : 0-247 |
||
257 | EE_Parameter.Gyro_Gier_P = 90; // Wert : 0-247 |
||
258 | EE_Parameter.Gyro_Gier_I = 120; // Wert : 0-247 |
||
1685 | holgerb | 259 | EE_Parameter.Gyro_Stability = 6; // Wert : 1-8 |
1622 | killagreg | 260 | EE_Parameter.I_Faktor = 32; |
261 | EE_Parameter.AchsKopplung1 = 90; |
||
262 | EE_Parameter.AchsKopplung2 = 80; |
||
263 | EE_Parameter.CouplingYawCorrection = 60; |
||
264 | EE_Parameter.GyroAccAbgleich = 32; // 1/k |
||
265 | EE_Parameter.DynamicStability = 75; |
||
266 | memcpy(EE_Parameter.Name, "Normal\0", 12); |
||
267 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
||
268 | } |
||
269 | |||
270 | |||
271 | /***************************************************/ |
||
272 | /* Default Values for parameter set 3 */ |
||
273 | /***************************************************/ |
||
274 | void ParamSet_DefaultSet3(void) // beginner |
||
275 | { |
||
1762 | holgerb | 276 | CommonDefaults(); |
1664 | holgerb | 277 | EE_Parameter.Stick_P = 8; // Wert : 1-20 |
278 | EE_Parameter.Stick_D = 16; // Wert : 0-20 |
||
1622 | killagreg | 279 | EE_Parameter.Gier_P = 6; // Wert : 1-20 |
280 | EE_Parameter.Gyro_P = 100; // Wert : 0-247 |
||
281 | EE_Parameter.Gyro_I = 120; // Wert : 0-247 |
||
282 | EE_Parameter.Gyro_Gier_P = 100; // Wert : 0-247 |
||
283 | EE_Parameter.Gyro_Gier_I = 120; // Wert : 0-247 |
||
1685 | holgerb | 284 | EE_Parameter.Gyro_Stability = 6; // Wert : 1-8 |
1622 | killagreg | 285 | EE_Parameter.I_Faktor = 16; |
286 | EE_Parameter.AchsKopplung1 = 90; |
||
287 | EE_Parameter.AchsKopplung2 = 80; |
||
288 | EE_Parameter.CouplingYawCorrection = 70; |
||
289 | EE_Parameter.GyroAccAbgleich = 32; // 1/k |
||
1690 | holgerb | 290 | EE_Parameter.DynamicStability = 70; |
1622 | killagreg | 291 | memcpy(EE_Parameter.Name, "Beginner\0", 12); |
292 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
||
293 | } |
||
294 | |||
295 | /***************************************************/ |
||
296 | /* Read Parameter from EEPROM as byte */ |
||
297 | /***************************************************/ |
||
298 | uint8_t GetParamByte(uint16_t param_id) |
||
299 | { |
||
300 | return eeprom_read_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + param_id)); |
||
301 | } |
||
302 | |||
303 | /***************************************************/ |
||
304 | /* Write Parameter to EEPROM as byte */ |
||
305 | /***************************************************/ |
||
306 | void SetParamByte(uint16_t param_id, uint8_t value) |
||
307 | { |
||
308 | eeprom_write_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + param_id), value); |
||
309 | } |
||
310 | |||
311 | /***************************************************/ |
||
312 | /* Read Parameter from EEPROM as word */ |
||
313 | /***************************************************/ |
||
314 | uint16_t GetParamWord(uint16_t param_id) |
||
315 | { |
||
316 | return eeprom_read_word((uint16_t *)(EEPROM_ADR_PARAM_BEGIN + param_id)); |
||
317 | } |
||
318 | |||
319 | /***************************************************/ |
||
320 | /* Write Parameter to EEPROM as word */ |
||
321 | /***************************************************/ |
||
322 | void SetParamWord(uint16_t param_id, uint16_t value) |
||
323 | { |
||
324 | eeprom_write_word((uint16_t*)(EEPROM_ADR_PARAM_BEGIN + param_id), value); |
||
325 | } |
||
326 | |||
327 | /***************************************************/ |
||
328 | /* Read Parameter Set from EEPROM */ |
||
329 | /***************************************************/ |
||
330 | // number [1..5] |
||
331 | uint8_t ParamSet_ReadFromEEProm(uint8_t setnumber) |
||
332 | { |
||
333 | uint8_t crc; |
||
334 | uint16_t eeaddr; |
||
335 | |||
336 | // range the setnumber |
||
337 | if((1 > setnumber) || (setnumber > 5)) setnumber = 3; |
||
338 | |||
339 | // calculate eeprom addr |
||
340 | eeaddr = EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1); |
||
341 | |||
342 | // calculate checksum from eeprom |
||
343 | crc = EEProm_Checksum(eeaddr, PARAMSET_STRUCT_LEN - 1); |
||
344 | |||
345 | // check crc |
||
346 | if(crc != eeprom_read_byte((uint8_t*)(eeaddr + PARAMSET_STRUCT_LEN - 1))) return 0; |
||
347 | |||
348 | // check revision |
||
349 | if(eeprom_read_byte((uint8_t*)(eeaddr)) != EEPARAM_REVISION) return 0; |
||
350 | |||
351 | // read paramset from eeprom |
||
352 | eeprom_read_block((void *) &EE_Parameter, (void*)(EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN); |
||
353 | LED_Init(); |
||
354 | return 1; |
||
355 | } |
||
356 | |||
357 | /***************************************************/ |
||
358 | /* Write Parameter Set to EEPROM */ |
||
359 | /***************************************************/ |
||
360 | // number [1..5] |
||
361 | uint8_t ParamSet_WriteToEEProm(uint8_t setnumber) |
||
362 | { |
||
363 | uint8_t crc; |
||
364 | |||
365 | if(EE_Parameter.Revision == EEPARAM_REVISION) // write only the right revision to eeprom |
||
366 | { |
||
367 | if(setnumber > 5) setnumber = 5; |
||
368 | if(setnumber < 1) return 0; |
||
369 | |||
370 | // update checksum |
||
371 | EE_Parameter.crc = RAM_Checksum((uint8_t*)(&EE_Parameter), sizeof(EE_Parameter)-1); |
||
372 | |||
373 | // write paramset to eeprom |
||
374 | eeprom_write_block((void *) &EE_Parameter, (void*)(EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN); |
||
375 | |||
376 | // backup channel settings to separate block in eeprom |
||
377 | eeprom_write_block( (void*)(EE_Parameter.Kanalbelegung), (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung)); |
||
378 | |||
379 | // write crc of channel block to eeprom |
||
380 | crc = RAM_Checksum((uint8_t*)(EE_Parameter.Kanalbelegung), sizeof(EE_Parameter.Kanalbelegung)); |
||
381 | eeprom_write_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung)), crc); |
||
382 | |||
383 | // update active settings number |
||
384 | SetActiveParamSet(setnumber); |
||
385 | LED_Init(); |
||
386 | return 1; |
||
387 | } |
||
388 | // wrong revision |
||
389 | return 0; |
||
390 | } |
||
391 | |||
392 | /***************************************************/ |
||
393 | /* Read MixerTable from EEPROM */ |
||
394 | /***************************************************/ |
||
395 | uint8_t MixerTable_ReadFromEEProm(void) |
||
396 | { |
||
397 | uint8_t crc; |
||
398 | |||
399 | // calculate checksum in eeprom |
||
400 | crc = EEProm_Checksum(EEPROM_ADR_MIXERTABLE, sizeof(Mixer) - 1); |
||
401 | |||
402 | // check crc |
||
403 | if( crc != eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXERTABLE + sizeof(Mixer) - 1)) ) return 0; |
||
404 | |||
405 | // check revision |
||
406 | if(eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXERTABLE)) != EEMIXER_REVISION) return 0; |
||
407 | |||
408 | // read mixer table |
||
409 | eeprom_read_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXERTABLE), sizeof(Mixer)); |
||
410 | return 1; |
||
411 | } |
||
412 | |||
413 | /***************************************************/ |
||
414 | /* Write Mixer Table to EEPROM */ |
||
415 | /***************************************************/ |
||
416 | uint8_t MixerTable_WriteToEEProm(void) |
||
417 | { |
||
418 | if(Mixer.Revision == EEMIXER_REVISION) |
||
419 | { |
||
420 | // update crc |
||
421 | Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1); |
||
422 | |||
423 | // write to eeprom |
||
424 | eeprom_write_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXERTABLE), sizeof(Mixer)); |
||
425 | return 1; |
||
426 | } |
||
427 | else return 0; |
||
428 | } |
||
429 | |||
430 | /***************************************************/ |
||
431 | /* Default Values for Mixer Table */ |
||
432 | /***************************************************/ |
||
433 | void MixerTable_Default(void) // Quadro |
||
434 | { |
||
435 | uint8_t i; |
||
436 | |||
437 | Mixer.Revision = EEMIXER_REVISION; |
||
438 | // clear mixer table |
||
439 | for(i = 0; i < 16; i++) |
||
440 | { |
||
441 | Mixer.Motor[i][MIX_GAS] = 0; |
||
442 | Mixer.Motor[i][MIX_NICK] = 0; |
||
443 | Mixer.Motor[i][MIX_ROLL] = 0; |
||
444 | Mixer.Motor[i][MIX_YAW] = 0; |
||
445 | } |
||
446 | // default = Quadro |
||
447 | Mixer.Motor[0][MIX_GAS] = 64; Mixer.Motor[0][MIX_NICK] = +64; Mixer.Motor[0][MIX_ROLL] = 0; Mixer.Motor[0][MIX_YAW] = +64; |
||
448 | Mixer.Motor[1][MIX_GAS] = 64; Mixer.Motor[1][MIX_NICK] = -64; Mixer.Motor[1][MIX_ROLL] = 0; Mixer.Motor[1][MIX_YAW] = +64; |
||
449 | Mixer.Motor[2][MIX_GAS] = 64; Mixer.Motor[2][MIX_NICK] = 0; Mixer.Motor[2][MIX_ROLL] = -64; Mixer.Motor[2][MIX_YAW] = -64; |
||
450 | Mixer.Motor[3][MIX_GAS] = 64; Mixer.Motor[3][MIX_NICK] = 0; Mixer.Motor[3][MIX_ROLL] = +64; Mixer.Motor[3][MIX_YAW] = -64; |
||
451 | memcpy(Mixer.Name, "Quadro\0", 7); |
||
452 | Mixer.crc = Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1); |
||
453 | } |
||
454 | |||
455 | /***************************************************/ |
||
456 | /* Get active parameter set */ |
||
457 | /***************************************************/ |
||
458 | uint8_t GetActiveParamSet(void) |
||
459 | { |
||
460 | uint8_t setnumber; |
||
461 | setnumber = eeprom_read_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + PID_ACTIVE_SET)); |
||
462 | if(setnumber > 5) |
||
463 | { |
||
464 | setnumber = 3; |
||
465 | eeprom_write_byte((void*)(EEPROM_ADR_PARAM_BEGIN+PID_ACTIVE_SET), setnumber); |
||
466 | } |
||
467 | return(setnumber); |
||
468 | } |
||
469 | |||
470 | /***************************************************/ |
||
471 | /* Set active parameter set */ |
||
472 | /***************************************************/ |
||
473 | void SetActiveParamSet(uint8_t setnumber) |
||
474 | { |
||
475 | if(setnumber > 5) setnumber = 5; |
||
476 | if(setnumber < 1) setnumber = 1; |
||
477 | eeprom_write_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + PID_ACTIVE_SET), setnumber); |
||
478 | } |
||
479 | |||
480 | /***************************************************/ |
||
1761 | killagreg | 481 | /* Set default parameter set */ |
482 | /***************************************************/ |
||
483 | void SetDefaultParameter(uint8_t set, uint8_t restore_channels) |
||
484 | { |
||
485 | |||
486 | if(set > 5) set = 5; |
||
487 | else if(set < 1) set = 1; |
||
488 | |||
489 | switch(set) |
||
490 | { |
||
491 | case 1: |
||
492 | ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport) |
||
493 | break; |
||
494 | case 2: |
||
495 | ParamSet_DefaultSet2(); // Kamera |
||
496 | break; |
||
497 | case 3: |
||
498 | ParamSet_DefaultSet3(); // Beginner |
||
499 | break; |
||
500 | default: |
||
501 | ParamSet_DefaultSet3(); // Beginner |
||
502 | break; |
||
503 | } |
||
504 | if(restore_channels) |
||
505 | { |
||
506 | uint8_t crc; |
||
507 | // 1st check for a valid channel backup in eeprom |
||
508 | crc = EEProm_Checksum(EEPROM_ADR_CHANNELS, sizeof(EE_Parameter.Kanalbelegung)); |
||
509 | if(crc == eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung))) ) |
||
510 | { |
||
511 | eeprom_read_block((void *)EE_Parameter.Kanalbelegung, (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung)); |
||
512 | } |
||
513 | else ParamSet_DefaultStickMapping(); |
||
514 | } |
||
515 | else ParamSet_DefaultStickMapping(); |
||
516 | ParamSet_WriteToEEProm(set); |
||
517 | } |
||
518 | |||
519 | /***************************************************/ |
||
1622 | killagreg | 520 | /* Initialize EEPROM Parameter Sets */ |
521 | /***************************************************/ |
||
522 | void ParamSet_Init(void) |
||
523 | { |
||
524 | uint8_t channel_backup = 0, bad_params = 0, ee_default = 0,i; |
||
525 | |||
526 | |||
527 | if(EEPARAM_REVISION != GetParamByte(PID_EE_REVISION) ) |
||
528 | { |
||
529 | ee_default = 1; // software update or forced by mktool |
||
530 | SetParamByte(PID_EE_REVISION, EEPARAM_REVISION); |
||
531 | } |
||
532 | |||
533 | |||
534 | // 1st check for a valid channel backup in eeprom |
||
535 | i = EEProm_Checksum(EEPROM_ADR_CHANNELS, sizeof(EE_Parameter.Kanalbelegung)); |
||
536 | if(i == eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(EE_Parameter.Kanalbelegung))) ) channel_backup = 1; |
||
537 | |||
538 | |||
539 | // parameter check |
||
540 | |||
541 | // check all 5 parameter settings |
||
542 | for (i = 1;i < 6; i++) |
||
543 | { |
||
544 | if(ee_default || !ParamSet_ReadFromEEProm(i)) // could not read paramset from eeprom |
||
545 | { |
||
546 | bad_params = 1; |
||
547 | printf("\n\rGenerating default Parameter Set %d",i); |
||
548 | switch(i) |
||
549 | { |
||
550 | case 1: |
||
551 | ParamSet_DefaultSet1(); // Fill ParamSet Structure to default parameter set 1 (Sport) |
||
552 | break; |
||
553 | case 2: |
||
554 | ParamSet_DefaultSet2(); // Kamera |
||
555 | break; |
||
556 | case 3: |
||
557 | ParamSet_DefaultSet3(); // Beginner |
||
558 | break; |
||
559 | default: |
||
1668 | holgerb | 560 | ParamSet_DefaultSet3(); // Kamera |
1622 | killagreg | 561 | break; |
562 | } |
||
563 | if(channel_backup) // if we have an channel mapping backup in eeprom |
||
564 | { // restore it from eeprom |
||
565 | eeprom_read_block((void *)EE_Parameter.Kanalbelegung, (void*)(EEPROM_ADR_CHANNELS), sizeof(EE_Parameter.Kanalbelegung)); |
||
566 | } |
||
567 | else |
||
568 | { // use default mapping |
||
569 | ParamSet_DefaultStickMapping(); |
||
570 | } |
||
571 | ParamSet_WriteToEEProm(i); |
||
572 | } |
||
573 | } |
||
574 | if(bad_params) // at least one of the parameter settings were invalid |
||
575 | { |
||
576 | // default-Setting is parameter set 3 |
||
577 | SetActiveParamSet(3); |
||
578 | } |
||
579 | |||
580 | |||
581 | // read active parameter set to ParamSet stucture |
||
582 | i = GetActiveParamSet(); |
||
583 | ParamSet_ReadFromEEProm(i); |
||
584 | printf("\n\rUsing Parameter Set %d", i); |
||
585 | |||
586 | // load mixer table |
||
587 | if(ee_default || !MixerTable_ReadFromEEProm() ) |
||
588 | { |
||
589 | printf("\n\rGenerating default Mixer Table"); |
||
590 | MixerTable_Default(); // Quadro |
||
591 | MixerTable_WriteToEEProm(); |
||
592 | } |
||
593 | // determine motornumber |
||
594 | RequiredMotors = 0; |
||
595 | for(i = 0; i < 16; i++) |
||
596 | { |
||
597 | if(Mixer.Motor[i][MIX_GAS] > 0) RequiredMotors++; |
||
598 | } |
||
599 | |||
600 | printf("\n\rMixer-Config: '%s' (%u Motors)",Mixer.Name, RequiredMotors); |
||
601 | printf("\n\r=============================="); |
||
602 | } |