Subversion Repositories FlightCtrl

Rev

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

Rev 1968 Rev 1969
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + Copyright (c) 04.2007 Holger Buss
2
// + Copyright (c) 04.2007 Holger Buss
3
// + Nur für den privaten Gebrauch
3
// + Nur für den privaten Gebrauch
4
// + www.MikroKopter.com
4
// + www.MikroKopter.com
5
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
6
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
7
// + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist.
7
// + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist.
8
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
8
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
9
// + bzgl. der Nutzungsbedingungen aufzunehmen.
9
// + bzgl. der Nutzungsbedingungen aufzunehmen.
10
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
10
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
11
// + Verkauf von Luftbildaufnahmen, usw.
11
// + Verkauf von Luftbildaufnahmen, usw.
12
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
13
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
14
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
14
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
16
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
17
// + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
17
// + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
18
// + eindeutig als Ursprung verlinkt und genannt werden
18
// + eindeutig als Ursprung verlinkt und genannt werden
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
20
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
21
// + Benutzung auf eigene Gefahr
21
// + Benutzung auf eigene Gefahr
22
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
22
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
24
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
25
// + mit unserer Zustimmung zulässig
25
// + mit unserer Zustimmung zulässig
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
27
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
29
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
30
// + this list of conditions and the following disclaimer.
30
// + this list of conditions and the following disclaimer.
31
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
31
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
32
// +     from this software without specific prior written permission.
32
// +     from this software without specific prior written permission.
33
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
33
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
34
// +     for non-commercial use (directly or indirectly)
34
// +     for non-commercial use (directly or indirectly)
35
// +     Commercial use (for example: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
35
// +     Commercial use (for example: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
36
// +     with our written permission
36
// +     with our written permission
37
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
37
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
38
// +     clearly linked as origin
38
// +     clearly linked as origin
39
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
39
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
40
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
40
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
41
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
43
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
44
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
44
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
45
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
46
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
47
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
48
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48
// +  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
49
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
50
// +  POSSIBILITY OF SUCH DAMAGE.
50
// +  POSSIBILITY OF SUCH DAMAGE.
51
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
51
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
52
 
52
 
53
#ifndef EEMEM
53
#ifndef EEMEM
54
#define EEMEM __attribute__ ((section (".eeprom")))
54
#define EEMEM __attribute__ ((section (".eeprom")))
55
#endif
55
#endif
56
 
56
 
57
#include "eeprom.h"
57
#include "eeprom.h"
58
#include "printf_P.h"
58
#include "printf_P.h"
59
#include "output.h"
59
#include "output.h"
60
#include <avr/eeprom.h>
60
#include <avr/eeprom.h>
61
 
61
 
62
// byte array in eeprom
62
// byte array in eeprom
63
uint8_t EEPromArray[E2END + 1] EEMEM;
63
uint8_t EEPromArray[E2END + 1] EEMEM;
64
 
64
 
65
/***************************************************/
65
/***************************************************/
66
/*       Read Parameter from EEPROM as byte        */
66
/*       Read Parameter from EEPROM as byte        */
67
/***************************************************/
67
/***************************************************/
68
uint8_t getParamByte(uint16_t param_id) {
68
uint8_t getParamByte(uint16_t param_id) {
69
  return eeprom_read_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]);
69
  return eeprom_read_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]);
70
}
70
}
71
 
71
 
72
/***************************************************/
72
/***************************************************/
73
/*       Write Parameter to EEPROM as byte         */
73
/*       Write Parameter to EEPROM as byte         */
74
/***************************************************/
74
/***************************************************/
75
void setParamByte(uint16_t param_id, uint8_t value) {
75
void setParamByte(uint16_t param_id, uint8_t value) {
76
  eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value);
76
  eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value);
77
}
77
}
78
 
78
 
79
/***************************************************/
79
/***************************************************/
80
/*       Read Parameter from EEPROM as word        */
80
/*       Read Parameter from EEPROM as word        */
81
/***************************************************/
81
/***************************************************/
82
/*
82
/*
83
uint16_t getParamWord(uint16_t param_id) {
83
uint16_t getParamWord(uint16_t param_id) {
84
  return eeprom_read_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN
84
  return eeprom_read_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN
85
                                                    + param_id]);
85
                                                    + param_id]);
86
}
86
}
87
*/
87
*/
88
 
88
 
