Rev 719 |
Rev 727 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#ifndef _MAIN_H
#define _MAIN_H
//#define FOLLOW_ME
#ifdef FOLLOW_ME
extern u8 TransmitAlsoToFC;
#endif
//-----------------------
//#define DEBUG 0
//-----------------------
#define VERSION_MAJOR 2
#define VERSION_MINOR 13
#define VERSION_PATCH 4
// 0 = A
// 1 = B
// 2 = C
// 3 = D
// 4 = E
// 5 = F
// 6 = G
// 7 = H
// 8 = I
// 9 = J
// 10 = k
// 11 = L
// 12 = M
// 13 = N
// 14 = O
// 15 = P
// 16 = Q
// 17 = R
// 18 = S
#define CAN_SLAVE_COMPATIBLE 1
#ifndef FOLLOW_ME
#define FC_SPI_COMPATIBLE 79 // <------------------
#else
#define FC_SPI_COMPATIBLE 0xFF
#endif
#define MK3MAG_I2C_COMPATIBLE 3
#define MAX_MOTORS 16 // since 2.10 (3.2014)
// FC.StatusFlags
#define FC_STATUS_MOTOR_RUN 0x01
#define FC_STATUS_FLY 0x02
#define FC_STATUS_CALIBRATE 0x04
#define FC_STATUS_START 0x08
#define FC_STATUS_EMERGENCY_LANDING 0x10
#define FC_STATUS_LOWBAT 0x20
#define FC_STATUS_VARIO_TRIM_UP 0x40
#define FC_STATUS_VARIO_TRIM_DOWN 0x80
// FC.StatusFlags2
#define FC_STATUS2_CAREFREE 0x01
#define FC_STATUS2_ALTITUDE_CONTROL 0x02
#define FC_STATUS2_RC_FAILSAVE_ACTIVE 0x04
#define FC_STATUS2_OUT1_ACTIVE 0x08
#define FC_STATUS2_OUT2_ACTIVE 0x10
#define FC_STATUS2_WAIT_FOR_TAKEOFF 0x20 // Motor Running, but still on the ground
#define FC_STATUS2_AUTO_STARTING 0x40
#define FC_STATUS2_AUTO_LANDING 0x80
// FC.StatusFlags3
#define FC_STATUS3_REDUNDANCE_AKTIVE 0x01
#define FC_STATUS3_BOAT 0x02
#define FC_STATUS3_REDUNDANCE_ERROR 0x04
#define FC_STATUS3_REDUNDANCE_TEST 0x08
#define FC_STATUS3_NOT_CALIBRATED 0x10
#define FC_STATUS3_MOTORS_STOPPED_BY_RC 0x20
#define OSD_FLAG_MASK1 (0x04 + 0x20 + 0x40 + 0x80)
#define OSD_FLAG_MASK2 (0x01 + 0x02 + 0x08 + 0x10)
// .NCFlags
#define NC_FLAG_FREE 0x01
#define NC_FLAG_PH 0x02
#define NC_FLAG_CH 0x04
#define NC_FLAG_RANGE_LIMIT 0x08
#define NC_FLAG_NOSERIALLINK 0x10
#define NC_FLAG_TARGET_REACHED 0x20
#define NC_FLAG_MANUAL_CONTROL 0x40
#define NC_FLAG_GPS_OK 0x80
// NC calculates
//OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
//OSDStatusFlags2 = (FC.StatusFlags & ~OSD_FLAG_MASK1) | (FC.StatusFlags2 & ~OSD_FLAG_MASK2);
//calculate Back:
//FC.StatusFlags = (OSDStatusFlags & OSD_FLAG_MASK1) | (OSDStatusFlags2 & ~OSD_FLAG_MASK1);
//FC.StatusFlags2 = (OSDStatusFlags & OSD_FLAG_MASK2) | (OSDStatusFlags2 & ~OSD_FLAG_MASK2);
// FC.Error[0]
#define FC_ERROR0_GYRO_NICK 0x01
#define FC_ERROR0_GYRO_ROLL 0x02
#define FC_ERROR0_GYRO_YAW 0x04
#define FC_ERROR0_ACC_NICK 0x08
#define FC_ERROR0_ACC_ROLL 0x10
#define FC_ERROR0_ACC_TOP 0x20
#define FC_ERROR0_PRESSURE 0x40
#define FC_ERROR0_CAREFREE 0x80
// FC.Error[1]
#define FC_ERROR1_I2C 0x01
#define FC_ERROR1_BL_MISSING 0x02
#define FC_ERROR1_SPI_RX 0x04
#define FC_ERROR1_PPM 0x08
#define FC_ERROR1_MIXER 0x10
#define FC_ERROR1_RC_VOLTAGE 0x20
#define FC_ERROR1_ACC_NOT_CAL 0x40
#define FC_ERROR1_RES3 0x80
// NC Errors
#define NCERR_FLAG_FC_COMPATIBLE 0x00000001
#define NCERR_FLAG_MK3MAG_COMPATIBLE 0x00000002
#define NCERR_FLAG_FC_COMMUNICATION 0x00000004
#define NCERR_FLAG_MK3MAG_COMMUNICATION 0x00000008
#define NCERR_FLAG_MKGPS_COMMUNICATION 0x00000010
#define NCERR_FLAG_BAD_COMPASS_HEADING 0x00000020
#define NCERR_FLAG_RC_SIGNAL_LOST 0x00000040
#define NCERR_FLAG_EEPROM_NOT_FOUND 0x00000080
//NC_To_FC_Flags
#define NC_TO_FC_FLYING_RANGE 0x01
#define NC_TO_FC_EMERGENCY_LANDING 0x02
#define NC_TO_FC_AUTOSTART 0x04
#define NC_TO_FC_FAILSAFE_LANDING 0x08 // activates Servos
#define NC_TO_FC_SIMULATION_ACTIVE 0x10 // don't start motors if simulation ist active
//Parameter.GlobalConfig3
#define CFG3_NO_SDCARD_NO_START 0x01
//#define CFG3_DPH_MAX_RADIUS 0x02
#define CFG3_VARIO_FAILSAFE 0x04
#define CFG3_MOTOR_SWITCH_MODE 0x08
#define CFG3_NO_GPSFIX_NO_START 0x10
// Parameter.GlobalConfig
#define FC_CFG_HOEHENREGELUNG 0x01
#define FC_CFG_HOEHEN_SCHALTER 0x02
#define FC_CFG_HEADING_HOLD 0x04
#define FC_CFG_KOMPASS_AKTIV 0x08
#define FC_CFG_KOMPASS_FIX 0x10
#define FC_CFG_GPS_AKTIV 0x20
#define FC_CFG_ACHSENKOPPLUNG_AKTIV 0x40
#define FC_CFG_DREHRATEN_BEGRENZER 0x80
//Parameter.ExtraConfig
#define CFG2_HEIGHT_LIMIT 0x01
#define CFG2_VARIO_BEEP 0x02
#define CFG_SENSITIVE_RC 0x04
#define CFG_3_3V_REFERENCE 0x08
#define CFG_NO_RCOFF_BEEPING 0x10
#define CFG_GPS_AID 0x20
#define CFG_TEACHABLE_CAREFREE 0x40
#define CFG_IGNORE_MAG_ERR_AT_STARTUP 0x80
// Parameter.HomeYawMode
#define NO_CHANGE 0
#define FRONT_TO_HOME 1
#define REAR_TO_HOME 2
#define LIKE_AT_START 3
// Parameter.ReceiverType defines for the receiver selection
#define RECEIVER_PPM 0
#define RECEIVER_SPEKTRUM 1
#define RECEIVER_SPEKTRUM_HI_RES 2
#define RECEIVER_SPEKTRUM_LOW_RES 3
#define RECEIVER_JETI 4
#define RECEIVER_ACT_DSL 5
#define RECEIVER_HOTT 6
#define RECEIVER_SBUS 7
#define RECEIVER_USER 8
#define RECEIVER_UNKNOWN 0xFF
#define LIMIT_MIN(value, min) {if(value <= min) value = min;}
#define LIMIT_MAX(value, max) {if(value >= max) value = max;}
#define LIMIT_MIN_MAX(value, min, max) {if(value <= min) value = min; else if(value >= max) value = max;}
#define Poti1 FC.Poti[0]
#define Poti2 FC.Poti[1]
#define Poti3 FC.Poti[2]
#define Poti4 FC.Poti[3]
#define Poti5 FC.Poti[4]
#define Poti6 FC.Poti[5]
#define Poti7 FC.Poti[6]
#define Poti8 FC.Poti[7]
extern u16 BeepTime;
extern u8 NCFlags;
extern u8 ClearFCStatusFlags;
void Interrupt_Init(void);
extern s16 GeoMagDec;
extern u8 NewWPL_Name;
#define NOTHING 0
#define MASTER 1
#define SLAVE 2
extern u8 IamMaster;
#define VERSION_SERIAL_MAJOR 11 // do not change!
typedef struct
{
u8 ActiveSetting;
u8 User1;
u8 User2;
u8 User3;
u8 User4;
u8 User5;
u8 User6;
u8 User7;
u8 User8;
u8 NaviGpsModeControl;
u8 NaviGpsGain;
u8 NaviGpsP;
u8 NaviGpsI;
u8 NaviGpsD;
u8 NaviGpsPLimit;
u8 NaviGpsILimit;
u8 NaviGpsDLimit;
u8 NaviGpsACC;
u8 NaviGpsMinSat;
u8 NaviStickThreshold;
u8 NaviMaxFlyingRange; // in 10m
u8 NaviWindCorrection;
u8 NaviAccCompensation;
u8 NaviSpeedCompensation;
u8 LowVoltageWarning;
u8 NaviAngleLimitation;
u8 NaviPH_LoginTime;
u8 OrientationAngle; // where is front - in 15°
u8 CamOrientation; // direction of the camera in 15°
u8 GlobalConfig;
u8 ExtraConfig;
u8 ComingHomeAltitude;
u8 GlobalConfig3;
u8 AutoPhotoDistance; // Distance between Photo releases (Position)
u8 FromFC_LandingSpeed;
u8 FromFC_LowVoltageHomeActive;
u8 AutoPhotoAltitudes; // Distance between Photo releases (Altitudes)
u8 SingleWpSpeed;
u8 DescendRange; // in 10m
u8 MaximumAltitude; // in m
u8 Driftkomp;
u8 ReceiverType;
u8 HomeYawMode;
u8 Speak100m;
u8 AutoWpEventValue;
u8 FailSafeTime;
} __attribute__((packed)) Param_t;
typedef struct
{
s8 StickNick;
s8 StickRoll;
s8 StickYaw;
s8 StickGas;
u8 Poti[8];
u8 RC_Quality;
u8 RC_RSSI;
u16 BAT_Voltage;
u16 BAT_Current;
u16 BAT_UsedCapacity;
u8 StatusFlags;
u8 Error[5];
u8 StatusFlags2;
u8 FromFC_SpeakHoTT;
s16 FromFC_CompassOffset;
u8 FromFC_DisableDeclination;
u8 StatusFlags3;
s16 Altimeter;
u8 RealStatusFlags; // this is a copy of the status flags -> but not effected by the simulation
u16 AdNeutralNick;
u16 AdNeutralRoll;
u16 AdNeutralYaw;
u16 BoatNeutralNick;
u16 BoatNeutralRoll;
u16 BoatNeutralYaw;
u8 AutoPhotoDistance;
} __attribute__((packed)) FC_t; // from FC
typedef struct
{
u8 ErrorCode;
u8 StatusFlags;
u8 StatusFlags2;
u8 StatusFlags3;
u8 NC_To_FC_Flags;
u8 MagnetField; // in %
s16 GyroCompassCorrected;
} __attribute__((packed)) Partner_t; // from FC
extern Partner_t Partner;
extern Param_t Parameter;
extern volatile FC_t FC;
extern s8 ErrorMSG[25];
extern s8 PartnerErrorMSG[25];
extern u8 ErrorCode,PartnerErrorCode;
extern u8 StopNavigation;
extern u8 ErrorGpsFixLost;
extern u8 FromFC_LoadWP_List, ToFC_MaxWpListIndex, FromFC_Load_SinglePoint, FromFC_Save_SinglePoint;
extern volatile u32 SPIWatchDog; // stop Navigation if this goes to zero
extern volatile u32 SD_WatchDog; // stop Logging if this goes to zero
extern volatile u32 PollingTimeout;
extern u32 CountGpsProcessedIn5Sec,CountNewGpsDataIn5Sec, FreqGpsNavProcessed, FreqNewGpsData;
extern u32 TimeSinceMotorStart;
extern u8 NC_To_FC_Flags, NC_To_FC_Autostart;
extern u16 SD_SettingWaitLED;
extern u16 SD_PosAccuracy;
extern u16 SD_ComingHomeSpeed;
extern u16 SD_DPH_Speed;
extern u32 MaxWP_Radius_in_m;
extern u8 SpeakWaypointRached; // Speak once as soon as the Points are active
extern u8 SpeakNextWaypoint; // Speak once when reached
extern u8 NewWaypointsReceived; // when 1: activates the Waypoint list as soon as CH is started
extern s16 GyroCompassCorrected;
extern s16 CompassSetpointCorrected; // The compass setpoint that the FC tries to keep - corrected with the magnetic declination
extern s16 CompassSetpoint;
extern u8 AmountOfMotors;
extern s16 SimulatedDirection; // simulated compass direction
#define CHECK_ONLY 0
#define GET_LICENSE 1
#define COPY_SD_TO_EE 2
extern u8 CheckLicense(u8);
// Portpin inputs
#define PIN6_0 (GPIO6->DR[0x3FC] & 0x01)
#define PIN6_1 (GPIO6->DR[0x3FC] & 0x02)
#define PIN6_2 (GPIO6->DR[0x3FC] & 0x04)
#define PIN6_3 (GPIO6->DR[0x3FC] & 0x08)
#define PIN6_4 (GPIO6->DR[0x3FC] & 0x10)
#define PIN6_5 (GPIO6->DR[0x3FC] & 0x20)
#define TRIGGER_PP_INTERN PIN6_0
#define TRIGGER_PP_EXTERN PIN6_3
#define BLITZ_CONNECTED PIN6_4
#endif // _MAIN_H