Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1612 dongfang 1
#ifndef _SPI_H
2
#define _SPI_H
3
 
4
//#include <util/delay.h>
5
#include <inttypes.h>
6
#define SPI_PROTOCOL_COMP   1
7
 
8
#define SPI_CMD_USER        10
9
#define SPI_CMD_STICK       11
10
#define SPI_CMD_MISC            12
11
#define SPI_CMD_PARAMETER1      13
12
#define SPI_CMD_VERSION         14
13
#define SPI_CMD_OSD_DATA        100
14
#define SPI_CMD_GPS_POS         101
15
#define SPI_CMD_GPS_TARGET      102
16
#define SPI_KALMAN                      103
2035 - 17
#define SPI_NCCMD_KALMAN                103
18
#define SPI_NCCMD_VERSION               104
19
#define SPI_NCCMD_GPSINFO               105
20
#define SPI_NCCMD_HOTT_DATA             106
21
#define SPI_MISC                                107
1612 dongfang 22
 
2035 - 23
// Satfix types for GPSData.SatFix
24
#define SATFIX_NONE                             0x00
25
#define SATFIX_DEADRECKOING             0x01
26
#define SATFIX_2D                               0x02
27
#define SATFIX_3D                               0x03
28
#define SATFIX_GPS_DEADRECKOING 0x04
29
#define SATFIX_TIMEONLY                 0x05
30
// Flags for interpretation of the GPSData.Flags
31
#define FLAG_GPSFIXOK                           0x01 // (i.e. within DOP & ACC Masks)
32
#define FLAG_DIFFSOLN                           0x02 // (is DGPS used)
33
#define FLAG_WKNSET                                     0x04 // (is Week Number valid)
34
#define FLAG_TOWSET                                     0x08 // (is Time of Week valid)
35
#define FLAG_GPS_NAVIGATION_ACTIVE      0x10 // NC to FC -> NC is ready to navigate
36
 
1645 - 37
typedef struct {
2035 - 38
        uint8_t sync1;
39
        uint8_t sync2;
40
        uint8_t command;
41
        int16_t integralPitch;
42
        int16_t integralRoll;
43
        int16_t accPitch;
44
        int16_t accRoll;
45
        int16_t gyroHeading;
46
        int16_t gyroPitch;
47
        int16_t gyroRoll;
48
        int16_t gyroYaw;
49
        uint8_t FCStatus;
50
        union {
51
                int8_t  asSignedByte[12];
52
                uint8_t asByte[12];
53
                int16_t asInt[6];
54
                int32_t asLong[3];
55
                float   asFloat[3];
56
        } param;
57
        uint8_t chksum;
58
}__attribute__((packed)) ToNaviCtrl_t;
59
 
60
typedef struct {
61
        uint8_t command;
1821 - 62
        int16_t GPSStickPitch;
63
        int16_t GPSStickRoll;
2035 - 64
        int16_t GPSStickYaw;
65
        int16_t accErrorPitch;
66
        int16_t accErrorRoll;
67
        int16_t magVectorZ;
68
        int16_t compassHeading;
69
        int16_t status;
70
        uint16_t beepTime;
1821 - 71
        union {
2035 - 72
                int8_t  asSignedByte[12];
73
                uint8_t asByte[12];
74
                int16_t asSignedInt[6];
75
                uint16_t asInt[6];
76
                int32_t asSignedLong[3];
77
                uint32_t asLong[3];
78
                float   asFloat[3];
79
        } param;
80
        uint8_t chksum;
1821 - 81
}__attribute__((packed)) FromNaviCtrl_t;
1612 dongfang 82
 
1645 - 83
typedef struct {
2035 - 84
        uint8_t major;
85
        uint8_t minor;
86
        uint8_t patch;
87
        uint8_t compatible;
88
        uint8_t hardware;
1821 - 89
}__attribute__((packed)) SPI_VersionInfo_t;
1612 dongfang 90
 
2035 - 91
// Some of this is defined for compatibility with H&I NaviCtrl rather than necessity of the data...
92
typedef struct {
93
        int8_t kalmanK;
94
        int8_t kalmanMaxDrift;
95
        int8_t kalmanMaxFusion;
96
        uint8_t serialDataOkay;
97
        int8_t GPS_Z;
98
}__attribute__((packed)) NCData_t;
99
 
100
typedef struct {
101
        unsigned char   flags;                  // Status Flags
102
        unsigned char   numOfSats;              // number of satelites
103
        unsigned char   satFix;                 // type of satfix
104
        unsigned char   speed;                  // m/sek
105
        unsigned int    homeDistance;   // distance to Home in dm
106
        int                             homeBearing;    // bearing to home in deg
107
}__attribute__((packed)) GPSInfo_t;
108
 
109
extern SPI_VersionInfo_t naviCtrlVersion;
1821 - 110
extern ToNaviCtrl_t toNaviCtrl;
111
extern FromNaviCtrl_t fromNaviCtrl;
2035 - 112
extern NCData_t naviCtrlData;
113
extern GPSInfo_t GPSInfo;
1612 dongfang 114
 
115
extern uint8_t NCDataOkay;
116
extern uint8_t NCSerialDataOkay;
117
 
118
void SPI_MasterInit(void);
119
void SPI_StartTransmitPacket(void);
120
void SPI_TransmitByte(void);
121
 
122
#endif //_SPI_H