89
/***************************************************/
89
/***************************************************/
90
/*       Write Parameter to EEPROM as word         */
90
/*       Write Parameter to EEPROM as word         */
91
/***************************************************/
91
/***************************************************/
92
/*
92
/*
93
void setParamWord(uint16_t param_id, uint16_t value) {
93
void setParamWord(uint16_t param_id, uint16_t value) {
94
  eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value);
94
  eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value);
95
}
95
}
96
*/
96
*/
97
 
97
 
98
uint16_t CRC16(uint8_t* data, uint16_t length) {
98
uint16_t CRC16(uint8_t* data, uint16_t length) {
99
  uint16_t crc = 0;
99
  uint16_t crc = 0;
100
  for (uint16_t i=0; i<length; i++) {
100
  for (uint16_t i=0; i<length; i++) {
101
    crc  = (uint8_t)(crc >> 8) | (crc << 8);
101
    crc  = (uint8_t)(crc >> 8) | (crc << 8);
102
    crc ^= data[i];
102
    crc ^= data[i];
103
    crc ^= (uint8_t)(crc & 0xff) >> 4;
103
    crc ^= (uint8_t)(crc & 0xff) >> 4;
104
    crc ^= (crc << 8) << 4;
104
    crc ^= (crc << 8) << 4;
105
    crc ^= ((crc & 0xff) << 4) << 1;
105
    crc ^= ((crc & 0xff) << 4) << 1;
106
  }
106
  }
107
  return crc;
107
  return crc;
108
}
108
}
109
 
109
 
110
// offset is where the checksum is stored, offset+1 is the revision number, and offset+2... are the data.
110
// offset is where the checksum is stored, offset+1 is the revision number, and offset+2... are the data.
111
// length is the length of the pure data not including checksum and revision number.
111
// length is the length of the pure data not including checksum and revision number.
112
void writeChecksummedBlock(uint8_t revisionNumber, uint8_t* data, uint16_t offset, uint16_t length) {
112
void writeChecksummedBlock(uint8_t revisionNumber, uint8_t* data, uint16_t offset, uint16_t length) {
113
  uint16_t CRC = CRC16(data, length);
113
  uint16_t CRC = CRC16(data, length);
-
 
114
  eeprom_write_byte(&EEPromArray[offset], CRC&0xff);
114
  eeprom_write_word(&EEPromArray[offset], CRC);
115
  eeprom_write_byte(&EEPromArray[offset+1], CRC>>8);
115
  eeprom_write_byte(&EEPromArray[offset+2], revisionNumber);
116
  eeprom_write_byte(&EEPromArray[offset+2], revisionNumber);
116
  eeprom_write_block(data, &EEPromArray[offset+3], length);
117
  eeprom_write_block(data, &EEPromArray[offset+3], length);
117
}
118
}
118
 
119
 
119
// offset is where the checksum is stored, offset+1 is the revision number, and offset+2... are the data.
120
// offset is where the checksum is stored, offset+1 is the revision number, and offset+2... are the data.
120
// length is the length of the pure data not including checksum and revision number.
121
// length is the length of the pure data not including checksum and revision number.
121
uint8_t readChecksummedBlock(uint8_t revisionNumber, uint8_t* target, uint16_t offset, uint16_t length) {
122
uint8_t readChecksummedBlock(uint8_t revisionNumber, uint8_t* target, uint16_t offset, uint16_t length) {
122
  uint16_t CRCRead = eeprom_read_word(&EEPromArray[offset]);
123
  uint16_t CRCRead = eeprom_read_byte(&EEPromArray[offset]) | (eeprom_read_byte(&EEPromArray[offset+1])<<8);
123
  uint8_t revisionNumberRead = eeprom_read_byte(&EEPromArray[offset+2]);
124
  uint8_t revisionNumberRead = eeprom_read_byte(&EEPromArray[offset+2]);
124
  eeprom_read_block(target, &EEPromArray[offset+3], length);
125
  eeprom_read_block(target, &EEPromArray[offset+3], length);
125
  uint16_t CRCCalculated = CRC(target, length);
126
  uint16_t CRCCalculated = CRC16(target, length);
126
 
127
 
127
  uint8_t CRCError = (CRCRead != CRCCalculated);
128
  uint8_t CRCError = (CRCRead != CRCCalculated);
128
  uint8_t revisionMismatch = (revisionNumber != revisionNumberRead);
129
  uint8_t revisionMismatch = (revisionNumber != revisionNumberRead);
129
 
130
 
130
  if (CRCError && revisionMismatch) printf("\n\rEEPROM CRC error and revision mismatch; ");
131
  if (CRCError && revisionMismatch) printf("\n\rEEPROM CRC error and revision mismatch; ");
131
  else if (CRCError) printf("\n\rEEPROM CRC error; ");
132
  else if (CRCError) printf("\n\rEEPROM CRC error; ");
132
  else if (revisionMismatch) printf("\n\rEEPROM revision mismatch; ");
133
  else if (revisionMismatch) printf("\n\rEEPROM revision mismatch; ");
133
  return (checksumError || revisionMismatch);
134
  return (CRCError || revisionMismatch);
134
}
135
}
135
 
