Subversion Repositories FlightCtrl

Rev

Rev 1927 | Rev 2099 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#ifndef _CONFIGURATION_H
#define _CONFIGURATION_H

#include <inttypes.h>
#include <avr/io.h>

typedef struct {
  /*PMM*/uint8_t HeightD;
  /* P */uint8_t MaxHeight;
  /*PMM*/uint8_t HeightP;
  /* P */uint8_t Height_ACC_Effect;
  /* P */uint8_t CompassYawEffect;

  /* P */uint8_t GyroPitchP;
  /* P */uint8_t GyroRollP;
  /* P */uint8_t GyroYawP;

  /* P */uint8_t UserParams[8];
  /* P */uint8_t ServoPitchControl;

  /* P */uint8_t GyroPitchD;  // LoopGasLimit in tool
  /* P */uint8_t GyroRollD;   // AxisCoupling1 in tool
  /* P */uint8_t GyroYawD;    // AxisCoupling2 in tool

  /* P */uint8_t ExternalControl;
  /*PMM*/uint8_t J16Timing;
  /*PMM*/uint8_t J17Timing;
} dynamicParam_t;
extern dynamicParam_t dynamicParams;

typedef struct {
  uint8_t sourceIdx, targetIdx;
  uint8_t min, max;
} MMXLATION;

typedef struct {
  uint8_t sourceIdx, targetIdx;
} XLATION;

// values above 250 representing poti1 to poti4
typedef struct {
  uint8_t ChannelAssignment[8]; // see upper defines for details
  uint8_t GlobalConfig; // see upper defines for bitcoding
  uint8_t HeightMinGas; // Value : 0-100
  uint8_t HeightD; // Value : 0-250
  uint8_t MaxHeight; // Value : 0-32
  uint8_t HeightP; // Value : 0-32
  uint8_t Height_Gain; // Value : 0-50
  uint8_t Height_ACC_Effect; // Value : 0-250

  uint8_t StickElevatorP;
  uint8_t StickAileronsP;
  uint8_t StickRudderP;

  uint8_t PIDGyroFilter;// Value: 1-8
 
  uint8_t DGyroFilter; // Value: 1-8
  uint8_t attitudeGyroFilter; // Value: 1-8

  uint8_t accFilter;

  uint8_t GyroPitchP;
  uint8_t GyroRollP;
  uint8_t GyroYawP;

  uint8_t UserParams[8]; // Value : 0-250

  uint8_t LowVoltageWarning; // Value : 0-250

  uint8_t servoDirections;
  uint8_t ServoRefresh; // Value: 0-250      // Refreshrate of servo pwm output

  uint8_t GyroPitchD;
  uint8_t GyroRollD;
  uint8_t GyroYawD;

  uint8_t zerothOrderGyroCorrectionZAccLimit;
  uint8_t zerothOrderGyroCorrectionFactorx1000;

  uint8_t secondOrderGyroCorrectionDivisor;
  uint8_t secondOrderGyroCorrectionLimit;
  uint8_t CompassYawEffect; // Value : 0-32

  uint8_t J16Bitmask; // for the J16 Output
  uint8_t J16Timing; // for the J16 Output
  uint8_t J17Bitmask; // for the J17 Output
  uint8_t J17Timing; // for the J17 Output

  uint8_t ExternalControl; // for serial Control
} paramset_t;

#define  PARAMSET_STRUCT_LEN  sizeof(paramset_t)

extern paramset_t staticParams;

typedef struct {
  uint8_t Revision;
  int8_t Name[12];
  int8_t Motor[16][4];
}__attribute__((packed)) MixerTable_t;

extern MixerTable_t Mixer;

// MKFlags
#define MKFLAG_MOTOR_RUN        (1<<0)
#define MKFLAG_FLY              (1<<1)
#define MKFLAG_CALIBRATE        (1<<2)
#define MKFLAG_START            (1<<3)
#define MKFLAG_EMERGENCY_LANDING (1<<4)
#define MKFLAG_RESERVE1         (1<<5)
#define MKFLAG_RESERVE2         (1<<6)
#define MKFLAG_RESERVE3         (1<<7)

// bit mask for staticParams.GlobalConfig
#define CFG_HEIGHT_CONTROL      (1<<0)
#define CFG_HEIGHT_SWITCH       (1<<1)
#define CFG_HEADING_HOLD        (1<<2)
#define CFG_COMPASS_ACTIVE      (1<<3)
#define CFG_COMPASS_FIX         (1<<4)
#define CFG_GPS_ACTIVE          (1<<5)
#define CFG_AXIS_COUPLING_ACTIVE (1<<6)
#define CFG_ROTARY_RATE_LIMITER (1<<7)

// bit mask for staticParams.ServoDirections
#define SERVO_DIRECTION_ELEVATOR        (1<<0)
#define SERVO_DIRECTION_AILERONS        (1<<1)
#define SERVO_DIRECTION_RUDDER          (1<<2)

#define ATMEGA644       0
#define ATMEGA644P      1
#define SYSCLK F_CPU

// Not really a part of configuration, but LEDs and HW version test are the same.
#define RED_OFF   {if((BoardRelease == 10) || (BoardRelease == 20)) PORTB &=~(1<<PORTB0); else  PORTB |= (1<<PORTB0);}
#define RED_ON    {if((BoardRelease == 10) || (BoardRelease == 20)) PORTB |= (1<<PORTB0); else  PORTB &=~(1<<PORTB0);}
#define RED_FLASH PORTB ^= (1<<PORTB0)
#define GRN_OFF   {if(BoardRelease  < 12) PORTB &=~(1<<PORTB1); else PORTB |= (1<<PORTB1);}
#define GRN_ON    {if(BoardRelease  < 12) PORTB |= (1<<PORTB1); else PORTB &=~(1<<PORTB1);}
#define GRN_FLASH PORTB ^= (1<<PORTB1)

// Mixer table
#define MIX_THROTTLE    0
#define MIX_PITCH       1
#define MIX_ROLL        2
#define MIX_YAW         3

extern volatile uint8_t MKFlags;
extern int16_t variables[8]; // The "Poti"s.
extern uint8_t BoardRelease;
extern uint8_t CPUType;

void configuration_staticToDynamic(void);
uint8_t getCPUType(void);
uint8_t getBoardRelease(void);

#endif // _CONFIGURATION_H