Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
41 | ingob | 1 | #ifndef _SPI_SLAVE_H |
2 | #define _SPI_SLAVE_H |
||
1 | ingob | 3 | |
41 | ingob | 4 | #include "fifo.h" |
215 | killagreg | 5 | #include "gps.h" |
606 | holgerb | 6 | #include "main.h" |
1 | ingob | 7 | |
486 | holgerb | 8 | #define SPEAK_ERR_CALIBARTION 1 |
9 | #define SPEAK_ERR_RECEICER 2 |
||
10 | #define SPEAK_ERR_DATABUS 3 |
||
11 | #define SPEAK_ERR_NAVI 4 |
||
12 | #define SPEAK_ERROR 5 |
||
13 | #define SPEAK_ERR_COMPASS 6 |
||
14 | #define SPEAK_ERR_SENSOR 7 |
||
15 | #define SPEAK_ERR_GPS 8 |
||
16 | #define SPEAK_ERR_MOTOR 9 |
||
17 | #define SPEAK_MAX_TEMPERAT 10 |
||
18 | #define SPEAK_ALTI_REACHED 11 |
||
19 | #define SPEAK_WP_REACHED 12 |
||
20 | #define SPEAK_NEXT_WP 13 |
||
21 | #define SPEAK_LANDING 14 |
||
22 | #define SPEAK_GPS_FIX 15 |
||
23 | #define SPEAK_UNDERVOLTAGE 16 |
||
24 | #define SPEAK_GPS_HOLD 17 |
||
25 | #define SPEAK_GPS_HOME 18 |
||
26 | #define SPEAK_GPS_OFF 19 |
||
27 | #define SPEAK_BEEP 20 |
||
28 | #define SPEAK_MIKROKOPTER 21 |
||
29 | #define SPEAK_CAPACITY 22 |
||
30 | #define SPEAK_CF_OFF 23 |
||
397 | holgerb | 31 | #define SPEAK_CALIBRATE 24 |
486 | holgerb | 32 | #define SPEAK_MAX_RANGE 25 |
33 | #define SPEAK_MAX_ALTITUD 26 |
||
34 | |||
622 | holgerb | 35 | #define SPEAK_20M 37 // ? |
486 | holgerb | 36 | #define SPEAK_MK_OFF 38 |
37 | #define SPEAK_ALTITUDE_ON 39 |
||
38 | #define SPEAK_ALTITUDE_OFF 40 |
||
622 | holgerb | 39 | #define SPEAK_100M 41 // ? |
636 | holgerb | 40 | #define SPEAK_CONNECTED 42 |
397 | holgerb | 41 | #define SPEAK_CF_ON 46 |
622 | holgerb | 42 | #define SPEAK_SINKING 47 // ? |
486 | holgerb | 43 | #define SPEAK_RISING 48 |
622 | holgerb | 44 | #define SPEAK_HOLDING 49 // ? |
636 | holgerb | 45 | #define SPEAK_GPS_ON 50 // ? |
622 | holgerb | 46 | #define SPEAK_FOLLWING 51 // ? |
486 | holgerb | 47 | #define SPEAK_STARTING 52 |
41 | ingob | 48 | |
397 | holgerb | 49 | |
1 | ingob | 50 | #define SS_PIN GPIO_ReadBit(GPIO2, GPIO_Pin_7) |
51 | |||
202 | killagreg | 52 | #define SPI_FCCMD_USER 10 |
53 | #define SPI_FCCMD_STICK 11 |
||
54 | #define SPI_FCCMD_MISC 12 |
||
55 | #define SPI_FCCMD_PARAMETER1 13 |
||
56 | #define SPI_FCCMD_VERSION 14 |
||
587 | holgerb | 57 | #define SPI_FCCMD_SLOW3 15 |
454 | holgerb | 58 | #define SPI_FCCMD_BL_ACCU 16 |
419 | holgerb | 59 | #define SPI_FCCMD_PARAMETER2 17 |
573 | holgerb | 60 | #define SPI_FCCMD_NEUTRAL 18 |
61 | #define SPI_FCCMD_SLOW 19 // kommt nicht vor |
||
587 | holgerb | 62 | #define SPI_FCCMD_SLOW2 20 |
690 | holgerb | 63 | #define SPI_FCCMD_STICK2 21 |
41 | ingob | 64 | |
426 | holgerb | 65 | #define CHK_POTI(b,a) { if(a < 248) b = a; else b = FC.Poti[255 - a]; } |
66 | #define CHK_POTI_MM(b,a,min,max) {CHK_POTI(b,a); LIMIT_MIN_MAX(b, min, max); } |
||
67 | |||
519 | holgerb | 68 | // devides only the Poti-value |
69 | #define CHK_POTI_DIV(b,a,div) { if(a < 248) b = a; else b = FC.Poti[255 - a] / div; } |
||
70 | #define CHK_POTI_MM_DIV(b,a,min,max,div) {CHK_POTI_DIV(b,a,div); LIMIT_MIN_MAX(b, min, max); } |
||
71 | |||
149 | killagreg | 72 | extern s32 Kalman_K; |
330 | holgerb | 73 | extern s32 Kalman_Kompass ; |
41 | ingob | 74 | extern s32 Kalman_MaxDrift; |
75 | extern s32 Kalman_MaxFusion; |
||
148 | holgerb | 76 | extern s32 ToFcGpsZ; |
222 | holgerb | 77 | extern s32 ToFC_Rotate_C, ToFC_Rotate_S; |
587 | holgerb | 78 | extern s32 HeadFreeStartAngle,CompassDirectionAtMotorStart; |
577 | holgerb | 79 | extern s16 FC_WP_EventChannel,LogFC_WP_EventChannel,FC_WP_EventChannel_Processed; |
286 | killagreg | 80 | extern u32 ToFC_AltitudeRate; |
285 | holgerb | 81 | extern s32 ToFC_AltitudeSetpoint; |
323 | holgerb | 82 | extern u8 NC_GPS_ModeCharacter; |
330 | holgerb | 83 | extern u8 FC_is_Calibrated; |
84 | extern u8 FCCalibActive; |
||
489 | killagreg | 85 | extern u8 SpeakHoTT; |
460 | holgerb | 86 | extern u8 NC_Wait_for_LED; |
463 | holgerb | 87 | extern s16 GyroCompassCorrected; |
510 | holgerb | 88 | extern s16 CompassSetpointCorrected; // The compass setpoint that the FC tries to keep - corrected with the magnetic declination |
89 | extern s16 CompassSetpoint; |
||
530 | holgerb | 90 | extern u8 AmountOfMotors; |
559 | holgerb | 91 | extern s16 SimulatedDirection; // simulated compass direction |
690 | holgerb | 92 | |
93 | #define MAX_RC_IN 16+12+3+4 // 16ch + 12ser + 3stages + 4 reserved |
||
94 | extern s8 PPM_In[MAX_RC_IN]; |
||
510 | holgerb | 95 | |
338 | holgerb | 96 | extern u8 BL_MinOfMaxPWM; // indication if all BL-controllers run on full power |
530 | holgerb | 97 | extern u8 Logging_BL_MinOfMaxPWM; |
98 | extern u8 ErrorCheck_BL_MinOfMaxPWM; |
||
338 | holgerb | 99 | extern u32 FC_I2C_ErrorConter; |
100 | extern u8 FromFC_VarioCharacter; |
||
101 | extern u8 Logging_FCStatusFlags1,Logging_FCStatusFlags2; |
||
351 | holgerb | 102 | extern s16 POI_KameraNick; |
448 | holgerb | 103 | extern u8 NC_To_FC_Flags, NC_To_FC_Autostart; |
532 | holgerb | 104 | extern u16 FlugMinutenGesamt; |
578 | holgerb | 105 | extern u32 LoggingGasFilter, LoggingGasCnt; |
106 | extern u8 HoverGas; |
||
690 | holgerb | 107 | extern s16 FromFlightCtrl_AccNick,FromFlightCtrl_AccRoll,FromFlightCtrl_GyroNick,FromFlightCtrl_GyroRoll; |
693 | holgerb | 108 | extern u8 RequestConfigFromFC; |
530 | holgerb | 109 | |
41 | ingob | 110 | typedef struct |
118 | killagreg | 111 | { |
112 | u8 Command; |
||
113 | s16 AngleNick; // NickAngle in 0.1 deg |
||
114 | s16 AngleRoll; // RollAngle in 0.1 deg |
||
280 | killagreg | 115 | s16 GyroHeading; // Heading in 0.1 deg |
118 | killagreg | 116 | s16 GyroYaw; |
284 | killagreg | 117 | u16 FCStatus; |
118 | killagreg | 118 | union |
119 | { |
||
690 | holgerb | 120 | u8 Byte[20]; |
121 | s8 sByte[20]; |
||
122 | u16 Int[10]; |
||
123 | s16 sInt[10]; |
||
124 | u32 Long[5]; |
||
125 | s32 sLong[5]; |
||
126 | float Float[5]; |
||
127 | } __attribute__((packed)) Param; |
||
118 | killagreg | 128 | u8 Chksum; |
41 | ingob | 129 | } __attribute__((packed)) FromFlightCtrl_t; |
130 | |||
202 | killagreg | 131 | #define SPI_NCCMD_OSD_DATA 100 |
132 | #define SPI_NCCMD_GPS_POS 101 |
||
133 | #define SPI_NCCMD_GPS_TARGET 102 |
||
134 | #define SPI_NCCMD_KALMAN 103 |
||
135 | #define SPI_NCCMD_VERSION 104 |
||
204 | killagreg | 136 | #define SPI_NCCMD_GPSINFO 105 |
329 | holgerb | 137 | #define SPI_NCCMD_HOTT_INFO 106 |
342 | holgerb | 138 | #define SPI_MISC 107 |
690 | holgerb | 139 | #define SPI_SERIAL_CH 108 |
1 | ingob | 140 | |
329 | holgerb | 141 | #define HOTT_VARIO_PACKET_ID 0x89 |
142 | #define HOTT_GPS_PACKET_ID 0x8A |
||
143 | #define HOTT_ELECTRIC_AIR_PACKET_ID 0x8E |
||
330 | holgerb | 144 | #define HOTT_GENERAL_PACKET_ID 0x8D |
462 | holgerb | 145 | #define JETI_GPS_PACKET_ID1 0x01 |
146 | #define JETI_GPS_PACKET_ID2 0x02 |
||
504 | holgerb | 147 | #define HOTT_WPL_NAME 0x03 |
329 | holgerb | 148 | |
41 | ingob | 149 | typedef struct |
150 | { |
||
151 | u8 Command; |
||
215 | killagreg | 152 | GPS_Stick_t GPSStick; |
41 | ingob | 153 | s16 CompassHeading; |
489 | killagreg | 154 | s16 AccErrorN; |
155 | s16 AccErrorR; |
||
41 | ingob | 156 | union |
157 | { |
||
690 | holgerb | 158 | u8 Byte[20]; |
159 | s8 sByte[20]; |
||
160 | u16 Int[10]; |
||
161 | s16 sInt[10]; |
||
162 | u32 Long[5]; |
||
163 | s32 sLong[5]; |
||
164 | float Float[5]; |
||
165 | } __attribute__((packed)) Param; |
||
41 | ingob | 166 | u8 Chksum; |
167 | } __attribute__((packed)) ToFlightCtrl_t; |
||
1 | ingob | 168 | |
358 | holgerb | 169 | typedef struct |
170 | { |
||
690 | holgerb | 171 | unsigned char Sync1,Sync2; |
172 | unsigned char WhoAmI; |
||
173 | unsigned char Data[240]; |
||
174 | unsigned char Chksum; |
||
175 | }__attribute__((packed)) str_HugeBlockFromFC; |
||
176 | extern str_HugeBlockFromFC HugeBlockFromFC; |
||
177 | |||
178 | typedef struct |
||
179 | { |
||
180 | unsigned char Sync1,Sync2; |
||
181 | unsigned char WhoAmI; |
||
182 | unsigned char Data[240]; |
||
183 | unsigned char Chksum; |
||
184 | }__attribute__((packed)) str_HugeBlockToFC; |
||
185 | extern str_HugeBlockToFC HugeBlockToFC; |
||
186 | |||
187 | typedef struct |
||
188 | { |
||
358 | holgerb | 189 | u8 Current; |
190 | u8 Temperature; |
||
191 | u8 MaxPWM; |
||
192 | u8 State; |
||
530 | holgerb | 193 | u8 NotReadyCnt; |
358 | holgerb | 194 | } __attribute__((packed)) Motor_t; |
1 | ingob | 195 | |
606 | holgerb | 196 | extern Motor_t Motor[MAX_MOTORS]; |
358 | holgerb | 197 | |
471 | holgerb | 198 | #define MOTOR_STATE_NEW_PROTOCOL_MASK 0x01 |
199 | #define MOTOR_STATE_FAST_MODE 0x02 |
||
200 | #define MOTOR_STATE_BL30 0x04 // extended Current measurement -> 200 = 20A 201 = 21A 255 = 75A (20+55) |
||
606 | holgerb | 201 | extern u8 Motor_Version[MAX_MOTORS]; // das kann nicht in die struct, weil der PC die Struktur bekommt |
471 | holgerb | 202 | |
203 | |||
41 | ingob | 204 | typedef struct |
1 | ingob | 205 | { |
41 | ingob | 206 | u8 Major; |
207 | u8 Minor; |
||
208 | u8 Patch; |
||
209 | u8 Compatible; |
||
61 | holgerb | 210 | u8 Hardware; |
41 | ingob | 211 | } __attribute__((packed)) SPI_Version_t; |
1 | ingob | 212 | |
693 | holgerb | 213 | |
215 | killagreg | 214 | extern FromFlightCtrl_t FromFlightCtrl; |
215 | extern ToFlightCtrl_t ToFlightCtrl; |
||
146 | killagreg | 216 | extern volatile u32 SPI0_Timeout; |
41 | ingob | 217 | extern SPI_Version_t FC_Version; |
514 | holgerb | 218 | extern s16 GPS_Aid_StickMultiplikator; |
392 | holgerb | 219 | extern u8 CompassCalState; |
619 | holgerb | 220 | extern u8 Out1TriggerUpdateNewData; |
625 | holgerb | 221 | extern u8 LowVoltageLandingActive; |
1 | ingob | 222 | |
41 | ingob | 223 | void SPI0_Init(void); |
224 | void SPI0_GetFlightCtrlVersion(void); |
||
225 | void SPI0_UpdateBuffer(void); |
||
489 | killagreg | 226 | u16 BL3_Current(u8 who); // in 0.1A |
1 | ingob | 227 | |
693 | holgerb | 228 | typedef struct |
229 | { |
||
230 | unsigned char Revision; |
||
231 | unsigned char Kanalbelegung[12]; // GAS[0], GIER[1],NICK[2], ROLL[3], POTI1, POTI2, POTI3 |
||
232 | unsigned char GlobalConfig; // 0x01=Höhenregler aktiv,0x02=Kompass aktiv, 0x04=GPS aktiv, 0x08=Heading Hold aktiv |
||
233 | unsigned char Hoehe_MinGas; // Wert : 0-100 |
||
234 | unsigned char Luftdruck_D; // Wert : 0-250 |
||
235 | unsigned char HoeheChannel; // Wert : 0-32 |
||
236 | unsigned char Hoehe_P; // Wert : 0-32 |
||
237 | unsigned char Hoehe_Verstaerkung; // Wert : 0-50 |
||
238 | unsigned char Hoehe_ACC_Wirkung; // Wert : 0-250 |
||
239 | unsigned char Hoehe_HoverBand; // Wert : 0-250 |
||
240 | unsigned char Hoehe_TiltCompensation; // Wert : 0-250 |
||
241 | unsigned char Hoehe_StickNeutralPoint;// Wert : 0-250 |
||
242 | unsigned char Stick_P; // Wert : 1-6 |
||
243 | unsigned char Stick_D; // Wert : 0-64 |
||
244 | unsigned char StickGier_P; // Wert : 1-20 |
||
245 | unsigned char Gas_Min; // Wert : 0-32 |
||
246 | unsigned char Gas_Max; // Wert : 33-250 |
||
247 | unsigned char GyroAccFaktor; // Wert : 1-64 |
||
248 | unsigned char KompassWirkung; // Wert : 0-32 |
||
249 | unsigned char Gyro_P; // Wert : 10-250 |
||
250 | unsigned char Gyro_I; // Wert : 0-250 |
||
251 | unsigned char Gyro_D; // Wert : 0-250 |
||
252 | unsigned char Gyro_Gier_P; // Wert : 10-250 |
||
253 | unsigned char Gyro_Gier_I; // Wert : 0-250 |
||
254 | unsigned char Gyro_Stability; // Wert : 0-16 |
||
255 | unsigned char UnterspannungsWarnung; // Wert : 0-250 |
||
256 | unsigned char NotGas; // Wert : 0-250 //Gaswert bei Empängsverlust |
||
257 | unsigned char NotGasZeit; // Wert : 0-250 // Zeitbis auf NotGas geschaltet wird, wg. Rx-Problemen |
||
258 | unsigned char Receiver; // 0= Summensignal, 1= Spektrum, 2 =Jeti, 3=ACT DSL, 4=ACT S3D |
||
259 | unsigned char I_Faktor; // Wert : 0-250 |
||
260 | unsigned char UserParam1; // Wert : 0-250 |
||
261 | unsigned char UserParam2; // Wert : 0-250 |
||
262 | unsigned char UserParam3; // Wert : 0-250 |
||
263 | unsigned char UserParam4; // Wert : 0-250 |
||
264 | unsigned char ServoNickControl; // Wert : 0-250 // Stellung des Servos |
||
265 | unsigned char ServoNickComp; // Wert : 0-250 // Einfluss Gyro/Servo |
||
266 | unsigned char ServoNickMin; // Wert : 0-250 // Anschlag |
||
267 | unsigned char ServoNickMax; // Wert : 0-250 // Anschlag |
||
268 | //--- Seit V0.75 |
||
269 | unsigned char ServoRollControl; // Wert : 0-250 // Stellung des Servos |
||
270 | unsigned char ServoRollComp; // Wert : 0-250 |
||
271 | unsigned char ServoRollMin; // Wert : 0-250 |
||
272 | unsigned char ServoRollMax; // Wert : 0-250 |
||
273 | //--- |
||
274 | unsigned char ServoNickRefresh; // Speed of the Servo |
||
275 | unsigned char ServoManualControlSpeed;// |
||
276 | unsigned char CamOrientation; // |
||
277 | unsigned char Servo3; // Value or mapping of the Servo Output |
||
278 | unsigned char Servo4; // Value or mapping of the Servo Output |
||
279 | unsigned char Servo5; // Value or mapping of the Servo Output |
||
280 | unsigned char LoopGasLimit; // Wert: 0-250 max. Gas während Looping |
||
281 | unsigned char LoopThreshold; // Wert: 0-250 Schwelle für Stickausschlag |
||
282 | unsigned char LoopHysterese; // Wert: 0-250 Hysterese für Stickausschlag |
||
283 | unsigned char AchsKopplung1; // Wert: 0-250 Faktor, mit dem Gier die Achsen Roll und Nick koppelt (NickRollMitkopplung) |
||
284 | unsigned char AchsKopplung2; // Wert: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden |
||
285 | unsigned char CouplingYawCorrection; // Wert: 0-250 Faktor, mit dem Nick und Roll verkoppelt werden |
||
286 | unsigned char WinkelUmschlagNick; // Wert: 0-250 180°-Punkt |
||
287 | unsigned char WinkelUmschlagRoll; // Wert: 0-250 180°-Punkt |
||
288 | unsigned char GyroAccAbgleich; // 1/k (Koppel_ACC_Wirkung) |
||
289 | unsigned char Driftkomp; |
||
290 | unsigned char DynamicStability; |
||
291 | unsigned char UserParam5; // Wert : 0-250 |
||
292 | unsigned char UserParam6; // Wert : 0-250 |
||
293 | unsigned char UserParam7; // Wert : 0-250 |
||
294 | unsigned char UserParam8; // Wert : 0-250 |
||
295 | //---Output --------------------------------------------- |
||
296 | unsigned char J16Bitmask; // for the J16 Output |
||
297 | unsigned char J16Timing; // for the J16 Output |
||
298 | unsigned char J17Bitmask; // for the J17 Output |
||
299 | unsigned char J17Timing; // for the J17 Output |
||
300 | // seit version V0.75c |
||
301 | unsigned char WARN_J16_Bitmask; // for the J16 Output |
||
302 | unsigned char WARN_J17_Bitmask; // for the J17 Output |
||
303 | //---NaviCtrl--------------------------------------------- |
||
304 | unsigned char AutoPhotoDistance; // Auto Photo |
||
305 | unsigned char NaviGpsModeChannel; // Parameters for the Naviboard |
||
306 | unsigned char NaviGpsGain; |
||
307 | unsigned char NaviGpsP; |
||
308 | unsigned char NaviGpsI; |
||
309 | unsigned char NaviGpsD; |
||
310 | unsigned char NaviGpsPLimit; |
||
311 | unsigned char NaviGpsILimit; |
||
312 | unsigned char NaviGpsDLimit; |
||
313 | unsigned char NaviGpsA; |
||
314 | unsigned char NaviGpsMinSat; |
||
315 | unsigned char NaviStickThreshold; |
||
316 | unsigned char NaviWindCorrection; |
||
317 | unsigned char NaviAccCompensation; // New since 0.86 -> was: SpeedCompensation |
||
318 | unsigned char NaviMaxFlyingRange; // in 10m |
||
319 | unsigned char NaviAngleLimitation; |
||
320 | unsigned char NaviPH_LoginTime; |
||
321 | unsigned char NaviDescendRange; |
||
322 | //---Ext.Ctrl--------------------------------------------- |
||
323 | unsigned char ExternalControl; // for serial Control |
||
324 | //---CareFree--------------------------------------------- |
||
325 | unsigned char OrientationAngle; // Where is the front-direction? |
||
326 | unsigned char CareFreeChannel; // switch for CareFree |
||
327 | unsigned char MotorSafetySwitch; |
||
328 | unsigned char MotorSmooth; |
||
329 | unsigned char ComingHomeAltitude; |
||
330 | unsigned char FailSafeTime; |
||
331 | unsigned char MaxAltitude; |
||
332 | unsigned char FailsafeChannel; // if the value of this channel is > 100, the MK reports "RC-Lost" |
||
333 | unsigned char ServoFilterNick; |
||
334 | unsigned char ServoFilterRoll; |
||
335 | unsigned char Servo3OnValue; |
||
336 | unsigned char Servo3OffValue; |
||
337 | unsigned char Servo4OnValue; |
||
338 | unsigned char Servo4OffValue; |
||
339 | unsigned char ServoFS_Pos[5]; |
||
340 | unsigned char StartLandChannel; |
||
341 | unsigned char LandingSpeed; |
||
342 | unsigned char CompassOffset; |
||
343 | unsigned char AutoLandingVoltage; // in 0,1V 0 -> disabled |
||
344 | unsigned char ComingHomeVoltage; // in 0,1V 0 -> disabled |
||
345 | unsigned char AutoPhotoAtitudes; |
||
346 | unsigned char SingleWpSpeed; |
||
347 | unsigned char LandingPulse; |
||
348 | unsigned char SingleWpControlChannel; |
||
349 | unsigned char MenuKeyChannel; |
||
350 | //------------------------------------------------ |
||
351 | unsigned char BitConfig; // (war Loop-Cfg) Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts / wird getrennt behandelt |
||
352 | unsigned char ServoCompInvert; // // 0x01 = Nick, 0x02 = Roll, 0x04 = relative moving // WICHTIG!!! am Ende lassen |
||
353 | unsigned char ExtraConfig; // bitcodiert |
||
354 | unsigned char GlobalConfig3; // bitcodiert |
||
355 | char Name[12]; |
||
356 | unsigned char crc; // must be the last byte! |
||
357 | } __attribute__((packed)) paramset_t; // 150 bytes |
||
358 | |||
359 | extern paramset_t EE_Parameter; |
||
360 | |||
41 | ingob | 361 | #endif //_SPI_SLAVE_H |