136
 
136
/***************************************************/
137
/***************************************************/
137
/*       Read Parameter Set from EEPROM            */
138
/*       Read Parameter Set from EEPROM            */
138
/***************************************************/
139
/***************************************************/
139
// setnumber [1..5]
140
// setnumber [1..5]
140
uint8_t paramSet_readFromEEProm(uint8_t setnumber) {
141
uint8_t paramSet_readFromEEProm(uint8_t setnumber) {
141
  uint16_t offset = EEPROM_ADR_PARAMSET_BEGIN + (setnumber-1)*(sizeof(paramset_t)+EEPROM_CHECKSUMMED_BLOCK_OVERHEAD);
142
  uint16_t offset = EEPROM_ADR_PARAMSET_BEGIN + (setnumber-1)*(sizeof(paramset_t)+EEPROM_CHECKSUMMED_BLOCK_OVERHEAD);
142
  output_init(); // what's that doing here??
143
  output_init(); // what's that doing here??
143
  return readChecksummedBlock(EEPARAM_REVISION, (uint8_t*)&staticParams, offset, sizeof(paramset_t));
144
  return readChecksummedBlock(EEPARAM_REVISION, (uint8_t*)&staticParams, offset, sizeof(paramset_t));
144
}
145
}
145
 
146
 
146
/***************************************************/
147
/***************************************************/
147
/*        Write Parameter Set to EEPROM            */
148
/*        Write Parameter Set to EEPROM            */
148
/***************************************************/
149
/***************************************************/
149
void paramSet_writeToEEProm(uint8_t setnumber) {
150
void paramSet_writeToEEProm(uint8_t setnumber) {
150
  uint16_t offset = EEPROM_ADR_PARAMSET_BEGIN + (setnumber-1)*(sizeof(paramset_t)+EEPROM_CHECKSUMMED_BLOCK_OVERHEAD);
151
  uint16_t offset = EEPROM_ADR_PARAMSET_BEGIN + (setnumber-1)*(sizeof(paramset_t)+EEPROM_CHECKSUMMED_BLOCK_OVERHEAD);
151
  writeChecksummedBlock(EEPARAM_REVISION, (uint8_t*)&staticParams, offset, sizeof(paramset_t));
152
  writeChecksummedBlock(EEPARAM_REVISION, (uint8_t*)&staticParams, offset, sizeof(paramset_t));
152
  // set this parameter set to active set
153
  // set this parameter set to active set
153
  setActiveParamSet(setnumber);
154
  setActiveParamSet(setnumber);
154
  output_init(); // what's that doing here??
155
  output_init(); // what's that doing here??
155
}
156
}
156
 
157
 
157
void paramSet_readOrDefault() {
158
void paramSet_readOrDefault() {
158
  uint8_t setnumber = getActiveParamSet();
159
  uint8_t setnumber = getActiveParamSet();
159
  // parameter version  check
160
  // parameter version  check
160
  if (setnumber<1 ||setnumber>5 || paramSet_readFromEEProm(setnumber)) {
161
  if (setnumber<1 ||setnumber>5 || paramSet_readFromEEProm(setnumber)) {
161
    // if version check faild
162
    // if version check faild
162
    printf("writing default parameter sets");
163
    printf("\n\rwriting default parameter sets");
163
    for (uint8_t i=5; i>0; i--) {
164
    for (uint8_t i=5; i>0; i--) {
164
      paramSet_default(i);
165
      paramSet_default(i);
165
      paramSet_writeToEEProm(i);
166
      paramSet_writeToEEProm(i);
166
    }
167
    }
167
    // default-Setting is parameter set 3
168
    // default-Setting is parameter set 3
168
    setActiveParamSet(1);
169
    setActiveParamSet(1);
169
  }
170
  }
170
 
171
 
171
  printf("\n\r\rUsing Parameter Set %d", getActiveParamSet());
172
  printf("\n\r\rUsing Parameter Set %d", getActiveParamSet());
172
}
173
}
173
 
