Subversion Repositories FlightCtrl

Rev

Rev 935 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 935 Rev 936
Line 8... Line 8...
8
#include "fc.h"
8
#include "fc.h"
9
#include "rc.h"
9
#include "rc.h"
10
#include "eeprom.h"
10
#include "eeprom.h"
11
#include "uart.h"
11
#include "uart.h"
12
#include "timer0.h"
12
#include "timer0.h"
-
 
13
#include "analog.h"
Line 13... Line 14...
13
 
14
 
14
#define SPI_TXSYNCBYTE1 0xAA
15
#define SPI_TXSYNCBYTE1 0xAA
15
#define SPI_TXSYNCBYTE2 0x83
16
#define SPI_TXSYNCBYTE2 0x83
16
#define SPI_RXSYNCBYTE1 0x81
17
#define SPI_RXSYNCBYTE1 0x81
Line 40... Line 41...
40
uint8_t SPI_TxBufferIndex = 0;
41
uint8_t SPI_TxBufferIndex = 0;
Line 41... Line 42...
41
 
42
 
42
uint8_t SPITransferCompleted, SPI_ChkSum;
43
uint8_t SPITransferCompleted, SPI_ChkSum;
Line 43... Line 44...
43
uint8_t SPI_RxDataValid;
44
uint8_t SPI_RxDataValid;
44
 
45
 
Line 45... Line -...
45
uint8_t SPI_CommandSequence[] = { SPI_CMD_USER, SPI_CMD_STICK, SPI_CMD_USER, SPI_CMD_STICK, SPI_CMD_CAL_COMPASS };
-
 
46
uint8_t SPI_CommandCounter = 0;
-
 
47
 
46
uint8_t SPI_CommandSequence[] = { SPI_CMD_USER, SPI_CMD_STICK, SPI_CMD_PARAMETER1, SPI_CMD_STICK, SPI_CMD_CAL_COMPASS };
48
#ifdef USE_SPI_COMMUNICATION
47
uint8_t SPI_CommandCounter = 0;
49
 
48
 
50
/*********************************************/
49
/*********************************************/
51
/*  Initialize SPI interface to NaviCtrl     */
50
/*  Initialize SPI interface to NaviCtrl     */
Line 101... Line 100...
101
                        ToNaviCtrl.Param.Byte[3] = FCParam.UserParam4;
100
                        ToNaviCtrl.Param.Byte[3] = FCParam.UserParam4;
102
                        ToNaviCtrl.Param.Byte[4] = FCParam.UserParam5;
101
                        ToNaviCtrl.Param.Byte[4] = FCParam.UserParam5;
103
                        ToNaviCtrl.Param.Byte[5] = FCParam.UserParam6;
102
                        ToNaviCtrl.Param.Byte[5] = FCParam.UserParam6;
104
                        ToNaviCtrl.Param.Byte[6] = FCParam.UserParam7;
103
                        ToNaviCtrl.Param.Byte[6] = FCParam.UserParam7;
105
                        ToNaviCtrl.Param.Byte[7] = FCParam.UserParam8;
104
                        ToNaviCtrl.Param.Byte[7] = FCParam.UserParam8;
-
 
105
                        ToNaviCtrl.Param.Byte[8] = MKFlags;
-
 
106
                        MKFlags &= ~(MKFLAG_CALIBRATE | MKFLAG_START); // calibrate and start are temporal states that are cleared immediately after transmitting
-
 
107
                        ToNaviCtrl.Param.Byte[9] = (uint8_t)UBat;
-
 
108
                        ToNaviCtrl.Param.Byte[10] = ParamSet.LowVoltageWarning;
-
 
109
                        ToNaviCtrl.Param.Byte[11] = GetActiveParamSet();
-
 
110
                        break;
-
 
111
 
-
 
112
                case SPI_CMD_PARAMETER1:
-
 
113
                        ToNaviCtrl.Param.Byte[0] = FCParam.NaviGpsModeControl;     // Parameters for the Naviboard
-
 
114
                        ToNaviCtrl.Param.Byte[1] = FCParam.NaviGpsGain;
-
 
115
                        ToNaviCtrl.Param.Byte[2] = FCParam.NaviGpsP;
-
 
116
                        ToNaviCtrl.Param.Byte[3] = FCParam.NaviGpsI;
-
 
117
                        ToNaviCtrl.Param.Byte[4] = FCParam.NaviGpsD;
-
 
118
                        ToNaviCtrl.Param.Byte[5] = FCParam.NaviGpsACC;
-
 
119
                        ToNaviCtrl.Param.Byte[6] = ParamSet.NaviGpsMinSat;
-
 
120
                        ToNaviCtrl.Param.Byte[7] = ParamSet.NaviStickThreshold;
