Subversion Repositories FlightCtrl

Rev

Rev 1821 | Blame | Last modification | View Log | RSS feed

#ifndef _SPI_H
#define _SPI_H

//#include <util/delay.h>
#include <inttypes.h>
#define SPI_PROTOCOL_COMP   1

#define SPI_CMD_USER        10
#define SPI_CMD_STICK       11
#define SPI_CMD_MISC            12
#define SPI_CMD_PARAMETER1      13
#define SPI_CMD_VERSION         14
#define SPI_CMD_OSD_DATA        100
#define SPI_CMD_GPS_POS         101
#define SPI_CMD_GPS_TARGET      102
#define SPI_KALMAN                      103
#define SPI_NCCMD_KALMAN                103
#define SPI_NCCMD_VERSION               104
#define SPI_NCCMD_GPSINFO               105
#define SPI_NCCMD_HOTT_DATA             106
#define SPI_MISC                                107

// Satfix types for GPSData.SatFix
#define SATFIX_NONE                             0x00
#define SATFIX_DEADRECKOING             0x01
#define SATFIX_2D                               0x02
#define SATFIX_3D                               0x03
#define SATFIX_GPS_DEADRECKOING 0x04
#define SATFIX_TIMEONLY                 0x05
// Flags for interpretation of the GPSData.Flags
#define FLAG_GPSFIXOK                           0x01 // (i.e. within DOP & ACC Masks)
#define FLAG_DIFFSOLN                           0x02 // (is DGPS used)
#define FLAG_WKNSET                                     0x04 // (is Week Number valid)
#define FLAG_TOWSET                                     0x08 // (is Time of Week valid)
#define FLAG_GPS_NAVIGATION_ACTIVE      0x10 // NC to FC -> NC is ready to navigate

typedef struct {
        uint8_t sync1;
        uint8_t sync2;
        uint8_t command;
        int16_t integralPitch;
        int16_t integralRoll;
        int16_t accPitch;
        int16_t accRoll;
        int16_t gyroHeading;
        int16_t gyroPitch;
        int16_t gyroRoll;
        int16_t gyroYaw;
        uint8_t FCStatus;
        union {
                int8_t  asSignedByte[12];
                uint8_t asByte[12];
                int16_t asInt[6];
                int32_t asLong[3];
                float   asFloat[3];
        } param;
        uint8_t chksum;
}__attribute__((packed)) ToNaviCtrl_t;

typedef struct {
        uint8_t command;
        int16_t GPSStickPitch;
        int16_t GPSStickRoll;
        int16_t GPSStickYaw;
        int16_t accErrorPitch;
        int16_t accErrorRoll;
        int16_t magVectorZ;
        int16_t compassHeading;
        int16_t status;
        uint16_t beepTime;
        union {
                int8_t  asSignedByte[12];
                uint8_t asByte[12];
                int16_t asSignedInt[6];
                uint16_t asInt[6];
                int32_t asSignedLong[3];
                uint32_t asLong[3];
                float   asFloat[3];
        } param;
        uint8_t chksum;
}__attribute__((packed)) FromNaviCtrl_t;

typedef struct {
        uint8_t major;
        uint8_t minor;
        uint8_t patch;
        uint8_t compatible;
        uint8_t hardware;
}__attribute__((packed)) SPI_VersionInfo_t;

// Some of this is defined for compatibility with H&I NaviCtrl rather than necessity of the data...
typedef struct {
        int8_t kalmanK;
        int8_t kalmanMaxDrift;
        int8_t kalmanMaxFusion;
        uint8_t serialDataOkay;
        int8_t GPS_Z;
}__attribute__((packed)) NCData_t;

typedef struct {
        unsigned char   flags;                  // Status Flags
        unsigned char   numOfSats;              // number of satelites
        unsigned char   satFix;                 // type of satfix
        unsigned char   speed;                  // m/sek
        unsigned int    homeDistance;   // distance to Home in dm
        int                             homeBearing;    // bearing to home in deg
}__attribute__((packed)) GPSInfo_t;

extern SPI_VersionInfo_t naviCtrlVersion;
extern ToNaviCtrl_t toNaviCtrl;
extern FromNaviCtrl_t fromNaviCtrl;
extern NCData_t naviCtrlData;
extern GPSInfo_t GPSInfo;

extern uint8_t NCDataOkay;
extern uint8_t NCSerialDataOkay;

void SPI_MasterInit(void);
void SPI_StartTransmitPacket(void);
void SPI_TransmitByte(void);

#endif //_SPI_H