Rev 1612 | Rev 1805 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1612 | Rev 1775 | ||
---|---|---|---|
Line 48... | Line 48... | ||
48 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
48 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
49 | // + POSSIBILITY OF SUCH DAMAGE. |
49 | // + POSSIBILITY OF SUCH DAMAGE. |
50 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
50 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
51 | #include <util/delay.h> |
51 | #include <util/delay.h> |
52 | #include <avr/eeprom.h> |
52 | #include <avr/eeprom.h> |
- | 53 | #include <stddef.h> |
|
53 | #include "configuration.h" |
54 | #include "configuration.h" |
54 | #include "eeprom.h" |
55 | #include "eeprom.h" |
55 | #include "timer0.h" |
56 | #include "timer0.h" |
Line 56... | Line 57... | ||
56 | 57 | ||
57 | int16_t variables[8] = {0,0,0,0,0,0,0,0}; |
58 | int16_t variables[8] = {0,0,0,0,0,0,0,0}; |
58 | fc_param_t dynamicParams = {48,251,16,58,64,8,150,150,2,10,{0,0,0,0,0,0,0,0},100,70,90,65,64,100,0,0,0}; |
59 | dynamicParam_t dynamicParams = {48,251,16,58,64,8,150,150,2,10,{0,0,0,0,0,0,0,0},100,70,90,65,64,100,0,0,0}; |
59 | uint8_t CPUType = ATMEGA644; |
60 | uint8_t CPUType = ATMEGA644; |
Line 60... | Line 61... | ||
60 | uint8_t BoardRelease = 13; |
61 | uint8_t BoardRelease = 13; |
61 | 62 | ||
- | 63 | /************************************************************************ |
|
62 | /************************************************************************ |
64 | * Map the parameter to pot values |
- | 65 | * Replacing this code by the code below saved almost 1 kbyte. |
|
63 | * Map the parameter to pot values |
66 | ************************************************************************/ |
64 | ************************************************************************/ |
67 | |
65 | void configuration_applyVariablesToParams(void) { |
68 | void configuration_applyVariablesToParams(void) { |
66 | uint8_t i; |
69 | uint8_t i; |
67 | #define SET_POT_MM(b,a,min,max) { if (a<255) {if (a>=251) b=variables[a-251]; else b=a;} if(b<=min) b=min; else if(b>=max) b=max;} |
70 | #define SET_POT_MM(b,a,min,max) {if (a<255) {if (a>=251) b=variables[a-251]; else b=a;} if(b<=min) b=min; else if(b>=max) b=max;} |
68 | #define SET_POT(b,a) { if (a<255) {if (a>=251) b=variables[a-251]; else b=a;}} |
71 | #define SET_POT(b,a) { if (a<255) {if (a>=251) b=variables[a-251]; else b=a;}} |
69 | SET_POT(dynamicParams.MaxHeight,staticParams.MaxHeight); |
72 | SET_POT(dynamicParams.MaxHeight,staticParams.MaxHeight); |
70 | SET_POT_MM(dynamicParams.HeightD,staticParams.HeightD,0,100); |
73 | SET_POT_MM(dynamicParams.HeightD,staticParams.HeightD,0,100); |
Line 101... | Line 104... | ||
101 | SET_POT(dynamicParams.NaviSpeedCompensation,staticParams.NaviSpeedCompensation); |
104 | SET_POT(dynamicParams.NaviSpeedCompensation,staticParams.NaviSpeedCompensation); |
102 | #endif |
105 | #endif |
103 | SET_POT(dynamicParams.ExternalControl,staticParams.ExternalControl); |
106 | SET_POT(dynamicParams.ExternalControl,staticParams.ExternalControl); |
104 | } |
107 | } |
Line -... | Line 108... | ||
- | 108 | ||
- | 109 | const XLATION XLATIONS[] = { |
|
- | 110 | {offsetof(paramset_t, MaxHeight), offsetof(dynamicParam_t, MaxHeight)}, |
|
- | 111 | {offsetof(paramset_t, Height_ACC_Effect), offsetof(dynamicParam_t, Height_ACC_Effect)}, |
|
- | 112 | {offsetof(paramset_t, CompassYawEffect), offsetof(dynamicParam_t, CompassYawEffect)}, |
|
- | 113 | {offsetof(paramset_t, GyroI), offsetof(dynamicParam_t, GyroI)}, |
|
- | 114 | {offsetof(paramset_t, GyroD), offsetof(dynamicParam_t, GyroD)}, |
|
- | 115 | {offsetof(paramset_t, IFactor), offsetof(dynamicParam_t, IFactor)}, |
|
- | 116 | {offsetof(paramset_t, ServoPitchControl), offsetof(dynamicParam_t, ServoPitchControl)}, |
|
- | 117 | {offsetof(paramset_t, LoopGasLimit), offsetof(dynamicParam_t, LoopGasLimit)}, |
|
- | 118 | {offsetof(paramset_t, AxisCoupling1), offsetof(dynamicParam_t, AxisCoupling1)}, |
|
- | 119 | {offsetof(paramset_t, AxisCoupling2), offsetof(dynamicParam_t, AxisCoupling2)}, |
|
- | 120 | {offsetof(paramset_t, AxisCouplingYawCorrection), offsetof(dynamicParam_t, AxisCouplingYawCorrection)}, |
|
- | 121 | {offsetof(paramset_t, DynamicStability), offsetof(dynamicParam_t, DynamicStability)}, |
|
- | 122 | {offsetof(paramset_t, NaviGpsModeControl), |
|
- | 123 | offsetof(dynamicParam_t, NaviGpsModeControl)}, |
|
- | 124 | {offsetof(paramset_t, NaviGpsGain), offsetof(dynamicParam_t, NaviGpsGain)}, |
|
- | 125 | {offsetof(paramset_t, NaviGpsP), offsetof(dynamicParam_t, NaviGpsP)}, |
|
- | 126 | {offsetof(paramset_t, NaviGpsI), offsetof(dynamicParam_t, NaviGpsI)}, |
|
- | 127 | {offsetof(paramset_t, NaviGpsD), offsetof(dynamicParam_t, NaviGpsD)}, |
|
- | 128 | {offsetof(paramset_t, NaviGpsACC), offsetof(dynamicParam_t, NaviGpsACC)}, |
|
- | 129 | {offsetof(paramset_t, NaviWindCorrection), offsetof(dynamicParam_t, NaviWindCorrection)}, |
|
- | 130 | {offsetof(paramset_t, NaviSpeedCompensation), offsetof(dynamicParam_t, NaviSpeedCompensation)}, |
|
- | 131 | {offsetof(paramset_t, ExternalControl), offsetof(dynamicParam_t, ExternalControl)} |
|
- | 132 | }; |
|
- | 133 | ||
- | 134 | const MMXLATION MMXLATIONS[] = { |
|
- | 135 | {offsetof(paramset_t, HeightD), offsetof(dynamicParam_t, HeightD),0,100}, |
|
- | 136 | {offsetof(paramset_t, HeightP), offsetof(dynamicParam_t, HeightD),0,150}, |
|
- | 137 | {offsetof(paramset_t, GyroP), offsetof(dynamicParam_t, GyroP),0,255}, |
|
- | 138 | {offsetof(paramset_t, J16Timing), offsetof(dynamicParam_t, J16Timing),1,255}, |
|
- | 139 | {offsetof(paramset_t, J17Timing), offsetof(dynamicParam_t, J17Timing),1,255}, |
|
- | 140 | {offsetof(paramset_t, NaviOperatingRadius), offsetof(dynamicParam_t, NaviOperatingRadius),10,255} |
|
- | 141 | }; |
|
- | 142 | ||
- | 143 | uint8_t configuration_applyVariableToParam(uint8_t src, uint8_t min, uint8_t max) { |
|
- | 144 | uint8_t result; |
|
- | 145 | if (src>=251) result = variables[src-251]; |
|
- | 146 | else result = src; |
|
- | 147 | if (result < min) result = min; |
|
- | 148 | else if (result > max) result = max; |
|
- | 149 | return result; |
|
- | 150 | } |
|
- | 151 | ||
- | 152 | void configuration_applyVariablesToParams_dead(void) { |
|
- | 153 | uint8_t i, src; |
|
- | 154 | uint8_t* pointerToTgt; |
|
- | 155 | for(i=0; i<sizeof(XLATIONS)/sizeof(XLATION); i++) { |
|
- | 156 | src = *((uint8_t*)(&staticParams + XLATIONS[i].sourceIdx)); |
|
- | 157 | pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx); |
|
- | 158 | if (src < 255) { |
|
- | 159 | *pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
|
- | 160 | } |
|
- | 161 | } |
|
- | 162 | ||
- | 163 | for(i=0; i<sizeof(MMXLATIONS)/sizeof(MMXLATION); i++) { |
|
- | 164 | src = *((uint8_t*)(&staticParams + MMXLATIONS[i].sourceIdx)); |
|
- | 165 | pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx); |
|
- | 166 | if (src < 255) { |
|
- | 167 | *pointerToTgt = configuration_applyVariableToParam(src, MMXLATIONS[i].min, MMXLATIONS[i].max); |
|
- | 168 | } |
|
- | 169 | } |
|
- | 170 | ||
- | 171 | for (i=0; i<sizeof(staticParams.UserParams1); i++) { |
|
- | 172 | src = *((uint8_t*)(&staticParams + offsetof(paramset_t, UserParams1) + i)); |
|
- | 173 | pointerToTgt = (uint8_t*)(&dynamicParams + offsetof(dynamicParam_t, UserParams) + i); |
|
- | 174 | if (src < 255) { |
|
- | 175 | *pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
|
- | 176 | } |
|
- | 177 | } |
|
- | 178 | ||
- | 179 | for (i=0; i<sizeof(staticParams.UserParams2); i++) { |
|
- | 180 | src = *((uint8_t*)(&staticParams + offsetof(paramset_t, UserParams2) + i)); |
|
- | 181 | pointerToTgt = (uint8_t*)(&dynamicParams + offsetof(dynamicParam_t, UserParams) + sizeof(staticParams.UserParams1) + i); |
|
- | 182 | if (src < 255) { |
|
- | 183 | *pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
|
- | 184 | } |
|
- | 185 | } |
|
- | 186 | } |
|
105 | 187 | ||
106 | uint8_t getCPUType(void) { // works only after reset or power on when the registers have default values |
188 | uint8_t getCPUType(void) { // works only after reset or power on when the registers have default values |
107 | uint8_t CPUType = ATMEGA644; |
189 | uint8_t CPUType = ATMEGA644; |
108 | if( (UCSR1A == 0x20) && (UCSR1C == 0x06) ) CPUType = ATMEGA644P; // initial Values for 644P after reset |
190 | if( (UCSR1A == 0x20) && (UCSR1C == 0x06) ) CPUType = ATMEGA644P; // initial Values for 644P after reset |
109 | return CPUType; |
191 | return CPUType; |