174
 
174
/***************************************************/
175
/***************************************************/
175
/* MixerTable                                      */
176
/* MixerTable                                      */
176
/***************************************************/
177
/***************************************************/
177
uint8_t mixerMatrix_readFromEEProm(void) {
-
 
178
  return readChecksummedBlock(EEMIXER_REVISION, (uint8_t*)&mixerMatrix, EEPROM_ADR_MIXER_TABLE, sizeof(mixerMatrix_t));
-
 
179
}
-
 
180
 
-
 
181
void mixerMatrix_writeToEEProm(void) {
178
void mixerMatrix_writeToEEProm(void) {
182
  writeChecksummedBlock(EEMIXER_REVISION, (uint8_t*)&mixerMatrix, EEPROM_ADR_MIXER_TABLE, sizeof(mixerMatrix_t));
179
  writeChecksummedBlock(EEMIXER_REVISION, (uint8_t*)&mixerMatrix, EEPROM_ADR_MIXER_TABLE, sizeof(mixerMatrix_t));
183
}
180
}
184
 
181
 
185
void mixerMatrix_readOrDefault(void) {
182
void mixerMatrix_readOrDefault(void) {
186
  // load mixer table
183
  // load mixer table
187
  if (mixerMatrix_readFromEEProm()) {
184
  if (readChecksummedBlock(EEMIXER_REVISION, (uint8_t*)&mixerMatrix, EEPROM_ADR_MIXER_TABLE, sizeof(mixerMatrix_t))) {
188
    printf("writing default mixerMatrix");
185
    printf("writing default mixerMatrix");
189
    mixerMatrix_default(); // Quadro
186
    mixerMatrix_default(); // Quadro
190
    mixerMatrix_writeToEEProm();
187
    mixerMatrix_writeToEEProm();
191
  }
188
  }
192
  // determine motornumber
189
  // determine motornumber
193
  requiredMotors = 0;
190
  requiredMotors = 0;
194
  for (uint8_t i=0; i<MAX_MOTORS; i++) {
191
  for (uint8_t i=0; i<MAX_MOTORS; i++) {
195
    if (mixerMatrix.motor[i][MIX_THROTTLE])
192
    if (mixerMatrix.motor[i][MIX_THROTTLE])
196
      requiredMotors++;
193
      requiredMotors++;
197
  }
194
  }
198
 
195
 
199
  printf("\n\r\rMixer-Config: '%s' (%u Motors)",mixerMatrix.name, requiredMotors);
196
  printf("\n\rMixer-Config: '%s' (%u Motors)",mixerMatrix.name, requiredMotors);
200
  printf("\n\r\r==============================");
197
  printf("\n\r===================================");
201
}
198
}
202
 
199
 
203
/***************************************************/
200
/***************************************************/
204
/* ChannelMap                                      */
201
/* ChannelMap                                      */
205
/***************************************************/
202
/***************************************************/
206
uint8_t channelMap_readFromEEProm(void) {
-
 
207
  return readChecksummedBlock(CHANNELMAP_REVISION, (uint8_t*)&channelMap, EEPROM_ADR_CHANNELMAP, sizeof(channelMap_t));
-
 
208
}
-
 
209
 
-
 
210
void channelMap_writeToEEProm(void) {
203
void channelMap_writeToEEProm(void) {
211
  writeChecksummedBlock(CHANNELMAP_REVISION, (uint8_t*)&channelMap, EEPROM_ADR_CHANNELMAP, sizeof(channelMap_t));
204
  writeChecksummedBlock(CHANNELMAP_REVISION, (uint8_t*)&channelMap, EEPROM_ADR_CHANNELMAP, sizeof(channelMap_t));
212
}
205
}
213
 
206
 