-
 
121
                        ToNaviCtrl.Param.Byte[8] = 15; // MaxRadius
106
                        break;
122
                        break;
Line -... Line 123...
-
 
123
 
107
 
124
 
108
                case SPI_CMD_STICK:
125
                case SPI_CMD_STICK:
109
                        tmp = PPM_in[ParamSet.ChannelAssignment[CH_GAS]];  if(tmp > 127) tmp = 127; else if(tmp < -128) tmp = -128;
126
                        tmp = PPM_in[ParamSet.ChannelAssignment[CH_GAS]];  if(tmp > 127) tmp = 127; else if(tmp < -128) tmp = -128;
110
                        ToNaviCtrl.Param.Byte[0] = (int8_t) tmp;
127
                        ToNaviCtrl.Param.Byte[0] = (int8_t) tmp;
111
                        tmp = PPM_in[ParamSet.ChannelAssignment[CH_YAW]]; if(tmp > 127) tmp = 127; else if(tmp < -128) tmp = -128;
128
                        tmp = PPM_in[ParamSet.ChannelAssignment[CH_YAW]]; if(tmp > 127) tmp = 127; else if(tmp < -128) tmp = -128;
Line 117... Line 134...
117
                        ToNaviCtrl.Param.Byte[4] = (uint8_t) Poti1;
134
                        ToNaviCtrl.Param.Byte[4] = (uint8_t) Poti1;
118
                        ToNaviCtrl.Param.Byte[5] = (uint8_t) Poti2;
135
                        ToNaviCtrl.Param.Byte[5] = (uint8_t) Poti2;
119
                        ToNaviCtrl.Param.Byte[6] = (uint8_t) Poti3;
136
                        ToNaviCtrl.Param.Byte[6] = (uint8_t) Poti3;
120
                        ToNaviCtrl.Param.Byte[7] = (uint8_t) Poti4;
137
                        ToNaviCtrl.Param.Byte[7] = (uint8_t) Poti4;
121
                        ToNaviCtrl.Param.Byte[8] = (uint8_t) RC_Quality;
138
                        ToNaviCtrl.Param.Byte[8] = (uint8_t) RC_Quality;
122
                        ToNaviCtrl.Param.Byte[9] = (uint8_t) MotorsOn;
-
 
123
                        break;
139
                        break;
Line 124... Line 140...
124
 
140
 
125
                case SPI_CMD_CAL_COMPASS:
141
                case SPI_CMD_CAL_COMPASS:
126
                        if(CompassCalState > 5)
142
                        if(CompassCalState > 5)
Line 142... Line 158...
142
        if (SPI_RxDataValid)
158
        if (SPI_RxDataValid)
143
        {
159
        {
144
                // update gps controls
160
                // update gps controls
145
                if(abs(FromNaviCtrl.GPS_Nick) < 512 && abs(FromNaviCtrl.GPS_Roll) < 512 && (ParamSet.GlobalConfig & CFG_GPS_ACTIVE))
161
                if(abs(FromNaviCtrl.GPS_Nick) < 512 && abs(FromNaviCtrl.GPS_Roll) < 512 && (ParamSet.GlobalConfig & CFG_GPS_ACTIVE))
146
                {
162
                {
147
                        GPS_Nick = FromNaviCtrl.GPS_Nick;
163
                        GPS_Nick        = FromNaviCtrl.GPS_Nick;
148
                        GPS_Roll  = FromNaviCtrl.GPS_Roll;
164
                        GPS_Roll        = FromNaviCtrl.GPS_Roll;
149
                }
165
                }
150
                // update compass readings
166
                // update compass readings
151
                if(FromNaviCtrl.CompassHeading <= 360)
167
                if(FromNaviCtrl.CompassHeading <= 360)
152
                {
168
                {
153
                        CompassHeading = FromNaviCtrl.CompassHeading;
169
                        CompassHeading = FromNaviCtrl.CompassHeading;
Line 201... Line 217...
201
 
217
 
202
                // cyclic commands
218
                // cyclic commands
203
                ToNaviCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++];
219
                ToNaviCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++];
Line 204... Line 220...
204
                if (SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0;
220
                if (SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0;
205
 
221
 
Line 206... Line 222...
206
                SPITransferCompleted = 0; // tranfer is in progress
222
                SPITransferCompleted = 0; // transfer is in progress
Line 207... Line 223...
207
                UpdateSPI_Buffer();    // update data in ToNaviCtrl
223
                UpdateSPI_Buffer();    // update data in ToNaviCtrl
Line 307... Line 323...
307
                SPITransferCompleted = 1;
323
                SPITransferCompleted = 1;
308
        }
324
        }
309
}
325
}
Line 310... Line -...
310
 
-
 
311
 
-