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 | |||
35 | #define SPEAK_MK_OFF 38 |
||
36 | #define SPEAK_ALTITUDE_ON 39 |
||
37 | #define SPEAK_ALTITUDE_OFF 40 |
||
397 | holgerb | 38 | #define SPEAK_CF_ON 46 |
486 | holgerb | 39 | #define SPEAK_SINKING 47 |
40 | #define SPEAK_RISING 48 |
||
41 | #define SPEAK_HOLDING 49 |
||
397 | holgerb | 42 | #define SPEAK_GPS_ON 50 |
486 | holgerb | 43 | #define SPEAK_FOLLWING 51 |
44 | #define SPEAK_STARTING 52 |
||
41 | ingob | 45 | |
397 | holgerb | 46 | |
1 | ingob | 47 | #define SS_PIN GPIO_ReadBit(GPIO2, GPIO_Pin_7) |
48 | |||
202 | killagreg | 49 | #define SPI_FCCMD_USER 10 |
50 | #define SPI_FCCMD_STICK 11 |
||
51 | #define SPI_FCCMD_MISC 12 |
||
52 | #define SPI_FCCMD_PARAMETER1 13 |
||
53 | #define SPI_FCCMD_VERSION 14 |
||
587 | holgerb | 54 | #define SPI_FCCMD_SLOW3 15 |
454 | holgerb | 55 | #define SPI_FCCMD_BL_ACCU 16 |
419 | holgerb | 56 | #define SPI_FCCMD_PARAMETER2 17 |
573 | holgerb | 57 | #define SPI_FCCMD_NEUTRAL 18 |
58 | #define SPI_FCCMD_SLOW 19 // kommt nicht vor |
||
587 | holgerb | 59 | #define SPI_FCCMD_SLOW2 20 |
41 | ingob | 60 | |
426 | holgerb | 61 | #define CHK_POTI(b,a) { if(a < 248) b = a; else b = FC.Poti[255 - a]; } |
62 | #define CHK_POTI_MM(b,a,min,max) {CHK_POTI(b,a); LIMIT_MIN_MAX(b, min, max); } |
||
63 | |||
519 | holgerb | 64 | // devides only the Poti-value |
65 | #define CHK_POTI_DIV(b,a,div) { if(a < 248) b = a; else b = FC.Poti[255 - a] / div; } |
||
66 | #define CHK_POTI_MM_DIV(b,a,min,max,div) {CHK_POTI_DIV(b,a,div); LIMIT_MIN_MAX(b, min, max); } |
||
67 | |||
149 | killagreg | 68 | extern s32 Kalman_K; |
330 | holgerb | 69 | extern s32 Kalman_Kompass ; |
41 | ingob | 70 | extern s32 Kalman_MaxDrift; |
71 | extern s32 Kalman_MaxFusion; |
||
148 | holgerb | 72 | extern s32 ToFcGpsZ; |
222 | holgerb | 73 | extern s32 ToFC_Rotate_C, ToFC_Rotate_S; |
587 | holgerb | 74 | extern s32 HeadFreeStartAngle,CompassDirectionAtMotorStart; |
577 | holgerb | 75 | extern s16 FC_WP_EventChannel,LogFC_WP_EventChannel,FC_WP_EventChannel_Processed; |
286 | killagreg | 76 | extern u32 ToFC_AltitudeRate; |
285 | holgerb | 77 | extern s32 ToFC_AltitudeSetpoint; |
323 | holgerb | 78 | extern u8 NC_GPS_ModeCharacter; |
330 | holgerb | 79 | extern u8 FC_is_Calibrated; |
80 | extern u8 FCCalibActive; |
||
489 | killagreg | 81 | extern u8 SpeakHoTT; |
460 | holgerb | 82 | extern u8 NC_Wait_for_LED; |
463 | holgerb | 83 | extern s16 GyroCompassCorrected; |
510 | holgerb | 84 | extern s16 CompassSetpointCorrected; // The compass setpoint that the FC tries to keep - corrected with the magnetic declination |
85 | extern s16 CompassSetpoint; |
||
530 | holgerb | 86 | extern u8 AmountOfMotors; |
559 | holgerb | 87 | extern s16 SimulatedDirection; // simulated compass direction |
510 | holgerb | 88 | |
338 | holgerb | 89 | extern u8 BL_MinOfMaxPWM; // indication if all BL-controllers run on full power |
530 | holgerb | 90 | extern u8 Logging_BL_MinOfMaxPWM; |
91 | extern u8 ErrorCheck_BL_MinOfMaxPWM; |
||
338 | holgerb | 92 | extern u32 FC_I2C_ErrorConter; |
93 | extern u8 FromFC_VarioCharacter; |
||
94 | extern u8 Logging_FCStatusFlags1,Logging_FCStatusFlags2; |
||
351 | holgerb | 95 | extern s16 POI_KameraNick; |
448 | holgerb | 96 | extern u8 NC_To_FC_Flags, NC_To_FC_Autostart; |
532 | holgerb | 97 | extern u16 FlugMinutenGesamt; |
578 | holgerb | 98 | extern u32 LoggingGasFilter, LoggingGasCnt; |
99 | extern u8 HoverGas; |
||
530 | holgerb | 100 | |
41 | ingob | 101 | typedef struct |
118 | killagreg | 102 | { |
103 | u8 Command; |
||
104 | s16 AngleNick; // NickAngle in 0.1 deg |
||
105 | s16 AngleRoll; // RollAngle in 0.1 deg |
||
106 | s16 AccNick; |
||
107 | s16 AccRoll; |
||
280 | killagreg | 108 | s16 GyroHeading; // Heading in 0.1 deg |
118 | killagreg | 109 | s16 GyroNick; |
110 | s16 GyroRoll; |
||
111 | s16 GyroYaw; |
||
284 | killagreg | 112 | u16 FCStatus; |
118 | killagreg | 113 | union |
114 | { |
||
205 | killagreg | 115 | u8 Byte[12]; |
118 | killagreg | 116 | s8 sByte[12]; |
205 | killagreg | 117 | u16 Int[6]; |
118 | s16 sInt[6]; |
||
119 | u32 Long[3]; |
||
120 | s32 sLong[3]; |
||
118 | killagreg | 121 | float Float[3]; |
122 | } Param; |
||
123 | u8 Chksum; |
||
41 | ingob | 124 | } __attribute__((packed)) FromFlightCtrl_t; |
125 | |||
351 | holgerb | 126 | //NC_To_FC_Flags |
127 | #define NC_TO_FC_FLYING_RANGE 0x01 |
||
128 | #define NC_TO_FC_EMERGENCY_LANDING 0x02 |
||
448 | holgerb | 129 | #define NC_TO_FC_AUTOSTART 0x04 |
489 | killagreg | 130 | #define NC_TO_FC_AUTOLANDING 0x08 // not used |
559 | holgerb | 131 | #define NC_TO_FC_SIMULATION_ACTIVE 0x10 // don't start motors if simulation ist active |
351 | holgerb | 132 | |
202 | killagreg | 133 | #define SPI_NCCMD_OSD_DATA 100 |
134 | #define SPI_NCCMD_GPS_POS 101 |
||
135 | #define SPI_NCCMD_GPS_TARGET 102 |
||
136 | #define SPI_NCCMD_KALMAN 103 |
||
137 | #define SPI_NCCMD_VERSION 104 |
||
204 | killagreg | 138 | #define SPI_NCCMD_GPSINFO 105 |
329 | holgerb | 139 | #define SPI_NCCMD_HOTT_INFO 106 |
342 | holgerb | 140 | #define SPI_MISC 107 |
1 | ingob | 141 | |
329 | holgerb | 142 | #define HOTT_VARIO_PACKET_ID 0x89 |
143 | #define HOTT_GPS_PACKET_ID 0x8A |
||
144 | #define HOTT_ELECTRIC_AIR_PACKET_ID 0x8E |
||
330 | holgerb | 145 | #define HOTT_GENERAL_PACKET_ID 0x8D |
462 | holgerb | 146 | #define JETI_GPS_PACKET_ID1 0x01 |
147 | #define JETI_GPS_PACKET_ID2 0x02 |
||
504 | holgerb | 148 | #define HOTT_WPL_NAME 0x03 |
329 | holgerb | 149 | |
41 | ingob | 150 | typedef struct |
151 | { |
||
152 | u8 Command; |
||
215 | killagreg | 153 | GPS_Stick_t GPSStick; |
419 | holgerb | 154 | s16 MagVecX; |
41 | ingob | 155 | s16 CompassHeading; |
489 | killagreg | 156 | s16 AccErrorN; |
157 | s16 AccErrorR; |
||
419 | holgerb | 158 | s16 MagVecY; |
489 | killagreg | 159 | s16 MagVecZ; |
41 | ingob | 160 | u16 BeepTime; |
161 | union |
||
162 | { |
||
205 | killagreg | 163 | u8 Byte[12]; |
41 | ingob | 164 | s8 sByte[12]; |
205 | killagreg | 165 | u16 Int[6]; |
166 | s16 sInt[6]; |
||
167 | u32 Long[3]; |
||
168 | s32 sLong[3]; |
||
41 | ingob | 169 | float Float[3]; |
170 | }Param; |
||
171 | u8 Chksum; |
||
172 | } __attribute__((packed)) ToFlightCtrl_t; |
||
1 | ingob | 173 | |
358 | holgerb | 174 | typedef struct |
175 | { |
||
176 | u8 Current; |
||
177 | u8 Temperature; |
||
178 | u8 MaxPWM; |
||
179 | u8 State; |
||
530 | holgerb | 180 | u8 NotReadyCnt; |
358 | holgerb | 181 | } __attribute__((packed)) Motor_t; |
1 | ingob | 182 | |
606 | holgerb | 183 | extern Motor_t Motor[MAX_MOTORS]; |
358 | holgerb | 184 | |
471 | holgerb | 185 | #define MOTOR_STATE_NEW_PROTOCOL_MASK 0x01 |
186 | #define MOTOR_STATE_FAST_MODE 0x02 |
||
187 | #define MOTOR_STATE_BL30 0x04 // extended Current measurement -> 200 = 20A 201 = 21A 255 = 75A (20+55) |
||
606 | holgerb | 188 | extern u8 Motor_Version[MAX_MOTORS]; // das kann nicht in die struct, weil der PC die Struktur bekommt |
471 | holgerb | 189 | |
190 | |||
41 | ingob | 191 | typedef struct |
1 | ingob | 192 | { |
41 | ingob | 193 | u8 Major; |
194 | u8 Minor; |
||
195 | u8 Patch; |
||
196 | u8 Compatible; |
||
61 | holgerb | 197 | u8 Hardware; |
41 | ingob | 198 | } __attribute__((packed)) SPI_Version_t; |
1 | ingob | 199 | |
215 | killagreg | 200 | extern FromFlightCtrl_t FromFlightCtrl; |
201 | extern ToFlightCtrl_t ToFlightCtrl; |
||
146 | killagreg | 202 | extern volatile u32 SPI0_Timeout; |
41 | ingob | 203 | extern SPI_Version_t FC_Version; |
514 | holgerb | 204 | extern s16 GPS_Aid_StickMultiplikator; |
392 | holgerb | 205 | extern u8 CompassCalState; |
619 | holgerb | 206 | extern u8 Out1TriggerUpdateNewData; |
1 | ingob | 207 | |
41 | ingob | 208 | void SPI0_Init(void); |
209 | void SPI0_GetFlightCtrlVersion(void); |
||
210 | void SPI0_UpdateBuffer(void); |
||
489 | killagreg | 211 | u16 BL3_Current(u8 who); // in 0.1A |
1 | ingob | 212 | |
41 | ingob | 213 | #endif //_SPI_SLAVE_H |