214
void channelMap_readOrDefault(void) {
207
void channelMap_readOrDefault(void) {
215
  if (channelMap_readFromEEProm()) {
208
  if (readChecksummedBlock(CHANNELMAP_REVISION, (uint8_t*)&channelMap, EEPROM_ADR_CHANNELMAP, sizeof(channelMap_t))) {
216
    printf("writing default channel map");
209
    printf("writing default channel map");
217
    channelMap_default();
210
    channelMap_default();
218
    channelMap_writeToEEProm();
211
    channelMap_writeToEEProm();
219
  }
212
  }
220
}
213
}
221
 
214
 
222
/***************************************************/
215
/***************************************************/
223
/* Sensor offsets                                  */
216
/* Sensor offsets                                  */
224
/***************************************************/
217
/***************************************************/
225
uint8_t gyroAmplifierOffset_readFromEEProm(void) {
218
uint8_t gyroAmplifierOffset_readFromEEProm(void) {
226
  return readChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&gyroAmplifierOffset, EEPROM_ADR_GYROAMPLIFIER, sizeof(sensorOffset_t));
219
  return readChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&gyroAmplifierOffset, EEPROM_ADR_GYROAMPLIFIER, sizeof(sensorOffset_t));
227
}
220
}
228
 
221
 
229
void gyroAmplifierOffset_writeToEEProm(void) {
222
void gyroAmplifierOffset_writeToEEProm(void) {
230
  return writeChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&gyroAmplifierOffset, EEPROM_ADR_GYROAMPLIFIER, sizeof(sensorOffset_t));
223
  return writeChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&gyroAmplifierOffset, EEPROM_ADR_GYROAMPLIFIER, sizeof(sensorOffset_t));
231
}
224
}
232
 
225
 
233
uint8_t gyroOffset_readFromEEProm(void) {
226
uint8_t gyroOffset_readFromEEProm(void) {
234
  return readChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&gyroOffset, EEPROM_ADR_GYROOFFSET, sizeof(sensorOffset_t));
227
  return readChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&gyroOffset, EEPROM_ADR_GYROOFFSET, sizeof(sensorOffset_t));
235
}
228
}
236
 
229
 
237
void gyroOffset_writeToEEProm(void) {
230
void gyroOffset_writeToEEProm(void) {
238
  writeChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&gyroOffset, EEPROM_ADR_GYROOFFSET, sizeof(sensorOffset_t));
231
  writeChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&gyroOffset, EEPROM_ADR_GYROOFFSET, sizeof(sensorOffset_t));
239
}
232
}
240
 
233
 
241
uint8_t accOffset_readFromEEProm(void) {
234
uint8_t accOffset_readFromEEProm(void) {
242
  return readChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&accOffset, EEPROM_ADR_ACCOFFSET, sizeof(sensorOffset_t));
235
  return readChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&accOffset, EEPROM_ADR_ACCOFFSET, sizeof(sensorOffset_t));
243
}
236
}
244
 
237
 
245
void accOffset_writeToEEProm(void) {
238
void accOffset_writeToEEProm(void) {
246
  writeChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&accOffset, EEPROM_ADR_ACCOFFSET, sizeof(sensorOffset_t));
239
  writeChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&accOffset, EEPROM_ADR_ACCOFFSET, sizeof(sensorOffset_t));
247
}
240
}
248
 
241
 
249
/***************************************************/
242
/***************************************************/
250
/*       Get active parameter set                  */
243
/*       Get active parameter set                  */
251
/***************************************************/
244
/***************************************************/
252
uint8_t getActiveParamSet(void) {
245
uint8_t getActiveParamSet(void) {
253
  uint8_t setnumber;
246
  uint8_t setnumber;
254
  setnumber = eeprom_read_byte(&EEPromArray[PID_ACTIVE_SET]);
247
  setnumber = eeprom_read_byte(&EEPromArray[PID_ACTIVE_SET]);
255
  if (setnumber > 4) {
248
  if (setnumber > 4) {
256
    setActiveParamSet(setnumber = 0);
249
    setActiveParamSet(setnumber = 0);
257
  }
250
  }
258
  return setnumber;
251
  return setnumber;
259
}
252
}
260
 
253
 
261
/***************************************************/
254
/***************************************************/
262
/*       Set active parameter set                  */
255
/*       Set active parameter set                  */
263
/***************************************************/
256
/***************************************************/
264
void setActiveParamSet(uint8_t setnumber) {
257
void setActiveParamSet(uint8_t setnumber) {
265
  eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber);
258
  eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber);
266
}
259
}
267
 
260
 
268
 
261