Rev 2025 | Rev 2102 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2025 | Rev 2099 | ||
---|---|---|---|
1 | #ifndef _CONFIGURATION_H |
1 | #ifndef _CONFIGURATION_H |
2 | #define _CONFIGURATION_H |
2 | #define _CONFIGURATION_H |
3 | 3 | ||
4 | #include <inttypes.h> |
4 | #include <inttypes.h> |
5 | #include <avr/io.h> |
5 | #include <avr/io.h> |
- | 6 | ||
- | 7 | #define MAX_CHANNELS 10 |
|
- | 8 | #define MAX_MOTORS 12 |
|
- | 9 | ||
- | 10 | // bitmask for VersionInfo_t.HardwareError[0] |
|
- | 11 | #define FC_ERROR0_GYRO_PITCH 0x01 |
|
- | 12 | #define FC_ERROR0_GYRO_ROLL 0x02 |
|
- | 13 | #define FC_ERROR0_GYRO_YAW 0x04 |
|
- | 14 | #define FC_ERROR0_ACC_X 0x08 |
|
- | 15 | #define FC_ERROR0_ACC_Y 0x10 |
|
- | 16 | #define FC_ERROR0_ACC_Z 0x20 |
|
- | 17 | #define FC_ERROR0_PRESSURE 0x40 |
|
- | 18 | #define FC_ERROR1_RES0 0x80 |
|
- | 19 | // bitmask for VersionInfo_t.HardwareError[1] |
|
- | 20 | #define FC_ERROR1_I2C 0x01 |
|
- | 21 | #define FC_ERROR1_BL_MISSING 0x02 |
|
- | 22 | #define FC_ERROR1_SPI_RX 0x04 |
|
- | 23 | #define FC_ERROR1_PPM 0x08 |
|
- | 24 | #define FC_ERROR1_MIXER 0x10 |
|
- | 25 | #define FC_ERROR1_RES1 0x20 |
|
- | 26 | #define FC_ERROR1_RES2 0x40 |
|
- | 27 | #define FC_ERROR1_RES3 0x80 |
|
- | 28 | ||
- | 29 | typedef struct { |
|
- | 30 | uint8_t SWMajor; |
|
- | 31 | uint8_t SWMinor; |
|
- | 32 | uint8_t protoMajor; |
|
- | 33 | uint8_t protoMinor; |
|
- | 34 | uint8_t SWPatch; |
|
- | 35 | uint8_t hardwareErrors[5]; |
|
- | 36 | }__attribute__((packed)) VersionInfo_t; |
|
- | 37 | ||
- | 38 | extern VersionInfo_t versionInfo; |
|
6 | 39 | ||
7 | typedef struct { |
40 | typedef struct { |
8 | /*PMM*/uint8_t HeightD; |
41 | /*PMM*/uint8_t gyroPitchD; |
9 | /* P */uint8_t MaxHeight; |
42 | /* P */uint8_t gyroRollD; |
- | 43 | /* P */uint8_t gyroYawD; |
|
10 | /*PMM*/uint8_t HeightP; |
44 | |
11 | /* P */uint8_t Height_ACC_Effect; |
45 | // Control |
12 | /* P */uint8_t CompassYawEffect; |
46 | /* P */uint8_t externalControl; |
13 | 47 | ||
14 | /* P */uint8_t GyroPitchP; |
48 | // Height control |
15 | /* P */uint8_t GyroRollP; |
49 | /*PMM*/uint8_t heightP; |
16 | /* P */uint8_t GyroYawP; |
- | |
17 | 50 | /* P */uint8_t heightI; |
|
18 | /* P */uint8_t UserParams[8]; |
51 | /*PMM*/uint8_t heightD; |
19 | /* P */uint8_t ServoPitchControl; |
52 | /* P */uint8_t heightSetting; |
20 | 53 | ||
21 | /* P */uint8_t GyroPitchD; // LoopGasLimit in tool |
54 | // Output and servo |
22 | /* P */uint8_t GyroRollD; // AxisCoupling1 in tool |
55 | /*PMM*/uint8_t output0Timing; |
23 | /* P */uint8_t GyroYawD; // AxisCoupling2 in tool |
56 | /*PMM*/uint8_t output1Timing; |
24 | 57 | ||
25 | /* P */uint8_t ExternalControl; |
- | |
- | 58 | uint8_t servoManualControl[2]; |
|
26 | /*PMM*/uint8_t J16Timing; |
59 | |
27 | /*PMM*/uint8_t J17Timing; |
60 | /* P */uint8_t userParams[8]; |
- | 61 | } DynamicParams_t; |
|
28 | } dynamicParam_t; |
62 | |
29 | extern dynamicParam_t dynamicParams; |
63 | extern volatile DynamicParams_t dynamicParams; |
30 | 64 | ||
31 | typedef struct { |
65 | typedef struct { |
32 | uint8_t sourceIdx, targetIdx; |
66 | uint8_t sourceIdx, targetIdx; |
33 | uint8_t min, max; |
67 | uint8_t min, max; |
34 | } MMXLATION; |
68 | } MMXLATION; |
- | 69 | ||
35 | 70 | /* |
|
36 | typedef struct { |
71 | typedef struct { |
37 | uint8_t sourceIdx, targetIdx; |
72 | uint8_t sourceIdx, targetIdx; |
38 | } XLATION; |
73 | } XLATION; |
- | 74 | */ |
|
- | 75 | ||
- | 76 | typedef struct { |
|
- | 77 | uint8_t channels[MAX_CHANNELS]; |
|
- | 78 | } channelMap_t; |
|
- | 79 | extern channelMap_t channelMap; |
|
- | 80 | ||
- | 81 | typedef struct { |
|
- | 82 | char name[12]; |
|
- | 83 | int8_t motor[MAX_MOTORS][4]; |
|
- | 84 | }__attribute__((packed)) mixerMatrix_t; |
|
- | 85 | extern mixerMatrix_t mixerMatrix; |
|
39 | - | ||
40 | // values above 250 representing poti1 to poti4 |
86 | |
41 | typedef struct { |
- | |
42 | uint8_t ChannelAssignment[8]; // see upper defines for details |
- | |
43 | uint8_t GlobalConfig; // see upper defines for bitcoding |
- | |
44 | uint8_t HeightMinGas; // Value : 0-100 |
- | |
45 | uint8_t HeightD; // Value : 0-250 |
- | |
46 | uint8_t MaxHeight; // Value : 0-32 |
- | |
47 | uint8_t HeightP; // Value : 0-32 |
- | |
48 | uint8_t Height_Gain; // Value : 0-50 |
- | |
49 | uint8_t Height_ACC_Effect; // Value : 0-250 |
- | |
50 | 87 | typedef struct { |
|
51 | uint8_t StickElevatorP; |
- | |
52 | uint8_t StickAileronsP; |
88 | int16_t offsets[3]; |
- | 89 | } sensorOffset_t; |
|
- | 90 | ||
53 | uint8_t StickRudderP; |
91 | typedef struct { |
- | 92 | uint8_t manualControl; |
|
- | 93 | uint8_t stabilizationFactor; |
|
- | 94 | uint8_t minValue; |
|
- | 95 | uint8_t maxValue; |
|
- | 96 | uint8_t flags; |
|
- | 97 | } servo_t; |
|
- | 98 | ||
- | 99 | #define SERVO_STABILIZATION_REVERSE 1 |
|
- | 100 | ||
- | 101 | typedef struct { |
|
- | 102 | uint8_t bitmask; |
|
- | 103 | uint8_t timing; |
|
- | 104 | } output_flash_t; |
|
- | 105 | ||
- | 106 | typedef struct { |
|
- | 107 | uint8_t gyroQuadrant; |
|
54 | 108 | uint8_t accQuadrant; |
|
- | 109 | uint8_t imuReversedFlags; |
|
55 | uint8_t PIDGyroFilter;// Value: 1-8 |
110 | |
- | 111 | uint8_t gyroPIDFilterConstant; |
|
- | 112 | uint8_t gyroDWindowLength; |
|
- | 113 | uint8_t gyroDFilterConstant; |
|
- | 114 | uint8_t accFilterConstant; |
|
- | 115 | ||
- | 116 | uint8_t zerothOrderCorrection; |
|
- | 117 | uint8_t rateTolerance; |
|
- | 118 | ||
- | 119 | uint8_t gyroActivityDamping; |
|
56 | 120 | uint8_t driftCompDivider; // 1/k (Koppel_ACC_Wirkung) |
|
- | 121 | uint8_t driftCompLimit; // limit for gyrodrift compensation |
|
57 | uint8_t DGyroFilter; // Value: 1-8 |
122 | } IMUConfig_t; |
58 | uint8_t attitudeGyroFilter; // Value: 1-8 |
123 | |
59 | 124 | extern IMUConfig_t IMUConfig; |
|
- | 125 | ||
60 | uint8_t accFilter; |
126 | // values above 250 representing poti1 to poti4 |
- | 127 | typedef struct { |
|
61 | 128 | // Global bitflags |
|
- | 129 | uint8_t bitConfig; // see upper defines for bitcoding |
|
- | 130 | ||
62 | uint8_t GyroPitchP; |
131 | // uint8_t axisCoupling1; // Value: 0-250 Faktor, mit dem Yaw die Achsen Roll und Nick koppelt (NickRollMitkopplung) |
63 | uint8_t GyroRollP; |
132 | // uint8_t axisCoupling2; // Value: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden |
64 | uint8_t GyroYawP; |
133 | // uint8_t axisCouplingYawCorrection;// Value: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden |
65 | 134 | ||
66 | uint8_t UserParams[8]; // Value : 0-250 |
135 | uint8_t levelCorrection[2]; |
- | 136 | ||
67 | 137 | // Control |
|
68 | uint8_t LowVoltageWarning; // Value : 0-250 |
138 | uint8_t gyroPitchP; |
69 | 139 | uint8_t gyroPitchI; |
|
70 | uint8_t servoDirections; |
140 | uint8_t gyroPitchD; |
71 | uint8_t ServoRefresh; // Value: 0-250 // Refreshrate of servo pwm output |
141 | |
72 | - | ||
73 | uint8_t GyroPitchD; |
- | |
74 | uint8_t GyroRollD; |
- | |
75 | uint8_t GyroYawD; |
142 | uint8_t gyroRollP; |
76 | - | ||
77 | uint8_t zerothOrderGyroCorrectionZAccLimit; |
143 | uint8_t gyroRollI; |
- | 144 | uint8_t gyroRollD; |
|
- | 145 | ||
78 | uint8_t zerothOrderGyroCorrectionFactorx1000; |
146 | uint8_t gyroYawP; |
- | 147 | uint8_t gyroYawI; |
|
- | 148 | uint8_t gyroYawD; |
|
79 | 149 | ||
- | 150 | uint8_t stickIElevator; |
|
80 | uint8_t secondOrderGyroCorrectionDivisor; |
151 | uint8_t stickIAilerons; |
81 | uint8_t secondOrderGyroCorrectionLimit; |
152 | uint8_t stickIRudder; |
82 | uint8_t CompassYawEffect; // Value : 0-32 |
153 | |
83 | 154 | uint8_t externalControl; // for serial Control |
|
- | 155 | ||
- | 156 | uint8_t IFactor; |
|
84 | uint8_t J16Bitmask; // for the J16 Output |
157 | |
- | 158 | uint8_t batteryVoltageWarning; |
|
- | 159 | uint8_t emergencyThrottle; |
|
- | 160 | uint8_t emergencyFlightDuration; |
|
- | 161 | ||
85 | uint8_t J16Timing; // for the J16 Output |
162 | // Servos |
86 | uint8_t J17Bitmask; // for the J17 Output |
163 | uint8_t servoCount; |
87 | uint8_t J17Timing; // for the J17 Output |
164 | uint8_t servoManualMaxSpeed; |
88 | 165 | servo_t servoConfigurations[2]; // [PITCH, ROLL] |
|
89 | uint8_t ExternalControl; // for serial Control |
166 | |
90 | } paramset_t; |
167 | // Outputs |
91 | 168 | output_flash_t outputFlash[2]; |
|
92 | #define PARAMSET_STRUCT_LEN sizeof(paramset_t) |
169 | uint8_t outputDebugMask; |
93 | 170 | uint8_t outputFlags; |
|
94 | extern paramset_t staticParams; |
171 | |
95 | 172 | // User params |
|
96 | typedef struct { |
173 | uint8_t userParams[8]; |
97 | uint8_t Revision; |
174 | |
98 | int8_t Name[12]; |
175 | // Name |
99 | int8_t Motor[16][4]; |
176 | char name[12]; |
100 | }__attribute__((packed)) MixerTable_t; |
177 | } ParamSet_t; |
101 | 178 | ||
102 | extern MixerTable_t Mixer; |
179 | extern ParamSet_t staticParams; |
103 | 180 | ||
104 | // MKFlags |
181 | // MKFlags |
105 | #define MKFLAG_MOTOR_RUN (1<<0) |
182 | #define MKFLAG_MOTOR_RUN (1<<0) |
106 | #define MKFLAG_FLY (1<<1) |
183 | //#define MKFLAG_FLY (1<<1) |
107 | #define MKFLAG_CALIBRATE (1<<2) |
184 | #define MKFLAG_CALIBRATE (1<<2) |
108 | #define MKFLAG_START (1<<3) |
185 | #define MKFLAG_START (1<<3) |
109 | #define MKFLAG_EMERGENCY_LANDING (1<<4) |
186 | #define MKFLAG_EMERGENCY_FLIGHT (1<<4) |
110 | #define MKFLAG_RESERVE1 (1<<5) |
187 | #define MKFLAG_LOWBAT (1<<5) |
111 | #define MKFLAG_RESERVE2 (1<<6) |
188 | #define MKFLAG_RESERVE2 (1<<6) |
112 | #define MKFLAG_RESERVE3 (1<<7) |
189 | #define MKFLAG_RESERVE3 (1<<7) |
113 | 190 | ||
114 | // bit mask for staticParams.GlobalConfig |
191 | // bit mask for staticParams.bitConfig |
115 | #define CFG_HEIGHT_CONTROL (1<<0) |
192 | #define CFG_SIMPLE_HEIGHT_CONTROL (1<<0) |
116 | #define CFG_HEIGHT_SWITCH (1<<1) |
193 | #define CFG_SIMPLE_HC_HOLD_SWITCH (1<<1) |
117 | #define CFG_HEADING_HOLD (1<<2) |
194 | #define CFG_HEADING_HOLD (1<<2) |
118 | #define CFG_COMPASS_ACTIVE (1<<3) |
195 | #define CFG_COMPASS_ENABLED (1<<3) |
119 | #define CFG_COMPASS_FIX (1<<4) |
196 | #define CFG_UNUSED (1<<4) |
120 | #define CFG_GPS_ACTIVE (1<<5) |
197 | #define CFG_NAVI_ENABLED (1<<5) |
121 | #define CFG_AXIS_COUPLING_ACTIVE (1<<6) |
198 | #define CFG_AXIS_COUPLING_ENABLED (1<<6) |
122 | #define CFG_ROTARY_RATE_LIMITER (1<<7) |
199 | #define CFG_GYRO_SATURATION_PREVENTION (1<<7) |
123 | 200 | ||
124 | // bit mask for staticParams.ServoDirections |
201 | #define IMU_REVERSE_GYRO_PR (1<<0) |
125 | #define SERVO_DIRECTION_ELEVATOR (1<<0) |
202 | #define IMU_REVERSE_GYRO_YAW (1<<1) |
126 | #define SERVO_DIRECTION_AILERONS (1<<1) |
203 | #define IMU_REVERSE_ACC_XY (1<<2) |
127 | #define SERVO_DIRECTION_RUDDER (1<<2) |
204 | #define IMU_REVERSE_ACC_Z (1<<3) |
128 | 205 | ||
129 | #define ATMEGA644 0 |
206 | #define ATMEGA644 0 |
130 | #define ATMEGA644P 1 |
207 | #define ATMEGA644P 1 |
131 | #define SYSCLK F_CPU |
208 | #define SYSCLK F_CPU |
132 | 209 | ||
133 | // Not really a part of configuration, but LEDs and HW version test are the same. |
210 | // Not really a part of configuration, but LEDs and HW s test are the same. |
134 | #define RED_OFF {if((BoardRelease == 10) || (BoardRelease == 20)) PORTB &=~(1<<PORTB0); else PORTB |= (1<<PORTB0);} |
211 | #define RED_OFF {if((boardRelease == 10) || (boardRelease == 20)) PORTB &=~(1<<PORTB0); else PORTB |= (1<<PORTB0);} |
135 | #define RED_ON {if((BoardRelease == 10) || (BoardRelease == 20)) PORTB |= (1<<PORTB0); else PORTB &=~(1<<PORTB0);} |
212 | #define RED_ON {if((boardRelease == 10) || (boardRelease == 20)) PORTB |= (1<<PORTB0); else PORTB &=~(1<<PORTB0);} |
136 | #define RED_FLASH PORTB ^= (1<<PORTB0) |
213 | #define RED_FLASH PORTB ^= (1<<PORTB0) |
137 | #define GRN_OFF {if(BoardRelease < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);} |
214 | #define GRN_OFF {if(boardRelease < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);} |
138 | #define GRN_ON {if(BoardRelease < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);} |
215 | #define GRN_ON {if(boardRelease < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);} |
139 | #define GRN_FLASH PORTB ^= (1<<PORTB1) |
216 | #define GRN_FLASH PORTB ^= (1<<PORTB1) |
140 | 217 | ||
141 | // Mixer table |
218 | // Mixer table |
142 | #define MIX_THROTTLE 0 |
219 | #define MIX_THROTTLE 0 |
143 | #define MIX_PITCH 1 |
220 | #define MIX_PITCH 1 |
144 | #define MIX_ROLL 2 |
221 | #define MIX_ROLL 2 |
145 | #define MIX_YAW 3 |
222 | #define MIX_YAW 3 |
- | 223 | ||
- | 224 | #define VARIABLE_COUNT 8 |
|
146 | 225 | ||
- | 226 | extern volatile uint8_t MKFlags; |
|
147 | extern volatile uint8_t MKFlags; |
227 | extern uint8_t requiredMotors; |
148 | extern int16_t variables[8]; // The "Poti"s. |
228 | extern int16_t variables[VARIABLE_COUNT]; // The "Poti"s. |
149 | extern uint8_t BoardRelease; |
229 | extern uint8_t boardRelease; |
- | 230 | extern uint8_t CPUType; |
|
- | 231 | ||
- | 232 | extern volatile uint8_t MKFlags; |
|
- | 233 | extern uint16_t isFlying; |
|
- | 234 | ||
- | 235 | void IMUConfig_default(void); |
|
- | 236 | void channelMap_default(void); |
|
- | 237 | void paramSet_default(uint8_t setnumber); |
|
- | 238 | void mixerMatrix_default(void); |
|
- | 239 | ||
150 | extern uint8_t CPUType; |
240 | void configuration_setNormalFlightParameters(void); |
- | 241 | void configuration_setFailsafeFlightParameters(void); |
|
151 | 242 | void configuration_applyVariablesToParams(void); |
|
152 | void configuration_staticToDynamic(void); |
243 | |
- | 244 | void setCPUType(void); |
|
- | 245 | void setBoardRelease(void); |
|
153 | uint8_t getCPUType(void); |
246 | |
154 | uint8_t getBoardRelease(void); |
247 | // Called after a change in configuration parameters, as a hook for modules to take over changes. |
155 | 248 | void configuration_paramSetDidChange(void); |
|
156 | #endif // _CONFIGURATION_H |
249 | #endif // _CONFIGURATION_H |
157 | 250 |