Rev 1965 | Rev 1968 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1965 | Rev 1967 | ||
---|---|---|---|
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 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
53 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
54 | // + Contant Values |
54 | // + Contant Values |
55 | // + 0-250 -> normale Values |
55 | // + 0-250 -> normale Values |
56 | // + 251 -> Poti1 |
56 | // + 251 -> Poti1 |
57 | // + 252 -> Poti2 |
57 | // + 252 -> Poti2 |
58 | // + 253 -> Poti3 |
58 | // + 253 -> Poti3 |
59 | // + 254 -> Poti4 |
59 | // + 254 -> Poti4 |
60 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
60 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
61 | 61 | ||
62 | #ifndef EEMEM |
62 | #ifndef EEMEM |
63 | #define EEMEM __attribute__ ((section (".eeprom"))) |
63 | #define EEMEM __attribute__ ((section (".eeprom"))) |
64 | #endif |
64 | #endif |
65 | 65 | ||
66 | #include "eeprom.h" |
66 | #include "eeprom.h" |
67 | #include "printf_P.h" |
67 | #include "printf_P.h" |
68 | #include "output.h" |
68 | #include "output.h" |
69 | #include <avr/eeprom.h> |
69 | #include <avr/eeprom.h> |
70 | 70 | ||
71 | // byte array in eeprom |
71 | // byte array in eeprom |
72 | uint8_t EEPromArray[E2END + 1] EEMEM; |
72 | uint8_t EEPromArray[E2END + 1] EEMEM; |
73 | 73 | ||
74 | /***************************************************/ |
74 | /***************************************************/ |
75 | /* Read Parameter from EEPROM as byte */ |
75 | /* Read Parameter from EEPROM as byte */ |
76 | /***************************************************/ |
76 | /***************************************************/ |
77 | uint8_t getParamByte(uint16_t param_id) { |
77 | uint8_t getParamByte(uint16_t param_id) { |
78 | return eeprom_read_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]); |
78 | return eeprom_read_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id]); |
79 | } |
79 | } |
80 | 80 | ||
81 | /***************************************************/ |
81 | /***************************************************/ |
82 | /* Write Parameter to EEPROM as byte */ |
82 | /* Write Parameter to EEPROM as byte */ |
83 | /***************************************************/ |
83 | /***************************************************/ |
84 | void setParamByte(uint16_t param_id, uint8_t value) { |
84 | void setParamByte(uint16_t param_id, uint8_t value) { |
85 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value); |
85 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value); |
86 | } |
86 | } |
87 | 87 | ||
88 | /***************************************************/ |
88 | /***************************************************/ |
89 | /* Read Parameter from EEPROM as word */ |
89 | /* Read Parameter from EEPROM as word */ |
90 | /***************************************************/ |
90 | /***************************************************/ |
- | 91 | /* |
|
91 | uint16_t getParamWord(uint16_t param_id) { |
92 | uint16_t getParamWord(uint16_t param_id) { |
92 | return eeprom_read_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN |
93 | return eeprom_read_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN |
93 | + param_id]); |
94 | + param_id]); |
94 | } |
95 | } |
- | 96 | */ |
|
95 | 97 | ||
96 | /***************************************************/ |
98 | /***************************************************/ |
97 | /* Write Parameter to EEPROM as word */ |
99 | /* Write Parameter to EEPROM as word */ |
98 | /***************************************************/ |
100 | /***************************************************/ |
- | 101 | /* |
|
99 | void setParamWord(uint16_t param_id, uint16_t value) { |
102 | void setParamWord(uint16_t param_id, uint16_t value) { |
100 | eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value); |
103 | eeprom_write_word((uint16_t *) &EEPromArray[EEPROM_ADR_PARAM_BEGIN + param_id], value); |
101 | } |
104 | } |
- | 105 | */ |
|
102 | 106 | ||
103 | uint8_t calculateChecksum(uint8_t* data, uint16_t length) { |
107 | uint8_t calculateChecksum(uint8_t* data, uint16_t length) { |
104 | uint8_t result = 0; |
108 | uint8_t result = 0; |
105 | for (uint16_t i=0; i<length; i++) { |
109 | for (uint16_t i=0; i<length; i++) { |
106 | result += data[i]; |
110 | result += data[i]; |
107 | } |
111 | } |
108 | return result; |
112 | return result; |
109 | } |
113 | } |
110 | 114 | ||
111 | // offset is where the checksum is stored, offset+1 is the revision number, and offset+2... are the data. |
115 | // offset is where the checksum is stored, offset+1 is the revision number, and offset+2... are the data. |
112 | // length is the length of the pure data not including checksum and revision number. |
116 | // length is the length of the pure data not including checksum and revision number. |
113 | void writeChecksummedBlock(uint8_t revisionNumber, uint8_t* data, uint16_t offset, uint16_t length) { |
117 | void writeChecksummedBlock(uint8_t revisionNumber, uint8_t* data, uint16_t offset, uint16_t length) { |
114 | uint8_t checksum = calculateChecksum(data, length); |
118 | uint8_t checksum = calculateChecksum(data, length); |
115 | eeprom_write_byte(&EEPromArray[offset], checksum); |
119 | eeprom_write_byte(&EEPromArray[offset], checksum); |
116 | eeprom_write_byte(&EEPromArray[offset+1], revisionNumber); |
120 | eeprom_write_byte(&EEPromArray[offset+1], revisionNumber); |
117 | eeprom_write_block(data, &EEPromArray[offset+2], length); |
121 | eeprom_write_block(data, &EEPromArray[offset+2], length); |
118 | } |
122 | } |
119 | 123 | ||
120 | // offset is where the checksum is stored, offset+1 is the revision number, and offset+2... are the data. |
124 | // offset is where the checksum is stored, offset+1 is the revision number, and offset+2... are the data. |
121 | // length is the length of the pure data not including checksum and revision number. |
125 | // length is the length of the pure data not including checksum and revision number. |
122 | uint8_t readChecksummedBlock(uint8_t revisionNumber, uint8_t* target, uint16_t offset, uint16_t length) { |
126 | uint8_t readChecksummedBlock(uint8_t revisionNumber, uint8_t* target, uint16_t offset, uint16_t length) { |
123 | uint8_t checksumRead = eeprom_read_byte(&EEPromArray[offset]); |
127 | uint8_t checksumRead = eeprom_read_byte(&EEPromArray[offset]); |
124 | uint8_t revisionNumberRead = eeprom_read_byte(&EEPromArray[offset+1]); |
128 | uint8_t revisionNumberRead = eeprom_read_byte(&EEPromArray[offset+1]); |
125 | eeprom_read_block(target, &EEPromArray[offset+2], length); |
129 | eeprom_read_block(target, &EEPromArray[offset+2], length); |
126 | uint8_t checksumCalculated = calculateChecksum(target, length); |
130 | uint8_t checksumCalculated = calculateChecksum(target, length); |
127 | 131 | ||
128 | uint8_t checksumError = (checksumRead != checksumCalculated); |
132 | uint8_t checksumError = (checksumRead != checksumCalculated); |
129 | uint8_t revisionMismatch = (revisionNumber != revisionNumberRead); |
133 | uint8_t revisionMismatch = (revisionNumber != revisionNumberRead); |
130 | 134 | ||
131 | if (checksumError && revisionMismatch) printf("\n\rEEPROM checksum error and revision mismatch, "); |
135 | if (checksumError && revisionMismatch) printf("\n\rEEPROM checksum error and revision mismatch, "); |
132 | else if (checksumError) printf("\n\rEEPROM checksum error, "); |
136 | else if (checksumError) printf("\n\rEEPROM checksum error, "); |
133 | else if (revisionMismatch) printf("\n\rEEPROM revision mismatch, "); |
137 | else if (revisionMismatch) printf("\n\rEEPROM revision mismatch, "); |
134 | return (checksumError || revisionMismatch); |
138 | return (checksumError || revisionMismatch); |
135 | } |
139 | } |
136 | 140 | ||
137 | /***************************************************/ |
141 | /***************************************************/ |
138 | /* Read Parameter Set from EEPROM */ |
142 | /* Read Parameter Set from EEPROM */ |
139 | /***************************************************/ |
143 | /***************************************************/ |
140 | // setnumber [1..5] |
144 | // setnumber [1..5] |
141 | uint8_t paramSet_readFromEEProm(uint8_t setnumber) { |
145 | uint8_t paramSet_readFromEEProm(uint8_t setnumber) { |
142 | uint16_t offset = EEPROM_ADR_PARAMSET_BEGIN + (setnumber-1)*(sizeof(paramset_t)+2); |
146 | uint16_t offset = EEPROM_ADR_PARAMSET_BEGIN + (setnumber-1)*(sizeof(paramset_t)+2); |
143 | output_init(); // what's that doing here?? |
147 | output_init(); // what's that doing here?? |
144 | return readChecksummedBlock(EEPARAM_REVISION, (uint8_t*)&staticParams, offset, sizeof(paramset_t)); |
148 | return readChecksummedBlock(EEPARAM_REVISION, (uint8_t*)&staticParams, offset, sizeof(paramset_t)); |
145 | } |
149 | } |
146 | 150 | ||
147 | /***************************************************/ |
151 | /***************************************************/ |
148 | /* Write Parameter Set to EEPROM */ |
152 | /* Write Parameter Set to EEPROM */ |
149 | /***************************************************/ |
153 | /***************************************************/ |
150 | void paramSet_writeToEEProm(uint8_t setnumber) { |
154 | void paramSet_writeToEEProm(uint8_t setnumber) { |
151 | uint16_t offset = EEPROM_ADR_PARAMSET_BEGIN + (setnumber-1)*(sizeof(paramset_t)+2); |
155 | uint16_t offset = EEPROM_ADR_PARAMSET_BEGIN + (setnumber-1)*(sizeof(paramset_t)+2); |
152 | writeChecksummedBlock(EEPARAM_REVISION, (uint8_t*)&staticParams, offset, sizeof(paramset_t)); |
156 | writeChecksummedBlock(EEPARAM_REVISION, (uint8_t*)&staticParams, offset, sizeof(paramset_t)); |
153 | // set this parameter set to active set |
157 | // set this parameter set to active set |
154 | setActiveParamSet(setnumber); |
158 | setActiveParamSet(setnumber); |
155 | output_init(); // what's that doing here?? |
159 | output_init(); // what's that doing here?? |
156 | } |
160 | } |
157 | 161 | ||
158 | void paramSet_readOrDefault() { |
162 | void paramSet_readOrDefault() { |
159 | uint8_t setnumber = getActiveParamSet(); |
163 | uint8_t setnumber = getActiveParamSet(); |
160 | // parameter version check |
164 | // parameter version check |
161 | if (setnumber<1 ||setnumber>5 || paramSet_readFromEEProm(setnumber)) { |
165 | if (setnumber<1 ||setnumber>5 || paramSet_readFromEEProm(setnumber)) { |
162 | // if version check faild |
166 | // if version check faild |
163 | printf("writing default parameter sets"); |
167 | printf("writing default parameter sets"); |
164 | for (uint8_t i=5; i>0; i--) { |
168 | for (uint8_t i=5; i>0; i--) { |
165 | paramSet_default(i); |
169 | paramSet_default(i); |
166 | paramSet_writeToEEProm(i); |
170 | paramSet_writeToEEProm(i); |
167 | } |
171 | } |
168 | // default-Setting is parameter set 3 |
172 | // default-Setting is parameter set 3 |
169 | setActiveParamSet(1); |
173 | setActiveParamSet(1); |
170 | } |
174 | } |
171 | 175 | ||
172 | printf("\n\r\rUsing Parameter Set %d", getActiveParamSet()); |
176 | printf("\n\r\rUsing Parameter Set %d", getActiveParamSet()); |
173 | } |
177 | } |
174 | 178 | ||
175 | /***************************************************/ |
179 | /***************************************************/ |
176 | /* MixerTable */ |
180 | /* MixerTable */ |
177 | /***************************************************/ |
181 | /***************************************************/ |
178 | uint8_t mixerMatrix_readFromEEProm(void) { |
182 | uint8_t mixerMatrix_readFromEEProm(void) { |
179 | return readChecksummedBlock(EEMIXER_REVISION, (uint8_t*)&mixerMatrix, EEPROM_ADR_MIXER_TABLE, sizeof(mixerMatrix_t)); |
183 | return readChecksummedBlock(EEMIXER_REVISION, (uint8_t*)&mixerMatrix, EEPROM_ADR_MIXER_TABLE, sizeof(mixerMatrix_t)); |
180 | } |
184 | } |
181 | 185 | ||
182 | void mixerMatrix_writeToEEProm(void) { |
186 | void mixerMatrix_writeToEEProm(void) { |
183 | writeChecksummedBlock(EEMIXER_REVISION, (uint8_t*)&mixerMatrix, EEPROM_ADR_MIXER_TABLE, sizeof(mixerMatrix_t)); |
187 | writeChecksummedBlock(EEMIXER_REVISION, (uint8_t*)&mixerMatrix, EEPROM_ADR_MIXER_TABLE, sizeof(mixerMatrix_t)); |
184 | } |
188 | } |
185 | 189 | ||
186 | void mixerMatrix_readOrDefault(void) { |
190 | void mixerMatrix_readOrDefault(void) { |
187 | // load mixer table |
191 | // load mixer table |
188 | if (mixerMatrix_readFromEEProm()) { |
192 | if (mixerMatrix_readFromEEProm()) { |
189 | printf("writing default mixerMatrix"); |
193 | printf("writing default mixerMatrix"); |
190 | mixerMatrix_default(); // Quadro |
194 | mixerMatrix_default(); // Quadro |
191 | mixerMatrix_writeToEEProm(); |
195 | mixerMatrix_writeToEEProm(); |
192 | } |
196 | } |
193 | // determine motornumber |
197 | // determine motornumber |
194 | requiredMotors = 0; |
198 | requiredMotors = 0; |
195 | for (uint8_t i=0; i<MAX_MOTORS; i++) { |
199 | for (uint8_t i=0; i<MAX_MOTORS; i++) { |
196 | if (mixerMatrix.motor[i][MIX_THROTTLE]) |
200 | if (mixerMatrix.motor[i][MIX_THROTTLE]) |
197 | requiredMotors++; |
201 | requiredMotors++; |
198 | } |
202 | } |
199 | 203 | ||
200 | printf("\n\r\rMixer-Config: '%s' (%u Motors)",mixerMatrix.name, requiredMotors); |
204 | printf("\n\r\rMixer-Config: '%s' (%u Motors)",mixerMatrix.name, requiredMotors); |
201 | printf("\n\r\r=============================="); |
205 | printf("\n\r\r=============================="); |
202 | } |
206 | } |
203 | 207 | ||
204 | /***************************************************/ |
208 | /***************************************************/ |
205 | /* ChannelMap */ |
209 | /* ChannelMap */ |
206 | /***************************************************/ |
210 | /***************************************************/ |
207 | uint8_t channelMap_readFromEEProm(void) { |
211 | uint8_t channelMap_readFromEEProm(void) { |
208 | return readChecksummedBlock(CHANNELMAP_REVISION, (uint8_t*)&channelMap, EEPROM_ADR_CHANNELMAP, sizeof(channelMap_t)); |
212 | return readChecksummedBlock(CHANNELMAP_REVISION, (uint8_t*)&channelMap, EEPROM_ADR_CHANNELMAP, sizeof(channelMap_t)); |
209 | } |
213 | } |
210 | 214 | ||
211 | void channelMap_writeToEEProm(void) { |
215 | void channelMap_writeToEEProm(void) { |
212 | writeChecksummedBlock(CHANNELMAP_REVISION, (uint8_t*)&channelMap, EEPROM_ADR_CHANNELMAP, sizeof(channelMap_t)); |
216 | writeChecksummedBlock(CHANNELMAP_REVISION, (uint8_t*)&channelMap, EEPROM_ADR_CHANNELMAP, sizeof(channelMap_t)); |
213 | } |
217 | } |
214 | 218 | ||
215 | void channelMap_readOrDefault(void) { |
219 | void channelMap_readOrDefault(void) { |
216 | if (channelMap_readFromEEProm()) { |
220 | if (channelMap_readFromEEProm()) { |
217 | printf("writing default channel map"); |
221 | printf("writing default channel map"); |
218 | channelMap_default(); |
222 | channelMap_default(); |
219 | channelMap_writeToEEProm(); |
223 | channelMap_writeToEEProm(); |
220 | } |
224 | } |
221 | } |
225 | } |
222 | 226 | ||
223 | /***************************************************/ |
227 | /***************************************************/ |
224 | /* Sensor offsets */ |
228 | /* Sensor offsets */ |
225 | /***************************************************/ |
229 | /***************************************************/ |
- | 230 | uint8_t gyroAmplifierOffset_readFromEEProm(void) { |
|
- | 231 | return readChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&gyroAmplifierOffset, EEPROM_ADR_GYROAMPLIFIER, sizeof(sensorOffset_t)); |
|
- | 232 | } |
|
- | 233 | ||
- | 234 | void gyroAmplifierOffset_writeToEEProm(void) { |
|
- | 235 | return writeChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&gyroAmplifierOffset, EEPROM_ADR_GYROAMPLIFIER, sizeof(sensorOffset_t)); |
|
- | 236 | } |
|
- | 237 | ||
226 | uint8_t gyroOffset_readFromEEProm(void) { |
238 | uint8_t gyroOffset_readFromEEProm(void) { |
227 | return readChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&gyroOffset, EEPROM_ADR_GYROOFFSET, sizeof(sensorOffset_t)) | |
239 | return readChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&gyroOffset, EEPROM_ADR_GYROOFFSET, sizeof(sensorOffset_t)); |
228 | readChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&DACValues, EEPROM_ADR_DACVALUES, sizeof(sensorOffset_t)); |
- | |
229 | } |
240 | } |
230 | 241 | ||
231 | void gyroOffset_writeToEEProm(void) { |
242 | void gyroOffset_writeToEEProm(void) { |
232 | writeChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&gyroOffset, EEPROM_ADR_GYROOFFSET, sizeof(sensorOffset_t)); |
243 | writeChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&gyroOffset, EEPROM_ADR_GYROOFFSET, sizeof(sensorOffset_t)); |
233 | writeChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&DACValues, EEPROM_ADR_DACVALUES, sizeof(sensorOffset_t)); |
- | |
234 | } |
244 | } |
235 | 245 | ||
236 | uint8_t accOffset_readFromEEProm(void) { |
246 | uint8_t accOffset_readFromEEProm(void) { |
237 | return readChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&accOffset, EEPROM_ADR_ACCOFFSET, sizeof(sensorOffset_t)); |
247 | return readChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&accOffset, EEPROM_ADR_ACCOFFSET, sizeof(sensorOffset_t)); |
238 | } |
248 | } |
239 | 249 | ||
240 | void accOffset_writeToEEProm(void) { |
250 | void accOffset_writeToEEProm(void) { |
241 | writeChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&accOffset, EEPROM_ADR_ACCOFFSET, sizeof(sensorOffset_t)); |
251 | writeChecksummedBlock(SENSOROFFSET_REVISION, (uint8_t*)&accOffset, EEPROM_ADR_ACCOFFSET, sizeof(sensorOffset_t)); |
242 | } |
252 | } |
243 | 253 | ||
244 | /***************************************************/ |
254 | /***************************************************/ |
245 | /* Get active parameter set */ |
255 | /* Get active parameter set */ |
246 | /***************************************************/ |
256 | /***************************************************/ |
247 | uint8_t getActiveParamSet(void) { |
257 | uint8_t getActiveParamSet(void) { |
248 | uint8_t setnumber; |
258 | uint8_t setnumber; |
249 | setnumber = eeprom_read_byte(&EEPromArray[PID_ACTIVE_SET]); |
259 | setnumber = eeprom_read_byte(&EEPromArray[PID_ACTIVE_SET]); |
250 | if (setnumber > 4) { |
260 | if (setnumber > 4) { |
251 | setActiveParamSet(setnumber = 0); |
261 | setActiveParamSet(setnumber = 0); |
252 | } |
262 | } |
253 | return setnumber; |
263 | return setnumber; |
254 | } |
264 | } |
255 | 265 | ||
256 | /***************************************************/ |
266 | /***************************************************/ |
257 | /* Set active parameter set */ |
267 | /* Set active parameter set */ |
258 | /***************************************************/ |
268 | /***************************************************/ |
259 | void setActiveParamSet(uint8_t setnumber) { |
269 | void setActiveParamSet(uint8_t setnumber) { |
260 | eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber); |
270 | eeprom_write_byte(&EEPromArray[PID_ACTIVE_SET], setnumber); |
261 | } |
271 | } |
262 | 272 | ||
263 | 273 |